From bfbf9682fe38c3b29e51913464674770869c6970 Mon Sep 17 00:00:00 2001 From: hinus Date: Tue, 17 Aug 2021 11:35:46 +0800 Subject: [PATCH] Title: System call getgroups Issue: https://gitee.com/hinus/linux_kernel_011/issues/I45YA6 Description: System call getgroups LTT: rm --- include/asm/segment.h | 2 ++ include/linux/sys.h | 4 ++-- include/unistd.h | 1 + kernel/printk.c | 2 +- kernel/segment.c | 4 ++++ kernel/sys.c | 15 +++++++++++++++ 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/asm/segment.h b/include/asm/segment.h index faf0d1b..fe41e78 100644 --- a/include/asm/segment.h +++ b/include/asm/segment.h @@ -5,6 +5,8 @@ inline unsigned char get_fs_byte(const char * addr); inline void put_fs_byte(char val,char *addr); +inline void put_fs_word(short val, short * addr) ; + inline unsigned long get_fs_long(const unsigned long *addr) ; inline void put_fs_long(unsigned long val,unsigned long * addr) ; diff --git a/include/linux/sys.h b/include/linux/sys.h index b5b5dcc..b341c0e 100644 --- a/include/linux/sys.h +++ b/include/linux/sys.h @@ -78,7 +78,7 @@ extern int sys_sigaction(); //extern int sys_getrusage(); extern int sys_gettimeofday(); //extern int sys_settimeofday(); -//extern int sys_getgroups(); +extern int sys_getgroups(); //extern int sys_setgroups(); //extern int sys_select(); //extern int sys_symlink(); @@ -177,7 +177,7 @@ fn_ptr sys_call_table[] = { 0, // sys_getrusage, sys_gettimeofday, 0, // sys_settimeofday, - 0, // sys_getgroups, + sys_getgroups, 0, // sys_setgroups, 0, // sys_select, 0, // sys_symlink, diff --git a/include/unistd.h b/include/unistd.h index de15641..ced7413 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -161,6 +161,7 @@ int execve(const char * filename, char ** argv, char ** envp); int fcntl(int fildes, int cmd, ...); int fork(); int fstat(); +int getgroups(int gidsetlen, gid_t *gidset); int gettimeofday(struct timeval *tv, struct timezone *tz); int setup(void *BIOS); int sync(); diff --git a/kernel/printk.c b/kernel/printk.c index 17ddc4d..c6f8510 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -31,7 +31,7 @@ int printk(const char* fmt, ...) { void print_sys(int index) { int i; - int filter[] = {3, 4, 5, 6, 18, 29, 45, 48, 54}; + int filter[] = {3, 4, 5, 6, 18, 29, 45, 48, 54, 80}; for (i = 0; i < sizeof(filter) / sizeof(int); i++) { if (index == filter[i]) diff --git a/kernel/segment.c b/kernel/segment.c index 35b9414..54dd69e 100644 --- a/kernel/segment.c +++ b/kernel/segment.c @@ -10,6 +10,10 @@ inline void put_fs_byte(char val,char *addr) { __asm__ ("movb %0,%%fs:%1"::"r" (val),"m" (*addr)); } +inline void put_fs_word(short val, short *addr) { + __asm__ ("movw %0,%%fs:%1"::"r" (val),"m" (*addr)); +} + inline unsigned long get_fs_long(const unsigned long *addr) { unsigned long _v; __asm__ ("movl %%fs:%1,%0":"=r" (_v):"m" (*addr)); diff --git a/kernel/sys.c b/kernel/sys.c index 09e4480..b0b89b8 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -130,6 +130,21 @@ int sys_ulimit() { return -ENOSYS; } +int sys_getgroups(int gidsetsize, gid_t *grouplist) { + int i; + if (gidsetsize) + verify_area(grouplist, sizeof(gid_t) * gidsetsize); + for (i = 0; (i < NGROUPS) && (current->groups[i] != NOGROUP); + i++, grouplist++) { + if (gidsetsize) { + if (i >= gidsetsize) + return -EINVAL; + put_fs_word(current->groups[i], (short *) grouplist); + } + } + return i; +} + int sys_brk(unsigned long end_data_seg) { if (end_data_seg >= current->end_code && end_data_seg < current->start_stack - 16384) -- Gitee