From 1a0fa34dd333102e135ede3be3100f5c43b789f9 Mon Sep 17 00:00:00 2001 From: pgoyette Date: Tue, 1 Dec 2015 23:56:43 +0000 Subject: [PATCH] Prepare for new compat_netbsd32_mqueue module to be split out of compat_netbsd32. Refactor the COMPAT_50 code related to mqueue, and update the syscall definitions. Remove dependency on mqueue from the compat_netbsd32 module (the new module will gain this dependency). Continuation of work on PR kern/50489 --- sys/compat/netbsd32/netbsd32_compat_50.c | 73 +------------- sys/compat/netbsd32/netbsd32_mod.c | 6 +- sys/compat/netbsd32/netbsd32_mqueue.c | 122 ++++++++++++++++++++++- sys/compat/netbsd32/syscalls.master | 38 ++++--- 4 files changed, 150 insertions(+), 89 deletions(-) diff --git a/sys/compat/netbsd32/netbsd32_compat_50.c b/sys/compat/netbsd32/netbsd32_compat_50.c index 4e38c0d18911..b34c86a50f88 100644 --- a/sys/compat/netbsd32/netbsd32_compat_50.c +++ b/sys/compat/netbsd32/netbsd32_compat_50.c @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_compat_50.c,v 1.30 2015/07/24 13:02:52 maxv Exp $ */ +/* $NetBSD: netbsd32_compat_50.c,v 1.31 2015/12/01 23:56:43 pgoyette Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.30 2015/07/24 13:02:52 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.31 2015/12/01 23:56:43 pgoyette Exp $"); #if defined(_KERNEL_OPT) #include "opt_sysv.h" @@ -1079,72 +1079,3 @@ compat_50_netbsd32_quotactl(struct lwp *l, const struct compat_50_netbsd32_quota return (compat_50_sys_quotactl(l, &ua, retval)); } -int -compat_50_netbsd32_mq_timedsend(struct lwp *l, - const struct compat_50_netbsd32_mq_timedsend_args *uap, - register_t *retval) -{ - /* { - syscallarg(mqd_t) mqdes; - syscallarg(const netbsd32_charp) msg_ptr; - syscallarg(netbsd32_size_t) msg_len; - syscallarg(unsigned) msg_prio; - syscallarg(const netbsd32_timespec50p_t) abs_timeout; - } */ - struct timespec ts, *tsp; - struct netbsd32_timespec50 ts32; - int error; - - /* Get and convert time value */ - if (SCARG_P32(uap, abs_timeout)) { - error = copyin(SCARG_P32(uap, abs_timeout), &ts32, - sizeof(ts32)); - if (error) - return error; - netbsd32_to_timespec50(&ts32, &ts); - tsp = &ts; - } else { - tsp = NULL; - } - - return mq_send1(SCARG(uap, mqdes), SCARG_P32(uap, msg_ptr), - SCARG(uap, msg_len), SCARG(uap, msg_prio), tsp); -} - -int -compat_50_netbsd32_mq_timedreceive(struct lwp *l, - const struct compat_50_netbsd32_mq_timedreceive_args *uap, - register_t *retval) -{ - /* { - syscallarg(mqd_t) mqdes; - syscallarg(netbsd32_charp) msg_ptr; - syscallarg(netbsd32_size_t) msg_len; - syscallarg(netbsd32_uintp) msg_prio; - syscallarg(const netbsd32_timespec50p_t) abs_timeout; - } */ - struct timespec ts, *tsp; - struct netbsd32_timespec50 ts32; - ssize_t mlen; - int error; - - /* Get and convert time value */ - if (SCARG_P32(uap, abs_timeout)) { - error = copyin(SCARG_P32(uap, abs_timeout), &ts32, - sizeof(ts32)); - if (error) - return error; - netbsd32_to_timespec50(&ts32, &ts); - tsp = &ts; - } else { - tsp = NULL; - } - - error = mq_recv1(SCARG(uap, mqdes), SCARG_P32(uap, msg_ptr), - SCARG(uap, msg_len), SCARG_P32(uap, msg_prio), tsp, &mlen); - if (error == 0) - *retval = mlen; - - return error; -} - diff --git a/sys/compat/netbsd32/netbsd32_mod.c b/sys/compat/netbsd32/netbsd32_mod.c index cf727b35b321..e2887699e4e0 100644 --- a/sys/compat/netbsd32/netbsd32_mod.c +++ b/sys/compat/netbsd32/netbsd32_mod.c @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_mod.c,v 1.11 2015/12/01 09:12:23 pgoyette Exp $ */ +/* $NetBSD: netbsd32_mod.c,v 1.12 2015/12/01 23:56:43 pgoyette Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.11 2015/12/01 09:12:23 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.12 2015/12/01 23:56:43 pgoyette Exp $"); #ifdef _KERNEL_OPT #include "opt_execfmt.h" @@ -48,7 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.11 2015/12/01 09:12:23 pgoyette E #include #include -# define DEPS1 "compat,compat_sysv,mqueue,ksem" +# define DEPS1 "compat,compat_sysv,ksem" #if defined(EXEC_ELF32) # define DEPS2 ",exec_elf32" diff --git a/sys/compat/netbsd32/netbsd32_mqueue.c b/sys/compat/netbsd32/netbsd32_mqueue.c index 967cd9704faa..b56086c1faa5 100644 --- a/sys/compat/netbsd32/netbsd32_mqueue.c +++ b/sys/compat/netbsd32/netbsd32_mqueue.c @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_mqueue.c,v 1.5 2015/06/30 11:56:27 christos Exp $ */ +/* $NetBSD: netbsd32_mqueue.c,v 1.6 2015/12/01 23:56:43 pgoyette Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: netbsd32_mqueue.c,v 1.5 2015/06/30 11:56:27 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_mqueue.c,v 1.6 2015/12/01 23:56:43 pgoyette Exp $"); #if defined(_KERNEL_OPT) #include "opt_compat_netbsd.h" @@ -40,12 +40,14 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_mqueue.c,v 1.5 2015/06/30 11:56:27 christos #include #include #include +#include #include #include #include #include +extern struct emul emul_netbsd32; int netbsd32_mq_open(struct lwp *l, const struct netbsd32_mq_open_args *uap, @@ -322,3 +324,119 @@ netbsd32___mq_timedreceive50(struct lwp *l, return error; } +#ifdef COMPAT_50 + +int +compat_50_netbsd32_mq_timedsend(struct lwp *l, + const struct compat_50_netbsd32_mq_timedsend_args *uap, + register_t *retval) +{ + /* { + syscallarg(mqd_t) mqdes; + syscallarg(const netbsd32_charp) msg_ptr; + syscallarg(netbsd32_size_t) msg_len; + syscallarg(unsigned) msg_prio; + syscallarg(const netbsd32_timespec50p_t) abs_timeout; + } */ + struct timespec ts, *tsp; + struct netbsd32_timespec50 ts32; + int error; + + /* Get and convert time value */ + if (SCARG_P32(uap, abs_timeout)) { + error = copyin(SCARG_P32(uap, abs_timeout), &ts32, + sizeof(ts32)); + if (error) + return error; + netbsd32_to_timespec50(&ts32, &ts); + tsp = &ts; + } else { + tsp = NULL; + } + + return mq_send1(SCARG(uap, mqdes), SCARG_P32(uap, msg_ptr), + SCARG(uap, msg_len), SCARG(uap, msg_prio), tsp); +} + +int +compat_50_netbsd32_mq_timedreceive(struct lwp *l, + const struct compat_50_netbsd32_mq_timedreceive_args *uap, + register_t *retval) +{ + /* { + syscallarg(mqd_t) mqdes; + syscallarg(netbsd32_charp) msg_ptr; + syscallarg(netbsd32_size_t) msg_len; + syscallarg(netbsd32_uintp) msg_prio; + syscallarg(const netbsd32_timespec50p_t) abs_timeout; + } */ + struct timespec ts, *tsp; + struct netbsd32_timespec50 ts32; + ssize_t mlen; + int error; + + /* Get and convert time value */ + if (SCARG_P32(uap, abs_timeout)) { + error = copyin(SCARG_P32(uap, abs_timeout), &ts32, + sizeof(ts32)); + if (error) + return error; + netbsd32_to_timespec50(&ts32, &ts); + tsp = &ts; + } else { + tsp = NULL; + } + + error = mq_recv1(SCARG(uap, mqdes), SCARG_P32(uap, msg_ptr), + SCARG(uap, msg_len), SCARG_P32(uap, msg_prio), tsp, &mlen); + if (error == 0) + *retval = mlen; + + return error; +} + +#endif /* COMPAT_50 */ + +#define _PKG_ENTRY(name) \ + { NETBSD32_SYS_ ## name, 0, (sy_call_t *)name } + +static const struct syscall_package compat_mqueue_syscalls[] = { + _PKG_ENTRY(netbsd32_mq_open), + _PKG_ENTRY(netbsd32_mq_close), + _PKG_ENTRY(netbsd32_mq_unlink), + _PKG_ENTRY(netbsd32_mq_getattr), + _PKG_ENTRY(netbsd32_mq_setattr), + _PKG_ENTRY(netbsd32_mq_notify), + _PKG_ENTRY(netbsd32_mq_send), + _PKG_ENTRY(netbsd32_mq_receive), + _PKG_ENTRY(netbsd32___mq_timedsend50), + _PKG_ENTRY(netbsd32___mq_timedreceive50), +#ifdef COMPAT_50 + _PKG_ENTRY(compat_50_netbsd32_mq_timedsend), + _PKG_ENTRY(compat_50_netbsd32_mq_timedreceive), +#endif + {0, 0, NULL} +}; + +MODULE(MODULE_CLASS_EXEC, compat_netbsd32_mqueue, "mqueue,compat_netbsd32"); + +static int +compat_netbsd32_mqueue_modcmd(modcmd_t cmd, void *arg) +{ + int error; + + switch (cmd) { + case MODULE_CMD_INIT: + error = syscall_establish(&emul_netbsd32, + compat_mqueue_syscalls); + break; + case MODULE_CMD_FINI: + error = syscall_disestablish(&emul_netbsd32, + compat_mqueue_syscalls); + break; + default: + error = ENOTTY; + break; + } + return error; +} diff --git a/sys/compat/netbsd32/syscalls.master b/sys/compat/netbsd32/syscalls.master index a04e1759a863..963bd9608938 100644 --- a/sys/compat/netbsd32/syscalls.master +++ b/sys/compat/netbsd32/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.110 2015/12/01 09:10:03 pgoyette Exp $ + $NetBSD: syscalls.master,v 1.111 2015/12/01 23:56:43 pgoyette Exp $ ; from: NetBSD: syscalls.master,v 1.81 1998/07/05 08:49:50 jonathan Exp ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -534,30 +534,40 @@ 255 STD { int|netbsd32||_ksem_destroy(netbsd32_intptr_t id); } 256 STD { int|netbsd32||_ksem_timedwait(intptr_t id, \ const netbsd32_timespecp_t abstime); } -257 STD { mqd_t|netbsd32||mq_open(const netbsd32_charp name, \ +257 STD MODULAR compat_netbsd32_mqueue \ + { mqd_t|netbsd32||mq_open(const netbsd32_charp name, \ int oflag, mode_t mode, \ netbsd32_mq_attrp_t attr); } -258 STD { int|netbsd32||mq_close(mqd_t mqdes); } -259 STD { int|netbsd32||mq_unlink(const netbsd32_charp name); } -260 STD { int|netbsd32||mq_getattr(mqd_t mqdes, \ +258 STD MODULAR compat_netbsd32_mqueue \ + { int|netbsd32||mq_close(mqd_t mqdes); } +259 STD MODULAR compat_netbsd32_mqueue \ + { int|netbsd32||mq_unlink(const netbsd32_charp name); } +260 STD MODULAR compat_netbsd32_mqueue \ + { int|netbsd32||mq_getattr(mqd_t mqdes, \ netbsd32_mq_attrp_t mqstat); } -261 STD { int|netbsd32||mq_setattr(mqd_t mqdes, \ +261 STD MODULAR compat_netbsd32_mqueue \ + { int|netbsd32||mq_setattr(mqd_t mqdes, \ const netbsd32_mq_attrp_t mqstat, \ netbsd32_mq_attrp_t omqstat); } -262 STD { int|netbsd32||mq_notify(mqd_t mqdes, \ +262 STD MODULAR compat_netbsd32_mqueue \ + { int|netbsd32||mq_notify(mqd_t mqdes, \ const netbsd32_sigeventp_t notification); } -263 STD { int|netbsd32||mq_send(mqd_t mqdes, \ +263 STD MODULAR compat_netbsd32_mqueue \ + { int|netbsd32||mq_send(mqd_t mqdes, \ const netbsd32_charp msg_ptr, \ netbsd32_size_t msg_len, unsigned msg_prio); } -264 STD { netbsd32_ssize_t|netbsd32||mq_receive(mqd_t mqdes, \ +264 STD MODULAR compat_netbsd32_mqueue \ + { netbsd32_ssize_t|netbsd32||mq_receive(mqd_t mqdes, \ netbsd32_charp msg_ptr, \ netbsd32_size_t msg_len, netbsd32_uintp msg_prio); } -265 COMPAT_50 { int|netbsd32||mq_timedsend(mqd_t mqdes, \ +265 COMPAT_50 MODULAR compat_netbsd32_mqueue \ + { int|netbsd32||mq_timedsend(mqd_t mqdes, \ const netbsd32_charp msg_ptr, \ netbsd32_size_t msg_len, \ unsigned msg_prio, \ const netbsd32_timespec50p_t abs_timeout); } -266 COMPAT_50 { netbsd32_ssize_t|netbsd32||mq_timedreceive( \ +266 COMPAT_50 MODULAR compat_netbsd32_mqueue \ + { netbsd32_ssize_t|netbsd32||mq_timedreceive( \ mqd_t mqdes, \ netbsd32_charp msg_ptr, netbsd32_size_t msg_len, \ netbsd32_uintp msg_prio, \ @@ -911,12 +921,14 @@ const netbsd32_sigsetp_t set, \ netbsd32_siginfop_t info, \ netbsd32_timespecp_t timeout); } -432 STD { int|netbsd32|50|mq_timedsend(mqd_t mqdes, \ +432 STD MODULAR compat_netbsd32_mqueue \ + { int|netbsd32|50|mq_timedsend(mqd_t mqdes, \ const netbsd32_charp msg_ptr, \ netbsd32_size_t msg_len, \ unsigned msg_prio, \ const netbsd32_timespecp_t abs_timeout); } -433 STD { netbsd32_ssize_t|netbsd32|50|mq_timedreceive( \ +433 STD MODULAR compat_netbsd32_mqueue \ + { netbsd32_ssize_t|netbsd32|50|mq_timedreceive( \ mqd_t mqdes, netbsd32_charp msg_ptr, \ netbsd32_size_t msg_len, netbsd32_uintp msg_prio, \ const netbsd32_timespecp_t abs_timeout); }