From 47c93d4cef1ce4a36cd7c05bda05279b84aa9d3d Mon Sep 17 00:00:00 2001 From: hinus Date: Fri, 30 Jul 2021 00:39:08 +0800 Subject: [PATCH] Title: System call 'brk' Issue: https://gitee.com/hinus/linux_kernel_011/issues/I42HQT Description: sys_brk and show sys_call index. --- include/linux/sys.h | 4 ++-- kernel/sys.c | 7 +++++++ kernel/sys_call.S | 9 +++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/linux/sys.h b/include/linux/sys.h index 0a65c9c..e2e4712 100644 --- a/include/linux/sys.h +++ b/include/linux/sys.h @@ -43,7 +43,7 @@ extern int sys_dup(); //extern int sys_pipe(); //extern int sys_times(); //extern int sys_prof(); -//extern int sys_brk(); +extern int sys_brk(); //extern int sys_setgid(); //extern int sys_getgid(); extern int sys_signal(); @@ -138,7 +138,7 @@ fn_ptr sys_call_table[] = { 0, // sys_pipe, 0, // sys_times, 0, // sys_prof, - 0, // sys_brk, + sys_brk, 0, // sys_setgid, 0, // sys_getgid, diff --git a/kernel/sys.c b/kernel/sys.c index 8c89258..c853687 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -20,6 +20,13 @@ int sys_ulimit() { return -ENOSYS; } +int sys_brk(unsigned long end_data_seg) { + if (end_data_seg >= current->end_code && + end_data_seg < current->start_stack - 16384) + current->brk = end_data_seg; + return current->brk; +} + int in_group_p(gid_t grp) { int i; if (grp == current->egid) diff --git a/kernel/sys_call.S b/kernel/sys_call.S index cb4298d..1f0ca52 100644 --- a/kernel/sys_call.S +++ b/kernel/sys_call.S @@ -20,6 +20,9 @@ OLDSS = 0x30 int_msg: .asciz "In kernel interrupt\n\r" +show_ind: + .asciz "sys call %d\n" + system_call: pushl %ds pushl %es @@ -34,6 +37,12 @@ system_call: movl $0x17, %edx movw %dx, %fs + pushl %eax + pushl $show_ind + call printk + popl %eax + popl %eax + call *sys_call_table(, %eax, 4) pushl %eax -- Gitee