| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: emul.c,v 1.80 2009/03/18 10:22:44 cegger Exp $ */ | | 1 | /* $NetBSD: emul.c,v 1.81 2009/03/18 17:56:15 pooka Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | | 4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. |
5 | * | | 5 | * |
6 | * Development of this software was supported by Google Summer of Code. | | 6 | * Development of this software was supported by Google Summer of Code. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | 18 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
27 | * SUCH DAMAGE. | | 27 | * SUCH DAMAGE. |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | #include <sys/cdefs.h> | | 30 | #include <sys/cdefs.h> |
31 | __KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.80 2009/03/18 10:22:44 cegger Exp $"); | | 31 | __KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.81 2009/03/18 17:56:15 pooka Exp $"); |
32 | | | 32 | |
33 | #include <sys/param.h> | | 33 | #include <sys/param.h> |
34 | #include <sys/malloc.h> | | 34 | #include <sys/malloc.h> |
35 | #include <sys/null.h> | | 35 | #include <sys/null.h> |
36 | #include <sys/vnode.h> | | 36 | #include <sys/vnode.h> |
37 | #include <sys/stat.h> | | 37 | #include <sys/stat.h> |
38 | #include <sys/select.h> | | 38 | #include <sys/select.h> |
39 | #include <sys/syslog.h> | | 39 | #include <sys/syslog.h> |
40 | #include <sys/namei.h> | | 40 | #include <sys/namei.h> |
41 | #include <sys/kauth.h> | | 41 | #include <sys/kauth.h> |
42 | #include <sys/conf.h> | | 42 | #include <sys/conf.h> |
43 | #include <sys/device.h> | | 43 | #include <sys/device.h> |
44 | #include <sys/queue.h> | | 44 | #include <sys/queue.h> |
| @@ -91,26 +91,27 @@ u_long bufmem_valimit; | | | @@ -91,26 +91,27 @@ u_long bufmem_valimit; |
91 | u_long bufmem_hiwater; | | 91 | u_long bufmem_hiwater; |
92 | u_long bufmem_lowater; | | 92 | u_long bufmem_lowater; |
93 | u_long bufmem; | | 93 | u_long bufmem; |
94 | u_int nbuf; | | 94 | u_int nbuf; |
95 | | | 95 | |
96 | const char *panicstr; | | 96 | const char *panicstr; |
97 | const char ostype[] = "NetBSD"; | | 97 | const char ostype[] = "NetBSD"; |
98 | const char osrelease[] = "999"; /* paradroid 4evah */ | | 98 | const char osrelease[] = "999"; /* paradroid 4evah */ |
99 | const char kernel_ident[] = "RUMP-ROAST"; | | 99 | const char kernel_ident[] = "RUMP-ROAST"; |
100 | const char *domainname; | | 100 | const char *domainname; |
101 | int domainnamelen; | | 101 | int domainnamelen; |
102 | | | 102 | |
103 | const struct filterops seltrue_filtops; | | 103 | const struct filterops seltrue_filtops; |
| | | 104 | const struct filterops sig_filtops; |
104 | | | 105 | |
105 | #define DEVSW_SIZE 255 | | 106 | #define DEVSW_SIZE 255 |
106 | const struct bdevsw *bdevsw0[DEVSW_SIZE]; /* XXX storage size */ | | 107 | const struct bdevsw *bdevsw0[DEVSW_SIZE]; /* XXX storage size */ |
107 | const struct bdevsw **bdevsw = bdevsw0; | | 108 | const struct bdevsw **bdevsw = bdevsw0; |
108 | const int sys_cdevsws = DEVSW_SIZE; | | 109 | const int sys_cdevsws = DEVSW_SIZE; |
109 | int max_cdevsws = DEVSW_SIZE; | | 110 | int max_cdevsws = DEVSW_SIZE; |
110 | | | 111 | |
111 | const struct cdevsw *cdevsw0[DEVSW_SIZE]; /* XXX storage size */ | | 112 | const struct cdevsw *cdevsw0[DEVSW_SIZE]; /* XXX storage size */ |
112 | const struct cdevsw **cdevsw = cdevsw0; | | 113 | const struct cdevsw **cdevsw = cdevsw0; |
113 | const int sys_bdevsws = DEVSW_SIZE; | | 114 | const int sys_bdevsws = DEVSW_SIZE; |
114 | int max_bdevsws = DEVSW_SIZE; | | 115 | int max_bdevsws = DEVSW_SIZE; |
115 | | | 116 | |
116 | struct devsw_conv devsw_conv0; | | 117 | struct devsw_conv devsw_conv0; |
| @@ -144,26 +145,36 @@ copystr(const void *kfaddr, void *kdaddr | | | @@ -144,26 +145,36 @@ copystr(const void *kfaddr, void *kdaddr |
144 | } | | 145 | } |
145 | | | 146 | |
146 | int | | 147 | int |
147 | copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done) | | 148 | copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done) |
148 | { | | 149 | { |
149 | | | 150 | |
150 | strlcpy(kaddr, uaddr, len); | | 151 | strlcpy(kaddr, uaddr, len); |
151 | if (done) | | 152 | if (done) |
152 | *done = strlen(kaddr)+1; /* includes termination */ | | 153 | *done = strlen(kaddr)+1; /* includes termination */ |
153 | return 0; | | 154 | return 0; |
154 | } | | 155 | } |
155 | | | 156 | |
156 | int | | 157 | int |
| | | 158 | copyoutstr(const void *kaddr, void *uaddr, size_t len, size_t *done) |
| | | 159 | { |
| | | 160 | |
| | | 161 | strlcpy(uaddr, kaddr, len); |
| | | 162 | if (done) |
| | | 163 | *done = strlen(uaddr)+1; /* includes termination */ |
| | | 164 | return 0; |
| | | 165 | } |
| | | 166 | |
| | | 167 | int |
157 | copyin_vmspace(struct vmspace *vm, const void *uaddr, void *kaddr, size_t len) | | 168 | copyin_vmspace(struct vmspace *vm, const void *uaddr, void *kaddr, size_t len) |
158 | { | | 169 | { |
159 | | | 170 | |
160 | return copyin(uaddr, kaddr, len); | | 171 | return copyin(uaddr, kaddr, len); |
161 | } | | 172 | } |
162 | | | 173 | |
163 | int | | 174 | int |
164 | copyout_vmspace(struct vmspace *vm, const void *kaddr, void *uaddr, size_t len) | | 175 | copyout_vmspace(struct vmspace *vm, const void *kaddr, void *uaddr, size_t len) |
165 | { | | 176 | { |
166 | | | 177 | |
167 | return copyout(kaddr, uaddr, len); | | 178 | return copyout(kaddr, uaddr, len); |
168 | } | | 179 | } |
169 | | | 180 | |
| @@ -483,40 +494,26 @@ int | | | @@ -483,40 +494,26 @@ int |
483 | sigispending(struct lwp *l, int signo) | | 494 | sigispending(struct lwp *l, int signo) |
484 | { | | 495 | { |
485 | | | 496 | |
486 | return 0; | | 497 | return 0; |
487 | } | | 498 | } |
488 | | | 499 | |
489 | void | | 500 | void |
490 | sigpending1(struct lwp *l, sigset_t *ss) | | 501 | sigpending1(struct lwp *l, sigset_t *ss) |
491 | { | | 502 | { |
492 | | | 503 | |
493 | panic("%s: not implemented", __func__); | | 504 | panic("%s: not implemented", __func__); |
494 | } | | 505 | } |
495 | | | 506 | |
496 | void | | | |
497 | knote_fdclose(int fd) | | | |
498 | { | | | |
499 | | | | |
500 | /* since we don't add knotes, we don't have to remove them */ | | | |
501 | } | | | |
502 | | | | |
503 | int | | | |
504 | seltrue_kqfilter(dev_t dev, struct knote *kn) | | | |
505 | { | | | |
506 | | | | |
507 | panic("%s: not implemented", __func__); | | | |
508 | } | | | |
509 | | | | |
510 | int | | 507 | int |
511 | kpause(const char *wmesg, bool intr, int timeo, kmutex_t *mtx) | | 508 | kpause(const char *wmesg, bool intr, int timeo, kmutex_t *mtx) |
512 | { | | 509 | { |
513 | extern int hz; | | 510 | extern int hz; |
514 | int rv, error; | | 511 | int rv, error; |
515 | uint64_t sec, nsec; | | 512 | uint64_t sec, nsec; |
516 | | | 513 | |
517 | if (mtx) | | 514 | if (mtx) |
518 | mutex_exit(mtx); | | 515 | mutex_exit(mtx); |
519 | | | 516 | |
520 | sec = timeo / hz; | | 517 | sec = timeo / hz; |
521 | nsec = (timeo % hz) * (1000000000 / hz); | | 518 | nsec = (timeo % hz) * (1000000000 / hz); |
522 | rv = rumpuser_nanosleep(&sec, &nsec, &error); | | 519 | rv = rumpuser_nanosleep(&sec, &nsec, &error); |
| @@ -700,13 +697,46 @@ tputchar(int c, int flags, struct tty *t | | | @@ -700,13 +697,46 @@ tputchar(int c, int flags, struct tty *t |
700 | | | 697 | |
701 | void | | 698 | void |
702 | cpu_reboot(int howto, char *bootstr) | | 699 | cpu_reboot(int howto, char *bootstr) |
703 | { | | 700 | { |
704 | | | 701 | |
705 | rumpuser_panic(); | | 702 | rumpuser_panic(); |
706 | } | | 703 | } |
707 | | | 704 | |
708 | /* XXX: static, but not used except to make spcopy.S link */ | | 705 | /* XXX: static, but not used except to make spcopy.S link */ |
709 | #ifdef __hppa__ | | 706 | #ifdef __hppa__ |
710 | #undef curlwp | | 707 | #undef curlwp |
711 | struct lwp *curlwp = &lwp0; | | 708 | struct lwp *curlwp = &lwp0; |
712 | #endif | | 709 | #endif |
| | | 710 | |
| | | 711 | /* |
| | | 712 | * XXX: from sys_select.c, see that file for license. |
| | | 713 | * (these will go away really soon in favour of the real sys_select.c) |
| | | 714 | * ((really, the select code just needs cleanup)) |
| | | 715 | * (((seriously))) |
| | | 716 | */ |
| | | 717 | int |
| | | 718 | inittimeleft(struct timeval *tv, struct timeval *sleeptv) |
| | | 719 | { |
| | | 720 | if (itimerfix(tv)) |
| | | 721 | return -1; |
| | | 722 | getmicrouptime(sleeptv); |
| | | 723 | return 0; |
| | | 724 | } |
| | | 725 | |
| | | 726 | int |
| | | 727 | gettimeleft(struct timeval *tv, struct timeval *sleeptv) |
| | | 728 | { |
| | | 729 | /* |
| | | 730 | * We have to recalculate the timeout on every retry. |
| | | 731 | */ |
| | | 732 | struct timeval slepttv; |
| | | 733 | /* |
| | | 734 | * reduce tv by elapsed time |
| | | 735 | * based on monotonic time scale |
| | | 736 | */ |
| | | 737 | getmicrouptime(&slepttv); |
| | | 738 | timeradd(tv, sleeptv, tv); |
| | | 739 | timersub(tv, &slepttv, tv); |
| | | 740 | *sleeptv = slepttv; |
| | | 741 | return tvtohz(tv); |
| | | 742 | } |