aboutsummaryrefslogtreecommitdiff
path: root/include/kmi/uapi.h
blob: 1ec69db2105e53ab2c6cb7bd8d7bd18363f4b952 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
/* SPDX-License-Identifier: copyleft-next-0.3.1 */
/* Copyright 2021 - 2022, Kim Kuparinen < kimi.h.kuparinen@gmail.com > */

#ifndef KMI_UAPI_H
#define KMI_UAPI_H

/**
 * @file uapi.h
 * Userspace api, syscall declarations.
 */

#include <kmi/syscalls.h>
#include <kmi/vmem.h>

/**
 * Syscall function type.
 * Let's start with five arguments and see where that goes
 */
typedef void (*sys_t)(struct tcb *t, long, long, long, long, long);

/**
 * Syscall argument type.
 *
 * \todo: Should this be arch specific? should be the size of an integer
 * register.
 */
typedef long sys_arg_t;

/**
 * Return structure of syscall.
 * \note Field names are generic, and can be used for whatever,
 * check documentation of whatever you're doing.
 * @todo should this be placed into syscalls.h?
 */
struct sys_ret {
	/** Status. */
	sys_arg_t s;

	/** First argument. */
	sys_arg_t ar0;

	/** Second argument. */
	sys_arg_t ar1;

	/** Third argument. */
	sys_arg_t ar2;

	/** Fourth argument. */
	sys_arg_t ar3;

	/** Fifth argument. */
	sys_arg_t ar4;
};

/** Helper for returning sys_ret with 0 arguments. */
#define SYS_RET0() (struct sys_ret){0, 0, 0, 0, 0, 0}

/** Helper for returning sys_ret with 1 arguments. */
#define SYS_RET1(a) (struct sys_ret){a, 0, 0, 0, 0, 0}

/** Helper for returning sys_ret with 2 arguments. */
#define SYS_RET2(a, b) (struct sys_ret){a, b, 0, 0, 0, 0}

/** Helper for returning sys_ret with 3 arguments. */
#define SYS_RET3(a, b, c) (struct sys_ret){a, b, c, 0, 0, 0}

/** Helper for returning sys_ret with 4 arguments. */
#define SYS_RET4(a, b, c, d) (struct sys_ret){a, b, c, d, 0, 0}

/** Helper for returning sys_ret with 5 arguments. */
#define SYS_RET5(a, b, c, d, e) (struct sys_ret){a, b, c, d, e, 0}

/** Helper for returning sys_ret with 6 arguments. */
#define SYS_RET6(a, b, c, d, e, f) (struct sys_ret){a, b, c, d, e, f}

/**
 * Helper macro for declaring syscalls with zero arguments.
 *
 * The idea is that all syscalls externally have the same amount of arguments,
 * but then by using some helper macros (see below) we can make actually
 * implementing the syscall more intuitive and less noisy.
 *
 * @param name Name of syscall.
 */
#define SYSCALL_DECLARE0(name)         \
	void sys_##name(struct tcb *t, \
	                sys_arg_t a,   \
	                sys_arg_t b,   \
	                sys_arg_t c,   \
	                sys_arg_t d,   \
	                sys_arg_t e);

/**
 * Helper macro for declaring syscalls with one argument.
 *
 * @param name Name of syscall.
 * @param a Name of argument.
 */
#define SYSCALL_DECLARE1(name, a)                                \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e);

/**
 * Helper macro for declaring syscalls with two arguments.
 *
 * @param name Name of syscall.
 * @param a Name of first argument.
 * @param b Name of second argument.
 */
#define SYSCALL_DECLARE2(name, a, b)                             \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e);

/**
 * Helper macro for declaring syscalls with three arguments.
 *
 * @param name Name of syscall.
 * @param a Name of first argument.
 * @param b Name of second argument.
 * @param c Name of third argument.
 */
#define SYSCALL_DECLARE3(name, a, b, c)                          \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e);

/**
 * Helper macro for declaring syscalls with four arguments.
 *
 * @param name Name of syscall.
 * @param a Name of first argument.
 * @param b Name of second argument.
 * @param c Name of third argument.
 * @param d Name of fourth argument.
 */
#define SYSCALL_DECLARE4(name, a, b, c, d)                       \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e);

/**
 * Helper macro for declaring syscalls with five arguments.
 *
 * @param name Name of syscall.
 * @param a Name of first argument.
 * @param b Name of second argument.
 * @param c Name of third argument.
 * @param d Name of fourth argument.
 * @param e Name of fifth argument.
 */
#define SYSCALL_DECLARE5(name, a, b, c, d, e)                    \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e);

/**
 * Helper macro for defining syscall with zero arguments.
 *
 * @param name Name of syscall.
 */
