Index: emulation/linux/linux_socket.c
===================================================================
RCS file: /nfs/daver/cvs-repos/cvs-dragonflybsd/src/sys/emulation/linux/linux_socket.c,v
retrieving revision 1.9
diff -u -r1.9 linux_socket.c
--- emulation/linux/linux_socket.c	6 Sep 2003 20:36:42 -0000	1.9
+++ emulation/linux/linux_socket.c	6 Sep 2003 23:44:34 -0000
@@ -42,9 +42,9 @@
 #include <sys/sysproto.h>
 #include <sys/fcntl.h>
 #include <sys/file.h>
+#include <sys/kern_syscall.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
-#include <sys/syscall1.h>
 #include <sys/uio.h>
 #include <sys/malloc.h>
 
@@ -442,7 +442,7 @@
 	if (error)
 		return (error);
 
-	error = bind1(linux_args.s, sa);
+	error = kern_bind(linux_args.s, sa);
 	FREE(sa, M_SONAME);
 
 	return (error);
@@ -476,7 +476,7 @@
 	if (error)
 		return (error);
 
-	error = connect1(linux_args.s, sa);
+	error = kern_connect(linux_args.s, sa);
 	FREE(sa, M_SONAME);
 
 	if (error != EISCONN)
@@ -556,7 +556,7 @@
 		if (error)
 			return (error);
 
-		error = accept1(linux_args.s, &sa, &sa_len, res);
+		error = kern_accept(linux_args.s, &sa, &sa_len, res);
 
 		if (error) {
 			/*
@@ -580,7 +580,7 @@
 		if (sa)
 			FREE(sa, M_SONAME);
 	} else {
-		error = accept1(linux_args.s, NULL, 0, res);
+		error = kern_accept(linux_args.s, NULL, 0, res);
 	}
 
 	if (error)
Index: kern/uipc_syscalls.c
===================================================================
RCS file: /nfs/daver/cvs-repos/cvs-dragonflybsd/src/sys/kern/uipc_syscalls.c,v
retrieving revision 1.12
diff -u -r1.12 uipc_syscalls.c
--- kern/uipc_syscalls.c	6 Sep 2003 20:34:35 -0000	1.12
+++ kern/uipc_syscalls.c	7 Sep 2003 00:03:44 -0000
@@ -52,12 +52,12 @@
 #include <sys/fcntl.h>
 #include <sys/file.h>
 #include <sys/filio.h>
+#include <sys/kern_syscall.h>
 #include <sys/mbuf.h>
 #include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/signalvar.h>
-#include <sys/syscall1.h>
 #include <sys/uio.h>
 #include <sys/vnode.h>
 #include <sys/lock.h>
@@ -80,8 +80,6 @@
 static int recvit(int s, struct msghdr *mp, caddr_t namelenp, int *res);
   
 static int do_sendfile(struct sendfile_args *uap, int compat);
-static int getsockname1(struct getsockname_args *uap, int compat);
-static int getpeername1(struct getpeername_args *uap, int compat);
 
 static SLIST_HEAD(, sf_buf) sf_freelist;
 static vm_offset_t sf_base;
@@ -135,7 +133,7 @@
 }
 
 int
-bind1(int s, struct sockaddr *sa)
+kern_bind(int s, struct sockaddr *sa)
 {
 	struct thread *td = curthread;
 	struct proc *p = td->td_proc;
@@ -163,18 +161,14 @@
 	error = getsockaddr(&sa, uap->name, uap->namelen);
 	if (error)
 		return (error);
-	error = bind1(uap->s, sa);
+	error = kern_bind(uap->s, sa);
 	FREE(sa, M_SONAME);
 
 	return (error);
 }
 
-/*
- * listen_args(int s, int backlog)
- */
-/* ARGSUSED */
 int
-listen(struct listen_args *uap)
+kern_listen(int s, int backlog)
 {
 	struct thread *td = curthread;
 	struct proc *p = td->td_proc;
@@ -182,22 +176,34 @@
 	int error;
 
 	KKASSERT(p);
-	error = holdsock(p->p_fd, uap->s, &fp);
+	error = holdsock(p->p_fd, s, &fp);
 	if (error)
 		return (error);
-	error = solisten((struct socket *)fp->f_data, uap->backlog, td);
+	error = solisten((struct socket *)fp->f_data, backlog, td);
 	fdrop(fp, td);
 	return(error);
 }
 
 /*
- * The second argument to accept1() is a handle to a struct sockaddr.
- * This allows accept1() to return a pointer to an allocated struct
+ * listen_args(int s, int backlog)
+ */
+int
+listen(struct listen_args *uap)
+{
+	int error;
+
+	error = kern_listen(uap->s, uap->backlog);
+	return (error);
+}
+
+/*
+ * The second argument to kern_accept() is a handle to a struct sockaddr.
+ * This allows kern_accept() to return a pointer to an allocated struct
  * sockaddr which must be freed later with FREE().  The caller must
  * initialize *name to NULL.
  */
 int
-accept1(int s, struct sockaddr **name, int *namelen, int *res)
+kern_accept(int s, struct sockaddr **name, int *namelen, int *res)
 {
 	struct thread *td = curthread;
 	struct proc *p = td->td_proc;
@@ -352,7 +358,7 @@
 		if (error)
 			return (error);
 
-		error = accept1(uap->s, &sa, &sa_len, &uap->sysmsg_result);
+		error = kern_accept(uap->s, &sa, &sa_len, &uap->sysmsg_result);
 
 		if (error == 0)
 			error = copyout(sa, uap->name, sa_len);
@@ -363,7 +369,7 @@
 		if (sa)
 			FREE(sa, M_SONAME);
 	} else {
-		error = accept1(uap->s, NULL, 0, &uap->sysmsg_result);
+		error = kern_accept(uap->s, NULL, 0, &uap->sysmsg_result);
 	}
 	return (error);
 }
