thunk.h revision 1.49 1 /* $NetBSD: thunk.h,v 1.49 2011/12/30 11:32:57 reinoud 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 pid_t thunk_getpid(void);
117
118 int thunk_sigaction(int, const struct sigaction *, struct sigaction *);
119 int thunk_sigaltstack(const stack_t *, stack_t *);
120 void thunk_signal(int, void (*)(int));
121 int thunk_sigblock(int);
122 int thunk_sigunblock(int);
123 int thunk_sigemptyset(sigset_t *sa_mask);
124 void thunk_sigaddset(sigset_t *sa_mask, int sig);
125 int thunk_sigprocmask(int how, const sigset_t * set, sigset_t *oset);
126 int thunk_atexit(void (*function)(void));
127
128 int thunk_aio_read(struct aiocb *);
129 int thunk_aio_write(struct aiocb *);
130 int thunk_aio_error(const struct aiocb *);
131 int thunk_aio_return(struct aiocb *);
132
133 void * thunk_malloc(size_t len);
134 void thunk_free(void *addr);
135 void * thunk_sbrk(intptr_t len);
136 void * thunk_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);
137 int thunk_munmap(void *addr, size_t len);
138 int thunk_mprotect(void *addr, size_t len, int prot);
139 int thunk_posix_memalign(void **, size_t, size_t);
140
141 int thunk_idle(void);
142
143 char * thunk_getenv(const char *);
144 vaddr_t thunk_get_vm_min_address(void);
145
146 int thunk_getcpuinfo(char *, int *);
147
148 int thunk_getmachine(char *, size_t, char *, size_t);
149
150 int thunk_setown(int);
151
152 int thunk_open_tap(const char *);
153 int thunk_pollin_tap(int, int);
154 int thunk_pollout_tap(int, int);
155
156 typedef struct {
157 unsigned int sample_rate;
158 unsigned int precision;
159 unsigned int validbits;
160 unsigned int channels;
161 } thunk_audio_config_t;
162
163 int thunk_audio_open(const char *);
164 int thunk_audio_close(int);
165 int thunk_audio_drain(int);
166 int thunk_audio_config(int, const thunk_audio_config_t *,
167 const thunk_audio_config_t *);
168 int thunk_audio_pollout(int);
169 int thunk_audio_pollin(int);
170 int thunk_audio_write(int, const void *, size_t);
171 int thunk_audio_read(int, void *, size_t);
172
173 typedef enum {
174 /* client -> server */
175 THUNK_RFB_SET_PIXEL_FORMAT = 0,
176 THUNK_RFB_SET_ENCODINGS = 2,
177 THUNK_RFB_FRAMEBUFFER_UPDATE_REQUEST = 3,
178 THUNK_RFB_KEY_EVENT = 4,
179 THUNK_RFB_POINTER_EVENT = 5,
180 THUNK_RFB_CLIENT_CUT_TEXT = 6,
181 } thunk_rfb_message_t;
182
183 typedef struct {
184 thunk_rfb_message_t message_type;
185 union {
186 struct {
187 uint8_t down_flag;
188 uint32_t keysym;
189 } key_event;
190 } data;
191 } thunk_rfb_event_t;
192
193
194 typedef struct {
195 uint8_t type;
196 uint16_t x, y, w, h;
197 uint32_t colour; /* for RRE clear */
198 } thunk_rfb_update_t;
199 #define THUNK_RFB_TYPE_UPDATE 0
200 #define THUNK_RFB_TYPE_COPYRECT 1
201 #define THUNK_RFB_TYPE_RRE 2 /* rectangle fill */
202
203 #define THUNK_RFB_QUEUELEN 128
204
205 typedef struct {
206 int sockfd;
207 int clientfd;
208 thunk_rfb_event_t event;
209
210 bool connected;
211
212 uint16_t width;
213 uint16_t height;
214 uint8_t depth;
215 char name[64];
216 uint8_t *framebuf;
217
218 unsigned int nupdates;
219 unsigned int first_mergable;
220 thunk_rfb_update_t update[THUNK_RFB_QUEUELEN];
221 } thunk_rfb_t;
222
223 int thunk_rfb_open(thunk_rfb_t *, uint16_t);
224 int thunk_rfb_poll(thunk_rfb_t *, thunk_rfb_event_t *);
225 void thunk_rfb_update(thunk_rfb_t *, int, int, int, int);
226
227 #endif /* !_ARCH_USERMODE_INCLUDE_THUNK_H */
228