#define SYSCALL_DEFINE0(name)                                    \
	static inline void __##name(struct tcb *t);              \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e)                \
	{                                                        \
		UNUSED(a);                                       \
		UNUSED(b);                                       \
		UNUSED(c);                                       \
		UNUSED(d);                                       \
		UNUSED(e);                                       \
		__##name(t);                                     \
	}                                                        \
	static inline void __##name

/**
 * Helper macro for defining syscall with one argument.
 *
 * @param name Name of syscall.
 */
#define SYSCALL_DEFINE1(name)                                    \
	static inline void __##name(struct tcb *, sys_arg_t);    \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e)                \
	{                                                        \
		UNUSED(b);                                       \
		UNUSED(c);                                       \
		UNUSED(d);                                       \
		UNUSED(e);                                       \
		__##name(t, a);                                  \
	}                                                        \
	static inline void __##name

/**
 * Helper macro for defining syscall with two arguments.
 *
 * @param name Name of syscall.
 */
#define SYSCALL_DEFINE2(name)                                    \
	static inline void __##name(struct tcb *, sys_arg_t,     \
	                            sys_arg_t);                  \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e)                \
	{                                                        \
		UNUSED(c);                                       \
		UNUSED(d);                                       \
		UNUSED(e);                                       \
		__##name(t, a, b);                               \
	}                                                        \
	static inline void __##name

/**
 * Helper macro for defining syscall with three arguments.
 *
 * @param name Name of syscall.
 */
#define SYSCALL_DEFINE3(name)                                    \
	static inline void __##name(struct tcb *, sys_arg_t,     \
	                            sys_arg_t,                   \
	                            sys_arg_t);                  \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e)                \
	{                                                        \
		UNUSED(d);                                       \
		UNUSED(e);                                       \
		__##name(t, a, b, c);                            \
	}                                                        \
	static inline void __##name

/**
 * Helper macro for defining syscall with four arguments.
 *
 * @param name Name of syscall.
 */
#define SYSCALL_DEFINE4(name)                                    \
	static inline void __##name(struct tcb *, sys_arg_t,     \
	                            sys_arg_t, sys_arg_t,        \
	                            sys_arg_t);                  \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e)                \
	{                                                        \
		UNUSED(e);                                       \
		__##name(t, a, b, c, d);                         \
	}                                                        \
	static inline void __##name

/**
 * Helper macro for defining syscall with five arguments.
 *
 * @param name Name of syscall.
 */
#define SYSCALL_DEFINE5(name)                                    \
	static inline void __##name(struct tcb *, sys_arg_t,     \
	                            sys_arg_t, sys_arg_t,        \
	                            sys_arg_t, sys_arg_t);       \
	void sys_##name(struct tcb *t, sys_arg_t a, sys_arg_t b, \
	                sys_arg_t c,                             \
	                sys_arg_t d, sys_arg_t e)                \
	{                                                        \
		__##name(t, a, b, c, d, e);                      \
	}                                                        \
	static void __##name

/** @name Misc syscalls. */
/** @{ */

/**
 * Noop syscall.
 *
 * @param t Current tcb.
 * @param a Unused.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and 0.
 */
SYSCALL_DECLARE0(noop);

/**
 * Putch syscall.
 *
 * @param t Current tcb.
 * @param ch Character to put.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and 0.
 */
SYSCALL_DECLARE1(putch, ch);

/** @} */

/* @name Memory handling syscalls. */
/** @{ */
/**
 * Request memory syscall.
 *
 * Allocates at least the specified size of allocation to current effective
 * process.
 *
 * @param t Current tcb.
 * @param size Size of allocation.
 * @param flags Flags of allocation.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and start of memory allocation.
 */
SYSCALL_DECLARE2(req_mem, size, flags);

/**
 * Request one page of memory. The nearest fitting size is chosen.
 *
 * This might be better implemented as some number of adjacent physical pages,
 * but the underlying physical page allocator doesn't really handle it very
 * well. This weird design decision is because I don't know if there are devices
 * whose drivers need multiple adjacent physical pages, only that at least
 * virtio devices need to be able to access the physical address of a single
 * page. Basic adjacent physical pages can be made from higher order pages,
 * just with a massive overhead. Still, probably good eough for now.
 *
 * For example, if you need two adjacent 4K pages, you pass size = 8K and you
 * get back a 2M page, if one is available.
 *
 * @param t Current tcb.
 * @param size Required size of region.
 * @param flags Mapping flags to use.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref ERR_OOMEM if no page is available, otherwise \c OK, virtual
 * address, actual size, physical size in that order.
 */
SYSCALL_DECLARE2(req_page, size, flags);

