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/start_up.c (Alex Dewar         2019-08-25 10:49:18 +0100   1) // SPDX-License-Identifier: GPL-2.0
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700   2) /*
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700   3)  * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700   4)  */
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700   5) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700   6) #include <stdio.h>
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700   7) #include <stdlib.h>
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700   8) #include <stdarg.h>
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700   9) #include <unistd.h>
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  10) #include <errno.h>
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  11) #include <fcntl.h>
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  12) #include <sched.h>
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  13) #include <signal.h>
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  14) #include <string.h>
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  15) #include <sys/mman.h>
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  16) #include <sys/stat.h>
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  17) #include <sys/wait.h>
fdfa4c952844f arch/um/os-Linux/start_up.c (Sergei Trofimovich 2012-12-30 01:37:30 +0300  18) #include <sys/time.h>
fdfa4c952844f arch/um/os-Linux/start_up.c (Sergei Trofimovich 2012-12-30 01:37:30 +0300  19) #include <sys/resource.h>
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  20) #include <asm/unistd.h>
37185b3324087 arch/um/os-Linux/start_up.c (Al Viro            2012-10-08 03:27:32 +0100  21) #include <init.h>
37185b3324087 arch/um/os-Linux/start_up.c (Al Viro            2012-10-08 03:27:32 +0100  22) #include <os.h>
37185b3324087 arch/um/os-Linux/start_up.c (Al Viro            2012-10-08 03:27:32 +0100  23) #include <mem_user.h>
37185b3324087 arch/um/os-Linux/start_up.c (Al Viro            2012-10-08 03:27:32 +0100  24) #include <ptrace_user.h>
37185b3324087 arch/um/os-Linux/start_up.c (Al Viro            2012-10-08 03:27:32 +0100  25) #include <registers.h>
37185b3324087 arch/um/os-Linux/start_up.c (Al Viro            2012-10-08 03:27:32 +0100  26) #include <skas.h>
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  27) 
626c59f5edb28 arch/um/os-Linux/start_up.c (WANG Cong          2008-04-28 02:13:53 -0700  28) static void ptrace_child(void)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  29) {
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  30) 	int ret;
512b6fb1c14d4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:11 -0700  31) 	/* Calling os_getpid because some libcs cached getpid incorrectly */
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  32) 	int pid = os_getpid(), ppid = getppid();
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  33) 	int sc_result;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  34) 
626c59f5edb28 arch/um/os-Linux/start_up.c (WANG Cong          2008-04-28 02:13:53 -0700  35) 	if (change_sig(SIGWINCH, 0) < 0 ||
626c59f5edb28 arch/um/os-Linux/start_up.c (WANG Cong          2008-04-28 02:13:53 -0700  36) 	    ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  37) 		perror("ptrace");
512b6fb1c14d4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:11 -0700  38) 		kill(pid, SIGKILL);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  39) 	}
73c8f4441f07d arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800  40) 	kill(pid, SIGSTOP);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  41) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  42) 	/*
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  43) 	 * This syscall will be intercepted by the parent. Don't call more than
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  44) 	 * once, please.
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  45) 	 */
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  46) 	sc_result = os_getpid();
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  47) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  48) 	if (sc_result == pid)
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  49) 		/* Nothing modified by the parent, we are running normally. */
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  50) 		ret = 1;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  51) 	else if (sc_result == ppid)
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  52) 		/*
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  53) 		 * Expected in check_ptrace and check_sysemu when they succeed
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  54) 		 * in modifying the stack frame
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  55) 		 */
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  56) 		ret = 0;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  57) 	else
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  58) 		/* Serious trouble! This could be caused by a bug in host 2.6
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  59) 		 * SKAS3/2.6 patch before release -V6, together with a bug in
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  60) 		 * the UML code itself.
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  61) 		 */
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700  62) 		ret = 2;
bf8fde785b872 arch/um/os-Linux/start_up.c (Jeff Dike          2008-02-04 22:31:04 -0800  63) 
bf8fde785b872 arch/um/os-Linux/start_up.c (Jeff Dike          2008-02-04 22:31:04 -0800  64) 	exit(ret);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  65) }
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  66) 
c9a3072d13e4b arch/um/os-Linux/start_up.c (WANG Cong          2008-02-04 22:30:35 -0800  67) static void fatal_perror(const char *str)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  68) {
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  69) 	perror(str);
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  70) 	exit(1);
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  71) }
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  72) 
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  73) static void fatal(char *fmt, ...)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  74) {
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  75) 	va_list list;
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  76) 
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  77) 	va_start(list, fmt);
626c59f5edb28 arch/um/os-Linux/start_up.c (WANG Cong          2008-04-28 02:13:53 -0700  78) 	vfprintf(stderr, fmt, list);
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  79) 	va_end(list);
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  80) 
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  81) 	exit(1);
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  82) }
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  83) 
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  84) static void non_fatal(char *fmt, ...)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  85) {
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  86) 	va_list list;
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  87) 
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  88) 	va_start(list, fmt);
626c59f5edb28 arch/um/os-Linux/start_up.c (WANG Cong          2008-04-28 02:13:53 -0700  89) 	vfprintf(stderr, fmt, list);
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  90) 	va_end(list);
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  91) }
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800  92) 
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700  93) static int start_ptraced_child(void)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  94) {
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700  95) 	int pid, n, status;
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700  96) 
0754fb298f2f2 arch/um/os-Linux/start_up.c (Vegard Nossum      2015-12-18 21:28:53 +0100  97) 	fflush(stdout);
0754fb298f2f2 arch/um/os-Linux/start_up.c (Vegard Nossum      2015-12-18 21:28:53 +0100  98) 
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700  99) 	pid = fork();
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 100) 	if (pid == 0)
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 101) 		ptrace_child();
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 102) 	else if (pid < 0)
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 103) 		fatal_perror("start_ptraced_child : fork failed");
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 104) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 105) 	CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 106) 	if (n < 0)
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 107) 		fatal_perror("check_ptrace : waitpid failed");
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 108) 	if (!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP))
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 109) 		fatal("check_ptrace : expected SIGSTOP, got status = %d",
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 110) 		      status);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 111) 
9eae9b132cd2c arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 112) 	return pid;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 113) }
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 114) 
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 115) /* When testing for SYSEMU support, if it is one of the broken versions, we
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 116)  * must just avoid using sysemu, not panic, but only if SYSEMU features are
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 117)  * broken.
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 118)  * So only for SYSEMU features we test mustpanic, while normal host features
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 119)  * must work anyway!
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 120)  */
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 121) static int stop_ptraced_child(int pid, int exitcode, int mustexit)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 122) {
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 123) 	int status, n, ret = 0;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 124) 
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 125) 	if (ptrace(PTRACE_CONT, pid, 0, 0) < 0) {
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 126) 		perror("stop_ptraced_child : ptrace failed");
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 127) 		return -1;
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 128) 	}
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 129) 	CATCH_EINTR(n = waitpid(pid, &status, 0));
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 130) 	if (!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) {
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 131) 		int exit_with = WEXITSTATUS(status);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 132) 		if (exit_with == 2)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 133) 			non_fatal("check_ptrace : child exited with status 2. "
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 134) 				  "\nDisabling SYSEMU support.\n");
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 135) 		non_fatal("check_ptrace : child exited with exitcode %d, while "
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 136) 			  "expecting %d; status 0x%x\n", exit_with,
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 137) 			  exitcode, status);
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 138) 		if (mustexit)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 139) 			exit(1);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 140) 		ret = -1;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 141) 	}
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 142) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 143) 	return ret;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 144) }
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 145) 
7242a4005d1c4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:19 -0800 146) /* Changed only during early boot */
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 147) static int force_sysemu_disabled = 0;
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 148) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 149) static int __init nosysemu_cmd_param(char *str, int* add)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 150) {
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 151) 	force_sysemu_disabled = 1;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 152) 	return 0;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 153) }
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 154) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 155) __uml_setup("nosysemu", nosysemu_cmd_param,
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 156) "nosysemu\n"
cbb0006def57d arch/um/os-Linux/start_up.c (James Pack         2017-08-08 13:19:41 -0700 157) "    Turns off syscall emulation patch for ptrace (SYSEMU).\n"
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 158) "    SYSEMU is a performance-patch introduced by Laurent Vivier. It changes\n"
cbb0006def57d arch/um/os-Linux/start_up.c (James Pack         2017-08-08 13:19:41 -0700 159) "    behaviour of ptrace() and helps reduce host context switch rates.\n"
cbb0006def57d arch/um/os-Linux/start_up.c (James Pack         2017-08-08 13:19:41 -0700 160) "    To make it work, you need a kernel patch for your host, too.\n"
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 161) "    See http://perso.wanadoo.fr/laurent.vivier/UML/ for further \n"
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 162) "    information.\n\n");
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 163) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 164) static void __init check_sysemu(void)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 165) {
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 166) 	unsigned long regs[MAX_REG_NR];
9eae9b132cd2c arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 167) 	int pid, n, status, count=0;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 168) 
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 169) 	os_info("Checking syscall emulation patch for ptrace...");
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 170) 	sysemu_supported = 0;
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 171) 	pid = start_ptraced_child();
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 172) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 173) 	if (ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 174) 		goto fail;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 175) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 176) 	CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 177) 	if (n < 0)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 178) 		fatal_perror("check_sysemu : wait failed");
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 179) 	if (!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP))
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 180) 		fatal("check_sysemu : expected SIGTRAP, got status = %d\n",
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 181) 		      status);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 182) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 183) 	if (ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 184) 		fatal_perror("check_sysemu : PTRACE_GETREGS failed");
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 185) 	if (PT_SYSCALL_NR(regs) != __NR_getpid) {
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 186) 		non_fatal("check_sysemu got system call number %d, "
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 187) 			  "expected %d...", PT_SYSCALL_NR(regs), __NR_getpid);
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 188) 		goto fail;
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 189) 	}
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 190) 
966e803ab1253 arch/um/os-Linux/start_up.c (Al Viro            2011-08-18 20:12:19 +0100 191) 	n = ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_RET_OFFSET, os_getpid());
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 192) 	if (n < 0) {
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 193) 		non_fatal("check_sysemu : failed to modify system call "
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 194) 			  "return");
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 195) 		goto fail;
cf6acedbeac17 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-23 13:57:40 -0700 196) 	}
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 197) 
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 198) 	if (stop_ptraced_child(pid, 0, 0) < 0)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 199) 		goto fail_stopped;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 200) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 201) 	sysemu_supported = 1;
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 202) 	os_info("OK\n");
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 203) 	set_using_sysemu(!force_sysemu_disabled);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 204) 
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 205) 	os_info("Checking advanced syscall emulation patch for ptrace...");
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 206) 	pid = start_ptraced_child();
f9dfefe423a76 arch/um/os-Linux/start_up.c (Bodo Stroesser     2005-09-03 15:57:51 -0700 207) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 208) 	if ((ptrace(PTRACE_OLDSETOPTIONS, pid, 0,
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 209) 		   (void *) PTRACE_O_TRACESYSGOOD) < 0))
5062910a06ee9 arch/um/os-Linux/start_up.c (WANG Cong          2009-03-31 15:23:41 -0700 210) 		fatal_perror("check_sysemu: PTRACE_OLDSETOPTIONS failed");
f9dfefe423a76 arch/um/os-Linux/start_up.c (Bodo Stroesser     2005-09-03 15:57:51 -0700 211) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 212) 	while (1) {
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 213) 		count++;
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 214) 		if (ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 215) 			goto fail;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 216) 		CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 217) 		if (n < 0)
5062910a06ee9 arch/um/os-Linux/start_up.c (WANG Cong          2009-03-31 15:23:41 -0700 218) 			fatal_perror("check_sysemu: wait failed");
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 219) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 220) 		if (WIFSTOPPED(status) &&
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 221) 		    (WSTOPSIG(status) == (SIGTRAP|0x80))) {
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 222) 			if (!count) {
5062910a06ee9 arch/um/os-Linux/start_up.c (WANG Cong          2009-03-31 15:23:41 -0700 223) 				non_fatal("check_sysemu: SYSEMU_SINGLESTEP "
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 224) 					  "doesn't singlestep");
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 225) 				goto fail;
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 226) 			}
966e803ab1253 arch/um/os-Linux/start_up.c (Al Viro            2011-08-18 20:12:19 +0100 227) 			n = ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_RET_OFFSET,
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 228) 				   os_getpid());
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 229) 			if (n < 0)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 230) 				fatal_perror("check_sysemu : failed to modify "
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 231) 					     "system call return");
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 232) 			break;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 233) 		}
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 234) 		else if (WIFSTOPPED(status) && (WSTOPSIG(status) == SIGTRAP))
f9dfefe423a76 arch/um/os-Linux/start_up.c (Bodo Stroesser     2005-09-03 15:57:51 -0700 235) 			count++;
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 236) 		else {
5062910a06ee9 arch/um/os-Linux/start_up.c (WANG Cong          2009-03-31 15:23:41 -0700 237) 			non_fatal("check_sysemu: expected SIGTRAP or "
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 238) 				  "(SIGTRAP | 0x80), got status = %d\n",
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 239) 				  status);
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 240) 			goto fail;
f1ef9167ca449 arch/um/os-Linux/start_up.c (Jeff Dike          2008-06-12 15:21:41 -0700 241) 		}
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 242) 	}
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 243) 	if (stop_ptraced_child(pid, 0, 0) < 0)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 244) 		goto fail_stopped;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 245) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 246) 	sysemu_supported = 2;
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 247) 	os_info("OK\n");
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 248) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 249) 	if (!force_sysemu_disabled)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 250) 		set_using_sysemu(sysemu_supported);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 251) 	return;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 252) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 253) fail:
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 254) 	stop_ptraced_child(pid, 1, 0);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 255) fail_stopped:
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 256) 	non_fatal("missing\n");
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 257) }
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 258) 
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 259) static void __init check_ptrace(void)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 260) {
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 261) 	int pid, syscall, n, status;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 262) 
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 263) 	os_info("Checking that ptrace can change system call numbers...");
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 264) 	pid = start_ptraced_child();
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 265) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 266) 	if ((ptrace(PTRACE_OLDSETOPTIONS, pid, 0,
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 267) 		   (void *) PTRACE_O_TRACESYSGOOD) < 0))
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 268) 		fatal_perror("check_ptrace: PTRACE_OLDSETOPTIONS failed");
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 269) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 270) 	while (1) {
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 271) 		if (ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 272) 			fatal_perror("check_ptrace : ptrace failed");
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 273) 
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 274) 		CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 275) 		if (n < 0)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 276) 			fatal_perror("check_ptrace : wait failed");
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 277) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 278) 		if (!WIFSTOPPED(status) ||
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 279) 		   (WSTOPSIG(status) != (SIGTRAP | 0x80)))
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 280) 			fatal("check_ptrace : expected (SIGTRAP|0x80), "
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 281) 			       "got status = %d", status);
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 282) 
966e803ab1253 arch/um/os-Linux/start_up.c (Al Viro            2011-08-18 20:12:19 +0100 283) 		syscall = ptrace(PTRACE_PEEKUSER, pid, PT_SYSCALL_NR_OFFSET,
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 284) 				 0);
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 285) 		if (syscall == __NR_getpid) {
966e803ab1253 arch/um/os-Linux/start_up.c (Al Viro            2011-08-18 20:12:19 +0100 286) 			n = ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET,
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 287) 				   __NR_getppid);
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 288) 			if (n < 0)
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 289) 				fatal_perror("check_ptrace : failed to modify "
3a150e1da8bc4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:28 -0800 290) 					     "system call");
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 291) 			break;
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 292) 		}
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 293) 	}
3cdaf45578b9a arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:09 -0700 294) 	stop_ptraced_child(pid, 0, 1);
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 295) 	os_info("OK\n");
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 296) 	check_sysemu();
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 297) }
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 298) 
966a082f80a07 arch/um/os-Linux/start_up.c (Rob Landley        2006-04-18 22:21:43 -0700 299) extern void check_tmpexec(void);
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 300) 
36e454630473c arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:11 -0700 301) static void __init check_coredump_limit(void)
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 302) {
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 303) 	struct rlimit lim;
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 304) 	int err = getrlimit(RLIMIT_CORE, &lim);
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 305) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 306) 	if (err) {
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 307) 		perror("Getting core dump limit");
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 308) 		return;
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 309) 	}
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 310) 
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 311) 	os_info("Core dump limits :\n\tsoft - ");
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 312) 	if (lim.rlim_cur == RLIM_INFINITY)
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 313) 		os_info("NONE\n");
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 314) 	else
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 315) 		os_info("%llu\n", (unsigned long long)lim.rlim_cur);
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 316) 
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 317) 	os_info("\thard - ");
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 318) 	if (lim.rlim_max == RLIM_INFINITY)
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 319) 		os_info("NONE\n");
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 320) 	else
d3878bb800300 arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:17:14 +0900 321) 		os_info("%llu\n", (unsigned long long)lim.rlim_max);
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 322) }
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 323) 
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 324) void  __init get_host_cpu_features(
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 325) 		void (*flags_helper_func)(char *line),
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 326) 		void (*cache_helper_func)(char *line))
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 327) {
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 328) 	FILE *cpuinfo;
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 329) 	char *line = NULL;
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 330) 	size_t len = 0;
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 331) 	int done_parsing = 0;
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 332) 
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 333) 	cpuinfo = fopen("/proc/cpuinfo", "r");
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 334) 	if (cpuinfo == NULL) {
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 335) 		os_info("Failed to get host CPU features\n");
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 336) 	} else {
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 337) 		while ((getline(&line, &len, cpuinfo)) != -1) {
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 338) 			if (strstr(line, "flags")) {
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 339) 				flags_helper_func(line);
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 340) 				done_parsing++;
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 341) 			}
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 342) 			if (strstr(line, "cache_alignment")) {
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 343) 				cache_helper_func(line);
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 344) 				done_parsing++;
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 345) 			}
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 346) 			free(line);
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 347) 			line = NULL;
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 348) 			if (done_parsing > 1)
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 349) 				break;
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 350) 		}
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 351) 		fclose(cpuinfo);
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 352) 	}
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 353) }
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 354) 
d8fb32f4790f2 arch/um/os-Linux/start_up.c (Anton Ivanov       2021-03-12 15:16:07 +0000 355) 
36e454630473c arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:11 -0700 356) void __init os_early_checks(void)
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 357) {
576c013df0ac9 arch/um/os-Linux/start_up.c (Jeff Dike          2008-02-04 22:31:22 -0800 358) 	int pid;
576c013df0ac9 arch/um/os-Linux/start_up.c (Jeff Dike          2008-02-04 22:31:22 -0800 359) 
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 360) 	/* Print out the core dump limits early */
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 361) 	check_coredump_limit();
1d94cda04eb82 arch/um/os-Linux/start_up.c (Jeff Dike          2007-05-06 14:51:00 -0700 362) 
60d339f6fe083 arch/um/os-Linux/start_up.c (Gennady Sharapov   2005-09-03 15:57:47 -0700 363) 	check_ptrace();
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 364) 
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 365) 	/* Need to check this early because mmapping happens before the
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 366) 	 * kernel is running.
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 367) 	 */
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 368) 	check_tmpexec();
576c013df0ac9 arch/um/os-Linux/start_up.c (Jeff Dike          2008-02-04 22:31:22 -0800 369) 
576c013df0ac9 arch/um/os-Linux/start_up.c (Jeff Dike          2008-02-04 22:31:22 -0800 370) 	pid = start_ptraced_child();
576c013df0ac9 arch/um/os-Linux/start_up.c (Jeff Dike          2008-02-04 22:31:22 -0800 371) 	if (init_registers(pid))
576c013df0ac9 arch/um/os-Linux/start_up.c (Jeff Dike          2008-02-04 22:31:22 -0800 372) 		fatal("Failed to initialize default registers");
576c013df0ac9 arch/um/os-Linux/start_up.c (Jeff Dike          2008-02-04 22:31:22 -0800 373) 	stop_ptraced_child(pid, 1, 1);
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 374) }
^1da177e4c3f4 arch/um/kernel/process.c    (Linus Torvalds     2005-04-16 15:20:36 -0700 375) 
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 376) int __init parse_iomem(char *str, int *add)
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 377) {
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 378) 	struct iomem_region *new;
73c8f4441f07d arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 379) 	struct stat64 buf;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 380) 	char *file, *driver;
73c8f4441f07d arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 381) 	int fd, size;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 382) 
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 383) 	driver = str;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 384) 	file = strchr(str,',');
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 385) 	if (file == NULL) {
0936d4f3d5a3d arch/um/os-Linux/start_up.c (Masami Hiramatsu   2017-05-18 02:19:31 +0900 386) 		os_warn("parse_iomem : failed to parse iomem\n");
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 387) 		goto out;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 388) 	}
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 389) 	*file = '\0';
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 390) 	file++;
73c8f4441f07d arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 391) 	fd = open(file, O_RDWR, 0);
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 392) 	if (fd < 0) {
512b6fb1c14d4 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:11 -0700 393) 		perror("parse_iomem - Couldn't open io file");
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 394) 		goto out;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 395) 	}
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 396) 
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 397) 	if (fstat64(fd, &buf) < 0) {
73c8f4441f07d arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 398) 		perror("parse_iomem - cannot stat_fd file");
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 399) 		goto out_close;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 400) 	}
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 401) 
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 402) 	new = malloc(sizeof(*new));
ba180fd437156 arch/um/os-Linux/start_up.c (Jeff Dike          2007-10-16 01:27:00 -0700 403) 	if (new == NULL) {
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 404) 		perror("Couldn't allocate iomem_region struct");
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 405) 		goto out_close;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 406) 	}
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 407) 
73c8f4441f07d arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 408) 	size = (buf.st_size + UM_KERN_PAGE_SIZE) & ~(UM_KERN_PAGE_SIZE - 1);
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 409) 
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 410) 	*new = ((struct iomem_region) { .next		= iomem_regions,
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 411) 					.driver		= driver,
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 412) 					.fd		= fd,
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 413) 					.size		= size,
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 414) 					.phys		= 0,
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 415) 					.virt		= 0 });
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 416) 	iomem_regions = new;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 417) 	iomem_size += new->size + UM_KERN_PAGE_SIZE;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 418) 
9eae9b132cd2c arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 419) 	return 0;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 420)  out_close:
73c8f4441f07d arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 421) 	close(fd);
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 422)  out:
9eae9b132cd2c arch/um/os-Linux/start_up.c (Jeff Dike          2007-02-10 01:44:20 -0800 423) 	return 1;
0f80bc85c587e arch/um/os-Linux/start_up.c (Jeff Dike          2005-09-16 19:27:50 -0700 424) }