@@ -381,7 +387,7 @@
 		if (error)
 			return (error);
 
-		error = accept1(uap->s, &sa, &sa_len, &uap->sysmsg_result);
+		error = kern_accept(uap->s, &sa, &sa_len, &uap->sysmsg_result);
 
 		if (error) {
 			/*
@@ -404,14 +410,14 @@
 		if (sa)
 			FREE(sa, M_SONAME);
 	} else {
-		error = accept1(uap->s, NULL, 0, &uap->sysmsg_result);
+		error = kern_accept(uap->s, NULL, 0, &uap->sysmsg_result);
 	}
 	return (error);
 }
 #endif /* COMPAT_OLDSOCK */
 
 int
-connect1(int s, struct sockaddr *sa)
+kern_connect(int s, struct sockaddr *sa)
 {
 	struct thread *td = curthread;
 	struct proc *p = td->td_proc;
@@ -466,31 +472,28 @@
 	error = getsockaddr(&sa, uap->name, uap->namelen);
 	if (error)
 		return (error);
-	error = connect1(uap->s, sa);
+	error = kern_connect(uap->s, sa);
 	FREE(sa, M_SONAME);
 
 	return (error);
 }
 
-/*
- * socketpair(int domain, int type, int protocol, int *rsv)
- */
 int
-socketpair(struct socketpair_args *uap)
+kern_socketpair(int domain, int type, int protocol, int *sv)
 {
 	struct thread *td = curthread;
 	struct proc *p = td->td_proc;
 	struct filedesc *fdp;
 	struct file *fp1, *fp2;
 	struct socket *so1, *so2;
-	int fd, error, sv[2];
+	int fd, error;
 
 	KKASSERT(p);
 	fdp = p->p_fd;
-	error = socreate(uap->domain, &so1, uap->type, uap->protocol, td);
+	error = socreate(domain, &so1, type, protocol, td);
 	if (error)
 		return (error);
-	error = socreate(uap->domain, &so2, uap->type, uap->protocol, td);
+	error = socreate(domain, &so2, type, protocol, td);
 	if (error)
 		goto free1;
 	error = falloc(p, &fp1, &fd);
@@ -508,7 +511,7 @@
 	error = soconnect2(so1, so2);
 	if (error)
 		goto free4;
-	if (uap->type == SOCK_DGRAM) {
+	if (type == SOCK_DGRAM) {
 		/*
 		 * Datagram socket connection is asymmetric.
 		 */
@@ -519,7 +522,6 @@
 	fp1->f_flag = fp2->f_flag = FREAD|FWRITE;
 	fp1->f_ops = fp2->f_ops = &socketops;
 	fp1->f_type = fp2->f_type = DTYPE_SOCKET;
-	error = copyout((caddr_t)sv, (caddr_t)uap->rsv, 2 * sizeof (int));
 	fdrop(fp1, td);
 	fdrop(fp2, td);
 	return (error);
@@ -542,6 +544,21 @@
 	return (error);
 }
 
+/*
+ * socketpair(int domain, int type, int protocol, int *rsv)
+ */
+int
+socketpair(struct socketpair_args *uap)
+{
+	int error, sockv[2];
+
+	error = kern_socketpair(uap->domain, uap->type, uap->protocol, sockv);
+
+	if (error == 0)
+		error = copyout(sockv, uap->rsv, sizeof(sockv));
+	return (error);
+}
+
 static int
 sendit(int s, struct msghdr *mp, int flags, int *res)
 {
@@ -1170,147 +1187,191 @@
 }
 
 /*
- * getsockname_args(int fdes, caddr_t asa, int *alen)
- *
- * Get socket name.
+ * The second argument to kern_getsockname() is a handle to a struct sockaddr.
+ * This allows kern_getsockname() to return a pointer to an allocated struct
+ * sockaddr which must be freed later with FREE().  The caller must
+ * initialize *name to NULL.
  */
-/* ARGSUSED */
-static int
-getsockname1(struct getsockname_args *uap, int compat)
+int
+kern_getsockname(int s, struct sockaddr **name, int *namelen)
 {
 	struct thread *td = curthread;
 	struct proc *p = td->td_proc;
 	struct file *fp;
 	struct socket *so;
-	struct sockaddr *sa;
-	int len, error;
+	struct sockaddr *sa = NULL;
+	int error;
 
-	error = holdsock(p->p_fd, uap->fdes, &fp);
+	error = holdsock(p->p_fd, s, &fp);
 	if (error)
 		return (error);
-	error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len));
-	if (error) {
-		fdrop(fp, td);
-		return (error);
-	}
-	if (len < 0) {
+	if (*namelen < 0) {
 		fdrop(fp, td);
 		return (EINVAL);
 	}
 	so = (struct socket *)fp->f_data;
-	sa = 0;
 	error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, &sa);
-	if (error)
-		goto bad;
-	if (sa == 0) {
-		len = 0;
-		goto gotnothing;
+	if (error == 0) {
+		if (sa == 0) {
+			*namelen = 0;
+		} else {
+			*namelen = MIN(*namelen, sa->sa_len);
+			*name = sa;
+		}
 	}
 
-	len = MIN(len, sa->sa_len);
-#ifdef COMPAT_OLDSOCK
-	if (compat)
-		((struct osockaddr *)sa)->sa_family = sa->sa_family;
-#endif
-	error = copyout(sa, (caddr_t)uap->asa, (u_int)len);
-	if (error == 0)
-gotnothing:
-		error = copyout((caddr_t)&len, (caddr_t)uap->alen,
-		    sizeof (len));
-bad:
-	if (sa)
-		FREE(sa, M_SONAME);
 	fdrop(fp, td);
 	return (error);
 }
 
+/*
+ * getsockname_args(int fdes, caddr_t asa, int *alen)
+ *
+ * Get socket name.
+ */
 int
 getsockname(struct getsockname_args *uap)
 {
+	struct sockaddr *sa = NULL;
+	int error, sa_len;
+
+	error = copyin(uap->alen, &sa_len, sizeof(sa_len));
+	if (error)
+		return (error);
+
+	error = kern_getsockname(uap->fdes, &sa, &sa_len);
 
-	return (getsockname1(uap, 0));
+	if (error == 0)
+		error = copyout(sa, uap->asa, sa_len);
+	if (error == 0)
+		error = copyout(&sa_len, uap->alen, sizeof(*uap->alen));
+	if (sa)
+		FREE(sa, M_SONAME);
+	return (error);
 }
 
 #ifdef COMPAT_OLDSOCK
 int
 ogetsockname(struct getsockname_args *uap)
 {
+	struct sockaddr *sa = NULL;
+	int error, sa_len;
 
-	return (getsockname1(uap, 1));
+	error = copyin(uap->alen, &sa_len, sizeof(sa_len));
+	if (error)
+		return (error);
+
+	error = kern_getsockname(uap->fdes, &sa, &sa_len);
+
+	if (error == 0) {
+		/*
+		 * Convert sa to the 4.3BSD sockaddr structure.
+		 */
+		((struct osockaddr *)sa)->sa_family = sa->sa_family;
+		error = copyout(sa, uap->asa, sa_len);
+	}
+	if (error == 0) {
+		error = copyout(&sa_len, uap->alen, sizeof(*uap->alen));
+	}
+	if (sa)
+		FREE(sa, M_SONAME);
+	return (error);
 }
 #endif /* COMPAT_OLDSOCK */
 
 /*
- * getpeername_args(int fdes, caddr_t asa, int *alen)
- *
- * Get name of peer for connected socket.
+ * The second argument to kern_getpeername() is a handle to a struct sockaddr.
+ * This allows kern_getpeername() to return a pointer to an allocated struct
+ * sockaddr which must be freed later with FREE().  The caller must
+ * initialize *name to NULL.
  */
-/* ARGSUSED */
-static int
-getpeername1(struct getpeername_args *uap, int compat)
+int
+kern_getpeername(int s, struct sockaddr **name, int *namelen)
 {
 	struct thread *td = curthread;
 	struct proc *p = td->td_proc;
 	struct file *fp;
 	struct socket *so;
-	struct sockaddr *sa;
-	int len, error;
+	struct sockaddr *sa = NULL;
+	int error;
 
-	error = holdsock(p->p_fd, uap->fdes, &fp);
+	error = holdsock(p->p_fd, s, &fp);
 	if (error)
 		return (error);
+	if (*namelen < 0) {
+		fdrop(fp, td);
+		return (EINVAL);
+	}
 	so = (struct socket *)fp->f_data;
 	if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) {
 		fdrop(fp, td);
 		return (ENOTCONN);
 	}
-	error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len));
-	if (error) {
-		fdrop(fp, td);
-		return (error);
-	}
-	if (len < 0) {
-		fdrop(fp, td);
-		return (EINVAL);
-	}
-	sa = 0;
 	error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, &sa);
