/snucse_os

๐Ÿ—ฝ 2017๋…„ ๋ด„ํ•™๊ธฐ ์šด์˜์ฒด์ œ ํ”„๋กœ์ ํŠธ

Primary LanguageCOtherNOASSERTION

os-team20

How to Build

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.

High-Level Design & Implementation

System call ptree[sys_ptree(380)] is implemented using recursive strategy. The algorithm consists of three parts.

  1. Start with init_task, which is the initial task with pid 0.
  2. Given a task, push it into the buffer
  3. 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
};

Lessons Learned

  • ํ”„๋กœ์ ํŠธ๋Š” ์—ญ์‹œ ์ผ์ฐ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.
  • ์ปค๋„ํŒจ๋‹‰์€ ๊ณ ํ†ต์Šค๋Ÿฝ์ง€๋งŒ printk()์™€ ํ•จ๊ป˜๋ผ๋ฉด ๋‘๋ ต์ง€ ์•Š๋‹ค.
  • ์†๊ฐ€๋ฝ๋ถ€ํ„ฐ ์›€์ง์—ฌ์„  ์•ˆ๋˜๊ณ  ๋ฐ˜๋“œ์‹œ ๋จผ์ € ์ƒ๊ฐํ•˜๊ณ  ์ฝ”๋”ฉํ•ด์•ผ ํ•œ๋‹ค.

์ž์ฃผ ์“ฐ๋Š” ์ปค๋งจ๋“œ

SDB ์‚ฌ์šฉํ•˜๋Š” ๋ฒ•

๋จผ์ € ์ •์ƒ์ ์œผ๋กœ artik ๋ถ€ํŒ…ํ•˜๊ณ  root๋กœ ๋กœ๊ทธ์ธ, ๋‹ค์Œ ์ปค๋งจ๋“œ๋ฅผ ์ž…๋ ฅ.

direct_set_debug.sh --sdb-set

์šฐ๋ถ„ํˆฌ ํ™˜๊ฒฝ์—์„œ sdb root๋กœ ์ „ํ™˜ ํ›„ push

sdb root on
push [์›๋ณธํŒŒ์ผ] [destination]

printk ์ถœ๋ ฅ ๋ ˆ๋ฒจ ๋ณ€๊ฒฝ

echo 8 > /proc/sys/kernel/printk

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ชจ๋“  ๋ฉ”์‹œ์ง€๊ฐ€ ์ฝ˜์†”์— ์ถœ๋ ฅ๋จ

How To Register System Call

1. Increment the number of System calls

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.

2. assign system call number

in file: "arch/arm/include/uapi/asm/unistd.h" add

#define __NR_myfunc      (__NR_SYSCALL_BASE+ #) 

3. make asmlinkage function

in file: "include/linux/syscalls.h"

asmlinkage int my_func()  // if no parameter then write 'void' 

4. add to system call table

in file: "arch/arm/kernel/calls.S"

call(sys_myfunc)

5. Revise Makefile

in file: "kernel/Makefile"

obj -y = ...  ptree.o

etc.

in file: "kernel/myfunc.c"
the name of function must be sys_myfunc()