]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/um/os-Linux/util.c
uml: remove user_util.h
[karo-tx-linux.git] / arch / um / os-Linux / util.c
1 /*
2  * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <limits.h>
10 #include <sys/mman.h>
11 #include <sys/stat.h>
12 #include <sys/utsname.h>
13 #include <sys/param.h>
14 #include <sys/time.h>
15 #include "asm/types.h"
16 #include <ctype.h>
17 #include <signal.h>
18 #include <wait.h>
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <sched.h>
22 #include <termios.h>
23 #include <string.h>
24 #include "kern_util.h"
25 #include "user.h"
26 #include "mem_user.h"
27 #include "init.h"
28 #include "ptrace_user.h"
29 #include "uml-config.h"
30 #include "os.h"
31 #include "longjmp.h"
32
33 void stack_protections(unsigned long address)
34 {
35         int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
36
37         if(mprotect((void *) address, page_size(), prot) < 0)
38                 panic("protecting stack failed, errno = %d", errno);
39 }
40
41 void task_protections(unsigned long address)
42 {
43         unsigned long guard = address + page_size();
44         unsigned long stack = guard + page_size();
45         int prot = 0, pages;
46
47 #ifdef notdef
48         if(mprotect((void *) stack, page_size(), prot) < 0)
49                 panic("protecting guard page failed, errno = %d", errno);
50 #endif
51         pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER) - 2;
52         prot = PROT_READ | PROT_WRITE | PROT_EXEC;
53         if(mprotect((void *) stack, pages * page_size(), prot) < 0)
54                 panic("protecting stack failed, errno = %d", errno);
55 }
56
57 int raw(int fd)
58 {
59         struct termios tt;
60         int err;
61
62         CATCH_EINTR(err = tcgetattr(fd, &tt));
63         if(err < 0)
64                 return -errno;
65
66         cfmakeraw(&tt);
67
68         CATCH_EINTR(err = tcsetattr(fd, TCSADRAIN, &tt));
69         if(err < 0)
70                 return -errno;
71
72         /* XXX tcsetattr could have applied only some changes
73          * (and cfmakeraw() is a set of changes) */
74         return(0);
75 }
76
77 void setup_machinename(char *machine_out)
78 {
79         struct utsname host;
80
81         uname(&host);
82 #ifdef UML_CONFIG_UML_X86
83 # ifndef UML_CONFIG_64BIT
84         if (!strcmp(host.machine, "x86_64")) {
85                 strcpy(machine_out, "i686");
86                 return;
87         }
88 # else
89         if (!strcmp(host.machine, "i686")) {
90                 strcpy(machine_out, "x86_64");
91                 return;
92         }
93 # endif
94 #endif
95         strcpy(machine_out, host.machine);
96 }
97
98 void setup_hostinfo(char *buf, int len)
99 {
100         struct utsname host;
101
102         uname(&host);
103         snprintf(buf, len, "%s %s %s %s %s", host.sysname, host.nodename,
104                  host.release, host.version, host.machine);
105 }
106
107 int setjmp_wrapper(void (*proc)(void *, void *), ...)
108 {
109         va_list args;
110         jmp_buf buf;
111         int n;
112
113         n = UML_SETJMP(&buf);
114         if(n == 0){
115                 va_start(args, proc);
116                 (*proc)(&buf, &args);
117         }
118         va_end(args);
119         return n;
120 }