VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
97870c34b4532 arch/um/os-Linux/main.c (Alex Dewar         2019-08-25 10:49:18 +0100   1) // SPDX-License-Identifier: GPL-2.0
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700   2) /*
2eb5f31bc4ea2 arch/um/os-Linux/main.c (Anton Ivanov       2015-11-02 16:16:37 +0000   3)  * Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700   4)  * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700   5)  */
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700   6) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700   7) #include <stdio.h>
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700   8) #include <stdlib.h>
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700   9) #include <unistd.h>
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  10) #include <errno.h>
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  11) #include <signal.h>
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  12) #include <string.h>
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  13) #include <sys/resource.h>
37185b3324087 arch/um/os-Linux/main.c (Al Viro            2012-10-08 03:27:32 +0100  14) #include <as-layout.h>
37185b3324087 arch/um/os-Linux/main.c (Al Viro            2012-10-08 03:27:32 +0100  15) #include <init.h>
37185b3324087 arch/um/os-Linux/main.c (Al Viro            2012-10-08 03:27:32 +0100  16) #include <kern_util.h>
37185b3324087 arch/um/os-Linux/main.c (Al Viro            2012-10-08 03:27:32 +0100  17) #include <os.h>
37185b3324087 arch/um/os-Linux/main.c (Al Viro            2012-10-08 03:27:32 +0100  18) #include <um_malloc.h>
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  19) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  20) #define PGD_BOUND (4 * 1024 * 1024)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  21) #define STACKSIZE (8 * 1024 * 1024)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  22) #define THREAD_NAME_LEN (256)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  23) 
b743ac54e54ca arch/um/os-Linux/main.c (Richard Weinberger 2011-07-25 17:12:52 -0700  24) long elf_aux_hwcap;
b743ac54e54ca arch/um/os-Linux/main.c (Richard Weinberger 2011-07-25 17:12:52 -0700  25) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  26) static void set_stklim(void)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  27) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  28) 	struct rlimit lim;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  29) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  30) 	if (getrlimit(RLIMIT_STACK, &lim) < 0) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  31) 		perror("getrlimit");
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  32) 		exit(1);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  33) 	}
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  34) 	if ((lim.rlim_cur == RLIM_INFINITY) || (lim.rlim_cur > STACKSIZE)) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  35) 		lim.rlim_cur = STACKSIZE;
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  36) 		if (setrlimit(RLIMIT_STACK, &lim) < 0) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  37) 			perror("setrlimit");
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  38) 			exit(1);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  39) 		}
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  40) 	}
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  41) }
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  42) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  43) static void last_ditch_exit(int sig)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  44) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  45) 	uml_cleanup();
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  46) 	exit(1);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  47) }
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700  48) 
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  49) static void install_fatal_handler(int sig)
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  50) {
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  51) 	struct sigaction action;
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  52) 
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  53) 	/* All signals are enabled in this handler ... */
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  54) 	sigemptyset(&action.sa_mask);
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  55) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  56) 	/*
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  57) 	 * ... including the signal being handled, plus we want the
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  58) 	 * handler reset to the default behavior, so that if an exit
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  59) 	 * handler is hanging for some reason, the UML will just die
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  60) 	 * after this signal is sent a second time.
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  61) 	 */
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  62) 	action.sa_flags = SA_RESETHAND | SA_NODEFER;
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  63) 	action.sa_restorer = NULL;
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  64) 	action.sa_handler = last_ditch_exit;
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  65) 	if (sigaction(sig, &action, NULL) < 0) {
0936d4f3d5a3d arch/um/os-Linux/main.c (Masami Hiramatsu   2017-05-18 02:19:31 +0900  66) 		os_warn("failed to install handler for signal %d "
0936d4f3d5a3d arch/um/os-Linux/main.c (Masami Hiramatsu   2017-05-18 02:19:31 +0900  67) 			"- errno = %d\n", sig, errno);
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  68) 		exit(1);
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  69) 	}
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  70) }
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700  71) 
0ce451acb1872 arch/um/os-Linux/main.c (Richard Weinberger 2011-05-24 17:13:00 -0700  72) #define UML_LIB_PATH	":" OS_LIB_PATH "/uml"
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  73) 
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  74) static void setup_env_path(void)
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  75) {
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  76) 	char *new_path = NULL;
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  77) 	char *old_path = NULL;
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  78) 	int path_len = 0;
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  79) 
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  80) 	old_path = getenv("PATH");
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  81) 	/*
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700  82) 	 * if no PATH variable is set or it has an empty value
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  83) 	 * just use the default + /usr/lib/uml
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  84) 	 */
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  85) 	if (!old_path || (path_len = strlen(old_path)) == 0) {
c9a3072d13e4b arch/um/os-Linux/main.c (WANG Cong          2008-02-04 22:30:35 -0800  86) 		if (putenv("PATH=:/bin:/usr/bin/" UML_LIB_PATH))
c9a3072d13e4b arch/um/os-Linux/main.c (WANG Cong          2008-02-04 22:30:35 -0800  87) 			perror("couldn't putenv");
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  88) 		return;
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  89) 	}
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  90) 
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  91) 	/* append /usr/lib/uml to the existing path */
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  92) 	path_len += strlen("PATH=" UML_LIB_PATH) + 1;
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  93) 	new_path = malloc(path_len);
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  94) 	if (!new_path) {
c9a3072d13e4b arch/um/os-Linux/main.c (WANG Cong          2008-02-04 22:30:35 -0800  95) 		perror("couldn't malloc to set a new PATH");
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  96) 		return;
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  97) 	}
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700  98) 	snprintf(new_path, path_len, "PATH=%s" UML_LIB_PATH, old_path);
c9a3072d13e4b arch/um/os-Linux/main.c (WANG Cong          2008-02-04 22:30:35 -0800  99) 	if (putenv(new_path)) {
c9a3072d13e4b arch/um/os-Linux/main.c (WANG Cong          2008-02-04 22:30:35 -0800 100) 		perror("couldn't putenv to set a new PATH");
c9a3072d13e4b arch/um/os-Linux/main.c (WANG Cong          2008-02-04 22:30:35 -0800 101) 		free(new_path);
c9a3072d13e4b arch/um/os-Linux/main.c (WANG Cong          2008-02-04 22:30:35 -0800 102) 	}
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700 103) }
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700 104) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 105) extern void scan_elf_aux( char **envp);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 106) 
36e454630473c arch/um/os-Linux/main.c (Jeff Dike          2007-05-06 14:51:11 -0700 107) int __init main(int argc, char **argv, char **envp)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 108) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 109) 	char **new_argv;
92515da73a5df arch/um/kernel/main.c   (Jeff Dike          2005-05-28 15:51:56 -0700 110) 	int ret, i, err;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 111) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 112) 	set_stklim();
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 113) 
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700 114) 	setup_env_path();
cb98cdcd0dd89 arch/um/os-Linux/main.c (Mattia Dongili     2006-05-01 12:16:01 -0700 115) 
250127216dd66 arch/um/os-Linux/main.c (Richard Weinberger 2013-08-18 13:30:09 +0200 116) 	setsid();
250127216dd66 arch/um/os-Linux/main.c (Richard Weinberger 2013-08-18 13:30:09 +0200 117) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 118) 	new_argv = malloc((argc + 1) * sizeof(char *));
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 119) 	if (new_argv == NULL) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 120) 		perror("Mallocing argv");
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 121) 		exit(1);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 122) 	}
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 123) 	for (i = 0; i < argc; i++) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 124) 		new_argv[i] = strdup(argv[i]);
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 125) 		if (new_argv[i] == NULL) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 126) 			perror("Mallocing an arg");
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 127) 			exit(1);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 128) 		}
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 129) 	}
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 130) 	new_argv[argc] = NULL;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 131) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 132) 	/*
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 133) 	 * Allow these signals to bring down a UML if all other
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700 134) 	 * methods of control fail.
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700 135) 	 */
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700 136) 	install_fatal_handler(SIGINT);
4b84c69b5f6c0 arch/um/os-Linux/main.c (Jeff Dike          2006-09-25 23:33:04 -0700 137) 	install_fatal_handler(SIGTERM);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 138) 
b743ac54e54ca arch/um/os-Linux/main.c (Richard Weinberger 2011-07-25 17:12:52 -0700 139) #ifdef CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 140) 	scan_elf_aux(envp);
b743ac54e54ca arch/um/os-Linux/main.c (Richard Weinberger 2011-07-25 17:12:52 -0700 141) #endif
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 142) 
9fcb663be42e4 arch/um/os-Linux/main.c (Anton Ivanov       2014-03-07 18:37:46 +0000 143) 	change_sig(SIGPIPE, 0);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 144) 	ret = linux_main(argc, argv);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 145) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 146) 	/*
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 147) 	 * Disable SIGPROF - I have no idea why libc doesn't do this or turn
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 148) 	 * off the profiling time, but UML dies with a SIGPROF just before
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 149) 	 * exiting when profiling is active.
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 150) 	 */
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 151) 	change_sig(SIGPROF, 0);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 152) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 153) 	/*
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 154) 	 * This signal stuff used to be in the reboot case.  However,
2eb5f31bc4ea2 arch/um/os-Linux/main.c (Anton Ivanov       2015-11-02 16:16:37 +0000 155) 	 * sometimes a timer signal can come in when we're halting (reproducably
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 156) 	 * when writing out gcov information, presumably because that takes
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 157) 	 * some time) and cause a segfault.
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 158) 	 */
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 159) 
2eb5f31bc4ea2 arch/um/os-Linux/main.c (Anton Ivanov       2015-11-02 16:16:37 +0000 160) 	/* stop timers and set timer signal to be ignored */
2eb5f31bc4ea2 arch/um/os-Linux/main.c (Anton Ivanov       2015-11-02 16:16:37 +0000 161) 	os_timer_disable();
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 162) 
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 163) 	/* disable SIGIO for the fds and set SIGIO to be ignored */
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 164) 	err = deactivate_all_fds();
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 165) 	if (err)
0936d4f3d5a3d arch/um/os-Linux/main.c (Masami Hiramatsu   2017-05-18 02:19:31 +0900 166) 		os_warn("deactivate_all_fds failed, errno = %d\n", -err);
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 167) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 168) 	/*
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 169) 	 * Let any pending signals fire now.  This ensures
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 170) 	 * that they won't be delivered after the exec, when
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 171) 	 * they are definitely not expected.
52c653b3bed32 arch/um/os-Linux/main.c (Jeff Dike          2005-11-07 00:58:50 -0800 172) 	 */
5c1f33e2a03c0 arch/um/os-Linux/main.c (Johannes Berg      2019-09-17 13:20:14 +0200 173) 	unblock_signals();
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 174) 
d3878bb800300 arch/um/os-Linux/main.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 175) 	os_info("\n");
92515da73a5df arch/um/kernel/main.c   (Jeff Dike          2005-05-28 15:51:56 -0700 176) 	/* Reboot */
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 177) 	if (ret) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 178) 		execvp(new_argv[0], new_argv);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 179) 		perror("Failed to exec kernel");
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 180) 		ret = 1;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 181) 	}
a5ed1ffa6c248 arch/um/os-Linux/main.c (Jeff Dike          2007-05-06 14:50:58 -0700 182) 	return uml_exitcode;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 183) }
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 184) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 185) extern void *__real_malloc(int);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 186) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 187) void *__wrap_malloc(int size)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 188) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 189) 	void *ret;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 190) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 191) 	if (!kmalloc_ok)
a5ed1ffa6c248 arch/um/os-Linux/main.c (Jeff Dike          2007-05-06 14:50:58 -0700 192) 		return __real_malloc(size);
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 193) 	else if (size <= UM_KERN_PAGE_SIZE)
c539ab73070b3 arch/um/os-Linux/main.c (Jeff Dike          2007-06-16 10:16:09 -0700 194) 		/* finding contiguous pages can be hard*/
43f5b3085fdd2 arch/um/os-Linux/main.c (Jeff Dike          2008-05-12 14:01:52 -0700 195) 		ret = uml_kmalloc(size, UM_GFP_KERNEL);
e4c4bf9968cb4 arch/um/os-Linux/main.c (Jeff Dike          2007-07-15 23:38:56 -0700 196) 	else ret = vmalloc(size);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 197) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 198) 	/*
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 199) 	 * glibc people insist that if malloc fails, errno should be
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 200) 	 * set by malloc as well. So we do.
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 201) 	 */
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 202) 	if (ret == NULL)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 203) 		errno = ENOMEM;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 204) 
a5ed1ffa6c248 arch/um/os-Linux/main.c (Jeff Dike          2007-05-06 14:50:58 -0700 205) 	return ret;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 206) }
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 207) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 208) void *__wrap_calloc(int n, int size)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 209) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 210) 	void *ptr = __wrap_malloc(n * size);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 211) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 212) 	if (ptr == NULL)
a5ed1ffa6c248 arch/um/os-Linux/main.c (Jeff Dike          2007-05-06 14:50:58 -0700 213) 		return NULL;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 214) 	memset(ptr, 0, n * size);
a5ed1ffa6c248 arch/um/os-Linux/main.c (Jeff Dike          2007-05-06 14:50:58 -0700 215) 	return ptr;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 216) }
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 217) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 218) extern void __real_free(void *);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 219) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 220) extern unsigned long high_physmem;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 221) 
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 222) void __wrap_free(void *ptr)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 223) {
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 224) 	unsigned long addr = (unsigned long) ptr;
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 225) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 226) 	/*
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 227) 	 * We need to know how the allocation happened, so it can be correctly
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 228) 	 * freed.  This is done by seeing what region of memory the pointer is
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 229) 	 * in -
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 230) 	 * 	physical memory - kmalloc/kfree
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 231) 	 *	kernel virtual memory - vmalloc/vfree
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 232) 	 * 	anywhere else - malloc/free
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 233) 	 * If kmalloc is not yet possible, then either high_physmem and/or
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 234) 	 * end_vm are still 0 (as at startup), in which case we call free, or
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 235) 	 * we have set them, but anyway addr has not been allocated from those
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 236) 	 * areas. So, in both cases __real_free is called.
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 237) 	 *
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 238) 	 * CAN_KMALLOC is checked because it would be bad to free a buffer
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 239) 	 * with kmalloc/vmalloc after they have been turned off during
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 240) 	 * shutdown.
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 241) 	 * XXX: However, we sometimes shutdown CAN_KMALLOC temporarily, so
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 242) 	 * there is a possibility for memory leaks.
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 243) 	 */
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 244) 
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 245) 	if ((addr >= uml_physmem) && (addr < high_physmem)) {
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 246) 		if (kmalloc_ok)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 247) 			kfree(ptr);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 248) 	}
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 249) 	else if ((addr >= start_vm) && (addr < end_vm)) {
ba180fd437156 arch/um/os-Linux/main.c (Jeff Dike          2007-10-16 01:27:00 -0700 250) 		if (kmalloc_ok)
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 251) 			vfree(ptr);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 252) 	}
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 253) 	else __real_free(ptr);
^1da177e4c3f4 arch/um/kernel/main.c   (Linus Torvalds     2005-04-16 15:20:36 -0700 254) }