xref: /netbsd-src/sys/compat/netbsd32/netbsd32_kern_proc.c (revision 9fc453562f6ebe8eabdfd51e21ae0a0058906d4f)
1*9fc45356Sriastradh /*	$NetBSD: netbsd32_kern_proc.c,v 1.6 2020/09/05 16:30:10 riastradh Exp $	*/
2d91f98a8Spgoyette 
3d91f98a8Spgoyette /*-
4d91f98a8Spgoyette  * Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
5d91f98a8Spgoyette  * All rights reserved.
6d91f98a8Spgoyette  *
7d91f98a8Spgoyette  * This code is derived from software contributed to The NetBSD Foundation
8d91f98a8Spgoyette  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9d91f98a8Spgoyette  * NASA Ames Research Center, and by Andrew Doran.
10d91f98a8Spgoyette  *
11d91f98a8Spgoyette  * Redistribution and use in source and binary forms, with or without
12d91f98a8Spgoyette  * modification, are permitted provided that the following conditions
13d91f98a8Spgoyette  * are met:
14d91f98a8Spgoyette  * 1. Redistributions of source code must retain the above copyright
15d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer.
16d91f98a8Spgoyette  * 2. Redistributions in binary form must reproduce the above copyright
17d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer in the
18d91f98a8Spgoyette  *    documentation and/or other materials provided with the distribution.
19d91f98a8Spgoyette  *
20d91f98a8Spgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21d91f98a8Spgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22d91f98a8Spgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23d91f98a8Spgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24d91f98a8Spgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25d91f98a8Spgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26d91f98a8Spgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27d91f98a8Spgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28d91f98a8Spgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29d91f98a8Spgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30d91f98a8Spgoyette  * POSSIBILITY OF SUCH DAMAGE.
31d91f98a8Spgoyette  */
32d91f98a8Spgoyette 
33d91f98a8Spgoyette /*
34d91f98a8Spgoyette  * Copyright (c) 1982, 1986, 1989, 1991, 1993
35d91f98a8Spgoyette  *	The Regents of the University of California.  All rights reserved.
36d91f98a8Spgoyette  *
37d91f98a8Spgoyette  * Redistribution and use in source and binary forms, with or without
38d91f98a8Spgoyette  * modification, are permitted provided that the following conditions
39d91f98a8Spgoyette  * are met:
40d91f98a8Spgoyette  * 1. Redistributions of source code must retain the above copyright
41d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer.
42d91f98a8Spgoyette  * 2. Redistributions in binary form must reproduce the above copyright
43d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer in the
44d91f98a8Spgoyette  *    documentation and/or other materials provided with the distribution.
45d91f98a8Spgoyette  * 3. Neither the name of the University nor the names of its contributors
46d91f98a8Spgoyette  *    may be used to endorse or promote products derived from this software
47d91f98a8Spgoyette  *    without specific prior written permission.
48d91f98a8Spgoyette  *
49d91f98a8Spgoyette  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50d91f98a8Spgoyette  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51d91f98a8Spgoyette  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52d91f98a8Spgoyette  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53d91f98a8Spgoyette  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54d91f98a8Spgoyette  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55d91f98a8Spgoyette  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56d91f98a8Spgoyette  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57d91f98a8Spgoyette  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58d91f98a8Spgoyette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59d91f98a8Spgoyette  * SUCH DAMAGE.
60d91f98a8Spgoyette  *
61d91f98a8Spgoyette  *	@(#)kern_proc.c	8.7 (Berkeley) 2/14/95
62d91f98a8Spgoyette  */
63d91f98a8Spgoyette 
64d91f98a8Spgoyette #include <sys/cdefs.h>
65*9fc45356Sriastradh __KERNEL_RCSID(0, "$NetBSD: netbsd32_kern_proc.c,v 1.6 2020/09/05 16:30:10 riastradh Exp $");
66d91f98a8Spgoyette 
67d91f98a8Spgoyette #ifdef _KERNEL_OPT
68d91f98a8Spgoyette #include "opt_kstack.h"
69d91f98a8Spgoyette #include "opt_maxuprc.h"
70d91f98a8Spgoyette #include "opt_dtrace.h"
71d91f98a8Spgoyette #include "opt_compat_netbsd32.h"
72d91f98a8Spgoyette #endif
73d91f98a8Spgoyette 
74d91f98a8Spgoyette #include <sys/param.h>
75d91f98a8Spgoyette #include <sys/systm.h>
76d91f98a8Spgoyette #include <sys/kernel.h>
77d91f98a8Spgoyette #include <sys/proc.h>
78d91f98a8Spgoyette #include <sys/resourcevar.h>
79d91f98a8Spgoyette #include <sys/buf.h>
80d91f98a8Spgoyette #include <sys/acct.h>
81d91f98a8Spgoyette #include <sys/wait.h>
82d91f98a8Spgoyette #include <sys/file.h>
83d91f98a8Spgoyette #include <ufs/ufs/quota.h>
84d91f98a8Spgoyette #include <sys/uio.h>
85d91f98a8Spgoyette #include <sys/pool.h>
86d91f98a8Spgoyette #include <sys/pset.h>
87d91f98a8Spgoyette #include <sys/mbuf.h>
88d91f98a8Spgoyette #include <sys/ioctl.h>
89d91f98a8Spgoyette #include <sys/tty.h>
90d91f98a8Spgoyette #include <sys/signalvar.h>
91d91f98a8Spgoyette #include <sys/ras.h>
92d91f98a8Spgoyette #include <sys/filedesc.h>
93d91f98a8Spgoyette #include <sys/syscall_stats.h>
94d91f98a8Spgoyette #include <sys/kauth.h>
95d91f98a8Spgoyette #include <sys/sleepq.h>
96d91f98a8Spgoyette #include <sys/atomic.h>
97d91f98a8Spgoyette #include <sys/kmem.h>
98d91f98a8Spgoyette #include <sys/namei.h>
99d91f98a8Spgoyette #include <sys/dtrace_bsd.h>
100d91f98a8Spgoyette #include <sys/sysctl.h>
101d91f98a8Spgoyette #include <sys/exec.h>
102d91f98a8Spgoyette #include <sys/cpu.h>
103d91f98a8Spgoyette #include <sys/compat_stub.h>
104d91f98a8Spgoyette 
105d91f98a8Spgoyette #include <compat/netbsd32/netbsd32.h>
106d91f98a8Spgoyette #include <compat/netbsd32/netbsd32_kern_proc.h>
107d91f98a8Spgoyette 
108d91f98a8Spgoyette static int
copyin_psstrings_32(struct proc * p,struct ps_strings * arginfo)109d91f98a8Spgoyette copyin_psstrings_32(struct proc *p, struct ps_strings *arginfo)
110d91f98a8Spgoyette {
111d91f98a8Spgoyette 	struct ps_strings32 arginfo32;
112d91f98a8Spgoyette 
113d91f98a8Spgoyette 	int error = copyin_proc(p, (void *)p->p_psstrp, &arginfo32,
114d91f98a8Spgoyette 	    sizeof(arginfo32));
115d91f98a8Spgoyette 	if (error)
116d91f98a8Spgoyette 		return error;
117d91f98a8Spgoyette 	arginfo->ps_argvstr = (void *)(uintptr_t)arginfo32.ps_argvstr;
118d91f98a8Spgoyette 	arginfo->ps_nargvstr = arginfo32.ps_nargvstr;
119d91f98a8Spgoyette 	arginfo->ps_envstr = (void *)(uintptr_t)arginfo32.ps_envstr;
120d91f98a8Spgoyette 	arginfo->ps_nenvstr = arginfo32.ps_nenvstr;
121d91f98a8Spgoyette 	return 0;
122d91f98a8Spgoyette }
123d91f98a8Spgoyette 
124d91f98a8Spgoyette static vaddr_t
get_base32(char ** argv,size_t i)125d91f98a8Spgoyette get_base32(char **argv, size_t i)
126d91f98a8Spgoyette {
127d91f98a8Spgoyette 
128d91f98a8Spgoyette 	netbsd32_charp *argv32;
129d91f98a8Spgoyette 
130d91f98a8Spgoyette 	argv32 = (netbsd32_charp *)argv;
131d91f98a8Spgoyette 	return (vaddr_t)NETBSD32PTR64(argv32[i]);
132d91f98a8Spgoyette }
133d91f98a8Spgoyette 
134d91f98a8Spgoyette void
netbsd32_kern_proc_32_init(void)135d91f98a8Spgoyette netbsd32_kern_proc_32_init(void)
136d91f98a8Spgoyette {
137d91f98a8Spgoyette 
138d91f98a8Spgoyette #if !defined(_RUMPSERVER)
1398a031a1dSpgoyette 	MODULE_HOOK_SET(kern_proc32_copyin_hook, copyin_psstrings_32);
1408a031a1dSpgoyette 	MODULE_HOOK_SET(kern_proc32_base_hook, get_base32);
141d91f98a8Spgoyette #endif
142d91f98a8Spgoyette }
143d91f98a8Spgoyette 
144d91f98a8Spgoyette void
netbsd32_kern_proc_32_fini(void)145d91f98a8Spgoyette netbsd32_kern_proc_32_fini(void)
146d91f98a8Spgoyette {
147d91f98a8Spgoyette 
148d91f98a8Spgoyette #if !defined(_RUMPSERVER)
1498c2f80f1Spgoyette 	MODULE_HOOK_UNSET(kern_proc32_copyin_hook);
1508c2f80f1Spgoyette 	MODULE_HOOK_UNSET(kern_proc32_base_hook);
151d91f98a8Spgoyette #endif
152d91f98a8Spgoyette }
153