/**
 * Request physical memory syscall.
 *
 * Allocates at least the specified size of allocation which includes the
 * physical start address somewhere in the allocation to the current effective
 * process.
 *
 * @param t Current tcb.
 * @param paddr Start of physical allocation.
 * @param size Size of physical allocation.
 * @param flags Flags of physical allocation.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and start of memory allocation.
 */
SYSCALL_DECLARE3(req_pmem, paddr, size, flags);

/**
 * Request fixed memory syscall.
 *
 * Allocates at least the specified size of allocation which includes the start
 * address of allocation to the current effective process.
 *
 * @param t Current tcb.
 * @param start Start of allocation.
 * @param size Size of allocation.
 * @param flags Flags of allocation.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and start of memory allocation.
 */
SYSCALL_DECLARE3(req_fixmem, start, size, flags);

/**
 * Request shared memory syscall.
 *
 * Allocates a region that can be shared between different processes, that is at
 * least the specified size of allocation. When clients are freeing memory, the
 * underlying physical allocation will not be freed unless the owning reference
 * (server) frees it.
 *
 * @param t Current tcb.
 * @param tid Thread to share memory with.
 * @param size Size of allocation.
 * @param sflags Flags of allocation for server, that is \p t.
 * @param cflags Flags of allocation for client, that is \p tid.
 * @param e Unused.
 *
 * Returns \ref OK and start of memory allocation.
 */
SYSCALL_DECLARE4(req_sharedmem, tid, size, sflags, cflags);

/**
 * Free memory syscall.
 *
 * Frees the memory region pointed to.
 *
 * @param t Current tcb.
 * @param start Start of memory.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and 0.
 */
SYSCALL_DECLARE1(free_mem, start);
/** @} */

/** @name Timer syscalls. */
/** @{ */
/**
 * Get timer accuracy in Hertz syscall.
 *
 * @param t Current tcb.
 * @param a Unused.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and frequency.
 * \todo Should this be some kind of config request instead of a separate
 * syscall?
 */
SYSCALL_DECLARE0(timebase);

/**
 * Get current ticks.
 *
 * @param t Current tcb.
 * @param a Unused.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns current ticks.
 */
SYSCALL_DECLARE0(ticks);

/**
 * Request relative timer syscall.
 *
 * Request timer that triggers a number of ticks in the future.
 *
 * @param t Current tcb.
 * @param ticks Number of ticks from now.
 * @param mult Number of times to trigger.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and ID of timer.
 */
SYSCALL_DECLARE2(req_rel_timer, ticks, mult);

/**
 * Request absolute timer syscall.
 *
 * Request timer that triggers at some absolute timepoint.
 *
 * @param t Current tcb.
 * @param ticks Timepoint.
 * @param mult Multiplier.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and ID of timer.
 * \todo Check repeat value.
 */
SYSCALL_DECLARE2(req_abs_timer, ticks, mult);

/**
 * Free timer syscall.
 *
 * @param t Current tcb.
 * @param cid ID of timer to free.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK.
 */
SYSCALL_DECLARE1(free_timer, cid);
/** @} */

/** @name IPC syscalls. */
/** @{ */
/**
 * Report process status as server syscall.
 *
 * @param t Current tcb.
 * @param callback Callback to request handler.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK.
 */
SYSCALL_DECLARE1(ipc_server, callback);

/**
 * Request syscall.
 *
 * @param t Current tcb.
 * @param pid Request target process.
 * @param d0 First request argument.
 * @param d1 Second request argument.
 * @param d2 Third forwarding argument.
 * @param d3 Fourth forwarding argument.
 *
 * Returns \ref OK and whatever the server sends back on success, otherwise some
 * other status value.
 */
SYSCALL_DECLARE5(ipc_req, pid, d0, d1, d2, d3);

/**
 * Forwarding syscall.
 *
 * In a server request handler, do a request to some other server on behalf of
 * whoever called us up.
 *
 * @param t Current tcb.
 * @param pid Forwarding target process.
 * @param d0 First forwarding argument.
 * @param d1 Second forwarding argument.
 * @param d2 Third forwarding argument.
 * @param d3 Fourth forwarding argument.
 *
 * Returns \ref OK and whatever the server sends back on success, otherwise some
 * other status value.
 */
SYSCALL_DECLARE5(ipc_fwd, pid, d0, d1, d2, d3);

/**
 * Response syscall.
 *
 * @param t Current tcb.
 * @param d0 First response argument.
 * @param d1 Second response argument.
 * @param d2 Third response argument.
 * @param d3 Fourth response argument.
 * @param e Unused.
 *
 * Returns \c d0 and \c d1.
 */
SYSCALL_DECLARE4(ipc_resp, d0, d1, d2, d3);

/**
 * Notify thread syscall.
 *
 * @param t Current tcb.
 * @param tid Thread ID to notify.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and 0.
 */
