uml: code tidying under arch/um/os-Linux
[linux-2.6-block.git] / arch / um / include / os.h
CommitLineData
329c6e42 1/*
ba180fd4 2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
1da177e4
LT
3 * Licensed under the GPL
4 */
5
6#ifndef __OS_H__
7#define __OS_H__
8
ba180fd4 9#include <stdarg.h>
63ae2a94 10#include "irq_user.h"
ba180fd4
JD
11#include "kern_util.h"
12#include "longjmp.h"
13#include "mm_id.h"
dd77aec0 14#include "sysdep/tls.h"
ba180fd4 15#include "../os/include/file.h"
1da177e4 16
24fa6c08
JD
17#define CATCH_EINTR(expr) while ((errno = 0, ((expr) < 0)) && (errno == EINTR))
18
329c6e42
JD
19#define OS_TYPE_FILE 1
20#define OS_TYPE_DIR 2
21#define OS_TYPE_SYMLINK 3
1da177e4
LT
22#define OS_TYPE_CHARDEV 4
23#define OS_TYPE_BLOCKDEV 5
24#define OS_TYPE_FIFO 6
25#define OS_TYPE_SOCK 7
26
27/* os_access() flags */
28#define OS_ACC_F_OK 0 /* Test for existence. */
29#define OS_ACC_X_OK 1 /* Test for execute permission. */
30#define OS_ACC_W_OK 2 /* Test for write permission. */
31#define OS_ACC_R_OK 4 /* Test for read permission. */
32#define OS_ACC_RW_OK (OS_ACC_W_OK | OS_ACC_R_OK) /* Test for RW permission */
33
34/*
35 * types taken from stat_file() in hostfs_user.c
36 * (if they are wrong here, they are wrong there...).
37 */
38struct uml_stat {
39 int ust_dev; /* device */
40 unsigned long long ust_ino; /* inode */
41 int ust_mode; /* protection */
42 int ust_nlink; /* number of hard links */
43 int ust_uid; /* user ID of owner */
44 int ust_gid; /* group ID of owner */
45 unsigned long long ust_size; /* total size, in bytes */
46 int ust_blksize; /* blocksize for filesystem I/O */
47 unsigned long long ust_blocks; /* number of blocks allocated */
48 unsigned long ust_atime; /* time of last access */
49 unsigned long ust_mtime; /* time of last modification */
50 unsigned long ust_ctime; /* time of last change */
51};
52
53struct openflags {
54 unsigned int r : 1;
55 unsigned int w : 1;
56 unsigned int s : 1; /* O_SYNC */
57 unsigned int c : 1; /* O_CREAT */
58 unsigned int t : 1; /* O_TRUNC */
59 unsigned int a : 1; /* O_APPEND */
60 unsigned int e : 1; /* O_EXCL */
61 unsigned int cl : 1; /* FD_CLOEXEC */
62};
63
64#define OPENFLAGS() ((struct openflags) { .r = 0, .w = 0, .s = 0, .c = 0, \
329c6e42 65 .t = 0, .a = 0, .e = 0, .cl = 0 })
1da177e4
LT
66
67static inline struct openflags of_read(struct openflags flags)
68{
329c6e42
JD
69 flags.r = 1;
70 return flags;
1da177e4
LT
71}
72
73static inline struct openflags of_write(struct openflags flags)
74{
329c6e42
JD
75 flags.w = 1;
76 return flags;
1da177e4
LT
77}
78
79static inline struct openflags of_rdwr(struct openflags flags)
80{
329c6e42 81 return of_read(of_write(flags));
1da177e4
LT
82}
83
84static inline struct openflags of_set_rw(struct openflags flags, int r, int w)
85{
86 flags.r = r;
87 flags.w = w;
329c6e42 88 return flags;
1da177e4
LT
89}
90
91static inline struct openflags of_sync(struct openflags flags)
329c6e42
JD
92{
93 flags.s = 1;
94 return flags;
1da177e4
LT
95}
96
97static inline struct openflags of_create(struct openflags flags)
329c6e42
JD
98{
99 flags.c = 1;
100 return flags;
1da177e4 101}
329c6e42 102
1da177e4 103static inline struct openflags of_trunc(struct openflags flags)
329c6e42
JD
104{
105 flags.t = 1;
106 return flags;
1da177e4 107}
329c6e42 108
1da177e4 109static inline struct openflags of_append(struct openflags flags)
329c6e42
JD
110{
111 flags.a = 1;
112 return flags;
1da177e4 113}
329c6e42 114
1da177e4 115static inline struct openflags of_excl(struct openflags flags)
329c6e42
JD
116{
117 flags.e = 1;
118 return flags;
1da177e4
LT
119}
120
121static inline struct openflags of_cloexec(struct openflags flags)
329c6e42
JD
122{
123 flags.cl = 1;
124 return flags;
1da177e4 125}
329c6e42 126
cf9165a5 127/* file.c */
1da177e4
LT
128extern int os_stat_file(const char *file_name, struct uml_stat *buf);
129extern int os_stat_fd(const int fd, struct uml_stat *buf);
130extern int os_access(const char *file, int mode);
1da177e4 131extern int os_get_exec_close(int fd, int *close_on_exec);
512b6fb1 132extern int os_set_exec_close(int fd);
1da177e4 133extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg);
1da177e4
LT
134extern int os_get_ifname(int fd, char *namebuf);
135extern int os_set_slip(int fd);
136extern int os_set_owner(int fd, int pid);
1da177e4
LT
137extern int os_mode_fd(int fd, int mode);
138
ba180fd4 139extern int os_seek_file(int fd, unsigned long long offset);
c9a3072d 140extern int os_open_file(const char *file, struct openflags flags, int mode);
1da177e4
LT
141extern int os_read_file(int fd, void *buf, int len);
142extern int os_write_file(int fd, const void *buf, int count);
c9a3072d
WC
143extern int os_file_size(const char *file, unsigned long long *size_out);
144extern int os_file_modtime(const char *file, unsigned long *modtime);
1da177e4
LT
145extern int os_pipe(int *fd, int stream, int close_on_exec);
146extern int os_set_fd_async(int fd, int owner);
147extern int os_clear_fd_async(int fd);
148extern int os_set_fd_block(int fd, int blocking);
149extern int os_accept_connection(int fd);
c9a3072d 150extern int os_create_unix_socket(const char *file, int len, int close_on_exec);
1da177e4
LT
151extern int os_shutdown_socket(int fd, int r, int w);
152extern void os_close_file(int fd);
153extern int os_rcv_fd(int fd, int *helper_pid_out);
154extern int create_unix_socket(char *file, int len, int close_on_exec);
c9a3072d 155extern int os_connect_socket(const char *name);
1da177e4 156extern int os_file_type(char *file);
c9a3072d 157extern int os_file_mode(const char *file, struct openflags *mode_out);
1da177e4 158extern int os_lock_file(int fd, int excl);
cf9165a5
JD
159extern void os_flush_stdout(void);
160extern int os_stat_filesystem(char *path, long *bsize_out,
161 long long *blocks_out, long long *bfree_out,
162 long long *bavail_out, long long *files_out,
163 long long *ffree_out, void *fsid_out,
164 int fsid_size, long *namelen_out,
165 long *spare_out);
166extern int os_change_dir(char *dir);
167extern int os_fchange_dir(int fd);
1da177e4 168
60d339f6
GS
169/* start_up.c */
170extern void os_early_checks(void);
171extern int can_do_skas(void);
8e367065 172extern void os_check_bugs(void);
3feb8856 173extern void check_host_supports_tls(int *supports_tls, int *tls_min);
60d339f6 174
8923648c
PBG
175/* Make sure they are clear when running in TT mode. Required by
176 * SEGV_MAYBE_FIXABLE */
177#define clear_can_do_skas() do { ptrace_faultinfo = proc_mm = 0; } while (0)
178
0f80bc85 179/* mem.c */
ae173816 180extern int create_mem_file(unsigned long long len);
0f80bc85 181
60d339f6 182/* process.c */
1da177e4
LT
183extern unsigned long os_process_pc(int pid);
184extern int os_process_parent(int pid);
185extern void os_stop_process(int pid);
186extern void os_kill_process(int pid, int reap_child);
187extern void os_kill_ptraced_process(int pid, int reap_child);
07f4e2c6
PBG
188extern long os_ptrace_ldt(long pid, long addr, long data);
189
1da177e4 190extern int os_getpid(void);
cd2ee4a3 191extern int os_getpgrp(void);
07f4e2c6 192
e64bd134 193extern void init_new_thread_signals(void);
fab95c55 194extern int run_kernel_thread(int (*fn)(void *), void *arg, jmp_buf **jmp_ptr);
1da177e4
LT
195
196extern int os_map_memory(void *virt, int fd, unsigned long long off,
197 unsigned long len, int r, int w, int x);
329c6e42 198extern int os_protect_memory(void *addr, unsigned long len,
1da177e4
LT
199 int r, int w, int x);
200extern int os_unmap_memory(void *addr, int len);
02dea087
JD
201extern int os_drop_memory(void *addr, int length);
202extern int can_drop_memory(void);
1da177e4 203extern void os_flush_stdout(void);
1da177e4 204
bb578426
GS
205/* uaccess.c */
206extern unsigned long __do_user_copy(void *to, const void *from, int n,
fab95c55 207 void **fault_addr, jmp_buf **fault_catcher,
bb578426
GS
208 void (*op)(void *to, const void *from,
209 int n), int *faulted_out);
210
5d48545e
PBG
211/* execvp.c */
212extern int execvp_noalloc(char *buf, const char *file, char *const argv[]);
ff5c6ff5 213/* helper.c */
c4399016 214extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv);
ff5c6ff5 215extern int run_helper_thread(int (*proc)(void *), void *arg,
c4399016 216 unsigned int flags, unsigned long *stack_out);
4dbed85a 217extern int helper_wait(int pid, int nohang, char *pname);
ff5c6ff5 218
aa6758d4
PBG
219
220/* tls.c */
dd77aec0
PBG
221extern int os_set_thread_area(user_desc_t *info, int pid);
222extern int os_get_thread_area(user_desc_t *info, int pid);
1da177e4 223
dd77aec0 224/* umid.c */
2264c475 225extern int umid_file_name(char *name, char *buf, int len);
7eebe8a9
JD
226extern int set_umid(char *name);
227extern char *get_umid(void);
2264c475 228
0805d89c 229/* signal.c */
78a26e25 230extern void timer_init(void);
0805d89c
GS
231extern void set_sigstack(void *sig_stack, int size);
232extern void remove_sigstack(void);
233extern void set_handler(int sig, void (*handler)(int), int flags, ...);
234extern int change_sig(int signal, int on);
235extern void block_signals(void);
236extern void unblock_signals(void);
237extern int get_signals(void);
238extern int set_signals(int enable);
239
ea2ba7dc
GS
240/* trap.c */
241extern void os_fill_handlinfo(struct kern_handlers h);
ea2ba7dc 242
4fef0c10
GS
243/* util.c */
244extern void stack_protections(unsigned long address);
4fef0c10
GS
245extern int raw(int fd);
246extern void setup_machinename(char *machine_out);
b4ffb6ad 247extern void setup_hostinfo(char *buf, int len);
4fef0c10 248extern int setjmp_wrapper(void (*proc)(void *, void *), ...);
63843c26 249extern void os_dump_core(void);
4fef0c10 250
cff65c4f 251/* time.c */
b160fb63 252extern void idle_sleep(unsigned long long nsecs);
a2f018bf 253extern int set_interval(void);
d2753a6d 254extern int timer_one_shot(int ticks);
5f734614 255extern long long disable_timer(void);
cff65c4f 256extern void uml_idle_timer(void);
5f734614 257extern long long os_nsecs(void);
cff65c4f 258
f45d9fc9
GS
259/* skas/mem.c */
260extern long run_syscall_stub(struct mm_id * mm_idp,
261 int syscall, unsigned long *args, long expected,
262 void **addr, int done);
263extern long syscall_stub_data(struct mm_id * mm_idp,
264 unsigned long *data, int data_count,
265 void **addr, void **stub_addr);
266extern int map(struct mm_id * mm_idp, unsigned long virt,
16dd07bc 267 unsigned long len, int prot, int phys_fd,
f45d9fc9 268 unsigned long long offset, int done, void **data);
64f60841 269extern int unmap(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
f45d9fc9
GS
270 int done, void **data);
271extern int protect(struct mm_id * mm_idp, unsigned long addr,
16dd07bc 272 unsigned long len, unsigned int prot, int done, void **data);
f45d9fc9 273
abaf6977
GS
274/* skas/process.c */
275extern int is_skas_winch(int pid, int fd, void *data);
276extern int start_userspace(unsigned long stub_stack);
277extern int copy_context_skas0(unsigned long stack, int pid);
77bf4400
JD
278extern void save_registers(int pid, struct uml_pt_regs *regs);
279extern void restore_registers(int pid, struct uml_pt_regs *regs);
280extern void userspace(struct uml_pt_regs *regs);
abaf6977
GS
281extern void map_stub_pages(int fd, unsigned long code,
282 unsigned long data, unsigned long stack);
3c917350
JD
283extern void new_thread(void *stack, jmp_buf *buf, void (*handler)(void));
284extern void switch_threads(jmp_buf *me, jmp_buf *you);
285extern int start_idle_thread(void *stack, jmp_buf *switch_buf);
abaf6977
GS
286extern void initial_thread_cb_skas(void (*proc)(void *),
287 void *arg);
288extern void halt_skas(void);
289extern void reboot_skas(void);
290
63ae2a94
JD
291/* irq.c */
292extern int os_waiting_for_events(struct irq_fd *active_fds);
63ae2a94
JD
293extern int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds);
294extern void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
295 struct irq_fd *active_fds, struct irq_fd ***last_irq_ptr2);
296extern void os_free_irq_later(struct irq_fd *active_fds,
297 int irq, void *dev_id);
298extern int os_get_pollfd(int i);
299extern void os_set_pollfd(int i, int fd);
300extern void os_set_ioignore(void);
301extern void init_irq_signals(int on_sigstack);
302
f206aabb 303/* sigio.c */
19bdf040 304extern int add_sigio_fd(int fd);
f206aabb 305extern int ignore_sigio_fd(int fd);
8e64d96a 306extern void maybe_sigio_broken(int fd, int read);
f206aabb 307
cf9165a5
JD
308/* skas/trap */
309extern void sig_handler_common_skas(int sig, void *sc_ptr);
cf9165a5 310
24fa6c08 311/* sys-x86_64/prctl.c */
f355559c
JD
312extern int os_arch_prctl(int pid, int code, unsigned long *addr);
313
24fa6c08
JD
314/* tty.c */
315int get_pty(void);
316
2264c475 317#endif