os.h 6.7 KB

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