SYSCALL_DECLARE1(ipc_notify, tid);
/** @} */

/** @name Process handling syscalls. */
/** @{ */
/**
 * Create thread syscall.
 *
 * Creates thread in current effective process context.
 *
 * @param t Current tcb.
 * @param func Function to call on startup.
 * @param d0 Argument 0.
 * @param d1 Argument 1.
 * @param d2 Argument 2.
 * @param d3 Argument 3.
 *
 * Returns \ref OK and 0.
 * \todo Should this take stack size etc?
 */
SYSCALL_DECLARE5(create, func, d0, d1, d2, d3);

/**
 * Fork process syscall.
 *
 * Forks a process, much like in *nix systems.
 *
 * @param t Current tcb.
 * @param a Unused.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and 0.
 */
SYSCALL_DECLARE0(fork);

/**
 * Execute binary syscall.
 *
 * Executes a new binary in existing process space.
 *
 * @param t Current tcb.
 * @param bin Address of binary.
 * @param interp Optional address of interpreter.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and 0.
 * \todo Check other return codes.
 */
SYSCALL_DECLARE2(exec, bin, interp);

/**
 * Spawn binary syscall. Try to prefer over unixy fork/exec.
 *
 * Executes a new binary in new process space.
 *
 * @param t Current tcb.
 * @param bin Address of binary.
 * @param interp Optional address of interpreter.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Retuns \ref OK and 0.
 * \todo Check other return codes.
 */
SYSCALL_DECLARE2(spawn, bin, interp);

/**
 * Kill syscall.
 *
 * @param t Current tcb.
 * @param tid Thread ID to kill. 0 if self.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK if not called on itself, otherwise doesn't return.
 */
SYSCALL_DECLARE1(kill, tid);

/**
 * Swap syscall.
 *
 * Swap currently running thread.
 *
 * @param t Current tcb.
 * @param tid Thread to swap to.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and 0.
 */
SYSCALL_DECLARE1(swap, tid);

/** @} */

/** @name Configuration syscalls. */
/** @{ */
/**
 * Set configuration syscall.
 *
 * Set some runtime parameter.
 *
 * @param t Current tcb.
 * @param param Parameter to set.
 * @param val Value to set parameter to.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK and 0.
 */
SYSCALL_DECLARE2(conf_set, param, val);

/**
 * Get configuration syscall.
 *
 * Get some runtime parameter.
 *
 * @param t Current tcb.
 * @param param Parameter to get.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK.
 */
SYSCALL_DECLARE1(conf_get, param);

/**
 * Set capabilities.
 *
 * @param t Current tcb.
 * @param tid Thread ID whose capabilities to set.
 * @param off Offset of capability, multiple of \c bits(cap).
 * @param caps Mask of capabilities to set.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK on success, \ref ERR_INVAL on invalid input.
 */
SYSCALL_DECLARE3(set_cap, tid, off, caps);

/**
 * Get capabilities.
 *
 * @param t Current tcb.
 * @param tid Thread ID whose capabilities to get.
 * @param off Offset of capability, multiple of \c bits(cap).
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK, capabilities.
 */
SYSCALL_DECLARE2(get_cap, tid, off);

/**
 * Clear capabilities.
 *
 * @param t Current tcb.
 * @param tid Thread ID whose capabilities to clear.
 * @param off Offset of capability, multiple of \c bits(cap).
 * @param cap Mask of capabilities to clear.
 * @param d Unused.
 * @param e Unused.
 *
 * Returns \ref OK.
 */
SYSCALL_DECLARE3(clear_cap, tid, off, cap);

/**
 * Power off syscall.
 *
 * Either shut down or reboot system.
 *
 * @param t Current tcb.
 * @param type Type of shutdown. \see poweroff_type.
 * @param b Unused.
 * @param c Unused.
 * @param d Unused.
 * @param e Unused.
 *
 * Shouldn't return at all.
 */
SYSCALL_DECLARE1(poweroff, type);
/** @} */

/**
 * Dispatch to correct syscall handler.
 *
 * @param syscall Syscall number.
 * @param a Syscall argument 0.
 * @param b Syscall argument 1.
 * @param c Syscall argument 2.
 * @param d Syscall argument 3.
 * @param e Syscall argument 4.
 * @param t Current tcb.
 * Returns whatever the specified syscall returns.
 */
void handle_syscall(sys_arg_t syscall, sys_arg_t a, sys_arg_t b,
                    sys_arg_t c, sys_arg_t d, sys_arg_t e, struct tcb *t);

/** \todo Should I add variable names as well, to make the documentation a bit
 * more readable? */

#include <arch/proc.h>
#define return_args(t, x) {set_args((t), (x)); return;}

#endif /* KMI_UAPI_H */