2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
13 #include <sys/ptrace.h>
14 #include <sys/utsname.h>
15 #include <sys/param.h>
17 #include "asm/types.h"
26 #include "user_util.h"
27 #include "kern_util.h"
32 #include "uml-config.h"
34 #define COMMAND_LINE_SIZE _POSIX_ARG_MAX
36 /* Changed in linux_main and setup_arch, which run before SMP is started */
37 char command_line[COMMAND_LINE_SIZE] = { 0 };
39 void add_arg(char *cmd_line, char *arg)
41 if (strlen(cmd_line) + strlen(arg) + 1 > COMMAND_LINE_SIZE) {
42 printf("add_arg: Too much command line!\n");
45 if(strlen(cmd_line) > 0) strcat(cmd_line, " ");
46 strcat(cmd_line, arg);
51 while(1) sleep(1000000);
54 void stack_protections(unsigned long address)
56 int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
58 if(mprotect((void *) address, page_size(), prot) < 0)
59 panic("protecting stack failed, errno = %d", errno);
62 void task_protections(unsigned long address)
64 unsigned long guard = address + page_size();
65 unsigned long stack = guard + page_size();
69 if(mprotect((void *) stack, page_size(), prot) < 0)
70 panic("protecting guard page failed, errno = %d", errno);
72 pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER) - 2;
73 prot = PROT_READ | PROT_WRITE | PROT_EXEC;
74 if(mprotect((void *) stack, pages * page_size(), prot) < 0)
75 panic("protecting stack failed, errno = %d", errno);
78 int wait_for_stop(int pid, int sig, int cont_type, void *relay)
80 sigset_t *relay_signals = relay;
84 if(((ret = waitpid(pid, &status, WUNTRACED)) < 0) ||
85 !WIFSTOPPED(status) || (WSTOPSIG(status) != sig)){
87 if(errno == EINTR) continue;
88 printk("wait failed, errno = %d\n",
91 else if(WIFEXITED(status))
92 printk("process exited with status %d\n",
94 else if(WIFSIGNALED(status))
95 printk("process exited with signal %d\n",
97 else if((WSTOPSIG(status) == SIGVTALRM) ||
98 (WSTOPSIG(status) == SIGALRM) ||
99 (WSTOPSIG(status) == SIGIO) ||
100 (WSTOPSIG(status) == SIGPROF) ||
101 (WSTOPSIG(status) == SIGCHLD) ||
102 (WSTOPSIG(status) == SIGWINCH) ||
103 (WSTOPSIG(status) == SIGINT)){
104 ptrace(cont_type, pid, 0, WSTOPSIG(status));
107 else if((relay_signals != NULL) &&
108 sigismember(relay_signals, WSTOPSIG(status))){
109 ptrace(cont_type, pid, 0, WSTOPSIG(status));
112 else printk("process stopped with signal %d\n",
114 panic("wait_for_stop failed to wait for %d to stop "
115 "with %d\n", pid, sig);
121 int clone_and_wait(int (*fn)(void *), void *arg, void *sp, int flags)
125 pid = clone(fn, sp, flags, arg);
126 if(pid < 0) return(-1);
127 wait_for_stop(pid, SIGSTOP, PTRACE_CONT, NULL);
128 ptrace(PTRACE_CONT, pid, 0, 0);
132 int raw(int fd, int complain)
139 err = tcsetattr(fd, TCSANOW, &tt);
140 if((err < 0) && complain){
141 printk("tcsetattr failed, errno = %d\n", errno);
147 void setup_machinename(char *machine_out)
152 strcpy(machine_out, host.machine);
155 char host_info[(_UTSNAME_LENGTH + 1) * 4 + _UTSNAME_NODENAME_LENGTH + 1];
157 void setup_hostinfo(void)
162 sprintf(host_info, "%s %s %s %s %s", host.sysname, host.nodename,
163 host.release, host.version, host.machine);
167 * Overrides for Emacs so that we follow Linus's tabbing style.
168 * Emacs will notice this stuff at the end of the file and automatically
169 * adjust the settings for this buffer only. This must remain at the end
171 * ---------------------------------------------------------------------------
173 * c-file-style: "linux"