Untitled
unknown
plain_text
9 months ago
1.5 kB
18
Indexable
void syscall(void)
{
int num;
struct proc *p = myproc();
num = p->trapframe->a7;
if (num > 0 && num < NELEM(syscalls) && syscalls[num])
{
uint64 arg0 = p->trapframe->a0; // Save first argument BEFORE syscall dispatch
p->trapframe->a0 = syscalls[num](); // Use num to lookup the system call function for num, call it, and store its return value in p->trapframe->a0
if (p->traced)
{
// Print syscall name, first argument
printf( "[pid %d] %s(", p->pid, syscall_names[num] );
if (num == SYS_open || num == SYS_unlink ||
num == SYS_chdir || num == SYS_mkdir || num == SYS_link
/* ignore the second string argument of `link` */)
{
// If the syscall is one of these five...
char buf[128];
if ( argstr( 0, buf, sizeof( buf ) ) >= 0 ) {
printf( "\"%s\"", buf );
}
else {
printf( "\?\"" );
}
}
else if ( num == SYS_exec ){
// If the syscall is exec...
char buf[128];
if (argstr(0, buf, sizeof(buf)) >= 0)
printf("exec(\"%s\")", buf);
else
printf("\"?\"");
}
else
{
// If the syscall is any of the others...
printf("%d", (int)arg0);
}
// Print the remaining part.
printf(") = %d\n", (int)arg0);
}
}
else
{
printf("%d %s: unknown sys call %d\n",
p->pid, p->name, num);
p->trapframe->a0 = -1;
}
}Editor is loading...
Leave a Comment