1100384Speter/*-
2100384Speter * Copyright (c) 1998-1999 Andrew Gallatin
3100384Speter * All rights reserved.
4100384Speter *
5100384Speter * Redistribution and use in source and binary forms, with or without
6100384Speter * modification, are permitted provided that the following conditions
7100384Speter * are met:
8100384Speter * 1. Redistributions of source code must retain the above copyright
9100384Speter *    notice, this list of conditions and the following disclaimer
10100384Speter *    in this position and unchanged.
11100384Speter * 2. Redistributions in binary form must reproduce the above copyright
12100384Speter *    notice, this list of conditions and the following disclaimer in the
13100384Speter *    documentation and/or other materials provided with the distribution.
14100384Speter * 3. The name of the author may not be used to endorse or promote products
15100384Speter *    derived from this software withough specific prior written permission
16100384Speter *
17100384Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18100384Speter * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19100384Speter * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20100384Speter * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21100384Speter * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22100384Speter * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23100384Speter * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24100384Speter * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25100384Speter * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26100384Speter * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27100384Speter *
28100384Speter * $FreeBSD$
29100384Speter */
30100384Speter
31183363Sjhb#ifndef _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
32183363Sjhb#define _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
33183363Sjhb
34183363Sjhb#include <sys/cdefs.h>
35183363Sjhb#include <sys/exec.h>
36183363Sjhb#include <sys/sysent.h>
37210498Skib#include <sys/uio.h>
38183363Sjhb
39100384Speter#include <vm/vm.h>
40100384Speter#include <vm/vm_param.h>
41100384Speter#include <vm/pmap.h>
42100384Speter
43119333Speterstruct freebsd32_ps_strings {
44100384Speter	u_int32_t ps_argvstr;	/* first of 0 or more argument strings */
45100384Speter	int	ps_nargvstr;	/* the number of argument strings */
46100384Speter	u_int32_t ps_envstr;	/* first of 0 or more environment strings */
47100384Speter	int	ps_nenvstr;	/* the number of environment strings */
48100384Speter};
49100384Speter
50119336Speter#if defined(__amd64__) || defined(__ia64__)
51119336Speter#include <compat/ia32/ia32_util.h>
52119336Speter#endif
53119336Speter
54119333Speter#define FREEBSD32_PS_STRINGS	\
55119333Speter	(FREEBSD32_USRSTACK - sizeof(struct freebsd32_ps_strings))
56183363Sjhb
57183365Sjhbextern struct sysent freebsd32_sysent[];
58183365Sjhb
59183365Sjhb#define SYSCALL32_MODULE(name, offset, new_sysent, evh, arg)   \
60183365Sjhbstatic struct syscall_module_data name##_syscall32_mod = {     \
61183365Sjhb       evh, arg, offset, new_sysent, { 0, NULL }               \
62183365Sjhb};                                                             \
63183365Sjhb                                                               \
64183365Sjhbstatic moduledata_t name##32_mod = {                           \
65205320Skib       "sys32/" #name,                                         \
66183365Sjhb       syscall32_module_handler,                               \
67183365Sjhb       &name##_syscall32_mod                                   \
68183365Sjhb};                                                             \
69183365SjhbDECLARE_MODULE(name##32, name##32_mod, SI_SUB_SYSCALLS, SI_ORDER_MIDDLE)
70183365Sjhb
71183365Sjhb#define SYSCALL32_MODULE_HELPER(syscallname)            \
72183365Sjhbstatic int syscallname##_syscall32 = FREEBSD32_SYS_##syscallname; \
73183365Sjhbstatic struct sysent syscallname##_sysent32 = {         \
74183365Sjhb    (sizeof(struct syscallname ## _args )               \
75183365Sjhb     / sizeof(register_t)),                             \
76183365Sjhb    (sy_call_t *)& syscallname                          \
77183365Sjhb};                                                      \
78183365SjhbSYSCALL32_MODULE(syscallname,                           \
79183365Sjhb    & syscallname##_syscall32, & syscallname##_sysent32,\
80183365Sjhb    NULL, NULL);
81183365Sjhb
82205321Skib#define SYSCALL32_INIT_HELPER(syscallname) {			\
83205321Skib    .new_sysent = {						\
84205321Skib	.sy_narg = (sizeof(struct syscallname ## _args )	\
85205321Skib	    / sizeof(register_t)),				\
86205321Skib	.sy_call = (sy_call_t *)& syscallname,			\
87205321Skib    },								\
88205321Skib    .syscall_no = FREEBSD32_SYS_##syscallname			\
89205321Skib}
90205321Skib
91225617Skmacy#define SYSCALL32_INIT_HELPER_COMPAT(syscallname) {		\
92225617Skmacy    .new_sysent = {						\
93225617Skmacy	.sy_narg = (sizeof(struct syscallname ## _args )	\
94225617Skmacy	    / sizeof(register_t)),				\
95225617Skmacy	.sy_call = (sy_call_t *)& sys_ ## syscallname,		\
96225617Skmacy    },								\
97225617Skmacy    .syscall_no = FREEBSD32_SYS_##syscallname			\
98225617Skmacy}
99225617Skmacy
100183365Sjhbint    syscall32_register(int *offset, struct sysent *new_sysent,
101183365Sjhb	    struct sysent *old_sysent);
102183365Sjhbint    syscall32_deregister(int *offset, struct sysent *old_sysent);
103183365Sjhbint    syscall32_module_handler(struct module *mod, int what, void *arg);
104205321Skibint    syscall32_helper_register(struct syscall_helper_data *sd);
105205321Skibint    syscall32_helper_unregister(struct syscall_helper_data *sd);
106183365Sjhb
107207007Skibstruct iovec32;
108207007Skibstruct rusage32;
109205014Snwhitehornregister_t *freebsd32_copyout_strings(struct image_params *imgp);
110205319Skibint	freebsd32_copyiniov(struct iovec32 *iovp, u_int iovcnt,
111205319Skib	    struct iovec **iov, int error);
112207007Skibvoid	freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32);
113205014Snwhitehorn
114210431Skibstruct image_args;
115210431Skibint freebsd32_exec_copyin_args(struct image_args *args, char *fname,
116210431Skib	    enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv);
117207007Skib
118183363Sjhb#endif /* !_COMPAT_FREEBSD32_FREEBSD32_UTIL_H_ */
119