Compare commits

..

3 commits

Author SHA1 Message Date
f920fb924f Enable getcount userspace test application 2015-03-16 23:41:04 +05:30
e30698ad64 Add getcount system call
This patch enables the getcount systemcall functionality.
2015-03-16 23:39:50 +05:30
bcef224332 proc: Add getcount() systemcall
This patch adds information to the core process structures for enabling
the getcount() systemcall. This systemcall when passed a valid
systemcall number as an argument, will return the number of times the
referenced systemcall was invoked by the calling process.
2015-03-16 23:32:07 +05:30
8 changed files with 25 additions and 1 deletions

View file

@ -167,7 +167,7 @@ UPROGS=\
_wc\ _wc\
_zombie\ _zombie\
_bigtest\ _bigtest\
#_getcount\ _getcount\
fs.img: mkfs README $(UPROGS) fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS) ./mkfs fs.img README $(UPROGS)

5
proc.c
View file

@ -36,6 +36,7 @@ allocproc(void)
{ {
struct proc *p; struct proc *p;
char *sp; char *sp;
int i;
acquire(&ptable.lock); acquire(&ptable.lock);
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) for(p = ptable.proc; p < &ptable.proc[NPROC]; p++)
@ -70,6 +71,10 @@ found:
memset(p->context, 0, sizeof *p->context); memset(p->context, 0, sizeof *p->context);
p->context->eip = (uint)forkret; p->context->eip = (uint)forkret;
// Initialise the syscall count array entries with 0
for (i = 0; i < NO_OF_SYSCALLS; i++)
p->syscall_count[i] = 0;
return p; return p;
} }

2
proc.h
View file

@ -1,5 +1,6 @@
// Segments in proc->gdt. // Segments in proc->gdt.
#define NSEGS 7 #define NSEGS 7
#define NO_OF_SYSCALLS 22
// Per-CPU state // Per-CPU state
struct cpu { struct cpu {
@ -66,6 +67,7 @@ struct proc {
struct file *ofile[NOFILE]; // Open files struct file *ofile[NOFILE]; // Open files
struct inode *cwd; // Current directory struct inode *cwd; // Current directory
char name[16]; // Process name (debugging) char name[16]; // Process name (debugging)
uint syscall_count[NO_OF_SYSCALLS]; // Number of particular syscalls
}; };
// Process memory is laid out contiguously, low addresses first: // Process memory is laid out contiguously, low addresses first:

View file

@ -98,6 +98,7 @@ extern int sys_unlink(void);
extern int sys_wait(void); extern int sys_wait(void);
extern int sys_write(void); extern int sys_write(void);
extern int sys_uptime(void); extern int sys_uptime(void);
extern int sys_getcount(void);
static int (*syscalls[])(void) = { static int (*syscalls[])(void) = {
[SYS_fork] sys_fork, [SYS_fork] sys_fork,
@ -121,6 +122,7 @@ static int (*syscalls[])(void) = {
[SYS_link] sys_link, [SYS_link] sys_link,
[SYS_mkdir] sys_mkdir, [SYS_mkdir] sys_mkdir,
[SYS_close] sys_close, [SYS_close] sys_close,
[SYS_getcount] sys_getcount,
}; };
void void
@ -130,6 +132,7 @@ syscall(void)
num = proc->tf->eax; num = proc->tf->eax;
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
proc->syscall_count[num]++;
proc->tf->eax = syscalls[num](); proc->tf->eax = syscalls[num]();
} else { } else {
cprintf("%d %s: unknown sys call %d\n", cprintf("%d %s: unknown sys call %d\n",

View file

@ -20,3 +20,4 @@
#define SYS_link 19 #define SYS_link 19
#define SYS_mkdir 20 #define SYS_mkdir 20
#define SYS_close 21 #define SYS_close 21
#define SYS_getcount 22

View file

@ -88,3 +88,14 @@ sys_uptime(void)
release(&tickslock); release(&tickslock);
return xticks; return xticks;
} }
int
sys_getcount(void)
{
int n;
if(argint(0, &n) < 0)
return -1;
return proc->syscall_count[n];
}

1
user.h
View file

@ -22,6 +22,7 @@ int getpid(void);
char* sbrk(int); char* sbrk(int);
int sleep(int); int sleep(int);
int uptime(void); int uptime(void);
int getcount(int);
// ulib.c // ulib.c
int stat(char*, struct stat*); int stat(char*, struct stat*);

1
usys.S
View file

@ -29,3 +29,4 @@ SYSCALL(getpid)
SYSCALL(sbrk) SYSCALL(sbrk)
SYSCALL(sleep) SYSCALL(sleep)
SYSCALL(uptime) SYSCALL(uptime)
SYSCALL(getcount)