tech-kern archive

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

Re: New getsockopt2() syscall



On Jun 24, 11:18pm, rjs%fdy2.co.uk@localhost (Robert Swindells) wrote:
-- Subject: Re: New getsockopt2() syscall

How about merging them thusly?

christos

Index: uipc_syscalls.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_syscalls.c,v
retrieving revision 1.194
diff -u -p -u -r1.194 uipc_syscalls.c
--- uipc_syscalls.c	4 May 2018 08:47:55 -0000	1.194
+++ uipc_syscalls.c	24 Jun 2018 23:28:14 -0000
@@ -1192,18 +1192,10 @@ sys_setsockopt(struct lwp *l, const stru
 	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;
 	unsigned int	valsize, len;
@@ -1217,38 +1209,69 @@ sys_getsockopt(struct lwp *l, const stru
 		valsize = 0;
 
 	if ((error = fd_getsock1(SCARG(uap, s), &so, &fp)) != 0)
-		return (error);
+		return error;
 
 	if (valsize > MCLBYTES)
 		return EINVAL;
 
 	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)
+	if (error || valsize == 0)
 		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;
-	}
+	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;
  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, uap, retval, true);
+}
+
 #ifdef PIPE_SOCKETPAIR
 
 int


Home | Main Index | Thread Index | Old Index