diff options
author | Gennady Sharapov <Gennady.V.Sharapov@intel.com> | 2006-01-18 20:42:41 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-18 22:20:19 -0500 |
commit | 4fef0c10fa174b57a10854b8b4b2b90d155706e0 (patch) | |
tree | 02cfcc989114da9a6d46484753937cc0e3a60b52 /arch/um/os-Linux/util.c | |
parent | 12919aa6e015dd85170fc3b1a3e10a5dfd116c72 (diff) |
[PATCH] uml: move libc-dependent utility procedures
The serial UML OS-abstraction layer patch (um/kernel dir).
This moves all systemcalls from user_util.c file under os-Linux dir
Signed-off-by: Gennady Sharapov <Gennady.V.Sharapov@intel.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/os-Linux/util.c')
-rw-r--r-- | arch/um/os-Linux/util.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/arch/um/os-Linux/util.c b/arch/um/os-Linux/util.c new file mode 100644 index 000000000000..d224434d5610 --- /dev/null +++ b/arch/um/os-Linux/util.c | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) | ||
3 | * Licensed under the GPL | ||
4 | */ | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <unistd.h> | ||
9 | #include <limits.h> | ||
10 | #include <setjmp.h> | ||
11 | #include <sys/mman.h> | ||
12 | #include <sys/stat.h> | ||
13 | #include <sys/utsname.h> | ||
14 | #include <sys/param.h> | ||
15 | #include <sys/time.h> | ||
16 | #include "asm/types.h" | ||
17 | #include <ctype.h> | ||
18 | #include <signal.h> | ||
19 | #include <wait.h> | ||
20 | #include <errno.h> | ||
21 | #include <stdarg.h> | ||
22 | #include <sched.h> | ||
23 | #include <termios.h> | ||
24 | #include <string.h> | ||
25 | #include "user_util.h" | ||
26 | #include "kern_util.h" | ||
27 | #include "user.h" | ||
28 | #include "mem_user.h" | ||
29 | #include "init.h" | ||
30 | #include "ptrace_user.h" | ||
31 | #include "uml-config.h" | ||
32 | #include "os.h" | ||
33 | |||
34 | void stack_protections(unsigned long address) | ||
35 | { | ||
36 | int prot = PROT_READ | PROT_WRITE | PROT_EXEC; | ||
37 | |||
38 | if(mprotect((void *) address, page_size(), prot) < 0) | ||
39 | panic("protecting stack failed, errno = %d", errno); | ||
40 | } | ||
41 | |||
42 | void task_protections(unsigned long address) | ||
43 | { | ||
44 | unsigned long guard = address + page_size(); | ||
45 | unsigned long stack = guard + page_size(); | ||
46 | int prot = 0, pages; | ||
47 | |||
48 | #ifdef notdef | ||
49 | if(mprotect((void *) stack, page_size(), prot) < 0) | ||
50 | panic("protecting guard page failed, errno = %d", errno); | ||
51 | #endif | ||
52 | pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER) - 2; | ||
53 | prot = PROT_READ | PROT_WRITE | PROT_EXEC; | ||
54 | if(mprotect((void *) stack, pages * page_size(), prot) < 0) | ||
55 | panic("protecting stack failed, errno = %d", errno); | ||
56 | } | ||
57 | |||
58 | int raw(int fd) | ||
59 | { | ||
60 | struct termios tt; | ||
61 | int err; | ||
62 | |||
63 | CATCH_EINTR(err = tcgetattr(fd, &tt)); | ||
64 | if(err < 0) | ||
65 | return -errno; | ||
66 | |||
67 | cfmakeraw(&tt); | ||
68 | |||
69 | CATCH_EINTR(err = tcsetattr(fd, TCSADRAIN, &tt)); | ||
70 | if(err < 0) | ||
71 | return -errno; | ||
72 | |||
73 | /* XXX tcsetattr could have applied only some changes | ||
74 | * (and cfmakeraw() is a set of changes) */ | ||
75 | return(0); | ||
76 | } | ||
77 | |||
78 | void setup_machinename(char *machine_out) | ||
79 | { | ||
80 | struct utsname host; | ||
81 | |||
82 | uname(&host); | ||
83 | #if defined(UML_CONFIG_UML_X86) && !defined(UML_CONFIG_64BIT) | ||
84 | if (!strcmp(host.machine, "x86_64")) { | ||
85 | strcpy(machine_out, "i686"); | ||
86 | return; | ||
87 | } | ||
88 | #endif | ||
89 | strcpy(machine_out, host.machine); | ||
90 | } | ||
91 | |||
92 | char host_info[(_UTSNAME_LENGTH + 1) * 4 + _UTSNAME_NODENAME_LENGTH + 1]; | ||
93 | |||
94 | void setup_hostinfo(void) | ||
95 | { | ||
96 | struct utsname host; | ||
97 | |||
98 | uname(&host); | ||
99 | sprintf(host_info, "%s %s %s %s %s", host.sysname, host.nodename, | ||
100 | host.release, host.version, host.machine); | ||
101 | } | ||
102 | |||
103 | int setjmp_wrapper(void (*proc)(void *, void *), ...) | ||
104 | { | ||
105 | va_list args; | ||
106 | sigjmp_buf buf; | ||
107 | int n; | ||
108 | |||
109 | n = sigsetjmp(buf, 1); | ||
110 | if(n == 0){ | ||
111 | va_start(args, proc); | ||
112 | (*proc)(&buf, &args); | ||
113 | } | ||
114 | va_end(args); | ||
115 | return(n); | ||
116 | } | ||