mirror of
https://github.com/ish-app/ish.git
synced 2026-01-25 14:06:40 +00:00
97 lines
2.5 KiB
C
97 lines
2.5 KiB
C
#ifndef PROCESS_H
|
|
#define PROCESS_H
|
|
|
|
#include <pthread.h>
|
|
#include "util/list.h"
|
|
#include "util/timer.h"
|
|
#include "emu/cpu.h"
|
|
#include "kernel/fs.h"
|
|
#include "kernel/signal.h"
|
|
#include "kernel/resource.h"
|
|
|
|
struct process {
|
|
struct cpu_state cpu; // do not access this field except on the current process
|
|
pthread_t thread;
|
|
|
|
dword_t pid, ppid;
|
|
dword_t uid, gid;
|
|
dword_t euid, egid;
|
|
|
|
addr_t vdso;
|
|
addr_t start_brk;
|
|
addr_t brk;
|
|
|
|
struct fd *pwd;
|
|
struct fd *root;
|
|
struct fd *files[MAX_FD];
|
|
mode_t_ umask;
|
|
|
|
struct sigaction_ sigactions[NUM_SIGS];
|
|
sigset_t_ blocked;
|
|
sigset_t_ queued; // where blocked signals go when they're sent
|
|
sigset_t_ pending;
|
|
lock_t signal_lock;
|
|
|
|
struct process *parent;
|
|
struct list children;
|
|
struct list siblings;
|
|
|
|
dword_t sid, pgid;
|
|
struct list session;
|
|
struct list group;
|
|
struct tty *tty;
|
|
|
|
bool has_timer;
|
|
struct timer *timer;
|
|
|
|
struct rlimit_ limits[RLIMIT_NLIMITS_];
|
|
|
|
// the next two fields are protected by the exit_lock on the parent
|
|
// process. this is because waitpid locks the parent process to wait for
|
|
// any of its children to exit.
|
|
dword_t exit_code;
|
|
struct rusage_ rusage;
|
|
bool zombie;
|
|
|
|
struct rusage_ children_rusage;
|
|
pthread_cond_t child_exit;
|
|
lock_t exit_lock;
|
|
|
|
pthread_cond_t vfork_done;
|
|
};
|
|
|
|
// current will always give the process that is currently executing
|
|
// if I have to stop using __thread, current will become a macro
|
|
extern __thread struct process *current;
|
|
#define curmem current->cpu.mem
|
|
|
|
// Creates a new process, initializes most fields from the parent. Specify
|
|
// parent as NULL to create the init process. Returns NULL if out of memory.
|
|
struct process *process_create(struct process *parent);
|
|
// Removes the process from the process table and frees it.
|
|
void process_destroy(struct process *proc);
|
|
|
|
struct pid {
|
|
dword_t id;
|
|
struct process *proc;
|
|
struct list session;
|
|
struct list group;
|
|
};
|
|
|
|
// these functions must be called with pids_lock
|
|
struct pid *pid_get(dword_t pid);
|
|
struct process *pid_get_proc(dword_t pid);
|
|
struct process *pid_get_proc_zombie(dword_t id); // don't return null if the process exists as a zombie
|
|
extern lock_t pids_lock;
|
|
|
|
#define MAX_PID (1 << 10) // oughta be enough
|
|
|
|
// When a thread is created to run a new process, this function is used.
|
|
extern void (*process_run_hook)(void);
|
|
// TODO document
|
|
void process_start(struct process *proc);
|
|
|
|
extern void (*exit_hook)(int code);
|
|
|
|
#endif
|