diff options
Diffstat (limited to 'arch/um/os-Linux')
| -rw-r--r-- | arch/um/os-Linux/Makefile | 8 | ||||
| -rw-r--r-- | arch/um/os-Linux/aio.c | 211 | ||||
| -rw-r--r-- | arch/um/os-Linux/drivers/tuntap_user.c | 8 | ||||
| -rw-r--r-- | arch/um/os-Linux/elf_aux.c | 8 | ||||
| -rw-r--r-- | arch/um/os-Linux/file.c | 82 | ||||
| -rw-r--r-- | arch/um/os-Linux/mem.c | 161 | ||||
| -rw-r--r-- | arch/um/os-Linux/process.c | 1 | ||||
| -rw-r--r-- | arch/um/os-Linux/start_up.c | 120 | ||||
| -rw-r--r-- | arch/um/os-Linux/sys-i386/registers.c | 19 | ||||
| -rw-r--r-- | arch/um/os-Linux/sys-x86_64/registers.c | 19 | ||||
| -rw-r--r-- | arch/um/os-Linux/tt.c | 14 | ||||
| -rw-r--r-- | arch/um/os-Linux/util/Makefile | 4 | ||||
| -rw-r--r-- | arch/um/os-Linux/util/mk_user_constants.c | 23 |
13 files changed, 456 insertions, 222 deletions
diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index 7a1662419c0c..d15ec2af6a22 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile | |||
| @@ -3,11 +3,11 @@ | |||
| 3 | # Licensed under the GPL | 3 | # Licensed under the GPL |
| 4 | # | 4 | # |
| 5 | 5 | ||
| 6 | obj-y = aio.o elf_aux.o file.o process.o signal.o start_up.o time.o tt.o \ | 6 | obj-y = aio.o elf_aux.o file.o mem.o process.o signal.o start_up.o time.o \ |
| 7 | tty.o user_syms.o drivers/ sys-$(SUBARCH)/ | 7 | tt.o tty.o user_syms.o drivers/ sys-$(SUBARCH)/ |
| 8 | 8 | ||
| 9 | USER_OBJS := aio.o elf_aux.o file.o process.o signal.o start_up.o time.o tt.o \ | 9 | USER_OBJS := aio.o elf_aux.o file.o mem.o process.o signal.o start_up.o \ |
| 10 | tty.o | 10 | time.o tt.o tty.o |
| 11 | 11 | ||
| 12 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h | 12 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h |
| 13 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um | 13 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um |
diff --git a/arch/um/os-Linux/aio.c b/arch/um/os-Linux/aio.c index b04897cd995d..41cfb0944201 100644 --- a/arch/um/os-Linux/aio.c +++ b/arch/um/os-Linux/aio.c | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| 7 | #include <unistd.h> | 7 | #include <unistd.h> |
| 8 | #include <signal.h> | 8 | #include <signal.h> |
| 9 | #include <string.h> | ||
| 10 | #include <errno.h> | 9 | #include <errno.h> |
| 11 | #include <sched.h> | 10 | #include <sched.h> |
| 12 | #include <sys/syscall.h> | 11 | #include <sys/syscall.h> |
| @@ -17,31 +16,18 @@ | |||
| 17 | #include "user.h" | 16 | #include "user.h" |
| 18 | #include "mode.h" | 17 | #include "mode.h" |
| 19 | 18 | ||
| 19 | struct aio_thread_req { | ||
| 20 | enum aio_type type; | ||
| 21 | int io_fd; | ||
| 22 | unsigned long long offset; | ||
| 23 | char *buf; | ||
| 24 | int len; | ||
| 25 | struct aio_context *aio; | ||
| 26 | }; | ||
| 27 | |||
| 20 | static int aio_req_fd_r = -1; | 28 | static int aio_req_fd_r = -1; |
| 21 | static int aio_req_fd_w = -1; | 29 | static int aio_req_fd_w = -1; |
| 22 | 30 | ||
| 23 | static int update_aio(struct aio_context *aio, int res) | ||
| 24 | { | ||
| 25 | if(res < 0) | ||
| 26 | aio->len = res; | ||
| 27 | else if((res == 0) && (aio->type == AIO_READ)){ | ||
| 28 | /* This is the EOF case - we have hit the end of the file | ||
| 29 | * and it ends in a partial block, so we fill the end of | ||
| 30 | * the block with zeros and claim success. | ||
| 31 | */ | ||
| 32 | memset(aio->data, 0, aio->len); | ||
| 33 | aio->len = 0; | ||
| 34 | } | ||
| 35 | else if(res > 0){ | ||
| 36 | aio->len -= res; | ||
| 37 | aio->data += res; | ||
| 38 | aio->offset += res; | ||
| 39 | return aio->len; | ||
| 40 | } | ||
| 41 | |||
| 42 | return 0; | ||
| 43 | } | ||
| 44 | |||
| 45 | #if defined(HAVE_AIO_ABI) | 31 | #if defined(HAVE_AIO_ABI) |
| 46 | #include <linux/aio_abi.h> | 32 | #include <linux/aio_abi.h> |
| 47 | 33 | ||
| @@ -80,7 +66,8 @@ static long io_getevents(aio_context_t ctx_id, long min_nr, long nr, | |||
| 80 | * that it now backs the mmapped area. | 66 | * that it now backs the mmapped area. |
| 81 | */ | 67 | */ |
| 82 | 68 | ||
| 83 | static int do_aio(aio_context_t ctx, struct aio_context *aio) | 69 | static int do_aio(aio_context_t ctx, enum aio_type type, int fd, char *buf, |
| 70 | int len, unsigned long long offset, struct aio_context *aio) | ||
| 84 | { | 71 | { |
| 85 | struct iocb iocb, *iocbp = &iocb; | 72 | struct iocb iocb, *iocbp = &iocb; |
| 86 | char c; | 73 | char c; |
| @@ -88,37 +75,40 @@ static int do_aio(aio_context_t ctx, struct aio_context *aio) | |||
| 88 | 75 | ||
| 89 | iocb = ((struct iocb) { .aio_data = (unsigned long) aio, | 76 | iocb = ((struct iocb) { .aio_data = (unsigned long) aio, |
| 90 | .aio_reqprio = 0, | 77 | .aio_reqprio = 0, |
| 91 | .aio_fildes = aio->fd, | 78 | .aio_fildes = fd, |
| 92 | .aio_buf = (unsigned long) aio->data, | 79 | .aio_buf = (unsigned long) buf, |
| 93 | .aio_nbytes = aio->len, | 80 | .aio_nbytes = len, |
| 94 | .aio_offset = aio->offset, | 81 | .aio_offset = offset, |
| 95 | .aio_reserved1 = 0, | 82 | .aio_reserved1 = 0, |
| 96 | .aio_reserved2 = 0, | 83 | .aio_reserved2 = 0, |
| 97 | .aio_reserved3 = 0 }); | 84 | .aio_reserved3 = 0 }); |
| 98 | 85 | ||
| 99 | switch(aio->type){ | 86 | switch(type){ |
| 100 | case AIO_READ: | 87 | case AIO_READ: |
| 101 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; | 88 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; |
| 89 | err = io_submit(ctx, 1, &iocbp); | ||
| 102 | break; | 90 | break; |
| 103 | case AIO_WRITE: | 91 | case AIO_WRITE: |
| 104 | iocb.aio_lio_opcode = IOCB_CMD_PWRITE; | 92 | iocb.aio_lio_opcode = IOCB_CMD_PWRITE; |
| 93 | err = io_submit(ctx, 1, &iocbp); | ||
| 105 | break; | 94 | break; |
| 106 | case AIO_MMAP: | 95 | case AIO_MMAP: |
| 107 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; | 96 | iocb.aio_lio_opcode = IOCB_CMD_PREAD; |
| 108 | iocb.aio_buf = (unsigned long) &c; | 97 | iocb.aio_buf = (unsigned long) &c; |
| 109 | iocb.aio_nbytes = sizeof(c); | 98 | iocb.aio_nbytes = sizeof(c); |
| 99 | err = io_submit(ctx, 1, &iocbp); | ||
| 110 | break; | 100 | break; |
| 111 | default: | 101 | default: |
| 112 | printk("Bogus op in do_aio - %d\n", aio->type); | 102 | printk("Bogus op in do_aio - %d\n", type); |
| 113 | err = -EINVAL; | 103 | err = -EINVAL; |
| 114 | goto out; | 104 | break; |
| 115 | } | 105 | } |
| 116 | 106 | ||
| 117 | err = io_submit(ctx, 1, &iocbp); | ||
| 118 | if(err > 0) | 107 | if(err > 0) |
| 119 | err = 0; | 108 | err = 0; |
| 109 | else | ||
| 110 | err = -errno; | ||
| 120 | 111 | ||
| 121 | out: | ||
| 122 | return err; | 112 | return err; |
| 123 | } | 113 | } |
| 124 | 114 | ||
| @@ -127,9 +117,8 @@ static aio_context_t ctx = 0; | |||
| 127 | static int aio_thread(void *arg) | 117 | static int aio_thread(void *arg) |
| 128 | { | 118 | { |
| 129 | struct aio_thread_reply reply; | 119 | struct aio_thread_reply reply; |
| 130 | struct aio_context *aio; | ||
| 131 | struct io_event event; | 120 | struct io_event event; |
| 132 | int err, n; | 121 | int err, n, reply_fd; |
| 133 | 122 | ||
| 134 | signal(SIGWINCH, SIG_IGN); | 123 | signal(SIGWINCH, SIG_IGN); |
| 135 | 124 | ||
| @@ -142,21 +131,14 @@ static int aio_thread(void *arg) | |||
| 142 | "errno = %d\n", errno); | 131 | "errno = %d\n", errno); |
| 143 | } | 132 | } |
| 144 | else { | 133 | else { |
| 145 | aio = (struct aio_context *) event.data; | ||
| 146 | if(update_aio(aio, event.res)){ | ||
| 147 | do_aio(ctx, aio); | ||
| 148 | continue; | ||
| 149 | } | ||
| 150 | |||
| 151 | reply = ((struct aio_thread_reply) | 134 | reply = ((struct aio_thread_reply) |
| 152 | { .data = aio, | 135 | { .data = (void *) (long) event.data, |
| 153 | .err = aio->len }); | 136 | .err = event.res }); |
| 154 | err = os_write_file(aio->reply_fd, &reply, | 137 | reply_fd = ((struct aio_context *) reply.data)->reply_fd; |
| 155 | sizeof(reply)); | 138 | err = os_write_file(reply_fd, &reply, sizeof(reply)); |
| 156 | if(err != sizeof(reply)) | 139 | if(err != sizeof(reply)) |
| 157 | printk("aio_thread - write failed, " | 140 | printk("aio_thread - write failed, fd = %d, " |
| 158 | "fd = %d, err = %d\n", aio->reply_fd, | 141 | "err = %d\n", aio_req_fd_r, -err); |
| 159 | -err); | ||
| 160 | } | 142 | } |
| 161 | } | 143 | } |
| 162 | return 0; | 144 | return 0; |
| @@ -164,35 +146,35 @@ static int aio_thread(void *arg) | |||
| 164 | 146 | ||
| 165 | #endif | 147 | #endif |
| 166 | 148 | ||
| 167 | static int do_not_aio(struct aio_context *aio) | 149 | static int do_not_aio(struct aio_thread_req *req) |
| 168 | { | 150 | { |
| 169 | char c; | 151 | char c; |
| 170 | int err; | 152 | int err; |
| 171 | 153 | ||
| 172 | switch(aio->type){ | 154 | switch(req->type){ |
| 173 | case AIO_READ: | 155 | case AIO_READ: |
| 174 | err = os_seek_file(aio->fd, aio->offset); | 156 | err = os_seek_file(req->io_fd, req->offset); |
| 175 | if(err) | 157 | if(err) |
| 176 | goto out; | 158 | goto out; |
| 177 | 159 | ||
| 178 | err = os_read_file(aio->fd, aio->data, aio->len); | 160 | err = os_read_file(req->io_fd, req->buf, req->len); |
| 179 | break; | 161 | break; |
| 180 | case AIO_WRITE: | 162 | case AIO_WRITE: |
| 181 | err = os_seek_file(aio->fd, aio->offset); | 163 | err = os_seek_file(req->io_fd, req->offset); |
| 182 | if(err) | 164 | if(err) |
| 183 | goto out; | 165 | goto out; |
| 184 | 166 | ||
| 185 | err = os_write_file(aio->fd, aio->data, aio->len); | 167 | err = os_write_file(req->io_fd, req->buf, req->len); |
| 186 | break; | 168 | break; |
| 187 | case AIO_MMAP: | 169 | case AIO_MMAP: |
| 188 | err = os_seek_file(aio->fd, aio->offset); | 170 | err = os_seek_file(req->io_fd, req->offset); |
| 189 | if(err) | 171 | if(err) |
| 190 | goto out; | 172 | goto out; |
| 191 | 173 | ||
| 192 | err = os_read_file(aio->fd, &c, sizeof(c)); | 174 | err = os_read_file(req->io_fd, &c, sizeof(c)); |
| 193 | break; | 175 | break; |
| 194 | default: | 176 | default: |
| 195 | printk("do_not_aio - bad request type : %d\n", aio->type); | 177 | printk("do_not_aio - bad request type : %d\n", req->type); |
| 196 | err = -EINVAL; | 178 | err = -EINVAL; |
| 197 | break; | 179 | break; |
| 198 | } | 180 | } |
| @@ -203,14 +185,14 @@ static int do_not_aio(struct aio_context *aio) | |||
| 203 | 185 | ||
| 204 | static int not_aio_thread(void *arg) | 186 | static int not_aio_thread(void *arg) |
| 205 | { | 187 | { |
| 206 | struct aio_context *aio; | 188 | struct aio_thread_req req; |
| 207 | struct aio_thread_reply reply; | 189 | struct aio_thread_reply reply; |
| 208 | int err; | 190 | int err; |
| 209 | 191 | ||
| 210 | signal(SIGWINCH, SIG_IGN); | 192 | signal(SIGWINCH, SIG_IGN); |
| 211 | while(1){ | 193 | while(1){ |
| 212 | err = os_read_file(aio_req_fd_r, &aio, sizeof(aio)); | 194 | err = os_read_file(aio_req_fd_r, &req, sizeof(req)); |
| 213 | if(err != sizeof(aio)){ | 195 | if(err != sizeof(req)){ |
| 214 | if(err < 0) | 196 | if(err < 0) |
| 215 | printk("not_aio_thread - read failed, " | 197 | printk("not_aio_thread - read failed, " |
| 216 | "fd = %d, err = %d\n", aio_req_fd_r, | 198 | "fd = %d, err = %d\n", aio_req_fd_r, |
| @@ -221,34 +203,17 @@ static int not_aio_thread(void *arg) | |||
| 221 | } | 203 | } |
| 222 | continue; | 204 | continue; |
| 223 | } | 205 | } |
| 224 | again: | 206 | err = do_not_aio(&req); |
| 225 | err = do_not_aio(aio); | 207 | reply = ((struct aio_thread_reply) { .data = req.aio, |
| 226 | 208 | .err = err }); | |
| 227 | if(update_aio(aio, err)) | 209 | err = os_write_file(req.aio->reply_fd, &reply, sizeof(reply)); |
| 228 | goto again; | ||
| 229 | |||
| 230 | reply = ((struct aio_thread_reply) { .data = aio, | ||
| 231 | .err = aio->len }); | ||
| 232 | err = os_write_file(aio->reply_fd, &reply, sizeof(reply)); | ||
| 233 | if(err != sizeof(reply)) | 210 | if(err != sizeof(reply)) |
| 234 | printk("not_aio_thread - write failed, fd = %d, " | 211 | printk("not_aio_thread - write failed, fd = %d, " |
| 235 | "err = %d\n", aio_req_fd_r, -err); | 212 | "err = %d\n", aio_req_fd_r, -err); |
| 236 | } | 213 | } |
| 237 | } | 214 | } |
| 238 | 215 | ||
| 239 | static int submit_aio_24(struct aio_context *aio) | ||
| 240 | { | ||
| 241 | int err; | ||
| 242 | |||
| 243 | err = os_write_file(aio_req_fd_w, &aio, sizeof(aio)); | ||
| 244 | if(err == sizeof(aio)) | ||
| 245 | err = 0; | ||
| 246 | |||
| 247 | return err; | ||
| 248 | } | ||
| 249 | |||
| 250 | static int aio_pid = -1; | 216 | static int aio_pid = -1; |
| 251 | static int (*submit_proc)(struct aio_context *aio); | ||
| 252 | 217 | ||
| 253 | static int init_aio_24(void) | 218 | static int init_aio_24(void) |
| 254 | { | 219 | { |
| @@ -280,68 +245,64 @@ static int init_aio_24(void) | |||
| 280 | #endif | 245 | #endif |
| 281 | printk("2.6 host AIO support not used - falling back to I/O " | 246 | printk("2.6 host AIO support not used - falling back to I/O " |
| 282 | "thread\n"); | 247 | "thread\n"); |
| 283 | |||
| 284 | submit_proc = submit_aio_24; | ||
| 285 | |||
| 286 | return 0; | 248 | return 0; |
| 287 | } | 249 | } |
| 288 | 250 | ||
| 289 | #ifdef HAVE_AIO_ABI | 251 | #ifdef HAVE_AIO_ABI |
| 290 | #define DEFAULT_24_AIO 0 | 252 | #define DEFAULT_24_AIO 0 |
| 291 | static int submit_aio_26(struct aio_context *aio) | ||
| 292 | { | ||
| 293 | struct aio_thread_reply reply; | ||
| 294 | int err; | ||
| 295 | |||
| 296 | err = do_aio(ctx, aio); | ||
| 297 | if(err){ | ||
| 298 | reply = ((struct aio_thread_reply) { .data = aio, | ||
| 299 | .err = err }); | ||
| 300 | err = os_write_file(aio->reply_fd, &reply, sizeof(reply)); | ||
| 301 | if(err != sizeof(reply)) | ||
| 302 | printk("submit_aio_26 - write failed, " | ||
| 303 | "fd = %d, err = %d\n", aio->reply_fd, -err); | ||
| 304 | else err = 0; | ||
| 305 | } | ||
| 306 | |||
| 307 | return err; | ||
| 308 | } | ||
| 309 | |||
| 310 | static int init_aio_26(void) | 253 | static int init_aio_26(void) |
| 311 | { | 254 | { |
| 312 | unsigned long stack; | 255 | unsigned long stack; |
| 313 | int err; | 256 | int err; |
| 314 | 257 | ||
| 315 | if(io_setup(256, &ctx)){ | 258 | if(io_setup(256, &ctx)){ |
| 259 | err = -errno; | ||
| 316 | printk("aio_thread failed to initialize context, err = %d\n", | 260 | printk("aio_thread failed to initialize context, err = %d\n", |
| 317 | errno); | 261 | errno); |
| 318 | return -errno; | 262 | return err; |
| 319 | } | 263 | } |
| 320 | 264 | ||
| 321 | err = run_helper_thread(aio_thread, NULL, | 265 | err = run_helper_thread(aio_thread, NULL, |
| 322 | CLONE_FILES | CLONE_VM | SIGCHLD, &stack, 0); | 266 | CLONE_FILES | CLONE_VM | SIGCHLD, &stack, 0); |
| 323 | if(err < 0) | 267 | if(err < 0) |
| 324 | return -errno; | 268 | return err; |
| 325 | 269 | ||
| 326 | aio_pid = err; | 270 | aio_pid = err; |
| 327 | 271 | ||
| 328 | printk("Using 2.6 host AIO\n"); | 272 | printk("Using 2.6 host AIO\n"); |
| 273 | return 0; | ||
| 274 | } | ||
| 275 | |||
| 276 | static int submit_aio_26(enum aio_type type, int io_fd, char *buf, int len, | ||
| 277 | unsigned long long offset, struct aio_context *aio) | ||
| 278 | { | ||
| 279 | struct aio_thread_reply reply; | ||
| 280 | int err; | ||
| 329 | 281 | ||
| 330 | submit_proc = submit_aio_26; | 282 | err = do_aio(ctx, type, io_fd, buf, len, offset, aio); |
| 283 | if(err){ | ||
| 284 | reply = ((struct aio_thread_reply) { .data = aio, | ||
| 285 | .err = err }); | ||
| 286 | err = os_write_file(aio->reply_fd, &reply, sizeof(reply)); | ||
| 287 | if(err != sizeof(reply)) | ||
| 288 | printk("submit_aio_26 - write failed, " | ||
| 289 | "fd = %d, err = %d\n", aio->reply_fd, -err); | ||
| 290 | else err = 0; | ||
| 291 | } | ||
| 331 | 292 | ||
| 332 | return 0; | 293 | return err; |
| 333 | } | 294 | } |
| 334 | 295 | ||
| 335 | #else | 296 | #else |
| 336 | #define DEFAULT_24_AIO 1 | 297 | #define DEFAULT_24_AIO 1 |
| 337 | static int submit_aio_26(struct aio_context *aio) | 298 | static int init_aio_26(void) |
| 338 | { | 299 | { |
| 339 | return -ENOSYS; | 300 | return -ENOSYS; |
| 340 | } | 301 | } |
| 341 | 302 | ||
| 342 | static int init_aio_26(void) | 303 | static int submit_aio_26(enum aio_type type, int io_fd, char *buf, int len, |
| 304 | unsigned long long offset, struct aio_context *aio) | ||
| 343 | { | 305 | { |
| 344 | submit_proc = submit_aio_26; | ||
| 345 | return -ENOSYS; | 306 | return -ENOSYS; |
| 346 | } | 307 | } |
| 347 | #endif | 308 | #endif |
| @@ -408,7 +369,33 @@ static void exit_aio(void) | |||
| 408 | 369 | ||
| 409 | __uml_exitcall(exit_aio); | 370 | __uml_exitcall(exit_aio); |
| 410 | 371 | ||
| 411 | int submit_aio(struct aio_context *aio) | 372 | static int submit_aio_24(enum aio_type type, int io_fd, char *buf, int len, |
| 373 | unsigned long long offset, struct aio_context *aio) | ||
| 412 | { | 374 | { |
| 413 | return (*submit_proc)(aio); | 375 | struct aio_thread_req req = { .type = type, |
| 376 | .io_fd = io_fd, | ||
| 377 | .offset = offset, | ||
| 378 | .buf = buf, | ||
| 379 | .len = len, | ||
| 380 | .aio = aio, | ||
| 381 | }; | ||
| 382 | int err; | ||
| 383 | |||
| 384 | err = os_write_file(aio_req_fd_w, &req, sizeof(req)); | ||
| 385 | if(err == sizeof(req)) | ||
| 386 | err = 0; | ||
| 387 | |||
| 388 | return err; | ||
| 389 | } | ||
| 390 | |||
| 391 | int submit_aio(enum aio_type type, int io_fd, char *buf, int len, | ||
| 392 | unsigned long long offset, int reply_fd, | ||
| 393 | struct aio_context *aio) | ||
| 394 | { | ||
| 395 | aio->reply_fd = reply_fd; | ||
| 396 | if(aio_24) | ||
| 397 | return submit_aio_24(type, io_fd, buf, len, offset, aio); | ||
| 398 | else { | ||
| 399 | return submit_aio_26(type, io_fd, buf, len, offset, aio); | ||
| 400 | } | ||
| 414 | } | 401 | } |
diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c index 4b83c6c3f48d..4ba9b17adf13 100644 --- a/arch/um/os-Linux/drivers/tuntap_user.c +++ b/arch/um/os-Linux/drivers/tuntap_user.c | |||
| @@ -75,7 +75,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, | |||
| 75 | struct msghdr msg; | 75 | struct msghdr msg; |
| 76 | struct cmsghdr *cmsg; | 76 | struct cmsghdr *cmsg; |
| 77 | struct iovec iov; | 77 | struct iovec iov; |
| 78 | int pid, n; | 78 | int pid, n, err; |
| 79 | 79 | ||
| 80 | sprintf(version_buf, "%d", UML_NET_VERSION); | 80 | sprintf(version_buf, "%d", UML_NET_VERSION); |
| 81 | 81 | ||
| @@ -105,9 +105,10 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, | |||
| 105 | n = recvmsg(me, &msg, 0); | 105 | n = recvmsg(me, &msg, 0); |
| 106 | *used_out = n; | 106 | *used_out = n; |
| 107 | if(n < 0){ | 107 | if(n < 0){ |
| 108 | err = -errno; | ||
| 108 | printk("tuntap_open_tramp : recvmsg failed - errno = %d\n", | 109 | printk("tuntap_open_tramp : recvmsg failed - errno = %d\n", |
| 109 | errno); | 110 | errno); |
| 110 | return(-errno); | 111 | return err; |
| 111 | } | 112 | } |
| 112 | CATCH_EINTR(waitpid(pid, NULL, 0)); | 113 | CATCH_EINTR(waitpid(pid, NULL, 0)); |
| 113 | 114 | ||
| @@ -147,9 +148,10 @@ static int tuntap_open(void *data) | |||
| 147 | ifr.ifr_flags = IFF_TAP | IFF_NO_PI; | 148 | ifr.ifr_flags = IFF_TAP | IFF_NO_PI; |
| 148 | strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name)); | 149 | strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name)); |
| 149 | if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){ | 150 | if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){ |
| 151 | err = -errno; | ||
| 150 | printk("TUNSETIFF failed, errno = %d\n", errno); | 152 | printk("TUNSETIFF failed, errno = %d\n", errno); |
| 151 | os_close_file(pri->fd); | 153 | os_close_file(pri->fd); |
| 152 | return(-errno); | 154 | return err; |
| 153 | } | 155 | } |
| 154 | } | 156 | } |
| 155 | else { | 157 | else { |
diff --git a/arch/um/os-Linux/elf_aux.c b/arch/um/os-Linux/elf_aux.c index 1399520a8588..5a99dd3fbed0 100644 --- a/arch/um/os-Linux/elf_aux.c +++ b/arch/um/os-Linux/elf_aux.c | |||
| @@ -12,9 +12,10 @@ | |||
| 12 | #include "init.h" | 12 | #include "init.h" |
| 13 | #include "elf_user.h" | 13 | #include "elf_user.h" |
| 14 | #include "mem_user.h" | 14 | #include "mem_user.h" |
| 15 | #include <kernel-offsets.h> | 15 | #include <kern_constants.h> |
| 16 | 16 | ||
| 17 | #if HOST_ELF_CLASS == ELFCLASS32 | 17 | /* Use the one from the kernel - the host may miss it, if having old headers. */ |
| 18 | #if UM_ELF_CLASS == UM_ELFCLASS32 | ||
| 18 | typedef Elf32_auxv_t elf_auxv_t; | 19 | typedef Elf32_auxv_t elf_auxv_t; |
| 19 | #else | 20 | #else |
| 20 | typedef Elf64_auxv_t elf_auxv_t; | 21 | typedef Elf64_auxv_t elf_auxv_t; |
| @@ -54,7 +55,8 @@ __init void scan_elf_aux( char **envp) | |||
| 54 | * a_un, so we have to use a_val, which is | 55 | * a_un, so we have to use a_val, which is |
| 55 | * all that's left. | 56 | * all that's left. |
| 56 | */ | 57 | */ |
| 57 | elf_aux_platform = (char *) auxv->a_un.a_val; | 58 | elf_aux_platform = |
| 59 | (char *) (long) auxv->a_un.a_val; | ||
| 58 | break; | 60 | break; |
| 59 | case AT_PAGESZ: | 61 | case AT_PAGESZ: |
| 60 | page_size = auxv->a_un.a_val; | 62 | page_size = auxv->a_un.a_val; |
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c index fd45bb260907..f55773c819e6 100644 --- a/arch/um/os-Linux/file.c +++ b/arch/um/os-Linux/file.c | |||
| @@ -119,15 +119,11 @@ int os_window_size(int fd, int *rows, int *cols) | |||
| 119 | 119 | ||
| 120 | int os_new_tty_pgrp(int fd, int pid) | 120 | int os_new_tty_pgrp(int fd, int pid) |
| 121 | { | 121 | { |
| 122 | if(ioctl(fd, TIOCSCTTY, 0) < 0){ | 122 | if(ioctl(fd, TIOCSCTTY, 0) < 0) |
| 123 | printk("TIOCSCTTY failed, errno = %d\n", errno); | 123 | return -errno; |
| 124 | return(-errno); | ||
| 125 | } | ||
| 126 | 124 | ||
| 127 | if(tcsetpgrp(fd, pid) < 0){ | 125 | if(tcsetpgrp(fd, pid) < 0) |
| 128 | printk("tcsetpgrp failed, errno = %d\n", errno); | 126 | return -errno; |
| 129 | return(-errno); | ||
| 130 | } | ||
| 131 | 127 | ||
| 132 | return(0); | 128 | return(0); |
| 133 | } | 129 | } |
| @@ -146,18 +142,12 @@ int os_set_slip(int fd) | |||
| 146 | int disc, sencap; | 142 | int disc, sencap; |
| 147 | 143 | ||
| 148 | disc = N_SLIP; | 144 | disc = N_SLIP; |
| 149 | if(ioctl(fd, TIOCSETD, &disc) < 0){ | 145 | if(ioctl(fd, TIOCSETD, &disc) < 0) |
| 150 | printk("Failed to set slip line discipline - " | 146 | return -errno; |
| 151 | "errno = %d\n", errno); | ||
| 152 | return(-errno); | ||
| 153 | } | ||
| 154 | 147 | ||
| 155 | sencap = 0; | 148 | sencap = 0; |
| 156 | if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0){ | 149 | if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0) |
| 157 | printk("Failed to set slip encapsulation - " | 150 | return -errno; |
| 158 | "errno = %d\n", errno); | ||
| 159 | return(-errno); | ||
| 160 | } | ||
| 161 | 151 | ||
| 162 | return(0); | 152 | return(0); |
| 163 | } | 153 | } |
| @@ -180,22 +170,15 @@ int os_sigio_async(int master, int slave) | |||
| 180 | int flags; | 170 | int flags; |
| 181 | 171 | ||
| 182 | flags = fcntl(master, F_GETFL); | 172 | flags = fcntl(master, F_GETFL); |
| 183 | if(flags < 0) { | 173 | if(flags < 0) |
| 184 | printk("fcntl F_GETFL failed, errno = %d\n", errno); | 174 | return errno; |
| 185 | return(-errno); | ||
| 186 | } | ||
| 187 | 175 | ||
| 188 | if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) || | 176 | if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) || |
| 189 | (fcntl(master, F_SETOWN, os_getpid()) < 0)){ | 177 | (fcntl(master, F_SETOWN, os_getpid()) < 0)) |
| 190 | printk("fcntl F_SETFL or F_SETOWN failed, errno = %d\n", | 178 | return -errno; |
| 191 | errno); | ||
| 192 | return(-errno); | ||
| 193 | } | ||
| 194 | 179 | ||
| 195 | if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0)){ | 180 | if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0)) |
| 196 | printk("fcntl F_SETFL failed, errno = %d\n", errno); | 181 | return -errno; |
| 197 | return(-errno); | ||
| 198 | } | ||
| 199 | 182 | ||
| 200 | return(0); | 183 | return(0); |
| 201 | } | 184 | } |
| @@ -255,7 +238,7 @@ int os_file_mode(char *file, struct openflags *mode_out) | |||
| 255 | 238 | ||
| 256 | int os_open_file(char *file, struct openflags flags, int mode) | 239 | int os_open_file(char *file, struct openflags flags, int mode) |
| 257 | { | 240 | { |
| 258 | int fd, f = 0; | 241 | int fd, err, f = 0; |
| 259 | 242 | ||
| 260 | if(flags.r && flags.w) f = O_RDWR; | 243 | if(flags.r && flags.w) f = O_RDWR; |
| 261 | else if(flags.r) f = O_RDONLY; | 244 | else if(flags.r) f = O_RDONLY; |
| @@ -272,8 +255,9 @@ int os_open_file(char *file, struct openflags flags, int mode) | |||
| 272 | return(-errno); | 255 | return(-errno); |
| 273 | 256 | ||
| 274 | if(flags.cl && fcntl(fd, F_SETFD, 1)){ | 257 | if(flags.cl && fcntl(fd, F_SETFD, 1)){ |
| 258 | err = -errno; | ||
| 275 | os_close_file(fd); | 259 | os_close_file(fd); |
| 276 | return(-errno); | 260 | return err; |
| 277 | } | 261 | } |
| 278 | 262 | ||
| 279 | return(fd); | 263 | return(fd); |
| @@ -383,9 +367,9 @@ int os_file_size(char *file, unsigned long long *size_out) | |||
| 383 | return(fd); | 367 | return(fd); |
| 384 | } | 368 | } |
| 385 | if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ | 369 | if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ |
| 370 | err = -errno; | ||
| 386 | printk("Couldn't get the block size of \"%s\", " | 371 | printk("Couldn't get the block size of \"%s\", " |
| 387 | "errno = %d\n", file, errno); | 372 | "errno = %d\n", file, errno); |
| 388 | err = -errno; | ||
| 389 | os_close_file(fd); | 373 | os_close_file(fd); |
| 390 | return(err); | 374 | return(err); |
| 391 | } | 375 | } |
| @@ -473,11 +457,14 @@ int os_pipe(int *fds, int stream, int close_on_exec) | |||
| 473 | 457 | ||
| 474 | int os_set_fd_async(int fd, int owner) | 458 | int os_set_fd_async(int fd, int owner) |
| 475 | { | 459 | { |
| 460 | int err; | ||
| 461 | |||
| 476 | /* XXX This should do F_GETFL first */ | 462 | /* XXX This should do F_GETFL first */ |
| 477 | if(fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK) < 0){ | 463 | if(fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK) < 0){ |
| 464 | err = -errno; | ||
| 478 | printk("os_set_fd_async : failed to set O_ASYNC and " | 465 | printk("os_set_fd_async : failed to set O_ASYNC and " |
| 479 | "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); | 466 | "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); |
| 480 | return(-errno); | 467 | return err; |
| 481 | } | 468 | } |
| 482 | #ifdef notdef | 469 | #ifdef notdef |
| 483 | if(fcntl(fd, F_SETFD, 1) < 0){ | 470 | if(fcntl(fd, F_SETFD, 1) < 0){ |
| @@ -488,10 +475,11 @@ int os_set_fd_async(int fd, int owner) | |||
| 488 | 475 | ||
| 489 | if((fcntl(fd, F_SETSIG, SIGIO) < 0) || | 476 | if((fcntl(fd, F_SETSIG, SIGIO) < 0) || |
| 490 | (fcntl(fd, F_SETOWN, owner) < 0)){ | 477 | (fcntl(fd, F_SETOWN, owner) < 0)){ |
| 478 | err = -errno; | ||
| 491 | printk("os_set_fd_async : Failed to fcntl F_SETOWN " | 479 | printk("os_set_fd_async : Failed to fcntl F_SETOWN " |
| 492 | "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd, | 480 | "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd, |
| 493 | owner, errno); | 481 | owner, errno); |
| 494 | return(-errno); | 482 | return err; |
| 495 | } | 483 | } |
| 496 | 484 | ||
| 497 | return(0); | 485 | return(0); |
| @@ -516,11 +504,9 @@ int os_set_fd_block(int fd, int blocking) | |||
| 516 | if(blocking) flags &= ~O_NONBLOCK; | 504 | if(blocking) flags &= ~O_NONBLOCK; |
| 517 | else flags |= O_NONBLOCK; | 505 | else flags |= O_NONBLOCK; |
| 518 | 506 | ||
| 519 | if(fcntl(fd, F_SETFL, flags) < 0){ | 507 | if(fcntl(fd, F_SETFL, flags) < 0) |
| 520 | printk("Failed to change blocking on fd # %d, errno = %d\n", | 508 | return -errno; |
| 521 | fd, errno); | 509 | |
| 522 | return(-errno); | ||
| 523 | } | ||
| 524 | return(0); | 510 | return(0); |
| 525 | } | 511 | } |
| 526 | 512 | ||
| @@ -609,11 +595,8 @@ int os_create_unix_socket(char *file, int len, int close_on_exec) | |||
| 609 | int sock, err; | 595 | int sock, err; |
| 610 | 596 | ||
| 611 | sock = socket(PF_UNIX, SOCK_DGRAM, 0); | 597 | sock = socket(PF_UNIX, SOCK_DGRAM, 0); |
| 612 | if (sock < 0){ | 598 | if(sock < 0) |
| 613 | printk("create_unix_socket - socket failed, errno = %d\n", | 599 | return -errno; |
| 614 | errno); | ||
| 615 | return(-errno); | ||
| 616 | } | ||
| 617 | 600 | ||
| 618 | if(close_on_exec) { | 601 | if(close_on_exec) { |
| 619 | err = os_set_exec_close(sock, 1); | 602 | err = os_set_exec_close(sock, 1); |
| @@ -628,11 +611,8 @@ int os_create_unix_socket(char *file, int len, int close_on_exec) | |||
| 628 | snprintf(addr.sun_path, len, "%s", file); | 611 | snprintf(addr.sun_path, len, "%s", file); |
| 629 | 612 | ||
| 630 | err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); | 613 | err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); |
| 631 | if (err < 0){ | 614 | if(err < 0) |
| 632 | printk("create_listening_socket at '%s' - bind failed, " | 615 | return -errno; |
| 633 | "errno = %d\n", file, errno); | ||
| 634 | return(-errno); | ||
| 635 | } | ||
| 636 | 616 | ||
| 637 | return(sock); | 617 | return(sock); |
| 638 | } | 618 | } |
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c new file mode 100644 index 000000000000..8e71edaaf80b --- /dev/null +++ b/arch/um/os-Linux/mem.c | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <stddef.h> | ||
| 4 | #include <stdarg.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <fcntl.h> | ||
| 9 | #include <sys/types.h> | ||
| 10 | #include <sys/mman.h> | ||
| 11 | #include "kern_util.h" | ||
| 12 | #include "user.h" | ||
| 13 | #include "user_util.h" | ||
| 14 | #include "mem_user.h" | ||
| 15 | #include "init.h" | ||
| 16 | #include "os.h" | ||
| 17 | #include "tempfile.h" | ||
| 18 | #include "kern_constants.h" | ||
| 19 | |||
| 20 | #include <sys/param.h> | ||
| 21 | |||
| 22 | static char *tempdir = NULL; | ||
| 23 | |||
| 24 | static void __init find_tempdir(void) | ||
| 25 | { | ||
| 26 | char *dirs[] = { "TMP", "TEMP", "TMPDIR", NULL }; | ||
| 27 | int i; | ||
| 28 | char *dir = NULL; | ||
| 29 | |||
| 30 | if(tempdir != NULL) return; /* We've already been called */ | ||
| 31 | for(i = 0; dirs[i]; i++){ | ||
| 32 | dir = getenv(dirs[i]); | ||
| 33 | if((dir != NULL) && (*dir != '\0')) | ||
| 34 | break; | ||
| 35 | } | ||
| 36 | if((dir == NULL) || (*dir == '\0')) | ||
| 37 | dir = "/tmp"; | ||
| 38 | |||
| 39 | tempdir = malloc(strlen(dir) + 2); | ||
| 40 | if(tempdir == NULL){ | ||
| 41 | fprintf(stderr, "Failed to malloc tempdir, " | ||
| 42 | "errno = %d\n", errno); | ||
| 43 | return; | ||
| 44 | } | ||
| 45 | strcpy(tempdir, dir); | ||
| 46 | strcat(tempdir, "/"); | ||
| 47 | } | ||
| 48 | |||
| 49 | /* | ||
| 50 | * This proc still used in tt-mode | ||
| 51 | * (file: kernel/tt/ptproxy/proxy.c, proc: start_debugger). | ||
| 52 | * So it isn't 'static' yet. | ||
| 53 | */ | ||
| 54 | int make_tempfile(const char *template, char **out_tempname, int do_unlink) | ||
| 55 | { | ||
| 56 | char tempname[MAXPATHLEN]; | ||
| 57 | int fd; | ||
| 58 | |||
| 59 | find_tempdir(); | ||
| 60 | if (*template != '/') | ||
| 61 | strcpy(tempname, tempdir); | ||
| 62 | else | ||
| 63 | *tempname = 0; | ||
| 64 | strcat(tempname, template); | ||
| 65 | fd = mkstemp(tempname); | ||
| 66 | if(fd < 0){ | ||
| 67 | fprintf(stderr, "open - cannot create %s: %s\n", tempname, | ||
| 68 | strerror(errno)); | ||
| 69 | return -1; | ||
| 70 | } | ||
| 71 | if(do_unlink && (unlink(tempname) < 0)){ | ||
| 72 | perror("unlink"); | ||
| 73 | return -1; | ||
| 74 | } | ||
| 75 | if(out_tempname){ | ||
| 76 | *out_tempname = strdup(tempname); | ||
| 77 | if(*out_tempname == NULL){ | ||
| 78 | perror("strdup"); | ||
| 79 | return -1; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | return(fd); | ||
| 83 | } | ||
| 84 | |||
| 85 | #define TEMPNAME_TEMPLATE "vm_file-XXXXXX" | ||
| 86 | |||
| 87 | /* | ||
| 88 | * This proc is used in start_up.c | ||
| 89 | * So it isn't 'static'. | ||
| 90 | */ | ||
| 91 | int create_tmp_file(unsigned long len) | ||
| 92 | { | ||
| 93 | int fd, err; | ||
| 94 | char zero; | ||
| 95 | |||
| 96 | fd = make_tempfile(TEMPNAME_TEMPLATE, NULL, 1); | ||
| 97 | if(fd < 0) { | ||
| 98 | exit(1); | ||
| 99 | } | ||
| 100 | |||
| 101 | err = fchmod(fd, 0777); | ||
| 102 | if(err < 0){ | ||
| 103 | perror("os_mode_fd"); | ||
| 104 | exit(1); | ||
| 105 | } | ||
| 106 | |||
| 107 | if (lseek64(fd, len, SEEK_SET) < 0) { | ||
| 108 | perror("os_seek_file"); | ||
| 109 | exit(1); | ||
| 110 | } | ||
| 111 | |||
| 112 | zero = 0; | ||
| 113 | |||
| 114 | err = os_write_file(fd, &zero, 1); | ||
| 115 | if(err != 1){ | ||
| 116 | errno = -err; | ||
| 117 | perror("os_write_file"); | ||
| 118 | exit(1); | ||
| 119 | } | ||
| 120 | |||
| 121 | return(fd); | ||
| 122 | } | ||
| 123 | |||
| 124 | static int create_anon_file(unsigned long len) | ||
| 125 | { | ||
| 126 | void *addr; | ||
| 127 | int fd; | ||
| 128 | |||
| 129 | fd = open("/dev/anon", O_RDWR); | ||
| 130 | if(fd < 0) { | ||
| 131 | perror("opening /dev/anon"); | ||
| 132 | exit(1); | ||
| 133 | } | ||
| 134 | |||
| 135 | addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); | ||
| 136 | if(addr == MAP_FAILED){ | ||
| 137 | perror("mapping physmem file"); | ||
| 138 | exit(1); | ||
| 139 | } | ||
| 140 | munmap(addr, len); | ||
| 141 | |||
| 142 | return(fd); | ||
| 143 | } | ||
| 144 | |||
| 145 | extern int have_devanon; | ||
| 146 | |||
| 147 | int create_mem_file(unsigned long len) | ||
| 148 | { | ||
| 149 | int err, fd; | ||
| 150 | |||
| 151 | if(have_devanon) | ||
| 152 | fd = create_anon_file(len); | ||
| 153 | else fd = create_tmp_file(len); | ||
| 154 | |||
| 155 | err = os_set_exec_close(fd, 1); | ||
| 156 | if(err < 0){ | ||
| 157 | errno = -err; | ||
| 158 | perror("exec_close"); | ||
| 159 | } | ||
| 160 | return(fd); | ||
| 161 | } | ||
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index d32413e4b4ce..d9c52387c4a1 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include <unistd.h> | ||
| 6 | #include <stdio.h> | 7 | #include <stdio.h> |
| 7 | #include <errno.h> | 8 | #include <errno.h> |
| 8 | #include <signal.h> | 9 | #include <signal.h> |
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index 040cc1472bc7..b99ab414542f 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c | |||
| @@ -4,18 +4,22 @@ | |||
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include <stdio.h> | 6 | #include <stdio.h> |
| 7 | #include <stddef.h> | ||
| 8 | #include <stdarg.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <string.h> | ||
| 7 | #include <unistd.h> | 11 | #include <unistd.h> |
| 8 | #include <signal.h> | 12 | #include <signal.h> |
| 9 | #include <sched.h> | 13 | #include <sched.h> |
| 14 | #include <fcntl.h> | ||
| 10 | #include <errno.h> | 15 | #include <errno.h> |
| 11 | #include <stdarg.h> | ||
| 12 | #include <stdlib.h> | ||
| 13 | #include <setjmp.h> | 16 | #include <setjmp.h> |
| 14 | #include <sys/time.h> | 17 | #include <sys/time.h> |
| 15 | #include <sys/wait.h> | 18 | #include <sys/wait.h> |
| 16 | #include <sys/mman.h> | 19 | #include <sys/mman.h> |
| 17 | #include <asm/unistd.h> | 20 | #include <asm/unistd.h> |
| 18 | #include <asm/page.h> | 21 | #include <asm/page.h> |
| 22 | #include <sys/types.h> | ||
| 19 | #include "user_util.h" | 23 | #include "user_util.h" |
| 20 | #include "kern_util.h" | 24 | #include "kern_util.h" |
| 21 | #include "user.h" | 25 | #include "user.h" |
| @@ -25,6 +29,7 @@ | |||
| 25 | #include "sysdep/sigcontext.h" | 29 | #include "sysdep/sigcontext.h" |
| 26 | #include "irq_user.h" | 30 | #include "irq_user.h" |
| 27 | #include "ptrace_user.h" | 31 | #include "ptrace_user.h" |
| 32 | #include "mem_user.h" | ||
| 28 | #include "time_user.h" | 33 | #include "time_user.h" |
| 29 | #include "init.h" | 34 | #include "init.h" |
| 30 | #include "os.h" | 35 | #include "os.h" |
| @@ -32,6 +37,8 @@ | |||
| 32 | #include "choose-mode.h" | 37 | #include "choose-mode.h" |
| 33 | #include "mode.h" | 38 | #include "mode.h" |
| 34 | #include "tempfile.h" | 39 | #include "tempfile.h" |
| 40 | #include "kern_constants.h" | ||
| 41 | |||
| 35 | #ifdef UML_CONFIG_MODE_SKAS | 42 | #ifdef UML_CONFIG_MODE_SKAS |
| 36 | #include "skas.h" | 43 | #include "skas.h" |
| 37 | #include "skas_ptrace.h" | 44 | #include "skas_ptrace.h" |
| @@ -136,11 +143,22 @@ static int __init skas0_cmd_param(char *str, int* add) | |||
| 136 | return 0; | 143 | return 0; |
| 137 | } | 144 | } |
| 138 | 145 | ||
| 146 | /* The two __uml_setup would conflict, without this stupid alias. */ | ||
| 147 | |||
| 148 | static int __init mode_skas0_cmd_param(char *str, int* add) | ||
| 149 | __attribute__((alias("skas0_cmd_param"))); | ||
| 150 | |||
| 139 | __uml_setup("skas0", skas0_cmd_param, | 151 | __uml_setup("skas0", skas0_cmd_param, |
| 140 | "skas0\n" | 152 | "skas0\n" |
| 141 | " Disables SKAS3 usage, so that SKAS0 is used, unless \n" | 153 | " Disables SKAS3 usage, so that SKAS0 is used, unless \n" |
| 142 | " you specify mode=tt.\n\n"); | 154 | " you specify mode=tt.\n\n"); |
| 143 | 155 | ||
| 156 | __uml_setup("mode=skas0", mode_skas0_cmd_param, | ||
| 157 | "mode=skas0\n" | ||
| 158 | " Disables SKAS3 usage, so that SKAS0 is used, unless you \n" | ||
| 159 | " specify mode=tt. Note that this was recently added - on \n" | ||
| 160 | " older kernels you must use simply \"skas0\".\n\n"); | ||
| 161 | |||
| 144 | static int force_sysemu_disabled = 0; | 162 | static int force_sysemu_disabled = 0; |
| 145 | 163 | ||
| 146 | static int __init nosysemu_cmd_param(char *str, int* add) | 164 | static int __init nosysemu_cmd_param(char *str, int* add) |
| @@ -276,9 +294,38 @@ static void __init check_ptrace(void) | |||
| 276 | check_sysemu(); | 294 | check_sysemu(); |
| 277 | } | 295 | } |
| 278 | 296 | ||
| 297 | extern int create_tmp_file(unsigned long len); | ||
| 298 | |||
| 299 | static void check_tmpexec(void) | ||
| 300 | { | ||
| 301 | void *addr; | ||
| 302 | int err, fd = create_tmp_file(UM_KERN_PAGE_SIZE); | ||
| 303 | |||
| 304 | addr = mmap(NULL, UM_KERN_PAGE_SIZE, | ||
| 305 | PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0); | ||
| 306 | printf("Checking PROT_EXEC mmap in /tmp..."); | ||
| 307 | fflush(stdout); | ||
| 308 | if(addr == MAP_FAILED){ | ||
| 309 | err = errno; | ||
| 310 | perror("failed"); | ||
| 311 | if(err == EPERM) | ||
| 312 | printf("/tmp must be not mounted noexec\n"); | ||
| 313 | exit(1); | ||
| 314 | } | ||
| 315 | printf("OK\n"); | ||
| 316 | munmap(addr, UM_KERN_PAGE_SIZE); | ||
| 317 | |||
| 318 | close(fd); | ||
| 319 | } | ||
| 320 | |||
| 279 | void os_early_checks(void) | 321 | void os_early_checks(void) |
| 280 | { | 322 | { |
| 281 | check_ptrace(); | 323 | check_ptrace(); |
| 324 | |||
| 325 | /* Need to check this early because mmapping happens before the | ||
| 326 | * kernel is running. | ||
| 327 | */ | ||
| 328 | check_tmpexec(); | ||
| 282 | } | 329 | } |
| 283 | 330 | ||
| 284 | static int __init noprocmm_cmd_param(char *str, int* add) | 331 | static int __init noprocmm_cmd_param(char *str, int* add) |
| @@ -357,3 +404,72 @@ int can_do_skas(void) | |||
| 357 | return(0); | 404 | return(0); |
| 358 | } | 405 | } |
| 359 | #endif | 406 | #endif |
| 407 | |||
| 408 | int have_devanon = 0; | ||
| 409 | |||
| 410 | void check_devanon(void) | ||
| 411 | { | ||
| 412 | int fd; | ||
| 413 | |||
| 414 | printk("Checking for /dev/anon on the host..."); | ||
| 415 | fd = open("/dev/anon", O_RDWR); | ||
| 416 | if(fd < 0){ | ||
| 417 | printk("Not available (open failed with errno %d)\n", errno); | ||
| 418 | return; | ||
| 419 | } | ||
| 420 | |||
| 421 | printk("OK\n"); | ||
| 422 | have_devanon = 1; | ||
| 423 | } | ||
| 424 | |||
| 425 | int __init parse_iomem(char *str, int *add) | ||
| 426 | { | ||
| 427 | struct iomem_region *new; | ||
| 428 | struct uml_stat buf; | ||
| 429 | char *file, *driver; | ||
| 430 | int fd, err, size; | ||
| 431 | |||
| 432 | driver = str; | ||
| 433 | file = strchr(str,','); | ||
| 434 | if(file == NULL){ | ||
| 435 | printf("parse_iomem : failed to parse iomem\n"); | ||
| 436 | goto out; | ||
| 437 | } | ||
| 438 | *file = '\0'; | ||
| 439 | file++; | ||
| 440 | fd = os_open_file(file, of_rdwr(OPENFLAGS()), 0); | ||
| 441 | if(fd < 0){ | ||
| 442 | os_print_error(fd, "parse_iomem - Couldn't open io file"); | ||
| 443 | goto out; | ||
| 444 | } | ||
| 445 | |||
| 446 | err = os_stat_fd(fd, &buf); | ||
| 447 | if(err < 0){ | ||
| 448 | os_print_error(err, "parse_iomem - cannot stat_fd file"); | ||
| 449 | goto out_close; | ||
| 450 | } | ||
| 451 | |||
| 452 | new = malloc(sizeof(*new)); | ||
| 453 | if(new == NULL){ | ||
| 454 | perror("Couldn't allocate iomem_region struct"); | ||
| 455 | goto out_close; | ||
| 456 | } | ||
| 457 | |||
| 458 | size = (buf.ust_size + UM_KERN_PAGE_SIZE) & ~(UM_KERN_PAGE_SIZE - 1); | ||
| 459 | |||
| 460 | *new = ((struct iomem_region) { .next = iomem_regions, | ||
| 461 | .driver = driver, | ||
| 462 | .fd = fd, | ||
| 463 | .size = size, | ||
| 464 | .phys = 0, | ||
| 465 | .virt = 0 }); | ||
| 466 | iomem_regions = new; | ||
| 467 | iomem_size += new->size + UM_KERN_PAGE_SIZE; | ||
| 468 | |||
| 469 | return(0); | ||
| 470 | out_close: | ||
| 471 | os_close_file(fd); | ||
| 472 | out: | ||
| 473 | return(1); | ||
| 474 | } | ||
| 475 | |||
diff --git a/arch/um/os-Linux/sys-i386/registers.c b/arch/um/os-Linux/sys-i386/registers.c index 3125d320722c..aee4812333c6 100644 --- a/arch/um/os-Linux/sys-i386/registers.c +++ b/arch/um/os-Linux/sys-i386/registers.c | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | #include <errno.h> | 6 | #include <errno.h> |
| 7 | #include <string.h> | 7 | #include <string.h> |
| 8 | #include <setjmp.h> | ||
| 8 | #include "sysdep/ptrace_user.h" | 9 | #include "sysdep/ptrace_user.h" |
| 9 | #include "sysdep/ptrace.h" | 10 | #include "sysdep/ptrace.h" |
| 10 | #include "uml-config.h" | 11 | #include "uml-config.h" |
| @@ -126,13 +127,11 @@ void get_safe_registers(unsigned long *regs) | |||
| 126 | memcpy(regs, exec_regs, HOST_FRAME_SIZE * sizeof(unsigned long)); | 127 | memcpy(regs, exec_regs, HOST_FRAME_SIZE * sizeof(unsigned long)); |
| 127 | } | 128 | } |
| 128 | 129 | ||
| 129 | /* | 130 | void get_thread_regs(union uml_pt_regs *uml_regs, void *buffer) |
| 130 | * Overrides for Emacs so that we follow Linus's tabbing style. | 131 | { |
| 131 | * Emacs will notice this stuff at the end of the file and automatically | 132 | struct __jmp_buf_tag *jmpbuf = buffer; |
| 132 | * adjust the settings for this buffer only. This must remain at the end | 133 | |
| 133 | * of the file. | 134 | UPT_SET(uml_regs, EIP, jmpbuf->__jmpbuf[JB_PC]); |
| 134 | * --------------------------------------------------------------------------- | 135 | UPT_SET(uml_regs, UESP, jmpbuf->__jmpbuf[JB_SP]); |
| 135 | * Local variables: | 136 | UPT_SET(uml_regs, EBP, jmpbuf->__jmpbuf[JB_BP]); |
| 136 | * c-file-style: "linux" | 137 | } |
| 137 | * End: | ||
| 138 | */ | ||
diff --git a/arch/um/os-Linux/sys-x86_64/registers.c b/arch/um/os-Linux/sys-x86_64/registers.c index 44438d15c3d6..4b638dfb52b0 100644 --- a/arch/um/os-Linux/sys-x86_64/registers.c +++ b/arch/um/os-Linux/sys-x86_64/registers.c | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | #include <errno.h> | 6 | #include <errno.h> |
| 7 | #include <string.h> | 7 | #include <string.h> |
| 8 | #include <setjmp.h> | ||
| 8 | #include "ptrace_user.h" | 9 | #include "ptrace_user.h" |
| 9 | #include "uml-config.h" | 10 | #include "uml-config.h" |
| 10 | #include "skas_ptregs.h" | 11 | #include "skas_ptregs.h" |
| @@ -74,13 +75,11 @@ void get_safe_registers(unsigned long *regs) | |||
| 74 | memcpy(regs, exec_regs, HOST_FRAME_SIZE * sizeof(unsigned long)); | 75 | memcpy(regs, exec_regs, HOST_FRAME_SIZE * sizeof(unsigned long)); |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | /* | 78 | void get_thread_regs(union uml_pt_regs *uml_regs, void *buffer) |
| 78 | * Overrides for Emacs so that we follow Linus's tabbing style. | 79 | { |
| 79 | * Emacs will notice this stuff at the end of the file and automatically | 80 | struct __jmp_buf_tag *jmpbuf = buffer; |
| 80 | * adjust the settings for this buffer only. This must remain at the end | 81 | |
| 81 | * of the file. | 82 | UPT_SET(uml_regs, RIP, jmpbuf->__jmpbuf[JB_PC]); |
| 82 | * --------------------------------------------------------------------------- | 83 | UPT_SET(uml_regs, RSP, jmpbuf->__jmpbuf[JB_RSP]); |
| 83 | * Local variables: | 84 | UPT_SET(uml_regs, RBP, jmpbuf->__jmpbuf[JB_RBP]); |
| 84 | * c-file-style: "linux" | 85 | } |
| 85 | * End: | ||
| 86 | */ | ||
diff --git a/arch/um/os-Linux/tt.c b/arch/um/os-Linux/tt.c index 5b047ab8416a..a6db8877931a 100644 --- a/arch/um/os-Linux/tt.c +++ b/arch/um/os-Linux/tt.c | |||
| @@ -36,6 +36,20 @@ | |||
| 36 | #include "mode.h" | 36 | #include "mode.h" |
| 37 | #include "tempfile.h" | 37 | #include "tempfile.h" |
| 38 | 38 | ||
| 39 | int protect_memory(unsigned long addr, unsigned long len, int r, int w, int x, | ||
| 40 | int must_succeed) | ||
| 41 | { | ||
| 42 | int err; | ||
| 43 | |||
| 44 | err = os_protect_memory((void *) addr, len, r, w, x); | ||
| 45 | if(err < 0){ | ||
| 46 | if(must_succeed) | ||
| 47 | panic("protect failed, err = %d", -err); | ||
| 48 | else return(err); | ||
| 49 | } | ||
| 50 | return(0); | ||
| 51 | } | ||
| 52 | |||
| 39 | /* | 53 | /* |
| 40 | *------------------------- | 54 | *------------------------- |
| 41 | * only for tt mode (will be deleted in future...) | 55 | * only for tt mode (will be deleted in future...) |
diff --git a/arch/um/os-Linux/util/Makefile b/arch/um/os-Linux/util/Makefile deleted file mode 100644 index 9778aed0c314..000000000000 --- a/arch/um/os-Linux/util/Makefile +++ /dev/null | |||
| @@ -1,4 +0,0 @@ | |||
| 1 | hostprogs-y := mk_user_constants | ||
| 2 | always := $(hostprogs-y) | ||
| 3 | |||
| 4 | HOSTCFLAGS_mk_user_constants.o := -I$(objtree)/arch/um | ||
diff --git a/arch/um/os-Linux/util/mk_user_constants.c b/arch/um/os-Linux/util/mk_user_constants.c deleted file mode 100644 index 4838f30eecf0..000000000000 --- a/arch/um/os-Linux/util/mk_user_constants.c +++ /dev/null | |||
| @@ -1,23 +0,0 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <user-offsets.h> | ||
| 3 | |||
| 4 | int main(int argc, char **argv) | ||
| 5 | { | ||
| 6 | printf("/*\n"); | ||
| 7 | printf(" * Generated by mk_user_constants\n"); | ||
| 8 | printf(" */\n"); | ||
| 9 | printf("\n"); | ||
| 10 | printf("#ifndef __UM_USER_CONSTANTS_H\n"); | ||
| 11 | printf("#define __UM_USER_CONSTANTS_H\n"); | ||
| 12 | printf("\n"); | ||
| 13 | /* I'd like to use FRAME_SIZE from ptrace.h here, but that's wrong on | ||
| 14 | * x86_64 (216 vs 168 bytes). user_regs_struct is the correct size on | ||
| 15 | * both x86_64 and i386. | ||
| 16 | */ | ||
| 17 | printf("#define UM_FRAME_SIZE %d\n", __UM_FRAME_SIZE); | ||
| 18 | |||
| 19 | printf("\n"); | ||
| 20 | printf("#endif\n"); | ||
| 21 | |||
| 22 | return(0); | ||
| 23 | } | ||
