managarm/hel
Loading...
Searching...
No Matches
hel.h
Go to the documentation of this file.
1
3
4#ifndef HEL_H
5#define HEL_H
6
7#include <stddef.h>
8#include <string.h>
9#include <stdint.h>
10
11#include "hel-types.h"
12
13#ifdef __cplusplus
14#define HEL_C_LINKAGE extern "C"
15#else
16#define HEL_C_LINKAGE
17#endif
18
19enum {
20 // largest system call number plus 1
21 kHelNumCalls = 113,
22
23 kHelCallLog = 1,
24 kHelCallPanic = 10,
25
26 kHelCallNop = 2,
27 kHelCallSubmitAsyncNop = 3,
28
29 kHelCallCreateUniverse = 62,
30 kHelCallTransferDescriptor = 66,
31 kHelCallDescriptorInfo = 32,
32 kHelCallGetCredentials = 84,
33 kHelCallCloseDescriptor = 21,
34 kHelCallObtainHandle = 4,
35
36 kHelCallCreateQueue = 89,
37 kHelCallDriveQueue = 105,
38 kHelCallAlertQueue = 106,
39
40 kHelCallAllocateMemory = 51,
41 kHelCallResizeMemory = 83,
42 kHelCallCreateManagedMemory = 64,
43 kHelCallCopyOnWrite = 39,
44 kHelCallAccessPhysical = 30,
45 kHelCallCreateSliceView = 88,
46 kHelCallForkMemory = 40,
47 kHelCallCreateSpace = 27,
48 kHelCallCreateDmaSpace = 108,
49 kHelCallConfigureIrq = 109,
50 kHelCallCreateIndirectMemory = 45,
51 kHelCallAlterMemoryIndirection = 52,
52 kHelCallMapMemory = 44,
53 kHelCallSubmitProtectMemory = 99,
54 kHelCallSubmitSynchronizeSpace = 53,
55 kHelCallUnmapMemory = 36,
56 kHelCallPointerPhysical = 43,
57 kHelCallSubmitReadMemory = 77,
58 kHelCallSubmitWriteMemory = 78,
59 kHelCallMemoryInfo = 26,
60 kHelCallSubmitManageMemory = 46,
61 kHelCallUpdateMemory = 47,
62 kHelCallSubmitLockMemoryView = 48,
63 kHelCallLoadahead = 49,
64 kHelCallCreateVirtualizedSpace = 50,
65 kHelCallCreateSwapSpace = 110,
66 kHelCallAllocateSwappableMemory = 111,
67
68 kHelCallAccessIommu = 13,
69
70 kHelCallCreateThread = 67,
71 kHelCallQueryThreadStats = 95,
72 kHelCallSetPriority = 85,
73 kHelCallYield = 34,
74 kHelCallSubmitObserve = 74,
75 kHelCallKillThread = 87,
76 kHelCallInterruptThread = 86,
77 kHelCallResume = 61,
78 kHelCallLoadRegisters = 75,
79 kHelCallStoreRegisters = 76,
80 kHelCallQueryRegisterInfo = 102,
81 kHelCallWriteFsBase = 41,
82 kHelCallGetClock = 42,
83 kHelCallSubmitAwaitClock = 80,
84 kHelCallCreateVirtualizedCpu = 37,
85 kHelCallRunVirtualizedCpu = 38,
86 kHelCallAssertVirtualizedIrq = 107,
87 kHelCallGetRandomBytes = 101,
88 kHelCallWriteGsBase = 54,
89 kHelCallReadFsBase = 55,
90 kHelCallReadGsBase = 56,
91 kHelCallGetCurrentCpu = 57,
92
93 kHelCallCreateStream = 68,
94 kHelCallSubmitAsync = 79,
95 kHelCallShutdownLane = 91,
96
97 kHelCallFutexWait = 73,
98 kHelCallFutexWake = 71,
99
100 kHelCallCreateOneshotEvent = 96,
101 kHelCallCreateBitsetEvent = 97,
102 kHelCallCreateSequencedEvent = 15,
103 kHelCallRaiseEvent = 98,
104 kHelCallAccessIrq = 14,
105 kHelCallHandleIrq = 5,
106 kHelCallAcknowledgeIrq = 81,
107 kHelCallSubmitAwaitEvent = 82,
108 kHelCallAutomateIrq = 94,
109 kHelCallQueryMsiInfo = 6,
110
111 kHelCallAccessIo = 11,
112 kHelCallEnableIo = 12,
113
114 kHelCallBindKernlet = 93,
115
116 kHelCallGetAffinity = 103,
117 kHelCallSetAffinity = 100,
118
119 kHelCallCreateToken = 104,
120
121 kHelCallExtendHierarchy = 7,
122
123 kHelCallSuper = 0x80000000
124};
125
126enum {
127 kHelErrNone = 0,
128 kHelErrBufferTooSmall = 1,
129 kHelErrBadDescriptor = 2,
130 kHelErrTimeout = 3,
131 kHelErrNoDescriptor = 4,
132 kHelErrIllegalSyscall = 5,
133 kHelErrIllegalObject = 6,
134 kHelErrIllegalArgs = 7,
135 kHelErrLaneShutdown = 8,
136 kHelErrEndOfLane = 9,
137 kHelErrFault = 10,
138 kHelErrThreadTerminated = 11,
139 kHelErrCancelled = 12,
140 kHelErrTransmissionMismatch = 13,
141 kHelErrQueueTooSmall = 14,
142 kHelErrIllegalState = 15,
143 kHelErrNoHardwareSupport = 16,
144 kHelErrNoMemory = 17,
145 kHelErrUnsupportedOperation = 18,
146 kHelErrOutOfBounds = 19,
147 kHelErrDismissed = 20,
148 kHelErrRemoteFault = 21,
149 kHelErrAlreadyExists = 22,
150 kHelErrBadPermissions = 23,
151 kHelErrOther = 24,
152 kHelErrFutexRace = 25,
153 kHelErrBadRights = 26,
154};
155
156typedef uint32_t HelRights;
157
158// No right but easier to recognize in code than a zero literal.
159// - General: descriptor properties can be queried without any rights.
160// - Memory view: memory size can be queried without any rights.
161// - Thread: statistics can be queried without any rights.
162static const HelRights kHelRightNull = 0;
163// Right to map into an object.
164// - Universe: required to transfer into the universe.
165// - Universe: required to close descriptors in the universe.
166// - Universe: required to create a thread in the universe.
167// - Address space: required to map into the space.
168// - Address space: required to change memory protection.
169// - Virtualized space: required to map into the space.
170// - DMA space: required to map into the space.
171static const HelRights kHelRightGrant = UINT32_C(1) << 0;
172// Right to map from an object.
173// - Universe: required to transfer out of the universe.
174// - Universe: required to create a thread in the universe.
175static const HelRights kHelRightTake = UINT32_C(1) << 1;
176// Right to read data.
177// - IPC queue: required to map readable.
178// - Memory view: required to read.
179// - Memory view: required to map readable.
180// - Memory view: required to create copy-on-write view.
181// - Memory view: required to map into indirect memory.
182// - Memory slice: required to map readable.
183// - Memory slice: required to map into indirect memory.
184// - Address space: required to read from it.
185// - Address space: required to create thread.
186// - Virtualized space: required to read from it.
187// - I/O objects: required to enable userspace I/O.
188// - Thread: required to read registers.
189// - Thread: required to read memory in its address space.
190// - Thread: required to get the affinity.
191// - Virtualized CPUs: required to read registers.
192static const HelRights kHelRightRead = UINT32_C(1) << 2;
193// Right to write data.
194// - IPC queue: required to map writeable.
195// - Memory view: required to write.
196// - Memory view: required to map writeable.
197// - Memory view: required to map into indirect memory.
198// - Memory slice: required to map writeable.
199// - Memory slice: required to map into indirect memory.
200// - Address space: required to write to it.
201// - Address space: required to create thread.
202// - Virtualized space: required to write to it.
203// - I/O objects: required to enable userspace I/O.
204// - Thread: required to write registers.
205// - Thread: required to write memory in its address space.
206// - Thread: required to set the affinity.
207// - Virtualized CPUs: required to write registers.
208static const HelRights kHelRightWrite = UINT32_C(1) << 3;
209// Right to execute code.
210// - Memory view: required to map executable.
211// - Memory slice: required to map executable.
212static const HelRights kHelRightExecute = UINT32_C(1) << 4;
213// Right to execute operations.
214// - IPC queue: required to submit.
215// - Lane: required to do exchange messages.
216// - Virtualized CPUs: required to run.
217static const HelRights kHelRightInvoke = UINT32_C(1) << 5;
218// Right to build new objects on top of existing ones.
219// - IPC queue: required to map.
220// - Universe: required to create thread.
221// - Address space: required to create thread.
222// - Memory view: required to map.
223// - Memory view: required to create copy-on-write view.
224// - Memory view: required to map into indirect memory.
225// - Memory view: required to create slice.
226// - Memory view: required to bind to kernlet.
227// - IRQ pin: required to install an IRQ handler.
228// - Memory slice: required to map.
229// - Memory slice: required to map into indirect memory.
230// - Swap space: required to allocate memory backed by it.
231// - Virtualized space: required to create virtualized CPU.
232// - I/O objects: required to enable userspace I/O.
233// - Kernlets: required to create a bound kernlet from it.
234// - Bound kernlets: required to attach to an IRQ.
235static const HelRights kHelRightAssign = UINT32_C(1) << 6;
236// Right to derive new objects that affect the original one.
237// - Memory view: required to fork.
238// - Hierarchy: required to extend it by a child hierarchy node.
239static const HelRights kHelRightDerive = UINT32_C(1) << 7;
240// Right to add, remove or manipulate components.
241// - Memory views: required to perform loadahead.
242// - Address space: required to synchronize.
243// - Address space: required to resolve physical addresses.
244// - DMA space: required to populate.
245// - DMA space: required to resolve physical addresses.
246// - Hierarchy: required to charge resources to it.
247static const HelRights kHelRightProvision = UINT32_C(1) << 8;
248// Right to pin memory pages.
249// - Memory view: required to pin pages.
250static const HelRights kHelRightPin = UINT32_C(1) << 9;
251// Right to perform memory fences.
252// - Memory view: required for fences.
253static const HelRights kHelRightFence = UINT32_C(1) << 10;
254// Right to wait on an object.
255// - IPC queue: required to drive.
256// - Thread: required to observe.
257// - Event: required to wait.
258// - IRQ: required to wait.
259// - IRQ: required to attach a kernlet.
260static const HelRights kHelRightWait = UINT32_C(1) << 11;
261// Right to signal an object.
262// - IPC queue: required to alert.
263// - Thread: required to interrupt.
264// - Event: required to raise.
265// - Event: required to bind to kernlet.
266// - IRQ: required to acknowledge.
267// - IRQ: required to attach a kernlet.
268// - Virtualized CPUs: required to raise an interrupt.
269static const HelRights kHelRightSignal = UINT32_C(1) << 12;
270// Right to manage an object (includes potentially destructive operations).
271// - Lane: required to shut down.
272// - Memory view: required to resize.
273// - Memory view: required to manage.
274// - Memory view: required to invalidate.
275// - Swap space: required to attach or detach swap regions.
276// - Thread: required to set priority.
277// - Thread: required to resume.
278// - Thread: required to kill.
279// - IRQ pin: required to configure the IRQ.
280// - IRQ pin: required to obtain MSI address and data words.
281static const HelRights kHelRightManage = UINT32_C(1) << 13;
282// All rights (even unspecified ones). Easier to recognize in code than a literal.
283static const HelRights kHelRightsMax = ~UINT32_C(0);
284
285struct HelX86SegmentRegister {
286 uint64_t base;
287 uint32_t limit;
288 uint16_t selector;
289 uint8_t type, present, dpl, db, s, l, g, avl;
290};
291
292struct HelX86DescriptorTable {
293 uint64_t base;
294 uint16_t limit;
295};
296
297struct HelX86VirtualizationRegs {
298 uint64_t rax;
299 uint64_t rbx;
300 uint64_t rcx;
301 uint64_t rdx;
302 uint64_t rsi;
303 uint64_t rdi;
304 uint64_t rbp;
305 uint64_t r8;
306 uint64_t r9;
307 uint64_t r10;
308 uint64_t r11;
309 uint64_t r12;
310 uint64_t r13;
311 uint64_t r14;
312 uint64_t r15;
313
314 uint64_t rsp;
315 uint64_t rip;
316 uint64_t rflags;
317
318 struct HelX86SegmentRegister cs, ds, es, fs, gs, ss;
319 struct HelX86SegmentRegister tr, ldt;
320 struct HelX86DescriptorTable gdt, idt;
321
322 uint64_t cr0, cr2, cr3, cr4, cr8;
323 uint64_t efer;
324 uint64_t apic_base;
325};
326
327struct HelRiscv64VirtualizationRegs {
328 union {
329 uint64_t x[32];
330
331 struct {
332 uint64_t zero;
333 uint64_t ra;
334 uint64_t sp;
335 uint64_t gp;
336 uint64_t tp;
337 uint64_t t0;
338 uint64_t t1;
339 uint64_t t2;
340 uint64_t s0;
341 uint64_t s1;
342 uint64_t a0;
343 uint64_t a1;
344 uint64_t a2;
345 uint64_t a3;
346 uint64_t a4;
347 uint64_t a5;
348 uint64_t a6;
349 uint64_t a7;
350 uint64_t s2;
351 uint64_t s3;
352 uint64_t s4;
353 uint64_t s5;
354 uint64_t s6;
355 uint64_t s7;
356 uint64_t s8;
357 uint64_t s9;
358 uint64_t s10;
359 uint64_t s11;
360 uint64_t t3;
361 uint64_t t4;
362 uint64_t t5;
363 uint64_t t6;
364 };
365 };
366
367 uint64_t pc;
368 uint8_t kernelMode;
369
370 // CSRs
371 uint64_t sstatus;
372 uint64_t sie;
373 uint64_t stvec;
374 uint64_t sscratch;
375 uint64_t sepc;
376 uint64_t scause;
377 uint64_t stval;
378 uint64_t sip;
379 uint64_t satp;
380 uint64_t stimecmp;
381};
382
383#if defined(__riscv) && __riscv_xlen == 64
384typedef struct HelRiscv64VirtualizationRegs HelVirtualizationRegs;
385#else
386typedef struct HelX86VirtualizationRegs HelVirtualizationRegs;
387#endif
388
389enum {
390 kHelNullHandle = 0,
391 kHelThisUniverse = -1,
392 kHelThisThread = -2
393};
394
395enum {
396 kHelWaitInfinite = -1
397};
398
399enum {
400 kHelActionNone = 0,
401 kHelActionDismiss = 11,
402 kHelActionOffer = 5,
403 kHelActionAccept = 6,
404 kHelActionImbueCredentials = 8,
405 kHelActionExtractCredentials = 9,
406 kHelActionSendFromBuffer = 1,
407 kHelActionSendFromBufferSg = 10,
408 kHelActionRecvInline = 7,
409 kHelActionRecvToBuffer = 3,
410 kHelActionPushDescriptor = 2,
411 kHelActionPullDescriptor = 4
412};
413
414enum {
415 kHelItemChain = 1,
416 kHelItemAncillary = 2,
417 kHelItemWantLane = (1 << 16),
418};
419
420static const uint32_t kHelTransferDescriptorOut = UINT32_C(1) << 0;
421static const uint32_t kHelTransferDescriptorIn = UINT32_C(1) << 1;
422
423enum {
424 kHelObtainZeroMemory = 1,
425 kHelObtainClockPage = 2
426};
427
429enum {
439 kHelClockTime = 4
441
452 uint64_t seqlock;
454 uint32_t clockType;
456 int32_t tickShift;
458 uint64_t tickFactor;
459};
460
461struct HelSgItem {
462 void *buffer;
463 size_t length;
464};
465
466struct HelAction {
467 int type;
468 uint32_t flags;
469 // TODO: It may be worth to restructure this to a union of structs
470 // (e.g., a HelActionDataBufferSize, HelActionDataDescriptorRights, ...),
471 // but that requires simultaneous mlibc and Managarm changes.
472 union {
473 uintptr_t word0;
474 void *buffer;
475 };
476 union {
477 uintptr_t word1;
478 size_t length;
479 // For kHelPushDescriptor, kHelPullDescriptor.
480 uint32_t rights;
481 };
482 union {
483 uintptr_t word2;
484 // For kHelActionImbueCredentials, kHelPushDescriptor, kHelPullDescriptor.
485 HelHandle handle;
486 };
487};
488
489struct HelDescriptorInfo {
490 int type;
491};
492
493enum HelAllocFlags {
494 kHelAllocContinuous = 4,
495 kHelAllocOnDemand = 1,
496};
497
498struct HelAllocRestrictions {
499 int addressBits;
500};
501
502enum HelManagedFlags {
503 kHelManagedReadahead = 1
504};
505
506enum HelManageRequests {
507 kHelManageInitialize = 1,
508 kHelManageWriteback = 2
509};
510
518
520 // Additional flags that may be set.
521 kHelMapProtRead = UINT32_C(1) << 8,
522 kHelMapProtWrite = UINT32_C(1) << 9,
523 kHelMapProtExecute = UINT32_C(1) << 10,
524 kHelMapDontRequireBacking = UINT32_C(1) << 7,
525 kHelMapFixed = UINT32_C(1) << 11,
526 kHelMapFixedNoReplace = UINT32_C(1) << 12,
527 kHelMapPreferBottom = UINT32_C(1) << 13,
530 kHelMapNoDirtyTracking = UINT32_C(1) << 14
532
533enum HelSliceFlags {
534 kHelSliceCacheWriteCombine = 1,
535};
536
537enum HelCachingMode {
538 kHelCachingDefault = 0,
539 kHelCachingUncached = 1,
540 kHelCachingWriteCombine = 2,
541 kHelCachingWriteThrough = 3,
542 kHelCachingWriteBack = 4,
543 kHelCachingMmio = 5,
544 kHelCachingMmioNonPosted = 6
545};
546
547enum HelThreadFlags {
548 kHelThreadStopped = 1
549};
550
551enum HelObservation {
552 kHelObserveNull = 0,
553 kHelObserveInterrupt = 4,
554 kHelObservePanic = 3,
555 kHelObserveBreakpoint = 1,
556 kHelObservePageFault = 2,
557 kHelObserveGeneralFault = 5,
558 kHelObserveIllegalInstruction = 6,
559 kHelObserveDivByZero = 7,
560 kHelObserveSuperCall = 0x80000000
561};
562
563enum HelRegisterSets {
564 kHelRegsProgram = 1,
565 kHelRegsGeneral = 2,
566 kHelRegsThread = 3,
567 kHelRegsDebug = 4,
568 kHelRegsVirtualization = 5,
569 kHelRegsSimd = 6,
570 kHelRegsSignal = 7,
571 kHelRegsPageFault = 8
572};
573
574enum HelPageFaultFlags {
575 kHelPageFaultMapError = 1,
576 kHelPageFaultAccessError = 2,
577 kHelPageFaultOutOfMemory = 3
578};
579
584};
585
586#if defined(__x86_64__)
587enum HelRegisterIndex {
588 kHelRegRax = 0,
589 kHelRegRbx = 1,
590 kHelRegRcx = 2,
591 kHelRegRdx = 3,
592 kHelRegRdi = 4,
593 kHelRegRsi = 5,
594 kHelRegR8 = 6,
595 kHelRegR9 = 7,
596 kHelRegR10 = 8,
597 kHelRegR11 = 9,
598 kHelRegR12 = 10,
599 kHelRegR13 = 11,
600 kHelRegR14 = 12,
601 kHelRegR15 = 13,
602 kHelRegRbp = 14,
603
604 kHelNumGprs = 15,
605
606 kHelRegIp = 0,
607 kHelRegSp = 1
608};
609
610enum HelSyscallArgs {
611 kHelRegNumber = kHelRegRdi,
612 kHelRegError = kHelRegRdi,
613
614 kHelRegArg0 = kHelRegRsi,
615 kHelRegArg1 = kHelRegRdx,
616 kHelRegArg2 = kHelRegRax,
617 kHelRegArg3 = kHelRegR8,
618 kHelRegArg4 = kHelRegR9,
619 kHelRegArg5 = kHelRegR10,
620 kHelRegArg6 = kHelRegR12,
621 kHelRegArg7 = kHelRegR13,
622 kHelRegArg8 = kHelRegR14,
623
624 kHelRegOut0 = kHelRegRsi,
625 kHelRegOut1 = kHelRegRdx,
626 kHelRegOut2 = kHelRegRax
627};
628
629#elif defined(__aarch64__)
630enum HelRegisterIndex {
631 kHelRegX0 = 0,
632 kHelRegX1,
633 kHelRegX2,
634 kHelRegX3,
635 kHelRegX4,
636 kHelRegX5,
637 kHelRegX6,
638 kHelRegX7,
639 kHelRegX8,
640 kHelRegX9,
641 kHelRegX10,
642 kHelRegX11,
643 kHelRegX12,
644 kHelRegX13,
645 kHelRegX14,
646 kHelRegX15,
647 kHelRegX16,
648 kHelRegX17,
649 kHelRegX18,
650 kHelRegX19,
651 kHelRegX20,
652 kHelRegX21,
653 kHelRegX22,
654 kHelRegX23,
655 kHelRegX24,
656 kHelRegX25,
657 kHelRegX26,
658 kHelRegX27,
659 kHelRegX28,
660 kHelRegX29,
661 kHelRegX30,
662
663 kHelNumGprs = 31,
664
665 kHelRegIp = 0,
666 kHelRegSp = 1
667};
668
669enum HelSyscallArgs {
670 kHelRegNumber = kHelRegX0,
671 kHelRegError = kHelRegX0,
672
673 kHelRegArg0 = kHelRegX1,
674 kHelRegArg1 = kHelRegX2,
675 kHelRegArg2 = kHelRegX3,
676 kHelRegArg3 = kHelRegX4,
677 kHelRegArg4 = kHelRegX5,
678 kHelRegArg5 = kHelRegX6,
679 kHelRegArg6 = kHelRegX7,
680 kHelRegArg7 = kHelRegX8,
681 kHelRegArg8 = kHelRegX9,
682
683 kHelRegOut0 = kHelRegX1,
684 kHelRegOut1 = kHelRegX2,
685 kHelRegOut2 = kHelRegX3
686};
687
688#elif defined(__riscv) && __riscv_xlen == 64
689enum HelRegisterIndex {
690 kHelRegRa = 0,
691 kHelRegGp,
692 kHelRegTp,
693 kHelRegT0,
694 kHelRegT1,
695 kHelRegT2,
696 kHelRegS0,
697 kHelRegS1,
698 kHelRegA0,
699 kHelRegA1,
700 kHelRegA2,
701 kHelRegA3,
702 kHelRegA4,
703 kHelRegA5,
704 kHelRegA6,
705 kHelRegA7,
706 kHelRegS2,
707 kHelRegS3,
708 kHelRegS4,
709 kHelRegS5,
710 kHelRegS6,
711 kHelRegS7,
712 kHelRegS8,
713 kHelRegS9,
714 kHelRegS10,
715 kHelRegS11,
716 kHelRegT3,
717 kHelRegT4,
718 kHelRegT5,
719 kHelRegT6,
720 kHelNumGprs,
721 kHelRegIp = 0,
722 kHelRegSp = 1
723};
724enum HelSyscallArgs {
725 kHelRegNumber = kHelRegA0,
726 kHelRegError = kHelRegA0,
727 kHelRegArg0 = kHelRegA1,
728 kHelRegArg1 = kHelRegA2,
729 kHelRegArg2 = kHelRegA3,
730 kHelRegArg3 = kHelRegA4,
731 kHelRegArg4 = kHelRegA5,
732 kHelRegArg5 = kHelRegA6,
733 kHelRegArg6 = kHelRegA7,
734 kHelRegArg7 = kHelRegS2,
735 kHelRegArg8 = kHelRegS3,
736
737 kHelRegOut0 = kHelRegA1,
738 kHelRegOut1 = kHelRegA2,
739 kHelRegOut2 = kHelRegA3
740};
741
742#endif
743
744struct HelQueueParameters {
745 uint32_t flags;
746 unsigned int numChunks;
747 size_t chunkSize;
748 unsigned int numSqChunks;
749};
750
752static const uint32_t kHelHierarchyMemoryController = UINT32_C(1) << 0;
753
754struct HelHierarchyParameters {
755 // Optional tag to identify the hierarchy in kernel messages.
756 // Null-terminated unless it fills the entire array.
757 char tag[128];
758 // Bitmask of controllers that we want to enable.
759 uint32_t controllers;
760 // Only used with kHelHierarchyMemoryController; must be zero otherwise.
761 // Allocations of the hierarchy and its descendants wait (or fail) unless memoryFloor bytes
762 // of memory stay free on top of the kernel's own reserve.
763 // This keeps memory available to hierarchies with lower floors.
764 // The effective floor is the maximum over this floor and any parent floor.
765 size_t memoryFloor;
766};
767
769static const int kHelUserNotifyCqProgress = (1 << 0);
771static const int kHelUserNotifySupplySqChunks = (1 << 1);
773static const int kHelUserNotifyError = (1 << 14);
775static const int kHelUserNotifyAlert = (1 << 15);
776
778static const int kHelKernelNotifySqProgress = (1 << 0);
780static const int kHelKernelNotifySupplyCqChunks = (1 << 1);
781
783static const uint32_t kHelDriveWait = (1 << 0);
784
785enum {
786 kHelAccessIommuIntelVtd = 1,
787 kHelAccessIommuAmdVi = 2,
788};
789
790enum {
791 kHelDmaRegionRead = 1,
792 kHelDmaRegionWrite = 2,
793};
794
797 uint64_t base;
798 uint64_t size;
799 uint32_t flags;
800};
801
804 uint32_t segment;
805 uint8_t bus;
806 uint8_t slot;
807 uint8_t function;
808};
809
811static const uint32_t kHelSubmitCancel = 256;
813static const uint32_t kHelSubmitAsyncNop = 1;
815static const uint32_t kHelSubmitExchangeMsgs = 2;
817static const uint32_t kHelSubmitAwaitClock = 3;
819static const uint32_t kHelSubmitAwaitEvent = 4;
821static const uint32_t kHelSubmitProtectMemory = 5;
823static const uint32_t kHelSubmitSynchronizeSpace = 6;
825static const uint32_t kHelSubmitReadMemory = 7;
827static const uint32_t kHelSubmitWriteMemory = 8;
829static const uint32_t kHelSubmitManageMemory = 9;
831static const uint32_t kHelSubmitLockMemoryView = 10;
833static const uint32_t kHelSubmitObserve = 11;
835static const uint32_t kHelSubmitResizeMemory = 12;
837static const uint32_t kHelSubmitForkMemory = 13;
839static const uint32_t kHelSubmitWritebackFence = 14;
841static const uint32_t kHelSubmitInvalidateMemory = 15;
843static const uint32_t kHelSubmitPopulateSpace = 16;
845static const uint32_t kHelSubmitMapMemory = 17;
847static const uint32_t kHelSubmitUnmapMemory = 18;
849static const uint32_t kHelSubmitBindDmaDevice = 19;
851static const uint32_t kHelSubmitUnbindDmaDevice = 20;
853static const uint32_t kHelSubmitActivateIommu = 21;
855static const uint32_t kHelSubmitSetSwapRegion = 23;
856
858struct HelQueue {
863
868
872
876};
877
879static const int kHelNextPresent = (1 << 24);
880
882static const int kHelProgressMask = 0xFFFFFF;
884static const int kHelProgressDone = (1 << 25);
886static const int kHelProgressFull = (1 << 26);
887
888struct HelChunk {
891 int next;
892
894 int progressFutex;
895
897 char buffer[];
898};
899
903 unsigned int length;
905 unsigned int opcode;
907 void *context;
908};
909
912 uint64_t cancellationTag;
913};
914
919 HelHandle lane;
921 size_t count;
923 uint32_t flags;
924};
925
929 uint64_t counter;
932};
933
937 HelHandle handle;
939 uint64_t sequence;
942};
943
947 HelHandle spaceHandle;
949 void *pointer;
951 size_t size;
953 uint32_t flags;
954};
955
959 HelHandle spaceHandle;
961 void *pointer;
963 size_t size;
964};
965
969 HelHandle handle;
971 uintptr_t address;
973 size_t length;
975 void *buffer;
976};
977
981 HelHandle handle;
983 uintptr_t address;
985 size_t length;
987 const void *buffer;
988};
989
993 HelHandle handle;
994};
995
999 HelHandle handle;
1001 uintptr_t offset;
1003 size_t size;
1004};
1005
1009 HelHandle handle;
1010};
1011
1015 HelHandle handle;
1017 size_t newSize;
1018};
1019
1025 HelHandle handle;
1026};
1027
1032 HelHandle handle;
1034 uintptr_t offset;
1036 size_t size;
1037};
1038
1040static const uint32_t kHelInvalidateNoWriteback = 1;
1041
1045 HelHandle handle;
1047 uintptr_t offset;
1049 size_t size;
1051 uint32_t flags;
1052};
1053
1057 HelHandle handle;
1059 uintptr_t address;
1061 size_t length;
1062};
1063
1067 HelHandle memoryHandle;
1069 HelHandle spaceHandle;
1071 void *pointer;
1073 uintptr_t offset;
1075 size_t size;
1077 uint32_t flags;
1078};
1079
1083 HelHandle spaceHandle;
1085 void *pointer;
1087 size_t size;
1088};
1089
1102
1112
1119 HelHandle iommuHandle;
1120};
1121
1125static const int kHelSwapRegionShift = 44;
1127static const uint32_t kHelNumSwapRegions = 1 << 18;
1128
1136 HelHandle swapHandle;
1140 size_t numPages;
1142 uint32_t region;
1143};
1144
1145struct HelSimpleResult {
1146 HelError error;
1147 int reserved;
1148};
1149
1150struct HelCredentialsResult {
1151 HelError error;
1152 int reserved;
1153 char credentials[16];
1154};
1155
1156struct HelManageResult {
1157 HelError error;
1158 int type;
1159 uintptr_t offset;
1160 size_t length;
1161};
1162
1163struct HelObserveResult {
1164 HelError error;
1165 unsigned int observation;
1166};
1167
1168struct HelInlineResult {
1169 HelError error;
1170 int reserved;
1171 size_t length;
1172 char data[];
1173};
1174
1175struct HelInlineResultNoFlex {
1176 HelError error;
1177 int reserved;
1178 size_t length;
1179};
1180
1181struct HelLengthResult {
1182 HelError error;
1183 int reserved;
1184 size_t length;
1185};
1186
1187struct HelHandleResult {
1188 HelError error;
1189 int reserved;
1190 HelHandle handle;
1191};
1192
1193struct HelPointerResult {
1194 HelError error;
1195 int reserved;
1196 void *pointer;
1197};
1198
1199struct HelEventResult {
1200 HelError error;
1201 uint32_t bitset;
1202 uint64_t sequence;
1203};
1204
1205enum HelAckFlags {
1206 kHelAckAcknowledge = 2,
1207 kHelAckNack = 3,
1208 kHelAckKick = 1,
1209 kHelAckClear = 0x100,
1210};
1211
1212union HelKernletData {
1213 HelHandle handle;
1214};
1215
1216struct HelThreadStats {
1217 uint64_t userTime;
1218};
1219
1220enum {
1221 kHelVmexitHlt = 0,
1222 kHelVmexitTranslationFault = 1,
1223 kHelVmexitHyperCall = 2,
1224 kHelVmexitInstructionTrap = 3,
1225 kHelVmexitError = -1,
1226 kHelVmexitUnknownPlatformSpecificExitCode = -2,
1227};
1228
1229enum {
1230 kHelVmFaultRead = 1 << 0,
1231 kHelVmFaultWrite = 1 << 1,
1232 kHelVmFaultExecute = 1 << 2,
1233};
1234
1235#if defined(__riscv) && __riscv_xlen == 64
1236
1237struct HelVmexitReason {
1238 uint32_t exitReason;
1239 // If bit 63 is set then stores a compressed unexpanded instruction,
1240 // otherwise stores a normal 32-bit instruction (possibly originally compressed in which case bits 1:0 aren't 0b11).
1241 uint64_t instruction;
1242 size_t address;
1243 size_t flags;
1244};
1245
1246#else
1247
1248struct HelVmexitReason {
1249 uint32_t exitReason;
1250 uint32_t code;
1251 size_t address;
1252 size_t flags;
1253};
1254
1255#endif
1256
1257// see RFC 5424
1258enum HelLogSeverity {
1259 kHelLogSeverityEmergency,
1260 kHelLogSeverityAlert,
1261 kHelLogSeverityCritical,
1262 kHelLogSeverityError,
1263 kHelLogSeverityWarning,
1264 kHelLogSeverityNotice,
1265 kHelLogSeverityInfo,
1266 kHelLogSeverityDebug,
1267};
1268
1269enum {
1270 kHelAccessIrqByGsi = 1,
1271 kHelAccessIrqByPhandle = 2,
1272 kHelAccessIrqAllocateMsi = 3,
1273};
1274
1276enum {
1277 kHelIrqNameSize = 32,
1278};
1279
1280enum {
1281 kHelIrqTriggerNull = 0,
1282 kHelIrqTriggerEdge = 1,
1283 kHelIrqTriggerLevel = 2
1284};
1285
1286enum {
1287 kHelIrqPolarityNull = 0,
1288 kHelIrqPolarityHigh = 1,
1289 kHelIrqPolarityLow = 2
1290};
1291
1294 uint64_t address;
1295 uint32_t data;
1296};
1297
1300
1308HEL_C_LINKAGE HelError helLog(const enum HelLogSeverity severity, const char *string, size_t length);
1309
1315HEL_C_LINKAGE void helPanic(const char *string, size_t length)
1316 __attribute__ (( noreturn ));
1317
1321
1323HEL_C_LINKAGE HelError helNop();
1324
1328HEL_C_LINKAGE HelError helSubmitAsyncNop(HelHandle queueHandle, uintptr_t context);
1329
1337HEL_C_LINKAGE HelError helExtendHierarchy(HelHandle hierarchyHandle,
1338 const struct HelHierarchyParameters *params, HelHandle *handle);
1339
1343
1347HEL_C_LINKAGE HelError helCreateUniverse(HelHandle *handle);
1348
1356HEL_C_LINKAGE HelError
1357helTransferDescriptor(HelHandle handle, HelHandle universeHandle,
1358 uint32_t flags, uint32_t exposedRights, uint32_t requiredRights, HelHandle *outHandle);
1359
1360HEL_C_LINKAGE HelError helDescriptorInfo(HelHandle handle, struct HelDescriptorInfo *info);
1361
1367HEL_C_LINKAGE HelError helGetCredentials(HelHandle handle, uint32_t flags,
1368 char *credentials);
1369
1375HEL_C_LINKAGE HelError helCloseDescriptor(HelHandle universeHandle, HelHandle handle);
1376
1382HEL_C_LINKAGE HelError helObtainHandle(int kind, HelHandle *handle);
1383
1387
1393HEL_C_LINKAGE HelError helCreateQueue(const struct HelQueueParameters *params,
1394 HelHandle *handle);
1395
1407HEL_C_LINKAGE HelError helDriveQueue(HelHandle queueHandle, uint32_t flags, uint32_t notifyMask);
1408
1415HEL_C_LINKAGE HelError helAlertQueue(HelHandle queueHandle);
1416
1420
1433HEL_C_LINKAGE HelError helAllocateMemory(HelHandle hierarchy, size_t size, uint32_t flags,
1434 const struct HelAllocRestrictions *restrictions, HelHandle *handle);
1435
1442HEL_C_LINKAGE HelError helResizeMemory(HelHandle handle, size_t newSize);
1443
1458HEL_C_LINKAGE HelError helCreateManagedMemory(HelHandle hierarchy, size_t size, uint32_t flags,
1459 HelHandle *backingHandle, HelHandle *frontalHandle);
1460
1482HEL_C_LINKAGE HelError helCreateSwapSpace(HelHandle hierarchy, uint32_t flags,
1483 HelHandle *backingHandle, HelHandle *swapHandle);
1484
1500HEL_C_LINKAGE HelError helAllocateSwappableMemory(HelHandle hierarchy, HelHandle swapSpace,
1501 size_t size, uint32_t flags, HelHandle *handle);
1502
1521HEL_C_LINKAGE HelError helCopyOnWrite(HelHandle hierarchy, HelHandle swapSpace, HelHandle memory,
1522 uintptr_t offset, size_t size, HelHandle *handle);
1523
1524HEL_C_LINKAGE HelError helAccessPhysical(
1525 HelHandle accessToken, uintptr_t physical, size_t size, uint32_t cachingMode, HelHandle *handle
1526);
1527
1533HEL_C_LINKAGE HelError helCreateIndirectMemory(size_t numSlots, HelHandle *handle);
1534
1551HEL_C_LINKAGE HelError helAlterMemoryIndirection(HelHandle indirectHandle, size_t slotIndex,
1552 HelHandle memoryHandle, uintptr_t offset, size_t size);
1553
1554HEL_C_LINKAGE HelError helCreateSliceView(HelHandle bundle, uintptr_t offset, size_t size,
1555 uint32_t flags, HelHandle *handle);
1556
1564HEL_C_LINKAGE HelError helForkMemory(HelHandle handle, HelHandle *forkedHandle);
1565
1569HEL_C_LINKAGE HelError helCreateSpace(HelHandle *handle);
1570
1580HEL_C_LINKAGE HelError helAccessIommu(HelHandle accessHandle, uint32_t mode, uint64_t base,
1581 HelHandle *handle);
1582
1602HEL_C_LINKAGE HelError helCreateDmaSpace(HelHandle iommuHandle,
1603 const struct HelDmaReservedRegion *regions, size_t numRegions,
1604 uint32_t flags, HelHandle *handle);
1605
1623HEL_C_LINKAGE HelError helMapMemory(HelHandle memoryHandle, HelHandle spaceHandle,
1624 void *pointer, uintptr_t offset, size_t size, uint32_t flags, void **actualPointer);
1625
1626
1637HEL_C_LINKAGE HelError helUnmapMemory(HelHandle spaceHandle, void *pointer, size_t size);
1638
1639HEL_C_LINKAGE HelError helPointerPhysical(HelHandle spaceHandle, const void *pointer, uintptr_t *physical);
1640
1641HEL_C_LINKAGE HelError helMemoryInfo(HelHandle handle,
1642 size_t *size);
1643
1644HEL_C_LINKAGE HelError helUpdateMemory(HelHandle handle, int type, uintptr_t offset, size_t length);
1645
1656HEL_C_LINKAGE HelError helLoadahead(HelHandle handle, uintptr_t offset, size_t length);
1657
1658HEL_C_LINKAGE HelError helCreateVirtualizedSpace(HelHandle *handle);
1659
1663
1678HEL_C_LINKAGE HelError helCreateThread(HelHandle hierarchy, HelHandle universe,
1679 HelHandle spaceHandle, void *ip, void *sp, uint32_t flags, HelHandle *handle);
1680
1686HEL_C_LINKAGE HelError helQueryThreadStats(HelHandle handle, struct HelThreadStats *stats);
1687
1696HEL_C_LINKAGE HelError helSetPriority(HelHandle handle, int priority);
1697
1699HEL_C_LINKAGE HelError helYield();
1700
1704HEL_C_LINKAGE HelError helKillThread(HelHandle handle);
1705
1712HEL_C_LINKAGE HelError helInterruptThread(HelHandle handle);
1713
1720HEL_C_LINKAGE HelError helResume(HelHandle handle);
1721
1729HEL_C_LINKAGE HelError helLoadRegisters(HelHandle handle, int set, void *image);
1730
1738HEL_C_LINKAGE HelError helStoreRegisters(HelHandle handle, int set, const void *image);
1739
1742// Register set to query information for.
1745HEL_C_LINKAGE HelError helQueryRegisterInfo(int set, struct HelRegisterInfo *info);
1746
1747HEL_C_LINKAGE HelError helWriteFsBase(void *pointer);
1748
1749HEL_C_LINKAGE HelError helReadFsBase(void **pointer);
1750
1751HEL_C_LINKAGE HelError helWriteGsBase(void *pointer);
1752
1753HEL_C_LINKAGE HelError helReadGsBase(void **pointer);
1754
1756HEL_C_LINKAGE HelError helGetCurrentCpu(int *cpu);
1757
1762HEL_C_LINKAGE HelError helGetClock(uint64_t *counter);
1763
1764HEL_C_LINKAGE HelError helCreateVirtualizedCpu(HelHandle handle, HelHandle *out_handle);
1765
1766HEL_C_LINKAGE HelError helRunVirtualizedCpu(HelHandle handle, struct HelVmexitReason *reason);
1767
1768HEL_C_LINKAGE HelError helAssertVirtualizedIrq(HelHandle handle, uint64_t irq, uint8_t level);
1769
1770HEL_C_LINKAGE HelError helGetRandomBytes(void *buffer, size_t wantedSize, size_t *actualSize);
1771
1781HEL_C_LINKAGE HelError helGetAffinity(HelHandle handle, uint8_t *mask, size_t size, size_t *actualSize);
1782
1790HEL_C_LINKAGE HelError helSetAffinity(HelHandle handle, uint8_t *mask, size_t size);
1791
1795
1803HEL_C_LINKAGE HelError helCreateStream(HelHandle *lane1, HelHandle *lane2, uint32_t attach_credentials);
1804
1805HEL_C_LINKAGE HelError helShutdownLane(HelHandle handle);
1806
1814HEL_C_LINKAGE HelError helCreateToken(HelHandle *handle);
1815
1819
1828HEL_C_LINKAGE HelError helFutexWait(int *pointer, int expected, int64_t deadline);
1829
1835HEL_C_LINKAGE HelError helFutexWake(int *pointer, unsigned int count);
1836
1840
1844HEL_C_LINKAGE HelError helCreateOneshotEvent(HelHandle *handle);
1845
1849HEL_C_LINKAGE HelError helCreateBitsetEvent(HelHandle *handle);
1850
1861HEL_C_LINKAGE HelError helCreateSequencedEvent(HelHandle *waitHandle, HelHandle *raiseHandle);
1862
1867HEL_C_LINKAGE HelError helRaiseEvent(HelHandle handle);
1868
1889HEL_C_LINKAGE HelError helAccessIrq(
1890 HelHandle accessHandle, uint32_t mode, uint64_t controller, uint64_t index,
1891 const char *name, HelHandle *handle
1892);
1893
1899HEL_C_LINKAGE HelError helHandleIrq(HelHandle pinHandle, HelHandle *handle);
1900
1912HEL_C_LINKAGE HelError helConfigureIrq(HelHandle pinHandle, uint32_t trigger, uint32_t polarity);
1913
1920HEL_C_LINKAGE HelError helQueryMsiInfo(HelHandle pinHandle, struct HelMsiInfo *info);
1921
1922HEL_C_LINKAGE HelError helAcknowledgeIrq(HelHandle handle, uint32_t flags, uint64_t sequence);
1923
1924HEL_C_LINKAGE HelError helAutomateIrq(HelHandle handle, uint32_t flags, HelHandle kernlet);
1925
1929
1930HEL_C_LINKAGE HelError helAccessIo(
1931 HelHandle accessToken, const uintptr_t *portArray, size_t numPorts, HelHandle *handle
1932);
1933
1937HEL_C_LINKAGE HelError helEnableIo(HelHandle handle);
1938
1942
1952HEL_C_LINKAGE HelError helBindKernlet(HelHandle handle,
1953 const union HelKernletData *data, size_t numData, HelHandle *boundHandle);
1954
1956
1957extern inline __attribute__ (( always_inline )) const char *_helErrorString(HelError code) {
1958 switch(code) {
1959 case kHelErrNone:
1960 return "Success";
1961 case kHelErrIllegalSyscall:
1962 return "Illegal syscall";
1963 case kHelErrIllegalArgs:
1964 return "Illegal arguments";
1965 case kHelErrIllegalState:
1966 return "Illegal state";
1967 case kHelErrUnsupportedOperation:
1968 return "Unsupported operation";
1969 case kHelErrNoDescriptor:
1970 return "No such descriptor";
1971 case kHelErrBadDescriptor:
1972 return "Illegal descriptor for this operation";
1973 case kHelErrThreadTerminated:
1974 return "Thread terminated already";
1975 case kHelErrLaneShutdown:
1976 return "Lane shutdown";
1977 case kHelErrEndOfLane:
1978 return "End of lane";
1979 case kHelErrDismissed:
1980 return "IPC item dismissed by remote";
1981 case kHelErrBufferTooSmall:
1982 return "Buffer too small";
1983 case kHelErrQueueTooSmall:
1984 return "Buffer too small";
1985 case kHelErrFault:
1986 return "Segfault";
1987 case kHelErrNoHardwareSupport:
1988 return "Missing hardware support for this feature";
1989 case kHelErrNoMemory:
1990 return "Out of memory";
1991 case kHelErrTransmissionMismatch:
1992 return "Transmission mismatch";
1993 case kHelErrCancelled:
1994 return "Cancelled";
1995 case kHelErrOutOfBounds:
1996 return "Out of bounds";
1997 case kHelErrAlreadyExists:
1998 return "Already exists";
1999 case kHelErrBadRights:
2000 return "Missing rights for this operation";
2001 default:
2002 return 0;
2003 }
2004}
2005
2006extern inline __attribute__ (( always_inline )) void _helCheckFailed(HelError err_code,
2007 const char *string, int fatal) {
2008 helLog(kHelLogSeverityError, string, strlen(string));
2009
2010 const char *err_string = _helErrorString(err_code);
2011 if(err_string == 0)
2012 err_string = "(Unexpected error code)";
2013 helLog(kHelLogSeverityError, err_string, strlen(err_string));
2014 helLog(kHelLogSeverityError, "\n", 1);
2015
2016 if(fatal)
2017 helPanic(0, 0);
2018}
2019
2020#define HEL_STRINGIFY_AUX(x) #x
2021#define HEL_STRINGIFY(x) HEL_STRINGIFY_AUX(x)
2022
2023#define HEL_CHECK(expr) do { HelError __error = expr; if(__error != kHelErrNone) \
2024 _helCheckFailed(__error, "HEL_CHECK failed: " #expr "\n" \
2025 " In file " __FILE__ " on line " HEL_STRINGIFY(__LINE__) "\n", 1); } while(0)
2026#define HEL_SOFT_CHECK(expr) do { HelError __error = expr; if(__error != kHelErrNone) \
2027 _helCheckFailed(__error, "HEL_SOFT_CHECK failed: " #expr "\n" \
2028 " In file " __FILE__ " on line " HEL_STRINGIFY(__LINE__) "\n", 0); } while(0)
2029
2030#endif // HEL_H
2031
@ kHelClockTsc
x86: TSC.
Definition hel.h:433
@ kHelClockCntvct
ARM: virtual counter (CNTVCT_EL0).
Definition hel.h:437
@ kHelClockCntpct
ARM: physical counter (CNTPCT_EL0).
Definition hel.h:435
@ kHelClockNone
No clock that is accessible to userspace (= helGetClock() has to be used).
Definition hel.h:431
@ kHelClockTime
RISC-V: time CSR.
Definition hel.h:439
HEL_C_LINKAGE HelError helLog(const enum HelLogSeverity severity, const char *string, size_t length)
Writes a text message (e.g., a line of text) to the kernel's log.
HEL_C_LINKAGE HelError helSetPriority(HelHandle handle, int priority)
Set the priority of a thread.
HEL_C_LINKAGE HelError helYield()
Yields the current thread.
HEL_C_LINKAGE HelError helQueryMsiInfo(HelHandle pinHandle, struct HelMsiInfo *info)
Retrieves the message address and data of an MSI pin.
HEL_C_LINKAGE HelError helAccessIrq(HelHandle accessHandle, uint32_t mode, uint64_t controller, uint64_t index, const char *name, HelHandle *handle)
Access the IRQ pin that an IRQ is attached to.
HEL_C_LINKAGE HelError helConfigureIrq(HelHandle pinHandle, uint32_t trigger, uint32_t polarity)
Configure the trigger mode and polarity of an IRQ pin.
static const int kHelUserNotifyAlert
Set in userNotify when the queue is alerted.
Definition hel.h:775
HEL_C_LINKAGE HelError helTransferDescriptor(HelHandle handle, HelHandle universeHandle, uint32_t flags, uint32_t exposedRights, uint32_t requiredRights, HelHandle *outHandle)
Copies descriptors from the current universe to another universe.
HEL_C_LINKAGE HelError helCloseDescriptor(HelHandle universeHandle, HelHandle handle)
Closes a descriptor.
HEL_C_LINKAGE HelError helQueryRegisterInfo(int set, struct HelRegisterInfo *info)
Query register-related information.
HEL_C_LINKAGE HelError helMapMemory(HelHandle memoryHandle, HelHandle spaceHandle, void *pointer, uintptr_t offset, size_t size, uint32_t flags, void **actualPointer)
Maps memory objects into an address space.
HEL_C_LINKAGE HelError helSetAffinity(HelHandle handle, uint8_t *mask, size_t size)
Set a thread's CPU affinity mask.
static const int kHelSwapRegionShift
Byte offset (((uint64_t)r << kHelSwapRegionShift) + o) in the backing memory of a swap space addresse...
Definition hel.h:1125
static const uint32_t kHelNumSwapRegions
Number of swap regions per swap space.
Definition hel.h:1127
static const int kHelKernelNotifySqProgress
Set in kernelNotify after userspace has added SQ elements.
Definition hel.h:778
static const uint32_t kHelSubmitInvalidateMemory
SQ opcode: invalidate memory.
Definition hel.h:841
HEL_C_LINKAGE HelError helQueryThreadStats(HelHandle handle, struct HelThreadStats *stats)
Query run-time statistics of a thread.
HEL_C_LINKAGE HelError helAlterMemoryIndirection(HelHandle indirectHandle, size_t slotIndex, HelHandle memoryHandle, uintptr_t offset, size_t size)
Modifies indirect memory objects.
HEL_C_LINKAGE HelError helCreateBitsetEvent(HelHandle *handle)
Create an event consisting of multiple bits that can fire independently.
static const uint32_t kHelInvalidateNoWriteback
Flag for kHelSubmitInvalidateMemory: discard dirty pages instead of writing them back.
Definition hel.h:1040
HEL_C_LINKAGE HelError helGetCredentials(HelHandle handle, uint32_t flags, char *credentials)
Returns the credentials associated with a given descriptor.
HEL_C_LINKAGE HelError helKillThread(HelHandle handle)
Kill (i.e., terminate) a thread.
static const uint32_t kHelSubmitWriteMemory
SQ opcode: write memory.
Definition hel.h:827
static const uint32_t kHelSubmitUnmapMemory
SQ opcode: unmap memory.
Definition hel.h:847
HEL_C_LINKAGE HelError helObtainHandle(int kind, HelHandle *handle)
Obtains a descriptor to one of the kernel's global objects.
HEL_C_LINKAGE HelError helCreateDmaSpace(HelHandle iommuHandle, const struct HelDmaReservedRegion *regions, size_t numRegions, uint32_t flags, HelHandle *handle)
Creates a DMA space that memory can be mapped into for device DMA.
HEL_C_LINKAGE HelError helGetAffinity(HelHandle handle, uint8_t *mask, size_t size, size_t *actualSize)
Get a thread's CPU affinity mask.
static const uint32_t kHelSubmitAsyncNop
SQ opcode: asynchronous no-op (for testing/profiling).
Definition hel.h:813
HEL_C_LINKAGE HelError helAccessIommu(HelHandle accessHandle, uint32_t mode, uint64_t base, HelHandle *handle)
Access an IOMMU that the kernel discovered from firmware.
HEL_C_LINKAGE HelError helGetClock(uint64_t *counter)
Read the system-wide monotone clock.
HEL_C_LINKAGE HelError helLoadahead(HelHandle handle, uintptr_t offset, size_t length)
Notifies the kernel that a certain range of memory should be preloaded.
HEL_C_LINKAGE HelError helCopyOnWrite(HelHandle hierarchy, HelHandle swapSpace, HelHandle memory, uintptr_t offset, size_t size, HelHandle *handle)
Creates memory object that obtains its memory by copy-on-write from another memory object.
HEL_C_LINKAGE HelError helLoadRegisters(HelHandle handle, int set, void *image)
Load a register image (e.g., from a thread).
HEL_C_LINKAGE void helPanic(const char *string, size_t length) __attribute__((noreturn))
Kills the current thread and writes an error message to the kernel's log.
HEL_C_LINKAGE HelError helUnmapMemory(HelHandle spaceHandle, void *pointer, size_t size)
Unmaps memory from an address space.
HEL_C_LINKAGE HelError helAllocateSwappableMemory(HelHandle hierarchy, HelHandle swapSpace, size_t size, uint32_t flags, HelHandle *handle)
Allocates memory that behaves like helAllocateMemory() but is backed by a swap space: under memory pr...
HEL_C_LINKAGE HelError helFutexWake(int *pointer, unsigned int count)
Wakes up all waiters of a futex.
HEL_C_LINKAGE HelError helResizeMemory(HelHandle handle, size_t newSize)
Resizes a memory object.
static const int kHelProgressMask
Mask to extract the number of valid bytes in the chunk.
Definition hel.h:882
static const uint32_t kHelSubmitManageMemory
SQ opcode: manage memory.
Definition hel.h:829
static const uint32_t kHelSubmitForkMemory
SQ opcode: fork memory.
Definition hel.h:837
HEL_C_LINKAGE HelError helInterruptThread(HelHandle handle)
Interrupt a thread.
static const int kHelProgressFull
Set by the producer once the chunk is full (i.e., no more bytes will be written).
Definition hel.h:886
static const uint32_t kHelSubmitUnbindDmaDevice
SQ opcode: block the DMA requests of a device.
Definition hel.h:851
static const uint32_t kHelSubmitSynchronizeSpace
SQ opcode: synchronize space.
Definition hel.h:823
HEL_C_LINKAGE HelError helRaiseEvent(HelHandle handle)
Raise an event.
static const uint32_t kHelDriveWait
Flag for helDriveQueue: wait until userNotify has any bits not in notifyMask set.
Definition hel.h:783
static const uint32_t kHelSubmitObserve
SQ opcode: observe thread.
Definition hel.h:833
HEL_C_LINKAGE HelError helForkMemory(HelHandle handle, HelHandle *forkedHandle)
Forks memory objects, i.e., copies them using copy-on-write.
HEL_C_LINKAGE HelError helCreateQueue(const struct HelQueueParameters *params, HelHandle *handle)
Creates an IPC queue.
HEL_C_LINKAGE HelError helCreateToken(HelHandle *handle)
Create a token object.
static const uint32_t kHelSubmitBindDmaDevice
SQ opcode: bind a device to a DMA space.
Definition hel.h:849
HEL_C_LINKAGE HelError helResume(HelHandle handle)
Resume a suspended thread.
static const uint32_t kHelSubmitExchangeMsgs
SQ opcode: exchange messages on a stream.
Definition hel.h:815
static const uint32_t kHelSubmitReadMemory
SQ opcode: read memory.
Definition hel.h:825
static const int kHelNextPresent
Marks the next field as present.
Definition hel.h:879
static const int kHelKernelNotifySupplyCqChunks
Set in kernelNotify after userspace has supplied new chunks.
Definition hel.h:780
HEL_C_LINKAGE HelError helSubmitAsyncNop(HelHandle queueHandle, uintptr_t context)
Does nothing, asynchronously (useful only for profiling).
HEL_C_LINKAGE HelError helHandleIrq(HelHandle pinHandle, HelHandle *handle)
Install an IRQ handler on an IRQ pin.
HEL_C_LINKAGE HelError helStoreRegisters(HelHandle handle, int set, const void *image)
Store a register image (e.g., to a thread).
static const uint32_t kHelSubmitAwaitEvent
SQ opcode: wait for an event.
Definition hel.h:819
static const uint32_t kHelSubmitAwaitClock
SQ opcode: wait for time to pass.
Definition hel.h:817
static const uint32_t kHelSubmitPopulateSpace
SQ opcode: populate a space.
Definition hel.h:843
HEL_C_LINKAGE HelError helAlertQueue(HelHandle queueHandle)
Alerts an IPC queue.
static const uint32_t kHelSubmitActivateIommu
SQ opcode: activate translation on an IOMMU.
Definition hel.h:853
HEL_C_LINKAGE HelError helCreateStream(HelHandle *lane1, HelHandle *lane2, uint32_t attach_credentials)
Create a stream (which always consists of two lanes).
static const uint32_t kHelSubmitProtectMemory
SQ opcode: protect memory.
Definition hel.h:821
HelMapFlags
Definition hel.h:519
@ kHelMapNoDirtyTracking
Discards the mapping's dirty bits instead of scheduling the pages for writeback.
Definition hel.h:530
static const uint32_t kHelSubmitMapMemory
SQ opcode: map memory.
Definition hel.h:845
static const int kHelUserNotifySupplySqChunks
Set in userNotify after kernel has supplied new SQ chunks.
Definition hel.h:771
HEL_C_LINKAGE HelError helCreateIndirectMemory(size_t numSlots, HelHandle *handle)
Creates a memory object that obtains its memory by delegating to other memory objects.
HEL_C_LINKAGE HelError helGetCurrentCpu(int *cpu)
Gets the index of the cpu which the calling thread is running on.
HEL_C_LINKAGE HelError helNop()
Does nothing (useful only for profiling).
HEL_C_LINKAGE HelError helFutexWait(int *pointer, int expected, int64_t deadline)
Waits on a futex.
HEL_C_LINKAGE HelError helBindKernlet(HelHandle handle, const union HelKernletData *data, size_t numData, HelHandle *boundHandle)
Bind parameters to a kernlet.
static const int kHelUserNotifyCqProgress
Set in userNotify after kernel has written progress.
Definition hel.h:769
HEL_C_LINKAGE HelError helCreateSpace(HelHandle *handle)
Creates a virtual address space that threads can run in.
static const uint32_t kHelSubmitWritebackFence
SQ opcode: writeback fence.
Definition hel.h:839
HelUpdateMemoryTypes
Additional type values of helUpdateMemory(); these are never issued as manage requests.
Definition hel.h:512
@ kHelUpdateMarkDirty
Marks a range as dirty, as if it had been written through a dirty-tracked mapping.
Definition hel.h:516
HEL_C_LINKAGE HelError helCreateSequencedEvent(HelHandle *waitHandle, HelHandle *raiseHandle)
Create an event that counts how often it was raised.
static const uint32_t kHelSubmitResizeMemory
SQ opcode: resize memory.
Definition hel.h:835
HEL_C_LINKAGE HelError helCreateOneshotEvent(HelHandle *handle)
Create an event that fires at most once.
HEL_C_LINKAGE HelError helCreateSwapSpace(HelHandle hierarchy, uint32_t flags, HelHandle *backingHandle, HelHandle *swapHandle)
Creates a swap space, the backing store for swappable anonymous memory (see helAllocateSwappableMemor...
HEL_C_LINKAGE HelError helDriveQueue(HelHandle queueHandle, uint32_t flags, uint32_t notifyMask)
Drives an IPC queue.
static const uint32_t kHelSubmitLockMemoryView
SQ opcode: lock memory view.
Definition hel.h:831
HEL_C_LINKAGE HelError helCreateUniverse(HelHandle *handle)
Creates a new universe descriptor.
static const int kHelProgressDone
Set by the producer once it retires the chunk.
Definition hel.h:884
HEL_C_LINKAGE HelError helEnableIo(HelHandle handle)
Enable userspace access to hardware I/O resources.
static const uint32_t kHelHierarchyMemoryController
Gives the new hierarchy its own memory controller with the given memoryFloor.
Definition hel.h:752
HEL_C_LINKAGE HelError helCreateManagedMemory(HelHandle hierarchy, size_t size, uint32_t flags, HelHandle *backingHandle, HelHandle *frontalHandle)
Creates a memory object that is managed by userspace.
static const int kHelUserNotifyError
Set in userNotify if the queue encounters a contract violation.
Definition hel.h:773
HEL_C_LINKAGE HelError helExtendHierarchy(HelHandle hierarchyHandle, const struct HelHierarchyParameters *params, HelHandle *handle)
Creates a child hierarchy capability.
HEL_C_LINKAGE HelError helCreateThread(HelHandle hierarchy, HelHandle universe, HelHandle spaceHandle, void *ip, void *sp, uint32_t flags, HelHandle *handle)
Create a new thread.
static const uint32_t kHelSubmitSetSwapRegion
SQ opcode: set the capacity of a swap region.
Definition hel.h:855
static const uint32_t kHelSubmitCancel
SQ opcode: cancel an asynchronous operation.
Definition hel.h:811
HEL_C_LINKAGE HelError helAllocateMemory(HelHandle hierarchy, size_t size, uint32_t flags, const struct HelAllocRestrictions *restrictions, HelHandle *handle)
Creates a memory object consisting of unmanaged RAM.
Parameters that allow userspace to compute the current time on the monotone clock (i....
Definition hel.h:451
int32_t tickShift
Scaling exponent of the tick -> nanosecond conversion.
Definition hel.h:456
uint64_t tickFactor
Factor of the tick -> nanosecond conversion.
Definition hel.h:458
uint32_t clockType
One of the kHelClock* constants.
Definition hel.h:454
Requester ID that a device issues DMA requests as (see kHelSubmitBindDmaDevice).
Definition hel.h:803
Range of physical memory that a DMA space identity-maps (see helCreateDmaSpace).
Definition hel.h:796
A single element of a HelQueue.
Definition hel.h:901
unsigned int length
Length of the element in bytes.
Definition hel.h:903
void * context
User-defined value.
Definition hel.h:907
unsigned int opcode
Operation code (for SQ elements).
Definition hel.h:905
Message address / data pair that raises an MSI (see helQueryMsiInfo).
Definition hel.h:1293
In-memory kernel/user-space queue.
Definition hel.h:858
int kernelNotify
Futex that is used to wake the kernel.
Definition hel.h:867
int userNotify
Futex that is used to wake userspace.
Definition hel.h:862
int cqFirst
Index of the first chunk of the completion queue.
Definition hel.h:871
int sqFirst
Index of the first chunk of the submission queue.
Definition hel.h:875
Register-related information returned by helQueryRegisterInfo.
Definition hel.h:581
int setSize
Size of the selected register set.
Definition hel.h:583
SQ data for kHelSubmitActivateIommu.
Definition hel.h:1117
HelHandle iommuHandle
Handle to the IOMMU (see helAccessIommu).
Definition hel.h:1119
SQ data for kHelSubmitAwaitClock.
Definition hel.h:927
uint64_t cancellationTag
Tag to cancel this operation.
Definition hel.h:931
uint64_t counter
Deadline in nanoseconds since boot.
Definition hel.h:929
SQ data for kHelSubmitAwaitEvent.
Definition hel.h:935
HelHandle handle
Handle to the event descriptor.
Definition hel.h:937
uint64_t cancellationTag
Tag to cancel this operation.
Definition hel.h:941
uint64_t sequence
Previous sequence number.
Definition hel.h:939
SQ data for kHelSubmitBindDmaDevice.
Definition hel.h:1093
struct HelDmaDeviceId id
Requester ID of the device.
Definition hel.h:1100
HelHandle iommuHandle
Handle to the IOMMU (see helAccessIommu).
Definition hel.h:1095
HelHandle dmaSpaceHandle
Handle to a DMA space of that IOMMU (see helCreateDmaSpace).
Definition hel.h:1098
SQ data for kHelSubmitCancel.
Definition hel.h:911
SQ data for kHelSubmitExchangeMsgs.
Definition hel.h:917
uint32_t flags
Flags.
Definition hel.h:923
size_t count
Number of actions.
Definition hel.h:921
HelHandle lane
Handle to the lane.
Definition hel.h:919
SQ data for kHelSubmitForkMemory.
Definition hel.h:1021
HelHandle hierarchyHandle
Handle to the hierarchy object that owns the memory object.
Definition hel.h:1023
HelHandle handle
Handle to the memory object.
Definition hel.h:1025
SQ data for kHelSubmitInvalidateMemory.
Definition hel.h:1043
uint32_t flags
Flags (kHelInvalidate*).
Definition hel.h:1051
HelHandle handle
Handle to the memory object.
Definition hel.h:1045
size_t size
Size of the range.
Definition hel.h:1049
uintptr_t offset
Offset within the memory object.
Definition hel.h:1047
SQ data for kHelSubmitLockMemoryView.
Definition hel.h:997
size_t size
Size to lock.
Definition hel.h:1003
uintptr_t offset
Offset within the memory object.
Definition hel.h:1001
HelHandle handle
Handle to the memory object.
Definition hel.h:999
SQ data for kHelSubmitManageMemory.
Definition hel.h:991
HelHandle handle
Handle to the memory object.
Definition hel.h:993
SQ data for kHelSubmitMapMemory.
Definition hel.h:1065
uint32_t flags
Flags (kHelMap*).
Definition hel.h:1077
HelHandle spaceHandle
Handle to the space that the memory is mapped into.
Definition hel.h:1069
HelHandle memoryHandle
Handle to the memory object.
Definition hel.h:1067
uintptr_t offset
Offset within the memory object.
Definition hel.h:1073
void * pointer
Address to map at (depending on kHelMap*).
Definition hel.h:1071
size_t size
Size of the mapping.
Definition hel.h:1075
SQ data for kHelSubmitObserve.
Definition hel.h:1007
HelHandle handle
Handle to the thread.
Definition hel.h:1009
SQ data for kHelSubmitPopulateSpace.
Definition hel.h:1055
HelHandle handle
Handle to the memory space.
Definition hel.h:1057
uintptr_t address
Address within the memory space.
Definition hel.h:1059
size_t length
Length of the range.
Definition hel.h:1061
SQ data for kHelSubmitProtectMemory.
Definition hel.h:945
size_t size
Size of the mapping.
Definition hel.h:951
void * pointer
Pointer to the mapping.
Definition hel.h:949
uint32_t flags
Protection flags.
Definition hel.h:953
HelHandle spaceHandle
Handle to the address space.
Definition hel.h:947
SQ data for kHelSubmitReadMemory.
Definition hel.h:967
uintptr_t address
Address within the memory object.
Definition hel.h:971
HelHandle handle
Handle to the memory object.
Definition hel.h:969
size_t length
Length in bytes.
Definition hel.h:973
void * buffer
Buffer to read into.
Definition hel.h:975
SQ data for kHelSubmitResizeMemory.
Definition hel.h:1013
HelHandle handle
Handle to the memory object.
Definition hel.h:1015
size_t newSize
New size in bytes.
Definition hel.h:1017
SQ data for kHelSubmitSetSwapRegion.
Definition hel.h:1133
size_t numPages
New capacity of the region in pages.
Definition hel.h:1140
HelHandle swapHandle
Handle to the swap space (from helCreateSwapSpace).
Definition hel.h:1136
uint32_t region
Index of the region. Must be smaller than kHelNumSwapRegions.
Definition hel.h:1142
SQ data for kHelSubmitSynchronizeSpace.
Definition hel.h:957
void * pointer
Pointer to the mapping.
Definition hel.h:961
size_t size
Size of the mapping.
Definition hel.h:963
HelHandle spaceHandle
Handle to the address space.
Definition hel.h:959
SQ data for kHelSubmitUnbindDmaDevice.
Definition hel.h:1106
HelHandle iommuHandle
Handle to the IOMMU (see helAccessIommu).
Definition hel.h:1108
struct HelDmaDeviceId id
Requester ID of the device.
Definition hel.h:1110
SQ data for kHelSubmitUnmapMemory.
Definition hel.h:1081
size_t size
Size of the mapping.
Definition hel.h:1087
void * pointer
Pointer to the mapping.
Definition hel.h:1085
HelHandle spaceHandle
Handle to the space that the mapping is removed from.
Definition hel.h:1083
SQ data for kHelSubmitWriteMemory.
Definition hel.h:979
HelHandle handle
Handle to the memory object.
Definition hel.h:981
size_t length
Length in bytes.
Definition hel.h:985
const void * buffer
Buffer to write from.
Definition hel.h:987
uintptr_t address
Address within the memory object.
Definition hel.h:983
SQ data for kHelSubmitWritebackFence.
Definition hel.h:1030
HelHandle handle
Handle to the memory object.
Definition hel.h:1032
size_t size
Size of the range.
Definition hel.h:1036
uintptr_t offset
Offset within the memory object.
Definition hel.h:1034