xref: /netbsd-src/sys/compat/netbsd32/netbsd32.h (revision cac8e449158efc7261bebc8657cbb0125a2cfdde)
1 /*	$NetBSD: netbsd32.h,v 1.76 2008/05/29 14:51:26 mrg Exp $	*/
2 
3 /*
4  * Copyright (c) 1998, 2001 Matthew R. Green
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  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _COMPAT_NETBSD32_NETBSD32_H_
30 #define _COMPAT_NETBSD32_NETBSD32_H_
31 /* We need to change the size of register_t */
32 #ifdef syscallargs
33 #undef syscallargs
34 #endif
35 /*
36  * NetBSD 32-bit compatibility module.
37  */
38 
39 #include <sys/systm.h>
40 #include <sys/mount.h>
41 #include <sys/stat.h>
42 #include <sys/statvfs.h>
43 #include <sys/syscallargs.h>
44 #include <sys/ipc.h>
45 #include <sys/shm.h>
46 #include <sys/ucontext.h>
47 #include <compat/sys/ucontext.h>
48 #include <compat/sys/mount.h>
49 
50 /*
51  * first, define the basic types we need.
52  */
53 
54 typedef int32_t netbsd32_long;
55 typedef uint32_t netbsd32_u_long;
56 
57 typedef uint32_t netbsd32_clock_t;
58 typedef uint32_t netbsd32_size_t;
59 typedef int32_t netbsd32_ssize_t;
60 typedef int32_t netbsd32_clockid_t;
61 typedef int32_t netbsd32_key_t;
62 typedef int32_t netbsd32_intptr_t;
63 typedef uint32_t netbsd32_uintptr_t;
64 
65 /* netbsd32_[u]int64 are machine dependant and defined below */
66 
67 /*
68  * machine depedant section; must define:
69  *	netbsd32_pointer_t
70  *		- 32-bit pointer type, normally uint32_t but can be int32_t
71  *		  for platforms which rely on sign-extension of pointers
72  *		  such as SH-5.
73  *	NETBSD32PTR64(p32)
74  *		- Translate a 32-bit pointer into something valid in a
75  *		  64-bit context.
76  *	struct netbsd32_sigcontext
77  *		- 32bit compatibility sigcontext structure for this arch.
78  *	netbsd32_sigcontextp_t
79  *		- type of pointer to above, normally uint32_t
80  *	void netbsd32_setregs(struct proc *p, struct exec_package *pack,
81  *	    unsigned long stack);
82  *	int netbsd32_sigreturn(struct proc *p, void *v,
83  *	    register_t *retval);
84  *	void netbsd32_sendsig(sig_t catcher, int sig, int mask, u_long code);
85  *	char netbsd32_esigcode[], netbsd32_sigcode[]
86  *		- the above are abvious
87  *
88  * pull in the netbsd32 machine dependant header, that may help with the
89  * above, or it may be provided via the MD layer itself.
90  */
91 #include <machine/netbsd32_machdep.h>
92 
93 /* netbsd32_machdep.h will have (typically) defined:
94 #define NETBSD32_POINTER_TYPE uint32_t
95 typedef	struct { NETBSD32_POINTER_TYPE i32; } netbsd32_pointer_t;
96 */
97 
98 /*
99  * Conversion functions for the rest of the compat32 code:
100  *
101  * NETBSD32PTR64()	Convert user-supplied 32bit pointer to 'void *'
102  * NETBSD32PTR32()	Assign a 'void *' to a 32bit pointer variable
103  * NETBSD32PTR32PLUS()	Add an integer to a 32bit pointer
104  *
105  * Under rare circumstances the following get used:
106  *
107  * NETBSD32PTR32I()	Convert 'void *' to the 32bit pointer base type.
108  * NETBSD32IPTR64()	Convert 32bit pointer base type to 'void *'
109  */
110 #define	NETBSD32PTR64(p32)		NETBSD32IPTR64((p32).i32)
111 #define	NETBSD32PTR32(p32, p64)		((p32).i32 = NETBSD32PTR32I(p64))
112 #define	NETBSD32PTR32PLUS(p32, incr)	((p32).i32 += incr)
113 
114 static __inline NETBSD32_POINTER_TYPE
115 NETBSD32PTR32I(const void *p64) { return (uintptr_t)p64; }
116 static __inline void *
117 NETBSD32IPTR64(NETBSD32_POINTER_TYPE p32) { return (void *)(intptr_t)p32; }
118 
119 /* Nothing should be using the raw type, so kill it */
120 #undef NETBSD32_POINTER_TYPE
121 
122 /*
123  * 64 bit integers only have 4-byte alignment on some 32 bit ports,
124  * but always have 8-byte alignment on 64 bit systems.
125  * NETBSD32_INT64_ALIGN may be __attribute__((__aligned__(4)))
126  */
127 typedef int64_t netbsd32_int64 NETBSD32_INT64_ALIGN;
128 typedef uint64_t netbsd32_uint64 NETBSD32_INT64_ALIGN;
129 #undef NETBSD32_INT64_ALIGN
130 
131 /*
132  * all pointers are netbsd32_pointer_t (defined in <machine/netbsd32_machdep.h>)
133  */
134 
135 typedef netbsd32_pointer_t netbsd32_voidp;
136 typedef netbsd32_pointer_t netbsd32_u_shortp;
137 typedef netbsd32_pointer_t netbsd32_charp;
138 typedef netbsd32_pointer_t netbsd32_u_charp;
139 typedef netbsd32_pointer_t netbsd32_charpp;
140 typedef netbsd32_pointer_t netbsd32_size_tp;
141 typedef netbsd32_pointer_t netbsd32_intp;
142 typedef netbsd32_pointer_t netbsd32_longp;
143 typedef netbsd32_pointer_t netbsd32_caddrp;
144 typedef netbsd32_pointer_t netbsd32_caddr;
145 typedef netbsd32_pointer_t netbsd32_gid_tp;
146 typedef netbsd32_pointer_t netbsd32_fsid_tp_t;
147 typedef netbsd32_pointer_t netbsd32_lwpidp;
148 typedef netbsd32_pointer_t netbsd32_ucontextp;
149 typedef netbsd32_pointer_t netbsd32_caddr_t;
150 typedef netbsd32_pointer_t netbsd32_lwpctlp;
151 
152 /*
153  * now, the compatibility structures and their fake pointer types.
154  */
155 
156 /* from <sys/types.h> */
157 typedef netbsd32_pointer_t netbsd32_fd_setp_t;
158 typedef netbsd32_intptr_t netbsd32_semid_t;
159 typedef netbsd32_pointer_t netbsd32_semidp_t;
160 
161 /* from <sys/uio.h> */
162 typedef netbsd32_pointer_t netbsd32_iovecp_t;
163 struct netbsd32_iovec {
164 	netbsd32_voidp	 iov_base;	/* Base address. */
165 	netbsd32_size_t	 iov_len;	/* Length. */
166 };
167 
168 /* from <sys/time.h> */
169 typedef int32_t netbsd32_timer_t;
170 typedef	int32_t netbsd32_time_t;
171 typedef netbsd32_pointer_t netbsd32_timerp_t;
172 
173 typedef netbsd32_pointer_t netbsd32_timespecp_t;
174 struct netbsd32_timespec {
175 	netbsd32_time_t	tv_sec;			/* seconds */
176 	netbsd32_long	tv_nsec;	/* and nanoseconds */
177 };
178 
179 typedef netbsd32_pointer_t netbsd32_timevalp_t;
180 struct netbsd32_timeval {
181 	netbsd32_long	tv_sec;		/* seconds */
182 	netbsd32_long	tv_usec;	/* and microseconds */
183 };
184 
185 typedef netbsd32_pointer_t netbsd32_timezonep_t;
186 struct netbsd32_timezone {
187 	int	tz_minuteswest;	/* minutes west of Greenwich */
188 	int	tz_dsttime;	/* type of dst correction */
189 };
190 
191 typedef netbsd32_pointer_t netbsd32_itimervalp_t;
192 struct	netbsd32_itimerval {
193 	struct	netbsd32_timeval it_interval;	/* timer interval */
194 	struct	netbsd32_timeval it_value;	/* current value */
195 };
196 
197 typedef netbsd32_pointer_t netbsd32_itimerspecp_t;
198 struct netbsd32_itimerspec {
199 	struct netbsd32_timespec it_interval;
200 	struct netbsd32_timespec it_value;
201 };
202 
203 /* from <sys/mount.h> */
204 typedef netbsd32_pointer_t netbsd32_fidp_t;
205 
206 typedef netbsd32_pointer_t netbsd32_fhandlep_t;
207 typedef netbsd32_pointer_t netbsd32_compat_30_fhandlep_t;
208 
209 typedef netbsd32_pointer_t netbsd32_statfsp_t;
210 struct netbsd32_statfs {
211 	short	f_type;			/* type of file system */
212 	unsigned short	f_flags;	/* copy of mount flags */
213 	netbsd32_long	f_bsize;	/* fundamental file system block size */
214 	netbsd32_long	f_iosize;	/* optimal transfer block size */
215 	netbsd32_long	f_blocks;	/* total data blocks in file system */
216 	netbsd32_long	f_bfree;	/* free blocks in fs */
217 	netbsd32_long	f_bavail;	/* free blocks avail to non-superuser */
218 	netbsd32_long	f_files;	/* total file nodes in file system */
219 	netbsd32_long	f_ffree;	/* free file nodes in fs */
220 	fsid_t	f_fsid;			/* file system id */
221 	uid_t	f_owner;		/* user that mounted the file system */
222 	netbsd32_long	f_spare[4];	/* spare for later */
223 	char	f_fstypename[MFSNAMELEN]; /* fs type name */
224 	char	f_mntonname[MNAMELEN];	  /* directory on which mounted */
225 	char	f_mntfromname[MNAMELEN];  /* mounted file system */
226 };
227 
228 /* from <sys/poll.h> */
229 typedef netbsd32_pointer_t netbsd32_pollfdp_t;
230 
231 /* from <sys/resource.h> */
232 typedef netbsd32_pointer_t netbsd32_rusagep_t;
233 struct	netbsd32_rusage {
234 	struct netbsd32_timeval ru_utime;/* user time used */
235 	struct netbsd32_timeval ru_stime;/* system time used */
236 	netbsd32_long	ru_maxrss;	/* max resident set size */
237 	netbsd32_long	ru_ixrss;	/* integral shared memory size */
238 	netbsd32_long	ru_idrss;	/* integral unshared data " */
239 	netbsd32_long	ru_isrss;	/* integral unshared stack " */
240 	netbsd32_long	ru_minflt;	/* page reclaims */
241 	netbsd32_long	ru_majflt;	/* page faults */
242 	netbsd32_long	ru_nswap;	/* swaps */
243 	netbsd32_long	ru_inblock;	/* block input operations */
244 	netbsd32_long	ru_oublock;	/* block output operations */
245 	netbsd32_long	ru_msgsnd;	/* messages sent */
246 	netbsd32_long	ru_msgrcv;	/* messages received */
247 	netbsd32_long	ru_nsignals;	/* signals received */
248 	netbsd32_long	ru_nvcsw;	/* voluntary context switches */
249 	netbsd32_long	ru_nivcsw;	/* involuntary " */
250 };
251 
252 typedef netbsd32_pointer_t netbsd32_orlimitp_t;
253 
254 typedef netbsd32_pointer_t netbsd32_rlimitp_t;
255 
256 struct netbsd32_loadavg {
257 	fixpt_t	ldavg[3];
258 	netbsd32_long	fscale;
259 };
260 
261 /* from <sys/ipc.h> */
262 typedef netbsd32_pointer_t netbsd32_ipc_permp_t;
263 struct netbsd32_ipc_perm {
264 	uid_t		cuid;	/* creator user id */
265 	gid_t		cgid;	/* creator group id */
266 	uid_t		uid;	/* user id */
267 	gid_t		gid;	/* group id */
268 	mode_t		mode;	/* r/w permission */
269 	unsigned short	_seq;	/* sequence # (to generate unique msg/sem/shm id) */
270 	netbsd32_key_t	_key;	/* user specified msg/sem/shm key */
271 };
272 struct netbsd32_ipc_perm14 {
273 	unsigned short	cuid;	/* creator user id */
274 	unsigned short	cgid;	/* creator group id */
275 	unsigned short	uid;	/* user id */
276 	unsigned short	gid;	/* group id */
277 	unsigned short	mode;	/* r/w permission */
278 	unsigned short	seq;	/* sequence # (to generate unique msg/sem/shm id) */
279 	netbsd32_key_t	key;	/* user specified msg/sem/shm key */
280 };
281 
282 /* from <sys/msg.h> */
283 typedef netbsd32_pointer_t netbsd32_msgp_t;
284 struct netbsd32_msg {
285 	netbsd32_msgp_t msg_next;	/* next msg in the chain */
286 	netbsd32_long	msg_type;	/* type of this message */
287     					/* >0 -> type of this message */
288     					/* 0 -> free header */
289 	unsigned short	msg_ts;		/* size of this message */
290 	short	msg_spot;		/* location of start of msg in buffer */
291 };
292 
293 typedef netbsd32_pointer_t netbsd32_msqid_dsp_t;
294 typedef uint32_t netbsd32_msgqnum_t;
295 typedef netbsd32_size_t netbsd32_msglen_t;
296 
297 struct netbsd32_msqid_ds {
298 	struct netbsd32_ipc_perm msg_perm;	/* operation permission strucure */
299 	netbsd32_msgqnum_t	msg_qnum;	/* number of messages in the queue */
300 	netbsd32_msglen_t	msg_qbytes;	/* max # of bytes in the queue */
301 	pid_t		msg_lspid;	/* process ID of last msgsend() */
302 	pid_t		msg_lrpid;	/* process ID of last msgrcv() */
303 	netbsd32_time_t		msg_stime;	/* time of last msgsend() */
304 	netbsd32_time_t		msg_rtime;	/* time of last msgrcv() */
305 	netbsd32_time_t		msg_ctime;	/* time of last change */
306 
307 	/*
308 	 * These members are private and used only in the internal
309 	 * implementation of this interface.
310 	 */
311 	netbsd32_msgp_t _msg_first;	/* first message in the queue */
312 	netbsd32_msgp_t	_msg_last;	/* last message in the queue */
313 	netbsd32_msglen_t _msg_cbytes;	/* # of bytes currently in queue */
314 };
315 struct netbsd32_msqid_ds14 {
316 	struct	netbsd32_ipc_perm14 msg_perm;	/* msg queue permission bits */
317 	netbsd32_msgp_t	msg_first;	/* first message in the queue */
318 	netbsd32_msgp_t	msg_last;	/* last message in the queue */
319 	netbsd32_u_long	msg_cbytes;	/* number of bytes in use on the queue */
320 	netbsd32_u_long	msg_qnum;	/* number of msgs in the queue */
321 	netbsd32_u_long	msg_qbytes;	/* max # of bytes on the queue */
322 	pid_t msg_lspid;		/* pid of last msgsnd() */
323 	pid_t msg_lrpid;		/* pid of last msgrcv() */
324 	netbsd32_time_t	msg_stime;	/* time of last msgsnd() */
325 	netbsd32_long	msg_pad1;
326 	netbsd32_time_t	msg_rtime;	/* time of last msgrcv() */
327 	netbsd32_long	msg_pad2;
328 	netbsd32_time_t	msg_ctime;	/* time of last msgctl() */
329 	netbsd32_long	msg_pad3;
330 	netbsd32_long	msg_pad4[4];
331 };
332 
333 /* from <sys/sem.h> */
334 typedef netbsd32_pointer_t netbsd32_semp_t;
335 
336 typedef netbsd32_pointer_t netbsd32_semid_dsp_t;
337 struct netbsd32_semid_ds {
338 	struct netbsd32_ipc_perm	sem_perm;/* operation permission struct */
339 	unsigned short	sem_nsems;	/* number of sems in set */
340 	netbsd32_time_t	sem_otime;	/* last operation time */
341 	netbsd32_time_t	sem_ctime;	/* last change time */
342 
343 	/*
344 	 * These members are private and used only in the internal
345 	 * implementation of this interface.
346 	 */
347 	netbsd32_semp_t	_sem_base;	/* pointer to first semaphore in set */
348 };
349 
350 struct netbsd32_semid_ds14 {
351 	struct netbsd32_ipc_perm14	sem_perm;/* operation permission struct */
352 	netbsd32_semp_t	sem_base;	/* pointer to first semaphore in set */
353 	unsigned short	sem_nsems;	/* number of sems in set */
354 	netbsd32_time_t	sem_otime;	/* last operation time */
355 	netbsd32_long	sem_pad1;	/* SVABI/386 says I need this here */
356 	netbsd32_time_t	sem_ctime;	/* last change time */
357 					/* Times measured in secs since */
358 					/* 00:00:00 GMT, Jan. 1, 1970 */
359 	netbsd32_long	sem_pad2;	/* SVABI/386 says I need this here */
360 	netbsd32_long	sem_pad3[4];	/* SVABI/386 says I need this here */
361 };
362 
363 typedef uint32_t netbsd32_semunu_t;
364 typedef netbsd32_pointer_t netbsd32_semunp_t;
365 union netbsd32_semun {
366 	int	val;			/* value for SETVAL */
367 	netbsd32_semid_dsp_t buf;	/* buffer for IPC_STAT & IPC_SET */
368 	netbsd32_u_shortp array;	/* array for GETALL & SETALL */
369 };
370 
371 typedef netbsd32_pointer_t netbsd32_sembufp_t;
372 struct netbsd32_sembuf {
373 	unsigned short	sem_num;	/* semaphore # */
374 	short		sem_op;		/* semaphore operation */
375 	short		sem_flg;	/* operation flags */
376 };
377 
378 /* from <sys/shm.h> */
379 typedef netbsd32_pointer_t netbsd32_shmid_dsp_t;
380 struct netbsd32_shmid_ds {
381 	struct netbsd32_ipc_perm shm_perm; /* operation permission structure */
382 	netbsd32_size_t	shm_segsz;	/* size of segment in bytes */
383 	pid_t		shm_lpid;	/* process ID of last shm op */
384 	pid_t		shm_cpid;	/* process ID of creator */
385 	shmatt_t	shm_nattch;	/* number of current attaches */
386 	netbsd32_time_t	shm_atime;	/* time of last shmat() */
387 	netbsd32_time_t	shm_dtime;	/* time of last shmdt() */
388 	netbsd32_time_t	shm_ctime;	/* time of last change by shmctl() */
389 	netbsd32_voidp	_shm_internal;	/* sysv stupidity */
390 };
391 
392 struct netbsd32_shmid_ds14 {
393 	struct netbsd32_ipc_perm14 shm_perm; /* operation permission structure */
394 	int		shm_segsz;	/* size of segment in bytes */
395 	pid_t		shm_lpid;	/* process ID of last shm op */
396 	pid_t		shm_cpid;	/* process ID of creator */
397 	short		shm_nattch;	/* number of current attaches */
398 	netbsd32_time_t	shm_atime;	/* time of last shmat() */
399 	netbsd32_time_t	shm_dtime;	/* time of last shmdt() */
400 	netbsd32_time_t	shm_ctime;	/* time of last change by shmctl() */
401 	netbsd32_voidp	_shm_internal;	/* sysv stupidity */
402 };
403 
404 /* from <sys/signal.h> */
405 typedef netbsd32_pointer_t netbsd32_sigsetp_t;
406 typedef netbsd32_pointer_t netbsd32_sigactionp_t;
407 struct	netbsd32_sigaction {
408 	netbsd32_voidp netbsd32_sa_handler;	/* signal handler */
409 	sigset_t netbsd32_sa_mask;		/* signal mask to apply */
410 	int	netbsd32_sa_flags;		/* see signal options below */
411 };
412 
413 typedef netbsd32_pointer_t netbsd32_sigaltstack13p_t;
414 struct netbsd32_sigaltstack13 {
415 	netbsd32_charp	ss_sp;		/* signal stack base */
416 	int	ss_size;		/* signal stack length */
417 	int	ss_flags;		/* SS_DISABLE and/or SS_ONSTACK */
418 };
419 
420 typedef netbsd32_pointer_t netbsd32_sigaltstackp_t;
421 struct netbsd32_sigaltstack {
422 	netbsd32_voidp	ss_sp;		/* signal stack base */
423 	netbsd32_size_t	ss_size;	/* signal stack length */
424 	int	ss_flags;		/* SS_DISABLE and/or SS_ONSTACK */
425 };
426 
427 typedef netbsd32_pointer_t netbsd32_sigstackp_t;
428 struct	netbsd32_sigstack {
429 	netbsd32_voidp	ss_sp;		/* signal stack pointer */
430 	int	ss_onstack;		/* current status */
431 };
432 
433 typedef netbsd32_pointer_t netbsd32_sigvecp_t;
434 struct	netbsd32_sigvec {
435 	netbsd32_voidp sv_handler;	/* signal handler */
436 	int	sv_mask;		/* signal mask to apply */
437 	int	sv_flags;		/* see signal options below */
438 };
439 
440 typedef netbsd32_pointer_t netbsd32_siginfop_t;
441 
442 union netbsd32_sigval {
443 	int	sival_int;
444 	netbsd32_voidp	sival_ptr;
445 };
446 
447 typedef netbsd32_pointer_t netbsd32_sigeventp_t;
448 struct netbsd32_sigevent {
449 	int	sigev_notify;
450 	int	sigev_signo;
451 	union netbsd32_sigval	sigev_value;
452 	netbsd32_voidp	sigev_notify_function;
453 	netbsd32_voidp	sigev_notify_attributes;
454 };
455 
456 /* from <sys/sigtypes.h> */
457 typedef netbsd32_pointer_t netbsd32_stackp_t;
458 
459 /* from <sys/socket.h> */
460 typedef netbsd32_pointer_t netbsd32_sockaddrp_t;
461 typedef netbsd32_pointer_t netbsd32_osockaddrp_t;
462 
463 typedef netbsd32_pointer_t netbsd32_msghdrp_t;
464 struct netbsd32_msghdr {
465 	netbsd32_caddr_t msg_name;		/* optional address */
466 	unsigned int	msg_namelen;		/* size of address */
467 	netbsd32_iovecp_t msg_iov;		/* scatter/gather array */
468 	unsigned int	msg_iovlen;		/* # elements in msg_iov */
469 	netbsd32_caddr_t msg_control;		/* ancillary data, see below */
470 	unsigned int	msg_controllen;		/* ancillary data buffer len */
471 	int	msg_flags;		/* flags on received message */
472 };
473 
474 typedef netbsd32_pointer_t netbsd32_omsghdrp_t;
475 struct netbsd32_omsghdr {
476 	netbsd32_caddr_t msg_name;		/* optional address */
477 	int		 msg_namelen;		/* size of address */
478 	netbsd32_iovecp_t msg_iov;		/* scatter/gather array */
479 	int		 msg_iovlen;		/* # elements in msg_iov */
480 	netbsd32_caddr_t msg_accrights;		/* access rights sent/recvd */
481 	int		 msg_accrightslen;
482 };
483 
484 /* from <sys/stat.h> */
485 typedef netbsd32_pointer_t netbsd32_stat12p_t;
486 struct netbsd32_stat12 {		/* NetBSD-1.2 stat struct */
487 	dev_t		st_dev;		/* inode's device */
488 	uint32_t	st_ino;		/* inode's number */
489 	uint16_t	st_mode;	/* inode protection mode */
490 	uint16_t	st_nlink;	/* number of hard links */
491 	uid_t		st_uid;		/* user ID of the file's owner */
492 	gid_t		st_gid;		/* group ID of the file's group */
493 	dev_t		st_rdev;	/* device type */
494 	struct netbsd32_timespec st_atimespec;/* time of last access */
495 	struct netbsd32_timespec st_mtimespec;/* time of last data modification */
496 	struct netbsd32_timespec st_ctimespec;/* time of last file status change */
497 	netbsd32_int64	st_size;	/* file size, in bytes */
498 	netbsd32_int64	st_blocks;	/* blocks allocated for file */
499 	uint32_t	st_blksize;	/* optimal blocksize for I/O */
500 	uint32_t	st_flags;	/* user defined flags for file */
501 	uint32_t	st_gen;		/* file generation number */
502 	int32_t		st_lspare;
503 	netbsd32_int64	st_qspare[2];
504 };
505 
506 typedef netbsd32_pointer_t netbsd32_stat43p_t;
507 struct netbsd32_stat43 {		/* BSD-4.3 stat struct */
508 	uint16_t  st_dev;		/* inode's device */
509 	uint32_t  st_ino;		/* inode's number */
510 	uint16_t  st_mode;		/* inode protection mode */
511 	uint16_t  st_nlink;		/* number of hard links */
512 	uint16_t  st_uid;		/* user ID of the file's owner */
513 	uint16_t  st_gid;		/* group ID of the file's group */
514 	uint16_t  st_rdev;		/* device type */
515 	int32_t	  st_size;		/* file size, in bytes */
516 	struct netbsd32_timespec st_atimespec;/* time of last access */
517 	struct netbsd32_timespec st_mtimespec;/* time of last data modification */
518 	struct netbsd32_timespec st_ctimespec;/* time of last file status change */
519 	int32_t	  st_blksize;		/* optimal blocksize for I/O */
520 	int32_t	  st_blocks;		/* blocks allocated for file */
521 	uint32_t  st_flags;		/* user defined flags for file */
522 	uint32_t  st_gen;		/* file generation number */
523 };
524 typedef netbsd32_pointer_t netbsd32_stat13p_t;
525 struct netbsd32_stat13 {
526 	dev_t	  st_dev;		/* inode's device */
527 	uint32_t  st_ino;		/* inode's number */
528 	mode_t	  st_mode;		/* inode protection mode */
529 	nlink_t	  st_nlink;		/* number of hard links */
530 	uid_t	  st_uid;		/* user ID of the file's owner */
531 	gid_t	  st_gid;		/* group ID of the file's group */
532 	dev_t	  st_rdev;		/* device type */
533 	struct netbsd32_timespec st_atimespec;/* time of last access */
534 	struct netbsd32_timespec st_mtimespec;/* time of last data modification */
535 	struct netbsd32_timespec st_ctimespec;/* time of last file status change */
536 	netbsd32_int64	  st_size;		/* file size, in bytes */
537 	netbsd32_uint64  st_blocks;		/* blocks allocated for file */
538 	blksize_t st_blksize;		/* optimal blocksize for I/O */
539 	uint32_t  st_flags;		/* user defined flags for file */
540 	uint32_t  st_gen;		/* file generation number */
541 	uint32_t  st_spare;		/* file generation number */
542 	struct	  netbsd32_timespec st_birthtimespec;
543 	uint32_t  st_spare2;
544 };
545 
546 typedef netbsd32_pointer_t netbsd32_statp_t;
547 struct netbsd32_stat {
548 	dev_t		st_dev;		/* inode's device */
549 	mode_t		st_mode;	/* inode protection mode */
550 	netbsd32_uint64	st_ino;		/* inode's number */
551 	nlink_t		st_nlink;	/* number of hard links */
552 	uid_t		st_uid;		/* user ID of the file's owner */
553 	gid_t		st_gid;		/* group ID of the file's group */
554 	dev_t		st_rdev;	/* device type */
555 	struct netbsd32_timespec st_atimespec;/* time of last access */
556 	struct netbsd32_timespec st_mtimespec;/* time of last data modification */
557 	struct netbsd32_timespec st_ctimespec;/* time of last file status change */
558 	struct netbsd32_timespec st_birthtimespec; /* time of creation */
559 	netbsd32_int64	st_size;	/* file size, in bytes */
560 	netbsd32_uint64 st_blocks;	/* blocks allocated for file */
561 	blksize_t	st_blksize;	/* optimal blocksize for I/O */
562 	uint32_t	st_flags;	/* user defined flags for file */
563 	uint32_t	st_gen;		/* file generation number */
564 	uint32_t	st_spare[2];
565 };
566 
567 /* from <sys/statvfs.h> */
568 typedef netbsd32_pointer_t netbsd32_statvfsp_t;
569 struct netbsd32_statvfs {
570 	netbsd32_u_long	f_flag;		/* copy of mount exported flags */
571 	netbsd32_u_long	f_bsize;	/* system block size */
572 	netbsd32_u_long	f_frsize;	/* system fragment size */
573 	netbsd32_u_long	f_iosize;	/* optimal file system block size */
574 	netbsd32_uint64	f_blocks;	/* number of blocks in file system */
575 	netbsd32_uint64	f_bfree;	/* free blocks avail in file system */
576 	netbsd32_uint64	f_bavail;	/* free blocks avail to non-root */
577 	netbsd32_uint64	f_bresvd;	/* blocks reserved for root */
578 	netbsd32_uint64	f_files;	/* total file nodes in file system */
579 	netbsd32_uint64	f_ffree;	/* free file nodes in file system */
580 	netbsd32_uint64	f_favail;	/* free file nodes avail to non-root */
581 	netbsd32_uint64	f_fresvd;	/* file nodes reserved for root */
582 	netbsd32_uint64	f_syncreads;	/* count of sync reads since mount */
583 	netbsd32_uint64	f_syncwrites;	/* count of sync writes since mount */
584 	netbsd32_uint64	f_asyncreads;	/* count of async reads since mount */
585 	netbsd32_uint64	f_asyncwrites;	/* count of async writes since mount */
586 	fsid_t		f_fsidx;	/* NetBSD compatible fsid */
587 	netbsd32_u_long	f_fsid;		/* Posix compatible fsid */
588 	netbsd32_u_long	f_namemax;	/* maximum filename length */
589 	uid_t		f_owner;	/* user that mounted the file system */
590 	uint32_t	f_spare[4];	/* spare space */
591 	char	f_fstypename[_VFS_NAMELEN]; /* fs type name */
592 	char	f_mntonname[_VFS_MNAMELEN];  /* directory on which mounted */
593 	char	f_mntfromname[_VFS_MNAMELEN];  /* mounted file system */
594 };
595 
596 /* from <sys/timex.h> */
597 typedef netbsd32_pointer_t netbsd32_ntptimevalp_t;
598 struct netbsd32_ntptimeval30 {
599 	struct netbsd32_timeval time;	/* current time (ro) */
600 	netbsd32_long maxerror;	/* maximum error (us) (ro) */
601 	netbsd32_long esterror;	/* estimated error (us) (ro) */
602 };
603 struct netbsd32_ntptimeval {
604 	struct netbsd32_timespec time;	/* current time (ro) */
605 	netbsd32_long maxerror;	/* maximum error (us) (ro) */
606 	netbsd32_long esterror;	/* estimated error (us) (ro) */
607 	netbsd32_long tai;	/* TAI offset */
608 	int time_state;		/* time status */
609 };
610 
611 typedef netbsd32_pointer_t netbsd32_timexp_t;
612 struct netbsd32_timex {
613 	unsigned int modes;	/* clock mode bits (wo) */
614 	netbsd32_long offset;	/* time offset (us) (rw) */
615 	netbsd32_long freq;	/* frequency offset (scaled ppm) (rw) */
616 	netbsd32_long maxerror;	/* maximum error (us) (rw) */
617 	netbsd32_long esterror;	/* estimated error (us) (rw) */
618 	int status;		/* clock status bits (rw) */
619 	netbsd32_long constant;	/* pll time constant (rw) */
620 	netbsd32_long precision;	/* clock precision (us) (ro) */
621 	netbsd32_long tolerance;	/* clock frequency tolerance (scaled
622 				 * ppm) (ro) */
623 	/*
624 	 * The following read-only structure members are implemented
625 	 * only if the PPS signal discipline is configured in the
626 	 * kernel.
627 	 */
628 	netbsd32_long ppsfreq;	/* pps frequency (scaled ppm) (ro) */
629 	netbsd32_long jitter;	/* pps jitter (us) (ro) */
630 	int shift;		/* interval duration (s) (shift) (ro) */
631 	netbsd32_long stabil;	/* pps stability (scaled ppm) (ro) */
632 	netbsd32_long jitcnt;	/* jitter limit exceeded (ro) */
633 	netbsd32_long calcnt;	/* calibration intervals (ro) */
634 	netbsd32_long errcnt;	/* calibration errors (ro) */
635 	netbsd32_long stbcnt;	/* stability limit exceeded (ro) */
636 };
637 
638 /* from <ufs/lfs/lfs.h> */
639 typedef netbsd32_pointer_t netbsd32_block_infop_t;  /* XXX broken */
640 
641 /* from <sys/utsname.h> */
642 typedef netbsd32_pointer_t netbsd32_utsnamep_t;
643 
644 /* from <compat/common/kern_info_09.c> */
645 typedef netbsd32_pointer_t netbsd32_outsnamep_t;
646 
647 /* from <arch/sparc{,64}/include/vuid_event.h> */
648 typedef struct firm_event32 {
649 	unsigned short	id;		/* key or MS_* or LOC_[XY]_DELTA */
650 	unsigned short	pad;		/* unused, at least by X11 */
651 	int	value;		/* VKEY_{UP,DOWN} or locator delta */
652 	struct netbsd32_timeval time;
653 } Firm_event32;
654 
655 /* from <sys/uuid.h> */
656 typedef netbsd32_pointer_t netbsd32_uuidp_t;
657 
658 /* from <sys/event.h> */
659 typedef netbsd32_pointer_t netbsd32_keventp_t;
660 
661 struct netbsd32_kevent {
662 	netbsd32_uintptr_t	ident;
663 	uint32_t		filter;
664 	uint32_t		flags;
665 	uint32_t		fflags;
666 	netbsd32_int64		data;
667 	netbsd32_intptr_t	udata;
668 };
669 
670 #if 0
671 int	netbsd32_kevent(struct lwp *, void *, register_t *);
672 #endif
673 
674 /*
675  * here are some macros to convert between netbsd32 and sparc64 types.
676  * note that they do *NOT* act like good macros and put ()'s around all
677  * arguments cuz this _breaks_ SCARG().
678  */
679 #define NETBSD32TO64(s32uap, uap, name) \
680 	    SCARG(uap, name) = SCARG(s32uap, name)
681 #define NETBSD32TOP(s32uap, uap, name, type) \
682 	    SCARG(uap, name) = SCARG_P32(s32uap, name)
683 #define NETBSD32TOX(s32uap, uap, name, type) \
684 	    SCARG(uap, name) = (type)SCARG(s32uap, name)
685 #define NETBSD32TOX64(s32uap, uap, name, type) \
686 	    SCARG(uap, name) = (type)(long)SCARG(s32uap, name)
687 
688 /* and some standard versions */
689 #define	NETBSD32TO64_UAP(name)		NETBSD32TO64(uap, &ua, name);
690 #define	NETBSD32TOP_UAP(name, type)	NETBSD32TOP(uap, &ua, name, type);
691 #define	NETBSD32TOX_UAP(name, type)	NETBSD32TOX(uap, &ua, name, type);
692 #define	NETBSD32TOX64_UAP(name, type)	NETBSD32TOX64(uap, &ua, name, type);
693 
694 #define	SCARG_P32(uap, name) NETBSD32PTR64(SCARG(uap, name))
695 
696 int	coredump_netbsd32(struct lwp *, void *);
697 
698 /*
699  * random other stuff
700  */
701 #include <compat/common/compat_util.h>
702 #include <compat/sys/siginfo.h>
703 
704 vaddr_t netbsd32_vm_default_addr(struct proc *, vaddr_t, vsize_t);
705 void netbsd32_adjust_limits(struct proc *);
706 
707 void	netbsd32_si_to_si32(siginfo32_t *, const siginfo_t *);
708 void	netbsd32_si32_to_si(siginfo_t *, const siginfo32_t *);
709 
710 void	startlwp32(void *);
711 struct netbsd32___semctl14_args;
712 int	do_netbsd32___semctl14(struct lwp *, const struct netbsd32___semctl14_args *, register_t *, void *);
713 
714 struct iovec *netbsd32_get_iov(struct netbsd32_iovec *, int, struct iovec *,
715 	    int);
716 
717 #ifdef SYSCTL_SETUP_PROTO
718 SYSCTL_SETUP_PROTO(netbsd32_sysctl_emul_setup);
719 #endif /* SYSCTL_SETUP_PROTO */
720 #endif /* _COMPAT_NETBSD32_NETBSD32_H_ */
721