xref: /freebsd/sys/compat/freebsd32/freebsd32_util.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1998-1999 Andrew Gallatin
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer
12  *    in this position and unchanged.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software withough specific prior written permission
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
32 #define _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
33 
34 #include <sys/cdefs.h>
35 #include <sys/exec.h>
36 #include <sys/sysent.h>
37 #include <sys/uio.h>
38 
39 #include <vm/vm.h>
40 #include <vm/vm_param.h>
41 #include <vm/pmap.h>
42 
43 struct freebsd32_ps_strings {
44 	uint32_t ps_argvstr;	/* first of 0 or more argument strings */
45 	int	ps_nargvstr;	/* the number of argument strings */
46 	uint32_t ps_envstr;	/* first of 0 or more environment strings */
47 	int	ps_nenvstr;	/* the number of environment strings */
48 };
49 
50 #if defined(__amd64__)
51 #include <compat/ia32/ia32_util.h>
52 #endif
53 
54 #define FREEBSD32_PS_STRINGS	\
55 	(FREEBSD32_USRSTACK - sizeof(struct freebsd32_ps_strings))
56 
57 extern struct sysent freebsd32_sysent[];
58 
59 #define SYSCALL32_MODULE(name, offset, new_sysent, evh, arg)   \
60 static struct syscall_module_data name##_syscall32_mod = {     \
61        evh, arg, offset, new_sysent, { 0, NULL }               \
62 };                                                             \
63                                                                \
64 static moduledata_t name##32_mod = {                           \
65        "sys32/" #name,                                         \
66        syscall32_module_handler,                               \
67        &name##_syscall32_mod                                   \
68 };                                                             \
69 DECLARE_MODULE(name##32, name##32_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE)
70 
71 #define SYSCALL32_MODULE_HELPER(syscallname)            \
72 static int syscallname##_syscall32 = FREEBSD32_SYS_##syscallname; \
73 static struct sysent syscallname##_sysent32 = {         \
74     (sizeof(struct syscallname ## _args )               \
75      / sizeof(register_t)),                             \
76     (sy_call_t *)& syscallname                          \
77 };                                                      \
78 SYSCALL32_MODULE(syscallname,                           \
79     & syscallname##_syscall32, & syscallname##_sysent32,\
80     NULL, NULL);
81 
82 #define SYSCALL32_INIT_HELPER_F(syscallname, flags) {		\
83     .new_sysent = {						\
84 	.sy_narg = (sizeof(struct syscallname ## _args )	\
85 	    / sizeof(register_t)),				\
86 	.sy_call = (sy_call_t *)& syscallname,			\
87 	.sy_flags = (flags)					\
88     },								\
89     .syscall_no = FREEBSD32_SYS_##syscallname			\
90 }
91 
92 #define SYSCALL32_INIT_HELPER_COMPAT_F(syscallname, flags) {	\
93     .new_sysent = {						\
94 	.sy_narg = (sizeof(struct syscallname ## _args )	\
95 	    / sizeof(register_t)),				\
96 	.sy_call = (sy_call_t *)& sys_ ## syscallname,		\
97 	.sy_flags = (flags)					\
98     },								\
99     .syscall_no = FREEBSD32_SYS_##syscallname			\
100 }
101 
102 #define SYSCALL32_INIT_HELPER(syscallname)			\
103     SYSCALL32_INIT_HELPER_F(syscallname, 0)
104 #define SYSCALL32_INIT_HELPER_COMPAT(syscallname)		\
105     SYSCALL32_INIT_HELPER_COMPAT_F(syscallname, 0)
106 
107 int    syscall32_module_handler(struct module *mod, int what, void *arg);
108 int    syscall32_helper_register(struct syscall_helper_data *sd, int flags);
109 int    syscall32_helper_unregister(struct syscall_helper_data *sd);
110 
111 struct iovec32;
112 struct rusage32;
113 int	freebsd32_copyout_strings(struct image_params *imgp,
114 	    uintptr_t *stack_base);
115 int	freebsd32_copyiniov(struct iovec32 *iovp, u_int iovcnt,
116 	    struct iovec **iov, int error);
117 int	freebsd32_copyinuio(const struct iovec32 *iovp, u_int iovcnt,
118 	    struct uio **uiop);
119 void	freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32);
120 
121 struct image_args;
122 int freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
123 	    enum uio_seg segflg, uint32_t *argv, uint32_t *envv);
124 
125 extern int compat_freebsd_32bit;
126 
127 #endif /* !_COMPAT_FREEBSD32_FREEBSD32_UTIL_H_ */
128