[NETFILTER]: PPTP conntrack: fix whitespace errors
[hh.org.git] / arch / um / os-Linux / util.c
blobc47a2a7ce70e75614e425e7270b2e1364188b67d
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 "ptrace_user.h"
31 #include "uml-config.h"
32 #include "os.h"
33 #include "longjmp.h"
35 void stack_protections(unsigned long address)
37 int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
39 if(mprotect((void *) address, page_size(), prot) < 0)
40 panic("protecting stack failed, errno = %d", errno);
43 void task_protections(unsigned long address)
45 unsigned long guard = address + page_size();
46 unsigned long stack = guard + page_size();
47 int prot = 0, pages;
49 #ifdef notdef
50 if(mprotect((void *) stack, page_size(), prot) < 0)
51 panic("protecting guard page failed, errno = %d", errno);
52 #endif
53 pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER) - 2;
54 prot = PROT_READ | PROT_WRITE | PROT_EXEC;
55 if(mprotect((void *) stack, pages * page_size(), prot) < 0)
56 panic("protecting stack failed, errno = %d", errno);
59 int raw(int fd)
61 struct termios tt;
62 int err;
64 CATCH_EINTR(err = tcgetattr(fd, &tt));
65 if(err < 0)
66 return -errno;
68 cfmakeraw(&tt);
70 CATCH_EINTR(err = tcsetattr(fd, TCSADRAIN, &tt));
71 if(err < 0)
72 return -errno;
74 /* XXX tcsetattr could have applied only some changes
75 * (and cfmakeraw() is a set of changes) */
76 return(0);
79 void setup_machinename(char *machine_out)
81 struct utsname host;
83 uname(&host);
84 #if defined(UML_CONFIG_UML_X86) && !defined(UML_CONFIG_64BIT)
85 if (!strcmp(host.machine, "x86_64")) {
86 strcpy(machine_out, "i686");
87 return;
89 #endif
90 strcpy(machine_out, host.machine);
93 char host_info[(_UTSNAME_LENGTH + 1) * 4 + _UTSNAME_NODENAME_LENGTH + 1];
95 void setup_hostinfo(void)
97 struct utsname host;
99 uname(&host);
100 sprintf(host_info, "%s %s %s %s %s", host.sysname, host.nodename,
101 host.release, host.version, host.machine);
104 int setjmp_wrapper(void (*proc)(void *, void *), ...)
106 va_list args;
107 jmp_buf buf;
108 int n;
110 n = sigsetjmp(buf, 1);
111 if(n == 0){
112 va_start(args, proc);
113 (*proc)(&buf, &args);
115 va_end(args);
116 return(n);