2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1998-1999 Andrew Gallatin
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
33 #ifndef _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
34 #define _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
36 #include <sys/cdefs.h>
38 #include <sys/sysent.h>
42 #include <vm/vm_param.h>
45 struct freebsd32_ps_strings {
46 u_int32_t ps_argvstr; /* first of 0 or more argument strings */
47 int ps_nargvstr; /* the number of argument strings */
48 u_int32_t ps_envstr; /* first of 0 or more environment strings */
49 int ps_nenvstr; /* the number of environment strings */
52 #if defined(__amd64__)
53 #include <compat/ia32/ia32_util.h>
56 #define FREEBSD32_PS_STRINGS \
57 (FREEBSD32_USRSTACK - sizeof(struct freebsd32_ps_strings))
59 extern struct sysent freebsd32_sysent[];
61 #define SYSCALL32_MODULE(name, offset, new_sysent, evh, arg) \
62 static struct syscall_module_data name##_syscall32_mod = { \
63 evh, arg, offset, new_sysent, { 0, NULL } \
66 static moduledata_t name##32_mod = { \
68 syscall32_module_handler, \
69 &name##_syscall32_mod \
71 DECLARE_MODULE(name##32, name##32_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE)
73 #define SYSCALL32_MODULE_HELPER(syscallname) \
74 static int syscallname##_syscall32 = FREEBSD32_SYS_##syscallname; \
75 static struct sysent syscallname##_sysent32 = { \
76 (sizeof(struct syscallname ## _args ) \
77 / sizeof(register_t)), \
78 (sy_call_t *)& syscallname \
80 SYSCALL32_MODULE(syscallname, \
81 & syscallname##_syscall32, & syscallname##_sysent32,\
84 #define SYSCALL32_INIT_HELPER_F(syscallname, flags) { \
86 .sy_narg = (sizeof(struct syscallname ## _args ) \
87 / sizeof(register_t)), \
88 .sy_call = (sy_call_t *)& syscallname, \
91 .syscall_no = FREEBSD32_SYS_##syscallname \
94 #define SYSCALL32_INIT_HELPER_COMPAT_F(syscallname, flags) { \
96 .sy_narg = (sizeof(struct syscallname ## _args ) \
97 / sizeof(register_t)), \
98 .sy_call = (sy_call_t *)& sys_ ## syscallname, \
101 .syscall_no = FREEBSD32_SYS_##syscallname \
104 #define SYSCALL32_INIT_HELPER(syscallname) \
105 SYSCALL32_INIT_HELPER_F(syscallname, 0)
106 #define SYSCALL32_INIT_HELPER_COMPAT(syscallname) \
107 SYSCALL32_INIT_HELPER_COMPAT_F(syscallname, 0)
109 int syscall32_module_handler(struct module *mod, int what, void *arg);
110 int syscall32_helper_register(struct syscall_helper_data *sd, int flags);
111 int syscall32_helper_unregister(struct syscall_helper_data *sd);
115 register_t *freebsd32_copyout_strings(struct image_params *imgp);
116 int freebsd32_copyiniov(struct iovec32 *iovp, u_int iovcnt,
117 struct iovec **iov, int error);
118 void freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32);
121 int freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
122 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv);
124 #endif /* !_COMPAT_FREEBSD32_FREEBSD32_UTIL_H_ */