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
2525e70
Documentation
arch
alpha
arm
avr32
blackfin
cris
frv
h8300
ia64
m32r
m68k
microblaze
mips
mn10300
parisc
powerpc
s390
score
sh
sparc
tile
um
drivers
include
kernel
os-Linux
drivers
skas
sys-i386
sys-x86_64
Makefile
aio.c
elf_aux.c
execvp.c
file.c
helper.c
irq.c
main.c
mem.c
process.c
registers.c
sigio.c
signal.c
start_up.c
time.c
tls.c
tty.c
uaccess.c
umid.c
user_syms.c
util.c
scripts
sys-i386
sys-ia64
sys-ppc
sys-x86_64
.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
/
main.c
Blame
Blame
Latest commit
History
History
260 lines (220 loc) · 5.8 KB
Breadcrumbs
linux
/
arch
/
um
/
os-Linux
/
main.c
Top
File metadata and controls
Code
Blame
260 lines (220 loc) · 5.8 KB
Raw
/* * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <signal.h> #include <string.h> #include <sys/resource.h> #include "as-layout.h" #include "init.h" #include "kern_constants.h" #include "kern_util.h" #include "os.h" #include "um_malloc.h" #define PGD_BOUND (4 * 1024 * 1024) #define STACKSIZE (8 * 1024 * 1024) #define THREAD_NAME_LEN (256) static void set_stklim(void) { struct rlimit lim; if (getrlimit(RLIMIT_STACK, &lim) < 0) { perror("getrlimit"); exit(1); } if ((lim.rlim_cur == RLIM_INFINITY) || (lim.rlim_cur > STACKSIZE)) { lim.rlim_cur = STACKSIZE; if (setrlimit(RLIMIT_STACK, &lim) < 0) { perror("setrlimit"); exit(1); } } } static __init void do_uml_initcalls(void) { initcall_t *call; call = &__uml_initcall_start; while (call < &__uml_initcall_end) { (*call)(); call++; } } static void last_ditch_exit(int sig) { uml_cleanup(); exit(1); } static void install_fatal_handler(int sig) { struct sigaction action; /* All signals are enabled in this handler ... */ sigemptyset(&action.sa_mask); /* * ... including the signal being handled, plus we want the * handler reset to the default behavior, so that if an exit * handler is hanging for some reason, the UML will just die * after this signal is sent a second time. */ action.sa_flags = SA_RESETHAND | SA_NODEFER; action.sa_restorer = NULL; action.sa_handler = last_ditch_exit; if (sigaction(sig, &action, NULL) < 0) { printf("failed to install handler for signal %d - errno = %d\n", sig, errno); exit(1); } } #define UML_LIB_PATH ":" OS_LIB_PATH "/uml" static void setup_env_path(void) { char *new_path = NULL; char *old_path = NULL; int path_len = 0; old_path = getenv("PATH"); /* * if no PATH variable is set or it has an empty value * just use the default + /usr/lib/uml */ if (!old_path || (path_len = strlen(old_path)) == 0) { if (putenv("PATH=:/bin:/usr/bin/" UML_LIB_PATH)) perror("couldn't putenv"); return; } /* append /usr/lib/uml to the existing path */ path_len += strlen("PATH=" UML_LIB_PATH) + 1; new_path = malloc(path_len); if (!new_path) { perror("couldn't malloc to set a new PATH"); return; } snprintf(new_path, path_len, "PATH=%s" UML_LIB_PATH, old_path); if (putenv(new_path)) { perror("couldn't putenv to set a new PATH"); free(new_path); } } extern void scan_elf_aux( char **envp); int __init main(int argc, char **argv, char **envp) { char **new_argv; int ret, i, err; set_stklim(); setup_env_path(); new_argv = malloc((argc + 1) * sizeof(char *)); if (new_argv == NULL) { perror("Mallocing argv"); exit(1); } for (i = 0; i < argc; i++) { new_argv[i] = strdup(argv[i]); if (new_argv[i] == NULL) { perror("Mallocing an arg"); exit(1); } } new_argv[argc] = NULL; /* * Allow these signals to bring down a UML if all other * methods of control fail. */ install_fatal_handler(SIGINT); install_fatal_handler(SIGTERM); scan_elf_aux(envp); do_uml_initcalls(); ret = linux_main(argc, argv); /* * Disable SIGPROF - I have no idea why libc doesn't do this or turn * off the profiling time, but UML dies with a SIGPROF just before * exiting when profiling is active. */ change_sig(SIGPROF, 0); /* * This signal stuff used to be in the reboot case. However, * sometimes a SIGVTALRM can come in when we're halting (reproducably * when writing out gcov information, presumably because that takes * some time) and cause a segfault. */ /* stop timers and set SIGVTALRM to be ignored */ disable_timer(); /* disable SIGIO for the fds and set SIGIO to be ignored */ err = deactivate_all_fds(); if (err) printf("deactivate_all_fds failed, errno = %d\n", -err); /* * Let any pending signals fire now. This ensures * that they won't be delivered after the exec, when * they are definitely not expected. */ unblock_signals(); /* Reboot */ if (ret) { printf("\n"); execvp(new_argv[0], new_argv); perror("Failed to exec kernel"); ret = 1; } printf("\n"); return uml_exitcode; } extern void *__real_malloc(int); void *__wrap_malloc(int size) { void *ret; if (!kmalloc_ok) return __real_malloc(size); else if (size <= UM_KERN_PAGE_SIZE) /* finding contiguous pages can be hard*/ ret = uml_kmalloc(size, UM_GFP_KERNEL); else ret = vmalloc(size); /* * glibc people insist that if malloc fails, errno should be * set by malloc as well. So we do. */ if (ret == NULL) errno = ENOMEM; return ret; } void *__wrap_calloc(int n, int size) { void *ptr = __wrap_malloc(n * size); if (ptr == NULL) return NULL; memset(ptr, 0, n * size); return ptr; } extern void __real_free(void *); extern unsigned long high_physmem; void __wrap_free(void *ptr) { unsigned long addr = (unsigned long) ptr; /* * We need to know how the allocation happened, so it can be correctly * freed. This is done by seeing what region of memory the pointer is * in - * physical memory - kmalloc/kfree * kernel virtual memory - vmalloc/vfree * anywhere else - malloc/free * If kmalloc is not yet possible, then either high_physmem and/or * end_vm are still 0 (as at startup), in which case we call free, or * we have set them, but anyway addr has not been allocated from those * areas. So, in both cases __real_free is called. * * CAN_KMALLOC is checked because it would be bad to free a buffer * with kmalloc/vmalloc after they have been turned off during * shutdown. * XXX: However, we sometimes shutdown CAN_KMALLOC temporarily, so * there is a possibility for memory leaks. */ if ((addr >= uml_physmem) && (addr < high_physmem)) { if (kmalloc_ok) kfree(ptr); } else if ((addr >= start_vm) && (addr < end_vm)) { if (kmalloc_ok) vfree(ptr); } else __real_free(ptr); }
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
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
260
You can’t perform that action at this time.