Skip to content

Latest commit

 

History

History
191 lines (166 loc) · 10.3 KB

REF.md

File metadata and controls

191 lines (166 loc) · 10.3 KB

信号相关

Socket相关

Zero Copy:

libc hook syscall hook

内存管理

Linux 内核:

进程调度 https://deepinout.com/linux-kernel-api/linux-kernel-api-process-scheduling/linux-kernel-api-wake_up_process.html
    内核空间:kthread_create kthread_stop wake_up_process
    用户空间:schedule();
    进程调度相关:
        https://www.apispace.com/news/post/27165.html  int nice(int inc);nice value getpriority/setpriority函数 sched_getaffinity和sched_setaffinity
        getrlimit()  setrlimit()
       资源限制 http://e.betheme.net/article/show-1355487.aspx?action=onClick 在Linux系统中,进程资源限制分为软限制(soft limit)和硬限制(hard limit)两种。

syscall

但是在linux内核5.x里,entrySYSCALL64的实现改了,不再试图用过call syscalltable[index]的方式进行系统调用,而是引入了一个dosyscall64的符号。具体的看下面截取的源码

syscall table :

https://blog.csdn.net/weixin_42915431/article/details/106507066 kallsyms_lookup_name | system.map | PAGE_OFFSET -> NR_close

https://zhuanlan.zhihu.com/p/480934356 设置 sys_call_table 数组为可写状态

syscall 传参:

https://zhuanlan.zhihu.com/p/446785414 asmlinkage 与 寄存器传参 在内核态直接写入用户态内存 copy_to_user

https://zhuanlan.zhihu.com/p/102957159 copy_to_user & copy_from_user 的说明

https://www.cnblogs.com/xinghuo123/p/13796932.html linux系统调用-SYSCALL_DEFINEx详解

ptrace & ptrace

动态添加系统调用:

__NR_syscall

关于用户向内核传递数据的问题:固定一个发送地址空间,固定一个接收地址空间,在系统调用时检查该空间 copy_to_user & copy_from_user

https://blog.csdn.net/weixin_45930312/article/details/126255496 采用既有系统调用(文件系统 read/write)向内核传递可读写用户空间地址

内存映像 mmap

https://blog.csdn.net/cwdben/article/details/119919094 linux内核模块与用户程序共享内存

内核热补丁 https://cloud.tencent.com/developer/article/1646414 klp_enable_patch 在内核代码中,就有热补丁的例子在samples/livepatch目录下

kernel & userspace 通信:

1,syscall

2,netlink

3,VFS

方案: 1,修改编译内核 2,sys_call_table 3,ftrace 4,lsm 5,ptrace

内核模块间通信:

深入Linux内核架构 -- P393 依赖关系与导出符号

关于内存管理 new/delete 运算符重载得反面意见:

意见值得重视,但问题并非不能解决 -- 无论如何,对外部使用者来说,为了使用某个功能而造成默认操作被不知情或被强迫地修改,是一个大问题。

内核内存分配 需求与方式的类型

sudo insmod kernel_syscall_hooks

sudo rmmod kernel_syscall_hooks

dmesg | tail -n20

虚拟文件系统:

深入Linux内核架构 -- P542

kernfs

https://blog.csdn.net/sinat_32960911/article/details/128582089 关于kernfs的说明:sysfs功能代码的抽离

sysfs

UTF-8

红黑树:

https://blog.csdn.net/qq_40843865/article/details/102498310 删除操作 TODO -- 检查各种情况下的无子节点情况

https://www.geeksforgeeks.org/introduction-to-red-black-tree/ 所以说很多东西,我们都是知其然不知其所以然,内部的很多规律定则,我们并没有搞清楚,只是照葫芦画瓢

linux驱动15---linux内核静态库的编译与使用 分类: LINUX2016-05-05 10:48:11 有时会遇到这样的情况,跟其它厂商合作时,厂商只给了库及其头文件, 然后加入到内核源码中进行编译,下面就摸拟这种情况.

  1. linux 内核目录下编译靜态库 cong@msi:/work/qemu/linux-3.0.1$ mkdir -pv drivers/mylib/ ;;在driver/mylib目录下放静态库的代码 cong@msi:/work/qemu/linux-3.0.1$ cat drivers/mylib/Makefile ;;编译静态库的Makefile,只有一行 lib-y := mylib.o cong@msi:/work/qemu/linux-3.0.1$ cat drivers/mylib/mylib.c ;;静态库的内容,就一个打印函数 #include #include #include int mylib_func(void) { printk("mylib func\n"); return 0; } EXPORT_SYMBOL(mylib_func); cong@msi:/work/qemu/linux-3.0.1$ cat include/linux/mylib.h ;;静态库的头文件 #ifndef _MYLIB_H #define _MYLIB_H int mylib_func(void); #endif /* _MYLIB_H */ cong@msi:/work/qemu/linux-3.0.1$ vi drivers/Makefile ;;最后在上级目录drivers的Makefile加入 obj-y += mylib/ ;;自己的库的编译 make编译内核,则会在drivers/mylib/目录下编译出静态库来了 cong@msi:/work/qemu/linux-3.0.1$ ls drivers/mylib/ built-in.o lib.a Makefile modules.order mylib.c mylib.o 2.linux内核使用静态库 cong@msi:/work/qemu/linux-3.0.1$ cat drivers/hello/hello.c #include <linux/kernel.h> #include <linux/module.h> #include <linux/mylib.h> ;;加入静态库的头文件 static int __init hello_init(void) { int ret = 0; printk(KERN_INFO "next cong test mylib\n"); mylib_func(); ;;调用静态库的函数 return ret; } static void __exit hello_exit(void) { return ; } MODULE_AUTHOR(" cong"); MODULE_DESCRIPTION("test mylib"); MODULE_LICENSE("GPL"); module_init(hello_init); module_exit(hello_exit);

cong@msi:/work/qemu/linux-3.0.1$ cat drivers/hello/Makefile ;;加入调用静态库的函数 obj-y += hello.o ../mylib/lib.a

cong@msi:/work/qemu/linux-3.0.1$ vi drivers/Makefile obj-y += hello/

3.最后试一下去掉静态库源码,只保留库 cong@msi:/work/qemu/linux-3.0.1$ cp ./drivers/mylib/lib.a ./drivers/hello/ ;;将库copy到调用库的地方 cong@msi:/work/qemu/linux-3.0.1$ vi drivers/Makefile #obj-y += mylib/ ;; 去掉库的编译 cong@msi:/work/qemu/linux-3.0.1$ rm -rf drivers/mylib ;; 同时去掉库的源码

cong@msi:/work/qemu/linux-3.0.1$ vi drivers/hello/Makefile ;; 修改调用者的Makefile obj-y += hello.o lib.a

#JavaScript 字体解析 https://zhangzhipeng.net/2020/04/19/js%e8%a7%a3%e6%9e%90ttf%e5%ad%97%e4%bd%93%e6%96%87%e4%bb%b6/