The output of the following code is just "hello!", which is confusing because when I do make qemu to start xv6 everything compiles well, but obviously something goes wrong with the function getiocounts.
I am new to sys calls, so there might be something obvios I'm missing. Please help! Thank you!
#include "types.h"
#include "stat.h"
#include "user.h"
#include "iostat.h"
int main(int argc, char** argv) {
struct iostat* io;
io =(struct iostat* ) malloc(sizeof(int)*2);
int r=0;
printf(1, "hello!");
printf(1, "%d", getiocounts(io));
r = io->readcount;
printf(1, "hello!");
printf(1, "%d", r);
exit();
}
int sys_getiocounts( struct iostat* io){
if(argptr(1, (void*)&io, sizeof(*io)) < 0)
return -1;
io->readcount = myproc()->r;
io->writecount = myproc()->w;
return 0;
}
CodePudding user response:
Some mistakes in your kernel code:
- Your system call is not correctly defined: its parameters prototype should be
(void)
- Your parameter reading is wrong: you must read the first parameter:
argptr( 0, ...
int sys_getiocounts( void ){
struct iostat* io;
if(argptr(0, (void*) &io, sizeof *io) < 0)
return -1;
io->readcount = myproc()->r;
io->writecount = myproc()->w;
return 0;
}
And your user code could be cleaner on the allocation:
struct iostat* io = malloc(sizeof *io );
....
getiocounts(io);
or even without allocation:
struct iostat io;
...
getiocounts(&io);