Module Name: src
Committed By: martin
Date: Sat Oct 26 15:56:31 UTC 2024
Modified Files:
src/sys/compat/netbsd32 [netbsd-10]: netbsd32_compat_16.c
netbsd32_signal.c
Log Message:
Pull up following revision(s) (requested by rin in ticket #989):
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.5
sys/compat/netbsd32/netbsd32_compat_16.c: revision 1.6
sys/compat/netbsd32/netbsd32_signal.c: revision 1.54
In netbsd32___sigaction_sigtramp continue to use the compat module when
already locked for this process.
Enable compat sigreturn system call.
netbsd32_compat_16.c: Fix whitespace.
No functional change intended.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.4.4.1 src/sys/compat/netbsd32/netbsd32_compat_16.c
cvs rdiff -u -r1.53 -r1.53.4.1 src/sys/compat/netbsd32/netbsd32_signal.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/compat/netbsd32/netbsd32_compat_16.c
diff -u src/sys/compat/netbsd32/netbsd32_compat_16.c:1.4 src/sys/compat/netbsd32/netbsd32_compat_16.c:1.4.4.1
--- src/sys/compat/netbsd32/netbsd32_compat_16.c:1.4 Fri Nov 26 08:06:11 2021
+++ src/sys/compat/netbsd32/netbsd32_compat_16.c Sat Oct 26 15:56:31 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_compat_16.c,v 1.4 2021/11/26 08:06:11 ryo Exp $ */
+/* $NetBSD: netbsd32_compat_16.c,v 1.4.4.1 2024/10/26 15:56:31 martin Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,13 +29,14 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_16.c,v 1.4 2021/11/26 08:06:11 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_16.c,v 1.4.4.1 2024/10/26 15:56:31 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/dirent.h>
#include <sys/exec.h>
+#include <sys/proc.h>
#include <sys/lwp.h>
#include <sys/syscallargs.h>
#include <sys/syscallvar.h>
@@ -47,40 +48,90 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_com
struct uvm_object *emul_netbsd32_object;
-MODULE(MODULE_CLASS_EXEC, compat_netbsd32_16, "compat_netbsd32_20,compat_16");
+static const struct syscall_package netbsd32_kern_sig_16_syscalls[] = {
+ /* compat_16_netbs32___sigreturn14 is in MD code! */
+ { NETBSD32_SYS_compat_16_netbsd32___sigreturn14, 0,
+ (sy_call_t *)compat_16_netbsd32___sigreturn14 },
+ { 0, 0, NULL }
+};
static int
-compat_netbsd32_16_modcmd(modcmd_t cmd, void *arg)
+compat_netbsd32_16_init(void)
+{
+ int error;
+
+ error = syscall_establish(&emul_netbsd32,
+ netbsd32_kern_sig_16_syscalls);
+ if (error)
+ return error;
+
+ rw_enter(&exec_lock, RW_WRITER);
+ emul_netbsd32.e_sigcode = netbsd32_sigcode;
+ emul_netbsd32.e_esigcode = netbsd32_esigcode;
+ emul_netbsd32.e_sigobject = &emul_netbsd32_object;
+ error = exec_sigcode_alloc(&emul_netbsd);
+ if (error) {
+ emul_netbsd32.e_sigcode = NULL;
+ emul_netbsd32.e_esigcode = NULL;
+ emul_netbsd32.e_sigobject = NULL;
+ }
+ rw_exit(&exec_lock);
+ if (error)
+ return error;
+ netbsd32_machdep_md_16_init();
+ return 0;
+}
+
+static int
+compat_netbsd32_16_fini(void)
{
+ proc_t *p;
int error;
+ error = syscall_disestablish(&emul_netbsd32,
+ netbsd32_kern_sig_16_syscalls);
+ if (error)
+ return error;
+ /*
+ * Ensure sendsig_sigcontext() is not being used.
+ * module_lock prevents the flag being set on any
+ * further processes while we are here. See
+ * sigaction1() for the opposing half.
+ */
+ mutex_enter(&proc_lock);
+ PROCLIST_FOREACH(p, &allproc) {
+ if ((p->p_lflag & PL_SIGCOMPAT) != 0) {
+ break;
+ }
+ }
+ mutex_exit(&proc_lock);
+ if (p != NULL) {
+ syscall_establish(&emul_netbsd32,
+ netbsd32_kern_sig_16_syscalls);
+ return EBUSY;
+ }
+
+ rw_enter(&exec_lock, RW_WRITER);
+ exec_sigcode_free(&emul_netbsd);
+ emul_netbsd32.e_sigcode = NULL;
+ emul_netbsd32.e_esigcode = NULL;
+ emul_netbsd32.e_sigobject = NULL;
+ rw_exit(&exec_lock);
+ netbsd32_machdep_md_16_fini();
+ return 0;
+}
+
+MODULE(MODULE_CLASS_EXEC, compat_netbsd32_16, "compat_netbsd32_20,compat_16");
+
+static int
+compat_netbsd32_16_modcmd(modcmd_t cmd, void *arg)
+{
switch (cmd) {
case MODULE_CMD_INIT:
- rw_enter(&exec_lock, RW_WRITER);
- emul_netbsd32.e_sigcode = netbsd32_sigcode;
- emul_netbsd32.e_esigcode = netbsd32_esigcode;
- emul_netbsd32.e_sigobject = &emul_netbsd32_object;
- error = exec_sigcode_alloc(&emul_netbsd);
- if (error) {
- emul_netbsd32.e_sigcode = NULL;
- emul_netbsd32.e_esigcode = NULL;
- emul_netbsd32.e_sigobject = NULL;
- }
- rw_exit(&exec_lock);
- if (error)
- return error;
- netbsd32_machdep_md_16_init();
- return 0;
+ return compat_netbsd32_16_init();
case MODULE_CMD_FINI:
- rw_enter(&exec_lock, RW_WRITER);
- exec_sigcode_free(&emul_netbsd);
- emul_netbsd32.e_sigcode = NULL;
- emul_netbsd32.e_esigcode = NULL;
- emul_netbsd32.e_sigobject = NULL;
- rw_exit(&exec_lock);
- netbsd32_machdep_md_16_fini();
- return 0;
+ return compat_netbsd32_16_fini();
default:
return ENOTTY;
Index: src/sys/compat/netbsd32/netbsd32_signal.c
diff -u src/sys/compat/netbsd32/netbsd32_signal.c:1.53 src/sys/compat/netbsd32/netbsd32_signal.c:1.53.4.1
--- src/sys/compat/netbsd32/netbsd32_signal.c:1.53 Sat Nov 6 20:42:56 2021
+++ src/sys/compat/netbsd32/netbsd32_signal.c Sat Oct 26 15:56:31 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_signal.c,v 1.53 2021/11/06 20:42:56 thorpej Exp $ */
+/* $NetBSD: netbsd32_signal.c,v 1.53.4.1 2024/10/26 15:56:31 martin Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.53 2021/11/06 20:42:56 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.53.4.1 2024/10/26 15:56:31 martin Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ktrace.h"
@@ -184,7 +184,7 @@ netbsd32___sigaction_sigtramp(struct lwp
*/
#ifdef __HAVE_STRUCT_SIGCONTEXT
struct proc *p = l->l_proc;
- bool sigcontext_valid = false;
+ bool sigcontext_valid;
/*
* We need to ensure the compat_netbsd32_16 module
@@ -196,9 +196,7 @@ netbsd32___sigaction_sigtramp(struct lwp
kernconfig_lock();
(void)module_autoload("compat_netbsd32_16",
MODULE_CLASS_ANY);
- if (netbsd32_sendsig_sigcontext_16_hook.hooked) {
- sigcontext_valid = true;
- }
+ sigcontext_valid = netbsd32_sendsig_sigcontext_16_hook.hooked;
mutex_enter(&proc_lock);
/*
* Prevent unload of compat module while
@@ -207,6 +205,11 @@ netbsd32___sigaction_sigtramp(struct lwp
p->p_lflag |= PL_SIGCOMPAT;
mutex_exit(&proc_lock);
kernconfig_unlock();
+ } else {
+ /*
+ * Module is already loaded and locked in memory
+ */
+ sigcontext_valid = netbsd32_sendsig_sigcontext_16_hook.hooked;
}
if (!sigcontext_valid) {
return EINVAL;