diff --git a/sys/amd64/sgx/sgx_linux.c b/sys/amd64/sgx/sgx_linux.c
index 60ebec0e0278..c2975b0d2c84 100644
--- a/sys/amd64/sgx/sgx_linux.c
+++ b/sys/amd64/sgx/sgx_linux.c
@@ -1,115 +1,116 @@
/*-
* Copyright (c) 2017 Ruslan Bukin
* All rights reserved.
*
* This software was developed by BAE Systems, the University of Cambridge
* Computer Laboratory, and Memorial University under DARPA/AFRL contract
* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing
* (TC) research program.
*
* 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 AUTHOR 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 AUTHOR 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.
*/
#include
__FBSDID("$FreeBSD$");
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define SGX_LINUX_IOCTL_MIN (SGX_IOC_ENCLAVE_CREATE & 0xffff)
#define SGX_LINUX_IOCTL_MAX (SGX_IOC_ENCLAVE_INIT & 0xffff)
static int
sgx_linux_ioctl(struct thread *td, struct linux_ioctl_args *args)
{
uint8_t data[SGX_IOCTL_MAX_DATA_LEN];
cap_rights_t rights;
struct file *fp;
u_long cmd;
int error;
int len;
- error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
+ error = fget(td, args->fd, cap_rights_init_one(&rights, CAP_IOCTL),
+ &fp);
if (error != 0)
return (error);
cmd = args->cmd;
args->cmd &= ~(LINUX_IOC_IN | LINUX_IOC_OUT);
if ((cmd & LINUX_IOC_IN) != 0)
args->cmd |= IOC_IN;
if ((cmd & LINUX_IOC_OUT) != 0)
args->cmd |= IOC_OUT;
len = IOCPARM_LEN(cmd);
if (len > SGX_IOCTL_MAX_DATA_LEN) {
error = EINVAL;
goto out;
}
if ((cmd & LINUX_IOC_IN) != 0) {
error = copyin((void *)args->arg, data, len);
if (error != 0)
goto out;
}
error = fo_ioctl(fp, args->cmd, (caddr_t)data, td->td_ucred, td);
out:
fdrop(fp, td);
return (error);
}
static struct linux_ioctl_handler sgx_linux_handler = {
sgx_linux_ioctl,
SGX_LINUX_IOCTL_MIN,
SGX_LINUX_IOCTL_MAX,
};
SYSINIT(sgx_linux_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_register_handler, &sgx_linux_handler);
SYSUNINIT(sgx_linux_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_unregister_handler, &sgx_linux_handler);
static int
sgx_linux_modevent(module_t mod, int type, void *data)
{
return (0);
}
DEV_MODULE(sgx_linux, sgx_linux_modevent, NULL);
MODULE_DEPEND(sgx_linux, linux64, 1, 1, 1);
diff --git a/sys/compat/freebsd32/freebsd32_ioctl.c b/sys/compat/freebsd32/freebsd32_ioctl.c
index db6946246b90..b3ed457f7132 100644
--- a/sys/compat/freebsd32/freebsd32_ioctl.c
+++ b/sys/compat/freebsd32/freebsd32_ioctl.c
@@ -1,247 +1,247 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 2008 David E. O'Brien
* 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.
* 3. Neither the name of the author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*/
#include
__FBSDID("$FreeBSD$");
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
CTASSERT(sizeof(struct mem_range_op32) == 12);
static int
freebsd32_ioctl_memrange(struct thread *td,
struct freebsd32_ioctl_args *uap, struct file *fp)
{
struct mem_range_op mro;
struct mem_range_op32 mro32;
int error;
u_long com;
if ((error = copyin(uap->data, &mro32, sizeof(mro32))) != 0)
return (error);
PTRIN_CP(mro32, mro, mo_desc);
CP(mro32, mro, mo_arg[0]);
CP(mro32, mro, mo_arg[1]);
com = 0;
switch (uap->com) {
case MEMRANGE_GET32:
com = MEMRANGE_GET;
break;
case MEMRANGE_SET32:
com = MEMRANGE_SET;
break;
default:
panic("%s: unknown MEMRANGE %#x", __func__, uap->com);
}
if ((error = fo_ioctl(fp, com, (caddr_t)&mro, td->td_ucred, td)) != 0)
return (error);
if ( (com & IOC_OUT) ) {
CP(mro, mro32, mo_arg[0]);
CP(mro, mro32, mo_arg[1]);
error = copyout(&mro32, uap->data, sizeof(mro32));
}
return (error);
}
static int
freebsd32_ioctl_barmmap(struct thread *td,
struct freebsd32_ioctl_args *uap, struct file *fp)
{
struct pci_bar_mmap32 pbm32;
struct pci_bar_mmap pbm;
int error;
error = copyin(uap->data, &pbm32, sizeof(pbm32));
if (error != 0)
return (error);
PTRIN_CP(pbm32, pbm, pbm_map_base);
CP(pbm32, pbm, pbm_sel);
CP(pbm32, pbm, pbm_reg);
CP(pbm32, pbm, pbm_flags);
CP(pbm32, pbm, pbm_memattr);
pbm.pbm_bar_length = PAIR32TO64(uint64_t, pbm32.pbm_bar_length);
error = fo_ioctl(fp, PCIOCBARMMAP, (caddr_t)&pbm, td->td_ucred, td);
if (error == 0) {
PTROUT_CP(pbm, pbm32, pbm_map_base);
CP(pbm, pbm32, pbm_map_length);
#if BYTE_ORDER == LITTLE_ENDIAN
pbm32.pbm_bar_length1 = pbm.pbm_bar_length;
pbm32.pbm_bar_length2 = pbm.pbm_bar_length >> 32;
#else
pbm32.pbm_bar_length1 = pbm.pbm_bar_length >> 32;
pbm32.pbm_bar_length2 = pbm.pbm_bar_length;
#endif
CP(pbm, pbm32, pbm_bar_off);
error = copyout(&pbm32, uap->data, sizeof(pbm32));
}
return (error);
}
static int
freebsd32_ioctl_sg(struct thread *td,
struct freebsd32_ioctl_args *uap, struct file *fp)
{
struct sg_io_hdr io;
struct sg_io_hdr32 io32;
int error;
if ((error = copyin(uap->data, &io32, sizeof(io32))) != 0)
return (error);
CP(io32, io, interface_id);
CP(io32, io, dxfer_direction);
CP(io32, io, cmd_len);
CP(io32, io, mx_sb_len);
CP(io32, io, iovec_count);
CP(io32, io, dxfer_len);
PTRIN_CP(io32, io, dxferp);
PTRIN_CP(io32, io, cmdp);
PTRIN_CP(io32, io, sbp);
CP(io32, io, timeout);
CP(io32, io, flags);
CP(io32, io, pack_id);
PTRIN_CP(io32, io, usr_ptr);
CP(io32, io, status);
CP(io32, io, masked_status);
CP(io32, io, msg_status);
CP(io32, io, sb_len_wr);
CP(io32, io, host_status);
CP(io32, io, driver_status);
CP(io32, io, resid);
CP(io32, io, duration);
CP(io32, io, info);
if ((error = fo_ioctl(fp, SG_IO, (caddr_t)&io, td->td_ucred, td)) != 0)
return (error);
CP(io, io32, interface_id);
CP(io, io32, dxfer_direction);
CP(io, io32, cmd_len);
CP(io, io32, mx_sb_len);
CP(io, io32, iovec_count);
CP(io, io32, dxfer_len);
PTROUT_CP(io, io32, dxferp);
PTROUT_CP(io, io32, cmdp);
PTROUT_CP(io, io32, sbp);
CP(io, io32, timeout);
CP(io, io32, flags);
CP(io, io32, pack_id);
PTROUT_CP(io, io32, usr_ptr);
CP(io, io32, status);
CP(io, io32, masked_status);
CP(io, io32, msg_status);
CP(io, io32, sb_len_wr);
CP(io, io32, host_status);
CP(io, io32, driver_status);
CP(io, io32, resid);
CP(io, io32, duration);
CP(io, io32, info);
error = copyout(&io32, uap->data, sizeof(io32));
return (error);
}
int
freebsd32_ioctl(struct thread *td, struct freebsd32_ioctl_args *uap)
{
struct ioctl_args ap /*{
int fd;
u_long com;
caddr_t data;
}*/ ;
struct file *fp;
cap_rights_t rights;
int error;
- error = fget(td, uap->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
+ error = fget(td, uap->fd, cap_rights_init_one(&rights, CAP_IOCTL), &fp);
if (error != 0)
return (error);
if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
fdrop(fp, td);
return (EBADF);
}
switch (uap->com) {
case MEMRANGE_GET32: /* FALLTHROUGH */
case MEMRANGE_SET32:
error = freebsd32_ioctl_memrange(td, uap, fp);
break;
case SG_IO_32:
error = freebsd32_ioctl_sg(td, uap, fp);
break;
case PCIOCBARMMAP_32:
error = freebsd32_ioctl_barmmap(td, uap, fp);
break;
default:
fdrop(fp, td);
ap.fd = uap->fd;
ap.com = uap->com;
PTRIN_CP(*uap, ap, data);
return sys_ioctl(td, &ap);
}
fdrop(fp, td);
return (error);
}
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 14afd433d9f1..b7db1c4468d7 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -1,3833 +1,3833 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2002 Doug Rabson
* 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 AUTHOR 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 AUTHOR 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.
*/
#include
__FBSDID("$FreeBSD$");
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_ktrace.h"
#define __ELF_WORD_SIZE 32
#ifdef COMPAT_FREEBSD11
#define _WANT_FREEBSD11_KEVENT
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include /* Must come after sys/malloc.h */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include /* Must come after sys/selinfo.h */
#include /* Must come after sys/selinfo.h */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef KTRACE
#include
#endif
#ifdef INET
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef __amd64__
#include
#endif
#include
#include
#include
#include
#include
#include
#include
FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
struct ptrace_io_desc32 {
int piod_op;
uint32_t piod_offs;
uint32_t piod_addr;
uint32_t piod_len;
};
struct ptrace_sc_ret32 {
uint32_t sr_retval[2];
int sr_error;
};
struct ptrace_vm_entry32 {
int pve_entry;
int pve_timestamp;
uint32_t pve_start;
uint32_t pve_end;
uint32_t pve_offset;
u_int pve_prot;
u_int pve_pathlen;
int32_t pve_fileid;
u_int pve_fsid;
uint32_t pve_path;
};
#ifdef __amd64__
CTASSERT(sizeof(struct timeval32) == 8);
CTASSERT(sizeof(struct timespec32) == 8);
CTASSERT(sizeof(struct itimerval32) == 16);
CTASSERT(sizeof(struct bintime32) == 12);
#endif
CTASSERT(sizeof(struct statfs32) == 256);
#ifdef __amd64__
CTASSERT(sizeof(struct rusage32) == 72);
#endif
CTASSERT(sizeof(struct sigaltstack32) == 12);
#ifdef __amd64__
CTASSERT(sizeof(struct kevent32) == 56);
#else
CTASSERT(sizeof(struct kevent32) == 64);
#endif
CTASSERT(sizeof(struct iovec32) == 8);
CTASSERT(sizeof(struct msghdr32) == 28);
#ifdef __amd64__
CTASSERT(sizeof(struct stat32) == 208);
CTASSERT(sizeof(struct freebsd11_stat32) == 96);
#endif
CTASSERT(sizeof(struct sigaction32) == 24);
static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
static int freebsd32_user_clock_nanosleep(struct thread *td, clockid_t clock_id,
int flags, const struct timespec32 *ua_rqtp, struct timespec32 *ua_rmtp);
void
freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
{
TV_CP(*s, *s32, ru_utime);
TV_CP(*s, *s32, ru_stime);
CP(*s, *s32, ru_maxrss);
CP(*s, *s32, ru_ixrss);
CP(*s, *s32, ru_idrss);
CP(*s, *s32, ru_isrss);
CP(*s, *s32, ru_minflt);
CP(*s, *s32, ru_majflt);
CP(*s, *s32, ru_nswap);
CP(*s, *s32, ru_inblock);
CP(*s, *s32, ru_oublock);
CP(*s, *s32, ru_msgsnd);
CP(*s, *s32, ru_msgrcv);
CP(*s, *s32, ru_nsignals);
CP(*s, *s32, ru_nvcsw);
CP(*s, *s32, ru_nivcsw);
}
int
freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
{
int error, status;
struct rusage32 ru32;
struct rusage ru, *rup;
if (uap->rusage != NULL)
rup = &ru;
else
rup = NULL;
error = kern_wait(td, uap->pid, &status, uap->options, rup);
if (error)
return (error);
if (uap->status != NULL)
error = copyout(&status, uap->status, sizeof(status));
if (uap->rusage != NULL && error == 0) {
freebsd32_rusage_out(&ru, &ru32);
error = copyout(&ru32, uap->rusage, sizeof(ru32));
}
return (error);
}
int
freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
{
struct wrusage32 wru32;
struct __wrusage wru, *wrup;
struct siginfo32 si32;
struct __siginfo si, *sip;
int error, status;
if (uap->wrusage != NULL)
wrup = &wru;
else
wrup = NULL;
if (uap->info != NULL) {
sip = &si;
bzero(sip, sizeof(*sip));
} else
sip = NULL;
error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
&status, uap->options, wrup, sip);
if (error != 0)
return (error);
if (uap->status != NULL)
error = copyout(&status, uap->status, sizeof(status));
if (uap->wrusage != NULL && error == 0) {
freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
error = copyout(&wru32, uap->wrusage, sizeof(wru32));
}
if (uap->info != NULL && error == 0) {
siginfo_to_siginfo32 (&si, &si32);
error = copyout(&si32, uap->info, sizeof(si32));
}
return (error);
}
#ifdef COMPAT_FREEBSD4
static void
copy_statfs(struct statfs *in, struct statfs32 *out)
{
statfs_scale_blocks(in, INT32_MAX);
bzero(out, sizeof(*out));
CP(*in, *out, f_bsize);
out->f_iosize = MIN(in->f_iosize, INT32_MAX);
CP(*in, *out, f_blocks);
CP(*in, *out, f_bfree);
CP(*in, *out, f_bavail);
out->f_files = MIN(in->f_files, INT32_MAX);
out->f_ffree = MIN(in->f_ffree, INT32_MAX);
CP(*in, *out, f_fsid);
CP(*in, *out, f_owner);
CP(*in, *out, f_type);
CP(*in, *out, f_flags);
out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
strlcpy(out->f_fstypename,
in->f_fstypename, MFSNAMELEN);
strlcpy(out->f_mntonname,
in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
strlcpy(out->f_mntfromname,
in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
}
#endif
#ifdef COMPAT_FREEBSD4
int
freebsd4_freebsd32_getfsstat(struct thread *td,
struct freebsd4_freebsd32_getfsstat_args *uap)
{
struct statfs *buf, *sp;
struct statfs32 stat32;
size_t count, size, copycount;
int error;
count = uap->bufsize / sizeof(struct statfs32);
size = count * sizeof(struct statfs);
error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->mode);
if (size > 0) {
sp = buf;
copycount = count;
while (copycount > 0 && error == 0) {
copy_statfs(sp, &stat32);
error = copyout(&stat32, uap->buf, sizeof(stat32));
sp++;
uap->buf++;
copycount--;
}
free(buf, M_STATFS);
}
if (error == 0)
td->td_retval[0] = count;
return (error);
}
#endif
#ifdef COMPAT_FREEBSD10
int
freebsd10_freebsd32_pipe(struct thread *td,
struct freebsd10_freebsd32_pipe_args *uap) {
return (freebsd10_pipe(td, (struct freebsd10_pipe_args*)uap));
}
#endif
int
freebsd32_sigaltstack(struct thread *td,
struct freebsd32_sigaltstack_args *uap)
{
struct sigaltstack32 s32;
struct sigaltstack ss, oss, *ssp;
int error;
if (uap->ss != NULL) {
error = copyin(uap->ss, &s32, sizeof(s32));
if (error)
return (error);
PTRIN_CP(s32, ss, ss_sp);
CP(s32, ss, ss_size);
CP(s32, ss, ss_flags);
ssp = &ss;
} else
ssp = NULL;
error = kern_sigaltstack(td, ssp, &oss);
if (error == 0 && uap->oss != NULL) {
PTROUT_CP(oss, s32, ss_sp);
CP(oss, s32, ss_size);
CP(oss, s32, ss_flags);
error = copyout(&s32, uap->oss, sizeof(s32));
}
return (error);
}
/*
* Custom version of exec_copyin_args() so that we can translate
* the pointers.
*/
int
freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
{
char *argp, *envp;
u_int32_t *p32, arg;
int error;
bzero(args, sizeof(*args));
if (argv == NULL)
return (EFAULT);
/*
* Allocate demand-paged memory for the file name, argument, and
* environment strings.
*/
error = exec_alloc_args(args);
if (error != 0)
return (error);
/*
* Copy the file name.
*/
error = exec_args_add_fname(args, fname, segflg);
if (error != 0)
goto err_exit;
/*
* extract arguments first
*/
p32 = argv;
for (;;) {
error = copyin(p32++, &arg, sizeof(arg));
if (error)
goto err_exit;
if (arg == 0)
break;
argp = PTRIN(arg);
error = exec_args_add_arg(args, argp, UIO_USERSPACE);
if (error != 0)
goto err_exit;
}
/*
* extract environment strings
*/
if (envv) {
p32 = envv;
for (;;) {
error = copyin(p32++, &arg, sizeof(arg));
if (error)
goto err_exit;
if (arg == 0)
break;
envp = PTRIN(arg);
error = exec_args_add_env(args, envp, UIO_USERSPACE);
if (error != 0)
goto err_exit;
}
}
return (0);
err_exit:
exec_free_args(args);
return (error);
}
int
freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
{
struct image_args eargs;
struct vmspace *oldvmspace;
int error;
error = pre_execve(td, &oldvmspace);
if (error != 0)
return (error);
error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
uap->argv, uap->envv);
if (error == 0)
error = kern_execve(td, &eargs, NULL, oldvmspace);
post_execve(td, error, oldvmspace);
AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
int
freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
{
struct image_args eargs;
struct vmspace *oldvmspace;
int error;
error = pre_execve(td, &oldvmspace);
if (error != 0)
return (error);
error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
uap->argv, uap->envv);
if (error == 0) {
eargs.fd = uap->fd;
error = kern_execve(td, &eargs, NULL, oldvmspace);
}
post_execve(td, error, oldvmspace);
AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
int
freebsd32_mknodat(struct thread *td, struct freebsd32_mknodat_args *uap)
{
return (kern_mknodat(td, uap->fd, uap->path, UIO_USERSPACE,
uap->mode, PAIR32TO64(dev_t, uap->dev)));
}
int
freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
{
int prot;
prot = uap->prot;
#if defined(__amd64__)
if (i386_read_exec && (prot & PROT_READ) != 0)
prot |= PROT_EXEC;
#endif
return (kern_mprotect(td, (uintptr_t)PTRIN(uap->addr), uap->len,
prot));
}
int
freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
{
int prot;
prot = uap->prot;
#if defined(__amd64__)
if (i386_read_exec && (prot & PROT_READ))
prot |= PROT_EXEC;
#endif
return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot,
uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos)));
}
#ifdef COMPAT_FREEBSD6
int
freebsd6_freebsd32_mmap(struct thread *td,
struct freebsd6_freebsd32_mmap_args *uap)
{
int prot;
prot = uap->prot;
#if defined(__amd64__)
if (i386_read_exec && (prot & PROT_READ))
prot |= PROT_EXEC;
#endif
return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot,
uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos)));
}
#endif
int
freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
{
struct itimerval itv, oitv, *itvp;
struct itimerval32 i32;
int error;
if (uap->itv != NULL) {
error = copyin(uap->itv, &i32, sizeof(i32));
if (error)
return (error);
TV_CP(i32, itv, it_interval);
TV_CP(i32, itv, it_value);
itvp = &itv;
} else
itvp = NULL;
error = kern_setitimer(td, uap->which, itvp, &oitv);
if (error || uap->oitv == NULL)
return (error);
TV_CP(oitv, i32, it_interval);
TV_CP(oitv, i32, it_value);
return (copyout(&i32, uap->oitv, sizeof(i32)));
}
int
freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
{
struct itimerval itv;
struct itimerval32 i32;
int error;
error = kern_getitimer(td, uap->which, &itv);
if (error || uap->itv == NULL)
return (error);
TV_CP(itv, i32, it_interval);
TV_CP(itv, i32, it_value);
return (copyout(&i32, uap->itv, sizeof(i32)));
}
int
freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
{
struct timeval32 tv32;
struct timeval tv, *tvp;
int error;
if (uap->tv != NULL) {
error = copyin(uap->tv, &tv32, sizeof(tv32));
if (error)
return (error);
CP(tv32, tv, tv_sec);
CP(tv32, tv, tv_usec);
tvp = &tv;
} else
tvp = NULL;
/*
* XXX Do pointers need PTRIN()?
*/
return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
sizeof(int32_t) * 8));
}
int
freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
{
struct timespec32 ts32;
struct timespec ts;
struct timeval tv, *tvp;
sigset_t set, *uset;
int error;
if (uap->ts != NULL) {
error = copyin(uap->ts, &ts32, sizeof(ts32));
if (error != 0)
return (error);
CP(ts32, ts, tv_sec);
CP(ts32, ts, tv_nsec);
TIMESPEC_TO_TIMEVAL(&tv, &ts);
tvp = &tv;
} else
tvp = NULL;
if (uap->sm != NULL) {
error = copyin(uap->sm, &set, sizeof(set));
if (error != 0)
return (error);
uset = &set;
} else
uset = NULL;
/*
* XXX Do pointers need PTRIN()?
*/
error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
uset, sizeof(int32_t) * 8);
return (error);
}
/*
* Copy 'count' items into the destination list pointed to by uap->eventlist.
*/
static int
freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
{
struct freebsd32_kevent_args *uap;
struct kevent32 ks32[KQ_NEVENTS];
uint64_t e;
int i, j, error;
KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
uap = (struct freebsd32_kevent_args *)arg;
for (i = 0; i < count; i++) {
CP(kevp[i], ks32[i], ident);
CP(kevp[i], ks32[i], filter);
CP(kevp[i], ks32[i], flags);
CP(kevp[i], ks32[i], fflags);
#if BYTE_ORDER == LITTLE_ENDIAN
ks32[i].data1 = kevp[i].data;
ks32[i].data2 = kevp[i].data >> 32;
#else
ks32[i].data1 = kevp[i].data >> 32;
ks32[i].data2 = kevp[i].data;
#endif
PTROUT_CP(kevp[i], ks32[i], udata);
for (j = 0; j < nitems(kevp->ext); j++) {
e = kevp[i].ext[j];
#if BYTE_ORDER == LITTLE_ENDIAN
ks32[i].ext64[2 * j] = e;
ks32[i].ext64[2 * j + 1] = e >> 32;
#else
ks32[i].ext64[2 * j] = e >> 32;
ks32[i].ext64[2 * j + 1] = e;
#endif
}
}
error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
if (error == 0)
uap->eventlist += count;
return (error);
}
/*
* Copy 'count' items from the list pointed to by uap->changelist.
*/
static int
freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
{
struct freebsd32_kevent_args *uap;
struct kevent32 ks32[KQ_NEVENTS];
uint64_t e;
int i, j, error;
KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
uap = (struct freebsd32_kevent_args *)arg;
error = copyin(uap->changelist, ks32, count * sizeof *ks32);
if (error)
goto done;
uap->changelist += count;
for (i = 0; i < count; i++) {
CP(ks32[i], kevp[i], ident);
CP(ks32[i], kevp[i], filter);
CP(ks32[i], kevp[i], flags);
CP(ks32[i], kevp[i], fflags);
kevp[i].data = PAIR32TO64(uint64_t, ks32[i].data);
PTRIN_CP(ks32[i], kevp[i], udata);
for (j = 0; j < nitems(kevp->ext); j++) {
#if BYTE_ORDER == LITTLE_ENDIAN
e = ks32[i].ext64[2 * j + 1];
e <<= 32;
e += ks32[i].ext64[2 * j];
#else
e = ks32[i].ext64[2 * j];
e <<= 32;
e += ks32[i].ext64[2 * j + 1];
#endif
kevp[i].ext[j] = e;
}
}
done:
return (error);
}
int
freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
{
struct timespec32 ts32;
struct timespec ts, *tsp;
struct kevent_copyops k_ops = {
.arg = uap,
.k_copyout = freebsd32_kevent_copyout,
.k_copyin = freebsd32_kevent_copyin,
};
#ifdef KTRACE
struct kevent32 *eventlist = uap->eventlist;
#endif
int error;
if (uap->timeout) {
error = copyin(uap->timeout, &ts32, sizeof(ts32));
if (error)
return (error);
CP(ts32, ts, tv_sec);
CP(ts32, ts, tv_nsec);
tsp = &ts;
} else
tsp = NULL;
#ifdef KTRACE
if (KTRPOINT(td, KTR_STRUCT_ARRAY))
ktrstructarray("kevent32", UIO_USERSPACE, uap->changelist,
uap->nchanges, sizeof(struct kevent32));
#endif
error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
&k_ops, tsp);
#ifdef KTRACE
if (error == 0 && KTRPOINT(td, KTR_STRUCT_ARRAY))
ktrstructarray("kevent32", UIO_USERSPACE, eventlist,
td->td_retval[0], sizeof(struct kevent32));
#endif
return (error);
}
#ifdef COMPAT_FREEBSD11
static int
freebsd32_kevent11_copyout(void *arg, struct kevent *kevp, int count)
{
struct freebsd11_freebsd32_kevent_args *uap;
struct kevent32_freebsd11 ks32[KQ_NEVENTS];
int i, error;
KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
uap = (struct freebsd11_freebsd32_kevent_args *)arg;
for (i = 0; i < count; i++) {
CP(kevp[i], ks32[i], ident);
CP(kevp[i], ks32[i], filter);
CP(kevp[i], ks32[i], flags);
CP(kevp[i], ks32[i], fflags);
CP(kevp[i], ks32[i], data);
PTROUT_CP(kevp[i], ks32[i], udata);
}
error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
if (error == 0)
uap->eventlist += count;
return (error);
}
/*
* Copy 'count' items from the list pointed to by uap->changelist.
*/
static int
freebsd32_kevent11_copyin(void *arg, struct kevent *kevp, int count)
{
struct freebsd11_freebsd32_kevent_args *uap;
struct kevent32_freebsd11 ks32[KQ_NEVENTS];
int i, j, error;
KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
uap = (struct freebsd11_freebsd32_kevent_args *)arg;
error = copyin(uap->changelist, ks32, count * sizeof *ks32);
if (error)
goto done;
uap->changelist += count;
for (i = 0; i < count; i++) {
CP(ks32[i], kevp[i], ident);
CP(ks32[i], kevp[i], filter);
CP(ks32[i], kevp[i], flags);
CP(ks32[i], kevp[i], fflags);
CP(ks32[i], kevp[i], data);
PTRIN_CP(ks32[i], kevp[i], udata);
for (j = 0; j < nitems(kevp->ext); j++)
kevp[i].ext[j] = 0;
}
done:
return (error);
}
int
freebsd11_freebsd32_kevent(struct thread *td,
struct freebsd11_freebsd32_kevent_args *uap)
{
struct timespec32 ts32;
struct timespec ts, *tsp;
struct kevent_copyops k_ops = {
.arg = uap,
.k_copyout = freebsd32_kevent11_copyout,
.k_copyin = freebsd32_kevent11_copyin,
};
#ifdef KTRACE
struct kevent32_freebsd11 *eventlist = uap->eventlist;
#endif
int error;
if (uap->timeout) {
error = copyin(uap->timeout, &ts32, sizeof(ts32));
if (error)
return (error);
CP(ts32, ts, tv_sec);
CP(ts32, ts, tv_nsec);
tsp = &ts;
} else
tsp = NULL;
#ifdef KTRACE
if (KTRPOINT(td, KTR_STRUCT_ARRAY))
ktrstructarray("kevent32_freebsd11", UIO_USERSPACE,
uap->changelist, uap->nchanges,
sizeof(struct kevent32_freebsd11));
#endif
error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
&k_ops, tsp);
#ifdef KTRACE
if (error == 0 && KTRPOINT(td, KTR_STRUCT_ARRAY))
ktrstructarray("kevent32_freebsd11", UIO_USERSPACE,
eventlist, td->td_retval[0],
sizeof(struct kevent32_freebsd11));
#endif
return (error);
}
#endif
int
freebsd32_gettimeofday(struct thread *td,
struct freebsd32_gettimeofday_args *uap)
{
struct timeval atv;
struct timeval32 atv32;
struct timezone rtz;
int error = 0;
if (uap->tp) {
microtime(&atv);
CP(atv, atv32, tv_sec);
CP(atv, atv32, tv_usec);
error = copyout(&atv32, uap->tp, sizeof (atv32));
}
if (error == 0 && uap->tzp != NULL) {
rtz.tz_minuteswest = 0;
rtz.tz_dsttime = 0;
error = copyout(&rtz, uap->tzp, sizeof (rtz));
}
return (error);
}
int
freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
{
struct rusage32 s32;
struct rusage s;
int error;
error = kern_getrusage(td, uap->who, &s);
if (error == 0) {
freebsd32_rusage_out(&s, &s32);
error = copyout(&s32, uap->rusage, sizeof(s32));
}
return (error);
}
static void
ptrace_lwpinfo_to32(const struct ptrace_lwpinfo *pl,
struct ptrace_lwpinfo32 *pl32)
{
bzero(pl32, sizeof(*pl32));
pl32->pl_lwpid = pl->pl_lwpid;
pl32->pl_event = pl->pl_event;
pl32->pl_flags = pl->pl_flags;
pl32->pl_sigmask = pl->pl_sigmask;
pl32->pl_siglist = pl->pl_siglist;
siginfo_to_siginfo32(&pl->pl_siginfo, &pl32->pl_siginfo);
strcpy(pl32->pl_tdname, pl->pl_tdname);
pl32->pl_child_pid = pl->pl_child_pid;
pl32->pl_syscall_code = pl->pl_syscall_code;
pl32->pl_syscall_narg = pl->pl_syscall_narg;
}
static void
ptrace_sc_ret_to32(const struct ptrace_sc_ret *psr,
struct ptrace_sc_ret32 *psr32)
{
bzero(psr32, sizeof(*psr32));
psr32->sr_retval[0] = psr->sr_retval[0];
psr32->sr_retval[1] = psr->sr_retval[1];
psr32->sr_error = psr->sr_error;
}
int
freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
{
union {
struct ptrace_io_desc piod;
struct ptrace_lwpinfo pl;
struct ptrace_vm_entry pve;
struct dbreg32 dbreg;
struct fpreg32 fpreg;
struct reg32 reg;
register_t args[nitems(td->td_sa.args)];
struct ptrace_sc_ret psr;
int ptevents;
} r;
union {
struct ptrace_io_desc32 piod;
struct ptrace_lwpinfo32 pl;
struct ptrace_vm_entry32 pve;
uint32_t args[nitems(td->td_sa.args)];
struct ptrace_sc_ret32 psr;
} r32;
void *addr;
int data, error = 0, i;
AUDIT_ARG_PID(uap->pid);
AUDIT_ARG_CMD(uap->req);
AUDIT_ARG_VALUE(uap->data);
addr = &r;
data = uap->data;
switch (uap->req) {
case PT_GET_EVENT_MASK:
case PT_GET_SC_ARGS:
case PT_GET_SC_RET:
break;
case PT_LWPINFO:
if (uap->data > sizeof(r32.pl))
return (EINVAL);
/*
* Pass size of native structure in 'data'. Truncate
* if necessary to avoid siginfo.
*/
data = sizeof(r.pl);
if (uap->data < offsetof(struct ptrace_lwpinfo32, pl_siginfo) +
sizeof(struct siginfo32))
data = offsetof(struct ptrace_lwpinfo, pl_siginfo);
break;
case PT_GETREGS:
bzero(&r.reg, sizeof(r.reg));
break;
case PT_GETFPREGS:
bzero(&r.fpreg, sizeof(r.fpreg));
break;
case PT_GETDBREGS:
bzero(&r.dbreg, sizeof(r.dbreg));
break;
case PT_SETREGS:
error = copyin(uap->addr, &r.reg, sizeof(r.reg));
break;
case PT_SETFPREGS:
error = copyin(uap->addr, &r.fpreg, sizeof(r.fpreg));
break;
case PT_SETDBREGS:
error = copyin(uap->addr, &r.dbreg, sizeof(r.dbreg));
break;
case PT_SET_EVENT_MASK:
if (uap->data != sizeof(r.ptevents))
error = EINVAL;
else
error = copyin(uap->addr, &r.ptevents, uap->data);
break;
case PT_IO:
error = copyin(uap->addr, &r32.piod, sizeof(r32.piod));
if (error)
break;
CP(r32.piod, r.piod, piod_op);
PTRIN_CP(r32.piod, r.piod, piod_offs);
PTRIN_CP(r32.piod, r.piod, piod_addr);
CP(r32.piod, r.piod, piod_len);
break;
case PT_VM_ENTRY:
error = copyin(uap->addr, &r32.pve, sizeof(r32.pve));
if (error)
break;
CP(r32.pve, r.pve, pve_entry);
CP(r32.pve, r.pve, pve_timestamp);
CP(r32.pve, r.pve, pve_start);
CP(r32.pve, r.pve, pve_end);
CP(r32.pve, r.pve, pve_offset);
CP(r32.pve, r.pve, pve_prot);
CP(r32.pve, r.pve, pve_pathlen);
CP(r32.pve, r.pve, pve_fileid);
CP(r32.pve, r.pve, pve_fsid);
PTRIN_CP(r32.pve, r.pve, pve_path);
break;
default:
addr = uap->addr;
break;
}
if (error)
return (error);
error = kern_ptrace(td, uap->req, uap->pid, addr, data);
if (error)
return (error);
switch (uap->req) {
case PT_VM_ENTRY:
CP(r.pve, r32.pve, pve_entry);
CP(r.pve, r32.pve, pve_timestamp);
CP(r.pve, r32.pve, pve_start);
CP(r.pve, r32.pve, pve_end);
CP(r.pve, r32.pve, pve_offset);
CP(r.pve, r32.pve, pve_prot);
CP(r.pve, r32.pve, pve_pathlen);
CP(r.pve, r32.pve, pve_fileid);
CP(r.pve, r32.pve, pve_fsid);
error = copyout(&r32.pve, uap->addr, sizeof(r32.pve));
break;
case PT_IO:
CP(r.piod, r32.piod, piod_len);
error = copyout(&r32.piod, uap->addr, sizeof(r32.piod));
break;
case PT_GETREGS:
error = copyout(&r.reg, uap->addr, sizeof(r.reg));
break;
case PT_GETFPREGS:
error = copyout(&r.fpreg, uap->addr, sizeof(r.fpreg));
break;
case PT_GETDBREGS:
error = copyout(&r.dbreg, uap->addr, sizeof(r.dbreg));
break;
case PT_GET_EVENT_MASK:
/* NB: The size in uap->data is validated in kern_ptrace(). */
error = copyout(&r.ptevents, uap->addr, uap->data);
break;
case PT_LWPINFO:
ptrace_lwpinfo_to32(&r.pl, &r32.pl);
error = copyout(&r32.pl, uap->addr, uap->data);
break;
case PT_GET_SC_ARGS:
for (i = 0; i < nitems(r.args); i++)
r32.args[i] = (uint32_t)r.args[i];
error = copyout(r32.args, uap->addr, MIN(uap->data,
sizeof(r32.args)));
break;
case PT_GET_SC_RET:
ptrace_sc_ret_to32(&r.psr, &r32.psr);
error = copyout(&r32.psr, uap->addr, MIN(uap->data,
sizeof(r32.psr)));
break;
}
return (error);
}
int
freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
{
struct iovec32 iov32;
struct iovec *iov;
struct uio *uio;
u_int iovlen;
int error, i;
*uiop = NULL;
if (iovcnt > UIO_MAXIOV)
return (EINVAL);
iovlen = iovcnt * sizeof(struct iovec);
uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
iov = (struct iovec *)(uio + 1);
for (i = 0; i < iovcnt; i++) {
error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
if (error) {
free(uio, M_IOV);
return (error);
}
iov[i].iov_base = PTRIN(iov32.iov_base);
iov[i].iov_len = iov32.iov_len;
}
uio->uio_iov = iov;
uio->uio_iovcnt = iovcnt;
uio->uio_segflg = UIO_USERSPACE;
uio->uio_offset = -1;
uio->uio_resid = 0;
for (i = 0; i < iovcnt; i++) {
if (iov->iov_len > INT_MAX - uio->uio_resid) {
free(uio, M_IOV);
return (EINVAL);
}
uio->uio_resid += iov->iov_len;
iov++;
}
*uiop = uio;
return (0);
}
int
freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
{
struct uio *auio;
int error;
error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
if (error)
return (error);
error = kern_readv(td, uap->fd, auio);
free(auio, M_IOV);
return (error);
}
int
freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
{
struct uio *auio;
int error;
error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
if (error)
return (error);
error = kern_writev(td, uap->fd, auio);
free(auio, M_IOV);
return (error);
}
int
freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
{
struct uio *auio;
int error;
error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
if (error)
return (error);
error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
free(auio, M_IOV);
return (error);
}
int
freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
{
struct uio *auio;
int error;
error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
if (error)
return (error);
error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
free(auio, M_IOV);
return (error);
}
int
freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
int error)
{
struct iovec32 iov32;
struct iovec *iov;
u_int iovlen;
int i;
*iovp = NULL;
if (iovcnt > UIO_MAXIOV)
return (error);
iovlen = iovcnt * sizeof(struct iovec);
iov = malloc(iovlen, M_IOV, M_WAITOK);
for (i = 0; i < iovcnt; i++) {
error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
if (error) {
free(iov, M_IOV);
return (error);
}
iov[i].iov_base = PTRIN(iov32.iov_base);
iov[i].iov_len = iov32.iov_len;
}
*iovp = iov;
return (0);
}
static int
freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
{
struct msghdr32 m32;
int error;
error = copyin(msg32, &m32, sizeof(m32));
if (error)
return (error);
msg->msg_name = PTRIN(m32.msg_name);
msg->msg_namelen = m32.msg_namelen;
msg->msg_iov = PTRIN(m32.msg_iov);
msg->msg_iovlen = m32.msg_iovlen;
msg->msg_control = PTRIN(m32.msg_control);
msg->msg_controllen = m32.msg_controllen;
msg->msg_flags = m32.msg_flags;
return (0);
}
static int
freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
{
struct msghdr32 m32;
int error;
m32.msg_name = PTROUT(msg->msg_name);
m32.msg_namelen = msg->msg_namelen;
m32.msg_iov = PTROUT(msg->msg_iov);
m32.msg_iovlen = msg->msg_iovlen;
m32.msg_control = PTROUT(msg->msg_control);
m32.msg_controllen = msg->msg_controllen;
m32.msg_flags = msg->msg_flags;
error = copyout(&m32, msg32, sizeof(m32));
return (error);
}
#ifndef __mips__
#define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
#else
#define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
#endif
#define FREEBSD32_ALIGN(p) \
(((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
#define FREEBSD32_CMSG_SPACE(l) \
(FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
#define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
static size_t
freebsd32_cmsg_convert(const struct cmsghdr *cm, void *data, socklen_t datalen)
{
size_t copylen;
union {
struct timespec32 ts;
struct timeval32 tv;
struct bintime32 bt;
} tmp32;
union {
struct timespec ts;
struct timeval tv;
struct bintime bt;
} *in;
in = data;
copylen = 0;
switch (cm->cmsg_level) {
case SOL_SOCKET:
switch (cm->cmsg_type) {
case SCM_TIMESTAMP:
TV_CP(*in, tmp32, tv);
copylen = sizeof(tmp32.tv);
break;
case SCM_BINTIME:
BT_CP(*in, tmp32, bt);
copylen = sizeof(tmp32.bt);
break;
case SCM_REALTIME:
case SCM_MONOTONIC:
TS_CP(*in, tmp32, ts);
copylen = sizeof(tmp32.ts);
break;
default:
break;
}
default:
break;
}
if (copylen == 0)
return (datalen);
KASSERT((datalen >= copylen), ("corrupted cmsghdr"));
bcopy(&tmp32, data, copylen);
return (copylen);
}
static int
freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
{
struct cmsghdr *cm;
void *data;
socklen_t clen, datalen, datalen_out, oldclen;
int error;
caddr_t ctlbuf;
int len, maxlen, copylen;
struct mbuf *m;
error = 0;
len = msg->msg_controllen;
maxlen = msg->msg_controllen;
msg->msg_controllen = 0;
ctlbuf = msg->msg_control;
for (m = control; m != NULL && len > 0; m = m->m_next) {
cm = mtod(m, struct cmsghdr *);
clen = m->m_len;
while (cm != NULL) {
if (sizeof(struct cmsghdr) > clen ||
cm->cmsg_len > clen) {
error = EINVAL;
break;
}
data = CMSG_DATA(cm);
datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
datalen_out = freebsd32_cmsg_convert(cm, data, datalen);
/*
* Copy out the message header. Preserve the native
* message size in case we need to inspect the message
* contents later.
*/
copylen = sizeof(struct cmsghdr);
if (len < copylen) {
msg->msg_flags |= MSG_CTRUNC;
m_dispose_extcontrolm(m);
goto exit;
}
oldclen = cm->cmsg_len;
cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
datalen_out;
error = copyout(cm, ctlbuf, copylen);
cm->cmsg_len = oldclen;
if (error != 0)
goto exit;
ctlbuf += FREEBSD32_ALIGN(copylen);
len -= FREEBSD32_ALIGN(copylen);
copylen = datalen_out;
if (len < copylen) {
msg->msg_flags |= MSG_CTRUNC;
m_dispose_extcontrolm(m);
break;
}
/* Copy out the message data. */
error = copyout(data, ctlbuf, copylen);
if (error)
goto exit;
ctlbuf += FREEBSD32_ALIGN(copylen);
len -= FREEBSD32_ALIGN(copylen);
if (CMSG_SPACE(datalen) < clen) {
clen -= CMSG_SPACE(datalen);
cm = (struct cmsghdr *)
((caddr_t)cm + CMSG_SPACE(datalen));
} else {
clen = 0;
cm = NULL;
}
msg->msg_controllen +=
FREEBSD32_CMSG_SPACE(datalen_out);
}
}
if (len == 0 && m != NULL) {
msg->msg_flags |= MSG_CTRUNC;
m_dispose_extcontrolm(m);
}
exit:
return (error);
}
int
freebsd32_recvmsg(td, uap)
struct thread *td;
struct freebsd32_recvmsg_args /* {
int s;
struct msghdr32 *msg;
int flags;
} */ *uap;
{
struct msghdr msg;
struct msghdr32 m32;
struct iovec *uiov, *iov;
struct mbuf *control = NULL;
struct mbuf **controlp;
int error;
error = copyin(uap->msg, &m32, sizeof(m32));
if (error)
return (error);
error = freebsd32_copyinmsghdr(uap->msg, &msg);
if (error)
return (error);
error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
EMSGSIZE);
if (error)
return (error);
msg.msg_flags = uap->flags;
uiov = msg.msg_iov;
msg.msg_iov = iov;
controlp = (msg.msg_control != NULL) ? &control : NULL;
error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
if (error == 0) {
msg.msg_iov = uiov;
if (control != NULL)
error = freebsd32_copy_msg_out(&msg, control);
else
msg.msg_controllen = 0;
if (error == 0)
error = freebsd32_copyoutmsghdr(&msg, uap->msg);
}
free(iov, M_IOV);
if (control != NULL) {
if (error != 0)
m_dispose_extcontrolm(control);
m_freem(control);
}
return (error);
}
/*
* Copy-in the array of control messages constructed using alignment
* and padding suitable for a 32-bit environment and construct an
* mbuf using alignment and padding suitable for a 64-bit kernel.
* The alignment and padding are defined indirectly by CMSG_DATA(),
* CMSG_SPACE() and CMSG_LEN().
*/
static int
freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
{
struct cmsghdr *cm;
struct mbuf *m;
void *in, *in1, *md;
u_int msglen, outlen;
int error;
if (buflen > MCLBYTES)
return (EINVAL);
in = malloc(buflen, M_TEMP, M_WAITOK);
error = copyin(buf, in, buflen);
if (error != 0)
goto out;
/*
* Make a pass over the input buffer to determine the amount of space
* required for 64 bit-aligned copies of the control messages.
*/
in1 = in;
outlen = 0;
while (buflen > 0) {
if (buflen < sizeof(*cm)) {
error = EINVAL;
break;
}
cm = (struct cmsghdr *)in1;
if (cm->cmsg_len < FREEBSD32_ALIGN(sizeof(*cm))) {
error = EINVAL;
break;
}
msglen = FREEBSD32_ALIGN(cm->cmsg_len);
if (msglen > buflen || msglen < cm->cmsg_len) {
error = EINVAL;
break;
}
buflen -= msglen;
in1 = (char *)in1 + msglen;
outlen += CMSG_ALIGN(sizeof(*cm)) +
CMSG_ALIGN(msglen - FREEBSD32_ALIGN(sizeof(*cm)));
}
if (error == 0 && outlen > MCLBYTES) {
/*
* XXXMJ This implies that the upper limit on 32-bit aligned
* control messages is less than MCLBYTES, and so we are not
* perfectly compatible. However, there is no platform
* guarantee that mbuf clusters larger than MCLBYTES can be
* allocated.
*/
error = EINVAL;
}
if (error != 0)
goto out;
m = m_get2(outlen, M_WAITOK, MT_CONTROL, 0);
m->m_len = outlen;
md = mtod(m, void *);
/*
* Make a second pass over input messages, copying them into the output
* buffer.
*/
in1 = in;
while (outlen > 0) {
/* Copy the message header and align the length field. */
cm = md;
memcpy(cm, in1, sizeof(*cm));
msglen = cm->cmsg_len - FREEBSD32_ALIGN(sizeof(*cm));
cm->cmsg_len = CMSG_ALIGN(sizeof(*cm)) + msglen;
/* Copy the message body. */
in1 = (char *)in1 + FREEBSD32_ALIGN(sizeof(*cm));
md = (char *)md + CMSG_ALIGN(sizeof(*cm));
memcpy(md, in1, msglen);
in1 = (char *)in1 + FREEBSD32_ALIGN(msglen);
md = (char *)md + CMSG_ALIGN(msglen);
KASSERT(outlen >= CMSG_ALIGN(sizeof(*cm)) + CMSG_ALIGN(msglen),
("outlen %u underflow, msglen %u", outlen, msglen));
outlen -= CMSG_ALIGN(sizeof(*cm)) + CMSG_ALIGN(msglen);
}
*mp = m;
out:
free(in, M_TEMP);
return (error);
}
int
freebsd32_sendmsg(struct thread *td,
struct freebsd32_sendmsg_args *uap)
{
struct msghdr msg;
struct msghdr32 m32;
struct iovec *iov;
struct mbuf *control = NULL;
struct sockaddr *to = NULL;
int error;
error = copyin(uap->msg, &m32, sizeof(m32));
if (error)
return (error);
error = freebsd32_copyinmsghdr(uap->msg, &msg);
if (error)
return (error);
error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
EMSGSIZE);
if (error)
return (error);
msg.msg_iov = iov;
if (msg.msg_name != NULL) {
error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
if (error) {
to = NULL;
goto out;
}
msg.msg_name = to;
}
if (msg.msg_control) {
if (msg.msg_controllen < sizeof(struct cmsghdr)) {
error = EINVAL;
goto out;
}
error = freebsd32_copyin_control(&control, msg.msg_control,
msg.msg_controllen);
if (error)
goto out;
msg.msg_control = NULL;
msg.msg_controllen = 0;
}
error = kern_sendit(td, uap->s, &msg, uap->flags, control,
UIO_USERSPACE);
out:
free(iov, M_IOV);
if (to)
free(to, M_SONAME);
return (error);
}
int
freebsd32_recvfrom(struct thread *td,
struct freebsd32_recvfrom_args *uap)
{
struct msghdr msg;
struct iovec aiov;
int error;
if (uap->fromlenaddr) {
error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
sizeof(msg.msg_namelen));
if (error)
return (error);
} else {
msg.msg_namelen = 0;
}
msg.msg_name = PTRIN(uap->from);
msg.msg_iov = &aiov;
msg.msg_iovlen = 1;
aiov.iov_base = PTRIN(uap->buf);
aiov.iov_len = uap->len;
msg.msg_control = NULL;
msg.msg_flags = uap->flags;
error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
if (error == 0 && uap->fromlenaddr)
error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
sizeof (msg.msg_namelen));
return (error);
}
int
freebsd32_settimeofday(struct thread *td,
struct freebsd32_settimeofday_args *uap)
{
struct timeval32 tv32;
struct timeval tv, *tvp;
struct timezone tz, *tzp;
int error;
if (uap->tv) {
error = copyin(uap->tv, &tv32, sizeof(tv32));
if (error)
return (error);
CP(tv32, tv, tv_sec);
CP(tv32, tv, tv_usec);
tvp = &tv;
} else
tvp = NULL;
if (uap->tzp) {
error = copyin(uap->tzp, &tz, sizeof(tz));
if (error)
return (error);
tzp = &tz;
} else
tzp = NULL;
return (kern_settimeofday(td, tvp, tzp));
}
int
freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
{
struct timeval32 s32[2];
struct timeval s[2], *sp;
int error;
if (uap->tptr != NULL) {
error = copyin(uap->tptr, s32, sizeof(s32));
if (error)
return (error);
CP(s32[0], s[0], tv_sec);
CP(s32[0], s[0], tv_usec);
CP(s32[1], s[1], tv_sec);
CP(s32[1], s[1], tv_usec);
sp = s;
} else
sp = NULL;
return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
sp, UIO_SYSSPACE));
}
int
freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
{
struct timeval32 s32[2];
struct timeval s[2], *sp;
int error;
if (uap->tptr != NULL) {
error = copyin(uap->tptr, s32, sizeof(s32));
if (error)
return (error);
CP(s32[0], s[0], tv_sec);
CP(s32[0], s[0], tv_usec);
CP(s32[1], s[1], tv_sec);
CP(s32[1], s[1], tv_usec);
sp = s;
} else
sp = NULL;
return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
}
int
freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
{
struct timeval32 s32[2];
struct timeval s[2], *sp;
int error;
if (uap->tptr != NULL) {
error = copyin(uap->tptr, s32, sizeof(s32));
if (error)
return (error);
CP(s32[0], s[0], tv_sec);
CP(s32[0], s[0], tv_usec);
CP(s32[1], s[1], tv_sec);
CP(s32[1], s[1], tv_usec);
sp = s;
} else
sp = NULL;
return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
}
int
freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
{
struct timeval32 s32[2];
struct timeval s[2], *sp;
int error;
if (uap->times != NULL) {
error = copyin(uap->times, s32, sizeof(s32));
if (error)
return (error);
CP(s32[0], s[0], tv_sec);
CP(s32[0], s[0], tv_usec);
CP(s32[1], s[1], tv_sec);
CP(s32[1], s[1], tv_usec);
sp = s;
} else
sp = NULL;
return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
sp, UIO_SYSSPACE));
}
int
freebsd32_futimens(struct thread *td, struct freebsd32_futimens_args *uap)
{
struct timespec32 ts32[2];
struct timespec ts[2], *tsp;
int error;
if (uap->times != NULL) {
error = copyin(uap->times, ts32, sizeof(ts32));
if (error)
return (error);
CP(ts32[0], ts[0], tv_sec);
CP(ts32[0], ts[0], tv_nsec);
CP(ts32[1], ts[1], tv_sec);
CP(ts32[1], ts[1], tv_nsec);
tsp = ts;
} else
tsp = NULL;
return (kern_futimens(td, uap->fd, tsp, UIO_SYSSPACE));
}
int
freebsd32_utimensat(struct thread *td, struct freebsd32_utimensat_args *uap)
{
struct timespec32 ts32[2];
struct timespec ts[2], *tsp;
int error;
if (uap->times != NULL) {
error = copyin(uap->times, ts32, sizeof(ts32));
if (error)
return (error);
CP(ts32[0], ts[0], tv_sec);
CP(ts32[0], ts[0], tv_nsec);
CP(ts32[1], ts[1], tv_sec);
CP(ts32[1], ts[1], tv_nsec);
tsp = ts;
} else
tsp = NULL;
return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE,
tsp, UIO_SYSSPACE, uap->flag));
}
int
freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
{
struct timeval32 tv32;
struct timeval delta, olddelta, *deltap;
int error;
if (uap->delta) {
error = copyin(uap->delta, &tv32, sizeof(tv32));
if (error)
return (error);
CP(tv32, delta, tv_sec);
CP(tv32, delta, tv_usec);
deltap = δ
} else
deltap = NULL;
error = kern_adjtime(td, deltap, &olddelta);
if (uap->olddelta && error == 0) {
CP(olddelta, tv32, tv_sec);
CP(olddelta, tv32, tv_usec);
error = copyout(&tv32, uap->olddelta, sizeof(tv32));
}
return (error);
}
#ifdef COMPAT_FREEBSD4
int
freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
{
struct statfs32 s32;
struct statfs *sp;
int error;
sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
error = kern_statfs(td, uap->path, UIO_USERSPACE, sp);
if (error == 0) {
copy_statfs(sp, &s32);
error = copyout(&s32, uap->buf, sizeof(s32));
}
free(sp, M_STATFS);
return (error);
}
#endif
#ifdef COMPAT_FREEBSD4
int
freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
{
struct statfs32 s32;
struct statfs *sp;
int error;
sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
error = kern_fstatfs(td, uap->fd, sp);
if (error == 0) {
copy_statfs(sp, &s32);
error = copyout(&s32, uap->buf, sizeof(s32));
}
free(sp, M_STATFS);
return (error);
}
#endif
#ifdef COMPAT_FREEBSD4
int
freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
{
struct statfs32 s32;
struct statfs *sp;
fhandle_t fh;
int error;
if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
return (error);
sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
error = kern_fhstatfs(td, fh, sp);
if (error == 0) {
copy_statfs(sp, &s32);
error = copyout(&s32, uap->buf, sizeof(s32));
}
free(sp, M_STATFS);
return (error);
}
#endif
int
freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
{
return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
PAIR32TO64(off_t, uap->offset)));
}
int
freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
{
return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
PAIR32TO64(off_t, uap->offset)));
}
#ifdef COMPAT_43
int
ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
{
return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
}
#endif
int
freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
{
int error;
off_t pos;
error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
uap->whence);
/* Expand the quad return into two parts for eax and edx */
pos = td->td_uretoff.tdu_off;
td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
return error;
}
int
freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
{
return (kern_truncate(td, uap->path, UIO_USERSPACE,
PAIR32TO64(off_t, uap->length)));
}
int
freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
{
return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
}
#ifdef COMPAT_43
int
ofreebsd32_getdirentries(struct thread *td,
struct ofreebsd32_getdirentries_args *uap)
{
struct ogetdirentries_args ap;
int error;
long loff;
int32_t loff_cut;
ap.fd = uap->fd;
ap.buf = uap->buf;
ap.count = uap->count;
ap.basep = NULL;
error = kern_ogetdirentries(td, &ap, &loff);
if (error == 0) {
loff_cut = loff;
error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
}
return (error);
}
#endif
#if defined(COMPAT_FREEBSD11)
int
freebsd11_freebsd32_getdirentries(struct thread *td,
struct freebsd11_freebsd32_getdirentries_args *uap)
{
long base;
int32_t base32;
int error;
error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count,
&base, NULL);
if (error)
return (error);
if (uap->basep != NULL) {
base32 = base;
error = copyout(&base32, uap->basep, sizeof(int32_t));
}
return (error);
}
int
freebsd11_freebsd32_getdents(struct thread *td,
struct freebsd11_freebsd32_getdents_args *uap)
{
struct freebsd11_freebsd32_getdirentries_args ap;
ap.fd = uap->fd;
ap.buf = uap->buf;
ap.count = uap->count;
ap.basep = NULL;
return (freebsd11_freebsd32_getdirentries(td, &ap));
}
#endif /* COMPAT_FREEBSD11 */
#ifdef COMPAT_FREEBSD6
/* versions with the 'int pad' argument */
int
freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
{
return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
PAIR32TO64(off_t, uap->offset)));
}
int
freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
{
return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
PAIR32TO64(off_t, uap->offset)));
}
int
freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
{
int error;
off_t pos;
error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
uap->whence);
/* Expand the quad return into two parts for eax and edx */
pos = *(off_t *)(td->td_retval);
td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
return error;
}
int
freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
{
return (kern_truncate(td, uap->path, UIO_USERSPACE,
PAIR32TO64(off_t, uap->length)));
}
int
freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
{
return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
}
#endif /* COMPAT_FREEBSD6 */
struct sf_hdtr32 {
uint32_t headers;
int hdr_cnt;
uint32_t trailers;
int trl_cnt;
};
static int
freebsd32_do_sendfile(struct thread *td,
struct freebsd32_sendfile_args *uap, int compat)
{
struct sf_hdtr32 hdtr32;
struct sf_hdtr hdtr;
struct uio *hdr_uio, *trl_uio;
struct file *fp;
cap_rights_t rights;
struct iovec32 *iov32;
off_t offset, sbytes;
int error;
offset = PAIR32TO64(off_t, uap->offset);
if (offset < 0)
return (EINVAL);
hdr_uio = trl_uio = NULL;
if (uap->hdtr != NULL) {
error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
if (error)
goto out;
PTRIN_CP(hdtr32, hdtr, headers);
CP(hdtr32, hdtr, hdr_cnt);
PTRIN_CP(hdtr32, hdtr, trailers);
CP(hdtr32, hdtr, trl_cnt);
if (hdtr.headers != NULL) {
iov32 = PTRIN(hdtr32.headers);
error = freebsd32_copyinuio(iov32,
hdtr32.hdr_cnt, &hdr_uio);
if (error)
goto out;
#ifdef COMPAT_FREEBSD4
/*
* In FreeBSD < 5.0 the nbytes to send also included
* the header. If compat is specified subtract the
* header size from nbytes.
*/
if (compat) {
if (uap->nbytes > hdr_uio->uio_resid)
uap->nbytes -= hdr_uio->uio_resid;
else
uap->nbytes = 0;
}
#endif
}
if (hdtr.trailers != NULL) {
iov32 = PTRIN(hdtr32.trailers);
error = freebsd32_copyinuio(iov32,
hdtr32.trl_cnt, &trl_uio);
if (error)
goto out;
}
}
AUDIT_ARG_FD(uap->fd);
if ((error = fget_read(td, uap->fd,
- cap_rights_init(&rights, CAP_PREAD), &fp)) != 0)
+ cap_rights_init_one(&rights, CAP_PREAD), &fp)) != 0)
goto out;
error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
uap->nbytes, &sbytes, uap->flags, td);
fdrop(fp, td);
if (uap->sbytes != NULL)
copyout(&sbytes, uap->sbytes, sizeof(off_t));
out:
if (hdr_uio)
free(hdr_uio, M_IOV);
if (trl_uio)
free(trl_uio, M_IOV);
return (error);
}
#ifdef COMPAT_FREEBSD4
int
freebsd4_freebsd32_sendfile(struct thread *td,
struct freebsd4_freebsd32_sendfile_args *uap)
{
return (freebsd32_do_sendfile(td,
(struct freebsd32_sendfile_args *)uap, 1));
}
#endif
int
freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
{
return (freebsd32_do_sendfile(td, uap, 0));
}
static void
copy_stat(struct stat *in, struct stat32 *out)
{
CP(*in, *out, st_dev);
CP(*in, *out, st_ino);
CP(*in, *out, st_mode);
CP(*in, *out, st_nlink);
CP(*in, *out, st_uid);
CP(*in, *out, st_gid);
CP(*in, *out, st_rdev);
TS_CP(*in, *out, st_atim);
TS_CP(*in, *out, st_mtim);
TS_CP(*in, *out, st_ctim);
CP(*in, *out, st_size);
CP(*in, *out, st_blocks);
CP(*in, *out, st_blksize);
CP(*in, *out, st_flags);
CP(*in, *out, st_gen);
TS_CP(*in, *out, st_birthtim);
out->st_padding0 = 0;
out->st_padding1 = 0;
#ifdef __STAT32_TIME_T_EXT
out->st_atim_ext = 0;
out->st_mtim_ext = 0;
out->st_ctim_ext = 0;
out->st_btim_ext = 0;
#endif
bzero(out->st_spare, sizeof(out->st_spare));
}
#ifdef COMPAT_43
static void
copy_ostat(struct stat *in, struct ostat32 *out)
{
bzero(out, sizeof(*out));
CP(*in, *out, st_dev);
CP(*in, *out, st_ino);
CP(*in, *out, st_mode);
CP(*in, *out, st_nlink);
CP(*in, *out, st_uid);
CP(*in, *out, st_gid);
CP(*in, *out, st_rdev);
out->st_size = MIN(in->st_size, INT32_MAX);
TS_CP(*in, *out, st_atim);
TS_CP(*in, *out, st_mtim);
TS_CP(*in, *out, st_ctim);
CP(*in, *out, st_blksize);
CP(*in, *out, st_blocks);
CP(*in, *out, st_flags);
CP(*in, *out, st_gen);
}
#endif
#ifdef COMPAT_43
int
ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
{
struct stat sb;
struct ostat32 sb32;
int error;
error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
&sb, NULL);
if (error)
return (error);
copy_ostat(&sb, &sb32);
error = copyout(&sb32, uap->ub, sizeof (sb32));
return (error);
}
#endif
int
freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
{
struct stat ub;
struct stat32 ub32;
int error;
error = kern_fstat(td, uap->fd, &ub);
if (error)
return (error);
copy_stat(&ub, &ub32);
error = copyout(&ub32, uap->ub, sizeof(ub32));
return (error);
}
#ifdef COMPAT_43
int
ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
{
struct stat ub;
struct ostat32 ub32;
int error;
error = kern_fstat(td, uap->fd, &ub);
if (error)
return (error);
copy_ostat(&ub, &ub32);
error = copyout(&ub32, uap->ub, sizeof(ub32));
return (error);
}
#endif
int
freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
{
struct stat ub;
struct stat32 ub32;
int error;
error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
&ub, NULL);
if (error)
return (error);
copy_stat(&ub, &ub32);
error = copyout(&ub32, uap->buf, sizeof(ub32));
return (error);
}
#ifdef COMPAT_43
int
ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
{
struct stat sb;
struct ostat32 sb32;
int error;
error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
UIO_USERSPACE, &sb, NULL);
if (error)
return (error);
copy_ostat(&sb, &sb32);
error = copyout(&sb32, uap->ub, sizeof (sb32));
return (error);
}
#endif
int
freebsd32_fhstat(struct thread *td, struct freebsd32_fhstat_args *uap)
{
struct stat sb;
struct stat32 sb32;
struct fhandle fh;
int error;
error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
if (error != 0)
return (error);
error = kern_fhstat(td, fh, &sb);
if (error != 0)
return (error);
copy_stat(&sb, &sb32);
error = copyout(&sb32, uap->sb, sizeof (sb32));
return (error);
}
#if defined(COMPAT_FREEBSD11)
extern int ino64_trunc_error;
static int
freebsd11_cvtstat32(struct stat *in, struct freebsd11_stat32 *out)
{
CP(*in, *out, st_ino);
if (in->st_ino != out->st_ino) {
switch (ino64_trunc_error) {
default:
case 0:
break;
case 1:
return (EOVERFLOW);
case 2:
out->st_ino = UINT32_MAX;
break;
}
}
CP(*in, *out, st_nlink);
if (in->st_nlink != out->st_nlink) {
switch (ino64_trunc_error) {
default:
case 0:
break;
case 1:
return (EOVERFLOW);
case 2:
out->st_nlink = UINT16_MAX;
break;
}
}
out->st_dev = in->st_dev;
if (out->st_dev != in->st_dev) {
switch (ino64_trunc_error) {
default:
break;
case 1:
return (EOVERFLOW);
}
}
CP(*in, *out, st_mode);
CP(*in, *out, st_uid);
CP(*in, *out, st_gid);
out->st_rdev = in->st_rdev;
if (out->st_rdev != in->st_rdev) {
switch (ino64_trunc_error) {
default:
break;
case 1:
return (EOVERFLOW);
}
}
TS_CP(*in, *out, st_atim);
TS_CP(*in, *out, st_mtim);
TS_CP(*in, *out, st_ctim);
CP(*in, *out, st_size);
CP(*in, *out, st_blocks);
CP(*in, *out, st_blksize);
CP(*in, *out, st_flags);
CP(*in, *out, st_gen);
TS_CP(*in, *out, st_birthtim);
out->st_lspare = 0;
bzero((char *)&out->st_birthtim + sizeof(out->st_birthtim),
sizeof(*out) - offsetof(struct freebsd11_stat32,
st_birthtim) - sizeof(out->st_birthtim));
return (0);
}
int
freebsd11_freebsd32_stat(struct thread *td,
struct freebsd11_freebsd32_stat_args *uap)
{
struct stat sb;
struct freebsd11_stat32 sb32;
int error;
error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
&sb, NULL);
if (error != 0)
return (error);
error = freebsd11_cvtstat32(&sb, &sb32);
if (error == 0)
error = copyout(&sb32, uap->ub, sizeof (sb32));
return (error);
}
int
freebsd11_freebsd32_fstat(struct thread *td,
struct freebsd11_freebsd32_fstat_args *uap)
{
struct stat sb;
struct freebsd11_stat32 sb32;
int error;
error = kern_fstat(td, uap->fd, &sb);
if (error != 0)
return (error);
error = freebsd11_cvtstat32(&sb, &sb32);
if (error == 0)
error = copyout(&sb32, uap->ub, sizeof (sb32));
return (error);
}
int
freebsd11_freebsd32_fstatat(struct thread *td,
struct freebsd11_freebsd32_fstatat_args *uap)
{
struct stat sb;
struct freebsd11_stat32 sb32;
int error;
error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
&sb, NULL);
if (error != 0)
return (error);
error = freebsd11_cvtstat32(&sb, &sb32);
if (error == 0)
error = copyout(&sb32, uap->buf, sizeof (sb32));
return (error);
}
int
freebsd11_freebsd32_lstat(struct thread *td,
struct freebsd11_freebsd32_lstat_args *uap)
{
struct stat sb;
struct freebsd11_stat32 sb32;
int error;
error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
UIO_USERSPACE, &sb, NULL);
if (error != 0)
return (error);
error = freebsd11_cvtstat32(&sb, &sb32);
if (error == 0)
error = copyout(&sb32, uap->ub, sizeof (sb32));
return (error);
}
int
freebsd11_freebsd32_fhstat(struct thread *td,
struct freebsd11_freebsd32_fhstat_args *uap)
{
struct stat sb;
struct freebsd11_stat32 sb32;
struct fhandle fh;
int error;
error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
if (error != 0)
return (error);
error = kern_fhstat(td, fh, &sb);
if (error != 0)
return (error);
error = freebsd11_cvtstat32(&sb, &sb32);
if (error == 0)
error = copyout(&sb32, uap->sb, sizeof (sb32));
return (error);
}
#endif
int
freebsd32___sysctl(struct thread *td, struct freebsd32___sysctl_args *uap)
{
int error, name[CTL_MAXNAME];
size_t j, oldlen;
uint32_t tmp;
if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
return (EINVAL);
error = copyin(uap->name, name, uap->namelen * sizeof(int));
if (error)
return (error);
if (uap->oldlenp) {
error = fueword32(uap->oldlenp, &tmp);
oldlen = tmp;
} else {
oldlen = 0;
}
if (error != 0)
return (EFAULT);
error = userland_sysctl(td, name, uap->namelen,
uap->old, &oldlen, 1,
uap->new, uap->newlen, &j, SCTL_MASK32);
if (error)
return (error);
if (uap->oldlenp)
suword32(uap->oldlenp, j);
return (0);
}
int
freebsd32___sysctlbyname(struct thread *td,
struct freebsd32___sysctlbyname_args *uap)
{
size_t oldlen, rv;
int error;
uint32_t tmp;
if (uap->oldlenp != NULL) {
error = fueword32(uap->oldlenp, &tmp);
oldlen = tmp;
} else {
error = oldlen = 0;
}
if (error != 0)
return (EFAULT);
error = kern___sysctlbyname(td, uap->name, uap->namelen, uap->old,
&oldlen, uap->new, uap->newlen, &rv, SCTL_MASK32, 1);
if (error != 0)
return (error);
if (uap->oldlenp != NULL)
error = suword32(uap->oldlenp, rv);
return (error);
}
int
freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
{
uint32_t version;
int error;
struct jail j;
error = copyin(uap->jail, &version, sizeof(uint32_t));
if (error)
return (error);
switch (version) {
case 0:
{
/* FreeBSD single IPv4 jails. */
struct jail32_v0 j32_v0;
bzero(&j, sizeof(struct jail));
error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
if (error)
return (error);
CP(j32_v0, j, version);
PTRIN_CP(j32_v0, j, path);
PTRIN_CP(j32_v0, j, hostname);
j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
break;
}
case 1:
/*
* Version 1 was used by multi-IPv4 jail implementations
* that never made it into the official kernel.
*/
return (EINVAL);
case 2: /* JAIL_API_VERSION */
{
/* FreeBSD multi-IPv4/IPv6,noIP jails. */
struct jail32 j32;
error = copyin(uap->jail, &j32, sizeof(struct jail32));
if (error)
return (error);
CP(j32, j, version);
PTRIN_CP(j32, j, path);
PTRIN_CP(j32, j, hostname);
PTRIN_CP(j32, j, jailname);
CP(j32, j, ip4s);
CP(j32, j, ip6s);
PTRIN_CP(j32, j, ip4);
PTRIN_CP(j32, j, ip6);
break;
}
default:
/* Sci-Fi jails are not supported, sorry. */
return (EINVAL);
}
return (kern_jail(td, &j));
}
int
freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
{
struct uio *auio;
int error;
/* Check that we have an even number of iovecs. */
if (uap->iovcnt & 1)
return (EINVAL);
error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
if (error)
return (error);
error = kern_jail_set(td, auio, uap->flags);
free(auio, M_IOV);
return (error);
}
int
freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
{
struct iovec32 iov32;
struct uio *auio;
int error, i;
/* Check that we have an even number of iovecs. */
if (uap->iovcnt & 1)
return (EINVAL);
error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
if (error)
return (error);
error = kern_jail_get(td, auio, uap->flags);
if (error == 0)
for (i = 0; i < uap->iovcnt; i++) {
PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
CP(auio->uio_iov[i], iov32, iov_len);
error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
if (error != 0)
break;
}
free(auio, M_IOV);
return (error);
}
int
freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
{
struct sigaction32 s32;
struct sigaction sa, osa, *sap;
int error;
if (uap->act) {
error = copyin(uap->act, &s32, sizeof(s32));
if (error)
return (error);
sa.sa_handler = PTRIN(s32.sa_u);
CP(s32, sa, sa_flags);
CP(s32, sa, sa_mask);
sap = &sa;
} else
sap = NULL;
error = kern_sigaction(td, uap->sig, sap, &osa, 0);
if (error == 0 && uap->oact != NULL) {
s32.sa_u = PTROUT(osa.sa_handler);
CP(osa, s32, sa_flags);
CP(osa, s32, sa_mask);
error = copyout(&s32, uap->oact, sizeof(s32));
}
return (error);
}
#ifdef COMPAT_FREEBSD4
int
freebsd4_freebsd32_sigaction(struct thread *td,
struct freebsd4_freebsd32_sigaction_args *uap)
{
struct sigaction32 s32;
struct sigaction sa, osa, *sap;
int error;
if (uap->act) {
error = copyin(uap->act, &s32, sizeof(s32));
if (error)
return (error);
sa.sa_handler = PTRIN(s32.sa_u);
CP(s32, sa, sa_flags);
CP(s32, sa, sa_mask);
sap = &sa;
} else
sap = NULL;
error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
if (error == 0 && uap->oact != NULL) {
s32.sa_u = PTROUT(osa.sa_handler);
CP(osa, s32, sa_flags);
CP(osa, s32, sa_mask);
error = copyout(&s32, uap->oact, sizeof(s32));
}
return (error);
}
#endif
#ifdef COMPAT_43
struct osigaction32 {
u_int32_t sa_u;
osigset_t sa_mask;
int sa_flags;
};
#define ONSIG 32
int
ofreebsd32_sigaction(struct thread *td,
struct ofreebsd32_sigaction_args *uap)
{
struct osigaction32 s32;
struct sigaction sa, osa, *sap;
int error;
if (uap->signum <= 0 || uap->signum >= ONSIG)
return (EINVAL);
if (uap->nsa) {
error = copyin(uap->nsa, &s32, sizeof(s32));
if (error)
return (error);
sa.sa_handler = PTRIN(s32.sa_u);
CP(s32, sa, sa_flags);
OSIG2SIG(s32.sa_mask, sa.sa_mask);
sap = &sa;
} else
sap = NULL;
error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
if (error == 0 && uap->osa != NULL) {
s32.sa_u = PTROUT(osa.sa_handler);
CP(osa, s32, sa_flags);
SIG2OSIG(osa.sa_mask, s32.sa_mask);
error = copyout(&s32, uap->osa, sizeof(s32));
}
return (error);
}
int
ofreebsd32_sigprocmask(struct thread *td,
struct ofreebsd32_sigprocmask_args *uap)
{
sigset_t set, oset;
int error;
OSIG2SIG(uap->mask, set);
error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
SIG2OSIG(oset, td->td_retval[0]);
return (error);
}
int
ofreebsd32_sigpending(struct thread *td,
struct ofreebsd32_sigpending_args *uap)
{
struct proc *p = td->td_proc;
sigset_t siglist;
PROC_LOCK(p);
siglist = p->p_siglist;
SIGSETOR(siglist, td->td_siglist);
PROC_UNLOCK(p);
SIG2OSIG(siglist, td->td_retval[0]);
return (0);
}
struct sigvec32 {
u_int32_t sv_handler;
int sv_mask;
int sv_flags;
};
int
ofreebsd32_sigvec(struct thread *td,
struct ofreebsd32_sigvec_args *uap)
{
struct sigvec32 vec;
struct sigaction sa, osa, *sap;
int error;
if (uap->signum <= 0 || uap->signum >= ONSIG)
return (EINVAL);
if (uap->nsv) {
error = copyin(uap->nsv, &vec, sizeof(vec));
if (error)
return (error);
sa.sa_handler = PTRIN(vec.sv_handler);
OSIG2SIG(vec.sv_mask, sa.sa_mask);
sa.sa_flags = vec.sv_flags;
sa.sa_flags ^= SA_RESTART;
sap = &sa;
} else
sap = NULL;
error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
if (error == 0 && uap->osv != NULL) {
vec.sv_handler = PTROUT(osa.sa_handler);
SIG2OSIG(osa.sa_mask, vec.sv_mask);
vec.sv_flags = osa.sa_flags;
vec.sv_flags &= ~SA_NOCLDWAIT;
vec.sv_flags ^= SA_RESTART;
error = copyout(&vec, uap->osv, sizeof(vec));
}
return (error);
}
int
ofreebsd32_sigblock(struct thread *td,
struct ofreebsd32_sigblock_args *uap)
{
sigset_t set, oset;
OSIG2SIG(uap->mask, set);
kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
SIG2OSIG(oset, td->td_retval[0]);
return (0);
}
int
ofreebsd32_sigsetmask(struct thread *td,
struct ofreebsd32_sigsetmask_args *uap)
{
sigset_t set, oset;
OSIG2SIG(uap->mask, set);
kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
SIG2OSIG(oset, td->td_retval[0]);
return (0);
}
int
ofreebsd32_sigsuspend(struct thread *td,
struct ofreebsd32_sigsuspend_args *uap)
{
sigset_t mask;
OSIG2SIG(uap->mask, mask);
return (kern_sigsuspend(td, mask));
}
struct sigstack32 {
u_int32_t ss_sp;
int ss_onstack;
};
int
ofreebsd32_sigstack(struct thread *td,
struct ofreebsd32_sigstack_args *uap)
{
struct sigstack32 s32;
struct sigstack nss, oss;
int error = 0, unss;
if (uap->nss != NULL) {
error = copyin(uap->nss, &s32, sizeof(s32));
if (error)
return (error);
nss.ss_sp = PTRIN(s32.ss_sp);
CP(s32, nss, ss_onstack);
unss = 1;
} else {
unss = 0;
}
oss.ss_sp = td->td_sigstk.ss_sp;
oss.ss_onstack = sigonstack(cpu_getstack(td));
if (unss) {
td->td_sigstk.ss_sp = nss.ss_sp;
td->td_sigstk.ss_size = 0;
td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
td->td_pflags |= TDP_ALTSTACK;
}
if (uap->oss != NULL) {
s32.ss_sp = PTROUT(oss.ss_sp);
CP(oss, s32, ss_onstack);
error = copyout(&s32, uap->oss, sizeof(s32));
}
return (error);
}
#endif
int
freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
{
return (freebsd32_user_clock_nanosleep(td, CLOCK_REALTIME,
TIMER_RELTIME, uap->rqtp, uap->rmtp));
}
int
freebsd32_clock_nanosleep(struct thread *td,
struct freebsd32_clock_nanosleep_args *uap)
{
int error;
error = freebsd32_user_clock_nanosleep(td, uap->clock_id, uap->flags,
uap->rqtp, uap->rmtp);
return (kern_posix_error(td, error));
}
static int
freebsd32_user_clock_nanosleep(struct thread *td, clockid_t clock_id,
int flags, const struct timespec32 *ua_rqtp, struct timespec32 *ua_rmtp)
{
struct timespec32 rmt32, rqt32;
struct timespec rmt, rqt;
int error, error2;
error = copyin(ua_rqtp, &rqt32, sizeof(rqt32));
if (error)
return (error);
CP(rqt32, rqt, tv_sec);
CP(rqt32, rqt, tv_nsec);
error = kern_clock_nanosleep(td, clock_id, flags, &rqt, &rmt);
if (error == EINTR && ua_rmtp != NULL && (flags & TIMER_ABSTIME) == 0) {
CP(rmt, rmt32, tv_sec);
CP(rmt, rmt32, tv_nsec);
error2 = copyout(&rmt32, ua_rmtp, sizeof(rmt32));
if (error2 != 0)
error = error2;
}
return (error);
}
int
freebsd32_clock_gettime(struct thread *td,
struct freebsd32_clock_gettime_args *uap)
{
struct timespec ats;
struct timespec32 ats32;
int error;
error = kern_clock_gettime(td, uap->clock_id, &ats);
if (error == 0) {
CP(ats, ats32, tv_sec);
CP(ats, ats32, tv_nsec);
error = copyout(&ats32, uap->tp, sizeof(ats32));
}
return (error);
}
int
freebsd32_clock_settime(struct thread *td,
struct freebsd32_clock_settime_args *uap)
{
struct timespec ats;
struct timespec32 ats32;
int error;
error = copyin(uap->tp, &ats32, sizeof(ats32));
if (error)
return (error);
CP(ats32, ats, tv_sec);
CP(ats32, ats, tv_nsec);
return (kern_clock_settime(td, uap->clock_id, &ats));
}
int
freebsd32_clock_getres(struct thread *td,
struct freebsd32_clock_getres_args *uap)
{
struct timespec ts;
struct timespec32 ts32;
int error;
if (uap->tp == NULL)
return (0);
error = kern_clock_getres(td, uap->clock_id, &ts);
if (error == 0) {
CP(ts, ts32, tv_sec);
CP(ts, ts32, tv_nsec);
error = copyout(&ts32, uap->tp, sizeof(ts32));
}
return (error);
}
int freebsd32_ktimer_create(struct thread *td,
struct freebsd32_ktimer_create_args *uap)
{
struct sigevent32 ev32;
struct sigevent ev, *evp;
int error, id;
if (uap->evp == NULL) {
evp = NULL;
} else {
evp = &ev;
error = copyin(uap->evp, &ev32, sizeof(ev32));
if (error != 0)
return (error);
error = convert_sigevent32(&ev32, &ev);
if (error != 0)
return (error);
}
error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
if (error == 0) {
error = copyout(&id, uap->timerid, sizeof(int));
if (error != 0)
kern_ktimer_delete(td, id);
}
return (error);
}
int
freebsd32_ktimer_settime(struct thread *td,
struct freebsd32_ktimer_settime_args *uap)
{
struct itimerspec32 val32, oval32;
struct itimerspec val, oval, *ovalp;
int error;
error = copyin(uap->value, &val32, sizeof(val32));
if (error != 0)
return (error);
ITS_CP(val32, val);
ovalp = uap->ovalue != NULL ? &oval : NULL;
error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
if (error == 0 && uap->ovalue != NULL) {
ITS_CP(oval, oval32);
error = copyout(&oval32, uap->ovalue, sizeof(oval32));
}
return (error);
}
int
freebsd32_ktimer_gettime(struct thread *td,
struct freebsd32_ktimer_gettime_args *uap)
{
struct itimerspec32 val32;
struct itimerspec val;
int error;
error = kern_ktimer_gettime(td, uap->timerid, &val);
if (error == 0) {
ITS_CP(val, val32);
error = copyout(&val32, uap->value, sizeof(val32));
}
return (error);
}
int
freebsd32_clock_getcpuclockid2(struct thread *td,
struct freebsd32_clock_getcpuclockid2_args *uap)
{
clockid_t clk_id;
int error;
error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
uap->which, &clk_id);
if (error == 0)
error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
return (error);
}
int
freebsd32_thr_new(struct thread *td,
struct freebsd32_thr_new_args *uap)
{
struct thr_param32 param32;
struct thr_param param;
int error;
if (uap->param_size < 0 ||
uap->param_size > sizeof(struct thr_param32))
return (EINVAL);
bzero(¶m, sizeof(struct thr_param));
bzero(¶m32, sizeof(struct thr_param32));
error = copyin(uap->param, ¶m32, uap->param_size);
if (error != 0)
return (error);
param.start_func = PTRIN(param32.start_func);
param.arg = PTRIN(param32.arg);
param.stack_base = PTRIN(param32.stack_base);
param.stack_size = param32.stack_size;
param.tls_base = PTRIN(param32.tls_base);
param.tls_size = param32.tls_size;
param.child_tid = PTRIN(param32.child_tid);
param.parent_tid = PTRIN(param32.parent_tid);
param.flags = param32.flags;
param.rtp = PTRIN(param32.rtp);
param.spare[0] = PTRIN(param32.spare[0]);
param.spare[1] = PTRIN(param32.spare[1]);
param.spare[2] = PTRIN(param32.spare[2]);
return (kern_thr_new(td, ¶m));
}
int
freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
{
struct timespec32 ts32;
struct timespec ts, *tsp;
int error;
error = 0;
tsp = NULL;
if (uap->timeout != NULL) {
error = copyin((const void *)uap->timeout, (void *)&ts32,
sizeof(struct timespec32));
if (error != 0)
return (error);
ts.tv_sec = ts32.tv_sec;
ts.tv_nsec = ts32.tv_nsec;
tsp = &ts;
}
return (kern_thr_suspend(td, tsp));
}
void
siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
{
bzero(dst, sizeof(*dst));
dst->si_signo = src->si_signo;
dst->si_errno = src->si_errno;
dst->si_code = src->si_code;
dst->si_pid = src->si_pid;
dst->si_uid = src->si_uid;
dst->si_status = src->si_status;
dst->si_addr = (uintptr_t)src->si_addr;
dst->si_value.sival_int = src->si_value.sival_int;
dst->si_timerid = src->si_timerid;
dst->si_overrun = src->si_overrun;
}
#ifndef _FREEBSD32_SYSPROTO_H_
struct freebsd32_sigqueue_args {
pid_t pid;
int signum;
/* union sigval32 */ int value;
};
#endif
int
freebsd32_sigqueue(struct thread *td, struct freebsd32_sigqueue_args *uap)
{
union sigval sv;
/*
* On 32-bit ABIs, sival_int and sival_ptr are the same.
* On 64-bit little-endian ABIs, the low bits are the same.
* In 64-bit big-endian ABIs, sival_int overlaps with
* sival_ptr's HIGH bits. We choose to support sival_int
* rather than sival_ptr in this case as it seems to be
* more common.
*/
bzero(&sv, sizeof(sv));
sv.sival_int = uap->value;
return (kern_sigqueue(td, uap->pid, uap->signum, &sv));
}
int
freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
{
struct timespec32 ts32;
struct timespec ts;
struct timespec *timeout;
sigset_t set;
ksiginfo_t ksi;
struct siginfo32 si32;
int error;
if (uap->timeout) {
error = copyin(uap->timeout, &ts32, sizeof(ts32));
if (error)
return (error);
ts.tv_sec = ts32.tv_sec;
ts.tv_nsec = ts32.tv_nsec;
timeout = &ts;
} else
timeout = NULL;
error = copyin(uap->set, &set, sizeof(set));
if (error)
return (error);
error = kern_sigtimedwait(td, set, &ksi, timeout);
if (error)
return (error);
if (uap->info) {
siginfo_to_siginfo32(&ksi.ksi_info, &si32);
error = copyout(&si32, uap->info, sizeof(struct siginfo32));
}
if (error == 0)
td->td_retval[0] = ksi.ksi_signo;
return (error);
}
/*
* MPSAFE
*/
int
freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
{
ksiginfo_t ksi;
struct siginfo32 si32;
sigset_t set;
int error;
error = copyin(uap->set, &set, sizeof(set));
if (error)
return (error);
error = kern_sigtimedwait(td, set, &ksi, NULL);
if (error)
return (error);
if (uap->info) {
siginfo_to_siginfo32(&ksi.ksi_info, &si32);
error = copyout(&si32, uap->info, sizeof(struct siginfo32));
}
if (error == 0)
td->td_retval[0] = ksi.ksi_signo;
return (error);
}
int
freebsd32_cpuset_setid(struct thread *td,
struct freebsd32_cpuset_setid_args *uap)
{
return (kern_cpuset_setid(td, uap->which,
PAIR32TO64(id_t, uap->id), uap->setid));
}
int
freebsd32_cpuset_getid(struct thread *td,
struct freebsd32_cpuset_getid_args *uap)
{
return (kern_cpuset_getid(td, uap->level, uap->which,
PAIR32TO64(id_t, uap->id), uap->setid));
}
int
freebsd32_cpuset_getaffinity(struct thread *td,
struct freebsd32_cpuset_getaffinity_args *uap)
{
return (kern_cpuset_getaffinity(td, uap->level, uap->which,
PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask));
}
int
freebsd32_cpuset_setaffinity(struct thread *td,
struct freebsd32_cpuset_setaffinity_args *uap)
{
return (kern_cpuset_setaffinity(td, uap->level, uap->which,
PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask));
}
int
freebsd32_cpuset_getdomain(struct thread *td,
struct freebsd32_cpuset_getdomain_args *uap)
{
return (kern_cpuset_getdomain(td, uap->level, uap->which,
PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy));
}
int
freebsd32_cpuset_setdomain(struct thread *td,
struct freebsd32_cpuset_setdomain_args *uap)
{
return (kern_cpuset_setdomain(td, uap->level, uap->which,
PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy));
}
int
freebsd32_nmount(struct thread *td,
struct freebsd32_nmount_args /* {
struct iovec *iovp;
unsigned int iovcnt;
int flags;
} */ *uap)
{
struct uio *auio;
uint64_t flags;
int error;
/*
* Mount flags are now 64-bits. On 32-bit archtectures only
* 32-bits are passed in, but from here on everything handles
* 64-bit flags correctly.
*/
flags = uap->flags;
AUDIT_ARG_FFLAGS(flags);
/*
* Filter out MNT_ROOTFS. We do not want clients of nmount() in
* userspace to set this flag, but we must filter it out if we want
* MNT_UPDATE on the root file system to work.
* MNT_ROOTFS should only be set by the kernel when mounting its
* root file system.
*/
flags &= ~MNT_ROOTFS;
/*
* check that we have an even number of iovec's
* and that we have at least two options.
*/
if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
return (EINVAL);
error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
if (error)
return (error);
error = vfs_donmount(td, flags, auio);
free(auio, M_IOV);
return error;
}
#if 0
int
freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
{
struct yyy32 *p32, s32;
struct yyy *p = NULL, s;
struct xxx_arg ap;
int error;
if (uap->zzz) {
error = copyin(uap->zzz, &s32, sizeof(s32));
if (error)
return (error);
/* translate in */
p = &s;
}
error = kern_xxx(td, p);
if (error)
return (error);
if (uap->zzz) {
/* translate out */
error = copyout(&s32, p32, sizeof(s32));
}
return (error);
}
#endif
int
syscall32_module_handler(struct module *mod, int what, void *arg)
{
return (kern_syscall_module_handler(freebsd32_sysent, mod, what, arg));
}
int
syscall32_helper_register(struct syscall_helper_data *sd, int flags)
{
return (kern_syscall_helper_register(freebsd32_sysent, sd, flags));
}
int
syscall32_helper_unregister(struct syscall_helper_data *sd)
{
return (kern_syscall_helper_unregister(freebsd32_sysent, sd));
}
int
freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
int argc, envc, i;
u_int32_t *vectp;
char *stringp;
uintptr_t destp, ustringp;
struct freebsd32_ps_strings *arginfo;
char canary[sizeof(long) * 8];
int32_t pagesizes32[MAXPAGESIZES];
size_t execpath_len;
int error, szsigcode;
/*
* Calculate string base and vector table pointers.
* Also deal with signal trampoline code for this exec type.
*/
if (imgp->execpath != NULL && imgp->auxargs != NULL)
execpath_len = strlen(imgp->execpath) + 1;
else
execpath_len = 0;
arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
sv_psstrings;
imgp->ps_strings = arginfo;
if (imgp->proc->p_sysent->sv_sigcode_base == 0)
szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
else
szsigcode = 0;
destp = (uintptr_t)arginfo;
/*
* install sigcode
*/
if (szsigcode != 0) {
destp -= szsigcode;
destp = rounddown2(destp, sizeof(uint32_t));
error = copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
szsigcode);
if (error != 0)
return (error);
}
/*
* Copy the image path for the rtld.
*/
if (execpath_len != 0) {
destp -= execpath_len;
imgp->execpathp = (void *)destp;
error = copyout(imgp->execpath, imgp->execpathp, execpath_len);
if (error != 0)
return (error);
}
/*
* Prepare the canary for SSP.
*/
arc4rand(canary, sizeof(canary), 0);
destp -= sizeof(canary);
imgp->canary = (void *)destp;
error = copyout(canary, imgp->canary, sizeof(canary));
if (error != 0)
return (error);
imgp->canarylen = sizeof(canary);
/*
* Prepare the pagesizes array.
*/
for (i = 0; i < MAXPAGESIZES; i++)
pagesizes32[i] = (uint32_t)pagesizes[i];
destp -= sizeof(pagesizes32);
destp = rounddown2(destp, sizeof(uint32_t));
imgp->pagesizes = (void *)destp;
error = copyout(pagesizes32, imgp->pagesizes, sizeof(pagesizes32));
if (error != 0)
return (error);
imgp->pagesizeslen = sizeof(pagesizes32);
/*
* Allocate room for the argument and environment strings.
*/
destp -= ARG_MAX - imgp->args->stringspace;
destp = rounddown2(destp, sizeof(uint32_t));
ustringp = destp;
exec_stackgap(imgp, &destp);
if (imgp->auxargs) {
/*
* Allocate room on the stack for the ELF auxargs
* array. It has up to AT_COUNT entries.
*/
destp -= AT_COUNT * sizeof(Elf32_Auxinfo);
destp = rounddown2(destp, sizeof(uint32_t));
}
vectp = (uint32_t *)destp;
/*
* Allocate room for the argv[] and env vectors including the
* terminating NULL pointers.
*/
vectp -= imgp->args->argc + 1 + imgp->args->envc + 1;
/*
* vectp also becomes our initial stack base
*/
*stack_base = (uintptr_t)vectp;
stringp = imgp->args->begin_argv;
argc = imgp->args->argc;
envc = imgp->args->envc;
/*
* Copy out strings - arguments and environment.
*/
error = copyout(stringp, (void *)ustringp,
ARG_MAX - imgp->args->stringspace);
if (error != 0)
return (error);
/*
* Fill in "ps_strings" struct for ps, w, etc.
*/
imgp->argv = vectp;
if (suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp) != 0 ||
suword32(&arginfo->ps_nargvstr, argc) != 0)
return (EFAULT);
/*
* Fill in argument portion of vector table.
*/
for (; argc > 0; --argc) {
if (suword32(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
ustringp++;
ustringp++;
}
/* a null vector table pointer separates the argp's from the envp's */
if (suword32(vectp++, 0) != 0)
return (EFAULT);
imgp->envv = vectp;
if (suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp) != 0 ||
suword32(&arginfo->ps_nenvstr, envc) != 0)
return (EFAULT);
/*
* Fill in environment portion of vector table.
*/
for (; envc > 0; --envc) {
if (suword32(vectp++, ustringp) != 0)
return (EFAULT);
while (*stringp++ != 0)
ustringp++;
ustringp++;
}
/* end of vector table is a null pointer */
if (suword32(vectp, 0) != 0)
return (EFAULT);
if (imgp->auxargs) {
vectp++;
error = imgp->sysent->sv_copyout_auxargs(imgp,
(uintptr_t)vectp);
if (error != 0)
return (error);
}
return (0);
}
int
freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
{
struct kld_file_stat *stat;
struct kld32_file_stat *stat32;
int error, version;
if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
!= 0)
return (error);
if (version != sizeof(struct kld32_file_stat_1) &&
version != sizeof(struct kld32_file_stat))
return (EINVAL);
stat = malloc(sizeof(*stat), M_TEMP, M_WAITOK | M_ZERO);
stat32 = malloc(sizeof(*stat32), M_TEMP, M_WAITOK | M_ZERO);
error = kern_kldstat(td, uap->fileid, stat);
if (error == 0) {
bcopy(&stat->name[0], &stat32->name[0], sizeof(stat->name));
CP(*stat, *stat32, refs);
CP(*stat, *stat32, id);
PTROUT_CP(*stat, *stat32, address);
CP(*stat, *stat32, size);
bcopy(&stat->pathname[0], &stat32->pathname[0],
sizeof(stat->pathname));
stat32->version = version;
error = copyout(stat32, uap->stat, version);
}
free(stat, M_TEMP);
free(stat32, M_TEMP);
return (error);
}
int
freebsd32_posix_fallocate(struct thread *td,
struct freebsd32_posix_fallocate_args *uap)
{
int error;
error = kern_posix_fallocate(td, uap->fd,
PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
return (kern_posix_error(td, error));
}
int
freebsd32_posix_fadvise(struct thread *td,
struct freebsd32_posix_fadvise_args *uap)
{
int error;
error = kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset),
PAIR32TO64(off_t, uap->len), uap->advice);
return (kern_posix_error(td, error));
}
int
convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
{
CP(*sig32, *sig, sigev_notify);
switch (sig->sigev_notify) {
case SIGEV_NONE:
break;
case SIGEV_THREAD_ID:
CP(*sig32, *sig, sigev_notify_thread_id);
/* FALLTHROUGH */
case SIGEV_SIGNAL:
CP(*sig32, *sig, sigev_signo);
PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
break;
case SIGEV_KEVENT:
CP(*sig32, *sig, sigev_notify_kqueue);
CP(*sig32, *sig, sigev_notify_kevent_flags);
PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
break;
default:
return (EINVAL);
}
return (0);
}
int
freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
{
void *data;
union {
struct procctl_reaper_status rs;
struct procctl_reaper_pids rp;
struct procctl_reaper_kill rk;
} x;
union {
struct procctl_reaper_pids32 rp;
} x32;
int error, error1, flags, signum;
if (uap->com >= PROC_PROCCTL_MD_MIN)
return (cpu_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
uap->com, PTRIN(uap->data)));
switch (uap->com) {
case PROC_ASLR_CTL:
case PROC_PROTMAX_CTL:
case PROC_SPROTECT:
case PROC_STACKGAP_CTL:
case PROC_TRACE_CTL:
case PROC_TRAPCAP_CTL:
error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
if (error != 0)
return (error);
data = &flags;
break;
case PROC_REAP_ACQUIRE:
case PROC_REAP_RELEASE:
if (uap->data != NULL)
return (EINVAL);
data = NULL;
break;
case PROC_REAP_STATUS:
data = &x.rs;
break;
case PROC_REAP_GETPIDS:
error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
if (error != 0)
return (error);
CP(x32.rp, x.rp, rp_count);
PTRIN_CP(x32.rp, x.rp, rp_pids);
data = &x.rp;
break;
case PROC_REAP_KILL:
error = copyin(uap->data, &x.rk, sizeof(x.rk));
if (error != 0)
return (error);
data = &x.rk;
break;
case PROC_ASLR_STATUS:
case PROC_PROTMAX_STATUS:
case PROC_STACKGAP_STATUS:
case PROC_TRACE_STATUS:
case PROC_TRAPCAP_STATUS:
data = &flags;
break;
case PROC_PDEATHSIG_CTL:
error = copyin(uap->data, &signum, sizeof(signum));
if (error != 0)
return (error);
data = &signum;
break;
case PROC_PDEATHSIG_STATUS:
data = &signum;
break;
default:
return (EINVAL);
}
error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
uap->com, data);
switch (uap->com) {
case PROC_REAP_STATUS:
if (error == 0)
error = copyout(&x.rs, uap->data, sizeof(x.rs));
break;
case PROC_REAP_KILL:
error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
if (error == 0)
error = error1;
break;
case PROC_ASLR_STATUS:
case PROC_PROTMAX_STATUS:
case PROC_STACKGAP_STATUS:
case PROC_TRACE_STATUS:
case PROC_TRAPCAP_STATUS:
if (error == 0)
error = copyout(&flags, uap->data, sizeof(flags));
break;
case PROC_PDEATHSIG_STATUS:
if (error == 0)
error = copyout(&signum, uap->data, sizeof(signum));
break;
}
return (error);
}
int
freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
{
long tmp;
switch (uap->cmd) {
/*
* Do unsigned conversion for arg when operation
* interprets it as flags or pointer.
*/
case F_SETLK_REMOTE:
case F_SETLKW:
case F_SETLK:
case F_GETLK:
case F_SETFD:
case F_SETFL:
case F_OGETLK:
case F_OSETLK:
case F_OSETLKW:
tmp = (unsigned int)(uap->arg);
break;
default:
tmp = uap->arg;
break;
}
return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
}
int
freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
{
struct timespec32 ts32;
struct timespec ts, *tsp;
sigset_t set, *ssp;
int error;
if (uap->ts != NULL) {
error = copyin(uap->ts, &ts32, sizeof(ts32));
if (error != 0)
return (error);
CP(ts32, ts, tv_sec);
CP(ts32, ts, tv_nsec);
tsp = &ts;
} else
tsp = NULL;
if (uap->set != NULL) {
error = copyin(uap->set, &set, sizeof(set));
if (error != 0)
return (error);
ssp = &set;
} else
ssp = NULL;
return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));
}
int
freebsd32_sched_rr_get_interval(struct thread *td,
struct freebsd32_sched_rr_get_interval_args *uap)
{
struct timespec ts;
struct timespec32 ts32;
int error;
error = kern_sched_rr_get_interval(td, uap->pid, &ts);
if (error == 0) {
CP(ts, ts32, tv_sec);
CP(ts, ts32, tv_nsec);
error = copyout(&ts32, uap->interval, sizeof(ts32));
}
return (error);
}
static void
timex_to_32(struct timex32 *dst, struct timex *src)
{
CP(*src, *dst, modes);
CP(*src, *dst, offset);
CP(*src, *dst, freq);
CP(*src, *dst, maxerror);
CP(*src, *dst, esterror);
CP(*src, *dst, status);
CP(*src, *dst, constant);
CP(*src, *dst, precision);
CP(*src, *dst, tolerance);
CP(*src, *dst, ppsfreq);
CP(*src, *dst, jitter);
CP(*src, *dst, shift);
CP(*src, *dst, stabil);
CP(*src, *dst, jitcnt);
CP(*src, *dst, calcnt);
CP(*src, *dst, errcnt);
CP(*src, *dst, stbcnt);
}
static void
timex_from_32(struct timex *dst, struct timex32 *src)
{
CP(*src, *dst, modes);
CP(*src, *dst, offset);
CP(*src, *dst, freq);
CP(*src, *dst, maxerror);
CP(*src, *dst, esterror);
CP(*src, *dst, status);
CP(*src, *dst, constant);
CP(*src, *dst, precision);
CP(*src, *dst, tolerance);
CP(*src, *dst, ppsfreq);
CP(*src, *dst, jitter);
CP(*src, *dst, shift);
CP(*src, *dst, stabil);
CP(*src, *dst, jitcnt);
CP(*src, *dst, calcnt);
CP(*src, *dst, errcnt);
CP(*src, *dst, stbcnt);
}
int
freebsd32_ntp_adjtime(struct thread *td, struct freebsd32_ntp_adjtime_args *uap)
{
struct timex tx;
struct timex32 tx32;
int error, retval;
error = copyin(uap->tp, &tx32, sizeof(tx32));
if (error == 0) {
timex_from_32(&tx, &tx32);
error = kern_ntp_adjtime(td, &tx, &retval);
if (error == 0) {
timex_to_32(&tx32, &tx);
error = copyout(&tx32, uap->tp, sizeof(tx32));
if (error == 0)
td->td_retval[0] = retval;
}
}
return (error);
}
diff --git a/sys/compat/linux/linux_event.c b/sys/compat/linux/linux_event.c
index b4b4be1f7b49..dfb4588392cc 100644
--- a/sys/compat/linux/linux_event.c
+++ b/sys/compat/linux/linux_event.c
@@ -1,1047 +1,1048 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2007 Roman Divacky
* Copyright (c) 2014 Dmitry Chagin
* 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 AUTHOR 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 AUTHOR 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.
*/
#include
__FBSDID("$FreeBSD$");
#include "opt_compat.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef COMPAT_LINUX32
#include
#include
#else
#include
#include
#endif
#include
#include
#include
#include
#include
/*
* epoll defines 'struct epoll_event' with the field 'data' as 64 bits
* on all architectures. But on 32 bit architectures BSD 'struct kevent' only
* has 32 bit opaque pointer as 'udata' field. So we can't pass epoll supplied
* data verbatuim. Therefore we allocate 64-bit memory block to pass
* user supplied data for every file descriptor.
*/
typedef uint64_t epoll_udata_t;
struct epoll_emuldata {
uint32_t fdc; /* epoll udata max index */
epoll_udata_t udata[1]; /* epoll user data vector */
};
#define EPOLL_DEF_SZ 16
#define EPOLL_SIZE(fdn) \
(sizeof(struct epoll_emuldata)+(fdn) * sizeof(epoll_udata_t))
struct epoll_event {
uint32_t events;
epoll_udata_t data;
}
#if defined(__amd64__)
__attribute__((packed))
#endif
;
#define LINUX_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event))
static void epoll_fd_install(struct thread *td, int fd, epoll_udata_t udata);
static int epoll_to_kevent(struct thread *td, int fd,
struct epoll_event *l_event, struct kevent *kevent,
int *nkevents);
static void kevent_to_epoll(struct kevent *kevent, struct epoll_event *l_event);
static int epoll_kev_copyout(void *arg, struct kevent *kevp, int count);
static int epoll_kev_copyin(void *arg, struct kevent *kevp, int count);
static int epoll_register_kevent(struct thread *td, struct file *epfp,
int fd, int filter, unsigned int flags);
static int epoll_fd_registered(struct thread *td, struct file *epfp,
int fd);
static int epoll_delete_all_events(struct thread *td, struct file *epfp,
int fd);
struct epoll_copyin_args {
struct kevent *changelist;
};
struct epoll_copyout_args {
struct epoll_event *leventlist;
struct proc *p;
uint32_t count;
int error;
};
/* timerfd */
typedef uint64_t timerfd_t;
static fo_rdwr_t timerfd_read;
static fo_ioctl_t timerfd_ioctl;
static fo_poll_t timerfd_poll;
static fo_kqfilter_t timerfd_kqfilter;
static fo_stat_t timerfd_stat;
static fo_close_t timerfd_close;
static fo_fill_kinfo_t timerfd_fill_kinfo;
static struct fileops timerfdops = {
.fo_read = timerfd_read,
.fo_write = invfo_rdwr,
.fo_truncate = invfo_truncate,
.fo_ioctl = timerfd_ioctl,
.fo_poll = timerfd_poll,
.fo_kqfilter = timerfd_kqfilter,
.fo_stat = timerfd_stat,
.fo_close = timerfd_close,
.fo_chmod = invfo_chmod,
.fo_chown = invfo_chown,
.fo_sendfile = invfo_sendfile,
.fo_fill_kinfo = timerfd_fill_kinfo,
.fo_flags = DFLAG_PASSABLE
};
static void filt_timerfddetach(struct knote *kn);
static int filt_timerfdread(struct knote *kn, long hint);
static struct filterops timerfd_rfiltops = {
.f_isfd = 1,
.f_detach = filt_timerfddetach,
.f_event = filt_timerfdread
};
struct timerfd {
clockid_t tfd_clockid;
struct itimerspec tfd_time;
struct callout tfd_callout;
timerfd_t tfd_count;
bool tfd_canceled;
struct selinfo tfd_sel;
struct mtx tfd_lock;
};
static void linux_timerfd_expire(void *);
static void linux_timerfd_curval(struct timerfd *, struct itimerspec *);
static void
epoll_fd_install(struct thread *td, int fd, epoll_udata_t udata)
{
struct linux_pemuldata *pem;
struct epoll_emuldata *emd;
struct proc *p;
p = td->td_proc;
pem = pem_find(p);
KASSERT(pem != NULL, ("epoll proc emuldata not found.\n"));
LINUX_PEM_XLOCK(pem);
if (pem->epoll == NULL) {
emd = malloc(EPOLL_SIZE(fd), M_EPOLL, M_WAITOK);
emd->fdc = fd;
pem->epoll = emd;
} else {
emd = pem->epoll;
if (fd > emd->fdc) {
emd = realloc(emd, EPOLL_SIZE(fd), M_EPOLL, M_WAITOK);
emd->fdc = fd;
pem->epoll = emd;
}
}
emd->udata[fd] = udata;
LINUX_PEM_XUNLOCK(pem);
}
static int
epoll_create_common(struct thread *td, int flags)
{
int error;
error = kern_kqueue(td, flags, NULL);
if (error != 0)
return (error);
epoll_fd_install(td, EPOLL_DEF_SZ, 0);
return (0);
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_epoll_create(struct thread *td, struct linux_epoll_create_args *args)
{
/*
* args->size is unused. Linux just tests it
* and then forgets it as well.
*/
if (args->size <= 0)
return (EINVAL);
return (epoll_create_common(td, 0));
}
#endif
int
linux_epoll_create1(struct thread *td, struct linux_epoll_create1_args *args)
{
int flags;
if ((args->flags & ~(LINUX_O_CLOEXEC)) != 0)
return (EINVAL);
flags = 0;
if ((args->flags & LINUX_O_CLOEXEC) != 0)
flags |= O_CLOEXEC;
return (epoll_create_common(td, flags));
}
/* Structure converting function from epoll to kevent. */
static int
epoll_to_kevent(struct thread *td, int fd, struct epoll_event *l_event,
struct kevent *kevent, int *nkevents)
{
uint32_t levents = l_event->events;
struct linux_pemuldata *pem;
struct proc *p;
unsigned short kev_flags = EV_ADD | EV_ENABLE;
/* flags related to how event is registered */
if ((levents & LINUX_EPOLLONESHOT) != 0)
kev_flags |= EV_DISPATCH;
if ((levents & LINUX_EPOLLET) != 0)
kev_flags |= EV_CLEAR;
if ((levents & LINUX_EPOLLERR) != 0)
kev_flags |= EV_ERROR;
if ((levents & LINUX_EPOLLRDHUP) != 0)
kev_flags |= EV_EOF;
/* flags related to what event is registered */
if ((levents & LINUX_EPOLL_EVRD) != 0) {
EV_SET(kevent++, fd, EVFILT_READ, kev_flags, 0, 0, 0);
++(*nkevents);
}
if ((levents & LINUX_EPOLL_EVWR) != 0) {
EV_SET(kevent++, fd, EVFILT_WRITE, kev_flags, 0, 0, 0);
++(*nkevents);
}
/* zero event mask is legal */
if ((levents & (LINUX_EPOLL_EVRD | LINUX_EPOLL_EVWR)) == 0) {
EV_SET(kevent++, fd, EVFILT_READ, EV_ADD|EV_DISABLE, 0, 0, 0);
++(*nkevents);
}
if ((levents & ~(LINUX_EPOLL_EVSUP)) != 0) {
p = td->td_proc;
pem = pem_find(p);
KASSERT(pem != NULL, ("epoll proc emuldata not found.\n"));
KASSERT(pem->epoll != NULL, ("epoll proc epolldata not found.\n"));
LINUX_PEM_XLOCK(pem);
if ((pem->flags & LINUX_XUNSUP_EPOLL) == 0) {
pem->flags |= LINUX_XUNSUP_EPOLL;
LINUX_PEM_XUNLOCK(pem);
linux_msg(td, "epoll_ctl unsupported flags: 0x%x",
levents);
} else
LINUX_PEM_XUNLOCK(pem);
return (EINVAL);
}
return (0);
}
/*
* Structure converting function from kevent to epoll. In a case
* this is called on error in registration we store the error in
* event->data and pick it up later in linux_epoll_ctl().
*/
static void
kevent_to_epoll(struct kevent *kevent, struct epoll_event *l_event)
{
if ((kevent->flags & EV_ERROR) != 0) {
l_event->events = LINUX_EPOLLERR;
return;
}
/* XXX EPOLLPRI, EPOLLHUP */
switch (kevent->filter) {
case EVFILT_READ:
l_event->events = LINUX_EPOLLIN;
if ((kevent->flags & EV_EOF) != 0)
l_event->events |= LINUX_EPOLLRDHUP;
break;
case EVFILT_WRITE:
l_event->events = LINUX_EPOLLOUT;
break;
}
}
/*
* Copyout callback used by kevent. This converts kevent
* events to epoll events and copies them back to the
* userspace. This is also called on error on registering
* of the filter.
*/
static int
epoll_kev_copyout(void *arg, struct kevent *kevp, int count)
{
struct epoll_copyout_args *args;
struct linux_pemuldata *pem;
struct epoll_emuldata *emd;
struct epoll_event *eep;
int error, fd, i;
args = (struct epoll_copyout_args*) arg;
eep = malloc(sizeof(*eep) * count, M_EPOLL, M_WAITOK | M_ZERO);
pem = pem_find(args->p);
KASSERT(pem != NULL, ("epoll proc emuldata not found.\n"));
LINUX_PEM_SLOCK(pem);
emd = pem->epoll;
KASSERT(emd != NULL, ("epoll proc epolldata not found.\n"));
for (i = 0; i < count; i++) {
kevent_to_epoll(&kevp[i], &eep[i]);
fd = kevp[i].ident;
KASSERT(fd <= emd->fdc, ("epoll user data vector"
" is too small.\n"));
eep[i].data = emd->udata[fd];
}
LINUX_PEM_SUNLOCK(pem);
error = copyout(eep, args->leventlist, count * sizeof(*eep));
if (error == 0) {
args->leventlist += count;
args->count += count;
} else if (args->error == 0)
args->error = error;
free(eep, M_EPOLL);
return (error);
}
/*
* Copyin callback used by kevent. This copies already
* converted filters from kernel memory to the kevent
* internal kernel memory. Hence the memcpy instead of
* copyin.
*/
static int
epoll_kev_copyin(void *arg, struct kevent *kevp, int count)
{
struct epoll_copyin_args *args;
args = (struct epoll_copyin_args*) arg;
memcpy(kevp, args->changelist, count * sizeof(*kevp));
args->changelist += count;
return (0);
}
/*
* Load epoll filter, convert it to kevent filter
* and load it into kevent subsystem.
*/
int
linux_epoll_ctl(struct thread *td, struct linux_epoll_ctl_args *args)
{
struct file *epfp, *fp;
struct epoll_copyin_args ciargs;
struct kevent kev[2];
struct kevent_copyops k_ops = { &ciargs,
NULL,
epoll_kev_copyin};
struct epoll_event le;
cap_rights_t rights;
int nchanges = 0;
int error;
if (args->op != LINUX_EPOLL_CTL_DEL) {
error = copyin(args->event, &le, sizeof(le));
if (error != 0)
return (error);
}
error = fget(td, args->epfd,
- cap_rights_init(&rights, CAP_KQUEUE_CHANGE), &epfp);
+ cap_rights_init_one(&rights, CAP_KQUEUE_CHANGE), &epfp);
if (error != 0)
return (error);
if (epfp->f_type != DTYPE_KQUEUE) {
error = EINVAL;
goto leave1;
}
/* Protect user data vector from incorrectly supplied fd. */
- error = fget(td, args->fd, cap_rights_init(&rights, CAP_POLL_EVENT), &fp);
+ error = fget(td, args->fd,
+ cap_rights_init_one(&rights, CAP_POLL_EVENT), &fp);
if (error != 0)
goto leave1;
/* Linux disallows spying on himself */
if (epfp == fp) {
error = EINVAL;
goto leave0;
}
ciargs.changelist = kev;
if (args->op != LINUX_EPOLL_CTL_DEL) {
error = epoll_to_kevent(td, args->fd, &le, kev, &nchanges);
if (error != 0)
goto leave0;
}
switch (args->op) {
case LINUX_EPOLL_CTL_MOD:
error = epoll_delete_all_events(td, epfp, args->fd);
if (error != 0)
goto leave0;
break;
case LINUX_EPOLL_CTL_ADD:
if (epoll_fd_registered(td, epfp, args->fd)) {
error = EEXIST;
goto leave0;
}
break;
case LINUX_EPOLL_CTL_DEL:
/* CTL_DEL means unregister this fd with this epoll */
error = epoll_delete_all_events(td, epfp, args->fd);
goto leave0;
default:
error = EINVAL;
goto leave0;
}
epoll_fd_install(td, args->fd, le.data);
error = kern_kevent_fp(td, epfp, nchanges, 0, &k_ops, NULL);
leave0:
fdrop(fp, td);
leave1:
fdrop(epfp, td);
return (error);
}
/*
* Wait for a filter to be triggered on the epoll file descriptor.
*/
static int
linux_epoll_wait_common(struct thread *td, int epfd, struct epoll_event *events,
int maxevents, int timeout, sigset_t *uset)
{
struct epoll_copyout_args coargs;
struct kevent_copyops k_ops = { &coargs,
epoll_kev_copyout,
NULL};
struct timespec ts, *tsp;
cap_rights_t rights;
struct file *epfp;
sigset_t omask;
int error;
if (maxevents <= 0 || maxevents > LINUX_MAX_EVENTS)
return (EINVAL);
error = fget(td, epfd,
- cap_rights_init(&rights, CAP_KQUEUE_EVENT), &epfp);
+ cap_rights_init_one(&rights, CAP_KQUEUE_EVENT), &epfp);
if (error != 0)
return (error);
if (epfp->f_type != DTYPE_KQUEUE) {
error = EINVAL;
goto leave;
}
if (uset != NULL) {
error = kern_sigprocmask(td, SIG_SETMASK, uset,
&omask, 0);
if (error != 0)
goto leave;
td->td_pflags |= TDP_OLDMASK;
/*
* Make sure that ast() is called on return to
* usermode and TDP_OLDMASK is cleared, restoring old
* sigmask.
*/
thread_lock(td);
td->td_flags |= TDF_ASTPENDING;
thread_unlock(td);
}
coargs.leventlist = events;
coargs.p = td->td_proc;
coargs.count = 0;
coargs.error = 0;
/*
* Linux epoll_wait(2) man page states that timeout of -1 causes caller
* to block indefinitely. Real implementation does it if any negative
* timeout value is passed.
*/
if (timeout >= 0) {
/* Convert from milliseconds to timespec. */
ts.tv_sec = timeout / 1000;
ts.tv_nsec = (timeout % 1000) * 1000000;
tsp = &ts;
} else {
tsp = NULL;
}
error = kern_kevent_fp(td, epfp, 0, maxevents, &k_ops, tsp);
if (error == 0 && coargs.error != 0)
error = coargs.error;
/*
* kern_kevent might return ENOMEM which is not expected from epoll_wait.
* Maybe we should translate that but I don't think it matters at all.
*/
if (error == 0)
td->td_retval[0] = coargs.count;
if (uset != NULL)
error = kern_sigprocmask(td, SIG_SETMASK, &omask,
NULL, 0);
leave:
fdrop(epfp, td);
return (error);
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_epoll_wait(struct thread *td, struct linux_epoll_wait_args *args)
{
return (linux_epoll_wait_common(td, args->epfd, args->events,
args->maxevents, args->timeout, NULL));
}
#endif
int
linux_epoll_pwait(struct thread *td, struct linux_epoll_pwait_args *args)
{
sigset_t mask, *pmask;
l_sigset_t lmask;
int error;
if (args->mask != NULL) {
if (args->sigsetsize != sizeof(l_sigset_t))
return (EINVAL);
error = copyin(args->mask, &lmask, sizeof(l_sigset_t));
if (error != 0)
return (error);
linux_to_bsd_sigset(&lmask, &mask);
pmask = &mask;
} else
pmask = NULL;
return (linux_epoll_wait_common(td, args->epfd, args->events,
args->maxevents, args->timeout, pmask));
}
static int
epoll_register_kevent(struct thread *td, struct file *epfp, int fd, int filter,
unsigned int flags)
{
struct epoll_copyin_args ciargs;
struct kevent kev;
struct kevent_copyops k_ops = { &ciargs,
NULL,
epoll_kev_copyin};
ciargs.changelist = &kev;
EV_SET(&kev, fd, filter, flags, 0, 0, 0);
return (kern_kevent_fp(td, epfp, 1, 0, &k_ops, NULL));
}
static int
epoll_fd_registered(struct thread *td, struct file *epfp, int fd)
{
/*
* Set empty filter flags to avoid accidental modification of already
* registered events. In the case of event re-registration:
* 1. If event does not exists kevent() does nothing and returns ENOENT
* 2. If event does exists, it's enabled/disabled state is preserved
* but fflags, data and udata fields are overwritten. So we can not
* set socket lowats and store user's context pointer in udata.
*/
if (epoll_register_kevent(td, epfp, fd, EVFILT_READ, 0) != ENOENT ||
epoll_register_kevent(td, epfp, fd, EVFILT_WRITE, 0) != ENOENT)
return (1);
return (0);
}
static int
epoll_delete_all_events(struct thread *td, struct file *epfp, int fd)
{
int error1, error2;
error1 = epoll_register_kevent(td, epfp, fd, EVFILT_READ, EV_DELETE);
error2 = epoll_register_kevent(td, epfp, fd, EVFILT_WRITE, EV_DELETE);
/* return 0 if at least one result positive */
return (error1 == 0 ? 0 : error2);
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_eventfd(struct thread *td, struct linux_eventfd_args *args)
{
struct specialfd_eventfd ae;
bzero(&ae, sizeof(ae));
ae.initval = args->initval;
return (kern_specialfd(td, SPECIALFD_EVENTFD, &ae));
}
#endif
int
linux_eventfd2(struct thread *td, struct linux_eventfd2_args *args)
{
struct specialfd_eventfd ae;
int flags;
if ((args->flags & ~(LINUX_O_CLOEXEC | LINUX_O_NONBLOCK |
LINUX_EFD_SEMAPHORE)) != 0)
return (EINVAL);
flags = 0;
if ((args->flags & LINUX_O_CLOEXEC) != 0)
flags |= EFD_CLOEXEC;
if ((args->flags & LINUX_O_NONBLOCK) != 0)
flags |= EFD_NONBLOCK;
if ((args->flags & LINUX_EFD_SEMAPHORE) != 0)
flags |= EFD_SEMAPHORE;
bzero(&ae, sizeof(ae));
ae.flags = flags;
ae.initval = args->initval;
return (kern_specialfd(td, SPECIALFD_EVENTFD, &ae));
}
int
linux_timerfd_create(struct thread *td, struct linux_timerfd_create_args *args)
{
struct filedesc *fdp;
struct timerfd *tfd;
struct file *fp;
clockid_t clockid;
int fflags, fd, error;
if ((args->flags & ~LINUX_TFD_CREATE_FLAGS) != 0)
return (EINVAL);
error = linux_to_native_clockid(&clockid, args->clockid);
if (error != 0)
return (error);
if (clockid != CLOCK_REALTIME && clockid != CLOCK_MONOTONIC)
return (EINVAL);
fflags = 0;
if ((args->flags & LINUX_TFD_CLOEXEC) != 0)
fflags |= O_CLOEXEC;
fdp = td->td_proc->p_fd;
error = falloc(td, &fp, &fd, fflags);
if (error != 0)
return (error);
tfd = malloc(sizeof(*tfd), M_EPOLL, M_WAITOK | M_ZERO);
tfd->tfd_clockid = clockid;
mtx_init(&tfd->tfd_lock, "timerfd", NULL, MTX_DEF);
callout_init_mtx(&tfd->tfd_callout, &tfd->tfd_lock, 0);
knlist_init_mtx(&tfd->tfd_sel.si_note, &tfd->tfd_lock);
fflags = FREAD;
if ((args->flags & LINUX_O_NONBLOCK) != 0)
fflags |= FNONBLOCK;
finit(fp, fflags, DTYPE_LINUXTFD, tfd, &timerfdops);
fdrop(fp, td);
td->td_retval[0] = fd;
return (error);
}
static int
timerfd_close(struct file *fp, struct thread *td)
{
struct timerfd *tfd;
tfd = fp->f_data;
if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
return (EINVAL);
timespecclear(&tfd->tfd_time.it_value);
timespecclear(&tfd->tfd_time.it_interval);
mtx_lock(&tfd->tfd_lock);
callout_drain(&tfd->tfd_callout);
mtx_unlock(&tfd->tfd_lock);
seldrain(&tfd->tfd_sel);
knlist_destroy(&tfd->tfd_sel.si_note);
fp->f_ops = &badfileops;
mtx_destroy(&tfd->tfd_lock);
free(tfd, M_EPOLL);
return (0);
}
static int
timerfd_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{
struct timerfd *tfd;
timerfd_t count;
int error;
tfd = fp->f_data;
if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
return (EINVAL);
if (uio->uio_resid < sizeof(timerfd_t))
return (EINVAL);
error = 0;
mtx_lock(&tfd->tfd_lock);
retry:
if (tfd->tfd_canceled) {
tfd->tfd_count = 0;
mtx_unlock(&tfd->tfd_lock);
return (ECANCELED);
}
if (tfd->tfd_count == 0) {
if ((fp->f_flag & FNONBLOCK) != 0) {
mtx_unlock(&tfd->tfd_lock);
return (EAGAIN);
}
error = mtx_sleep(&tfd->tfd_count, &tfd->tfd_lock, PCATCH, "ltfdrd", 0);
if (error == 0)
goto retry;
}
if (error == 0) {
count = tfd->tfd_count;
tfd->tfd_count = 0;
mtx_unlock(&tfd->tfd_lock);
error = uiomove(&count, sizeof(timerfd_t), uio);
} else
mtx_unlock(&tfd->tfd_lock);
return (error);
}
static int
timerfd_poll(struct file *fp, int events, struct ucred *active_cred,
struct thread *td)
{
struct timerfd *tfd;
int revents = 0;
tfd = fp->f_data;
if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
return (POLLERR);
mtx_lock(&tfd->tfd_lock);
if ((events & (POLLIN|POLLRDNORM)) && tfd->tfd_count > 0)
revents |= events & (POLLIN|POLLRDNORM);
if (revents == 0)
selrecord(td, &tfd->tfd_sel);
mtx_unlock(&tfd->tfd_lock);
return (revents);
}
static int
timerfd_kqfilter(struct file *fp, struct knote *kn)
{
struct timerfd *tfd;
tfd = fp->f_data;
if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
return (EINVAL);
if (kn->kn_filter == EVFILT_READ)
kn->kn_fop = &timerfd_rfiltops;
else
return (EINVAL);
kn->kn_hook = tfd;
knlist_add(&tfd->tfd_sel.si_note, kn, 0);
return (0);
}
static void
filt_timerfddetach(struct knote *kn)
{
struct timerfd *tfd = kn->kn_hook;
mtx_lock(&tfd->tfd_lock);
knlist_remove(&tfd->tfd_sel.si_note, kn, 1);
mtx_unlock(&tfd->tfd_lock);
}
static int
filt_timerfdread(struct knote *kn, long hint)
{
struct timerfd *tfd = kn->kn_hook;
return (tfd->tfd_count > 0);
}
static int
timerfd_ioctl(struct file *fp, u_long cmd, void *data,
struct ucred *active_cred, struct thread *td)
{
if (fp->f_data == NULL || fp->f_type != DTYPE_LINUXTFD)
return (EINVAL);
switch (cmd) {
case FIONBIO:
case FIOASYNC:
return (0);
}
return (ENOTTY);
}
static int
timerfd_stat(struct file *fp, struct stat *st, struct ucred *active_cred,
struct thread *td)
{
return (ENXIO);
}
static int
timerfd_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
{
kif->kf_type = KF_TYPE_UNKNOWN;
return (0);
}
static void
linux_timerfd_clocktime(struct timerfd *tfd, struct timespec *ts)
{
if (tfd->tfd_clockid == CLOCK_REALTIME)
getnanotime(ts);
else /* CLOCK_MONOTONIC */
getnanouptime(ts);
}
static void
linux_timerfd_curval(struct timerfd *tfd, struct itimerspec *ots)
{
struct timespec cts;
linux_timerfd_clocktime(tfd, &cts);
*ots = tfd->tfd_time;
if (ots->it_value.tv_sec != 0 || ots->it_value.tv_nsec != 0) {
timespecsub(&ots->it_value, &cts, &ots->it_value);
if (ots->it_value.tv_sec < 0 ||
(ots->it_value.tv_sec == 0 &&
ots->it_value.tv_nsec == 0)) {
ots->it_value.tv_sec = 0;
ots->it_value.tv_nsec = 1;
}
}
}
int
linux_timerfd_gettime(struct thread *td, struct linux_timerfd_gettime_args *args)
{
struct l_itimerspec lots;
struct itimerspec ots;
struct timerfd *tfd;
struct file *fp;
int error;
error = fget(td, args->fd, &cap_read_rights, &fp);
if (error != 0)
return (error);
tfd = fp->f_data;
if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) {
error = EINVAL;
goto out;
}
mtx_lock(&tfd->tfd_lock);
linux_timerfd_curval(tfd, &ots);
mtx_unlock(&tfd->tfd_lock);
error = native_to_linux_itimerspec(&lots, &ots);
if (error == 0)
error = copyout(&lots, args->old_value, sizeof(lots));
out:
fdrop(fp, td);
return (error);
}
int
linux_timerfd_settime(struct thread *td, struct linux_timerfd_settime_args *args)
{
struct l_itimerspec lots;
struct itimerspec nts, ots;
struct timespec cts, ts;
struct timerfd *tfd;
struct timeval tv;
struct file *fp;
int error;
if ((args->flags & ~LINUX_TFD_SETTIME_FLAGS) != 0)
return (EINVAL);
error = copyin(args->new_value, &lots, sizeof(lots));
if (error != 0)
return (error);
error = linux_to_native_itimerspec(&nts, &lots);
if (error != 0)
return (error);
error = fget(td, args->fd, &cap_write_rights, &fp);
if (error != 0)
return (error);
tfd = fp->f_data;
if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) {
error = EINVAL;
goto out;
}
mtx_lock(&tfd->tfd_lock);
if (!timespecisset(&nts.it_value))
timespecclear(&nts.it_interval);
if (args->old_value != NULL)
linux_timerfd_curval(tfd, &ots);
tfd->tfd_time = nts;
if (timespecisset(&nts.it_value)) {
linux_timerfd_clocktime(tfd, &cts);
ts = nts.it_value;
if ((args->flags & LINUX_TFD_TIMER_ABSTIME) == 0) {
timespecadd(&tfd->tfd_time.it_value, &cts,
&tfd->tfd_time.it_value);
} else {
timespecsub(&ts, &cts, &ts);
}
TIMESPEC_TO_TIMEVAL(&tv, &ts);
callout_reset(&tfd->tfd_callout, tvtohz(&tv),
linux_timerfd_expire, tfd);
tfd->tfd_canceled = false;
} else {
tfd->tfd_canceled = true;
callout_stop(&tfd->tfd_callout);
}
mtx_unlock(&tfd->tfd_lock);
if (args->old_value != NULL) {
error = native_to_linux_itimerspec(&lots, &ots);
if (error == 0)
error = copyout(&lots, args->old_value, sizeof(lots));
}
out:
fdrop(fp, td);
return (error);
}
static void
linux_timerfd_expire(void *arg)
{
struct timespec cts, ts;
struct timeval tv;
struct timerfd *tfd;
tfd = (struct timerfd *)arg;
linux_timerfd_clocktime(tfd, &cts);
if (timespeccmp(&cts, &tfd->tfd_time.it_value, >=)) {
if (timespecisset(&tfd->tfd_time.it_interval))
timespecadd(&tfd->tfd_time.it_value,
&tfd->tfd_time.it_interval,
&tfd->tfd_time.it_value);
else
/* single shot timer */
timespecclear(&tfd->tfd_time.it_value);
if (timespecisset(&tfd->tfd_time.it_value)) {
timespecsub(&tfd->tfd_time.it_value, &cts, &ts);
TIMESPEC_TO_TIMEVAL(&tv, &ts);
callout_reset(&tfd->tfd_callout, tvtohz(&tv),
linux_timerfd_expire, tfd);
}
tfd->tfd_count++;
KNOTE_LOCKED(&tfd->tfd_sel.si_note, 0);
selwakeup(&tfd->tfd_sel);
wakeup(&tfd->tfd_count);
} else if (timespecisset(&tfd->tfd_time.it_value)) {
timespecsub(&tfd->tfd_time.it_value, &cts, &ts);
TIMESPEC_TO_TIMEVAL(&tv, &ts);
callout_reset(&tfd->tfd_callout, tvtohz(&tv),
linux_timerfd_expire, tfd);
}
}
diff --git a/sys/dev/aac/aac_linux.c b/sys/dev/aac/aac_linux.c
index 02babb5c0576..3f2d8a827441 100644
--- a/sys/dev/aac/aac_linux.c
+++ b/sys/dev/aac/aac_linux.c
@@ -1,96 +1,97 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2002 Scott Long
* 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 AUTHOR 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 AUTHOR 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.
*/
#include
__FBSDID("$FreeBSD$");
/*
* Linux ioctl handler for the aac device driver
*/
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef __amd64__
#include
#include
#else
#include
#include
#endif
#include
/* There are multiple ioctl number ranges that need to be handled */
#define AAC_LINUX_IOCTL_MIN 0x0000
#define AAC_LINUX_IOCTL_MAX 0x21ff
static linux_ioctl_function_t aac_linux_ioctl;
static struct linux_ioctl_handler aac_linux_handler = {aac_linux_ioctl,
AAC_LINUX_IOCTL_MIN,
AAC_LINUX_IOCTL_MAX};
SYSINIT (aac_linux_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_register_handler, &aac_linux_handler);
SYSUNINIT(aac_linux_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_unregister_handler, &aac_linux_handler);
static int
aac_linux_modevent(module_t mod, int type, void *data)
{
/* Do we care about any specific load/unload actions? */
return (0);
}
DEV_MODULE(aac_linux, aac_linux_modevent, NULL);
MODULE_DEPEND(aac_linux, linux, 1, 1, 1);
static int
aac_linux_ioctl(struct thread *td, struct linux_ioctl_args *args)
{
cap_rights_t rights;
struct file *fp;
u_long cmd;
int error;
- error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
+ error = fget(td, args->fd, cap_rights_init_one(&rights, CAP_IOCTL),
+ &fp);
if (error != 0)
return (error);
cmd = args->cmd;
/*
* Pass the ioctl off to our standard handler.
*/
error = (fo_ioctl(fp, cmd, (caddr_t)args->arg, td->td_ucred, td));
fdrop(fp, td);
return (error);
}
diff --git a/sys/dev/aacraid/aacraid_linux.c b/sys/dev/aacraid/aacraid_linux.c
index b58b8bacd7f3..7592a0d5a8cb 100644
--- a/sys/dev/aacraid/aacraid_linux.c
+++ b/sys/dev/aacraid/aacraid_linux.c
@@ -1,100 +1,100 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2002 Scott Long
* Copyright (c) 2002-2010 Adaptec, Inc.
* Copyright (c) 2010-2012 PMC-Sierra, Inc.
* 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 AUTHOR 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 AUTHOR 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.
*/
#include
__FBSDID("$FreeBSD$");
/*
* Linux ioctl handler for the aac device driver
*/
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef __amd64__
#include
#include
#else
#include
#include
#endif
#include
/* There are multiple ioctl number ranges that need to be handled */
#define AAC_LINUX_IOCTL_MIN 0x0000
#define AAC_LINUX_IOCTL_MAX 0x21ff
static linux_ioctl_function_t aacraid_linux_ioctl;
static struct linux_ioctl_handler aacraid_linux_handler = {aacraid_linux_ioctl,
AAC_LINUX_IOCTL_MIN,
AAC_LINUX_IOCTL_MAX};
SYSINIT (aacraid_linux_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_register_handler, &aacraid_linux_handler);
SYSUNINIT(aacraid_linux_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_unregister_handler, &aacraid_linux_handler);
static int
aacraid_linux_modevent(module_t mod, int type, void *data)
{
/* Do we care about any specific load/unload actions? */
return (0);
}
DEV_MODULE(aacraid_linux, aacraid_linux_modevent, NULL);
MODULE_DEPEND(aacraid_linux, linux, 1, 1, 1);
static int
aacraid_linux_ioctl(struct thread *td, struct linux_ioctl_args *args)
{
struct file *fp;
cap_rights_t rights;
u_long cmd;
int error;
if ((error = fget(td, args->fd,
- cap_rights_init(&rights, CAP_IOCTL),
+ cap_rights_init_one(&rights, CAP_IOCTL),
&fp)) != 0) {
return (error);
}
cmd = args->cmd;
/*
* Pass the ioctl off to our standard handler.
*/
error = (fo_ioctl(fp, cmd, (caddr_t)args->arg, td->td_ucred, td));
fdrop(fp, td);
return (error);
}
diff --git a/sys/dev/amr/amr_linux.c b/sys/dev/amr/amr_linux.c
index 967907cc6846..9e0a5cac693e 100644
--- a/sys/dev/amr/amr_linux.c
+++ b/sys/dev/amr/amr_linux.c
@@ -1,87 +1,87 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2005 Paul Saab
* 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 AUTHOR 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 AUTHOR 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.
*
*/
#include
__FBSDID("$FreeBSD$");
#include
#include
#include
#include
#include
#include
#include
#include
#if defined(__amd64__) /* Assume amd64 wants 32 bit Linux */
#include
#include
#else
#include
#include
#endif
#include
/* There are multiple ioctl number ranges that need to be handled */
#define AMR_LINUX_IOCTL_MIN 0x6d00
#define AMR_LINUX_IOCTL_MAX 0x6d01
static linux_ioctl_function_t amr_linux_ioctl;
static struct linux_ioctl_handler amr_linux_handler = {amr_linux_ioctl,
AMR_LINUX_IOCTL_MIN,
AMR_LINUX_IOCTL_MAX};
SYSINIT (amr_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_register_handler, &amr_linux_handler);
SYSUNINIT(amr_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_unregister_handler, &amr_linux_handler);
static int
amr_linux_modevent(module_t mod, int cmd, void *data)
{
return (0);
}
DEV_MODULE(amr_linux, amr_linux_modevent, NULL);
MODULE_DEPEND(amr, linux, 1, 1, 1);
static int
amr_linux_ioctl(struct thread *p, struct linux_ioctl_args *args)
{
cap_rights_t rights;
struct file *fp;
int error;
- error = fget(p, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
+ error = fget(p, args->fd, cap_rights_init_one(&rights, CAP_IOCTL), &fp);
if (error != 0)
return (error);
error = fo_ioctl(fp, args->cmd, (caddr_t)args->arg, p->td_ucred, p);
fdrop(fp, p);
return (error);
}
diff --git a/sys/dev/cxgbe/cxgbei/icl_cxgbei.c b/sys/dev/cxgbe/cxgbei/icl_cxgbei.c
index f5d4f03476cb..5588d3cb9511 100644
--- a/sys/dev/cxgbe/cxgbei/icl_cxgbei.c
+++ b/sys/dev/cxgbe/cxgbei/icl_cxgbei.c
@@ -1,1098 +1,1098 @@
/*-
* Copyright (c) 2012 The FreeBSD Foundation
* Copyright (c) 2015 Chelsio Communications, Inc.
* All rights reserved.
*
* This software was developed by Edward Tomasz Napierala under sponsorship
* from the FreeBSD Foundation.
*
* 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 AUTHOR 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 AUTHOR 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.
*
*/
/*
* cxgbei implementation of iSCSI Common Layer kobj(9) interface.
*/
#include
__FBSDID("$FreeBSD$");
#include "opt_inet.h"
#include "opt_inet6.h"
#ifdef TCP_OFFLOAD
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "common/common.h"
#include "common/t4_tcb.h"
#include "tom/t4_tom.h"
#include "cxgbei.h"
SYSCTL_NODE(_kern_icl, OID_AUTO, cxgbei, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
"Chelsio iSCSI offload");
static int coalesce = 1;
SYSCTL_INT(_kern_icl_cxgbei, OID_AUTO, coalesce, CTLFLAG_RWTUN,
&coalesce, 0, "Try to coalesce PDUs before sending");
static int partial_receive_len = 128 * 1024;
SYSCTL_INT(_kern_icl_cxgbei, OID_AUTO, partial_receive_len, CTLFLAG_RWTUN,
&partial_receive_len, 0, "Minimum read size for partially received "
"data segment");
static int sendspace = 1048576;
SYSCTL_INT(_kern_icl_cxgbei, OID_AUTO, sendspace, CTLFLAG_RWTUN,
&sendspace, 0, "Default send socket buffer size");
static int recvspace = 1048576;
SYSCTL_INT(_kern_icl_cxgbei, OID_AUTO, recvspace, CTLFLAG_RWTUN,
&recvspace, 0, "Default receive socket buffer size");
static uma_zone_t prsv_zone;
static volatile u_int icl_cxgbei_ncons;
#define ICL_CONN_LOCK(X) mtx_lock(X->ic_lock)
#define ICL_CONN_UNLOCK(X) mtx_unlock(X->ic_lock)
#define ICL_CONN_LOCK_ASSERT(X) mtx_assert(X->ic_lock, MA_OWNED)
#define ICL_CONN_LOCK_ASSERT_NOT(X) mtx_assert(X->ic_lock, MA_NOTOWNED)
struct icl_pdu *icl_cxgbei_new_pdu(int);
void icl_cxgbei_new_pdu_set_conn(struct icl_pdu *, struct icl_conn *);
static icl_conn_new_pdu_t icl_cxgbei_conn_new_pdu;
icl_conn_pdu_free_t icl_cxgbei_conn_pdu_free;
static icl_conn_pdu_data_segment_length_t
icl_cxgbei_conn_pdu_data_segment_length;
static icl_conn_pdu_append_data_t icl_cxgbei_conn_pdu_append_data;
static icl_conn_pdu_get_data_t icl_cxgbei_conn_pdu_get_data;
static icl_conn_pdu_queue_t icl_cxgbei_conn_pdu_queue;
static icl_conn_handoff_t icl_cxgbei_conn_handoff;
static icl_conn_free_t icl_cxgbei_conn_free;
static icl_conn_close_t icl_cxgbei_conn_close;
static icl_conn_task_setup_t icl_cxgbei_conn_task_setup;
static icl_conn_task_done_t icl_cxgbei_conn_task_done;
static icl_conn_transfer_setup_t icl_cxgbei_conn_transfer_setup;
static icl_conn_transfer_done_t icl_cxgbei_conn_transfer_done;
static kobj_method_t icl_cxgbei_methods[] = {
KOBJMETHOD(icl_conn_new_pdu, icl_cxgbei_conn_new_pdu),
KOBJMETHOD(icl_conn_pdu_free, icl_cxgbei_conn_pdu_free),
KOBJMETHOD(icl_conn_pdu_data_segment_length,
icl_cxgbei_conn_pdu_data_segment_length),
KOBJMETHOD(icl_conn_pdu_append_data, icl_cxgbei_conn_pdu_append_data),
KOBJMETHOD(icl_conn_pdu_get_data, icl_cxgbei_conn_pdu_get_data),
KOBJMETHOD(icl_conn_pdu_queue, icl_cxgbei_conn_pdu_queue),
KOBJMETHOD(icl_conn_handoff, icl_cxgbei_conn_handoff),
KOBJMETHOD(icl_conn_free, icl_cxgbei_conn_free),
KOBJMETHOD(icl_conn_close, icl_cxgbei_conn_close),
KOBJMETHOD(icl_conn_task_setup, icl_cxgbei_conn_task_setup),
KOBJMETHOD(icl_conn_task_done, icl_cxgbei_conn_task_done),
KOBJMETHOD(icl_conn_transfer_setup, icl_cxgbei_conn_transfer_setup),
KOBJMETHOD(icl_conn_transfer_done, icl_cxgbei_conn_transfer_done),
{ 0, 0 }
};
DEFINE_CLASS(icl_cxgbei, icl_cxgbei_methods, sizeof(struct icl_cxgbei_conn));
void
icl_cxgbei_conn_pdu_free(struct icl_conn *ic, struct icl_pdu *ip)
{
#ifdef INVARIANTS
struct icl_cxgbei_pdu *icp = ip_to_icp(ip);
#endif
MPASS(icp->icp_signature == CXGBEI_PDU_SIGNATURE);
MPASS(ic == ip->ip_conn);
MPASS(ip->ip_bhs_mbuf != NULL);
m_freem(ip->ip_ahs_mbuf);
m_freem(ip->ip_data_mbuf);
m_freem(ip->ip_bhs_mbuf); /* storage for icl_cxgbei_pdu itself */
#ifdef DIAGNOSTIC
if (__predict_true(ic != NULL))
refcount_release(&ic->ic_outstanding_pdus);
#endif
}
struct icl_pdu *
icl_cxgbei_new_pdu(int flags)
{
struct icl_cxgbei_pdu *icp;
struct icl_pdu *ip;
struct mbuf *m;
uintptr_t a;
m = m_gethdr(flags, MT_DATA);
if (__predict_false(m == NULL))
return (NULL);
a = roundup2(mtod(m, uintptr_t), _Alignof(struct icl_cxgbei_pdu));
icp = (struct icl_cxgbei_pdu *)a;
bzero(icp, sizeof(*icp));
icp->icp_signature = CXGBEI_PDU_SIGNATURE;
ip = &icp->ip;
ip->ip_bhs_mbuf = m;
a = roundup2((uintptr_t)(icp + 1), _Alignof(struct iscsi_bhs *));
ip->ip_bhs = (struct iscsi_bhs *)a;
#ifdef INVARIANTS
/* Everything must fit entirely in the mbuf. */
a = (uintptr_t)(ip->ip_bhs + 1);
MPASS(a <= (uintptr_t)m + MSIZE);
#endif
bzero(ip->ip_bhs, sizeof(*ip->ip_bhs));
m->m_data = (void *)ip->ip_bhs;
m->m_len = sizeof(struct iscsi_bhs);
m->m_pkthdr.len = m->m_len;
return (ip);
}
void
icl_cxgbei_new_pdu_set_conn(struct icl_pdu *ip, struct icl_conn *ic)
{
ip->ip_conn = ic;
#ifdef DIAGNOSTIC
refcount_acquire(&ic->ic_outstanding_pdus);
#endif
}
/*
* Allocate icl_pdu with empty BHS to fill up by the caller.
*/
static struct icl_pdu *
icl_cxgbei_conn_new_pdu(struct icl_conn *ic, int flags)
{
struct icl_pdu *ip;
ip = icl_cxgbei_new_pdu(flags);
if (__predict_false(ip == NULL))
return (NULL);
icl_cxgbei_new_pdu_set_conn(ip, ic);
return (ip);
}
static size_t
icl_pdu_data_segment_length(const struct icl_pdu *request)
{
uint32_t len = 0;
len += request->ip_bhs->bhs_data_segment_len[0];
len <<= 8;
len += request->ip_bhs->bhs_data_segment_len[1];
len <<= 8;
len += request->ip_bhs->bhs_data_segment_len[2];
return (len);
}
size_t
icl_cxgbei_conn_pdu_data_segment_length(struct icl_conn *ic,
const struct icl_pdu *request)
{
return (icl_pdu_data_segment_length(request));
}
static struct mbuf *
finalize_pdu(struct icl_cxgbei_conn *icc, struct icl_cxgbei_pdu *icp)
{
struct icl_pdu *ip = &icp->ip;
uint8_t ulp_submode, padding;
struct mbuf *m, *last;
struct iscsi_bhs *bhs;
/*
* Fix up the data segment mbuf first.
*/
m = ip->ip_data_mbuf;
ulp_submode = icc->ulp_submode;
if (m) {
last = m_last(m);
/*
* Round up the data segment to a 4B boundary. Pad with 0 if
* necessary. There will definitely be room in the mbuf.
*/
padding = roundup2(ip->ip_data_len, 4) - ip->ip_data_len;
if (padding) {
bzero(mtod(last, uint8_t *) + last->m_len, padding);
last->m_len += padding;
}
} else {
MPASS(ip->ip_data_len == 0);
ulp_submode &= ~ULP_CRC_DATA;
padding = 0;
}
/*
* Now the header mbuf that has the BHS.
*/
m = ip->ip_bhs_mbuf;
MPASS(m->m_pkthdr.len == sizeof(struct iscsi_bhs));
MPASS(m->m_len == sizeof(struct iscsi_bhs));
bhs = ip->ip_bhs;
bhs->bhs_data_segment_len[2] = ip->ip_data_len;
bhs->bhs_data_segment_len[1] = ip->ip_data_len >> 8;
bhs->bhs_data_segment_len[0] = ip->ip_data_len >> 16;
/* "Convert" PDU to mbuf chain. Do not use icp/ip after this. */
m->m_pkthdr.len = sizeof(struct iscsi_bhs) + ip->ip_data_len + padding;
m->m_next = ip->ip_data_mbuf;
set_mbuf_ulp_submode(m, ulp_submode);
#ifdef INVARIANTS
bzero(icp, sizeof(*icp));
#endif
#ifdef DIAGNOSTIC
refcount_release(&icc->ic.ic_outstanding_pdus);
#endif
return (m);
}
int
icl_cxgbei_conn_pdu_append_data(struct icl_conn *ic, struct icl_pdu *ip,
const void *addr, size_t len, int flags)
{
struct mbuf *m;
#ifdef INVARIANTS
struct icl_cxgbei_pdu *icp = ip_to_icp(ip);
#endif
MPASS(icp->icp_signature == CXGBEI_PDU_SIGNATURE);
MPASS(ic == ip->ip_conn);
KASSERT(len > 0, ("%s: len is %jd", __func__, (intmax_t)len));
m = ip->ip_data_mbuf;
if (m == NULL) {
m = m_getjcl(M_NOWAIT, MT_DATA, 0, MJUM16BYTES);
if (__predict_false(m == NULL))
return (ENOMEM);
ip->ip_data_mbuf = m;
}
if (__predict_true(m_append(m, len, addr) != 0)) {
ip->ip_data_len += len;
MPASS(ip->ip_data_len <= ic->ic_max_data_segment_length);
return (0);
} else {
if (flags & M_WAITOK) {
CXGBE_UNIMPLEMENTED("fail safe append");
}
ip->ip_data_len = m_length(m, NULL);
return (1);
}
}
void
icl_cxgbei_conn_pdu_get_data(struct icl_conn *ic, struct icl_pdu *ip,
size_t off, void *addr, size_t len)
{
struct icl_cxgbei_pdu *icp = ip_to_icp(ip);
if (icp->icp_flags & ICPF_RX_DDP)
return; /* data is DDP'ed, no need to copy */
m_copydata(ip->ip_data_mbuf, off, len, addr);
}
void
icl_cxgbei_conn_pdu_queue(struct icl_conn *ic, struct icl_pdu *ip)
{
struct icl_cxgbei_conn *icc = ic_to_icc(ic);
struct icl_cxgbei_pdu *icp = ip_to_icp(ip);
struct socket *so = ic->ic_socket;
struct toepcb *toep = icc->toep;
struct inpcb *inp;
struct mbuf *m;
MPASS(ic == ip->ip_conn);
MPASS(ip->ip_bhs_mbuf != NULL);
/* The kernel doesn't generate PDUs with AHS. */
MPASS(ip->ip_ahs_mbuf == NULL && ip->ip_ahs_len == 0);
ICL_CONN_LOCK_ASSERT(ic);
/* NOTE: sowriteable without so_snd lock is a mostly harmless race. */
if (ic->ic_disconnecting || so == NULL || !sowriteable(so)) {
icl_cxgbei_conn_pdu_free(ic, ip);
return;
}
m = finalize_pdu(icc, icp);
M_ASSERTPKTHDR(m);
MPASS((m->m_pkthdr.len & 3) == 0);
/*
* Do not get inp from toep->inp as the toepcb might have detached
* already.
*/
inp = sotoinpcb(so);
INP_WLOCK(inp);
if (__predict_false(inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) ||
__predict_false((toep->flags & TPF_ATTACHED) == 0))
m_freem(m);
else {
mbufq_enqueue(&toep->ulp_pduq, m);
t4_push_pdus(icc->sc, toep, 0);
}
INP_WUNLOCK(inp);
}
static struct icl_conn *
icl_cxgbei_new_conn(const char *name, struct mtx *lock)
{
struct icl_cxgbei_conn *icc;
struct icl_conn *ic;
refcount_acquire(&icl_cxgbei_ncons);
icc = (struct icl_cxgbei_conn *)kobj_create(&icl_cxgbei_class, M_CXGBE,
M_WAITOK | M_ZERO);
icc->icc_signature = CXGBEI_CONN_SIGNATURE;
STAILQ_INIT(&icc->rcvd_pdus);
ic = &icc->ic;
ic->ic_lock = lock;
/* XXXNP: review. Most of these icl_conn fields aren't really used */
STAILQ_INIT(&ic->ic_to_send);
cv_init(&ic->ic_send_cv, "icl_cxgbei_tx");
cv_init(&ic->ic_receive_cv, "icl_cxgbei_rx");
#ifdef DIAGNOSTIC
refcount_init(&ic->ic_outstanding_pdus, 0);
#endif
/* This is a stop-gap value that will be corrected during handoff. */
ic->ic_max_data_segment_length = 16384;
ic->ic_name = name;
ic->ic_offload = "cxgbei";
ic->ic_unmapped = false;
CTR2(KTR_CXGBE, "%s: icc %p", __func__, icc);
return (ic);
}
void
icl_cxgbei_conn_free(struct icl_conn *ic)
{
struct icl_cxgbei_conn *icc = ic_to_icc(ic);
MPASS(icc->icc_signature == CXGBEI_CONN_SIGNATURE);
CTR2(KTR_CXGBE, "%s: icc %p", __func__, icc);
cv_destroy(&ic->ic_send_cv);
cv_destroy(&ic->ic_receive_cv);
kobj_delete((struct kobj *)icc, M_CXGBE);
refcount_release(&icl_cxgbei_ncons);
}
static int
icl_cxgbei_setsockopt(struct icl_conn *ic, struct socket *so, int sspace,
int rspace)
{
struct sockopt opt;
int error, one = 1, ss, rs;
ss = max(sendspace, sspace);
rs = max(recvspace, rspace);
error = soreserve(so, ss, rs);
if (error != 0) {
icl_cxgbei_conn_close(ic);
return (error);
}
SOCKBUF_LOCK(&so->so_snd);
so->so_snd.sb_flags |= SB_AUTOSIZE;
SOCKBUF_UNLOCK(&so->so_snd);
SOCKBUF_LOCK(&so->so_rcv);
so->so_rcv.sb_flags |= SB_AUTOSIZE;
SOCKBUF_UNLOCK(&so->so_rcv);
/*
* Disable Nagle.
*/
bzero(&opt, sizeof(opt));
opt.sopt_dir = SOPT_SET;
opt.sopt_level = IPPROTO_TCP;
opt.sopt_name = TCP_NODELAY;
opt.sopt_val = &one;
opt.sopt_valsize = sizeof(one);
error = sosetopt(so, &opt);
if (error != 0) {
icl_cxgbei_conn_close(ic);
return (error);
}
return (0);
}
/*
* Request/response structure used to find out the adapter offloading a socket.
*/
struct find_ofld_adapter_rr {
struct socket *so;
struct adapter *sc; /* result */
};
static void
find_offload_adapter(struct adapter *sc, void *arg)
{
struct find_ofld_adapter_rr *fa = arg;
struct socket *so = fa->so;
struct tom_data *td = sc->tom_softc;
struct tcpcb *tp;
struct inpcb *inp;
/* Non-TCP were filtered out earlier. */
MPASS(so->so_proto->pr_protocol == IPPROTO_TCP);
if (fa->sc != NULL)
return; /* Found already. */
if (td == NULL)
return; /* TOE not enabled on this adapter. */
inp = sotoinpcb(so);
INP_WLOCK(inp);
if ((inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) == 0) {
tp = intotcpcb(inp);
if (tp->t_flags & TF_TOE && tp->tod == &td->tod)
fa->sc = sc; /* Found. */
}
INP_WUNLOCK(inp);
}
/* XXXNP: move this to t4_tom. */
static void
send_iscsi_flowc_wr(struct adapter *sc, struct toepcb *toep, int maxlen)
{
struct wrqe *wr;
struct fw_flowc_wr *flowc;
const u_int nparams = 1;
u_int flowclen;
struct ofld_tx_sdesc *txsd = &toep->txsd[toep->txsd_pidx];
flowclen = sizeof(*flowc) + nparams * sizeof(struct fw_flowc_mnemval);
wr = alloc_wrqe(roundup2(flowclen, 16), toep->ofld_txq);
if (wr == NULL) {
/* XXX */
panic("%s: allocation failure.", __func__);
}
flowc = wrtod(wr);
memset(flowc, 0, wr->wr_len);
flowc->op_to_nparams = htobe32(V_FW_WR_OP(FW_FLOWC_WR) |
V_FW_FLOWC_WR_NPARAMS(nparams));
flowc->flowid_len16 = htonl(V_FW_WR_LEN16(howmany(flowclen, 16)) |
V_FW_WR_FLOWID(toep->tid));
flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_TXDATAPLEN_MAX;
flowc->mnemval[0].val = htobe32(maxlen);
txsd->tx_credits = howmany(flowclen, 16);
txsd->plen = 0;
KASSERT(toep->tx_credits >= txsd->tx_credits && toep->txsd_avail > 0,
("%s: not enough credits (%d)", __func__, toep->tx_credits));
toep->tx_credits -= txsd->tx_credits;
if (__predict_false(++toep->txsd_pidx == toep->txsd_total))
toep->txsd_pidx = 0;
toep->txsd_avail--;
t4_wrq_tx(sc, wr);
}
static void
set_ulp_mode_iscsi(struct adapter *sc, struct toepcb *toep, int hcrc, int dcrc)
{
uint64_t val = ULP_MODE_ISCSI;
if (hcrc)
val |= ULP_CRC_HEADER << 4;
if (dcrc)
val |= ULP_CRC_DATA << 4;
CTR4(KTR_CXGBE, "%s: tid %u, ULP_MODE_ISCSI, CRC hdr=%d data=%d",
__func__, toep->tid, hcrc, dcrc);
t4_set_tcb_field(sc, toep->ctrlq, toep, W_TCB_ULP_TYPE,
V_TCB_ULP_TYPE(M_TCB_ULP_TYPE) | V_TCB_ULP_RAW(M_TCB_ULP_RAW), val,
0, 0);
}
/*
* XXXNP: Who is responsible for cleaning up the socket if this returns with an
* error? Review all error paths.
*
* XXXNP: What happens to the socket's fd reference if the operation is
* successful, and how does that affect the socket's life cycle?
*/
int
icl_cxgbei_conn_handoff(struct icl_conn *ic, int fd)
{
struct icl_cxgbei_conn *icc = ic_to_icc(ic);
struct cxgbei_data *ci;
struct find_ofld_adapter_rr fa;
struct file *fp;
struct socket *so;
struct inpcb *inp;
struct tcpcb *tp;
struct toepcb *toep;
cap_rights_t rights;
int error;
MPASS(icc->icc_signature == CXGBEI_CONN_SIGNATURE);
ICL_CONN_LOCK_ASSERT_NOT(ic);
/*
* Steal the socket from userland.
*/
error = fget(curthread, fd,
- cap_rights_init(&rights, CAP_SOCK_CLIENT), &fp);
+ cap_rights_init_one(&rights, CAP_SOCK_CLIENT), &fp);
if (error != 0)
return (error);
if (fp->f_type != DTYPE_SOCKET) {
fdrop(fp, curthread);
return (EINVAL);
}
so = fp->f_data;
if (so->so_type != SOCK_STREAM ||
so->so_proto->pr_protocol != IPPROTO_TCP) {
fdrop(fp, curthread);
return (EINVAL);
}
ICL_CONN_LOCK(ic);
if (ic->ic_socket != NULL) {
ICL_CONN_UNLOCK(ic);
fdrop(fp, curthread);
return (EBUSY);
}
ic->ic_disconnecting = false;
ic->ic_socket = so;
fp->f_ops = &badfileops;
fp->f_data = NULL;
fdrop(fp, curthread);
ICL_CONN_UNLOCK(ic);
/* Find the adapter offloading this socket. */
fa.sc = NULL;
fa.so = so;
t4_iterate(find_offload_adapter, &fa);
if (fa.sc == NULL)
return (EINVAL);
icc->sc = fa.sc;
ci = icc->sc->iscsi_ulp_softc;
inp = sotoinpcb(so);
INP_WLOCK(inp);
tp = intotcpcb(inp);
if (inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT))
error = EBUSY;
else {
/*
* socket could not have been "unoffloaded" if here.
*/
MPASS(tp->t_flags & TF_TOE);
MPASS(tp->tod != NULL);
MPASS(tp->t_toe != NULL);
toep = tp->t_toe;
MPASS(toep->vi->adapter == icc->sc);
icc->toep = toep;
icc->cwt = cxgbei_select_worker_thread(icc);
/*
* We maintain the _send_ DSL in this field just to have a
* convenient way to assert that the kernel never sends
* oversized PDUs. This field is otherwise unused in the driver
* or the kernel.
*/
ic->ic_max_data_segment_length = ci->max_tx_pdu_len -
ISCSI_BHS_SIZE;
icc->ulp_submode = 0;
if (ic->ic_header_crc32c) {
icc->ulp_submode |= ULP_CRC_HEADER;
ic->ic_max_data_segment_length -=
ISCSI_HEADER_DIGEST_SIZE;
}
if (ic->ic_data_crc32c) {
icc->ulp_submode |= ULP_CRC_DATA;
ic->ic_max_data_segment_length -=
ISCSI_DATA_DIGEST_SIZE;
}
so->so_options |= SO_NO_DDP;
toep->params.ulp_mode = ULP_MODE_ISCSI;
toep->ulpcb = icc;
send_iscsi_flowc_wr(icc->sc, toep, ci->max_tx_pdu_len);
set_ulp_mode_iscsi(icc->sc, toep, ic->ic_header_crc32c,
ic->ic_data_crc32c);
error = 0;
}
INP_WUNLOCK(inp);
if (error == 0) {
error = icl_cxgbei_setsockopt(ic, so, ci->max_tx_pdu_len,
ci->max_rx_pdu_len);
}
return (error);
}
void
icl_cxgbei_conn_close(struct icl_conn *ic)
{
struct icl_cxgbei_conn *icc = ic_to_icc(ic);
struct icl_pdu *ip;
struct socket *so;
struct sockbuf *sb;
struct inpcb *inp;
struct toepcb *toep = icc->toep;
MPASS(icc->icc_signature == CXGBEI_CONN_SIGNATURE);
ICL_CONN_LOCK_ASSERT_NOT(ic);
ICL_CONN_LOCK(ic);
so = ic->ic_socket;
if (ic->ic_disconnecting || so == NULL) {
CTR4(KTR_CXGBE, "%s: icc %p (disconnecting = %d), so %p",
__func__, icc, ic->ic_disconnecting, so);
ICL_CONN_UNLOCK(ic);
return;
}
ic->ic_disconnecting = true;
/* These are unused in this driver right now. */
MPASS(STAILQ_EMPTY(&ic->ic_to_send));
MPASS(ic->ic_receive_pdu == NULL);
#ifdef DIAGNOSTIC
KASSERT(ic->ic_outstanding_pdus == 0,
("destroying session with %d outstanding PDUs",
ic->ic_outstanding_pdus));
#endif
ICL_CONN_UNLOCK(ic);
CTR3(KTR_CXGBE, "%s: tid %d, icc %p", __func__, toep ? toep->tid : -1,
icc);
inp = sotoinpcb(so);
sb = &so->so_rcv;
INP_WLOCK(inp);
if (toep != NULL) { /* NULL if connection was never offloaded. */
toep->ulpcb = NULL;
mbufq_drain(&toep->ulp_pduq);
SOCKBUF_LOCK(sb);
if (icc->rx_flags & RXF_ACTIVE) {
volatile u_int *p = &icc->rx_flags;
SOCKBUF_UNLOCK(sb);
INP_WUNLOCK(inp);
while (*p & RXF_ACTIVE)
pause("conclo", 1);
INP_WLOCK(inp);
SOCKBUF_LOCK(sb);
}
while (!STAILQ_EMPTY(&icc->rcvd_pdus)) {
ip = STAILQ_FIRST(&icc->rcvd_pdus);
STAILQ_REMOVE_HEAD(&icc->rcvd_pdus, ip_next);
icl_cxgbei_conn_pdu_free(ic, ip);
}
SOCKBUF_UNLOCK(sb);
}
INP_WUNLOCK(inp);
ICL_CONN_LOCK(ic);
ic->ic_socket = NULL;
ICL_CONN_UNLOCK(ic);
/*
* XXXNP: we should send RST instead of FIN when PDUs held in various
* queues were purged instead of delivered reliably but soabort isn't
* really general purpose and wouldn't do the right thing here.
*/
soclose(so);
}
int
icl_cxgbei_conn_task_setup(struct icl_conn *ic, struct icl_pdu *ip,
struct ccb_scsiio *csio, uint32_t *ittp, void **arg)
{
struct icl_cxgbei_conn *icc = ic_to_icc(ic);
struct toepcb *toep = icc->toep;
struct adapter *sc = icc->sc;
struct cxgbei_data *ci = sc->iscsi_ulp_softc;
struct ppod_region *pr = &ci->pr;
struct ppod_reservation *prsv;
uint32_t itt;
int rc = 0;
/* This is for the offload driver's state. Must not be set already. */
MPASS(arg != NULL);
MPASS(*arg == NULL);
if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_IN ||
csio->dxfer_len < ci->ddp_threshold) {
no_ddp:
/*
* No DDP for this I/O. Allocate an ITT (based on the one
* passed in) that cannot be a valid hardware DDP tag in the
* iSCSI region.
*/
itt = *ittp & M_PPOD_TAG;
itt = V_PPOD_TAG(itt) | pr->pr_invalid_bit;
*ittp = htobe32(itt);
MPASS(*arg == NULL); /* State is maintained for DDP only. */
if (rc != 0)
counter_u64_add(ci->ddp_setup_error, 1);
return (0);
}
/*
* Reserve resources for DDP, update the itt that should be used in the
* PDU, and save DDP specific state for this I/O in *arg.
*/
prsv = uma_zalloc(prsv_zone, M_NOWAIT);
if (prsv == NULL) {
rc = ENOMEM;
goto no_ddp;
}
/* XXX add support for all CAM_DATA_ types */
MPASS((csio->ccb_h.flags & CAM_DATA_MASK) == CAM_DATA_VADDR);
rc = t4_alloc_page_pods_for_buf(pr, (vm_offset_t)csio->data_ptr,
csio->dxfer_len, prsv);
if (rc != 0) {
uma_zfree(prsv_zone, prsv);
goto no_ddp;
}
rc = t4_write_page_pods_for_buf(sc, toep->ofld_txq, toep->tid, prsv,
(vm_offset_t)csio->data_ptr, csio->dxfer_len);
if (rc != 0) {
t4_free_page_pods(prsv);
uma_zfree(prsv_zone, prsv);
goto no_ddp;
}
*ittp = htobe32(prsv->prsv_tag);
*arg = prsv;
counter_u64_add(ci->ddp_setup_ok, 1);
return (0);
}
void
icl_cxgbei_conn_task_done(struct icl_conn *ic, void *arg)
{
if (arg != NULL) {
struct ppod_reservation *prsv = arg;
t4_free_page_pods(prsv);
uma_zfree(prsv_zone, prsv);
}
}
/* XXXNP: PDU should be passed in as parameter, like on the initiator. */
#define io_to_request_pdu(io) ((io)->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr)
#define io_to_ppod_reservation(io) ((io)->io_hdr.ctl_private[CTL_PRIV_FRONTEND2].ptr)
int
icl_cxgbei_conn_transfer_setup(struct icl_conn *ic, union ctl_io *io,
uint32_t *tttp, void **arg)
{
struct icl_cxgbei_conn *icc = ic_to_icc(ic);
struct toepcb *toep = icc->toep;
struct ctl_scsiio *ctsio = &io->scsiio;
struct adapter *sc = icc->sc;
struct cxgbei_data *ci = sc->iscsi_ulp_softc;
struct ppod_region *pr = &ci->pr;
struct ppod_reservation *prsv;
uint32_t ttt;
int xferlen, rc = 0, alias;
/* This is for the offload driver's state. Must not be set already. */
MPASS(arg != NULL);
MPASS(*arg == NULL);
if (ctsio->ext_data_filled == 0) {
int first_burst;
struct icl_pdu *ip = io_to_request_pdu(io);
vm_offset_t buf;
#ifdef INVARIANTS
struct icl_cxgbei_pdu *icp = ip_to_icp(ip);
MPASS(icp->icp_signature == CXGBEI_PDU_SIGNATURE);
MPASS(ic == ip->ip_conn);
MPASS(ip->ip_bhs_mbuf != NULL);
#endif
first_burst = icl_pdu_data_segment_length(ip);
/*
* Note that ICL calls conn_transfer_setup even if the first
* burst had everything and there's nothing left to transfer.
*/
MPASS(ctsio->kern_data_len >= first_burst);
xferlen = ctsio->kern_data_len;
if (xferlen - first_burst < ci->ddp_threshold) {
no_ddp:
/*
* No DDP for this transfer. Allocate a TTT (based on
* the one passed in) that cannot be a valid hardware
* DDP tag in the iSCSI region.
*/
ttt = *tttp & M_PPOD_TAG;
ttt = V_PPOD_TAG(ttt) | pr->pr_invalid_bit;
*tttp = htobe32(ttt);
MPASS(io_to_ppod_reservation(io) == NULL);
if (rc != 0)
counter_u64_add(ci->ddp_setup_error, 1);
return (0);
}
if (ctsio->kern_sg_entries == 0)
buf = (vm_offset_t)ctsio->kern_data_ptr;
else if (ctsio->kern_sg_entries == 1) {
struct ctl_sg_entry *sgl = (void *)ctsio->kern_data_ptr;
MPASS(sgl->len == xferlen);
buf = (vm_offset_t)sgl->addr;
} else {
rc = EAGAIN; /* XXX implement */
goto no_ddp;
}
/*
* Reserve resources for DDP, update the ttt that should be used
* in the PDU, and save DDP specific state for this I/O.
*/
MPASS(io_to_ppod_reservation(io) == NULL);
prsv = uma_zalloc(prsv_zone, M_NOWAIT);
if (prsv == NULL) {
rc = ENOMEM;
goto no_ddp;
}
rc = t4_alloc_page_pods_for_buf(pr, buf, xferlen, prsv);
if (rc != 0) {
uma_zfree(prsv_zone, prsv);
goto no_ddp;
}
rc = t4_write_page_pods_for_buf(sc, toep->ofld_txq, toep->tid,
prsv, buf, xferlen);
if (rc != 0) {
t4_free_page_pods(prsv);
uma_zfree(prsv_zone, prsv);
goto no_ddp;
}
*tttp = htobe32(prsv->prsv_tag);
io_to_ppod_reservation(io) = prsv;
*arg = ctsio;
counter_u64_add(ci->ddp_setup_ok, 1);
return (0);
}
/*
* In the middle of an I/O. A non-NULL page pod reservation indicates
* that a DDP buffer is being used for the I/O.
*/
prsv = io_to_ppod_reservation(ctsio);
if (prsv == NULL)
goto no_ddp;
alias = (prsv->prsv_tag & pr->pr_alias_mask) >> pr->pr_alias_shift;
alias++;
prsv->prsv_tag &= ~pr->pr_alias_mask;
prsv->prsv_tag |= alias << pr->pr_alias_shift & pr->pr_alias_mask;
*tttp = htobe32(prsv->prsv_tag);
*arg = ctsio;
return (0);
}
void
icl_cxgbei_conn_transfer_done(struct icl_conn *ic, void *arg)
{
struct ctl_scsiio *ctsio = arg;
if (ctsio != NULL && ctsio->kern_data_len == ctsio->ext_data_filled) {
struct ppod_reservation *prsv;
prsv = io_to_ppod_reservation(ctsio);
MPASS(prsv != NULL);
t4_free_page_pods(prsv);
uma_zfree(prsv_zone, prsv);
}
}
static void
cxgbei_limits(struct adapter *sc, void *arg)
{
struct icl_drv_limits *idl = arg;
struct cxgbei_data *ci;
int max_dsl;
if (begin_synchronized_op(sc, NULL, HOLD_LOCK, "t4lims") != 0)
return;
if (uld_active(sc, ULD_ISCSI)) {
ci = sc->iscsi_ulp_softc;
MPASS(ci != NULL);
/*
* AHS is not supported by the kernel so we'll not account for
* it either in our PDU len -> data segment len conversions.
*/
max_dsl = ci->max_rx_pdu_len - ISCSI_BHS_SIZE -
ISCSI_HEADER_DIGEST_SIZE - ISCSI_DATA_DIGEST_SIZE;
if (idl->idl_max_recv_data_segment_length > max_dsl)
idl->idl_max_recv_data_segment_length = max_dsl;
max_dsl = ci->max_tx_pdu_len - ISCSI_BHS_SIZE -
ISCSI_HEADER_DIGEST_SIZE - ISCSI_DATA_DIGEST_SIZE;
if (idl->idl_max_send_data_segment_length > max_dsl)
idl->idl_max_send_data_segment_length = max_dsl;
}
end_synchronized_op(sc, LOCK_HELD);
}
static int
icl_cxgbei_limits(struct icl_drv_limits *idl)
{
/* Maximum allowed by the RFC. cxgbei_limits will clip them. */
idl->idl_max_recv_data_segment_length = (1 << 24) - 1;
idl->idl_max_send_data_segment_length = (1 << 24) - 1;
/* These are somewhat arbitrary. */
idl->idl_max_burst_length = 2 * 1024 * 1024;
idl->idl_first_burst_length = 8192;
t4_iterate(cxgbei_limits, idl);
return (0);
}
int
icl_cxgbei_mod_load(void)
{
int rc;
/*
* Space to track pagepod reservations.
*/
prsv_zone = uma_zcreate("Pagepod reservations",
sizeof(struct ppod_reservation), NULL, NULL, NULL, NULL,
UMA_ALIGN_CACHE, 0);
refcount_init(&icl_cxgbei_ncons, 0);
rc = icl_register("cxgbei", false, -100, icl_cxgbei_limits,
icl_cxgbei_new_conn);
return (rc);
}
int
icl_cxgbei_mod_unload(void)
{
if (icl_cxgbei_ncons != 0)
return (EBUSY);
icl_unregister("cxgbei", false);
uma_zdestroy(prsv_zone);
return (0);
}
#endif
diff --git a/sys/dev/filemon/filemon_wrapper.c b/sys/dev/filemon/filemon_wrapper.c
index 52dd3bb483eb..4e64d8254f8d 100644
--- a/sys/dev/filemon/filemon_wrapper.c
+++ b/sys/dev/filemon/filemon_wrapper.c
@@ -1,460 +1,460 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2011, David E. O'Brien.
* Copyright (c) 2009-2011, Juniper Networks, Inc.
* Copyright (c) 2015-2016, EMC Corp.
* 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 JUNIPER NETWORKS 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 JUNIPER NETWORKS 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.
*/
#include
__FBSDID("$FreeBSD$");
#include
#include
#include
#include
#include
#include
#include
#include
static void filemon_output_event(struct filemon *filemon, const char *fmt, ...)
__printflike(2, 3);
static eventhandler_tag filemon_exec_tag;
static eventhandler_tag filemon_exit_tag;
static eventhandler_tag filemon_fork_tag;
static void
filemon_output(struct filemon *filemon, char *msg, size_t len)
{
struct uio auio;
struct iovec aiov;
int error;
if (filemon->fp == NULL)
return;
aiov.iov_base = msg;
aiov.iov_len = len;
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_resid = len;
auio.uio_segflg = UIO_SYSSPACE;
auio.uio_rw = UIO_WRITE;
auio.uio_td = curthread;
auio.uio_offset = (off_t) -1;
if (filemon->fp->f_type == DTYPE_VNODE)
bwillwrite();
error = fo_write(filemon->fp, &auio, filemon->cred, 0, curthread);
if (error != 0 && filemon->error == 0)
filemon->error = error;
}
static void
filemon_output_event(struct filemon *filemon, const char *fmt, ...)
{
va_list ap;
size_t len;
va_start(ap, fmt);
len = vsnprintf(filemon->msgbufr, sizeof(filemon->msgbufr), fmt, ap);
va_end(ap);
/* The event is truncated but still worth logging. */
if (len >= sizeof(filemon->msgbufr))
len = sizeof(filemon->msgbufr) - 1;
filemon_output(filemon, filemon->msgbufr, len);
}
static int
filemon_wrapper_chdir(struct thread *td, struct chdir_args *uap)
{
int error, ret;
struct filemon *filemon;
if ((ret = sys_chdir(td, uap)) == 0) {
if ((filemon = filemon_proc_get(curproc)) != NULL) {
if ((error = copyinstr(uap->path, filemon->fname1,
sizeof(filemon->fname1), NULL)) != 0) {
filemon->error = error;
goto copyfail;
}
filemon_output_event(filemon, "C %d %s\n",
curproc->p_pid, filemon->fname1);
copyfail:
filemon_drop(filemon);
}
}
return (ret);
}
static void
filemon_event_process_exec(void *arg __unused, struct proc *p,
struct image_params *imgp)
{
struct filemon *filemon;
if ((filemon = filemon_proc_get(p)) != NULL) {
filemon_output_event(filemon, "E %d %s\n",
p->p_pid,
imgp->execpath != NULL ? imgp->execpath : "");
/* If the credentials changed then cease tracing. */
if (imgp->newcred != NULL &&
imgp->credential_setid &&
priv_check_cred(filemon->cred, PRIV_DEBUG_DIFFCRED) != 0) {
/*
* It may have changed to NULL already, but
* will not be re-attached by anything else.
*/
if (p->p_filemon != NULL) {
KASSERT(p->p_filemon == filemon,
("%s: proc %p didn't have expected"
" filemon %p", __func__, p, filemon));
filemon_proc_drop(p);
}
}
filemon_drop(filemon);
}
}
static void
_filemon_wrapper_openat(struct thread *td, const char *upath, int flags,
int fd)
{
int error;
struct file *fp;
struct filemon *filemon;
char *atpath, *freepath;
cap_rights_t rights;
if ((filemon = filemon_proc_get(curproc)) != NULL) {
atpath = "";
freepath = NULL;
fp = NULL;
if ((error = copyinstr(upath, filemon->fname1,
sizeof(filemon->fname1), NULL)) != 0) {
filemon->error = error;
goto copyfail;
}
if (filemon->fname1[0] != '/' && fd != AT_FDCWD) {
/*
* rats - we cannot do too much about this.
* the trace should show a dir we read
* recently.. output an A record as a clue
* until we can do better.
* XXX: This may be able to come out with
* the namecache lookup now.
*/
filemon_output_event(filemon, "A %d %s\n",
curproc->p_pid, filemon->fname1);
/*
* Try to resolve the path from the vnode using the
* namecache. It may be inaccurate, but better
* than nothing.
*/
if (getvnode(td, fd,
- cap_rights_init(&rights, CAP_LOOKUP), &fp) == 0) {
+ cap_rights_init_one(&rights, CAP_LOOKUP), &fp) == 0) {
vn_fullpath(fp->f_vnode, &atpath, &freepath);
}
}
if (flags & O_RDWR) {
/*
* We'll get the W record below, but need
* to also output an R to distinguish from
* O_WRONLY.
*/
filemon_output_event(filemon, "R %d %s%s%s\n",
curproc->p_pid, atpath,
atpath[0] != '\0' ? "/" : "", filemon->fname1);
}
filemon_output_event(filemon, "%c %d %s%s%s\n",
(flags & O_ACCMODE) ? 'W':'R',
curproc->p_pid, atpath,
atpath[0] != '\0' ? "/" : "", filemon->fname1);
copyfail:
filemon_drop(filemon);
if (fp != NULL)
fdrop(fp, td);
free(freepath, M_TEMP);
}
}
static int
filemon_wrapper_open(struct thread *td, struct open_args *uap)
{
int ret;
if ((ret = sys_open(td, uap)) == 0)
_filemon_wrapper_openat(td, uap->path, uap->flags, AT_FDCWD);
return (ret);
}
static int
filemon_wrapper_openat(struct thread *td, struct openat_args *uap)
{
int ret;
if ((ret = sys_openat(td, uap)) == 0)
_filemon_wrapper_openat(td, uap->path, uap->flag, uap->fd);
return (ret);
}
static int
filemon_wrapper_rename(struct thread *td, struct rename_args *uap)
{
int error, ret;
struct filemon *filemon;
if ((ret = sys_rename(td, uap)) == 0) {
if ((filemon = filemon_proc_get(curproc)) != NULL) {
if (((error = copyinstr(uap->from, filemon->fname1,
sizeof(filemon->fname1), NULL)) != 0) ||
((error = copyinstr(uap->to, filemon->fname2,
sizeof(filemon->fname2), NULL)) != 0)) {
filemon->error = error;
goto copyfail;
}
filemon_output_event(filemon, "M %d '%s' '%s'\n",
curproc->p_pid, filemon->fname1, filemon->fname2);
copyfail:
filemon_drop(filemon);
}
}
return (ret);
}
static void
_filemon_wrapper_link(struct thread *td, const char *upath1,
const char *upath2)
{
struct filemon *filemon;
int error;
if ((filemon = filemon_proc_get(curproc)) != NULL) {
if (((error = copyinstr(upath1, filemon->fname1,
sizeof(filemon->fname1), NULL)) != 0) ||
((error = copyinstr(upath2, filemon->fname2,
sizeof(filemon->fname2), NULL)) != 0)) {
filemon->error = error;
goto copyfail;
}
filemon_output_event(filemon, "L %d '%s' '%s'\n",
curproc->p_pid, filemon->fname1, filemon->fname2);
copyfail:
filemon_drop(filemon);
}
}
static int
filemon_wrapper_link(struct thread *td, struct link_args *uap)
{
int ret;
if ((ret = sys_link(td, uap)) == 0)
_filemon_wrapper_link(td, uap->path, uap->link);
return (ret);
}
static int
filemon_wrapper_symlink(struct thread *td, struct symlink_args *uap)
{
int ret;
if ((ret = sys_symlink(td, uap)) == 0)
_filemon_wrapper_link(td, uap->path, uap->link);
return (ret);
}
static int
filemon_wrapper_linkat(struct thread *td, struct linkat_args *uap)
{
int ret;
if ((ret = sys_linkat(td, uap)) == 0)
_filemon_wrapper_link(td, uap->path1, uap->path2);
return (ret);
}
static void
filemon_event_process_exit(void *arg __unused, struct proc *p)
{
struct filemon *filemon;
if ((filemon = filemon_proc_get(p)) != NULL) {
filemon_output_event(filemon, "X %d %d %d\n",
p->p_pid, p->p_xexit, p->p_xsig);
/*
* filemon_untrack_processes() may have dropped this p_filemon
* already while in filemon_proc_get() before acquiring the
* filemon lock.
*/
KASSERT(p->p_filemon == NULL || p->p_filemon == filemon,
("%s: p %p was attached while exiting, expected "
"filemon %p or NULL", __func__, p, filemon));
if (p->p_filemon == filemon)
filemon_proc_drop(p);
filemon_drop(filemon);
}
}
static int
filemon_wrapper_unlink(struct thread *td, struct unlink_args *uap)
{
int error, ret;
struct filemon *filemon;
if ((ret = sys_unlink(td, uap)) == 0) {
if ((filemon = filemon_proc_get(curproc)) != NULL) {
if ((error = copyinstr(uap->path, filemon->fname1,
sizeof(filemon->fname1), NULL)) != 0) {
filemon->error = error;
goto copyfail;
}
filemon_output_event(filemon, "D %d %s\n",
curproc->p_pid, filemon->fname1);
copyfail:
filemon_drop(filemon);
}
}
return (ret);
}
static void
filemon_event_process_fork(void *arg __unused, struct proc *p1,
struct proc *p2, int flags __unused)
{
struct filemon *filemon;
if ((filemon = filemon_proc_get(p1)) != NULL) {
filemon_output_event(filemon, "F %d %d\n",
p1->p_pid, p2->p_pid);
/*
* filemon_untrack_processes() or
* filemon_ioctl(FILEMON_SET_PID) may have changed the parent's
* p_filemon while in filemon_proc_get() before acquiring the
* filemon lock. Only inherit if the parent is still traced by
* this filemon.
*/
if (p1->p_filemon == filemon) {
PROC_LOCK(p2);
/*
* It may have been attached to already by a new
* filemon.
*/
if (p2->p_filemon == NULL) {
p2->p_filemon = filemon_acquire(filemon);
++filemon->proccnt;
}
PROC_UNLOCK(p2);
}
filemon_drop(filemon);
}
}
static void
filemon_wrapper_install(void)
{
sysent[SYS_chdir].sy_call = (sy_call_t *) filemon_wrapper_chdir;
sysent[SYS_open].sy_call = (sy_call_t *) filemon_wrapper_open;
sysent[SYS_openat].sy_call = (sy_call_t *) filemon_wrapper_openat;
sysent[SYS_rename].sy_call = (sy_call_t *) filemon_wrapper_rename;
sysent[SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink;
sysent[SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link;
sysent[SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink;
sysent[SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat;
#if defined(COMPAT_FREEBSD32)
freebsd32_sysent[FREEBSD32_SYS_chdir].sy_call = (sy_call_t *) filemon_wrapper_chdir;
freebsd32_sysent[FREEBSD32_SYS_open].sy_call = (sy_call_t *) filemon_wrapper_open;
freebsd32_sysent[FREEBSD32_SYS_openat].sy_call = (sy_call_t *) filemon_wrapper_openat;
freebsd32_sysent[FREEBSD32_SYS_rename].sy_call = (sy_call_t *) filemon_wrapper_rename;
freebsd32_sysent[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink;
freebsd32_sysent[FREEBSD32_SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link;
freebsd32_sysent[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink;
freebsd32_sysent[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat;
#endif /* COMPAT_FREEBSD32 */
filemon_exec_tag = EVENTHANDLER_REGISTER(process_exec,
filemon_event_process_exec, NULL, EVENTHANDLER_PRI_LAST);
filemon_exit_tag = EVENTHANDLER_REGISTER(process_exit,
filemon_event_process_exit, NULL, EVENTHANDLER_PRI_LAST);
filemon_fork_tag = EVENTHANDLER_REGISTER(process_fork,
filemon_event_process_fork, NULL, EVENTHANDLER_PRI_LAST);
}
static void
filemon_wrapper_deinstall(void)
{
sysent[SYS_chdir].sy_call = (sy_call_t *)sys_chdir;
sysent[SYS_open].sy_call = (sy_call_t *)sys_open;
sysent[SYS_openat].sy_call = (sy_call_t *)sys_openat;
sysent[SYS_rename].sy_call = (sy_call_t *)sys_rename;
sysent[SYS_unlink].sy_call = (sy_call_t *)sys_unlink;
sysent[SYS_link].sy_call = (sy_call_t *)sys_link;
sysent[SYS_symlink].sy_call = (sy_call_t *)sys_symlink;
sysent[SYS_linkat].sy_call = (sy_call_t *)sys_linkat;
#if defined(COMPAT_FREEBSD32)
freebsd32_sysent[FREEBSD32_SYS_chdir].sy_call = (sy_call_t *)sys_chdir;
freebsd32_sysent[FREEBSD32_SYS_open].sy_call = (sy_call_t *)sys_open;
freebsd32_sysent[FREEBSD32_SYS_openat].sy_call = (sy_call_t *)sys_openat;
freebsd32_sysent[FREEBSD32_SYS_rename].sy_call = (sy_call_t *)sys_rename;
freebsd32_sysent[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *)sys_unlink;
freebsd32_sysent[FREEBSD32_SYS_link].sy_call = (sy_call_t *)sys_link;
freebsd32_sysent[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *)sys_symlink;
freebsd32_sysent[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *)sys_linkat;
#endif /* COMPAT_FREEBSD32 */
EVENTHANDLER_DEREGISTER(process_exec, filemon_exec_tag);
EVENTHANDLER_DEREGISTER(process_exit, filemon_exit_tag);
EVENTHANDLER_DEREGISTER(process_fork, filemon_fork_tag);
}
diff --git a/sys/dev/ipmi/ipmi_linux.c b/sys/dev/ipmi/ipmi_linux.c
index 136712e8cfb5..4b33c5b014d8 100644
--- a/sys/dev/ipmi/ipmi_linux.c
+++ b/sys/dev/ipmi/ipmi_linux.c
@@ -1,118 +1,119 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2009 IronPort Systems Inc.
* 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 AUTHOR 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 AUTHOR 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.
*/
#include
__FBSDID("$FreeBSD$");
/*
* Linux ioctl handler for the ipmi device driver
*/
#include
#include
#include
#include
#include