xv6 add a system call that counts system calls

大憨熊 提交于 2019-12-30 10:00:10

问题


EDIT:

GOT IT

here is what I did:

in syscall.c:

extern int numSysCalls;

in sysproc.c:

int numSysCalls = -1;

Okay, so I'm working on implementing an easy system call that returns the number of times a system call has been made. Seems easy, but I'm getting an error I don't understand...

Basically, here is what I did: in syscall.c there is a function called syscall() that checks whether it is a syscall or not. I have basically declared a variable and am incrementing it every time this function is called.

Var Declaration in syscall.c:

18: int16_t numSysCalls = -1; //global

Syscall() function:

115:  void syscall(void){
116:     numSysCalls++; 
...

Error I'm getting:

kernel/syscall.c:116: error: ‘numSysCalls’ undeclared (first use in this function)
kernel/syscall.c:116: error: (Each undeclared identifier is reported only once
kernel/syscall.c:116: error: for each function it appears in.)

Then, in sysproc.c, I have the same extern int and simply return the int when I call my function numCalls, as follows:

Extern Variable in sysproc.c:

extern int numSysCalls;

Method in question:

int sys_numSys(void){
if (numSysCalls == -1) return numSysCalls;
else return numSysCalls + 1;
}

In summary: numSysCalls should be incremented whenever a syscall (of any kind) is called - successful or not.

numSys only returns the number, or -1 if error.

来源:https://stackoverflow.com/questions/21653195/xv6-add-a-system-call-that-counts-system-calls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!