Module Name: src Committed By: riastradh Date: Fri Dec 6 18:44:00 UTC 2024
Modified Files: src/sys/kern: sys_socket.c uipc_accf.c uipc_domain.c uipc_mbuf.c uipc_sem.c uipc_socket.c uipc_socket2.c uipc_syscalls.c uipc_usrreq.c Log Message: sys/kern/sys_socket.c, uipc_*.c: Sprinkle SET_ERROR dtrace probes. PR kern/58378: Kernel error code origination lacks dtrace probes To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 src/sys/kern/sys_socket.c cvs rdiff -u -r1.15 -r1.16 src/sys/kern/uipc_accf.c cvs rdiff -u -r1.110 -r1.111 src/sys/kern/uipc_domain.c cvs rdiff -u -r1.253 -r1.254 src/sys/kern/uipc_mbuf.c cvs rdiff -u -r1.61 -r1.62 src/sys/kern/uipc_sem.c cvs rdiff -u -r1.312 -r1.313 src/sys/kern/uipc_socket.c cvs rdiff -u -r1.145 -r1.146 src/sys/kern/uipc_socket2.c cvs rdiff -u -r1.213 -r1.214 src/sys/kern/uipc_syscalls.c cvs rdiff -u -r1.205 -r1.206 src/sys/kern/uipc_usrreq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/sys_socket.c diff -u src/sys/kern/sys_socket.c:1.83 src/sys/kern/sys_socket.c:1.84 --- src/sys/kern/sys_socket.c:1.83 Fri Dec 6 18:36:47 2024 +++ src/sys/kern/sys_socket.c Fri Dec 6 18:44:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_socket.c,v 1.83 2024/12/06 18:36:47 riastradh Exp $ */ +/* $NetBSD: sys_socket.c,v 1.84 2024/12/06 18:44:00 riastradh Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.83 2024/12/06 18:36:47 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.84 2024/12/06 18:44:00 riastradh Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -73,6 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_socket.c #include <sys/poll.h> #include <sys/proc.h> #include <sys/protosw.h> +#include <sys/sdt.h> #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/stat.h> @@ -279,7 +280,7 @@ soo_fpathconf(struct file *fp, int name, *retval = PIPE_BUF; return 0; default: - return EINVAL; + return SET_ERROR(EINVAL); } } @@ -287,5 +288,5 @@ static int soo_posix_fadvise(struct file *fp, off_t offset, off_t len, int advice) { - return ESPIPE; + return SET_ERROR(ESPIPE); } Index: src/sys/kern/uipc_accf.c diff -u src/sys/kern/uipc_accf.c:1.15 src/sys/kern/uipc_accf.c:1.16 --- src/sys/kern/uipc_accf.c:1.15 Fri Dec 6 18:36:47 2024 +++ src/sys/kern/uipc_accf.c Fri Dec 6 18:44:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_accf.c,v 1.15 2024/12/06 18:36:47 riastradh Exp $ */ +/* $NetBSD: uipc_accf.c,v 1.16 2024/12/06 18:44:00 riastradh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_accf.c,v 1.15 2024/12/06 18:36:47 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_accf.c,v 1.16 2024/12/06 18:44:00 riastradh Exp $"); #define ACCEPT_FILTER_MOD @@ -76,6 +76,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_accf.c, #include <sys/protosw.h> #include <sys/queue.h> #include <sys/rwlock.h> +#include <sys/sdt.h> #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/sysctl.h> @@ -118,7 +119,7 @@ accept_filt_add(struct accept_filter *fi LIST_FOREACH(p, &accept_filtlsthd, accf_next) { if (strcmp(p->accf_name, filt->accf_name) == 0) { rw_exit(&accept_filter_lock); - return EEXIST; + return SET_ERROR(EEXIST); } } LIST_INSERT_HEAD(&accept_filtlsthd, filt, accf_next); @@ -134,7 +135,7 @@ accept_filt_del(struct accept_filter *p) rw_enter(&accept_filter_lock, RW_WRITER); if (p->accf_refcnt != 0) { rw_exit(&accept_filter_lock); - return EBUSY; + return SET_ERROR(EBUSY); } LIST_REMOVE(p, accf_next); rw_exit(&accept_filter_lock); @@ -208,11 +209,11 @@ accept_filt_getopt(struct socket *so, st KASSERT(solocked(so)); if ((so->so_options & SO_ACCEPTCONN) == 0) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto out; } if ((so->so_options & SO_ACCEPTFILTER) == 0) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto out; } @@ -239,7 +240,7 @@ accept_filt_clear(struct socket *so) KASSERT(solocked(so)); if ((so->so_options & SO_ACCEPTCONN) == 0) { - return EINVAL; + return SET_ERROR(EINVAL); } if (so->so_accf != NULL) { /* Break in-flight processing. */ @@ -304,7 +305,7 @@ accept_filt_setopt(struct socket *so, co afp = accept_filt_get(afa.af_name); if (afp == NULL) { solock(so); - return ENOENT; + return SET_ERROR(ENOENT); } /* * Allocate the new accept filter instance storage. We may @@ -333,7 +334,7 @@ accept_filt_setopt(struct socket *so, co */ solock(so); if ((so->so_options & SO_ACCEPTCONN) == 0 || so->so_accf != NULL) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto out; } @@ -346,7 +347,7 @@ accept_filt_setopt(struct socket *so, co newaf->so_accept_filter_arg = (*afp->accf_create)(so, afa.af_arg); if (newaf->so_accept_filter_arg == NULL) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto out; } } Index: src/sys/kern/uipc_domain.c diff -u src/sys/kern/uipc_domain.c:1.110 src/sys/kern/uipc_domain.c:1.111 --- src/sys/kern/uipc_domain.c:1.110 Fri Dec 6 18:36:31 2024 +++ src/sys/kern/uipc_domain.c Fri Dec 6 18:44:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_domain.c,v 1.110 2024/12/06 18:36:31 riastradh Exp $ */ +/* $NetBSD: uipc_domain.c,v 1.111 2024/12/06 18:44:00 riastradh Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_domain.c,v 1.110 2024/12/06 18:36:31 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_domain.c,v 1.111 2024/12/06 18:44:00 riastradh Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_domain. #include <sys/proc.h> #include <sys/protosw.h> #include <sys/queue.h> +#include <sys/sdt.h> #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/sysctl.h> @@ -563,14 +564,14 @@ sysctl_unpcblist(SYSCTLFN_ARGS) return sysctl_query(SYSCTLFN_CALL(rnode)); if (namelen != 4) - return EINVAL; + return SET_ERROR(EINVAL); if (oldp != NULL) { len = *oldlenp; elem_size = name[2]; elem_count = name[3]; if (elem_size != sizeof(pcb)) - return EINVAL; + return SET_ERROR(EINVAL); } else { len = 0; elem_size = sizeof(pcb); @@ -582,7 +583,7 @@ sysctl_unpcblist(SYSCTLFN_ARGS) needed = 0; if (name - oname != 4) - return EINVAL; + return SET_ERROR(EINVAL); pf = oname[1]; type = oname[2]; @@ -593,7 +594,7 @@ sysctl_unpcblist(SYSCTLFN_ARGS) sysctl_unlock(); if ((dfp = fgetdummy()) == NULL) { sysctl_relock(); - return ENOMEM; + return SET_ERROR(ENOMEM); } /* Index: src/sys/kern/uipc_mbuf.c diff -u src/sys/kern/uipc_mbuf.c:1.253 src/sys/kern/uipc_mbuf.c:1.254 --- src/sys/kern/uipc_mbuf.c:1.253 Fri Dec 6 18:36:31 2024 +++ src/sys/kern/uipc_mbuf.c Fri Dec 6 18:44:00 2024 @@ -1,5 +1,5 @@ -/* $NetBSD: uipc_mbuf.c,v 1.253 2024/12/06 18:36:31 riastradh Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.254 2024/12/06 18:44:00 riastradh Exp $ */ /* * Copyright (c) 1999, 2001, 2018 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.253 2024/12/06 18:36:31 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.254 2024/12/06 18:44:00 riastradh Exp $"); #ifdef _KERNEL_OPT #include "ether.h" @@ -84,6 +84,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c, #include <sys/pool.h> #include <sys/proc.h> #include <sys/protosw.h> +#include <sys/sdt.h> #include <sys/socket.h> #include <sys/sysctl.h> #include <sys/syslog.h> @@ -296,21 +297,21 @@ sysctl_kern_mbuf(SYSCTLFN_ARGS) newval = nmbclusters_limit(); break; default: - return EOPNOTSUPP; + return SET_ERROR(EOPNOTSUPP); } error = sysctl_lookup(SYSCTLFN_CALL(&node)); if (error || newp == NULL) return error; if (newval < 0) - return EINVAL; + return SET_ERROR(EINVAL); switch (node.sysctl_num) { case MBUF_NMBCLUSTERS: if (newval < nmbclusters) - return EINVAL; + return SET_ERROR(EINVAL); if (newval > nmbclusters_limit()) - return EINVAL; + return SET_ERROR(EINVAL); nmbclusters = newval; pool_cache_sethardlimit(mcl_cache, nmbclusters, mclpool_warnmsg, 60); @@ -361,9 +362,9 @@ sysctl_kern_mbuf_mowners(SYSCTLFN_ARGS) int error = 0; if (namelen != 0) - return EINVAL; + return SET_ERROR(EINVAL); if (newp != NULL) - return EPERM; + return SET_ERROR(EPERM); LIST_FOREACH(mo, &mowners, mo_link) { struct mowner_user mo_user; @@ -372,7 +373,7 @@ sysctl_kern_mbuf_mowners(SYSCTLFN_ARGS) if (oldp != NULL) { if (*oldlenp - len < sizeof(mo_user)) { - error = ENOMEM; + error = SET_ERROR(ENOMEM); break; } error = copyout(&mo_user, (char *)oldp + len, @@ -1716,7 +1717,7 @@ out: return 0; enobufs: - return ENOBUFS; + return SET_ERROR(ENOBUFS); } /* Index: src/sys/kern/uipc_sem.c diff -u src/sys/kern/uipc_sem.c:1.61 src/sys/kern/uipc_sem.c:1.62 --- src/sys/kern/uipc_sem.c:1.61 Fri Dec 6 18:36:31 2024 +++ src/sys/kern/uipc_sem.c Fri Dec 6 18:44:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_sem.c,v 1.61 2024/12/06 18:36:31 riastradh Exp $ */ +/* $NetBSD: uipc_sem.c,v 1.62 2024/12/06 18:44:00 riastradh Exp $ */ /*- * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.61 2024/12/06 18:36:31 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.62 2024/12/06 18:44:00 riastradh Exp $"); #include <sys/param.h> #include <sys/types.h> @@ -80,6 +80,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v #include <sys/mutex.h> #include <sys/proc.h> #include <sys/rwlock.h> +#include <sys/sdt.h> #include <sys/semaphore.h> #include <sys/stat.h> #include <sys/syscall.h> @@ -256,7 +257,7 @@ ksem_sysfini(bool interface) if (nsems_total) { error = syscall_establish(NULL, ksem_syscalls); KASSERT(error == 0); - return EBUSY; + return SET_ERROR(EBUSY); } } kauth_unlisten_scope(ksem_listener); @@ -279,7 +280,7 @@ ksem_modcmd(modcmd_t cmd, void *arg) return ksem_sysfini(true); default: - return ENOTTY; + return SET_ERROR(ENOTTY); } } @@ -307,7 +308,7 @@ ksem_perm(lwp_t *l, ksem_t *ks) KASSERT(mutex_owned(&ks->ks_lock)); if (kauth_authorize_system(uc, KAUTH_SYSTEM_SEMAPHORE, 0, ks, NULL, NULL) != 0) - return EACCES; + return SET_ERROR(EACCES); return 0; } @@ -407,7 +408,7 @@ ksem_get(intptr_t id, ksem_t **ksret, in */ ks = ksem_lookup_pshared(id); if (ks == NULL) - return EINVAL; + return SET_ERROR(EINVAL); KASSERT(ks->ks_pshared_id == id); KASSERT(ks->ks_pshared_proc != NULL); fd = -1; @@ -416,16 +417,16 @@ ksem_get(intptr_t id, ksem_t **ksret, in file_t *fp = fd_getfile(fd); if (__predict_false(fp == NULL)) - return EINVAL; + return SET_ERROR(EINVAL); if (__predict_false(fp->f_type != DTYPE_SEM)) { fd_putfile(fd); - return EINVAL; + return SET_ERROR(EINVAL); } ks = fp->f_ksem; mutex_enter(&ks->ks_lock); ks->ks_ref++; } else { - return EINVAL; + return SET_ERROR(EINVAL); } *ksret = ks; @@ -446,21 +447,21 @@ ksem_create(lwp_t *l, const char *name, /* Pre-check for the limit. */ if (nsems >= ksem_max) { - return ENFILE; + return SET_ERROR(ENFILE); } if (val > SEM_VALUE_MAX) { - return EINVAL; + return SET_ERROR(EINVAL); } if (name != NULL) { len = strlen(name); if (len > SEM_MAX_NAMELEN) { - return ENAMETOOLONG; + return SET_ERROR(ENAMETOOLONG); } /* Name must start with a '/' but not contain one. */ if (*name != '/' || len < 2 || strchr(name + 1, '/') != NULL) { - return EINVAL; + return SET_ERROR(EINVAL); } kname = kmem_alloc(++len, KM_SLEEP); strlcpy(kname, name, len); @@ -588,7 +589,7 @@ do_ksem_init(lwp_t *l, u_int val, intptr * would be bad. */ fd_abort(p, fp, fd); - return EMFILE; + return SET_ERROR(EMFILE); } /* Note the mode does not matter for anonymous semaphores. */ @@ -666,7 +667,7 @@ do_ksem_open(struct lwp *l, const char * * would be bad. */ fd_abort(p, fp, fd); - return EMFILE; + return SET_ERROR(EMFILE); } /* @@ -699,7 +700,7 @@ do_ksem_open(struct lwp *l, const char * /* Check for exclusive create. */ if (oflag & O_EXCL) { mutex_exit(&ks->ks_lock); - error = EEXIST; + error = SET_ERROR(EEXIST); goto err; } /* @@ -719,14 +720,14 @@ do_ksem_open(struct lwp *l, const char * if ((oflag & O_CREAT) == 0) { mutex_exit(&ksem_lock); KASSERT(ksnew == NULL); - error = ENOENT; + error = SET_ERROR(ENOENT); goto err; } /* Check for the limit locked. */ if (nsems >= ksem_max) { mutex_exit(&ksem_lock); - error = ENFILE; + error = SET_ERROR(ENFILE); goto err; } @@ -773,7 +774,7 @@ sys__ksem_close(struct lwp *l, const str /* This is only for named semaphores. */ if (ks->ks_name == NULL) { - error = EINVAL; + error = SET_ERROR(EINVAL); } ksem_release(ks, -1); if (error) { @@ -873,7 +874,7 @@ sys__ksem_unlink(struct lwp *l, const st name_destroy(&name); if (ks == NULL) { mutex_exit(&ksem_lock); - return ENOENT; + return SET_ERROR(ENOENT); } KASSERT(mutex_owned(&ks->ks_lock)); @@ -919,7 +920,7 @@ sys__ksem_post(struct lwp *l, const stru } KASSERT(mutex_owned(&ks->ks_lock)); if (ks->ks_value == SEM_VALUE_MAX) { - error = EOVERFLOW; + error = SET_ERROR(EOVERFLOW); goto out; } ks->ks_value++; @@ -952,7 +953,7 @@ do_ksem_wait(lwp_t *l, intptr_t id, bool } else { timeo = 0; } - error = try_p ? EAGAIN : cv_timedwait_sig(&ks->ks_cv, + error = try_p ? SET_ERROR(EAGAIN) : cv_timedwait_sig(&ks->ks_cv, &ks->ks_lock, timeo); ks->ks_waiters--; if (error) @@ -991,11 +992,11 @@ sys__ksem_timedwait(struct lwp *l, const return error; if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= 1000000000) - return EINVAL; + return SET_ERROR(EINVAL); error = do_ksem_wait(l, SCARG(uap, id), false, &ts); if (error == EWOULDBLOCK) - error = ETIMEDOUT; + error = SET_ERROR(ETIMEDOUT); return error; } @@ -1053,12 +1054,12 @@ sys__ksem_destroy(struct lwp *l, const s /* Operation is only for unnamed semaphores. */ if (ks->ks_name != NULL) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto out; } /* Cannot destroy if there are waiters. */ if (ks->ks_waiters) { - error = EBUSY; + error = SET_ERROR(EBUSY); goto out; } if (KSEM_ID_IS_PSHARED(id)) { @@ -1066,7 +1067,7 @@ sys__ksem_destroy(struct lwp *l, const s KASSERT(fd == -1); KASSERT(ks->ks_pshared_proc != NULL); if (ks->ks_pshared_proc != curproc) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto out; } fd = ks->ks_pshared_fd; Index: src/sys/kern/uipc_socket.c diff -u src/sys/kern/uipc_socket.c:1.312 src/sys/kern/uipc_socket.c:1.313 --- src/sys/kern/uipc_socket.c:1.312 Fri Dec 6 18:36:47 2024 +++ src/sys/kern/uipc_socket.c Fri Dec 6 18:44:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.312 2024/12/06 18:36:47 riastradh Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.313 2024/12/06 18:44:00 riastradh Exp $ */ /* * Copyright (c) 2002, 2007, 2008, 2009, 2023 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.312 2024/12/06 18:36:47 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.313 2024/12/06 18:44:00 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -103,6 +103,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_socket. #include <sys/proc.h> #include <sys/protosw.h> #include <sys/resourcevar.h> +#include <sys/sdt.h> #include <sys/signalvar.h> #include <sys/socket.h> #include <sys/socketvar.h> @@ -510,16 +511,16 @@ socreate(int dom, struct socket **aso, i if (prp == NULL) { /* no support for domain */ if (pffinddomain(dom) == 0) - return EAFNOSUPPORT; + return SET_ERROR(EAFNOSUPPORT); /* no support for socket type */ if (proto == 0 && type != 0) - return EPROTOTYPE; - return EPROTONOSUPPORT; + return SET_ERROR(EPROTOTYPE); + return SET_ERROR(EPROTONOSUPPORT); } if (prp->pr_usrreqs == NULL) - return EPROTONOSUPPORT; + return SET_ERROR(EPROTONOSUPPORT); if (prp->pr_type != type) - return EPROTOTYPE; + return SET_ERROR(EPROTOTYPE); so = soget(true); so->so_type = type; @@ -640,7 +641,7 @@ sobind(struct socket *so, struct sockadd solock(so); if (nam->sa_family != so->so_proto->pr_domain->dom_family) { sounlock(so); - return EAFNOSUPPORT; + return SET_ERROR(EAFNOSUPPORT); } error = (*so->so_proto->pr_usrreqs->pr_bind)(so, nam, l); sounlock(so); @@ -657,7 +658,7 @@ solisten(struct socket *so, int backlog, if ((so->so_state & (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) != 0) { sounlock(so); - return EINVAL; + return SET_ERROR(EINVAL); } oldopt = so->so_options; oldqlimit = so->so_qlimit; @@ -821,7 +822,7 @@ soaccept(struct socket *so, struct socka (so->so_proto->pr_flags & PR_ABRTACPTDIS) == 0) error = (*so->so_proto->pr_usrreqs->pr_accept)(so, nam); else - error = ECONNABORTED; + error = SET_ERROR(ECONNABORTED); return error; } @@ -834,7 +835,7 @@ soconnect(struct socket *so, struct sock KASSERT(solocked(so)); if (so->so_options & SO_ACCEPTCONN) - return EOPNOTSUPP; + return SET_ERROR(EOPNOTSUPP); /* * If protocol is connection-based, can only connect once. * Otherwise, if connected, try to disconnect first. @@ -844,10 +845,10 @@ soconnect(struct socket *so, struct sock if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) && ((so->so_proto->pr_flags & PR_CONNREQUIRED) || (error = sodisconnect(so)))) { - error = EISCONN; + error = SET_ERROR(EISCONN); } else { if (nam->sa_family != so->so_proto->pr_domain->dom_family) { - return EAFNOSUPPORT; + return SET_ERROR(EAFNOSUPPORT); } error = (*so->so_proto->pr_usrreqs->pr_connect)(so, nam, l); } @@ -871,9 +872,9 @@ sodisconnect(struct socket *so) KASSERT(solocked(so)); if ((so->so_state & SS_ISCONNECTED) == 0) { - error = ENOTCONN; + error = SET_ERROR(ENOTCONN); } else if (so->so_state & SS_ISDISCONNECTING) { - error = EALREADY; + error = SET_ERROR(EALREADY); } else { error = (*so->so_proto->pr_usrreqs->pr_disconnect)(so); } @@ -929,7 +930,7 @@ sosend(struct socket *so, struct sockadd * causes us to loop sending 0-length segments to the protocol. */ if (resid < 0) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto out; } dontroute = @@ -943,11 +944,11 @@ sosend(struct socket *so, struct sockadd goto out; do { if (so->so_state & SS_CANTSENDMORE) { - error = EPIPE; + error = SET_ERROR(EPIPE); goto release; } if (so->so_error) { - error = so->so_error; + error = SET_ERROR(so->so_error); if ((flags & MSG_PEEK) == 0) so->so_error = 0; goto release; @@ -955,11 +956,11 @@ sosend(struct socket *so, struct sockadd if ((so->so_state & SS_ISCONNECTED) == 0) { if (so->so_proto->pr_flags & PR_CONNREQUIRED) { if (resid || clen == 0) { - error = ENOTCONN; + error = SET_ERROR(ENOTCONN); goto release; } } else if (addr == NULL) { - error = EDESTADDRREQ; + error = SET_ERROR(EDESTADDRREQ); goto release; } } @@ -968,18 +969,18 @@ sosend(struct socket *so, struct sockadd space += 1024; if ((atomic && resid > so->so_snd.sb_hiwat) || clen > so->so_snd.sb_hiwat) { - error = EMSGSIZE; + error = SET_ERROR(EMSGSIZE); goto release; } if (space < resid + clen && (atomic || space < so->so_snd.sb_lowat || space < clen)) { if ((so->so_state & SS_NBIO) || (flags & MSG_NBIO)) { - error = EWOULDBLOCK; + error = SET_ERROR(EWOULDBLOCK); goto release; } sbunlock(&so->so_snd); if (wakeup_state & SS_RESTARTSYS) { - error = ERESTART; + error = SET_ERROR(ERESTART); goto out; } error = sbwait(&so->so_snd); @@ -1065,7 +1066,7 @@ sosend(struct socket *so, struct sockadd } while (space > 0 && atomic); if (so->so_state & SS_CANTSENDMORE) { - error = EPIPE; + error = SET_ERROR(EPIPE); goto release; } if (dontroute) @@ -1247,7 +1248,7 @@ restart: if (m != NULL) goto dontblock; e = so->so_error ? &so->so_error : &so->so_rerror; - error = *e; + error = SET_ERROR(*e); if ((flags & MSG_PEEK) == 0) *e = 0; goto release; @@ -1265,21 +1266,21 @@ restart: } if ((so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING)) == 0 && (so->so_proto->pr_flags & PR_CONNREQUIRED)) { - error = ENOTCONN; + error = SET_ERROR(ENOTCONN); goto release; } if (uio->uio_resid == 0) goto release; if ((so->so_state & SS_NBIO) || (flags & (MSG_DONTWAIT|MSG_NBIO))) { - error = EWOULDBLOCK; + error = SET_ERROR(EWOULDBLOCK); goto release; } SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 1"); SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 1"); sbunlock(&so->so_rcv); if (wakeup_state & SS_RESTARTSYS) - error = ERESTART; + error = SET_ERROR(ERESTART); else error = sbwait(&so->so_rcv); if (error != 0) { @@ -1608,7 +1609,7 @@ dontblock: SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2"); SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2"); if (wakeup_state & SS_RESTARTSYS) - error = ERESTART; + error = SET_ERROR(ERESTART); else error = sbwait(&so->so_rcv); if (error != 0) { @@ -1672,7 +1673,7 @@ soshutdown(struct socket *so, int how) pr = so->so_proto; if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR)) - return EINVAL; + return SET_ERROR(EINVAL); if (how == SHUT_RD || how == SHUT_RDWR) { sorflush(so); @@ -1759,7 +1760,7 @@ sosetopt1(struct socket *so, const struc break; if (l.l_linger < 0 || l.l_linger > USHRT_MAX || l.l_linger > (INT_MAX / hz)) { - error = EDOM; + error = SET_ERROR(EDOM); break; } so->so_linger = l.l_linger; @@ -1804,14 +1805,14 @@ sosetopt1(struct socket *so, const struc * options, so disallow them. */ if (optval < 1) { - error = EINVAL; + error = SET_ERROR(EINVAL); break; } switch (opt) { case SO_SNDBUF: if (sbreserve(&so->so_snd, (u_long)optval, so) == 0) { - error = ENOBUFS; + error = SET_ERROR(ENOBUFS); break; } if (sofixedbuf) @@ -1820,7 +1821,7 @@ sosetopt1(struct socket *so, const struc case SO_RCVBUF: if (sbreserve(&so->so_rcv, (u_long)optval, so) == 0) { - error = ENOBUFS; + error = SET_ERROR(ENOBUFS); break; } if (sofixedbuf) @@ -1855,11 +1856,11 @@ sosetopt1(struct socket *so, const struc break; if (tv.tv_sec < 0 || tv.tv_usec < 0 || tv.tv_usec >= 1000000) { - error = EDOM; + error = SET_ERROR(EDOM); break; } if (tv.tv_sec > (INT_MAX - tv.tv_usec / tick) / hz) { - error = EDOM; + error = SET_ERROR(EDOM); break; } @@ -1882,7 +1883,7 @@ sosetopt1(struct socket *so, const struc (opt, so, sopt), enosys(), error); if (error == ENOSYS || error == EPASSTHROUGH) { solock(so); - error = ENOPROTOOPT; + error = SET_ERROR(ENOPROTOOPT); } break; } @@ -1899,7 +1900,7 @@ sosetopt(struct socket *so, struct socko error = sosetopt1(so, sopt); KASSERT(solocked(so)); } else { - error = ENOPROTOOPT; + error = SET_ERROR(ENOPROTOOPT); solock(so); } @@ -2025,7 +2026,7 @@ sogetopt1(struct socket *so, struct sock MODULE_HOOK_CALL(uipc_socket_50_getopt1_hook, (opt, so, sopt), enosys(), error); if (error) - error = ENOPROTOOPT; + error = SET_ERROR(ENOPROTOOPT); break; } @@ -2043,7 +2044,7 @@ sogetopt(struct socket *so, struct socko error = ((*so->so_proto->pr_ctloutput) (PRCO_GETOPT, so, sopt)); } else - error = (ENOPROTOOPT); + error = SET_ERROR(ENOPROTOOPT); } else { error = sogetopt1(so, sopt); } @@ -2065,7 +2066,7 @@ sockopt_alloc(struct sockopt *sopt, size if (len > sizeof(sopt->sopt_buf)) { data = kmem_zalloc(len, kmflag); if (data == NULL) - return ENOMEM; + return SET_ERROR(ENOMEM); sopt->sopt_data = data; } else sopt->sopt_data = sopt->sopt_buf; @@ -2146,7 +2147,7 @@ sockopt_get(const struct sockopt *sopt, { if (sopt->sopt_size != len) - return EINVAL; + return SET_ERROR(EINVAL); memcpy(buf, sopt->sopt_data, len); return 0; @@ -2400,7 +2401,7 @@ soo_kqfilter(struct file *fp, struct kno /* Other end of pipe has been closed. */ if (so->so_state & SS_ISDISCONNECTED) { sounlock(so); - return EBADF; + return SET_ERROR(EBADF); } } #endif @@ -2411,7 +2412,7 @@ soo_kqfilter(struct file *fp, struct kno break; default: sounlock(so); - return EINVAL; + return SET_ERROR(EINVAL); } selrecord_knote(&sb->sb_sel, kn); sb->sb_flags |= SB_KNOTE; @@ -2520,7 +2521,7 @@ sysctl_kern_somaxkva(SYSCTLFN_ARGS) return error; if (new_somaxkva < (16 * 1024 * 1024)) /* sanity */ - return EINVAL; + return SET_ERROR(EINVAL); mutex_enter(&so_pendfree_lock); somaxkva = new_somaxkva; @@ -2572,7 +2573,7 @@ sysctl_kern_sooptions(SYSCTLFN_ARGS) return error; if (new_options & ~SO_DEFOPTS) - return EINVAL; + return SET_ERROR(EINVAL); sooptions = new_options; Index: src/sys/kern/uipc_socket2.c diff -u src/sys/kern/uipc_socket2.c:1.145 src/sys/kern/uipc_socket2.c:1.146 --- src/sys/kern/uipc_socket2.c:1.145 Fri Dec 6 18:36:47 2024 +++ src/sys/kern/uipc_socket2.c Fri Dec 6 18:44:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket2.c,v 1.145 2024/12/06 18:36:47 riastradh Exp $ */ +/* $NetBSD: uipc_socket2.c,v 1.146 2024/12/06 18:44:00 riastradh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.145 2024/12/06 18:36:47 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.146 2024/12/06 18:44:00 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -79,6 +79,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_socket2 #include <sys/pool.h> #include <sys/proc.h> #include <sys/protosw.h> +#include <sys/sdt.h> #include <sys/signalvar.h> #include <sys/socket.h> #include <sys/socketvar.h> @@ -518,7 +519,7 @@ soroverflow(struct socket *so) so->so_rcv.sb_overflowed++; if (so->so_options & SO_RERROR) { - so->so_rerror = ENOBUFS; + so->so_rerror = SET_ERROR(ENOBUFS); sorwakeup(so); } } @@ -648,7 +649,7 @@ sb_max_set(u_long new_sbmax) int s; if (new_sbmax < (16 * 1024)) - return (EINVAL); + return SET_ERROR(EINVAL); s = splsoftnet(); sb_max = new_sbmax; @@ -691,7 +692,7 @@ soreserve(struct socket *so, u_long sndc bad2: sbrelease(&so->so_snd, so); bad: - return (ENOBUFS); + return SET_ERROR(ENOBUFS); } /* @@ -1171,7 +1172,7 @@ sbappendaddrchain(struct sockbuf *sb, co /* Prepend sockaddr to this record (m) of input chain m0 */ n = m_prepend_sockaddr(sb, m, asa); if (n == NULL) { - error = ENOBUFS; + error = SET_ERROR(ENOBUFS); goto bad; } @@ -1541,7 +1542,7 @@ sblock(struct sockbuf *sb, int wf) return 0; } if (wf != M_WAITOK) - return EWOULDBLOCK; + return SET_ERROR(EWOULDBLOCK); so = sb->sb_so; lock = so->so_lock; if ((sb->sb_flags & SB_NOINTR) != 0) { Index: src/sys/kern/uipc_syscalls.c diff -u src/sys/kern/uipc_syscalls.c:1.213 src/sys/kern/uipc_syscalls.c:1.214 --- src/sys/kern/uipc_syscalls.c:1.213 Fri Dec 6 18:36:31 2024 +++ src/sys/kern/uipc_syscalls.c Fri Dec 6 18:44:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.213 2024/12/06 18:36:31 riastradh Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.214 2024/12/06 18:44:00 riastradh Exp $ */ /*- * Copyright (c) 2008, 2009, 2023 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ #define MBUFTYPES #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.213 2024/12/06 18:36:31 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.214 2024/12/06 18:44:00 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_pipe.h" @@ -84,6 +84,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_syscall #include <sys/mount.h> #include <sys/proc.h> #include <sys/protosw.h> +#include <sys/sdt.h> #include <sys/signalvar.h> #include <sys/socket.h> #include <sys/socketvar.h> @@ -182,10 +183,10 @@ do_sys_accept(struct lwp *l, int sock, s short wakeup_state = 0; if ((fp = fd_getfile(sock)) == NULL) - return EBADF; + return SET_ERROR(EBADF); if (fp->f_type != DTYPE_SOCKET) { fd_putfile(sock); - return ENOTSOCK; + return SET_ERROR(ENOTSOCK); } if ((error = fd_allocfile(&fp2, &fd)) != 0) { fd_putfile(sock); @@ -199,24 +200,24 @@ do_sys_accept(struct lwp *l, int sock, s sigsuspendsetup(l, mask); if (!(so->so_proto->pr_flags & PR_LISTEN)) { - error = EOPNOTSUPP; + error = SET_ERROR(EOPNOTSUPP); goto bad; } if ((so->so_options & SO_ACCEPTCONN) == 0) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto bad; } if ((so->so_state & SS_NBIO) && so->so_qlen == 0) { - error = EWOULDBLOCK; + error = SET_ERROR(EWOULDBLOCK); goto bad; } while (so->so_qlen == 0 && so->so_error == 0) { if (so->so_state & SS_CANTRCVMORE) { - so->so_error = ECONNABORTED; + so->so_error = SET_ERROR(ECONNABORTED); break; } if (wakeup_state & SS_RESTARTSYS) { - error = ERESTART; + error = SET_ERROR(ERESTART); goto bad; } error = sowait(so, true, 0); @@ -226,7 +227,7 @@ do_sys_accept(struct lwp *l, int sock, s wakeup_state = so->so_state; } if (so->so_error) { - error = so->so_error; + error = SET_ERROR(so->so_error); so->so_error = 0; goto bad; } @@ -366,7 +367,7 @@ do_sys_connect(struct lwp *l, int fd, st } solock(so); if ((so->so_state & SS_ISCONNECTING) != 0) { - error = EALREADY; + error = SET_ERROR(EALREADY); goto out; } @@ -375,13 +376,13 @@ do_sys_connect(struct lwp *l, int fd, st goto bad; if ((so->so_state & (SS_NBIO|SS_ISCONNECTING)) == (SS_NBIO|SS_ISCONNECTING)) { - error = EINPROGRESS; + error = SET_ERROR(EINPROGRESS); goto out; } while ((so->so_state & SS_ISCONNECTING) != 0 && so->so_error == 0) { error = sowait(so, true, 0); if (__predict_false((so->so_state & SS_ISABORTING) != 0)) { - error = EPIPE; + error = SET_ERROR(EPIPE); interrupted = 1; break; } @@ -392,14 +393,14 @@ do_sys_connect(struct lwp *l, int fd, st } } if (error == 0) { - error = so->so_error; + error = SET_ERROR(so->so_error); so->so_error = 0; } bad: if (!interrupted) so->so_state &= ~SS_ISCONNECTING; if (error == ERESTART) - error = EINTR; + error = SET_ERROR(EINTR); out: sounlock(so); fd_putfile(fd); @@ -530,7 +531,7 @@ do_sys_sendmsg_so(struct lwp *l, int s, if (mp->msg_flags & MSG_IOVUSRSPACE) { if ((unsigned int)mp->msg_iovlen > UIO_SMALLIOV) { if ((unsigned int)mp->msg_iovlen > IOV_MAX) { - error = EMSGSIZE; + error = SET_ERROR(EMSGSIZE); goto bad; } iov = kmem_alloc(iovsz, KM_SLEEP); @@ -560,7 +561,7 @@ do_sys_sendmsg_so(struct lwp *l, int s, */ auio.uio_resid += tiov->iov_len; if (tiov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto bad; } } @@ -574,7 +575,7 @@ do_sys_sendmsg_so(struct lwp *l, int s, if (mp->msg_control) { if (mp->msg_controllen < CMSG_ALIGN(sizeof(struct cmsghdr))) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto bad; } if (control == NULL) { @@ -906,7 +907,7 @@ do_sys_recvmsg_so(struct lwp *l, int s, if (mp->msg_flags & MSG_IOVUSRSPACE) { if ((unsigned int)mp->msg_iovlen > UIO_SMALLIOV) { if ((unsigned int)mp->msg_iovlen > IOV_MAX) { - error = EMSGSIZE; + error = SET_ERROR(EMSGSIZE); goto out; } iov = kmem_alloc(iovsz, KM_SLEEP); @@ -935,7 +936,7 @@ do_sys_recvmsg_so(struct lwp *l, int s, */ auio.uio_resid += tiov->iov_len; if (tiov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto out; } } @@ -1014,7 +1015,7 @@ sys_recvmmsg(struct lwp *l, const struct if ((error = copyin(SCARG(uap, timeout), &ts, sizeof(ts))) != 0) return error; if (ts.tv_nsec < 0 || ts.tv_nsec >= 1000000000L) - return EINVAL; + return SET_ERROR(EINVAL); getnanotime(&now); if (timespecaddok(&now, &ts)) { timespecadd(&now, &ts, &ts); @@ -1032,7 +1033,7 @@ sys_recvmmsg(struct lwp *l, const struct * If so->so_rerror holds a deferred error return it now. */ if (so->so_rerror) { - error = so->so_rerror; + error = SET_ERROR(so->so_rerror); so->so_rerror = 0; fd_putfile(s); return error; @@ -1155,10 +1156,10 @@ sys_setsockopt(struct lwp *l, const stru len = SCARG(uap, valsize); if (len > 0 && SCARG(uap, val) == NULL) - return EINVAL; + return SET_ERROR(EINVAL); if (len > MCLBYTES) - return EINVAL; + return SET_ERROR(EINVAL); if ((error = fd_getsock1(SCARG(uap, s), &so, &fp)) != 0) return (error); @@ -1201,7 +1202,7 @@ getsockopt(struct lwp *l, const struct s valsize = 0; if (valsize > MCLBYTES) - return EINVAL; + return SET_ERROR(EINVAL); if ((error = fd_getsock1(SCARG(uap, s), &so, &fp)) != 0) return error; @@ -1274,7 +1275,7 @@ pipe1(struct lwp *l, int *fildes, int fl proc_t *p = l->l_proc; if (flags & ~(O_CLOEXEC|O_NONBLOCK|O_NOSIGPIPE)) - return EINVAL; + return SET_ERROR(EINVAL); if (flags & O_CLOEXEC) soflags |= SOCK_CLOEXEC; if (flags & O_NONBLOCK) @@ -1351,7 +1352,7 @@ do_sys_getpeername(int fd, struct sockad solock(so); if ((so->so_state & SS_ISCONNECTED) == 0) - error = ENOTCONN; + error = SET_ERROR(ENOTCONN); else { error = (*so->so_proto->pr_usrreqs->pr_peeraddr)(so, nam); } @@ -1436,7 +1437,7 @@ copyout_sockname(struct sockaddr *asa, u } else len = *alen; if (len < 0) - return EINVAL; + return SET_ERROR(EINVAL); if (addr == NULL) { len = 0; @@ -1522,7 +1523,7 @@ sockargs_sb(struct sockaddr_big *sb, con */ if (buflen > UCHAR_MAX || buflen <= offsetof(struct sockaddr_big, sb_data)) - return EINVAL; + return SET_ERROR(EINVAL); error = copyin(name, (void *)sb, buflen); if (error) @@ -1558,13 +1559,13 @@ sockargs(struct mbuf **mp, const void *b * length is just too much. */ if (buflen > (type == MT_SONAME ? UCHAR_MAX : PAGE_SIZE)) - return EINVAL; + return SET_ERROR(EINVAL); /* * length must greater than sizeof(sa_family) + sizeof(sa_len) */ if (type == MT_SONAME && buflen <= 2) - return EINVAL; + return SET_ERROR(EINVAL); /* Allocate an mbuf to hold the arguments. */ m = m_get(M_WAIT, type); @@ -1619,7 +1620,7 @@ sockargs(struct mbuf **mp, const void *b } return 0; default: - return EINVAL; + return SET_ERROR(EINVAL); } } @@ -1685,6 +1686,6 @@ do_sys_peeloff(struct socket *head, void return error; #else - return EOPNOTSUPP; + return SET_ERROR(EOPNOTSUPP); #endif } Index: src/sys/kern/uipc_usrreq.c diff -u src/sys/kern/uipc_usrreq.c:1.205 src/sys/kern/uipc_usrreq.c:1.206 --- src/sys/kern/uipc_usrreq.c:1.205 Fri Dec 6 18:36:47 2024 +++ src/sys/kern/uipc_usrreq.c Fri Dec 6 18:44:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.205 2024/12/06 18:36:47 riastradh Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.206 2024/12/06 18:44:00 riastradh Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009, 2020 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.205 2024/12/06 18:36:47 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.206 2024/12/06 18:44:00 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -118,6 +118,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_usrreq. #include <sys/namei.h> #include <sys/proc.h> #include <sys/protosw.h> +#include <sys/sdt.h> #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/stat.h> @@ -350,7 +351,7 @@ unp_output(struct mbuf *m, struct mbuf * /* XXX: server side closed the socket */ if (unp->unp_conn == NULL) - return ECONNREFUSED; + return SET_ERROR(ECONNREFUSED); so2 = unp->unp_conn->unp_socket; KASSERT(solocked(so2)); @@ -372,7 +373,7 @@ unp_output(struct mbuf *m, struct mbuf * /* Don't call soroverflow because we're returning this * error directly to the sender. */ so2->so_rcv.sb_overflowed++; - return ENOBUFS; + return SET_ERROR(ENOBUFS); } else { sorwakeup(so2); return 0; @@ -452,7 +453,7 @@ unp_recvoob(struct socket *so, struct mb { KASSERT(solocked(so)); - return EOPNOTSUPP; + return SET_ERROR(EOPNOTSUPP); } static int @@ -491,7 +492,7 @@ unp_send(struct socket *so, struct mbuf KASSERT(so->so_lock == uipc_lock); if (nam) { if ((so->so_state & SS_ISCONNECTED) != 0) - error = EISCONN; + error = SET_ERROR(EISCONN); else { /* * Note: once connected, the @@ -506,7 +507,7 @@ unp_send(struct socket *so, struct mbuf } } else { if ((so->so_state & SS_ISCONNECTED) == 0) - error = ENOTCONN; + error = SET_ERROR(ENOTCONN); } if (error) { unp_dispose(control); @@ -525,7 +526,7 @@ unp_send(struct socket *so, struct mbuf #define rcv (&so2->so_rcv) #define snd (&so->so_snd) if (unp->unp_conn == NULL) { - error = ENOTCONN; + error = SET_ERROR(ENOTCONN); break; } so2 = unp->unp_conn->unp_socket; @@ -601,7 +602,7 @@ unp_sendoob(struct socket *so, struct mb m_freem(m); m_freem(control); - return EOPNOTSUPP; + return SET_ERROR(EOPNOTSUPP); } /* @@ -616,14 +617,14 @@ uipc_ctloutput(int op, struct socket *so KASSERT(solocked(so)); if (sopt->sopt_level != SOL_LOCAL) { - error = ENOPROTOOPT; + error = SET_ERROR(ENOPROTOOPT); } else switch (op) { case PRCO_SETOPT: switch (sopt->sopt_name) { case LOCAL_OCREDS: if (!compat70_ocreds_valid) { - error = ENOPROTOOPT; + error = SET_ERROR(ENOPROTOOPT); break; } /* FALLTHROUGH */ @@ -653,7 +654,7 @@ uipc_ctloutput(int op, struct socket *so #undef OPTSET default: - error = ENOPROTOOPT; + error = SET_ERROR(ENOPROTOOPT); break; } break; @@ -666,7 +667,7 @@ uipc_ctloutput(int op, struct socket *so error = sockopt_set(sopt, &unp->unp_connid, sizeof(unp->unp_connid)); } else { - error = EINVAL; + error = SET_ERROR(EINVAL); } break; case LOCAL_CREDS: @@ -684,7 +685,7 @@ uipc_ctloutput(int op, struct socket *so #undef OPTBIT /* FALLTHROUGH */ default: - error = ENOPROTOOPT; + error = SET_ERROR(ENOPROTOOPT); break; } solock(so); @@ -788,7 +789,7 @@ unp_detach(struct socket *so) unp_disconnect1(unp); while (unp->unp_refs) { KASSERT(solocked2(so, unp->unp_refs->unp_socket)); - if (unp_drop(unp->unp_refs, ECONNRESET)) { + if (unp_drop(unp->unp_refs, SET_ERROR(ECONNRESET))) { solock(so); goto retry; } @@ -820,7 +821,7 @@ unp_accept(struct socket *so, struct soc /* XXX code review required to determine if unp can ever be NULL */ if (unp == NULL) - return EINVAL; + return SET_ERROR(EINVAL); KASSERT(so->so_lock == uipc_lock); /* @@ -875,7 +876,7 @@ unp_accept(struct socket *so, struct soc static int unp_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp) { - return EOPNOTSUPP; + return SET_ERROR(EOPNOTSUPP); } static int @@ -888,7 +889,7 @@ unp_stat(struct socket *so, struct stat unp = sotounpcb(so); if (unp == NULL) - return EINVAL; + return SET_ERROR(EINVAL); ub->st_blksize = so->so_snd.sb_hiwat; switch (so->so_type) { @@ -972,13 +973,13 @@ unp_bind(struct socket *so, struct socka KASSERT(nam != NULL); if (unp->unp_vnode != NULL) - return (EINVAL); + return SET_ERROR(EINVAL); if ((unp->unp_flags & UNP_BUSY) != 0) { /* * EALREADY may not be strictly accurate, but since this * is a major application error it's hardly a big deal. */ - return (EALREADY); + return SET_ERROR(EALREADY); } unp->unp_flags |= UNP_BUSY; sounlock(so); @@ -988,7 +989,7 @@ unp_bind(struct socket *so, struct socka pb = pathbuf_create(sun->sun_path); if (pb == NULL) { - error = ENOMEM; + error = SET_ERROR(ENOMEM); goto bad; } NDINIT(&nd, CREATE, FOLLOW | LOCKPARENT | TRYEMULROOT, pb); @@ -1007,7 +1008,7 @@ unp_bind(struct socket *so, struct socka vput(nd.ni_dvp); vrele(vp); pathbuf_destroy(pb); - error = EADDRINUSE; + error = SET_ERROR(EADDRINUSE); goto bad; } vattr_null(&vattr); @@ -1053,7 +1054,7 @@ unp_listen(struct socket *so, struct lwp */ unp_resetlock(so); if (unp->unp_vnode == NULL) - return EINVAL; + return SET_ERROR(EINVAL); unp_connid(l, unp, UNP_EIDSBIND); return 0; @@ -1086,7 +1087,7 @@ unp_abort(struct socket *so) KASSERT(solocked(so)); KASSERT(sotounpcb(so) != NULL); - (void)unp_drop(sotounpcb(so), ECONNABORTED); + (void)unp_drop(sotounpcb(so), SET_ERROR(ECONNABORTED)); KASSERT(so->so_head == NULL); KASSERT(so->so_pcb != NULL); unp_detach(so); @@ -1100,7 +1101,7 @@ unp_connect1(struct socket *so, struct s struct unpcb *unp2; if (so2->so_type != so->so_type) - return EPROTOTYPE; + return SET_ERROR(EPROTOTYPE); /* * All three sockets involved must be locked by same lock: @@ -1162,7 +1163,7 @@ unp_connect(struct socket *so, struct so * EALREADY may not be strictly accurate, but since this * is a major application error it's hardly a big deal. */ - return (EALREADY); + return SET_ERROR(EALREADY); } unp->unp_flags |= UNP_BUSY; sounlock(so); @@ -1170,7 +1171,7 @@ unp_connect(struct socket *so, struct so sun = makeun_sb(nam, &addrlen); pb = pathbuf_create(sun->sun_path); if (pb == NULL) { - error = ENOMEM; + error = SET_ERROR(ENOMEM); goto bad2; } @@ -1183,7 +1184,7 @@ unp_connect(struct socket *so, struct so vp = nd.ni_vp; pathbuf_destroy(pb); if (vp->v_type != VSOCK) { - error = ENOTSOCK; + error = SET_ERROR(ENOTSOCK); goto bad; } if ((error = VOP_ACCESS(vp, VWRITE, l->l_cred)) != 0) @@ -1193,12 +1194,12 @@ unp_connect(struct socket *so, struct so so2 = vp->v_socket; if (so2 == NULL) { mutex_exit(vp->v_interlock); - error = ECONNREFUSED; + error = SET_ERROR(ECONNREFUSED); goto bad; } if (so->so_type != so2->so_type) { mutex_exit(vp->v_interlock); - error = EPROTOTYPE; + error = SET_ERROR(EPROTOTYPE); goto bad; } solock(so); @@ -1214,7 +1215,7 @@ unp_connect(struct socket *so, struct so so2->so_lock == uipc_lock); if ((so2->so_options & SO_ACCEPTCONN) == 0 || (so3 = sonewconn(so2, false)) == NULL) { - error = ECONNREFUSED; + error = SET_ERROR(ECONNREFUSED); sounlock(so); goto bad; } @@ -1424,7 +1425,7 @@ unp_externalize(struct mbuf *rights, str for (size_t i = 0; i < nfds; i++) { file_t * const fp = *rp++; if (fp == NULL) { - error = EINVAL; + error = SET_ERROR(EINVAL); goto out; } /* @@ -1437,7 +1438,7 @@ unp_externalize(struct mbuf *rights, str vnode_t *vp = fp->f_vnode; if ((vp->v_type == VDIR) && !vn_isunder(vp, p->p_cwdi->cwdi_rdir, l)) { - error = EPERM; + error = SET_ERROR(EPERM); goto out; } } @@ -1466,7 +1467,7 @@ unp_externalize(struct mbuf *rights, str * been returned, and some callers may * expect it. */ - error = EMSGSIZE; + error = SET_ERROR(EMSGSIZE); goto out; } } @@ -1552,7 +1553,7 @@ unp_internalize(struct mbuf **controlp) if (cm->cmsg_type != SCM_RIGHTS || cm->cmsg_level != SOL_SOCKET || cm->cmsg_len > control->m_len || cm->cmsg_len < CMSG_ALIGN(sizeof(*cm))) - return (EINVAL); + return SET_ERROR(EINVAL); /* * Verify that the file descriptors are valid, and acquire @@ -1566,7 +1567,7 @@ unp_internalize(struct mbuf **controlp) if (atomic_inc_uint_nv(&unp_rights) > maxmsg) { atomic_dec_uint(&unp_rights); nfds = i; - error = EAGAIN; + error = SET_ERROR(EAGAIN); goto out; } if ((fp = fd_getfile(fd)) == NULL @@ -1575,7 +1576,7 @@ unp_internalize(struct mbuf **controlp) fd_putfile(fd); atomic_dec_uint(&unp_rights); nfds = i; - error = EBADF; + error = SET_ERROR(EBADF); goto out; } } @@ -1583,7 +1584,7 @@ unp_internalize(struct mbuf **controlp) /* Allocate new space and copy header into it. */ newcm = malloc(CMSG_SPACE(nfds * sizeof(file_t *)), M_MBUF, M_WAITOK); if (newcm == NULL) { - error = E2BIG; + error = SET_ERROR(E2BIG); goto out; } memcpy(newcm, cm, sizeof(struct cmsghdr));