linux kernel中的一些utility API---(1)
来源:互联网 发布:mysql 时间小于等于 编辑:程序博客网 时间:2024/04/30 11:20
===========================================================================================================
--- index:
=> How to get current registers? - _RET_IP_, _THIS_IP_
=> sort array - sort() in /lib/sort.c
=> <linux/math64.h> - 64-bit division
=> <linux/textsearch.h> - text search library
===========================================================================================================
@@ How to get current registers? - _RET_IP_, _THIS_IP_
#
# /include/linux/kernel.h
#
#define _RET_IP_(unsigned long)__builtin_return_address(0) # This is the built in support from gcc.
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })# A trick
===========================================================================================================
@@ sort array - sort() in /lib/sort.c
#
# <linux/sort.h>
#
# /lib/sort.c
#
/**
* sort - sort an array of elements
* @base: pointer to data to sort
* @num: number of elements
* @size: size of each element
* @cmp_func: pointer to comparison function
* @swap_func: pointer to swap function or NULL
*
* This function does a heapsort on the given array. You may provide a
* swap_func function optimized to your element type.
*
* Sorting time is O(n log n) both on average and worst-case. While
* qsort is about 20% faster on average, it suffers from exploitable
* O(n*n) worst-case behavior and extra memory requirements that make
* it less suitable for kernel use.
*/
void sort(void *base, size_t num, size_t size,
int (*cmp_func)(const void *, const void *),
void (*swap_func)(void *, void *, int size))
#
# "swap_func" is to swap "src" and "dst" content.
#
# If "swap_func" is NULL, then sort()'s default one is:
# "src" <- memcpy() -> "dst"
#
===========================================================================================================
@@ <linux/math64.h> - 64-bit division
#
# 64-bit division may need to conform to special rules on some $(arch).
#
# [*] For example, Huizhao once fixed a WIFI driver crash bug on mips32 platform, which was 64-bit division:
#
# u64 a, b, c;
#
# c = a / b;
#
# It cause some magic crash with symbol like "_div". It seems to be that gcc may generate some error ASM
# instructions for 64-bit division on some 32-bit $(arch), or cause unaligned exception, or other possiblities.
#
#
# Kernel is aware of that.
#
#
# See the <comment> in /lib/div64.c
#
*
* Generic C version of 64bit/32bit division and modulo, with
* 64bit result and 32bit remainder.
*
* The fast case for (n>>32 == 0) is handled inline by do_div().
*
* Code generated for this function might be very inefficient
* for some CPUs. __div64_32() can be overridden by linking arch-specific
* assembly versions such as arch/ppc/lib/div64.S and arch/sh/lib/div64.S.
#
#
# So, the following files:
#
# <linux/math64.h># declare inline function for 64-bit division
#
# <asm/div64.h># $(arch) may provide its own 64-bit division function in ASM.
#
# #if BITS_PER_LONG == 64
#
# ... # For 64-bit $(arch), no need for special handling on 64-bit division.
#
# #elif BITS_PER_LONG == 32
#
# ... # For 32-bit $(arch), if there is no ASM defintion in <asm/div64.h>, then
# # kernel will try to provide C implementation in /lib/div64.c
#
# #endif /* BITS_PER_LONG */
#
#
#
# [?] I only see 64-bit division here, how about 64-bit multiplcation ?
#
===========================================================================================================
@@ <linux/textsearch.h> - text search library
Note these APIs:
textsearch_prepare()
skb_find_text() -> textsearch_find()
textsearch_destroy()
Usage example: <<netfilterIF---MATCH-EXT---common.txt>>- "iptables" - "string" - "xt_string_mt_reg"
===========================================================================================================
0 0
- linux kernel中的一些utility API---(1)
- The Linux Kernel API
- Linux Kernel API (2.6)
- 查阅linux kernel api
- The Linux Kernel API
- The Linux Kernel API
- The Linux Kernel API
- The Linux Kernel API
- The Linux API / Kernel API
- 一些linux kernel 网站
- 原来还有linux kernel api
- LINUX GPIO Kernel/User API
- Linux Kernel API man (ubuntu)
- Linux kernel中的IS_ENABLED
- linux kernel的一些写法
- 一些linux kernel hacking资料
- Electron中的一些API
- LUA中的一些API
- 国内SEO人才与公司现状
- Samba 的使用与访问
- 当freemarker中EL表达式的值为空时出现异常的解决方法
- 文本文件生成时的一项注意点(UTF-8)
- request.parameter是数组,不能直接==来用
- linux kernel中的一些utility API---(1)
- Java 成员内部类
- 影响网站seo排名的因素大全
- c#实现改变背景颜色、背景图片、插入背景音乐
- c#作业第二期第一弹(记事本程序)
- samurai-native 学习笔记--samurai的启动过程(待完善)
- java 正则校验
- 零基础入门学习C++ 001
- JDBC(CallableStatement)--In Parameter Insert Record