Skip to content

Instantly share code, notes, and snippets.

@wbs0829
wbs0829 / pa.c
Last active December 9, 2020 08:39
__phys_addr_nodebug analysis
//CC=gcc
//CFLAGS=-O3 -S
//
//pa.s: pa.c
// $(CC) -DRAW_PA $(CFLAGS) -o $@ $^
//
//my_pa.s: pa.c
// $(CC) $(CFLAGS) -o $@ $^
//
//all: pa.s my_pa.s
@wbs0829
wbs0829 / generate_random_number.c
Created April 6, 2016 12:45
generate a random number with x86 rdrand instruction
#include <stdio.h>
int main()
{
unsigned long n;
asm("rdrand %%rax":"=a"(n));
printf("%lx\n", n);
return 0;
}
@wbs0829
wbs0829 / effective_LOC_C.sh
Last active April 14, 2016 02:39
统计有效的代码行(非空行、非注释行)数
#!/bin/sh
find . -name "*.[chS]"|xargs grep -Ev "^\s*((//|\*|/\*).*)?$"|wc -l
@wbs0829
wbs0829 / find_excluding.sh
Last active April 14, 2016 06:49
find排除特定目录搜索文件
find . -not \( -path "./asm" -prune \) -name "*.h"
#不直接使用-prune,因为在加上-o -name过后会输出排除的目录
@wbs0829
wbs0829 / kernel_notes.md
Last active June 16, 2016 08:59
内核杂记

内核杂记

有问题先看Documentation/下的文档

set_all_modules_text_rw, set_kernel_text_rw, set_memory_rw等函数设置页表权限。

lookup_address查找页表入口。

offsetof获得结构体成员偏移。

@wbs0829
wbs0829 / generated_copy_or_move_operation.cpp
Last active April 16, 2016 02:01
某些情况编译器会生成类的copy或move操作
#include <iostream>
#include <typeinfo>
#include <type_traits>
class A {
};
class C {
public:
~C(){}
@wbs0829
wbs0829 / kernel_gdb_script_cause_loading_module_failure.md
Created April 16, 2016 03:23
内核gdb调试脚本导致模块加载失败

kernel gdb script causes loading module failure

(qemu) gdbserver

[host] $ gdb vmlinuz

(gdb) target remote :1234

(gdb) lx-symbols

@wbs0829
wbs0829 / .gdbinit
Last active April 19, 2020 13:16
gdb内核模块调试脚本
# change this according to build kernel source path
add-auto-load-safe-path /home/wambers/code/build-4.2.5-debug/src/linux-4.2.5
define dm
source ~/code/modules/add-module-symbol-file.py
source ~/code/modules/debug-module.gdb
connect-qemu
debug-module
end
@wbs0829
wbs0829 / make_initrd.sh
Created April 23, 2016 02:09
生成initrd
find . | cpio --quiet -R 0:0 -o -H newc) | gzip >initrd.gz