root / lab4 / .minix-src / include / minix / syslib.h @ 14
History | View | Annotate | Download (12.3 KB)
1 |
/* Prototypes for system library functions. */
|
---|---|
2 |
|
3 |
#ifndef _SYSLIB_H
|
4 |
#define _SYSLIB_H
|
5 |
|
6 |
#include <sys/types.h> |
7 |
#include <sys/sigtypes.h> |
8 |
|
9 |
#include <minix/ipc.h> |
10 |
#include <minix/u64.h> |
11 |
#include <minix/devio.h> |
12 |
|
13 |
#include <minix/safecopies.h> |
14 |
#include <minix/sef.h> |
15 |
#include <machine/mcontext.h> |
16 |
|
17 |
/* Forward declaration */
|
18 |
struct rs_pci;
|
19 |
struct rusage;
|
20 |
struct sockcred;
|
21 |
struct reg86;
|
22 |
|
23 |
#define SYSTASK SYSTEM
|
24 |
|
25 |
/*==========================================================================*
|
26 |
* Minix system library. *
|
27 |
*==========================================================================*/
|
28 |
int _taskcall(endpoint_t who, int syscallnr, message *msgptr); |
29 |
int _kernel_call(int syscallnr, message *msgptr); |
30 |
|
31 |
int sys_abort(int how); |
32 |
int sys_enable_iop(endpoint_t proc_ep);
|
33 |
int sys_int86(struct reg86 *reg86p); |
34 |
int sys_exec(endpoint_t proc_ep, vir_bytes stack_ptr, vir_bytes progname,
|
35 |
vir_bytes pc, vir_bytes ps_str); |
36 |
int sys_fork(endpoint_t parent, endpoint_t child, endpoint_t *,
|
37 |
u32_t vm, vir_bytes *); |
38 |
int sys_clear(endpoint_t proc_ep);
|
39 |
int sys_exit(void); |
40 |
int sys_trace(int req, endpoint_t proc_ep, long addr, long *data_p); |
41 |
|
42 |
int sys_schedule(endpoint_t proc_ep, int priority, int quantum, int cpu, |
43 |
int niced);
|
44 |
int sys_schedctl(unsigned flags, endpoint_t proc_ep, int priority, int |
45 |
quantum, int cpu);
|
46 |
|
47 |
/* Shorthands for sys_runctl() system call. */
|
48 |
#define sys_stop(proc_ep) sys_runctl(proc_ep, RC_STOP, 0) |
49 |
#define sys_delay_stop(proc_ep) sys_runctl(proc_ep, RC_STOP, RC_DELAY)
|
50 |
#define sys_resume(proc_ep) sys_runctl(proc_ep, RC_RESUME, 0) |
51 |
int sys_runctl(endpoint_t proc_ep, int action, int flags); |
52 |
|
53 |
int sys_update(endpoint_t src_ep, endpoint_t dst_ep, int flags); |
54 |
int sys_statectl(int request, void* address, int length); |
55 |
int sys_privctl(endpoint_t proc_ep, int req, void *p); |
56 |
int sys_privquery_mem(endpoint_t proc_ep, phys_bytes physstart,
|
57 |
phys_bytes physlen); |
58 |
int sys_setgrant(cp_grant_t *grants, int ngrants); |
59 |
|
60 |
int sys_vm_setbuf(phys_bytes base, phys_bytes size, phys_bytes high);
|
61 |
int sys_vm_map(endpoint_t proc_ep, int do_map, phys_bytes base, |
62 |
phys_bytes size, phys_bytes offset); |
63 |
int sys_vmctl(endpoint_t who, int param, u32_t value); |
64 |
int sys_vmctl_get_pdbr(endpoint_t who, u32_t *pdbr);
|
65 |
int sys_vmctl_get_memreq(endpoint_t *who, vir_bytes *mem, vir_bytes
|
66 |
*len, int *wrflag, endpoint_t *who_s, vir_bytes *mem_s, endpoint_t *);
|
67 |
int sys_vmctl_enable_paging(void * data); |
68 |
|
69 |
int sys_readbios(phys_bytes address, void *buf, size_t size); |
70 |
int sys_settime(int now, clockid_t clk_id, time_t sec, long nsec); |
71 |
int sys_stime(time_t boottime);
|
72 |
int sys_vmctl_get_mapping(int index, phys_bytes *addr, phys_bytes *len, |
73 |
int *flags);
|
74 |
int sys_vmctl_reply_mapping(int index, vir_bytes addr); |
75 |
int sys_vmctl_set_addrspace(endpoint_t who, phys_bytes ptroot, void |
76 |
*ptroot_v); |
77 |
|
78 |
|
79 |
/* Shorthands for sys_sdevio() system call. */
|
80 |
#define sys_insb(port, proc_ep, buffer, count) \
|
81 |
sys_sdevio(DIO_INPUT_BYTE, port, proc_ep, buffer, count, 0)
|
82 |
#define sys_insw(port, proc_ep, buffer, count) \
|
83 |
sys_sdevio(DIO_INPUT_WORD, port, proc_ep, buffer, count, 0)
|
84 |
#define sys_outsb(port, proc_ep, buffer, count) \
|
85 |
sys_sdevio(DIO_OUTPUT_BYTE, port, proc_ep, buffer, count, 0)
|
86 |
#define sys_outsw(port, proc_ep, buffer, count) \
|
87 |
sys_sdevio(DIO_OUTPUT_WORD, port, proc_ep, buffer, count, 0)
|
88 |
#define sys_safe_insb(port, ept, grant, offset, count) \
|
89 |
sys_sdevio(DIO_SAFE_INPUT_BYTE, port, ept, (void*)grant, count, offset)
|
90 |
#define sys_safe_outsb(port, ept, grant, offset, count) \
|
91 |
sys_sdevio(DIO_SAFE_OUTPUT_BYTE, port, ept, (void*)grant, count, offset)
|
92 |
#define sys_safe_insw(port, ept, grant, offset, count) \
|
93 |
sys_sdevio(DIO_SAFE_INPUT_WORD, port, ept, (void*)grant, count, offset)
|
94 |
#define sys_safe_outsw(port, ept, grant, offset, count) \
|
95 |
sys_sdevio(DIO_SAFE_OUTPUT_WORD, port, ept, (void*)grant, count, offset)
|
96 |
int sys_sdevio(int req, long port, endpoint_t proc_ep, void *buffer, int |
97 |
count, vir_bytes offset); |
98 |
void *alloc_contig(size_t len, int flags, phys_bytes *phys); |
99 |
int free_contig(void *addr, size_t len); |
100 |
|
101 |
#define AC_ALIGN4K 0x01 |
102 |
#define AC_LOWER16M 0x02 |
103 |
#define AC_ALIGN64K 0x04 |
104 |
#define AC_LOWER1M 0x08 |
105 |
|
106 |
/* Clock functionality: get system times, (un)schedule an alarm call, or
|
107 |
* retrieve/set a process-virtual timer.
|
108 |
*/
|
109 |
int sys_times(endpoint_t proc_ep, clock_t *user_time, clock_t *sys_time,
|
110 |
clock_t *uptime, time_t *boottime); |
111 |
|
112 |
#define sys_setalarm(exp, abs) sys_setalarm2(exp, abs, NULL, NULL) |
113 |
int sys_setalarm2(clock_t exp_time, int abs_time, clock_t *time_left, |
114 |
clock_t *uptime); |
115 |
|
116 |
int sys_vtimer(endpoint_t proc_nr, int which, clock_t *newval, clock_t |
117 |
*oldval); |
118 |
|
119 |
/* Shorthands for sys_irqctl() system call. */
|
120 |
#define sys_irqdisable(hook_id) \
|
121 |
sys_irqctl(IRQ_DISABLE, 0, 0, hook_id) |
122 |
#define sys_irqenable(hook_id) \
|
123 |
sys_irqctl(IRQ_ENABLE, 0, 0, hook_id) |
124 |
#define sys_irqsetpolicy(irq_vec, policy, hook_id) \
|
125 |
sys_irqctl(IRQ_SETPOLICY, irq_vec, policy, hook_id) |
126 |
#define sys_irqrmpolicy(hook_id) \
|
127 |
sys_irqctl(IRQ_RMPOLICY, 0, 0, hook_id) |
128 |
int sys_irqctl(int request, int irq_vec, int policy, int *irq_hook_id); |
129 |
|
130 |
/* Shorthands for sys_vircopy() and sys_physcopy() system calls. */
|
131 |
#define sys_datacopy(p1, v1, p2, v2, len) sys_vircopy(p1, v1, p2, v2, len, 0) |
132 |
#define sys_datacopy_try(p1, v1, p2, v2, len) sys_vircopy(p1, v1, p2, v2, len, CP_FLAG_TRY)
|
133 |
int sys_vircopy(endpoint_t src_proc, vir_bytes src_v,
|
134 |
endpoint_t dst_proc, vir_bytes dst_vir, phys_bytes bytes, int flags);
|
135 |
|
136 |
#define sys_abscopy(src_phys, dst_phys, bytes) \
|
137 |
sys_physcopy(NONE, src_phys, NONE, dst_phys, bytes, 0)
|
138 |
int sys_physcopy(endpoint_t src_proc, vir_bytes src_vir,
|
139 |
endpoint_t dst_proc, vir_bytes dst_vir, phys_bytes bytes, int flags);
|
140 |
|
141 |
|
142 |
/* Grant-based copy functions. */
|
143 |
int sys_safecopyfrom(endpoint_t source, cp_grant_id_t grant, vir_bytes
|
144 |
grant_offset, vir_bytes my_address, size_t bytes); |
145 |
int sys_safecopyto(endpoint_t dest, cp_grant_id_t grant, vir_bytes
|
146 |
grant_offset, vir_bytes my_address, size_t bytes); |
147 |
int sys_vsafecopy(struct vscp_vec *copyvec, int elements); |
148 |
|
149 |
int sys_safememset(endpoint_t source, cp_grant_id_t grant, vir_bytes
|
150 |
grant_offset, int pattern, size_t bytes);
|
151 |
|
152 |
int sys_memset(endpoint_t who, unsigned long pattern, |
153 |
phys_bytes base, phys_bytes bytes); |
154 |
|
155 |
int sys_vumap(endpoint_t endpt, struct vumap_vir *vvec, |
156 |
int vcount, size_t offset, int access, struct vumap_phys *pvec, |
157 |
int *pcount);
|
158 |
int sys_umap(endpoint_t proc_ep, int seg, vir_bytes vir_addr, vir_bytes |
159 |
bytes, phys_bytes *phys_addr); |
160 |
int sys_umap_data_fb(endpoint_t proc_ep, vir_bytes vir_addr, vir_bytes
|
161 |
bytes, phys_bytes *phys_addr); |
162 |
int sys_umap_remote(endpoint_t proc_ep, endpoint_t grantee, int seg, |
163 |
vir_bytes vir_addr, vir_bytes bytes, phys_bytes *phys_addr); |
164 |
|
165 |
/* Shorthands for sys_diagctl() system call. */
|
166 |
#define sys_diagctl_diag(buf,len) \
|
167 |
sys_diagctl(DIAGCTL_CODE_DIAG, buf, len) |
168 |
#define sys_diagctl_stacktrace(ep) \
|
169 |
sys_diagctl(DIAGCTL_CODE_STACKTRACE, NULL, ep)
|
170 |
#define sys_diagctl_register() \
|
171 |
sys_diagctl(DIAGCTL_CODE_REGISTER, NULL, 0) |
172 |
#define sys_diagctl_unregister() \
|
173 |
sys_diagctl(DIAGCTL_CODE_UNREGISTER, NULL, 0) |
174 |
int sys_diagctl(int ctl, char *arg1, int arg2); |
175 |
|
176 |
/* Shorthands for sys_getinfo() system call. */
|
177 |
#define sys_getkinfo(dst) sys_getinfo(GET_KINFO, dst, 0,0,0) |
178 |
#define sys_getloadinfo(dst) sys_getinfo(GET_LOADINFO, dst, 0,0,0) |
179 |
#define sys_getmachine(dst) sys_getinfo(GET_MACHINE, dst, 0,0,0) |
180 |
#define sys_getcpuinfo(dst) sys_getinfo(GET_CPUINFO, dst, 0,0,0) |
181 |
#define sys_getproctab(dst) sys_getinfo(GET_PROCTAB, dst, 0,0,0) |
182 |
#define sys_getprivtab(dst) sys_getinfo(GET_PRIVTAB, dst, 0,0,0) |
183 |
#define sys_getproc(dst,nr) sys_getinfo(GET_PROC, dst, 0,0, nr) |
184 |
#define sys_getrandomness(dst) sys_getinfo(GET_RANDOMNESS, dst, 0,0,0) |
185 |
#define sys_getrandom_bin(d,b) sys_getinfo(GET_RANDOMNESS_BIN, d, 0,0,b) |
186 |
#define sys_getimage(dst) sys_getinfo(GET_IMAGE, dst, 0,0,0) |
187 |
#define sys_getirqhooks(dst) sys_getinfo(GET_IRQHOOKS, dst, 0,0,0) |
188 |
#define sys_getirqactids(dst) sys_getinfo(GET_IRQACTIDS, dst, 0,0,0) |
189 |
#define sys_getmonparams(v,vl) sys_getinfo(GET_MONPARAMS, v,vl, 0,0) |
190 |
#define sys_getschedinfo(v1,v2) sys_getinfo(GET_SCHEDINFO, v1,0, v2,0) |
191 |
#define sys_getpriv(dst, nr) sys_getinfo(GET_PRIV, dst, 0,0, nr) |
192 |
#define sys_getidletsc(dst) sys_getinfo(GET_IDLETSC, dst, 0,0,0) |
193 |
#define sys_getregs(dst,nr) sys_getinfo(GET_REGS, dst, 0,0, nr) |
194 |
#define sys_getcputicks(dst,nr) sys_getinfo(GET_CPUTICKS, dst, 0,0, nr) |
195 |
int sys_getinfo(int request, void *val_ptr, int val_len, void *val_ptr2, |
196 |
int val_len2);
|
197 |
int sys_whoami(endpoint_t *ep, char *name, int namelen, int |
198 |
*priv_flags, int* init_flags);
|
199 |
|
200 |
/* Signal control. */
|
201 |
int sys_kill(endpoint_t proc_ep, int sig); |
202 |
int sys_sigsend(endpoint_t proc_ep, struct sigmsg *sig_ctxt); |
203 |
int sys_sigreturn(endpoint_t proc_ep, struct sigmsg *sig_ctxt); |
204 |
int sys_getksig(endpoint_t *proc_ep, sigset_t *k_sig_map);
|
205 |
int sys_endksig(endpoint_t proc_ep);
|
206 |
|
207 |
/* NOTE: two different approaches were used to distinguish the device I/O
|
208 |
* types 'byte', 'word', 'long': the latter uses #define and results in a
|
209 |
* smaller implementation, but looses the static type checking.
|
210 |
*/
|
211 |
int sys_voutb(pvb_pair_t *pvb_pairs, int nr_ports); |
212 |
int sys_voutw(pvw_pair_t *pvw_pairs, int nr_ports); |
213 |
int sys_voutl(pvl_pair_t *pvl_pairs, int nr_ports); |
214 |
int sys_vinb(pvb_pair_t *pvb_pairs, int nr_ports); |
215 |
int sys_vinw(pvw_pair_t *pvw_pairs, int nr_ports); |
216 |
int sys_vinl(pvl_pair_t *pvl_pairs, int nr_ports); |
217 |
|
218 |
/* Shorthands for sys_out() system call. */
|
219 |
#define sys_outb(p,v) sys_out((p), (u32_t) (v), _DIO_BYTE)
|
220 |
#define sys_outw(p,v) sys_out((p), (u32_t) (v), _DIO_WORD)
|
221 |
#define sys_outl(p,v) sys_out((p), (u32_t) (v), _DIO_LONG)
|
222 |
int sys_out(int port, u32_t value, int type); |
223 |
|
224 |
/* Shorthands for sys_in() system call. */
|
225 |
#define sys_inb(p,v) sys_in((p), (v), _DIO_BYTE)
|
226 |
#define sys_inw(p,v) sys_in((p), (v), _DIO_WORD)
|
227 |
#define sys_inl(p,v) sys_in((p), (v), _DIO_LONG)
|
228 |
int sys_in(int port, u32_t *value, int type); |
229 |
|
230 |
/* arm pinmux */
|
231 |
int sys_padconf(u32_t padconf, u32_t mask, u32_t value);
|
232 |
|
233 |
/* pci.c */
|
234 |
void pci_init(void); |
235 |
int pci_first_dev(int *devindp, u16_t *vidp, u16_t *didp); |
236 |
int pci_next_dev(int *devindp, u16_t *vidp, u16_t *didp); |
237 |
int pci_find_dev(u8_t bus, u8_t dev, u8_t func, int *devindp); |
238 |
void pci_reserve(int devind); |
239 |
int pci_reserve_ok(int devind); |
240 |
void pci_ids(int devind, u16_t *vidp, u16_t *didp); |
241 |
void pci_rescan_bus(u8_t busnr);
|
242 |
u8_t pci_attr_r8(int devind, int port); |
243 |
u16_t pci_attr_r16(int devind, int port); |
244 |
u32_t pci_attr_r32(int devind, int port); |
245 |
void pci_attr_w8(int devind, int port, u8_t value); |
246 |
void pci_attr_w16(int devind, int port, u16_t value); |
247 |
void pci_attr_w32(int devind, int port, u32_t value); |
248 |
char *pci_dev_name(u16_t vid, u16_t did);
|
249 |
char *pci_slot_name(int devind); |
250 |
int pci_set_acl(struct rs_pci *rs_pci); |
251 |
int pci_del_acl(endpoint_t proc_ep);
|
252 |
int pci_get_bar(int devind, int port, u32_t *base, u32_t *size, int |
253 |
*ioflag); |
254 |
|
255 |
/* Profiling. */
|
256 |
int sys_sprof(int action, int size, int freq, int type, endpoint_t |
257 |
endpt, vir_bytes ctl_ptr, vir_bytes mem_ptr); |
258 |
|
259 |
/* machine context */
|
260 |
int sys_getmcontext(endpoint_t proc, vir_bytes mcp);
|
261 |
int sys_setmcontext(endpoint_t proc, vir_bytes mcp);
|
262 |
|
263 |
/* input */
|
264 |
int tty_input_inject(int type, int code, int val); |
265 |
|
266 |
/* Miscellaneous calls from servers and drivers. */
|
267 |
pid_t srv_fork(uid_t reuid, gid_t regid); |
268 |
int srv_kill(pid_t pid, int sig); |
269 |
int getprocnr(pid_t pid, endpoint_t *proc_ep);
|
270 |
int mapdriver(const char *label, devmajor_t major, const int *domains, |
271 |
int nr_domains);
|
272 |
pid_t getepinfo(endpoint_t proc_ep, uid_t *uidp, gid_t *gidp); |
273 |
pid_t getnpid(endpoint_t proc_ep); |
274 |
uid_t getnuid(endpoint_t proc_ep); |
275 |
gid_t getngid(endpoint_t proc_ep); |
276 |
int getsockcred(endpoint_t proc_ep, struct sockcred * sockcred, gid_t * groups, |
277 |
int ngroups);
|
278 |
int socketpath(endpoint_t endpt, const char *path, size_t size, int what, |
279 |
dev_t *dev, ino_t *ino); |
280 |
#define SPATH_CHECK 0 /* check user permissions on socket path */ |
281 |
#define SPATH_CREATE 1 /* create socket file at given path */ |
282 |
int copyfd(endpoint_t endpt, int fd, int what); |
283 |
#define COPYFD_FROM 0 /* copy file descriptor from remote process */ |
284 |
#define COPYFD_TO 1 /* copy file descriptor to remote process */ |
285 |
#define COPYFD_CLOSE 2 /* close file descriptor in remote process */ |
286 |
#define COPYFD_CLOEXEC 0x8000 /* with COPYFD_TO: set close-on-exec flag */ |
287 |
#define COPYFD_FLAGS 0xF000 /* flags mask */ |
288 |
int closenb(int fd); |
289 |
|
290 |
/*
|
291 |
* These are also the event numbers used in PROC_EVENT messages, but in order
|
292 |
* to allow for subscriptions to multiple events, they form a bit mask.
|
293 |
*/
|
294 |
#define PROC_EVENT_EXIT 0x01 /* process has exited */ |
295 |
#define PROC_EVENT_SIGNAL 0x02 /* process has caught signal */ |
296 |
int proceventmask(unsigned int mask); |
297 |
|
298 |
#endif /* _SYSLIB_H */ |
299 |
|