2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
13 #include <sys/utsname.h>
14 #include <sys/param.h>
16 #include "asm/types.h"
25 #include "user_util.h"
26 #include "kern_util.h"
31 #include "ptrace_user.h"
32 #include "uml-config.h"
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();
54 if(mprotect((void *) stack
, page_size(), prot
) < 0)
55 panic("protecting guard page failed, errno = %d", errno
);
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
;
69 CATCH_EINTR(ret
= waitpid(pid
, &status
, WUNTRACED
));
71 !WIFSTOPPED(status
) || (WSTOPSIG(status
) != sig
)){
73 printk("wait failed, errno = %d\n",
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
));
92 else if((relay_signals
!= NULL
) &&
93 sigismember(relay_signals
, WSTOPSIG(status
))){
94 ptrace(cont_type
, pid
, 0, WSTOPSIG(status
));
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
);
111 CATCH_EINTR(err
= tcgetattr(fd
, &tt
));
113 printk("tcgetattr failed, errno = %d\n", errno
);
119 CATCH_EINTR(err
= tcsetattr(fd
, TCSADRAIN
, &tt
));
121 printk("tcsetattr failed, errno = %d\n", errno
);
125 /* XXX tcsetattr could have applied only some changes
126 * (and cfmakeraw() is a set of changes) */
130 void setup_machinename(char *machine_out
)
135 strcpy(machine_out
, host
.machine
);
138 char host_info
[(_UTSNAME_LENGTH
+ 1) * 4 + _UTSNAME_NODENAME_LENGTH
+ 1];
140 void setup_hostinfo(void)
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 *), ...)
155 n
= sigsetjmp(buf
, 1);
157 va_start(args
, proc
);
158 (*proc
)(&buf
, &args
);
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
169 * ---------------------------------------------------------------------------
171 * c-file-style: "linux"