Compare commits
3 commits
master
...
add_sys_ca
Author | SHA1 | Date | |
---|---|---|---|
f920fb924f | |||
e30698ad64 | |||
bcef224332 |
8 changed files with 25 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -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
5
proc.c
|
@ -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
2
proc.h
|
@ -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:
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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
|
||||||
|
|
11
sysproc.c
11
sysproc.c
|
@ -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
1
user.h
|
@ -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
1
usys.S
|
@ -29,3 +29,4 @@ SYSCALL(getpid)
|
||||||
SYSCALL(sbrk)
|
SYSCALL(sbrk)
|
||||||
SYSCALL(sleep)
|
SYSCALL(sleep)
|
||||||
SYSCALL(uptime)
|
SYSCALL(uptime)
|
||||||
|
SYSCALL(getcount)
|
||||||
|
|
Loading…
Reference in a new issue