On Thu, Jul 07, 2011 at 07:41:13PM -0700, Matthew Dempsky wrote: > Shrinks an i386 kernel by 190 bytes!!
tedu@ suggested just moving sys_pipe() into sys_pipe.c and merging it with opipe(). ok? Index: kern/syscalls.master =================================================================== RCS file: /home/mdempsky/anoncvs/cvs/src/sys/kern/syscalls.master,v retrieving revision 1.111 diff -u -p -r1.111 syscalls.master --- kern/syscalls.master 7 Jul 2011 23:45:00 -0000 1.111 +++ kern/syscalls.master 8 Jul 2011 02:22:23 -0000 @@ -110,7 +110,7 @@ 39 STD { pid_t sys_getppid(void); } 40 OBSOL lstat43 41 STD { int sys_dup(int fd); } -42 STD { int sys_opipe(void); } +42 OBSOL opipe 43 STD { gid_t sys_getegid(void); } 44 STD { int sys_profil(caddr_t samples, size_t size, \ u_long offset, u_int scale); } Index: kern/sys_pipe.c =================================================================== RCS file: /home/mdempsky/anoncvs/cvs/src/sys/kern/sys_pipe.c,v retrieving revision 1.59 diff -u -p -r1.59 sys_pipe.c --- kern/sys_pipe.c 27 May 2011 08:53:15 -0000 1.59 +++ kern/sys_pipe.c 8 Jul 2011 04:48:36 -0000 @@ -101,12 +101,15 @@ int pipespace(struct pipe *, u_int); /* ARGSUSED */ int -sys_opipe(struct proc *p, void *v, register_t *retval) +sys_pipe(struct proc *p, void *v, register_t *retval) { + struct sys_pipe_args /* { + syscallarg(int *) fdp; + } */ *uap = v; struct filedesc *fdp = p->p_fd; struct file *rf, *wf; struct pipe *rpipe, *wpipe; - int fd, error; + int fds[2], error; fdplock(fdp); @@ -119,23 +122,21 @@ sys_opipe(struct proc *p, void *v, regis if (error != 0) goto free2; - error = falloc(p, &rf, &fd); + error = falloc(p, &rf, &fds[0]); if (error != 0) goto free2; rf->f_flag = FREAD | FWRITE; rf->f_type = DTYPE_PIPE; rf->f_data = rpipe; rf->f_ops = &pipeops; - retval[0] = fd; - error = falloc(p, &wf, &fd); + error = falloc(p, &wf, &fds[1]); if (error != 0) goto free3; wf->f_flag = FREAD | FWRITE; wf->f_type = DTYPE_PIPE; wf->f_data = wpipe; wf->f_ops = &pipeops; - retval[1] = fd; rpipe->pipe_peer = wpipe; wpipe->pipe_peer = rpipe; @@ -144,10 +145,18 @@ sys_opipe(struct proc *p, void *v, regis FILE_SET_MATURE(wf); fdpunlock(fdp); - return (0); + + error = copyout(fds, SCARG(uap, fdp), sizeof(fds)); + if (error != 0) { + fdplock(fdp); + fdrelease(p, fds[0]); + fdrelease(p, fds[1]); + fdpunlock(fdp); + } + return (error); free3: - fdremove(fdp, retval[0]); + fdremove(fdp, fds[0]); closef(rf, p); rpipe = NULL; free2: Index: kern/uipc_syscalls.c =================================================================== RCS file: /home/mdempsky/anoncvs/cvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.79 diff -u -p -r1.79 uipc_syscalls.c --- kern/uipc_syscalls.c 4 Apr 2011 12:44:10 -0000 1.79 +++ kern/uipc_syscalls.c 8 Jul 2011 04:48:28 -0000 @@ -886,30 +886,6 @@ out: return (error); } -int -sys_pipe(struct proc *p, void *v, register_t *retval) -{ - struct sys_pipe_args /* { - syscallarg(int *) fdp; - } */ *uap = v; - int error, fds[2]; - register_t rval[2]; - - if ((error = sys_opipe(p, v, rval)) != 0) - return (error); - - fds[0] = rval[0]; - fds[1] = rval[1]; - error = copyout(fds, SCARG(uap, fdp), 2 * sizeof (int)); - if (error) { - fdplock(p->p_fd); - fdrelease(p, fds[0]); - fdrelease(p, fds[1]); - fdpunlock(p->p_fd); - } - return (error); -} - /* * Get socket name. */ Index: compat/linux/syscalls.master =================================================================== RCS file: /home/mdempsky/anoncvs/cvs/src/sys/compat/linux/syscalls.master,v retrieving revision 1.57 diff -u -p -r1.57 syscalls.master --- compat/linux/syscalls.master 7 Jul 2011 06:15:47 -0000 1.57 +++ compat/linux/syscalls.master 8 Jul 2011 02:36:29 -0000 @@ -97,7 +97,7 @@ 39 STD { int linux_sys_mkdir(char *path, int mode); } 40 STD { int linux_sys_rmdir(char *path); } 41 NOARGS { int sys_dup(u_int fd); } -42 STD { int linux_sys_pipe(int *pfds); } +42 NOARGS { int sys_pipe(int *fdp); } 43 STD { int linux_sys_times(struct times *tms); } 44 STD { int linux_sys_prof(void); } 45 STD { int linux_sys_brk(char *nsize); } Index: compat/linux/linux_misc.c =================================================================== RCS file: /home/mdempsky/anoncvs/cvs/src/sys/compat/linux/linux_misc.c,v retrieving revision 1.69 diff -u -p -r1.69 linux_misc.c --- compat/linux/linux_misc.c 7 Jul 2011 01:19:39 -0000 1.69 +++ compat/linux/linux_misc.c 8 Jul 2011 02:30:46 -0000 @@ -765,52 +765,6 @@ linux_sys_times(p, v, retval) } /* - * OpenBSD passes fd[0] in retval[0], and fd[1] in retval[1]. - * Linux directly passes the pointer. - */ -int -linux_sys_pipe(p, v, retval) - struct proc *p; - void *v; - register_t *retval; -{ - struct linux_sys_pipe_args /* { - syscallarg(int *) pfds; - } */ *uap = v; - int error; - int pfds[2]; -#ifdef __i386__ - int reg_edx = retval[1]; -#endif /* __i386__ */ - - if ((error = sys_opipe(p, 0, retval))) { -#ifdef __i386__ - retval[1] = reg_edx; -#endif /* __i386__ */ - return error; - } - - /* Assumes register_t is an int */ - - pfds[0] = retval[0]; - pfds[1] = retval[1]; - if ((error = copyout(pfds, SCARG(uap, pfds), 2 * sizeof (int)))) { -#ifdef __i386__ - retval[1] = reg_edx; -#endif /* __i386__ */ - fdrelease(p, retval[0]); - fdrelease(p, retval[1]); - return error; - } - - retval[0] = 0; -#ifdef __i386__ - retval[1] = reg_edx; -#endif /* __i386__ */ - return 0; -} - -/* * Alarm. This is a libc call which uses setitimer(2) in OpenBSD. * Fiddle with the timers to make it work. */