Sun Aug 28 21:19:49 2011 UTC ()
add thunk_tcgetattr and thunk_tcsetattr


(jmcneill)
diff -r1.19 -r1.20 src/sys/arch/usermode/include/thunk.h
diff -r1.21 -r1.22 src/sys/arch/usermode/usermode/thunk.c

cvs diff -r1.19 -r1.20 src/sys/arch/usermode/include/thunk.h (expand / switch to unified diff)

--- src/sys/arch/usermode/include/thunk.h 2011/08/28 19:37:15 1.19
+++ src/sys/arch/usermode/include/thunk.h 2011/08/28 21:19:49 1.20
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: thunk.h,v 1.19 2011/08/28 19:37:15 reinoud Exp $ */ 1/* $NetBSD: thunk.h,v 1.20 2011/08/28 21:19:49 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -38,41 +38,54 @@ @@ -38,41 +38,54 @@
38#include <sys/aio.h> 38#include <sys/aio.h>
39#include <sys/mman.h> 39#include <sys/mman.h>
40 40
41struct thunk_timeval { 41struct thunk_timeval {
42 int64_t tv_sec; 42 int64_t tv_sec;
43 int32_t tv_usec; 43 int32_t tv_usec;
44}; 44};
45 45
46struct thunk_itimerval { 46struct thunk_itimerval {
47 struct thunk_timeval it_interval; 47 struct thunk_timeval it_interval;
48 struct thunk_timeval it_value; 48 struct thunk_timeval it_value;
49}; 49};
50 50
 51struct thunk_termios {
 52 uint32_t c_iflag;
 53 uint32_t c_oflag;
 54 uint32_t c_cflag;
 55 uint32_t c_lflag;
 56 uint8_t c_cc[20];
 57 int32_t c_ispeed;
 58 int32_t c_ospeed;
 59};
 60
51int thunk_setitimer(int, const struct thunk_itimerval *, struct thunk_itimerval *); 61int thunk_setitimer(int, const struct thunk_itimerval *, struct thunk_itimerval *);
52int thunk_gettimeofday(struct thunk_timeval *, void *); 62int thunk_gettimeofday(struct thunk_timeval *, void *);
53unsigned int thunk_getcounter(void); 63unsigned int thunk_getcounter(void);
54long thunk_clock_getres_monotonic(void); 64long thunk_clock_getres_monotonic(void);
55int thunk_usleep(useconds_t); 65int thunk_usleep(useconds_t);
56 66
57void thunk_exit(int); 67void thunk_exit(int);
58void thunk_abort(void); 68void thunk_abort(void);
59 69
60int thunk_getcontext(ucontext_t *); 70int thunk_getcontext(ucontext_t *);
61int thunk_setcontext(const ucontext_t *); 71int thunk_setcontext(const ucontext_t *);
62void thunk_makecontext(ucontext_t *, void (*)(void), int, void (*)(void *), void *);  72void thunk_makecontext(ucontext_t *, void (*)(void), int, void (*)(void *), void *);
63void thunk_makecontext_trapframe2go(ucontext_t *, void *func, void *trapframe); 73void thunk_makecontext_trapframe2go(ucontext_t *, void *func, void *trapframe);
64int thunk_swapcontext(ucontext_t *, ucontext_t *); 74int thunk_swapcontext(ucontext_t *, ucontext_t *);
65 75
 76int thunk_tcgetattr(int, struct thunk_termios *);
 77int thunk_tcsetattr(int, int, const struct thunk_termios *);
 78
66int thunk_getchar(void); 79int thunk_getchar(void);
67void thunk_putchar(int); 80void thunk_putchar(int);
68 81
69int thunk_execv(const char *, char * const []); 82int thunk_execv(const char *, char * const []);
70 83
71int thunk_open(const char *, int, mode_t); 84int thunk_open(const char *, int, mode_t);
72int thunk_fstat_getsize(int, ssize_t *, ssize_t *); 85int thunk_fstat_getsize(int, ssize_t *, ssize_t *);
73ssize_t thunk_pread(int, void *, size_t, off_t); 86ssize_t thunk_pread(int, void *, size_t, off_t);
74ssize_t thunk_pwrite(int, const void *, size_t, off_t); 87ssize_t thunk_pwrite(int, const void *, size_t, off_t);
75int thunk_fsync(int); 88int thunk_fsync(int);
76int thunk_mkstemp(char *); 89int thunk_mkstemp(char *);
77int thunk_unlink(const char *); 90int thunk_unlink(const char *);
78 91

cvs diff -r1.21 -r1.22 src/sys/arch/usermode/usermode/thunk.c (expand / switch to unified diff)

--- src/sys/arch/usermode/usermode/thunk.c 2011/08/28 19:37:16 1.21
+++ src/sys/arch/usermode/usermode/thunk.c 2011/08/28 21:19:49 1.22
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: thunk.c,v 1.21 2011/08/28 19:37:16 reinoud Exp $ */ 1/* $NetBSD: thunk.c,v 1.22 2011/08/28 21:19:49 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,39 +17,40 @@ @@ -17,39 +17,40 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 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 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__RCSID("$NetBSD: thunk.c,v 1.21 2011/08/28 19:37:16 reinoud Exp $"); 30__RCSID("$NetBSD: thunk.c,v 1.22 2011/08/28 21:19:49 jmcneill Exp $");
31 31
32#include <sys/types.h> 32#include <sys/types.h>
33#include <sys/ansi.h> 33#include <sys/ansi.h>
34 34
35#include <aio.h> 35#include <aio.h>
36#include <assert.h> 36#include <assert.h>
37#include <fcntl.h> 37#include <fcntl.h>
38#include <stdarg.h> 38#include <stdarg.h>
39#include <stdint.h> 39#include <stdint.h>
40#include <stdio.h> 40#include <stdio.h>
41#include <stdlib.h> 41#include <stdlib.h>
42#include <signal.h> 42#include <signal.h>
 43#include <termios.h>
43#include <time.h> 44#include <time.h>
44#include <ucontext.h> 45#include <ucontext.h>
45#include <unistd.h> 46#include <unistd.h>
46 47
47#include "../include/thunk.h" 48#include "../include/thunk.h"
48 49
49static void 50static void
50thunk_to_timeval(const struct thunk_timeval *ttv, struct timeval *tv) 51thunk_to_timeval(const struct thunk_timeval *ttv, struct timeval *tv)
51{ 52{
52 tv->tv_sec = ttv->tv_sec; 53 tv->tv_sec = ttv->tv_sec;
53 tv->tv_usec = ttv->tv_usec; 54 tv->tv_usec = ttv->tv_usec;
54} 55}
55 56
@@ -64,26 +65,56 @@ static void @@ -64,26 +65,56 @@ static void
64thunk_to_itimerval(const struct thunk_itimerval *tit, struct itimerval *it) 65thunk_to_itimerval(const struct thunk_itimerval *tit, struct itimerval *it)
65{ 66{
66 thunk_to_timeval(&tit->it_interval, &it->it_interval); 67 thunk_to_timeval(&tit->it_interval, &it->it_interval);
67 thunk_to_timeval(&tit->it_value, &it->it_value); 68 thunk_to_timeval(&tit->it_value, &it->it_value);
68} 69}
69 70
70static void 71static void
71thunk_from_itimerval(const struct itimerval *it, struct thunk_itimerval *tit) 72thunk_from_itimerval(const struct itimerval *it, struct thunk_itimerval *tit)
72{ 73{
73 thunk_from_timeval(&it->it_interval, &tit->it_interval); 74 thunk_from_timeval(&it->it_interval, &tit->it_interval);
74 thunk_from_timeval(&it->it_value, &tit->it_value); 75 thunk_from_timeval(&it->it_value, &tit->it_value);
75} 76}
76 77
 78static void
 79thunk_to_termios(const struct thunk_termios *tt, struct termios *t)
 80{
 81 int i;
 82
 83 t->c_iflag = tt->c_iflag;
 84 t->c_oflag = tt->c_oflag;
 85 t->c_cflag = tt->c_cflag;
 86 t->c_lflag = tt->c_lflag;
 87 for (i = 0; i < __arraycount(t->c_cc); i++)
 88 t->c_cc[i] = tt->c_cc[i];
 89 t->c_ispeed = tt->c_ispeed;
 90 t->c_ospeed= tt->c_ospeed;
 91}
 92
 93static void
 94thunk_from_termios(const struct termios *t, struct thunk_termios *tt)
 95{
 96 int i;
 97
 98 tt->c_iflag = t->c_iflag;
 99 tt->c_oflag = t->c_oflag;
 100 tt->c_cflag = t->c_cflag;
 101 tt->c_lflag = t->c_lflag;
 102 for (i = 0; i < __arraycount(tt->c_cc); i++)
 103 tt->c_cc[i] = t->c_cc[i];
 104 tt->c_ispeed = t->c_ispeed;
 105 tt->c_ospeed= t->c_ospeed;
 106}
 107
77int 108int
78thunk_setitimer(int which, const struct thunk_itimerval *value, 109thunk_setitimer(int which, const struct thunk_itimerval *value,
79 struct thunk_itimerval *ovalue) 110 struct thunk_itimerval *ovalue)
80{ 111{
81 struct itimerval it, oit; 112 struct itimerval it, oit;
82 int error; 113 int error;
83 114
84 thunk_to_itimerval(value, &it); 115 thunk_to_itimerval(value, &it);
85 error = setitimer(which, &it, &oit); 116 error = setitimer(which, &it, &oit);
86 if (error) 117 if (error)
87 return error; 118 return error;
88 if (ovalue) 119 if (ovalue)
89 thunk_from_itimerval(&oit, ovalue); 120 thunk_from_itimerval(&oit, ovalue);
@@ -176,26 +207,48 @@ thunk_makecontext(ucontext_t *ucp, void  @@ -176,26 +207,48 @@ thunk_makecontext(ucontext_t *ucp, void
176void 207void
177thunk_makecontext_trapframe2go(ucontext_t *ucp, void *func, void *trapframe) 208thunk_makecontext_trapframe2go(ucontext_t *ucp, void *func, void *trapframe)
178{ 209{
179 makecontext(ucp, func, 1, trapframe); 210 makecontext(ucp, func, 1, trapframe);
180} 211}
181 212
182int 213int
183thunk_swapcontext(ucontext_t *oucp, ucontext_t *ucp) 214thunk_swapcontext(ucontext_t *oucp, ucontext_t *ucp)
184{ 215{
185 return swapcontext(oucp, ucp); 216 return swapcontext(oucp, ucp);
186} 217}
187 218
188int 219int
 220thunk_tcgetattr(int fd, struct thunk_termios *tt)
 221{
 222 struct termios t;
 223 int error;
 224
 225 error = tcgetattr(fd, &t);
 226 if (error)
 227 return error;
 228 thunk_from_termios(&t, tt);
 229 return 0;
 230}
 231
 232int
 233thunk_tcsetattr(int fd, int action, const struct thunk_termios *tt)
 234{
 235 struct termios t;
 236
 237 thunk_to_termios(tt, &t);
 238 return tcsetattr(fd, action, &t);
 239}
 240
 241int
189thunk_getchar(void) 242thunk_getchar(void)
190{ 243{
191 return getchar(); 244 return getchar();
192} 245}
193 246
194void 247void
195thunk_putchar(int c) 248thunk_putchar(int c)
196{ 249{
197 char wc = (char) c; 250 char wc = (char) c;
198 write(1, &wc, 1); 251 write(1, &wc, 1);
199} 252}
200 253
201int 254int