xref: /minix/minix/kernel/priv.h (revision 9f988b79)
1 #ifndef PRIV_H
2 #define PRIV_H
3 
4 /* Declaration of the system privileges structure. It defines flags, system
5  * call masks, an synchronous alarm timer, I/O privileges, pending hardware
6  * interrupts and notifications, and so on.
7  * System processes each get their own structure with properties, whereas all
8  * user processes share one structure. This setup provides a clear separation
9  * between common and privileged process fields and is very space efficient.
10  *
11  * Changes:
12  *   Nov 22, 2009  rewrite of privilege management (Cristiano Giuffrida)
13  *   Jul 01, 2005  Created.  (Jorrit N. Herder)
14  */
15 #include <minix/com.h>
16 #include <minix/const.h>
17 #include <minix/priv.h>
18 #include "kernel/const.h"
19 #include "kernel/type.h"
20 #include "kernel/ipc_filter.h"
21 
22 struct priv {
23   proc_nr_t s_proc_nr;		/* number of associated process */
24   sys_id_t s_id;		/* index of this system structure */
25   short s_flags;		/* PREEMTIBLE, BILLABLE, etc. */
26   int s_init_flags;             /* initialization flags given to the process. */
27 
28   /* Asynchronous sends */
29   vir_bytes s_asyntab;		/* addr. of table in process' address space */
30   size_t s_asynsize;		/* number of elements in table. 0 when not in
31 				 * use
32 				 */
33   endpoint_t s_asynendpoint;    /* the endpoint the asyn table belongs to. */
34 
35   short s_trap_mask;		/* allowed system call traps */
36   sys_map_t s_ipc_to;		/* allowed destination processes */
37 
38   /* allowed kernel calls */
39   bitchunk_t s_k_call_mask[SYS_CALL_MASK_SIZE];
40 
41   endpoint_t s_sig_mgr;		/* signal manager for system signals */
42   endpoint_t s_bak_sig_mgr;	/* backup signal manager for system signals */
43   sys_map_t s_notify_pending;  	/* bit map with pending notifications */
44   sys_map_t s_asyn_pending;	/* bit map with pending asyn messages */
45   irq_id_t s_int_pending;	/* pending hardware interrupts */
46   sigset_t s_sig_pending;	/* pending signals */
47   ipc_filter_t *s_ipcf;         /* ipc filter (NULL when no filter is set) */
48 
49   minix_timer_t s_alarm_timer;	/* synchronous alarm timer */
50   reg_t *s_stack_guard;		/* stack guard word for kernel tasks */
51 
52   char s_diag_sig;		/* send a SIGKMESS when diagnostics arrive? */
53 
54   int s_nr_io_range;		/* allowed I/O ports */
55   struct io_range s_io_tab[NR_IO_RANGE];
56 
57   int s_nr_mem_range;		/* allowed memory ranges */
58   struct minix_mem_range s_mem_tab[NR_MEM_RANGE];
59 
60   int s_nr_irq;			/* allowed IRQ lines */
61   int s_irq_tab[NR_IRQ];
62   vir_bytes s_grant_table;	/* grant table address of process, or 0 */
63   int s_grant_entries;		/* no. of entries, or 0 */
64   endpoint_t s_grant_endpoint;  /* the endpoint the grant table belongs to */
65   vir_bytes s_state_table;	/* state table address of process, or 0 */
66   int s_state_entries;		/* no. of entries, or 0 */
67 };
68 
69 /* Guard word for task stacks. */
70 #define STACK_GUARD	((reg_t) (sizeof(reg_t) == 2 ? 0xBEEF : 0xDEADBEEF))
71 
72 /* Magic system structure table addresses. */
73 #define BEG_PRIV_ADDR              (&priv[0])
74 #define END_PRIV_ADDR              (&priv[NR_SYS_PROCS])
75 #define BEG_STATIC_PRIV_ADDR       BEG_PRIV_ADDR
76 #define END_STATIC_PRIV_ADDR       (BEG_STATIC_PRIV_ADDR + NR_STATIC_PRIV_IDS)
77 #define BEG_DYN_PRIV_ADDR          END_STATIC_PRIV_ADDR
78 #define END_DYN_PRIV_ADDR          END_PRIV_ADDR
79 
80 #define priv_addr(i)      (ppriv_addr)[(i)]
81 #define priv_id(rp)	  ((rp)->p_priv->s_id)
82 #define priv(rp)	  ((rp)->p_priv)
83 
84 #define id_to_nr(id)	priv_addr(id)->s_proc_nr
85 #define nr_to_id(nr)    priv(proc_addr(nr))->s_id
86 
87 #define may_send_to(rp, nr) (get_sys_bit(priv(rp)->s_ipc_to, nr_to_id(nr)))
88 #define may_asynsend_to(rp, nr) (may_send_to(rp, nr) || (rp)->p_nr == nr)
89 
90 /* The system structures table and pointers to individual table slots. The
91  * pointers allow faster access because now a process entry can be found by
92  * indexing the psys_addr array, while accessing an element i requires a
93  * multiplication with sizeof(struct sys) to determine the address.
94  */
95 EXTERN struct priv priv[NR_SYS_PROCS];		/* system properties table */
96 EXTERN struct priv *ppriv_addr[NR_SYS_PROCS];	/* direct slot pointers */
97 
98 /* Make sure the system can boot. The following sanity check verifies that
99  * the system privileges table is large enough for the number of processes
100  * in the boot image.
101  */
102 #if (NR_BOOT_PROCS > NR_SYS_PROCS)
103 #error NR_SYS_PROCS must be larger than NR_BOOT_PROCS
104 #endif
105 
106 #endif /* PRIV_H */
107