From e30698ad64809cebbe8fcebf28dd586b68480d91 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Mon, 16 Mar 2015 23:39:50 +0530 Subject: [PATCH] Add getcount system call This patch enables the getcount systemcall functionality. --- syscall.c | 3 +++ syscall.h | 1 + sysproc.c | 11 +++++++++++ user.h | 1 + usys.S | 1 + 5 files changed, 17 insertions(+) diff --git a/syscall.c b/syscall.c index 799ebc2..97e07ec 100644 --- a/syscall.c +++ b/syscall.c @@ -98,6 +98,7 @@ extern int sys_unlink(void); extern int sys_wait(void); extern int sys_write(void); extern int sys_uptime(void); +extern int sys_getcount(void); static int (*syscalls[])(void) = { [SYS_fork] sys_fork, @@ -121,6 +122,7 @@ static int (*syscalls[])(void) = { [SYS_link] sys_link, [SYS_mkdir] sys_mkdir, [SYS_close] sys_close, +[SYS_getcount] sys_getcount, }; void @@ -130,6 +132,7 @@ syscall(void) num = proc->tf->eax; if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { + proc->syscall_count[num]++; proc->tf->eax = syscalls[num](); } else { cprintf("%d %s: unknown sys call %d\n", diff --git a/syscall.h b/syscall.h index bc5f356..6f0a59c 100644 --- a/syscall.h +++ b/syscall.h @@ -20,3 +20,4 @@ #define SYS_link 19 #define SYS_mkdir 20 #define SYS_close 21 +#define SYS_getcount 22 diff --git a/sysproc.c b/sysproc.c index c66339e..e8cc051 100644 --- a/sysproc.c +++ b/sysproc.c @@ -88,3 +88,14 @@ sys_uptime(void) release(&tickslock); return xticks; } + +int +sys_getcount(void) +{ + int n; + + if(argint(0, &n) < 0) + return -1; + + return proc->syscall_count[n]; +} diff --git a/user.h b/user.h index 9e26cf1..96ed8cf 100644 --- a/user.h +++ b/user.h @@ -22,6 +22,7 @@ int getpid(void); char* sbrk(int); int sleep(int); int uptime(void); +int getcount(int); // ulib.c int stat(char*, struct stat*); diff --git a/usys.S b/usys.S index 8bfd8a1..3cdc17e 100644 --- a/usys.S +++ b/usys.S @@ -29,3 +29,4 @@ SYSCALL(getpid) SYSCALL(sbrk) SYSCALL(sleep) SYSCALL(uptime) +SYSCALL(getcount)