panic() cleanup.
[minix.git] / kernel / priv.h
blobd05a22683ed86b32dc7ba5eea9d8f9198642e9da
1 #ifndef PRIV_H
2 #define PRIV_H
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.
11 * Changes:
12 * Nov 22, 2009 rewrite of privilege management (Cristiano Giuffrida)
13 * Jul 01, 2005 Created. (Jorrit N. Herder)
15 #include <minix/com.h>
16 #include "const.h"
17 #include "type.h"
19 /* Max. number of I/O ranges that can be assigned to a process */
20 #define NR_IO_RANGE 32
22 /* Max. number of device memory ranges that can be assigned to a process */
23 #define NR_MEM_RANGE 10
25 /* Max. number of IRQs that can be assigned to a process */
26 #define NR_IRQ 4
28 struct priv {
29 proc_nr_t s_proc_nr; /* number of associated process */
30 sys_id_t s_id; /* index of this system structure */
31 short s_flags; /* PREEMTIBLE, BILLABLE, etc. */
33 /* Asynchronous sends */
34 vir_bytes s_asyntab; /* addr. of table in process' address space */
35 size_t s_asynsize; /* number of elements in table. 0 when not in
36 * use
39 short s_trap_mask; /* allowed system call traps */
40 sys_map_t s_ipc_to; /* allowed destination processes */
42 /* allowed kernel calls */
43 bitchunk_t s_k_call_mask[SYS_CALL_MASK_SIZE];
45 sys_map_t s_notify_pending; /* bit map with pending notifications */
46 irq_id_t s_int_pending; /* pending hardware interrupts */
47 sigset_t s_sig_pending; /* pending signals */
49 timer_t s_alarm_timer; /* synchronous alarm timer */
50 struct far_mem s_farmem[NR_REMOTE_SEGS]; /* remote memory map */
51 reg_t *s_stack_guard; /* stack guard word for kernel tasks */
53 int s_nr_io_range; /* allowed I/O ports */
54 struct io_range s_io_tab[NR_IO_RANGE];
56 int s_nr_mem_range; /* allowed memory ranges */
57 struct mem_range s_mem_tab[NR_MEM_RANGE];
59 int s_nr_irq; /* allowed IRQ lines */
60 int s_irq_tab[NR_IRQ];
61 vir_bytes s_grant_table; /* grant table address of process, or 0 */
62 int s_grant_entries; /* no. of entries, or 0 */
65 /* Guard word for task stacks. */
66 #define STACK_GUARD ((reg_t) (sizeof(reg_t) == 2 ? 0xBEEF : 0xDEADBEEF))
68 /* Static privilege id definitions. */
69 #define NR_STATIC_PRIV_IDS NR_BOOT_PROCS
70 #define is_static_priv_id(id) (id >= 0 && id < NR_STATIC_PRIV_IDS)
71 #define static_priv_id(n) (NR_TASKS + (n))
73 /* Magic system structure table addresses. */
74 #define BEG_PRIV_ADDR (&priv[0])
75 #define END_PRIV_ADDR (&priv[NR_SYS_PROCS])
76 #define BEG_STATIC_PRIV_ADDR BEG_PRIV_ADDR
77 #define END_STATIC_PRIV_ADDR (BEG_STATIC_PRIV_ADDR + NR_STATIC_PRIV_IDS)
78 #define BEG_DYN_PRIV_ADDR END_STATIC_PRIV_ADDR
79 #define END_DYN_PRIV_ADDR END_PRIV_ADDR
81 #define priv_addr(i) (ppriv_addr)[(i)]
82 #define priv_id(rp) ((rp)->p_priv->s_id)
83 #define priv(rp) ((rp)->p_priv)
85 #define id_to_nr(id) priv_addr(id)->s_proc_nr
86 #define nr_to_id(nr) priv(proc_addr(nr))->s_id
88 #define may_send_to(rp, nr) (get_sys_bit(priv(rp)->s_ipc_to, nr_to_id(nr)))
90 /* Privilege management shorthands. */
91 #define spi_to(n) (1 << (static_priv_id(n)))
92 #define unset_usr_to(m) ((m) & ~(1 << USER_PRIV_ID))
94 /* The system structures table and pointers to individual table slots. The
95 * pointers allow faster access because now a process entry can be found by
96 * indexing the psys_addr array, while accessing an element i requires a
97 * multiplication with sizeof(struct sys) to determine the address.
99 EXTERN struct priv priv[NR_SYS_PROCS]; /* system properties table */
100 EXTERN struct priv *ppriv_addr[NR_SYS_PROCS]; /* direct slot pointers */
102 /* Unprivileged user processes all share the privilege structure of the
103 * root user process.
104 * This id must be fixed because it is used to check send mask entries.
106 #define USER_PRIV_ID static_priv_id(ROOT_USR_PROC_NR)
107 /* Specifies a null privilege id.
109 #define NULL_PRIV_ID (-1)
111 /* Make sure the system can boot. The following sanity check verifies that
112 * the system privileges table is large enough for the number of processes
113 * in the boot image.
115 #if (NR_BOOT_PROCS > NR_SYS_PROCS)
116 #error NR_SYS_PROCS must be larger than NR_BOOT_PROCS
117 #endif
120 * Privileges masks used by the kernel.
122 #define IDL_F (SYS_PROC | BILLABLE) /* idle task is not preemptible as we
123 * don't want it to interfere with the
124 * timer tick interrupt handler code.
125 * Unlike other processes idle task is
126 * handled in a special way and is
127 * preempted always if timer tick occurs
128 * and there is another runnable process
130 #define TSK_F (SYS_PROC) /* other kernel tasks */
131 #define RSYS_F (SYS_PROC | PREEMPTIBLE) /* root system proc */
132 #define DEF_SYS_F (RSYS_F | DYN_PRIV_ID) /* default sys proc */
134 /* allowed traps */
135 #define CSK_T (1 << RECEIVE) /* clock and system */
136 #define TSK_T 0 /* other kernel tasks */
137 #define RSYS_T (~0) /* root system proc */
138 #define DEF_SYS_T RSYS_T /* default sys proc */
140 /* allowed targets */
141 #define TSK_M 0 /* all kernel tasks */
142 #define RSYS_M (~0) /* root system proc */
143 #define DEF_SYS_M unset_usr_to(RSYS_M) /* default sys proc */
145 /* allowed kernel calls */
146 #define NO_C 0 /* no calls allowed */
147 #define ALL_C 1 /* all calls allowed */
148 #define TSK_KC NO_C /* all kernel tasks */
149 #define RSYS_KC ALL_C /* root system proc */
150 #define DEF_SYS_KC RSYS_KC /* default sys proc */
152 #endif /* PRIV_H */