Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
0de021f
Documentation
arch
alpha
arm
avr32
blackfin
cris
frv
h8300
ia64
m32r
m68k
microblaze
mips
mn10300
openrisc
parisc
powerpc
s390
score
sh
sparc
tile
um
drivers
include
kernel
os-Linux
drivers
skas
sys-x86
Makefile
aio.c
elf_aux.c
execvp.c
file.c
helper.c
internal.h
irq.c
main.c
mem.c
process.c
registers.c
sigio.c
signal.c
start_up.c
time.c
tls.c
tty.c
umid.c
user_syms.c
util.c
scripts
sys-ia64
sys-ppc
sys-x86
.gitignore
Kconfig.char
Kconfig.common
Kconfig.debug
Kconfig.net
Kconfig.rest
Kconfig.um
Kconfig.x86
Makefile
Makefile-i386
Makefile-ia64
Makefile-os-Linux
Makefile-ppc
Makefile-skas
Makefile-x86_64
defconfig
unicore32
x86
xtensa
.gitignore
Kconfig
block
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
arch
/
um
/
os-Linux
/
process.c
Copy path
Blame
Blame
Latest commit
History
History
259 lines (216 loc) · 5.21 KB
Breadcrumbs
linux
/
arch
/
um
/
os-Linux
/
process.c
Top
File metadata and controls
Code
Blame
259 lines (216 loc) · 5.21 KB
Raw
/* * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ #include <stdio.h> #include <unistd.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/ptrace.h> #include <sys/wait.h> #include <asm/unistd.h> #include "init.h" #include "longjmp.h" #include "os.h" #include "skas_ptrace.h" #define ARBITRARY_ADDR -1 #define FAILURE_PID -1 #define STAT_PATH_LEN sizeof("/proc/#######/stat\0") #define COMM_SCANF "%*[^)])" unsigned long os_process_pc(int pid) { char proc_stat[STAT_PATH_LEN], buf[256]; unsigned long pc = ARBITRARY_ADDR; int fd, err; sprintf(proc_stat, "/proc/%d/stat", pid); fd = open(proc_stat, O_RDONLY, 0); if (fd < 0) { printk(UM_KERN_ERR "os_process_pc - couldn't open '%s', " "errno = %d\n", proc_stat, errno); goto out; } CATCH_EINTR(err = read(fd, buf, sizeof(buf))); if (err < 0) { printk(UM_KERN_ERR "os_process_pc - couldn't read '%s', " "err = %d\n", proc_stat, errno); goto out_close; } os_close_file(fd); pc = ARBITRARY_ADDR; if (sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d " "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d " "%*d %*d %*d %*d %*d %lu", &pc) != 1) printk(UM_KERN_ERR "os_process_pc - couldn't find pc in '%s'\n", buf); out_close: close(fd); out: return pc; } int os_process_parent(int pid) { char stat[STAT_PATH_LEN]; char data[256]; int parent = FAILURE_PID, n, fd; if (pid == -1) return parent; snprintf(stat, sizeof(stat), "/proc/%d/stat", pid); fd = open(stat, O_RDONLY, 0); if (fd < 0) { printk(UM_KERN_ERR "Couldn't open '%s', errno = %d\n", stat, errno); return parent; } CATCH_EINTR(n = read(fd, data, sizeof(data))); close(fd); if (n < 0) { printk(UM_KERN_ERR "Couldn't read '%s', errno = %d\n", stat, errno); return parent; } parent = FAILURE_PID; n = sscanf(data, "%*d " COMM_SCANF " %*c %d", &parent); if (n != 1) printk(UM_KERN_ERR "Failed to scan '%s'\n", data); return parent; } void os_stop_process(int pid) { kill(pid, SIGSTOP); } void os_kill_process(int pid, int reap_child) { kill(pid, SIGKILL); if (reap_child) CATCH_EINTR(waitpid(pid, NULL, __WALL)); } /* This is here uniquely to have access to the userspace errno, i.e. the one * used by ptrace in case of error. */ long os_ptrace_ldt(long pid, long addr, long data) { int ret; ret = ptrace(PTRACE_LDT, pid, addr, data); if (ret < 0) return -errno; return ret; } /* Kill off a ptraced child by all means available. kill it normally first, * then PTRACE_KILL it, then PTRACE_CONT it in case it's in a run state from * which it can't exit directly. */ void os_kill_ptraced_process(int pid, int reap_child) { kill(pid, SIGKILL); ptrace(PTRACE_KILL, pid); ptrace(PTRACE_CONT, pid); if (reap_child) CATCH_EINTR(waitpid(pid, NULL, __WALL)); } /* Don't use the glibc version, which caches the result in TLS. It misses some * syscalls, and also breaks with clone(), which does not unshare the TLS. */ int os_getpid(void) { return syscall(__NR_getpid); } int os_getpgrp(void) { return getpgrp(); } int os_map_memory(void *virt, int fd, unsigned long long off, unsigned long len, int r, int w, int x) { void *loc; int prot; prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | (x ? PROT_EXEC : 0); loc = mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED, fd, off); if (loc == MAP_FAILED) return -errno; return 0; } int os_protect_memory(void *addr, unsigned long len, int r, int w, int x) { int prot = ((r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | (x ? PROT_EXEC : 0)); if (mprotect(addr, len, prot) < 0) return -errno; return 0; } int os_unmap_memory(void *addr, int len) { int err; err = munmap(addr, len); if (err < 0) return -errno; return 0; } #ifndef MADV_REMOVE #define MADV_REMOVE KERNEL_MADV_REMOVE #endif int os_drop_memory(void *addr, int length) { int err; err = madvise(addr, length, MADV_REMOVE); if (err < 0) err = -errno; return err; } int __init can_drop_memory(void) { void *addr; int fd, ok = 0; printk(UM_KERN_INFO "Checking host MADV_REMOVE support..."); fd = create_mem_file(UM_KERN_PAGE_SIZE); if (fd < 0) { printk(UM_KERN_ERR "Creating test memory file failed, " "err = %d\n", -fd); goto out; } addr = mmap64(NULL, UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { printk(UM_KERN_ERR "Mapping test memory file failed, " "err = %d\n", -errno); goto out_close; } if (madvise(addr, UM_KERN_PAGE_SIZE, MADV_REMOVE) != 0) { printk(UM_KERN_ERR "MADV_REMOVE failed, err = %d\n", -errno); goto out_unmap; } printk(UM_KERN_CONT "OK\n"); ok = 1; out_unmap: munmap(addr, UM_KERN_PAGE_SIZE); out_close: close(fd); out: return ok; } void init_new_thread_signals(void) { set_handler(SIGSEGV); set_handler(SIGTRAP); set_handler(SIGFPE); set_handler(SIGILL); set_handler(SIGBUS); signal(SIGHUP, SIG_IGN); set_handler(SIGIO); signal(SIGWINCH, SIG_IGN); signal(SIGTERM, SIG_DFL); } int run_kernel_thread(int (*fn)(void *), void *arg, jmp_buf **jmp_ptr) { jmp_buf buf; int n; *jmp_ptr = &buf; n = UML_SETJMP(&buf); if (n != 0) return n; (*fn)(arg); return 0; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
You can’t perform that action at this time.