Fork me on GitHub

root/include/fiwix/process.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * fiwix/include/fiwix/process.h
   3  *
   4  * Copyright 2018-2021, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #ifndef _FIWIX_PROCESS_H
   9 #define _FIWIX_PROCESS_H
  10 
  11 struct vma {
  12         unsigned int start;
  13         unsigned int end;
  14         char prot;              /* PROT_READ, PROT_WRITE, ... */
  15         unsigned int flags;     /* MAP_SHARED, MAP_PRIVATE, ... */
  16         unsigned int offset;
  17         char s_type;            /* section type (P_TEXT, P_DATA, ...) */
  18         struct inode *inode;    /* file inode */
  19         char o_mode;            /* open mode (O_RDONLY, O_RDWR, ...) */
  20 };
  21 
  22 #include <fiwix/config.h>
  23 #include <fiwix/types.h>
  24 #include <fiwix/signal.h>
  25 #include <fiwix/limits.h>
  26 #include <fiwix/sigcontext.h>
  27 #include <fiwix/time.h>
  28 #include <fiwix/resource.h>
  29 #include <fiwix/tty.h>
  30 
  31 #define IDLE            0               /* PID of idle */
  32 #define INIT            1               /* PID of /sbin/init */
  33 #define SAFE_SLOTS      2               /* process slots reserved for root */
  34 #define SLOT(p)         ((p) - (&proc_table[0]))
  35 
  36 /* bits in flags */
  37 #define PF_KPROC        0x00000001      /* kernel internal process */
  38 #define PF_PEXEC        0x00000002      /* has performed a sys_execve() */
  39 #define PF_USEREAL      0x00000004      /* use real UID in permission checks */
  40 
  41 #define MMAP_START      0x40000000      /* mmap()s start at 1GB */
  42 #define IS_SUPERUSER    (current->euid == 0)
  43 
  44 #define IO_BITMAP_SIZE  32              /* 32 * 32bit = 1024 = 0x3FF */
  45                                         /* 2048 * 32bit = 65536 = 0xFFFF */
  46 
  47 #define PG_LEADER(p)    ((p)->pid == (p)->pgid)
  48 #define SESS_LEADER(p)  ((p)->pid == (p)->pgid && (p)->pid == (p)->sid)
  49 
  50 #define FOR_EACH_PROCESS(p)             p = proc_table_head->next ; while(p)
  51 #define FOR_EACH_PROCESS_RUNNING(p)     p = proc_run_head ; while(p)
  52 
  53 /* value to be determined during system startup */
  54 extern unsigned int proc_table_size;    /* size in bytes */
  55 
  56 extern char any_key_to_reboot;
  57 extern int nr_processes;
  58 extern __pid_t lastpid;
  59 extern struct proc *proc_table_head;
  60 
  61 struct binargs {
  62         unsigned int page[ARG_MAX];
  63         int argc;
  64         int argv_len;
  65         int envc;
  66         int envp_len;
  67         int offset;
  68 };
  69 
  70 /* Intel 386 Task Switch State */
  71 struct i386tss {
  72         unsigned int prev_tss;
  73         unsigned int esp0;
  74         unsigned int ss0;
  75         unsigned int esp1;
  76         unsigned int ss1;
  77         unsigned int esp2;
  78         unsigned int ss2;
  79         unsigned int cr3;
  80         unsigned int eip;
  81         unsigned int eflags;
  82         unsigned int eax;
  83         unsigned int ecx;
  84         unsigned int edx;
  85         unsigned int ebx;
  86         unsigned int esp;
  87         unsigned int ebp;
  88         unsigned int esi;
  89         unsigned int edi;
  90         unsigned int es;
  91         unsigned int cs;
  92         unsigned int ss;
  93         unsigned int ds;
  94         unsigned int fs;
  95         unsigned int gs;
  96         unsigned int ldt;
  97         unsigned short int debug_trap;
  98         unsigned short int io_bitmap_addr;
  99 };
 100 
 101 struct proc {
 102         struct i386tss tss;
 103         unsigned int io_bitmap[IO_BITMAP_SIZE + 1];
 104         __pid_t pid;                    /* process ID */
 105         __pid_t ppid;                   /* parent process ID */
 106         __pid_t pgid;                   /* process group ID */
 107         __pid_t sid;                    /* session ID */
 108         int flags;
 109         int groups[NGROUPS_MAX];
 110         int children;                   /* number of children */
 111         struct tty *ctty;               /* controlling terminal */
 112         int state;                      /* process state */
 113         int priority;
 114         int cpu_count;                  /* time of process running */
 115         __time_t start_time;
 116         int exit_code;  
 117         void *sleep_address;
 118         unsigned short int uid;         /* real user ID */
 119         unsigned short int gid;         /* real group ID */
 120         unsigned short int euid;        /* effective user ID */
 121         unsigned short int egid;        /* effective group ID */
 122         unsigned short int suid;        /* saved user ID */
 123         unsigned short int sgid;        /* saved group ID */
 124         unsigned short int fd[OPEN_MAX];
 125         unsigned char fd_flags[OPEN_MAX];
 126         struct inode *root;
 127         struct inode *pwd;              /* process working directory */
 128         unsigned int entry_address;
 129         char argv0[NAME_MAX + 1];
 130         int argc;
 131         char **argv;
 132         int envc;
 133         char **envp;
 134         char pidstr[5];                 /* pid number converted to string */
 135         struct vma vma[VMA_REGIONS];    /* virtual memory-map addresses */
 136         unsigned int brk_lower;         /* lower limit of the heap section */
 137         unsigned int brk;               /* current limit of the heap */
 138         __sigset_t sigpending;
 139         __sigset_t sigblocked;
 140         __sigset_t sigexecuting;
 141         struct sigaction sigaction[NSIG];
 142         struct sigcontext sc[NSIG];     /* each signal has its own context */
 143         unsigned int sp;                /* current process' stack frame */
 144         struct rusage usage;            /* process resource usage */
 145         struct rusage cusage;           /* children resource usage */
 146         unsigned long int it_real_interval, it_real_value;
 147         unsigned long int it_virt_interval, it_virt_value;
 148         unsigned long int it_prof_interval, it_prof_value;
 149         unsigned long int timeout;
 150         struct rlimit rlim[RLIM_NLIMITS];
 151         unsigned long int rss;
 152         __mode_t umask;
 153         unsigned char loopcnt;          /* nested symlinks counter */
 154         struct proc *prev;
 155         struct proc *next;
 156         struct proc *prev_sleep;
 157         struct proc *next_sleep;
 158         struct proc *prev_run;
 159         struct proc *next_run;
 160 };
 161 
 162 extern struct proc *current;
 163 extern struct proc *proc_table;
 164 
 165 int send_sig(struct proc *, __sigset_t);
 166 int kill_pid(__pid_t, __sigset_t);
 167 int kill_pgrp(__pid_t, __sigset_t);
 168 void add_crusage(struct proc *, struct rusage *);
 169 void get_rusage(struct proc *, struct rusage *);
 170 void add_rusage(struct proc *);
 171 struct proc * get_next_zombie(struct proc *);
 172 __pid_t remove_zombie(struct proc *);
 173 int is_orphaned_pgrp(__pid_t);
 174 struct proc * get_proc_free(void);
 175 void release_proc(struct proc *);
 176 int get_unused_pid(void);
 177 struct proc * get_proc_by_pid(__pid_t);
 178 
 179 int get_new_user_fd(int);
 180 void release_user_fd(int);
 181 
 182 struct proc * kernel_process(const char *, int (*fn)(void));
 183 void proc_slot_init(struct proc *);
 184 void proc_init(void);
 185 
 186 int elf_load(struct inode *, struct binargs *, struct sigcontext *, char *);
 187 int script_load(char *, char *, char *);
 188 
 189 #endif /* _FIWIX_PROCESS_H */

/* [previous][next][first][last][top][bottom][index][help] */