Loading

摘要: Linux 内核中 offset_of 和 container_of 宏的实现 offset_of via: https://elixir.bootlin.com/linux/latest/source/tools/include/linux/kernel.h#L23 获取成员在结构体中的偏移量 # 阅读全文
posted @ 2020-07-09 16:25 scriptk1d 阅读(351) 评论(0) 推荐(0)
摘要: malloc_par via:https://elixir.bootlin.com/glibc/glibc-2.26/source/malloc/malloc.c#L1783 每个分配区是 struct malloc_state 的一个实例, ptmalloc 使用 malloc_state 来管理 阅读全文
posted @ 2020-07-01 17:05 scriptk1d 阅读(533) 评论(0) 推荐(0)
摘要: 从 glibc2.26 开始引入了一个 freed chunk 管理机制:tcache -- thread local caching 还是那句话:Read The F**king Source Code glibc 版本:2.26,via:https://elixir.bootlin.com/gl 阅读全文
posted @ 2020-06-30 18:04 scriptk1d 阅读(412) 评论(0) 推荐(0)
摘要: 今天有点无聊在 YouTube 上瞎看 看到了 liveoverflow 的一个视频,提到 TOCTOU ,所以打算复现一下 via: https://www.youtube.com/watch?v=5g137gsB9Wk demo 代码: via: https://gist.github.com/ 阅读全文
posted @ 2020-06-26 15:00 scriptk1d 阅读(2512) 评论(0) 推荐(0)
摘要: 这几天一直在忙别的事,完事了,看了点文件系统相关的部分,就看看 read 在内核里面的实现 这是大概的函数调用链,但是我不会一个一个全部去分析,我只看主要的 man 手册描述 via:https://man7.org/linux/man-pages/man2/read.2.html NAME rea 阅读全文
posted @ 2020-06-25 16:38 scriptk1d 阅读(1721) 评论(0) 推荐(0)
摘要: Linux内核源码分析 -- 同步原语 -- 互斥锁 mutex /* * Simple, straightforward mutexes with strict semantics: * * - only one task can hold the mutex at a time (同一时间仅能被 阅读全文
posted @ 2020-06-11 01:32 scriptk1d 阅读(1231) 评论(0) 推荐(0)
摘要: Linux内核源码分析 -- 同步原语 -- 自旋锁 spinlock_t typedef struct spinlock { union { struct raw_spinlock rlock; #ifdef CONFIG_DEBUG_LOCK_ALLOC # define LOCK_PADSIZ 阅读全文
posted @ 2020-06-07 22:57 scriptk1d 阅读(1134) 评论(0) 推荐(0)
摘要: Linux内核源码分析 -- 同步原语 -- 信号量 semaphore 源码位于 include/linux/semaphore struct semaphore { raw_spinlock_t lock; // 保护信号量的自旋锁 unsigned int count; // 现有的资源的数量 阅读全文
posted @ 2020-06-07 18:37 scriptk1d 阅读(514) 评论(0) 推荐(0)
摘要: Linux 内核源码分析 -- getuid,geteuid getuid 获取用户标识号 via:https://man7.org/linux/man-pages/man2/geteuid.2.html returns the real user ID of the calling process 阅读全文
posted @ 2020-06-05 23:54 scriptk1d 阅读(1913) 评论(0) 推荐(0)
摘要: chroot 在 内核中的实现 在 Linux 5.6 版本中 chroot 函数的系统调用对应的函数位于:./fs/open.c:539:SYSCALL_DEFINE1(chroot, const char __user *, filename) via: https://elixir.bootl 阅读全文
posted @ 2020-06-04 02:09 scriptk1d 阅读(1064) 评论(0) 推荐(0)