Compare commits

...

3 Commits

Author SHA1 Message Date
Sanchayan Maity f920fb924f Enable getcount userspace test application 2015-03-16 23:41:04 +05:30
Sanchayan Maity e30698ad64 Add getcount system call
This patch enables the getcount systemcall functionality.
2015-03-16 23:39:50 +05:30
Sanchayan Maity 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\
_zombie\
_bigtest\
#_getcount\
_getcount\
fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)

5
proc.c
View File

@ -36,6 +36,7 @@ allocproc(void)
{
struct proc *p;
char *sp;
int i;
acquire(&ptable.lock);
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++)
@ -70,6 +71,10 @@ found:
memset(p->context, 0, sizeof *p->context);
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;
}

2
proc.h
View File

@ -1,5 +1,6 @@
// Segments in proc->gdt.
#define NSEGS 7
#define NO_OF_SYSCALLS 22
// Per-CPU state
struct cpu {
@ -66,6 +67,7 @@ struct proc {
struct file *ofile[NOFILE]; // Open files
struct inode *cwd; // Current directory
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:

View File

@ -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",

View File

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

View File

@ -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];
}

1
user.h
View File

@ -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*);

1
usys.S
View File

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