xref: /freebsd/sys/compat/freebsd32/freebsd32_util.h (revision ff0ba87247820afbdfdc1b307c803f7923d0e4d3)
1 /*-
2  * Copyright (c) 1998-1999 Andrew Gallatin
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer
10  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software withough specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD$
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 	u_int32_t ps_argvstr;	/* first of 0 or more argument strings */
45 	int	ps_nargvstr;	/* the number of argument strings */
46 	u_int32_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(syscallname) {			\
83     .new_sysent = {						\
84 	.sy_narg = (sizeof(struct syscallname ## _args )	\
85 	    / sizeof(register_t)),				\
86 	.sy_call = (sy_call_t *)& syscallname,			\
87     },								\
88     .syscall_no = FREEBSD32_SYS_##syscallname			\
89 }
90 
91 #define SYSCALL32_INIT_HELPER_COMPAT(syscallname) {		\
92     .new_sysent = {						\
93 	.sy_narg = (sizeof(struct syscallname ## _args )	\
94 	    / sizeof(register_t)),				\
95 	.sy_call = (sy_call_t *)& sys_ ## syscallname,		\
96     },								\
97     .syscall_no = FREEBSD32_SYS_##syscallname			\
98 }
99 
100 int    syscall32_register(int *offset, struct sysent *new_sysent,
101 	    struct sysent *old_sysent, int flags);
102 int    syscall32_deregister(int *offset, struct sysent *old_sysent);
103 int    syscall32_module_handler(struct module *mod, int what, void *arg);
104 int    syscall32_helper_register(struct syscall_helper_data *sd, int flags);
105 int    syscall32_helper_unregister(struct syscall_helper_data *sd);
106 
107 struct iovec32;
108 struct rusage32;
109 register_t *freebsd32_copyout_strings(struct image_params *imgp);
110 int	freebsd32_copyiniov(struct iovec32 *iovp, u_int iovcnt,
111 	    struct iovec **iov, int error);
112 void	freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32);
113 
114 struct image_args;
115 int freebsd32_exec_copyin_args(struct image_args *args, char *fname,
116 	    enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv);
117 
118 #endif /* !_COMPAT_FREEBSD32_FREEBSD32_UTIL_H_ */
119