aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/os-Linux/process.c')
-rw-r--r--arch/um/os-Linux/process.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c
index 76bdd6712417..92a7b59120d6 100644
--- a/arch/um/os-Linux/process.c
+++ b/arch/um/os-Linux/process.c
@@ -14,7 +14,6 @@
14#include "ptrace_user.h" 14#include "ptrace_user.h"
15#include "os.h" 15#include "os.h"
16#include "user.h" 16#include "user.h"
17#include "user_util.h"
18#include "process.h" 17#include "process.h"
19#include "irq_user.h" 18#include "irq_user.h"
20#include "kern_util.h" 19#include "kern_util.h"
@@ -22,6 +21,7 @@
22#include "skas_ptrace.h" 21#include "skas_ptrace.h"
23#include "kern_constants.h" 22#include "kern_constants.h"
24#include "uml-config.h" 23#include "uml-config.h"
24#include "init.h"
25 25
26#define ARBITRARY_ADDR -1 26#define ARBITRARY_ADDR -1
27#define FAILURE_PID -1 27#define FAILURE_PID -1
@@ -40,14 +40,14 @@ unsigned long os_process_pc(int pid)
40 if(fd < 0){ 40 if(fd < 0){
41 printk("os_process_pc - couldn't open '%s', err = %d\n", 41 printk("os_process_pc - couldn't open '%s', err = %d\n",
42 proc_stat, -fd); 42 proc_stat, -fd);
43 return(ARBITRARY_ADDR); 43 return ARBITRARY_ADDR;
44 } 44 }
45 err = os_read_file(fd, buf, sizeof(buf)); 45 CATCH_EINTR(err = read(fd, buf, sizeof(buf)));
46 if(err < 0){ 46 if(err < 0){
47 printk("os_process_pc - couldn't read '%s', err = %d\n", 47 printk("os_process_pc - couldn't read '%s', err = %d\n",
48 proc_stat, -err); 48 proc_stat, errno);
49 os_close_file(fd); 49 os_close_file(fd);
50 return(ARBITRARY_ADDR); 50 return ARBITRARY_ADDR;
51 } 51 }
52 os_close_file(fd); 52 os_close_file(fd);
53 pc = ARBITRARY_ADDR; 53 pc = ARBITRARY_ADDR;
@@ -56,7 +56,7 @@ unsigned long os_process_pc(int pid)
56 "%*d %*d %*d %*d %*d %lu", &pc) != 1){ 56 "%*d %*d %*d %*d %*d %lu", &pc) != 1){
57 printk("os_process_pc - couldn't find pc in '%s'\n", buf); 57 printk("os_process_pc - couldn't find pc in '%s'\n", buf);
58 } 58 }
59 return(pc); 59 return pc;
60} 60}
61 61
62int os_process_parent(int pid) 62int os_process_parent(int pid)
@@ -65,21 +65,22 @@ int os_process_parent(int pid)
65 char data[256]; 65 char data[256];
66 int parent, n, fd; 66 int parent, n, fd;
67 67
68 if(pid == -1) return(-1); 68 if(pid == -1)
69 return -1;
69 70
70 snprintf(stat, sizeof(stat), "/proc/%d/stat", pid); 71 snprintf(stat, sizeof(stat), "/proc/%d/stat", pid);
71 fd = os_open_file(stat, of_read(OPENFLAGS()), 0); 72 fd = os_open_file(stat, of_read(OPENFLAGS()), 0);
72 if(fd < 0){ 73 if(fd < 0){
73 printk("Couldn't open '%s', err = %d\n", stat, -fd); 74 printk("Couldn't open '%s', err = %d\n", stat, -fd);
74 return(FAILURE_PID); 75 return FAILURE_PID;
75 } 76 }
76 77
77 n = os_read_file(fd, data, sizeof(data)); 78 CATCH_EINTR(n = read(fd, data, sizeof(data)));
78 os_close_file(fd); 79 os_close_file(fd);
79 80
80 if(n < 0){ 81 if(n < 0){
81 printk("Couldn't read '%s', err = %d\n", stat, -n); 82 printk("Couldn't read '%s', err = %d\n", stat, errno);
82 return(FAILURE_PID); 83 return FAILURE_PID;
83 } 84 }
84 85
85 parent = FAILURE_PID; 86 parent = FAILURE_PID;
@@ -87,7 +88,7 @@ int os_process_parent(int pid)
87 if(n != 1) 88 if(n != 1)
88 printk("Failed to scan '%s'\n", data); 89 printk("Failed to scan '%s'\n", data);
89 90
90 return(parent); 91 return parent;
91} 92}
92 93
93void os_stop_process(int pid) 94void os_stop_process(int pid)
@@ -145,7 +146,7 @@ void os_usr1_process(int pid)
145 146
146int os_getpid(void) 147int os_getpid(void)
147{ 148{
148 return(syscall(__NR_getpid)); 149 return syscall(__NR_getpid);
149} 150}
150 151
151int os_getpgrp(void) 152int os_getpgrp(void)
@@ -165,8 +166,8 @@ int os_map_memory(void *virt, int fd, unsigned long long off, unsigned long len,
165 loc = mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED, 166 loc = mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED,
166 fd, off); 167 fd, off);
167 if(loc == MAP_FAILED) 168 if(loc == MAP_FAILED)
168 return(-errno); 169 return -errno;
169 return(0); 170 return 0;
170} 171}
171 172
172int os_protect_memory(void *addr, unsigned long len, int r, int w, int x) 173int os_protect_memory(void *addr, unsigned long len, int r, int w, int x)
@@ -175,8 +176,8 @@ int os_protect_memory(void *addr, unsigned long len, int r, int w, int x)
175 (x ? PROT_EXEC : 0)); 176 (x ? PROT_EXEC : 0));
176 177
177 if(mprotect(addr, len, prot) < 0) 178 if(mprotect(addr, len, prot) < 0)
178 return(-errno); 179 return -errno;
179 return(0); 180 return 0;
180} 181}
181 182
182int os_unmap_memory(void *addr, int len) 183int os_unmap_memory(void *addr, int len)
@@ -185,15 +186,15 @@ int os_unmap_memory(void *addr, int len)
185 186
186 err = munmap(addr, len); 187 err = munmap(addr, len);
187 if(err < 0) 188 if(err < 0)
188 return(-errno); 189 return -errno;
189 return(0); 190 return 0;
190} 191}
191 192
192#ifndef MADV_REMOVE 193#ifndef MADV_REMOVE
193#define MADV_REMOVE KERNEL_MADV_REMOVE 194#define MADV_REMOVE KERNEL_MADV_REMOVE
194#endif 195#endif
195 196
196int os_drop_memory(void *addr, int length) 197int __init os_drop_memory(void *addr, int length)
197{ 198{
198 int err; 199 int err;
199 200
@@ -203,7 +204,7 @@ int os_drop_memory(void *addr, int length)
203 return err; 204 return err;
204} 205}
205 206
206int can_drop_memory(void) 207int __init can_drop_memory(void)
207{ 208{
208 void *addr; 209 void *addr;
209 int fd, ok = 0; 210 int fd, ok = 0;
@@ -244,7 +245,7 @@ void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int))
244 245
245 if(sig_stack != NULL){ 246 if(sig_stack != NULL){
246 pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER); 247 pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER);
247 set_sigstack(sig_stack, pages * page_size()); 248 set_sigstack(sig_stack, pages * UM_KERN_PAGE_SIZE);
248 flags = SA_ONSTACK; 249 flags = SA_ONSTACK;
249 } 250 }
250 if(usr1_handler){ 251 if(usr1_handler){