vm: include no-caching bits in PTF_ALLFLAGS for flags sanity check.
[minix.git] / kernel / priv.h
blob42e62698621bb46579cc375c1402a123e53848cf
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 <minix/const.h>
17 #include "const.h"
18 #include "type.h"
20 /* Max. number of I/O ranges that can be assigned to a process */
21 #define NR_IO_RANGE 32
23 /* Max. number of device memory ranges that can be assigned to a process */
24 #define NR_MEM_RANGE 10
26 /* Max. number of IRQs that can be assigned to a process */
27 #define NR_IRQ 4
29 struct priv {
30 proc_nr_t s_proc_nr; /* number of associated process */
31 sys_id_t s_id; /* index of this system structure */
32 short s_flags; /* PREEMTIBLE, BILLABLE, etc. */
34 /* Asynchronous sends */
35 vir_bytes s_asyntab; /* addr. of table in process' address space */
36 size_t s_asynsize; /* number of elements in table. 0 when not in
37 * use
40 short s_trap_mask; /* allowed system call traps */
41 sys_map_t s_ipc_to; /* allowed destination processes */
43 /* allowed kernel calls */
44 bitchunk_t s_k_call_mask[SYS_CALL_MASK_SIZE];
46 endpoint_t s_sig_mgr; /* signal manager for system signals */
47 sys_map_t s_notify_pending; /* bit map with pending notifications */
48 irq_id_t s_int_pending; /* pending hardware interrupts */
49 sigset_t s_sig_pending; /* pending signals */
51 timer_t s_alarm_timer; /* synchronous alarm timer */
52 struct far_mem s_farmem[NR_REMOTE_SEGS]; /* remote memory map */
53 reg_t *s_stack_guard; /* stack guard word for kernel tasks */
55 int s_nr_io_range; /* allowed I/O ports */
56 struct io_range s_io_tab[NR_IO_RANGE];
58 int s_nr_mem_range; /* allowed memory ranges */
59 struct mem_range s_mem_tab[NR_MEM_RANGE];
61 int s_nr_irq; /* allowed IRQ lines */
62 int s_irq_tab[NR_IRQ];
63 vir_bytes s_grant_table; /* grant table address of process, or 0 */
64 int s_grant_entries; /* no. of entries, or 0 */
67 /* Guard word for task stacks. */
68 #define STACK_GUARD ((reg_t) (sizeof(reg_t) == 2 ? 0xBEEF : 0xDEADBEEF))
70 /* Static privilege id definitions. */
71 #define NR_STATIC_PRIV_IDS NR_BOOT_PROCS
72 #define is_static_priv_id(id) (id >= 0 && id < NR_STATIC_PRIV_IDS)
73 #define static_priv_id(n) (NR_TASKS + (n))
75 /* Magic system structure table addresses. */
76 #define BEG_PRIV_ADDR (&priv[0])
77 #define END_PRIV_ADDR (&priv[NR_SYS_PROCS])
78 #define BEG_STATIC_PRIV_ADDR BEG_PRIV_ADDR
79 #define END_STATIC_PRIV_ADDR (BEG_STATIC_PRIV_ADDR + NR_STATIC_PRIV_IDS)
80 #define BEG_DYN_PRIV_ADDR END_STATIC_PRIV_ADDR
81 #define END_DYN_PRIV_ADDR END_PRIV_ADDR
83 #define priv_addr(i) (ppriv_addr)[(i)]
84 #define priv_id(rp) ((rp)->p_priv->s_id)
85 #define priv(rp) ((rp)->p_priv)
87 #define id_to_nr(id) priv_addr(id)->s_proc_nr
88 #define nr_to_id(nr) priv(proc_addr(nr))->s_id
90 #define may_send_to(rp, nr) (get_sys_bit(priv(rp)->s_ipc_to, nr_to_id(nr)))
92 /* Privilege management shorthands. */
93 #define spi_to(n) (1 << (static_priv_id(n)))
94 #define unset_usr_to(m) ((m) & ~(1 << USER_PRIV_ID))
96 /* The system structures table and pointers to individual table slots. The
97 * pointers allow faster access because now a process entry can be found by
98 * indexing the psys_addr array, while accessing an element i requires a
99 * multiplication with sizeof(struct sys) to determine the address.
101 EXTERN struct priv priv[NR_SYS_PROCS]; /* system properties table */
102 EXTERN struct priv *ppriv_addr[NR_SYS_PROCS]; /* direct slot pointers */
104 /* Unprivileged user processes all share the privilege structure of the
105 * root user process.
106 * This id must be fixed because it is used to check send mask entries.
108 #define USER_PRIV_ID static_priv_id(ROOT_USR_PROC_NR)
109 /* Specifies a null privilege id.
111 #define NULL_PRIV_ID (-1)
113 /* Make sure the system can boot. The following sanity check verifies that
114 * the system privileges table is large enough for the number of processes
115 * in the boot image.
117 #if (NR_BOOT_PROCS > NR_SYS_PROCS)
118 #error NR_SYS_PROCS must be larger than NR_BOOT_PROCS
119 #endif
122 * Privileges masks used by the kernel.
124 #define IDL_F (SYS_PROC | BILLABLE) /* idle task is not preemptible as we
125 * don't want it to interfere with the
126 * timer tick interrupt handler code.
127 * Unlike other processes idle task is
128 * handled in a special way and is
129 * preempted always if timer tick occurs
130 * and there is another runnable process
132 #define TSK_F (SYS_PROC) /* other kernel tasks */
133 #define RSYS_F (SYS_PROC | PREEMPTIBLE) /* root system proc */
134 #define DEF_SYS_F (RSYS_F | DYN_PRIV_ID) /* default sys proc */
136 /* allowed traps */
137 #define CSK_T (1 << RECEIVE) /* clock and system */
138 #define TSK_T 0 /* other kernel tasks */
139 #define RSYS_T (~0) /* root system proc */
140 #define DEF_SYS_T RSYS_T /* default sys proc */
142 /* allowed targets */
143 #define TSK_M 0 /* all kernel tasks */
144 #define RSYS_M (~0) /* root system proc */
145 #define DEF_SYS_M unset_usr_to(RSYS_M) /* default sys proc */
147 /* allowed kernel calls */
148 #define NO_C 0 /* no calls allowed */
149 #define ALL_C 1 /* all calls allowed */
150 #define TSK_KC NO_C /* all kernel tasks */
151 #define RSYS_KC ALL_C /* root system proc */
152 #define DEF_SYS_KC RSYS_KC /* default sys proc */
154 /* signal manager */
155 #define RSYS_SM ROOT_SYS_PROC_NR /* root system proc */
156 #define DEF_SYS_SM ROOT_SYS_PROC_NR /* default sys proc */
158 #endif /* PRIV_H */