-	if (error)
-		goto bad;
-	if (sa == 0) {
-		len = 0;
-		goto gotnothing;
+	if (error == 0) {
+		if (sa == 0) {
+			*namelen = 0;
+		} else {
+			*namelen = MIN(*namelen, sa->sa_len);
+			*name = sa;
+		}
 	}
-	len = MIN(len, sa->sa_len);
-#ifdef COMPAT_OLDSOCK
-	if (compat)
-		((struct osockaddr *)sa)->sa_family =
-		    sa->sa_family;
-#endif
-	error = copyout(sa, (caddr_t)uap->asa, (u_int)len);
-	if (error)
-		goto bad;
-gotnothing:
-	error = copyout((caddr_t)&len, (caddr_t)uap->alen, sizeof (len));
-bad:
-	if (sa)
-		FREE(sa, M_SONAME);
+
 	fdrop(fp, td);
 	return (error);
 }
 
+/*
+ * getpeername_args(int fdes, caddr_t asa, int *alen)
+ *
+ * Get name of peer for connected socket.
+ */
 int
 getpeername(struct getpeername_args *uap)
 {
-	return (getpeername1(uap, 0));
+	struct sockaddr *sa = NULL;
+	int error, sa_len;
+
+	error = copyin(uap->alen, &sa_len, sizeof(sa_len));
+	if (error)
+		return (error);
+
+	error = kern_getpeername(uap->fdes, &sa, &sa_len);
+
+	if (error == 0)
+		error = copyout(sa, uap->asa, sa_len);
+	if (error == 0)
+		error = copyout(&sa_len, uap->alen, sizeof(*uap->alen));
+	if (sa)
+		FREE(sa, M_SONAME);
+	return (error);
 }
 
 #ifdef COMPAT_OLDSOCK
 int
 ogetpeername(struct ogetpeername_args *uap)
 {
-	/* XXX uap should have type `getpeername_args *' to begin with. */
-	return (getpeername1((struct getpeername_args *)uap, 1));
+	struct sockaddr *sa = NULL;
+	int error, sa_len;
+
+	error = copyin(uap->alen, &sa_len, sizeof(sa_len));
+	if (error)
+		return (error);
+
+	error = kern_getpeername(uap->fdes, &sa, &sa_len);
+
+	if (error == 0) {
+		/*
+		 * Convert sa to the 4.3BSD sockaddr structure.
+		 */
+		((struct osockaddr *)sa)->sa_family = sa->sa_family;
+		error = copyout(sa, uap->asa, sa_len);
+	}
+	if (error == 0)
+		error = copyout(&sa_len, uap->alen, sizeof(*uap->alen));
+	if (sa)
+		FREE(sa, M_SONAME);
+	return (error);
 }
 #endif /* COMPAT_OLDSOCK */
 
