[NETLINK]: w1_int.c: fix default netlink group
[linux-2.6/verdex.git] / arch / um / kernel / user_util.c
blob954ff67cc8b3ec9f701fea22eb9182f07869edcd
1 /*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <limits.h>
10 #include <setjmp.h>
11 #include <sys/mman.h>
12 #include <sys/stat.h>
13 #include <sys/utsname.h>
14 #include <sys/param.h>
15 #include <sys/time.h>
16 #include "asm/types.h"
17 #include <ctype.h>
18 #include <signal.h>
19 #include <wait.h>
20 #include <errno.h>
21 #include <stdarg.h>
22 #include <sched.h>
23 #include <termios.h>
24 #include <string.h>
25 #include "user_util.h"
26 #include "kern_util.h"
27 #include "user.h"
28 #include "mem_user.h"
29 #include "init.h"
30 #include "helper.h"
31 #include "ptrace_user.h"
32 #include "uml-config.h"
34 void stop(void)
36 while(1) sleep(1000000);
39 void stack_protections(unsigned long address)
41 int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
43 if(mprotect((void *) address, page_size(), prot) < 0)
44 panic("protecting stack failed, errno = %d", errno);
47 void task_protections(unsigned long address)
49 unsigned long guard = address + page_size();
50 unsigned long stack = guard + page_size();
51 int prot = 0, pages;
53 #ifdef notdef
54 if(mprotect((void *) stack, page_size(), prot) < 0)
55 panic("protecting guard page failed, errno = %d", errno);
56 #endif
57 pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER) - 2;
58 prot = PROT_READ | PROT_WRITE | PROT_EXEC;
59 if(mprotect((void *) stack, pages * page_size(), prot) < 0)
60 panic("protecting stack failed, errno = %d", errno);
63 int wait_for_stop(int pid, int sig, int cont_type, void *relay)
65 sigset_t *relay_signals = relay;
66 int status, ret;
68 while(1){
69 CATCH_EINTR(ret = waitpid(pid, &status, WUNTRACED));
70 if((ret < 0) ||
71 !WIFSTOPPED(status) || (WSTOPSIG(status) != sig)){
72 if(ret < 0){
73 printk("wait failed, errno = %d\n",
74 errno);
76 else if(WIFEXITED(status))
77 printk("process %d exited with status %d\n",
78 pid, WEXITSTATUS(status));
79 else if(WIFSIGNALED(status))
80 printk("process %d exited with signal %d\n",
81 pid, WTERMSIG(status));
82 else if((WSTOPSIG(status) == SIGVTALRM) ||
83 (WSTOPSIG(status) == SIGALRM) ||
84 (WSTOPSIG(status) == SIGIO) ||
85 (WSTOPSIG(status) == SIGPROF) ||
86 (WSTOPSIG(status) == SIGCHLD) ||
87 (WSTOPSIG(status) == SIGWINCH) ||
88 (WSTOPSIG(status) == SIGINT)){
89 ptrace(cont_type, pid, 0, WSTOPSIG(status));
90 continue;
92 else if((relay_signals != NULL) &&
93 sigismember(relay_signals, WSTOPSIG(status))){
94 ptrace(cont_type, pid, 0, WSTOPSIG(status));
95 continue;
97 else printk("process %d stopped with signal %d\n",
98 pid, WSTOPSIG(status));
99 panic("wait_for_stop failed to wait for %d to stop "
100 "with %d\n", pid, sig);
102 return(status);
106 int raw(int fd)
108 struct termios tt;
109 int err;
111 CATCH_EINTR(err = tcgetattr(fd, &tt));
112 if (err < 0) {
113 printk("tcgetattr failed, errno = %d\n", errno);
114 return(-errno);
117 cfmakeraw(&tt);
119 CATCH_EINTR(err = tcsetattr(fd, TCSADRAIN, &tt));
120 if (err < 0) {
121 printk("tcsetattr failed, errno = %d\n", errno);
122 return(-errno);
125 /* XXX tcsetattr could have applied only some changes
126 * (and cfmakeraw() is a set of changes) */
127 return(0);
130 void setup_machinename(char *machine_out)
132 struct utsname host;
134 uname(&host);
135 strcpy(machine_out, host.machine);
138 char host_info[(_UTSNAME_LENGTH + 1) * 4 + _UTSNAME_NODENAME_LENGTH + 1];
140 void setup_hostinfo(void)
142 struct utsname host;
144 uname(&host);
145 sprintf(host_info, "%s %s %s %s %s", host.sysname, host.nodename,
146 host.release, host.version, host.machine);
149 int setjmp_wrapper(void (*proc)(void *, void *), ...)
151 va_list args;
152 sigjmp_buf buf;
153 int n;
155 n = sigsetjmp(buf, 1);
156 if(n == 0){
157 va_start(args, proc);
158 (*proc)(&buf, &args);
160 va_end(args);
161 return(n);
165 * Overrides for Emacs so that we follow Linus's tabbing style.
166 * Emacs will notice this stuff at the end of the file and automatically
167 * adjust the settings for this buffer only. This must remain at the end
168 * of the file.
169 * ---------------------------------------------------------------------------
170 * Local variables:
171 * c-file-style: "linux"
172 * End: