
内核API
文章平均质量分 67
yldfree
有技术就是一切
展开
-
内核函数 __module_addess
struct module *__module_address(unsigned long addr)function: 根据地址获得该地址所在的模块addr: 内存地址返回值: 地址所在模块的地址,若不存在则返回NULL注意: 使用此函数需要禁止内核抢占使用preempt_disable和preempt_enable来禁止和允许内核抢占头文件: #inc...原创 2018-07-03 00:03:13 · 1736 阅读 · 0 评论 -
内核函数add_timer 内核版本2.6.32
struct timer_list { struct list_head entry; //将多个定时器连城链表 unsigned long expires; //超时时间,用节拍表示,此值小于或等于jiffies的时候说明定时器到期或终止 void (*function)(unsigned long);//超时后执行的...原创 2018-07-25 23:43:08 · 2013 阅读 · 0 评论 -
内核函数__get_free_page和 free_pages
unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order)功能:以gfp_mask的方式分配2^order个物理页面gfP_mask:分配的方式,指出如何分配在哪分配如GFP_KERNELorder:分配2^order个页面返回值:返回分配的第一个页的逻辑地址头文件: #include <gfp/linux.h...原创 2018-07-20 23:40:35 · 11279 阅读 · 0 评论 -
内核函数 __get_vm_area和free_vm_area
struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags, unsigned long start, unsigned long end)功能: 从start到end之间获得size字节大小的内核虚拟空间size:分配字节的大小flags:地址空...原创 2018-07-21 12:25:16 · 3145 阅读 · 0 评论 -
文件系统内核函数
int __mnt_is_readonly(struct vfsmount *mnt)功能:挂载设备是不是只读的mnt:挂载结构体指针返回值: 1是只读的 0不是只读的头文件:#include <linux/mount.h>内核实现:(2.6.32)int __mnt_is_readonly(struct vfsmount *mnt){ if (mnt->mn...原创 2018-08-02 00:00:15 · 1929 阅读 · 0 评论 -
通用netlink NETLINK_GENERIC 基本函数
消息格式 int genl_register_family(struct genl_family *family)功能:通用link协议由family来管理,此函数注册一个通用netlink family,其实就是将family表项加入到family_ht表中family:通用netlink family返回值:成功返回0 失败返回负数错误码头文件: #include <n...原创 2018-09-10 18:26:54 · 4131 阅读 · 0 评论 -
内核网络通知链的使用netdev_chain和inetaddr_chain
函数介绍(1) int register_netdevice_notifier(struct notifier_block *nb)功能: 在内核通知链netdev_chain上注册消息块,用来接收有关网络设备的注册状态等信息nb:消息块,在里面自己添加消息处理函数返回值:成功返回0头文件:#include <linux/netdevice.h>(2) int unre...原创 2018-11-14 15:16:52 · 4125 阅读 · 1 评论 -
kobject的使用
struct kobj_type { void (*release)(struct kobject *kobj);//在kobect_put()中会调用释放kobect对象 struct sysfs_ops *sysfs_ops; //对attribute进行操作 struct attribute **default_attrs; /*每个属性代...原创 2018-11-23 15:20:22 · 3457 阅读 · 0 评论 -
linux 2.6.32下sysctl的使用
struct ctl_table { int ctl_name; /* 结点标识,同一层的结点用不同的数字来标识 此处设置的意义可以看do_sysctl()->parse_table() ...原创 2018-11-27 15:36:50 · 2639 阅读 · 0 评论 -
linux 如何隐藏 /proc/目录下的文件(version 2.6 其他版本没适配)
只为研究而用 禁止用于非法行为!!!!!/* *通过加载此模块 来将/proc目录下的文件进行隐藏* 使用方式 insmod xx.ko hidestr='xxxx' * */#include <linux/kmod.h>#include <linux/module.h>#include <linux/init.h>#include &...原创 2019-06-06 15:44:43 · 495 阅读 · 0 评论 -
内核函数时间获得
struct timespec { long tv_sec; 秒数 long tv_nsec; 纳秒数};struct timeval { __kernel_time_t tv_sec; 秒数 __kernel_suseconds_t tv_usec; 微妙};struct rtc...原创 2018-07-25 13:26:59 · 5812 阅读 · 0 评论 -
内核函数pages相关
void *alloc_pages_exact(size_t size, gfp_t gfp_mask)功能:类似于__get_free_pages其实它内部也是调用了__get_free_pages,不同之处是__get_free_pages会申请2^order个物理页,但此函数申请满足需求的最小页个数size:需求的内存大小,但需求的和实习分配的不一定会相同gfp_mask: 分配标识 G...原创 2018-07-24 19:16:35 · 2151 阅读 · 0 评论 -
内核函数 kmem_cache_xxxx
struct kmem_cache *kmem_cache_create (const char *name, size_t size, ...原创 2018-07-24 15:33:37 · 3083 阅读 · 0 评论 -
内核函数 __module_text_address
struct module *__module_text_address(unsigned long addr)功能: 若addr此地址在某模块的代码段中 返回模块的地址addr:内存地址返回值:模块地址或NULL注意: 使用时禁止内核抢占 preempt_disable和preempt_enable头文件: #include <linux/module.h>举例子: ...原创 2018-07-03 00:24:19 · 1808 阅读 · 0 评论 -
内核函数 __print_symbol
void __print_symbol(const char *fmt, unsigned long address);功能: 根据地址返回符号的基本信息 符号名 大小等fmt:格式化字符串 address:地址头文件: #include <linux/kallsyms.h>内核中实现如下:void __print_symbol(const char *fmt, unsigned l...原创 2018-07-03 00:42:48 · 2258 阅读 · 0 评论 -
add_wait_queue 等待队列添加等待队列元素
//将队列元素加入到等待队列头部设置非互斥等待void add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait){ unsigned long flags; /* 当一个等待队列入口有 WQ_FLAG_EXCL...原创 2018-07-16 22:27:17 · 4806 阅读 · 0 评论 -
内核符号之获得内核符号地址1__symbol_get
void *__symbol_get(const char * symbol)symbol: 符号名ret: 符号的地址,不存在则返回空头文件: #include <linux/module.h>原创 2018-07-02 14:55:09 · 3438 阅读 · 0 评论 -
内核函数find_module
struct module *find_module(const char *name)功能: 根据模块名获得模块的地址,遍历modules链表,比较符号名,modules链表连接所有的模块name:模块名返回值:查找成功 返回模块地址,失败返回NULL头文件:#include <linux/module.h>find_module的实现如下在2.6.32版本:struct modu...原创 2018-07-04 23:16:18 · 2504 阅读 · 0 评论 -
内核函数 内核模块引用计数
static inline int module_is_live(struct module *mod)功能:此函数为inline函数判断模块是否在活跃状态,如果不是MODULE_STATE_GOING(正在被卸载)状态,则就是活跃状态mod:模块的地址返回值: 为真或假头文件: #include <linux/modle.h>内核实现:(2.6.32)static inline in...原创 2018-07-05 07:47:45 · 2979 阅读 · 0 评论 -
内核函数autoremove_wake_function
int autoremove_wake_function(wait_queue_t *wait, //等待队列中的某一个元素 unsigned mode, //能被唤醒的进程所处于的状态 ...原创 2018-07-17 22:16:10 · 2159 阅读 · 0 评论 -
内核函数 内核线程创建
struct task_struct *kthread_create(int (*threadfn)(void *data),void *data, const char namefmt[], ...)功能:创建一个内核线程threadfn:线程运行的函数data:传递给线程函数的参数namefmt: 进程名 在task->comm中保存此字符串头文件: #include <linux...原创 2018-07-12 19:31:47 · 2568 阅读 · 0 评论 -
内核函数 设置 获取进程nice值
void set_user_nice( struct task_struct *p, long nice)功能: 设置进程的nice值p:进程的描述符nice:设置的nice值 取值范围为 -20 ~ 19 值越大优先级越小头文件: #include <linux/sched.h>int task_nice(const struct task_struct *p...原创 2018-07-19 07:35:26 · 4560 阅读 · 0 评论 -
linux内核sort()排序的使用
函数原型void sort(void *base,size_t num,size_t size,int (*cmp_func)(const void *, const void *),void (*swap_func)(void *, void *, int size))参数说明base:数据的...原创 2019-07-09 11:08:22 · 1695 阅读 · 0 评论