Index: sys/kern_syscall.h
===================================================================
RCS file: sys/kern_syscall.h
diff -N sys/kern_syscall.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sys/kern_syscall.h	6 Sep 2003 23:40:08 -0000
@@ -0,0 +1,44 @@
+/*
+ * KERN_SYSCALL.H	- Split syscall prototypes
+ *
+ * Copyright (c) 2003 David P. Reese, Jr. <daver@gomerbud.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $DragonFly$
+ */
+
+#ifndef _SYS_KERN_SYSCALL_H_
+#define _SYS_KERN_SYSCALL_H_
+
+struct sockaddr;
+
+int kern_accept(int s, struct sockaddr **name, int *namelen, int *res);
+int kern_bind(int s, struct sockaddr *sa);
+int kern_connect(int s, struct sockaddr *sa);
+int kern_listen(int s, int backlog);
+int kern_getpeername(int s, struct sockaddr **name, int *namelen);
+int kern_getsockname(int s, struct sockaddr **name, int *namelen);
+int kern_socketpair(int domain, int type, int protocol, int *sockv);
+
+#endif /* !_SYS_KERN_SYSCALL_H_ */
Index: sys/syscall1.h
===================================================================
RCS file: sys/syscall1.h
diff -N sys/syscall1.h
--- sys/syscall1.h	6 Sep 2003 22:45:08 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,40 +0,0 @@
-/*
- * SYSCALL1.H	- Split syscall prototypes
- *
- * Copyright (c) 2003 David P. Reese, Jr. <daver@gomerbud.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $DragonFly: src/sys/sys/syscall1.h,v 1.1 2003/09/06 22:45:08 dillon Exp $
- */
-
-#ifndef _SYS_SYSCALL1_H_
-#define _SYS_SYSCALL1_H_
-
-struct sockaddr;
-
-int accept1(int s, struct sockaddr **name, int *namelen, int *res);
-int bind1(int s, struct sockaddr *sa);
-int connect1(int s, struct sockaddr *sa);
-
-#endif /* !_SYS_SYSCALL1_H_ */

