process.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. */
  3. #pragma once
  4. #include <kernel/signal.h>
  5. #include <kernel/task.h>
  6. #include <toaru/tree.h>
  7. #define KERNEL_STACK_SIZE 0x8000
  8. typedef signed int pid_t;
  9. typedef unsigned int user_t;
  10. typedef unsigned int status_t;
  11. #define USER_ROOT_UID (user_t)0
  12. /* Unix waitpid() options */
  13. enum wait_option{
  14. WCONTINUED,
  15. WNOHANG,
  16. WUNTRACED
  17. };
  18. /* x86 task */
  19. typedef struct thread {
  20. uintptr_t esp; /* Stack Pointer */
  21. uintptr_t ebp; /* Base Pointer */
  22. uintptr_t eip; /* Instruction Pointer */
  23. uint8_t fpu_enabled;
  24. uint8_t fp_regs[512];
  25. uint8_t padding[32]; /* I don't know */
  26. page_directory_t * page_directory; /* Page Directory */
  27. } thread_t;
  28. /* Portable image struct */
  29. typedef struct image {
  30. size_t size; /* Image size */
  31. uintptr_t entry; /* Binary entry point */
  32. uintptr_t heap; /* Heap pointer */
  33. uintptr_t heap_actual; /* Actual heap location */
  34. uintptr_t stack; /* Process kernel stack */
  35. uintptr_t user_stack; /* User stack */
  36. uintptr_t start;
  37. uintptr_t shm_heap;
  38. volatile int lock[2];
  39. } image_t;
  40. /* Resizable descriptor table */
  41. typedef struct descriptor_table {
  42. fs_node_t ** entries;
  43. size_t length;
  44. size_t capacity;
  45. size_t refs;
  46. } fd_table_t;
  47. /* XXX */
  48. #define SIG_COUNT 10
  49. /* Signal Table */
  50. typedef struct signal_table {
  51. uintptr_t functions[NUMSIGNALS+1];
  52. } sig_table_t;
  53. /* Portable process struct */
  54. typedef struct process {
  55. pid_t id; /* Process ID (pid) */
  56. char * name; /* Process Name */
  57. char * description; /* Process description */
  58. user_t user; /* Effective user */
  59. int mask; /* Umask */
  60. char ** cmdline;
  61. pid_t group; /* Process thread group */
  62. pid_t job; /* Process job group */
  63. pid_t session; /* Session group */
  64. thread_t thread; /* Associated task information */
  65. tree_node_t * tree_entry; /* Process Tree Entry */
  66. image_t image; /* Binary image information */
  67. fs_node_t * wd_node; /* Working directory VFS node */
  68. char * wd_name; /* Working directory path name */
  69. fd_table_t * fds; /* File descriptor table */
  70. status_t status; /* Process status */
  71. sig_table_t signals; /* Signal table */
  72. uint8_t finished; /* Status indicator */
  73. uint8_t started;
  74. uint8_t running;
  75. struct regs * syscall_registers; /* Registers at interrupt */
  76. list_t * wait_queue;
  77. list_t * shm_mappings; /* Shared memory chunk mappings */
  78. list_t * signal_queue; /* Queued signals */
  79. thread_t signal_state;
  80. char * signal_kstack;
  81. node_t sched_node;
  82. node_t sleep_node;
  83. node_t * timed_sleep_node;
  84. uint8_t is_tasklet;
  85. volatile uint8_t sleep_interrupted;
  86. list_t * node_waits;
  87. int awoken_index;
  88. node_t * timeout_node;
  89. struct timeval start;
  90. uint8_t suspended;
  91. } process_t;
  92. typedef struct {
  93. unsigned long end_tick;
  94. unsigned long end_subtick;
  95. process_t * process;
  96. int is_fswait;
  97. } sleeper_t;
  98. extern void initialize_process_tree(void);
  99. extern process_t * spawn_process(volatile process_t * parent, int reuse_fds);
  100. extern void debug_print_process_tree(void);
  101. extern process_t * spawn_init(void);
  102. extern process_t * spawn_kidle(void);
  103. extern void set_process_environment(process_t * proc, page_directory_t * directory);
  104. extern void make_process_ready(process_t * proc);
  105. extern uint8_t process_available(void);
  106. extern process_t * next_ready_process(void);
  107. extern uint32_t process_append_fd(process_t * proc, fs_node_t * node);
  108. extern process_t * process_from_pid(pid_t pid);
  109. extern void delete_process(process_t * proc);
  110. process_t * process_get_parent(process_t * process);
  111. extern uint32_t process_move_fd(process_t * proc, int src, int dest);
  112. extern int process_is_ready(process_t * proc);
  113. extern void wakeup_sleepers(unsigned long seconds, unsigned long subseconds);
  114. extern void sleep_until(process_t * process, unsigned long seconds, unsigned long subseconds);
  115. extern volatile process_t * current_process;
  116. extern process_t * kernel_idle_task;
  117. extern list_t * process_list;
  118. extern int process_wait_nodes(process_t * process,fs_node_t * nodes[], int timeout);
  119. extern int process_alert_node(process_t * process, void * value);
  120. extern int process_awaken_from_fswait(process_t * process, int index);
  121. typedef void (*tasklet_t) (void *, char *);
  122. extern int create_kernel_tasklet(tasklet_t tasklet, char * name, void * argp);
  123. extern void release_directory(page_directory_t * dir);
  124. extern void release_directory_for_exec(page_directory_t * dir);
  125. extern void cleanup_process(process_t * proc, int retval);
  126. extern void reap_process(process_t * proc);
  127. extern int waitpid(int pid, int * status, int options);
  128. extern int is_valid_process(process_t * process);