freebsd32_util.h revision 303975
1117397Skan/*-
2117397Skan * Copyright (c) 1998-1999 Andrew Gallatin
3117397Skan * All rights reserved.
4117397Skan *
5117397Skan * Redistribution and use in source and binary forms, with or without
6117397Skan * modification, are permitted provided that the following conditions
7117397Skan * are met:
8117397Skan * 1. Redistributions of source code must retain the above copyright
9117397Skan *    notice, this list of conditions and the following disclaimer
10117397Skan *    in this position and unchanged.
11117397Skan * 2. Redistributions in binary form must reproduce the above copyright
12117397Skan *    notice, this list of conditions and the following disclaimer in the
13117397Skan *    documentation and/or other materials provided with the distribution.
14117397Skan * 3. The name of the author may not be used to endorse or promote products
15117397Skan *    derived from this software withough specific prior written permission
16117397Skan *
17117397Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18117397Skan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19117397Skan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20117397Skan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21117397Skan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22117397Skan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23117397Skan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24117397Skan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25117397Skan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26117397Skan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27117397Skan *
28117397Skan * $FreeBSD: releng/11.0/sys/compat/freebsd32/freebsd32_util.h 273707 2014-10-26 19:42:44Z mjg $
29117397Skan */
30117397Skan
31117397Skan#ifndef _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
32117397Skan#define _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
33117397Skan
34117397Skan#include <sys/cdefs.h>
35117397Skan#include <sys/exec.h>
36117397Skan#include <sys/sysent.h>
37117397Skan#include <sys/uio.h>
38117397Skan
39117397Skan#include <vm/vm.h>
40117397Skan#include <vm/vm_param.h>
41117397Skan#include <vm/pmap.h>
42117397Skan
43132720Skanstruct freebsd32_ps_strings {
44117397Skan	u_int32_t ps_argvstr;	/* first of 0 or more argument strings */
45117397Skan	int	ps_nargvstr;	/* the number of argument strings */
46132720Skan	u_int32_t ps_envstr;	/* first of 0 or more environment strings */
47132720Skan	int	ps_nenvstr;	/* the number of environment strings */
48132720Skan};
49132720Skan
50132720Skan#if defined(__amd64__)
51132720Skan#include <compat/ia32/ia32_util.h>
52117397Skan#endif
53117397Skan
54132720Skan#define FREEBSD32_PS_STRINGS	\
55117397Skan	(FREEBSD32_USRSTACK - sizeof(struct freebsd32_ps_strings))
56117397Skan
57132720Skanextern struct sysent freebsd32_sysent[];
58132720Skan
59132720Skan#define SYSCALL32_MODULE(name, offset, new_sysent, evh, arg)   \
60132720Skanstatic struct syscall_module_data name##_syscall32_mod = {     \
61132720Skan       evh, arg, offset, new_sysent, { 0, NULL }               \
62132720Skan};                                                             \
63117397Skan                                                               \
64117397Skanstatic moduledata_t name##32_mod = {                           \
65117397Skan       "sys32/" #name,                                         \
66117397Skan       syscall32_module_handler,                               \
67117397Skan       &name##_syscall32_mod                                   \
68117397Skan};                                                             \
69117397SkanDECLARE_MODULE(name##32, name##32_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE)
70117397Skan
71117397Skan#define SYSCALL32_MODULE_HELPER(syscallname)            \
72117397Skanstatic int syscallname##_syscall32 = FREEBSD32_SYS_##syscallname; \
73117397Skanstatic struct sysent syscallname##_sysent32 = {         \
74117397Skan    (sizeof(struct syscallname ## _args )               \
75117397Skan     / sizeof(register_t)),                             \
76117397Skan    (sy_call_t *)& syscallname                          \
77117397Skan};                                                      \
78117397SkanSYSCALL32_MODULE(syscallname,                           \
79117397Skan    & syscallname##_syscall32, & syscallname##_sysent32,\
80117397Skan    NULL, NULL);
81117397Skan
82117397Skan#define SYSCALL32_INIT_HELPER(syscallname) {			\
83117397Skan    .new_sysent = {						\
84117397Skan	.sy_narg = (sizeof(struct syscallname ## _args )	\
85117397Skan	    / sizeof(register_t)),				\
86117397Skan	.sy_call = (sy_call_t *)& syscallname,			\
87117397Skan    },								\
88117397Skan    .syscall_no = FREEBSD32_SYS_##syscallname			\
89117397Skan}
90117397Skan
91117397Skan#define SYSCALL32_INIT_HELPER_COMPAT(syscallname) {		\
92117397Skan    .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
100int    syscall32_register(int *offset, struct sysent *new_sysent,
101	    struct sysent *old_sysent, int flags);
102int    syscall32_deregister(int *offset, struct sysent *old_sysent);
103int    syscall32_module_handler(struct module *mod, int what, void *arg);
104int    syscall32_helper_register(struct syscall_helper_data *sd, int flags);
105int    syscall32_helper_unregister(struct syscall_helper_data *sd);
106
107struct iovec32;
108struct rusage32;
109register_t *freebsd32_copyout_strings(struct image_params *imgp);
110int	freebsd32_copyiniov(struct iovec32 *iovp, u_int iovcnt,
111	    struct iovec **iov, int error);
112void	freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32);
113
114struct image_args;
115int 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