4

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.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
katiea
  • 223
  • 1
  • 5
  • 19
  • is the extern visible from syscall.c? – suspectus Feb 08 '14 at 23:45
  • yes. See above edit. (I accidentally clipped the "extern" when I pasted here) – katiea Feb 08 '14 at 23:47
  • 1
    the definition is type int16_t and the extern is type int. – suspectus Feb 08 '14 at 23:52
  • Okay I changed the following: **extern int numSysCalls = -1;** to **extern int16_t numSysCalls = -1;** No cigar. Same error. – katiea Feb 08 '14 at 23:54
  • Basically, it would appear that syscall() isn't in the scope of the global variable - which it SHOULD be. I am not understanding the issue. numSysCalls is definitely in the global scope, and syscall() is not within any other function. – katiea Feb 08 '14 at 23:56
  • GOT IT here is what I did: in syscall.c: extern int numSysCalls; in sysproc.c: int numSysCalls = -1; – katiea Feb 09 '14 at 00:00
  • 1
    That should have been ok. Are you compiling these modules together or separately? Aha yes the types differed. That explains it! – suspectus Feb 09 '14 at 00:03
  • 2
    syscall.c would have required definition `int16_t numsysCalls` but compiler did not find it - the definition in sysproc.c was type int. – suspectus Feb 09 '14 at 00:06

0 Answers0