Building the kernel is simple. Just type
$ build
on the top directory of this repo.
To build the test code, type
$ sh test/build.sh test1.c
on the top directory. The executable will be located in "test" directory.
System call ptree[sys_ptree(380
)] is implemented using recursive strategy. The algorithm consists of three parts.
- Start with
init_task
, which is the initial task with pid 0. - Given a task, push it into the buffer
- Repeat
2 and 3
for every child process and halt.
Overall design is depicted in the diagram below.
To avoid using global variable and achieve better design, we used our own structure named SearchResult
to manage prinfo values. It's a basic implementation of array list.
struct SearchResult {
struct prinfo *data; // pointer to prinfo array
int max_size; // length of <data>
int count; // actual number of prinfo elements
};
- ํ๋ก์ ํธ๋ ์ญ์ ์ผ์ฐ ํ๋ ๊ฒ์ด ์ข๋ค.
- ์ปค๋ํจ๋์ ๊ณ ํต์ค๋ฝ์ง๋ง printk()์ ํจ๊ป๋ผ๋ฉด ๋๋ ต์ง ์๋ค.
- ์๊ฐ๋ฝ๋ถํฐ ์์ง์ฌ์ ์๋๊ณ ๋ฐ๋์ ๋จผ์ ์๊ฐํ๊ณ ์ฝ๋ฉํด์ผ ํ๋ค.
๋จผ์ ์ ์์ ์ผ๋ก artik ๋ถํ ํ๊ณ root๋ก ๋ก๊ทธ์ธ, ๋ค์ ์ปค๋งจ๋๋ฅผ ์ ๋ ฅ.
direct_set_debug.sh --sdb-set
์ฐ๋ถํฌ ํ๊ฒฝ์์ sdb root๋ก ์ ํ ํ push
sdb root on
push [์๋ณธํ์ผ] [destination]
echo 8 > /proc/sys/kernel/printk
์ด๋ ๊ฒ ํ๋ฉด ๋ชจ๋ ๋ฉ์์ง๊ฐ ์ฝ์์ ์ถ๋ ฅ๋จ
in file: "arch/arm/include/asm/unistd.h"
#define __NR_syscalls (N)
to
#define __NR_syscalls (N+4)
Total number of system calls must be a multiplication of 4.
in file: "arch/arm/include/uapi/asm/unistd.h" add
#define __NR_myfunc (__NR_SYSCALL_BASE+ #)
in file: "include/linux/syscalls.h"
asmlinkage int my_func() // if no parameter then write 'void'
in file: "arch/arm/kernel/calls.S"
call(sys_myfunc)
in file: "kernel/Makefile"
obj -y = ... ptree.o
in file: "kernel/myfunc.c"
the name of function must be sys_myfunc()