Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Add getsockopt2() syscall.



details:   https://anonhg.NetBSD.org/src/rev/aa3097b4d8ab
branches:  trunk
changeset: 363511:aa3097b4d8ab
user:      rjs <rjs%NetBSD.org@localhost>
date:      Tue Jul 31 13:00:13 2018 +0000

description:
Add getsockopt2() syscall.

diffstat:

 sys/kern/syscalls.master |   5 +-
 sys/kern/uipc_syscalls.c |  74 +++++++++++++++++++++++++++++++----------------
 2 files changed, 51 insertions(+), 28 deletions(-)

diffs (141 lines):

diff -r a83eea72acd6 -r aa3097b4d8ab sys/kern/syscalls.master
--- a/sys/kern/syscalls.master  Tue Jul 31 10:31:02 2018 +0000
+++ b/sys/kern/syscalls.master  Tue Jul 31 13:00:13 2018 +0000
@@ -1,4 +1,4 @@
-       $NetBSD: syscalls.master,v 1.292 2018/07/12 10:46:48 maxv Exp $
+       $NetBSD: syscalls.master,v 1.293 2018/07/31 13:00:13 rjs Exp $
 
 ;      @(#)syscalls.master     8.2 (Berkeley) 1/13/94
 
@@ -411,7 +411,8 @@
                            struct stat12 *ub); } lstat12
 191    STD     RUMP    { long|sys||pathconf(const char *path, int name); }
 192    STD     RUMP    { long|sys||fpathconf(int fd, int name); }
-193    UNIMPL
+193    STD     RUMP    { int|sys||getsockopt2(int s, int level, int name, \
+                           void *val, socklen_t *avalsize); }
 194    STD     RUMP    { int|sys||getrlimit(int which, \
                            struct rlimit *rlp); }
 195    STD     RUMP    { int|sys||setrlimit(int which, \
diff -r a83eea72acd6 -r aa3097b4d8ab sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c  Tue Jul 31 10:31:02 2018 +0000
+++ b/sys/kern/uipc_syscalls.c  Tue Jul 31 13:00:13 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_syscalls.c,v 1.194 2018/05/04 08:47:55 christos Exp $     */
+/*     $NetBSD: uipc_syscalls.c,v 1.195 2018/07/31 13:00:13 rjs Exp $  */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.194 2018/05/04 08:47:55 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.195 2018/07/31 13:00:13 rjs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pipe.h"
@@ -1192,17 +1192,10 @@
        return error;
 }
 
-int
-sys_getsockopt(struct lwp *l, const struct sys_getsockopt_args *uap,
-    register_t *retval)
+static int
+getsockopt(struct lwp *l, const struct sys_getsockopt_args *uap,
+    register_t *retval, bool copyarg)
 {
-       /* {
-               syscallarg(int)                 s;
-               syscallarg(int)                 level;
-               syscallarg(int)                 name;
-               syscallarg(void *)              val;
-               syscallarg(unsigned int *)      avalsize;
-       } */
        struct sockopt  sopt;
        struct socket   *so;
        file_t          *fp;
@@ -1216,39 +1209,68 @@
        } else
                valsize = 0;
 
-       if ((error = fd_getsock1(SCARG(uap, s), &so, &fp)) != 0)
-               return (error);
-
        if (valsize > MCLBYTES)
                return EINVAL;
 
+       if ((error = fd_getsock1(SCARG(uap, s), &so, &fp)) != 0)
+               return error;
+
        sockopt_init(&sopt, SCARG(uap, level), SCARG(uap, name), valsize);
+       if (copyarg && valsize > 0) {
+               error = copyin(SCARG(uap, val), sopt.sopt_data, valsize);
+               if (error)
+                       goto out;
+       }
 
        if (fp->f_flag & FNOSIGPIPE)
                so->so_options |= SO_NOSIGPIPE;
        else
                so->so_options &= ~SO_NOSIGPIPE;
+
        error = sogetopt(so, &sopt);
+       if (error || valsize == 0)
+               goto out;
+
+       len = min(valsize, sopt.sopt_retsize);
+       error = copyout(sopt.sopt_data, SCARG(uap, val), len);
        if (error)
                goto out;
 
-       if (valsize > 0) {
-               len = min(valsize, sopt.sopt_retsize);
-               error = copyout(sopt.sopt_data, SCARG(uap, val), len);
-               if (error)
-                       goto out;
-
-               error = copyout(&len, SCARG(uap, avalsize), sizeof(len));
-               if (error)
-                       goto out;
-       }
-
+       error = copyout(&len, SCARG(uap, avalsize), sizeof(len));
  out:
        sockopt_destroy(&sopt);
        fd_putfile(SCARG(uap, s));
        return error;
 }
 
+int
+sys_getsockopt(struct lwp *l, const struct sys_getsockopt_args *uap,
+    register_t *retval)
+{
+       /* {
+               syscallarg(int)                 s;
+               syscallarg(int)                 level;
+               syscallarg(int)                 name;
+               syscallarg(void *)              val;
+               syscallarg(unsigned int *)      avalsize;
+       } */
+       return getsockopt(l, uap, retval, false);
+}
+
+int
+sys_getsockopt2(struct lwp *l, const struct sys_getsockopt2_args *uap,
+    register_t *retval)
+{
+       /* {
+               syscallarg(int)                 s;
+               syscallarg(int)                 level;
+               syscallarg(int)                 name;
+               syscallarg(void *)              val;
+               syscallarg(unsigned int *)      avalsize;
+       } */
+       return getsockopt(l, (const struct sys_getsockopt_args *) uap, retval, true);
+}
+
 #ifdef PIPE_SOCKETPAIR
 
 int



Home | Main Index | Thread Index | Old Index