2011-12-08 06:59:08 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PROCESS_H
|
|
|
|
#define PROCESS_H
|
|
|
|
|
2012-02-06 00:16:59 +04:00
|
|
|
//#include <system.h>
|
2011-12-08 06:59:08 +04:00
|
|
|
#include <tree.h>
|
|
|
|
#include <signal.h>
|
2012-02-06 00:16:59 +04:00
|
|
|
#include <task.h>
|
2011-12-08 06:59:08 +04:00
|
|
|
|
2012-02-21 09:31:00 +04:00
|
|
|
#define KERNEL_STACK_SIZE 0x8000
|
2011-12-09 01:25:48 +04:00
|
|
|
|
2011-12-08 06:59:08 +04:00
|
|
|
typedef signed int pid_t;
|
|
|
|
typedef unsigned int user_t;
|
|
|
|
typedef unsigned char status_t;
|
|
|
|
|
2012-01-27 08:46:18 +04:00
|
|
|
#define USER_ROOT_UID (user_t)0
|
|
|
|
|
2011-12-08 06:59:08 +04:00
|
|
|
/* Unix waitpid() options */
|
|
|
|
enum wait_option{
|
|
|
|
WCONTINUED,
|
|
|
|
WNOHANG,
|
|
|
|
WUNTRACED
|
|
|
|
};
|
|
|
|
|
|
|
|
/* x86 task */
|
|
|
|
typedef struct thread {
|
|
|
|
uintptr_t esp; /* Stack Pointer */
|
|
|
|
uintptr_t ebp; /* Base Pointer */
|
|
|
|
uintptr_t eip; /* Instruction Pointer */
|
|
|
|
|
2013-04-16 11:03:23 +04:00
|
|
|
uint8_t fpu_enabled;
|
2013-04-16 10:23:56 +04:00
|
|
|
uint8_t fp_regs[512];
|
2012-10-22 07:17:47 +04:00
|
|
|
|
2012-12-11 08:28:31 +04:00
|
|
|
uint8_t padding[32]; /* I don't know */
|
|
|
|
|
2011-12-08 06:59:08 +04:00
|
|
|
page_directory_t * page_directory; /* Page Directory */
|
|
|
|
} thread_t;
|
|
|
|
|
|
|
|
/* Portable image struct */
|
|
|
|
typedef struct image {
|
|
|
|
size_t size; /* Image size */
|
|
|
|
uintptr_t entry; /* Binary entry point */
|
|
|
|
uintptr_t heap; /* Heap pointer */
|
|
|
|
uintptr_t heap_actual; /* Actual heap location */
|
|
|
|
uintptr_t stack; /* Process kernel stack */
|
|
|
|
uintptr_t user_stack; /* User stack */
|
2012-02-08 12:40:44 +04:00
|
|
|
uintptr_t start;
|
2012-02-11 08:13:31 +04:00
|
|
|
uintptr_t shm_heap;
|
2011-12-08 06:59:08 +04:00
|
|
|
} image_t;
|
|
|
|
|
|
|
|
/* Resizable descriptor table */
|
|
|
|
typedef struct descriptor_table {
|
|
|
|
fs_node_t ** entries;
|
|
|
|
size_t length;
|
|
|
|
size_t capacity;
|
2012-03-15 07:03:55 +04:00
|
|
|
size_t refs;
|
2011-12-08 06:59:08 +04:00
|
|
|
} fd_table_t;
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
#define SIG_COUNT 10
|
|
|
|
|
|
|
|
/* Signal Table */
|
|
|
|
typedef struct signal_table {
|
2012-02-13 04:47:01 +04:00
|
|
|
uintptr_t functions[NUMSIGNALS+1];
|
2011-12-08 06:59:08 +04:00
|
|
|
} sig_table_t;
|
|
|
|
|
|
|
|
/* Portable process struct */
|
|
|
|
typedef struct process {
|
2012-02-06 00:16:59 +04:00
|
|
|
pid_t id; /* Process ID (pid) */
|
|
|
|
char * name; /* Process Name */
|
|
|
|
char * description; /* Process description */
|
|
|
|
user_t user; /* Effective user */
|
2013-04-23 12:14:33 +04:00
|
|
|
int mask; /* Umask */
|
2013-03-18 03:33:28 +04:00
|
|
|
|
2013-03-19 08:52:45 +04:00
|
|
|
char ** cmdline;
|
|
|
|
|
2013-03-18 03:33:28 +04:00
|
|
|
pid_t group; /* Process thread group */
|
|
|
|
pid_t job; /* Process job group */
|
|
|
|
pid_t session; /* Session group */
|
|
|
|
|
2012-02-06 00:16:59 +04:00
|
|
|
thread_t thread; /* Associated task information */
|
|
|
|
tree_node_t * tree_entry; /* Process Tree Entry */
|
|
|
|
image_t image; /* Binary image information */
|
|
|
|
fs_node_t * wd_node; /* Working directory VFS node */
|
|
|
|
char * wd_name; /* Working directory path name */
|
2012-02-17 00:31:40 +04:00
|
|
|
fd_table_t * fds; /* File descriptor table */
|
2012-02-06 00:16:59 +04:00
|
|
|
status_t status; /* Process status */
|
|
|
|
sig_table_t signals; /* Signal table */
|
2012-12-05 03:16:53 +04:00
|
|
|
uint8_t finished; /* Status indicator */
|
|
|
|
uint8_t started;
|
2012-01-29 03:06:07 +04:00
|
|
|
struct regs * syscall_registers; /* Registers at interrupt */
|
2012-02-01 05:27:38 +04:00
|
|
|
list_t * wait_queue;
|
2012-02-06 00:16:59 +04:00
|
|
|
list_t * shm_mappings; /* Shared memory chunk mappings */
|
2012-02-08 12:40:44 +04:00
|
|
|
list_t * signal_queue; /* Queued signals */
|
|
|
|
thread_t signal_state;
|
|
|
|
char * signal_kstack;
|
2012-02-21 09:31:00 +04:00
|
|
|
node_t sched_node;
|
2012-12-01 06:26:47 +04:00
|
|
|
node_t sleep_node;
|
2011-12-08 06:59:08 +04:00
|
|
|
} process_t;
|
|
|
|
|
2012-12-11 08:28:31 +04:00
|
|
|
typedef struct {
|
|
|
|
unsigned long end_tick;
|
|
|
|
unsigned long end_subtick;
|
|
|
|
process_t * process;
|
|
|
|
} sleeper_t;
|
|
|
|
|
2011-12-08 06:59:08 +04:00
|
|
|
void initialize_process_tree();
|
2011-12-09 01:25:48 +04:00
|
|
|
process_t * spawn_process(volatile process_t * parent);
|
2011-12-08 06:59:08 +04:00
|
|
|
void debug_print_process_tree();
|
2011-12-09 01:25:48 +04:00
|
|
|
process_t * spawn_init();
|
|
|
|
void set_process_environment(process_t * proc, page_directory_t * directory);
|
|
|
|
void make_process_ready(process_t * proc);
|
2011-12-16 03:21:28 +04:00
|
|
|
void make_process_reapable(process_t * proc);
|
2011-12-09 01:25:48 +04:00
|
|
|
uint8_t process_available();
|
|
|
|
process_t * next_ready_process();
|
2011-12-16 03:21:28 +04:00
|
|
|
uint8_t should_reap();
|
|
|
|
process_t * next_reapable_process();
|
2011-12-09 01:25:48 +04:00
|
|
|
uint32_t process_append_fd(process_t * proc, fs_node_t * node);
|
|
|
|
process_t * process_from_pid(pid_t pid);
|
2013-03-21 08:24:55 +04:00
|
|
|
process_t * process_get_first_child(process_t * process);
|
2011-12-16 03:21:28 +04:00
|
|
|
void delete_process(process_t * proc);
|
2012-01-25 05:06:07 +04:00
|
|
|
uint32_t process_move_fd(process_t * proc, int src, int dest);
|
2012-12-01 06:26:47 +04:00
|
|
|
int process_is_ready(process_t * proc);
|
2013-03-21 08:24:55 +04:00
|
|
|
void set_reaped(process_t * proc);
|
2011-12-09 01:25:48 +04:00
|
|
|
|
2012-12-11 08:28:31 +04:00
|
|
|
void wakeup_sleepers(unsigned long seconds, unsigned long subseconds);
|
|
|
|
void sleep_until(process_t * process, unsigned long seconds, unsigned long subseconds);
|
|
|
|
|
2011-12-09 01:25:48 +04:00
|
|
|
volatile process_t * current_process;
|
2011-12-08 06:59:08 +04:00
|
|
|
|
2013-03-19 08:52:45 +04:00
|
|
|
list_t * process_list;
|
|
|
|
|
2011-12-08 06:59:08 +04:00
|
|
|
#endif
|