thunk.h revision 1.45 1 /* $NetBSD: thunk.h,v 1.45 2011/12/26 12:39:19 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 2011 Jared D. McNeill <jmcneill (at) invisible.ca>
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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef _ARCH_USERMODE_INCLUDE_THUNK_H
30 #define _ARCH_USERMODE_INCLUDE_THUNK_H
31
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #include <sys/stat.h>
35 #include <sys/fcntl.h>
36 #include <sys/ucontext.h>
37 #include <sys/signal.h>
38
39 struct thunk_timeval {
40 int64_t tv_sec;
41 int32_t tv_usec;
42 };
43
44 struct thunk_itimerval {
45 struct thunk_timeval it_interval;
46 struct thunk_timeval it_value;
47 };
48
49 struct thunk_termios {
50 uint32_t c_iflag;
51 uint32_t c_oflag;
52 uint32_t c_cflag;
53 uint32_t c_lflag;
54 uint8_t c_cc[20];
55 int32_t c_ispeed;
56 int32_t c_ospeed;
57 };
58
59 #define THUNK_MAP_ANON 0x0001
60 #define THUNK_MAP_FIXED 0x0002
61 #define THUNK_MAP_FILE 0x0004
62 #define THUNK_MAP_SHARED 0x0010
63 #define THUNK_MAP_PRIVATE 0x0020
64 #define THUNK_MAP_NOSYSCALLS 0x0040
65
66 #define THUNK_PROT_NONE 0x00
67 #define THUNK_PROT_READ 0x01
68 #define THUNK_PROT_WRITE 0x02
69 #define THUNK_PROT_EXEC 0x04
70
71 struct aiocb;
72
73 void dprintf_debug(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
74
75 int thunk_setitimer(int, const struct thunk_itimerval *, struct thunk_itimerval *);
76 int thunk_gettimeofday(struct thunk_timeval *, void *);
77 unsigned int thunk_getcounter(void);
78 long thunk_clock_getres_monotonic(void);
79 int thunk_usleep(useconds_t);
80
81 timer_t thunk_timer_attach(void);
82 int thunk_timer_start(timer_t, int);
83 int thunk_timer_getoverrun(timer_t);
84
85 void thunk_exit(int);
86 void thunk_abort(void);
87
88 int thunk_geterrno(void);
89 void thunk_seterrno(int err);
90
91 int thunk_getcontext(ucontext_t *);
92 int thunk_setcontext(const ucontext_t *);
93 void thunk_makecontext(ucontext_t *ucp, void (*func)(void),
94 int nargs, void *arg1, void *arg2, void *arg3);
95 int thunk_swapcontext(ucontext_t *, ucontext_t *);
96
97 int thunk_tcgetattr(int, struct thunk_termios *);
98 int thunk_tcsetattr(int, int, const struct thunk_termios *);
99
100 int thunk_set_stdin_sigio(int);
101 int thunk_pollchar(void);
102 int thunk_getchar(void);
103 void thunk_putchar(int);
104
105 int thunk_execv(const char *, char * const []);
106
107 int thunk_open(const char *, int, mode_t);
108 int thunk_fstat_getsize(int, ssize_t *, ssize_t *);
109 ssize_t thunk_pread(int, void *, size_t, off_t);
110 ssize_t thunk_pwrite(int, const void *, size_t, off_t);
111 ssize_t thunk_read(int, void *, size_t);
112 ssize_t thunk_write(int, const void *, size_t);
113 int thunk_fsync(int);
114 int thunk_mkstemp(char *);
115 int thunk_unlink(const char *);
116
117 int thunk_sigaction(int, const struct sigaction *, struct sigaction *);
118 int thunk_sigaltstack(const stack_t *, stack_t *);
119 void thunk_signal(int, void (*)(int));
120 int thunk_sigblock(int);
121 int thunk_sigunblock(int);
122 int thunk_sigemptyset(sigset_t *sa_mask);
123 void thunk_sigaddset(sigset_t *sa_mask, int sig);
124 int thunk_sigprocmask(int how, const sigset_t * set, sigset_t *oset);
125 int thunk_atexit(void (*function)(void));
126
127 int thunk_aio_read(struct aiocb *);
128 int thunk_aio_write(struct aiocb *);
129 int thunk_aio_error(const struct aiocb *);
130 int thunk_aio_return(struct aiocb *);
131
132 void * thunk_malloc(size_t len);
133 void thunk_free(void *addr);
134 void * thunk_sbrk(intptr_t len);
135 void * thunk_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);
136 int thunk_munmap(void *addr, size_t len);
137 int thunk_mprotect(void *addr, size_t len, int prot);
138 int thunk_posix_memalign(void **, size_t, size_t);
139
140 int thunk_idle(void);
141
142 char * thunk_getenv(const char *);
143 vaddr_t thunk_get_vm_min_address(void);
144
145 int thunk_getcpuinfo(char *, int *);
146
147 int thunk_getmachine(char *, size_t, char *, size_t);
148
149 int thunk_setown(int);
150
151 int thunk_open_tap(const char *);
152 int thunk_pollin_tap(int, int);
153 int thunk_pollout_tap(int, int);
154
155 int thunk_sdl_init(unsigned int, unsigned int, unsigned short);
156 void * thunk_sdl_getfb(size_t);
157 int thunk_sdl_getchar(void);
158
159 #endif /* !_ARCH_USERMODE_INCLUDE_THUNK_H */
160