Pull context-bitmap into release branch
[pandora-kernel.git] / arch / um / include / os.h
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #ifndef __OS_H__
7 #define __OS_H__
8
9 #include "uml-config.h"
10 #include "asm/types.h"
11 #include "../os/include/file.h"
12
13 #define OS_TYPE_FILE 1 
14 #define OS_TYPE_DIR 2 
15 #define OS_TYPE_SYMLINK 3 
16 #define OS_TYPE_CHARDEV 4
17 #define OS_TYPE_BLOCKDEV 5
18 #define OS_TYPE_FIFO 6
19 #define OS_TYPE_SOCK 7
20
21 /* os_access() flags */
22 #define OS_ACC_F_OK    0       /* Test for existence.  */
23 #define OS_ACC_X_OK    1       /* Test for execute permission.  */
24 #define OS_ACC_W_OK    2       /* Test for write permission.  */
25 #define OS_ACC_R_OK    4       /* Test for read permission.  */
26 #define OS_ACC_RW_OK   (OS_ACC_W_OK | OS_ACC_R_OK) /* Test for RW permission */
27
28 /*
29  * types taken from stat_file() in hostfs_user.c
30  * (if they are wrong here, they are wrong there...).
31  */
32 struct uml_stat {
33         int                ust_dev;        /* device */
34         unsigned long long ust_ino;        /* inode */
35         int                ust_mode;       /* protection */
36         int                ust_nlink;      /* number of hard links */
37         int                ust_uid;        /* user ID of owner */
38         int                ust_gid;        /* group ID of owner */
39         unsigned long long ust_size;       /* total size, in bytes */
40         int                ust_blksize;    /* blocksize for filesystem I/O */
41         unsigned long long ust_blocks;     /* number of blocks allocated */
42         unsigned long      ust_atime;      /* time of last access */
43         unsigned long      ust_mtime;      /* time of last modification */
44         unsigned long      ust_ctime;      /* time of last change */
45 };
46
47 struct openflags {
48         unsigned int r : 1;
49         unsigned int w : 1;
50         unsigned int s : 1;     /* O_SYNC */
51         unsigned int c : 1;     /* O_CREAT */
52         unsigned int t : 1;     /* O_TRUNC */
53         unsigned int a : 1;     /* O_APPEND */
54         unsigned int e : 1;     /* O_EXCL */
55         unsigned int cl : 1;    /* FD_CLOEXEC */
56 };
57
58 #define OPENFLAGS() ((struct openflags) { .r = 0, .w = 0, .s = 0, .c = 0, \
59                                           .t = 0, .a = 0, .e = 0, .cl = 0 })
60
61 static inline struct openflags of_read(struct openflags flags)
62 {
63         flags.r = 1; 
64         return(flags);
65 }
66
67 static inline struct openflags of_write(struct openflags flags)
68 {
69         flags.w = 1; 
70         return(flags); 
71 }
72
73 static inline struct openflags of_rdwr(struct openflags flags)
74 {
75         return(of_read(of_write(flags)));
76 }
77
78 static inline struct openflags of_set_rw(struct openflags flags, int r, int w)
79 {
80         flags.r = r;
81         flags.w = w;
82         return(flags);
83 }
84
85 static inline struct openflags of_sync(struct openflags flags)
86
87         flags.s = 1; 
88         return(flags); 
89 }
90
91 static inline struct openflags of_create(struct openflags flags)
92
93         flags.c = 1; 
94         return(flags); 
95 }
96  
97 static inline struct openflags of_trunc(struct openflags flags)
98
99         flags.t = 1; 
100         return(flags); 
101 }
102  
103 static inline struct openflags of_append(struct openflags flags)
104
105         flags.a = 1; 
106         return(flags); 
107 }
108  
109 static inline struct openflags of_excl(struct openflags flags)
110
111         flags.e = 1; 
112         return(flags); 
113 }
114
115 static inline struct openflags of_cloexec(struct openflags flags)
116
117         flags.cl = 1; 
118         return(flags); 
119 }
120   
121 extern int os_stat_file(const char *file_name, struct uml_stat *buf);
122 extern int os_stat_fd(const int fd, struct uml_stat *buf);
123 extern int os_access(const char *file, int mode);
124 extern void os_print_error(int error, const char* str);
125 extern int os_get_exec_close(int fd, int *close_on_exec);
126 extern int os_set_exec_close(int fd, int close_on_exec);
127 extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg);
128 extern int os_window_size(int fd, int *rows, int *cols);
129 extern int os_new_tty_pgrp(int fd, int pid);
130 extern int os_get_ifname(int fd, char *namebuf);
131 extern int os_set_slip(int fd);
132 extern int os_set_owner(int fd, int pid);
133 extern int os_sigio_async(int master, int slave);
134 extern int os_mode_fd(int fd, int mode);
135
136 extern int os_seek_file(int fd, __u64 offset);
137 extern int os_open_file(char *file, struct openflags flags, int mode);
138 extern int os_read_file(int fd, void *buf, int len);
139 extern int os_write_file(int fd, const void *buf, int count);
140 extern int os_file_size(char *file, unsigned long long *size_out);
141 extern int os_file_modtime(char *file, unsigned long *modtime);
142 extern int os_pipe(int *fd, int stream, int close_on_exec);
143 extern int os_set_fd_async(int fd, int owner);
144 extern int os_clear_fd_async(int fd);
145 extern int os_set_fd_block(int fd, int blocking);
146 extern int os_accept_connection(int fd);
147 extern int os_create_unix_socket(char *file, int len, int close_on_exec);
148 extern int os_shutdown_socket(int fd, int r, int w);
149 extern void os_close_file(int fd);
150 extern int os_rcv_fd(int fd, int *helper_pid_out);
151 extern int create_unix_socket(char *file, int len, int close_on_exec);
152 extern int os_connect_socket(char *name);
153 extern int os_file_type(char *file);
154 extern int os_file_mode(char *file, struct openflags *mode_out);
155 extern int os_lock_file(int fd, int excl);
156
157 /* start_up.c */
158 extern void os_early_checks(void);
159 extern int can_do_skas(void);
160
161 /* Make sure they are clear when running in TT mode. Required by
162  * SEGV_MAYBE_FIXABLE */
163 #ifdef UML_CONFIG_MODE_SKAS
164 #define clear_can_do_skas() do { ptrace_faultinfo = proc_mm = 0; } while (0)
165 #else
166 #define clear_can_do_skas() do {} while (0)
167 #endif
168
169 /* mem.c */
170 extern int create_mem_file(unsigned long long len);
171
172 /* process.c */
173 extern unsigned long os_process_pc(int pid);
174 extern int os_process_parent(int pid);
175 extern void os_stop_process(int pid);
176 extern void os_kill_process(int pid, int reap_child);
177 extern void os_kill_ptraced_process(int pid, int reap_child);
178 extern void os_usr1_process(int pid);
179 extern int os_getpid(void);
180 extern int os_getpgrp(void);
181 extern void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int));
182 extern void init_new_thread_signals(int altstack);
183 extern int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr);
184
185 extern int os_map_memory(void *virt, int fd, unsigned long long off,
186                          unsigned long len, int r, int w, int x);
187 extern int os_protect_memory(void *addr, unsigned long len, 
188                              int r, int w, int x);
189 extern int os_unmap_memory(void *addr, int len);
190 extern void os_flush_stdout(void);
191 extern unsigned long long os_usecs(void);
192
193 /* tt.c
194  * for tt mode only (will be deleted in future...)
195  */
196 extern int protect_memory(unsigned long addr, unsigned long len,
197                           int r, int w, int x, int must_succeed);
198 extern void forward_pending_sigio(int target);
199 extern int start_fork_tramp(void *arg, unsigned long temp_stack,
200                             int clone_flags, int (*tramp)(void *));
201
202 /* uaccess.c */
203 extern unsigned long __do_user_copy(void *to, const void *from, int n,
204                                     void **fault_addr, void **fault_catcher,
205                                     void (*op)(void *to, const void *from,
206                                                int n), int *faulted_out);
207
208 /* helper.c */
209 extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
210                       unsigned long *stack_out);
211 extern int run_helper_thread(int (*proc)(void *), void *arg,
212                              unsigned int flags, unsigned long *stack_out,
213                              int stack_order);
214 extern int helper_wait(int pid);
215
216 #endif
217
218 /*
219  * Overrides for Emacs so that we follow Linus's tabbing style.
220  * Emacs will notice this stuff at the end of the file and automatically
221  * adjust the settings for this buffer only.  This must remain at the end
222  * of the file.
223  * ---------------------------------------------------------------------------
224  * Local variables:
225  * c-file-style: "linux"
226  * End:
227  */