xref: /freebsd/sys/compat/freebsd32/freebsd32_util.h (revision faf25f48d601ae39f5752602f3020e2e92605625)
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  * $FreeBSD$
31  */
32 
33 #ifndef _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
34 #define _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
35 
36 #include <sys/cdefs.h>
37 #include <sys/exec.h>
38 #include <sys/sysent.h>
39 #include <sys/uio.h>
40 
41 #include <vm/vm.h>
42 #include <vm/vm_param.h>
43 #include <vm/pmap.h>
44 
45 struct freebsd32_ps_strings {
46 	uint32_t ps_argvstr;	/* first of 0 or more argument strings */
47 	int	ps_nargvstr;	/* the number of argument strings */
48 	uint32_t ps_envstr;	/* first of 0 or more environment strings */
49 	int	ps_nenvstr;	/* the number of environment strings */
50 };
51 
52 #if defined(__amd64__)
53 #include <compat/ia32/ia32_util.h>
54 #endif
55 
56 #define FREEBSD32_PS_STRINGS	\
57 	(FREEBSD32_USRSTACK - sizeof(struct freebsd32_ps_strings))
58 
59 extern struct sysent freebsd32_sysent[];
60 
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 }               \
64 };                                                             \
65                                                                \
66 static moduledata_t name##32_mod = {                           \
67        "sys32/" #name,                                         \
68        syscall32_module_handler,                               \
69        &name##_syscall32_mod                                   \
70 };                                                             \
71 DECLARE_MODULE(name##32, name##32_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE)
72 
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                          \
79 };                                                      \
80 SYSCALL32_MODULE(syscallname,                           \
81     & syscallname##_syscall32, & syscallname##_sysent32,\
82     NULL, NULL);
83 
84 #define SYSCALL32_INIT_HELPER_F(syscallname, flags) {		\
85     .new_sysent = {						\
86 	.sy_narg = (sizeof(struct syscallname ## _args )	\
87 	    / sizeof(register_t)),				\
88 	.sy_call = (sy_call_t *)& syscallname,			\
89 	.sy_flags = (flags)					\
90     },								\
91     .syscall_no = FREEBSD32_SYS_##syscallname			\
92 }
93 
94 #define SYSCALL32_INIT_HELPER_COMPAT_F(syscallname, flags) {	\
95     .new_sysent = {						\
96 	.sy_narg = (sizeof(struct syscallname ## _args )	\
97 	    / sizeof(register_t)),				\
98 	.sy_call = (sy_call_t *)& sys_ ## syscallname,		\
99 	.sy_flags = (flags)					\
100     },								\
101     .syscall_no = FREEBSD32_SYS_##syscallname			\
102 }
103 
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)
108 
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);
112 
113 struct iovec32;
114 struct rusage32;
115 int	freebsd32_copyout_strings(struct image_params *imgp,
116 	    uintptr_t *stack_base);
117 int	freebsd32_copyiniov(struct iovec32 *iovp, u_int iovcnt,
118 	    struct iovec **iov, int error);
119 int	freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt,
120 	    struct uio **uiop);
121 void	freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32);
122 
123 struct image_args;
124 int freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
125 	    enum uio_seg segflg, uint32_t *argv, uint32_t *envv);
126 
127 #endif /* !_COMPAT_FREEBSD32_FREEBSD32_UTIL_H_ */
128