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 = 105,
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
35 kHelCallCreateQueue = 89,
36 kHelCallCancelAsync = 92,
37
38 kHelCallAllocateMemory = 51,
39 kHelCallResizeMemory = 83,
40 kHelCallCreateManagedMemory = 64,
41 kHelCallCopyOnWrite = 39,
42 kHelCallAccessPhysical = 30,
43 kHelCallCreateSliceView = 88,
44 kHelCallForkMemory = 40,
45 kHelCallCreateSpace = 27,
46 kHelCallCreateIndirectMemory = 45,
47 kHelCallAlterMemoryIndirection = 52,
48 kHelCallMapMemory = 44,
49 kHelCallSubmitProtectMemory = 99,
50 kHelCallSubmitSynchronizeSpace = 53,
51 kHelCallUnmapMemory = 36,
52 kHelCallPointerPhysical = 43,
53 kHelCallSubmitReadMemory = 77,
54 kHelCallSubmitWriteMemory = 78,
55 kHelCallMemoryInfo = 26,
56 kHelCallSubmitManageMemory = 46,
57 kHelCallUpdateMemory = 47,
58 kHelCallSubmitLockMemoryView = 48,
59 kHelCallLoadahead = 49,
60 kHelCallCreateVirtualizedSpace = 50,
61
62 kHelCallCreateThread = 67,
63 kHelCallQueryThreadStats = 95,
64 kHelCallSetPriority = 85,
65 kHelCallYield = 34,
66 kHelCallSubmitObserve = 74,
67 kHelCallKillThread = 87,
68 kHelCallInterruptThread = 86,
69 kHelCallResume = 61,
70 kHelCallLoadRegisters = 75,
71 kHelCallStoreRegisters = 76,
72 kHelCallQueryRegisterInfo = 102,
73 kHelCallWriteFsBase = 41,
74 kHelCallGetClock = 42,
75 kHelCallSubmitAwaitClock = 80,
76 kHelCallCreateVirtualizedCpu = 37,
77 kHelCallRunVirtualizedCpu = 38,
78 kHelCallGetRandomBytes = 101,
79 kHelCallWriteGsBase = 54,
80 kHelCallReadFsBase = 55,
81 kHelCallReadGsBase = 56,
82 kHelCallGetCurrentCpu = 57,
83
84 kHelCallCreateStream = 68,
85 kHelCallSubmitAsync = 79,
86 kHelCallShutdownLane = 91,
87
88 kHelCallFutexWait = 73,
89 kHelCallFutexWake = 71,
90
91 kHelCallCreateOneshotEvent = 96,
92 kHelCallCreateBitsetEvent = 97,
93 kHelCallRaiseEvent = 98,
94 kHelCallAccessIrq = 14,
95 kHelCallAcknowledgeIrq = 81,
96 kHelCallSubmitAwaitEvent = 82,
97 kHelCallAutomateIrq = 94,
98
99 kHelCallAccessIo = 11,
100 kHelCallEnableIo = 12,
101 kHelCallEnableFullIo = 35,
102
103 kHelCallBindKernlet = 93,
104
105 kHelCallGetAffinity = 103,
106 kHelCallSetAffinity = 100,
107
108 kHelCallCreateToken = 104,
109
110 kHelCallSuper = 0x80000000
111};
112
113enum {
114 kHelErrNone = 0,
115 kHelErrIllegalSyscall = 5,
116 kHelErrIllegalArgs = 7,
117 kHelErrIllegalState = 15,
118 kHelErrUnsupportedOperation = 18,
119 kHelErrOutOfBounds = 19,
120 kHelErrQueueTooSmall = 14,
121 kHelErrCancelled = 12,
122 kHelErrNoDescriptor = 4,
123 kHelErrBadDescriptor = 2,
124 kHelErrThreadTerminated = 11,
125 kHelErrTransmissionMismatch = 13,
126 kHelErrLaneShutdown = 8,
127 kHelErrEndOfLane = 9,
128 kHelErrDismissed = 20,
129 kHelErrBufferTooSmall = 1,
130 kHelErrFault = 10,
131 kHelErrRemoteFault = 21,
132 kHelErrNoHardwareSupport = 16,
133 kHelErrNoMemory = 17,
134 kHelErrAlreadyExists = 22
135};
136
137struct HelX86SegmentRegister {
138 uint64_t base;
139 uint32_t limit;
140 uint16_t selector;
141 uint8_t type, present, dpl, db, s, l, g, avl;
142};
143
144struct HelX86DescriptorTable {
145 uint64_t base;
146 uint16_t limit;
147};
148
149struct HelX86VirtualizationRegs {
150 uint64_t rax;
151 uint64_t rbx;
152 uint64_t rcx;
153 uint64_t rdx;
154 uint64_t rsi;
155 uint64_t rdi;
156 uint64_t rbp;
157 uint64_t r8;
158 uint64_t r9;
159 uint64_t r10;
160 uint64_t r11;
161 uint64_t r12;
162 uint64_t r13;
163 uint64_t r14;
164 uint64_t r15;
165
166 uint64_t rsp;
167 uint64_t rip;
168 uint64_t rflags;
169
170 struct HelX86SegmentRegister cs, ds, es, fs, gs, ss;
171 struct HelX86SegmentRegister tr, ldt;
172 struct HelX86DescriptorTable gdt, idt;
173
174 uint64_t cr0, cr2, cr3, cr4, cr8;
175 uint64_t efer;
176 uint64_t apic_base;
177};
178
179enum {
180 kHelNullHandle = 0,
181 kHelThisUniverse = -1,
182 kHelThisThread = -2,
183 kHelZeroMemory = -3
184};
185
186enum {
187 kHelWaitInfinite = -1
188};
189
190enum {
191 kHelAbiSystemV = 1
192};
193
194enum {
195 kHelActionDismiss = 11,
196 kHelActionOffer = 5,
197 kHelActionAccept = 6,
198 kHelActionImbueCredentials = 8,
199 kHelActionExtractCredentials = 9,
200 kHelActionSendFromBuffer = 1,
201 kHelActionSendFromBufferSg = 10,
202 kHelActionRecvInline = 7,
203 kHelActionRecvToBuffer = 3,
204 kHelActionPushDescriptor = 2,
205 kHelActionPullDescriptor = 4
206};
207
208enum {
209 kHelItemChain = 1,
210 kHelItemAncillary = 2,
211 kHelItemWantLane = (1 << 16),
212};
213
214struct HelSgItem {
215 void *buffer;
216 size_t length;
217};
218
219struct HelAction {
220 int type;
221 uint32_t flags;
222 // TODO: the following fields could be put into unions
223 void *buffer;
224 size_t length;
225 HelHandle handle;
226};
227
228struct HelDescriptorInfo {
229 int type;
230};
231
232enum HelAllocFlags {
233 kHelAllocContinuous = 4,
234 kHelAllocOnDemand = 1,
235};
236
237struct HelAllocRestrictions {
238 int addressBits;
239};
240
241enum HelManagedFlags {
242 kHelManagedReadahead = 1
243};
244
245enum HelManageRequests {
246 kHelManageInitialize = 1,
247 kHelManageWriteback = 2
248};
249
250enum HelMapFlags {
251 // Additional flags that may be set.
252 kHelMapProtRead = 256,
253 kHelMapProtWrite = 512,
254 kHelMapProtExecute = 1024,
255 kHelMapDontRequireBacking = 128,
256 kHelMapFixed = 2048,
257 kHelMapFixedNoReplace = 4096
258};
259
260enum HelThreadFlags {
261 kHelThreadStopped = 1
262};
263
264enum HelObservation {
265 kHelObserveNull = 0,
266 kHelObserveInterrupt = 4,
267 kHelObservePanic = 3,
268 kHelObserveBreakpoint = 1,
269 kHelObservePageFault = 2,
270 kHelObserveGeneralFault = 5,
271 kHelObserveIllegalInstruction = 6,
272 kHelObserveDivByZero = 7,
273 kHelObserveSuperCall = 0x80000000
274};
275
276enum HelRegisterSets {
277 kHelRegsProgram = 1,
278 kHelRegsGeneral = 2,
279 kHelRegsThread = 3,
280 kHelRegsDebug = 4,
281 kHelRegsVirtualization = 5,
282 kHelRegsSimd = 6,
283 kHelRegsSignal = 7
284};
285
290};
291
292#if defined(__x86_64__)
293enum HelRegisterIndex {
294 kHelRegRax = 0,
295 kHelRegRbx = 1,
296 kHelRegRcx = 2,
297 kHelRegRdx = 3,
298 kHelRegRdi = 4,
299 kHelRegRsi = 5,
300 kHelRegR8 = 6,
301 kHelRegR9 = 7,
302 kHelRegR10 = 8,
303 kHelRegR11 = 9,
304 kHelRegR12 = 10,
305 kHelRegR13 = 11,
306 kHelRegR14 = 12,
307 kHelRegR15 = 13,
308 kHelRegRbp = 14,
309
310 kHelNumGprs = 15,
311
312 kHelRegIp = 0,
313 kHelRegSp = 1
314};
315
316enum HelSyscallArgs {
317 kHelRegNumber = kHelRegRdi,
318 kHelRegError = kHelRegRdi,
319
320 kHelRegArg0 = kHelRegRsi,
321 kHelRegArg1 = kHelRegRdx,
322 kHelRegArg2 = kHelRegRax,
323 kHelRegArg3 = kHelRegR8,
324 kHelRegArg4 = kHelRegR9,
325 kHelRegArg5 = kHelRegR10,
326 kHelRegArg6 = kHelRegR12,
327 kHelRegArg7 = kHelRegR13,
328 kHelRegArg8 = kHelRegR14,
329
330 kHelRegOut0 = kHelRegRsi,
331 kHelRegOut1 = kHelRegRdx
332};
333
334#elif defined(__aarch64__)
335enum HelRegisterIndex {
336 kHelRegX0 = 0,
337 kHelRegX1,
338 kHelRegX2,
339 kHelRegX3,
340 kHelRegX4,
341 kHelRegX5,
342 kHelRegX6,
343 kHelRegX7,
344 kHelRegX8,
345 kHelRegX9,
346 kHelRegX10,
347 kHelRegX11,
348 kHelRegX12,
349 kHelRegX13,
350 kHelRegX14,
351 kHelRegX15,
352 kHelRegX16,
353 kHelRegX17,
354 kHelRegX18,
355 kHelRegX19,
356 kHelRegX20,
357 kHelRegX21,
358 kHelRegX22,
359 kHelRegX23,
360 kHelRegX24,
361 kHelRegX25,
362 kHelRegX26,
363 kHelRegX27,
364 kHelRegX28,
365 kHelRegX29,
366 kHelRegX30,
367
368 kHelNumGprs = 31,
369
370 kHelRegIp = 0,
371 kHelRegSp = 1
372};
373
374enum HelSyscallArgs {
375 kHelRegNumber = kHelRegX0,
376 kHelRegError = kHelRegX0,
377
378 kHelRegArg0 = kHelRegX1,
379 kHelRegArg1 = kHelRegX2,
380 kHelRegArg2 = kHelRegX3,
381 kHelRegArg3 = kHelRegX4,
382 kHelRegArg4 = kHelRegX5,
383 kHelRegArg5 = kHelRegX6,
384 kHelRegArg6 = kHelRegX7,
385 kHelRegArg7 = kHelRegX8,
386 kHelRegArg8 = kHelRegX9,
387
388 kHelRegOut0 = kHelRegX1,
389 kHelRegOut1 = kHelRegX2
390};
391
392#elif defined(__riscv) && __riscv_xlen == 64
393enum HelRegisterIndex {
394 kHelRegRa = 0,
395 kHelRegGp,
396 kHelRegTp,
397 kHelRegT0,
398 kHelRegT1,
399 kHelRegT2,
400 kHelRegS0,
401 kHelRegS1,
402 kHelRegA0,
403 kHelRegA1,
404 kHelRegA2,
405 kHelRegA3,
406 kHelRegA4,
407 kHelRegA5,
408 kHelRegA6,
409 kHelRegA7,
410 kHelRegS2,
411 kHelRegS3,
412 kHelRegS4,
413 kHelRegS5,
414 kHelRegS6,
415 kHelRegS7,
416 kHelRegS8,
417 kHelRegS9,
418 kHelRegS10,
419 kHelRegS11,
420 kHelRegT3,
421 kHelRegT4,
422 kHelRegT5,
423 kHelRegT6,
424 kHelNumGprs,
425 kHelRegIp = 0,
426 kHelRegSp = 1
427};
428enum HelSyscallArgs {
429 kHelRegNumber = kHelRegA0,
430 kHelRegError = kHelRegA0,
431 kHelRegArg0 = kHelRegA1,
432 kHelRegArg1 = kHelRegA2,
433 kHelRegArg2 = kHelRegA3,
434 kHelRegArg3 = kHelRegA4,
435 kHelRegArg4 = kHelRegA5,
436 kHelRegArg5 = kHelRegA6,
437 kHelRegArg6 = kHelRegA7,
438 kHelRegArg7 = kHelRegS2,
439 kHelRegArg8 = kHelRegS3,
440 kHelRegOut0 = kHelRegA1,
441 kHelRegOut1 = kHelRegA2
442};
443
444#endif
445
446struct HelQueueParameters {
447 uint32_t flags;
448 unsigned int ringShift;
449 unsigned int numChunks;
450 size_t chunkSize;
451};
452
454static const int kHelHeadMask = 0xFFFFFF;
455
457static const int kHelHeadWaiters = (1 << 24);
458
460struct HelQueue {
463
465 char padding[4];
466
469};
470
472static const int kHelProgressMask = 0xFFFFFF;
473
475static const int kHelProgressWaiters = (1 << 24);
476
478static const int kHelProgressDone = (1 << 25);
479
480struct HelChunk {
482 int progressFutex;
483
485 char padding[4];
486
488 char buffer[];
489};
490
494 unsigned int length;
495 unsigned int reserved;
497 void *context;
498};
499
500struct HelSimpleResult {
501 HelError error;
502 int reserved;
503};
504
505struct HelCredentialsResult {
506 HelError error;
507 int reserved;
508 char credentials[16];
509};
510
511struct HelManageResult {
512 HelError error;
513 int type;
514 uintptr_t offset;
515 size_t length;
516};
517
518struct HelObserveResult {
519 HelError error;
520 unsigned int observation;
521 uint64_t sequence;
522};
523
524struct HelInlineResult {
525 HelError error;
526 int reserved;
527 size_t length;
528 char data[];
529};
530
531struct HelInlineResultNoFlex {
532 HelError error;
533 int reserved;
534 size_t length;
535};
536
537struct HelLengthResult {
538 HelError error;
539 int reserved;
540 size_t length;
541};
542
543struct HelHandleResult {
544 HelError error;
545 int reserved;
546 HelHandle handle;
547};
548
549struct HelEventResult {
550 HelError error;
551 uint32_t bitset;
552 uint64_t sequence;
553};
554
555enum HelAckFlags {
556 kHelAckAcknowledge = 2,
557 kHelAckNack = 3,
558 kHelAckKick = 1,
559 kHelAckClear = 0x100,
560};
561
562union HelKernletData {
563 HelHandle handle;
564};
565
566struct HelThreadStats {
567 uint64_t userTime;
568};
569
570enum {
571 kHelVmexitHlt = 0,
572 kHelVmexitTranslationFault = 1,
573 kHelVmexitError = -1,
574 kHelVmexitUnknownPlatformSpecificExitCode = -2,
575};
576
577struct HelVmexitReason {
578 uint32_t exitReason;
579 uint32_t code;
580 size_t address;
581 size_t flags;
582};
583
584// see RFC 5424
585enum HelLogSeverity {
586 kHelLogSeverityEmergency,
587 kHelLogSeverityAlert,
588 kHelLogSeverityCritical,
589 kHelLogSeverityError,
590 kHelLogSeverityWarning,
591 kHelLogSeverityNotice,
592 kHelLogSeverityInfo,
593 kHelLogSeverityDebug,
594};
595
598
606HEL_C_LINKAGE HelError helLog(const HelLogSeverity severity, const char *string, size_t length);
607
613HEL_C_LINKAGE void helPanic(const char *string, size_t length)
614 __attribute__ (( noreturn ));
615
619
621HEL_C_LINKAGE HelError helNop();
622
626HEL_C_LINKAGE HelError helSubmitAsyncNop(HelHandle queueHandle, uintptr_t context);
627
631
635HEL_C_LINKAGE HelError helCreateUniverse(HelHandle *handle);
636
644HEL_C_LINKAGE HelError helTransferDescriptor(HelHandle handle, HelHandle universeHandle,
645 HelHandle *outHandle);
646
647HEL_C_LINKAGE HelError helDescriptorInfo(HelHandle handle, struct HelDescriptorInfo *info);
648
654HEL_C_LINKAGE HelError helGetCredentials(HelHandle handle, uint32_t flags,
655 char *credentials);
656
662HEL_C_LINKAGE HelError helCloseDescriptor(HelHandle universeHandle, HelHandle handle);
663
667
669HEL_C_LINKAGE HelError helCreateQueue(struct HelQueueParameters *params,
670 HelHandle *handle);
671
677HEL_C_LINKAGE HelError helCancelAsync(HelHandle queueHandle, uint64_t asyncId);
678
682
692HEL_C_LINKAGE HelError helAllocateMemory(size_t size, uint32_t flags,
693 struct HelAllocRestrictions *restrictions, HelHandle *handle);
694
701HEL_C_LINKAGE HelError helResizeMemory(HelHandle handle, size_t newSize);
702
714HEL_C_LINKAGE HelError helCreateManagedMemory(size_t size, uint32_t flags,
715 HelHandle *backingHandle, HelHandle *frontalHandle);
716
727HEL_C_LINKAGE HelError helCopyOnWrite(HelHandle memory,
728 uintptr_t offset, size_t size, HelHandle *handle);
729
730HEL_C_LINKAGE HelError helAccessPhysical(uintptr_t physical,
731 size_t size, HelHandle *handle);
732
738HEL_C_LINKAGE HelError helCreateIndirectMemory(size_t numSlots, HelHandle *handle);
739
756HEL_C_LINKAGE HelError helAlterMemoryIndirection(HelHandle indirectHandle, size_t slotIndex,
757 HelHandle memoryHandle, uintptr_t offset, size_t size);
758
759HEL_C_LINKAGE HelError helCreateSliceView(HelHandle bundle, uintptr_t offset, size_t size,
760 uint32_t flags, HelHandle *handle);
761
769HEL_C_LINKAGE HelError helForkMemory(HelHandle handle, HelHandle *forkedHandle);
770
774HEL_C_LINKAGE HelError helCreateSpace(HelHandle *handle);
775
793HEL_C_LINKAGE HelError helMapMemory(HelHandle memoryHandle, HelHandle spaceHandle,
794 void *pointer, uintptr_t offset, size_t size, uint32_t flags, void **actualPointer);
795
807HEL_C_LINKAGE HelError helSubmitProtectMemory(HelHandle spaceHandle,
808 void *pointer, size_t size, uint32_t flags,
809 HelHandle queueHandle, uintptr_t context);
810
826HEL_C_LINKAGE HelError helSubmitSynchronizeSpace(HelHandle spaceHandle,
827 void *pointer, size_t size,
828 HelHandle queueHandle, uintptr_t context);
829
840HEL_C_LINKAGE HelError helUnmapMemory(HelHandle spaceHandle, void *pointer, size_t size);
841
842HEL_C_LINKAGE HelError helPointerPhysical(const void *pointer, uintptr_t *physical);
843
855HEL_C_LINKAGE HelError helSubmitReadMemory(HelHandle handle, uintptr_t address,
856 size_t length, void *buffer,
857 HelHandle queue, uintptr_t context);
858
870HEL_C_LINKAGE HelError helSubmitWriteMemory(HelHandle handle, uintptr_t address,
871 size_t length, const void *buffer,
872 HelHandle queue, uintptr_t context);
873
874HEL_C_LINKAGE HelError helMemoryInfo(HelHandle handle,
875 size_t *size);
876
877HEL_C_LINKAGE HelError helSubmitManageMemory(HelHandle handle,
878 HelHandle queue, uintptr_t context);
879
880HEL_C_LINKAGE HelError helUpdateMemory(HelHandle handle, int type, uintptr_t offset, size_t length);
881
882HEL_C_LINKAGE HelError helSubmitLockMemoryView(HelHandle handle, uintptr_t offset, size_t size,
883 HelHandle queue, uintptr_t context);
884
895HEL_C_LINKAGE HelError helLoadahead(HelHandle handle, uintptr_t offset, size_t length);
896
897HEL_C_LINKAGE HelError helCreateVirtualizedSpace(HelHandle *handle);
898
902
916HEL_C_LINKAGE HelError helCreateThread(HelHandle universe, HelHandle spaceHandle,
917 HelAbi abi, void *ip, void *sp, uint32_t flags, HelHandle *handle);
918
924HEL_C_LINKAGE HelError helQueryThreadStats(HelHandle handle, struct HelThreadStats *stats);
925
934HEL_C_LINKAGE HelError helSetPriority(HelHandle handle, int priority);
935
937HEL_C_LINKAGE HelError helYield();
938
946HEL_C_LINKAGE HelError helSubmitObserve(HelHandle handle, uint64_t sequence,
947 HelHandle queue, uintptr_t context);
948
952HEL_C_LINKAGE HelError helKillThread(HelHandle handle);
953
960HEL_C_LINKAGE HelError helInterruptThread(HelHandle handle);
961
968HEL_C_LINKAGE HelError helResume(HelHandle handle);
969
977HEL_C_LINKAGE HelError helLoadRegisters(HelHandle handle, int set, void *image);
978
986HEL_C_LINKAGE HelError helStoreRegisters(HelHandle handle, int set, const void *image);
987
990// Register set to query information for.
993HEL_C_LINKAGE HelError helQueryRegisterInfo(int set, struct HelRegisterInfo *info);
994
995HEL_C_LINKAGE HelError helWriteFsBase(void *pointer);
996
997HEL_C_LINKAGE HelError helReadFsBase(void **pointer);
998
999HEL_C_LINKAGE HelError helWriteGsBase(void *pointer);
1000
1001HEL_C_LINKAGE HelError helReadGsBase(void **pointer);
1002
1004HEL_C_LINKAGE HelError helGetCurrentCpu(int *cpu);
1005
1010HEL_C_LINKAGE HelError helGetClock(uint64_t *counter);
1011
1019HEL_C_LINKAGE HelError helSubmitAwaitClock(uint64_t counter,
1020 HelHandle queue, uintptr_t context, uint64_t *asyncId);
1021
1022HEL_C_LINKAGE HelError helCreateVirtualizedCpu(HelHandle handle, HelHandle *out_handle);
1023
1024HEL_C_LINKAGE HelError helRunVirtualizedCpu(HelHandle handle, struct HelVmexitReason *reason);
1025
1026HEL_C_LINKAGE HelError helGetRandomBytes(void *buffer, size_t wantedSize, size_t *actualSize);
1027
1037HEL_C_LINKAGE HelError helGetAffinity(HelHandle handle, uint8_t *mask, size_t size, size_t *actualSize);
1038
1046HEL_C_LINKAGE HelError helSetAffinity(HelHandle handle, uint8_t *mask, size_t size);
1047
1051
1059HEL_C_LINKAGE HelError helCreateStream(HelHandle *lane1, HelHandle *lane2, uint32_t attach_credentials);
1060
1068HEL_C_LINKAGE HelError helSubmitAsync(HelHandle handle, const struct HelAction *actions,
1069 size_t count, HelHandle queue, uintptr_t context, uint32_t flags);
1070
1071HEL_C_LINKAGE HelError helShutdownLane(HelHandle handle);
1072
1080HEL_C_LINKAGE HelError helCreateToken(HelHandle *handle);
1081
1085
1094HEL_C_LINKAGE HelError helFutexWait(int *pointer, int expected, int64_t deadline);
1095
1099HEL_C_LINKAGE HelError helFutexWake(int *pointer);
1100
1104
1108HEL_C_LINKAGE HelError helCreateOneshotEvent(HelHandle *handle);
1109
1113HEL_C_LINKAGE HelError helCreateBitsetEvent(HelHandle *handle);
1114
1118HEL_C_LINKAGE HelError helRaiseEvent(HelHandle handle);
1119
1120HEL_C_LINKAGE HelError helAccessIrq(int number, HelHandle *handle);
1121
1122HEL_C_LINKAGE HelError helAcknowledgeIrq(HelHandle handle, uint32_t flags, uint64_t sequence);
1123
1131HEL_C_LINKAGE HelError helSubmitAwaitEvent(HelHandle handle, uint64_t sequence,
1132 HelHandle queue, uintptr_t context);
1133
1134HEL_C_LINKAGE HelError helAutomateIrq(HelHandle handle, uint32_t flags, HelHandle kernlet);
1135
1139
1140HEL_C_LINKAGE HelError helAccessIo(uintptr_t *port_array, size_t num_ports,
1141 HelHandle *handle);
1142
1146HEL_C_LINKAGE HelError helEnableIo(HelHandle handle);
1147
1148HEL_C_LINKAGE HelError helEnableFullIo();
1149
1153
1163HEL_C_LINKAGE HelError helBindKernlet(HelHandle handle,
1164 const union HelKernletData *data, size_t numData, HelHandle *boundHandle);
1165
1167
1168extern inline __attribute__ (( always_inline )) const char *_helErrorString(HelError code) {
1169 switch(code) {
1170 case kHelErrNone:
1171 return "Success";
1172 case kHelErrIllegalSyscall:
1173 return "Illegal syscall";
1174 case kHelErrIllegalArgs:
1175 return "Illegal arguments";
1176 case kHelErrIllegalState:
1177 return "Illegal state";
1178 case kHelErrUnsupportedOperation:
1179 return "Unsupported operation";
1180 case kHelErrNoDescriptor:
1181 return "No such descriptor";
1182 case kHelErrBadDescriptor:
1183 return "Illegal descriptor for this operation";
1184 case kHelErrThreadTerminated:
1185 return "Thread terminated already";
1186 case kHelErrLaneShutdown:
1187 return "Lane shutdown";
1188 case kHelErrEndOfLane:
1189 return "End of lane";
1190 case kHelErrDismissed:
1191 return "IPC item dismissed by remote";
1192 case kHelErrBufferTooSmall:
1193 return "Buffer too small";
1194 case kHelErrQueueTooSmall:
1195 return "Buffer too small";
1196 case kHelErrFault:
1197 return "Segfault";
1198 case kHelErrNoHardwareSupport:
1199 return "Missing hardware support for this feature";
1200 case kHelErrNoMemory:
1201 return "Out of memory";
1202 case kHelErrTransmissionMismatch:
1203 return "Transmission mismatch";
1204 case kHelErrCancelled:
1205 return "Cancelled";
1206 case kHelErrOutOfBounds:
1207 return "Out of bounds";
1208 case kHelErrAlreadyExists:
1209 return "Already exists";
1210 default:
1211 return 0;
1212 }
1213}
1214
1215extern inline __attribute__ (( always_inline )) void _helCheckFailed(HelError err_code,
1216 const char *string, int fatal) {
1217 helLog(kHelLogSeverityError, string, strlen(string));
1218
1219 const char *err_string = _helErrorString(err_code);
1220 if(err_string == 0)
1221 err_string = "(Unexpected error code)";
1222 helLog(kHelLogSeverityError, err_string, strlen(err_string));
1223 helLog(kHelLogSeverityError, "\n", 1);
1224
1225 if(fatal)
1226 helPanic(0, 0);
1227}
1228
1229#define HEL_STRINGIFY_AUX(x) #x
1230#define HEL_STRINGIFY(x) HEL_STRINGIFY_AUX(x)
1231
1232#define HEL_CHECK(expr) do { HelError __error = expr; if(__error != kHelErrNone) \
1233 _helCheckFailed(__error, "HEL_CHECK failed: " #expr "\n" \
1234 " In file " __FILE__ " on line " HEL_STRINGIFY(__LINE__) "\n", 1); } while(0)
1235#define HEL_SOFT_CHECK(expr) do { HelError __error = expr; if(__error != kHelErrNone) \
1236 _helCheckFailed(__error, "HEL_SOFT_CHECK failed: " #expr "\n" \
1237 " In file " __FILE__ " on line " HEL_STRINGIFY(__LINE__) "\n", 0); } while(0)
1238
1239#endif // HEL_H
1240
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 helSubmitReadMemory(HelHandle handle, uintptr_t address, size_t length, void *buffer, HelHandle queue, uintptr_t context)
Load memory (i.e., bytes) from a descriptor.
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.
HEL_C_LINKAGE HelError helSubmitAsync(HelHandle handle, const struct HelAction *actions, size_t count, HelHandle queue, uintptr_t context, uint32_t flags)
Pass messages on a stream.
HEL_C_LINKAGE HelError helSubmitAwaitEvent(HelHandle handle, uint64_t sequence, HelHandle queue, uintptr_t context)
Wait for an event.
HEL_C_LINKAGE HelError helLog(const HelLogSeverity severity, const char *string, size_t length)
Writes a text message (e.g., a line of text) to the kernel's log.
static const int kHelHeadMask
Mask to extract the current queue head.
Definition hel.h:454
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.
HEL_C_LINKAGE HelError helSubmitObserve(HelHandle handle, uint64_t sequence, HelHandle queue, uintptr_t context)
Observe whether a thread changes its state.
HEL_C_LINKAGE HelError helAllocateMemory(size_t size, uint32_t flags, struct HelAllocRestrictions *restrictions, HelHandle *handle)
Creates a memory object consisting of unmanaged RAM.
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.
HEL_C_LINKAGE HelError helCreateQueue(struct HelQueueParameters *params, HelHandle *handle)
Creates an IPC queue.
HEL_C_LINKAGE HelError helSubmitAwaitClock(uint64_t counter, HelHandle queue, uintptr_t context, uint64_t *asyncId)
Wait until time passes.
HEL_C_LINKAGE HelError helGetAffinity(HelHandle handle, uint8_t *mask, size_t size, size_t *actualSize)
Get a thread's CPU affinity mask.
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 helLoadRegisters(HelHandle handle, int set, void *image)
Load a register image (e.g., from a thread).
HEL_C_LINKAGE HelError helCopyOnWrite(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 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 helResizeMemory(HelHandle handle, size_t newSize)
Resizes a memory object.
HEL_C_LINKAGE HelError helSubmitSynchronizeSpace(HelHandle spaceHandle, void *pointer, size_t size, HelHandle queueHandle, uintptr_t context)
Notifies the kernel of dirty pages in a memory mapping.
static const int kHelProgressMask
Mask to extract the number of valid bytes in the chunk.
Definition hel.h:472
HEL_C_LINKAGE HelError helCreateManagedMemory(size_t size, uint32_t flags, HelHandle *backingHandle, HelHandle *frontalHandle)
Creates a memory object that is managed by userspace.
HEL_C_LINKAGE HelError helInterruptThread(HelHandle handle)
Interrupt a thread.
HEL_C_LINKAGE HelError helRaiseEvent(HelHandle handle)
Raise an event.
HEL_C_LINKAGE HelError helForkMemory(HelHandle handle, HelHandle *forkedHandle)
Forks memory objects, i.e., copies them using copy-on-write.
HEL_C_LINKAGE HelError helFutexWake(int *pointer)
Wakes up all waiters of a futex.
HEL_C_LINKAGE HelError helCreateToken(HelHandle *handle)
Create a token object.
HEL_C_LINKAGE HelError helCreateThread(HelHandle universe, HelHandle spaceHandle, HelAbi abi, void *ip, void *sp, uint32_t flags, HelHandle *handle)
Create a new thread.
HEL_C_LINKAGE HelError helResume(HelHandle handle)
Resume a suspended thread.
HEL_C_LINKAGE HelError helSubmitAsyncNop(HelHandle queueHandle, uintptr_t context)
Does nothing, asynchronously (useful only for profiling).
HEL_C_LINKAGE HelError helStoreRegisters(HelHandle handle, int set, const void *image)
Store a register image (e.g., to a thread).
HEL_C_LINKAGE HelError helTransferDescriptor(HelHandle handle, HelHandle universeHandle, HelHandle *outHandle)
Copies descriptors from the current universe to another universe.
HEL_C_LINKAGE HelError helSubmitProtectMemory(HelHandle spaceHandle, void *pointer, size_t size, uint32_t flags, HelHandle queueHandle, uintptr_t context)
Changes protection attributes of a memory mapping.
HEL_C_LINKAGE HelError helCreateStream(HelHandle *lane1, HelHandle *lane2, uint32_t attach_credentials)
Create a stream (which always consists of two lanes).
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 helSubmitWriteMemory(HelHandle handle, uintptr_t address, size_t length, const void *buffer, HelHandle queue, uintptr_t context)
Store memory (i.e., bytes) to a descriptor.
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.
static const int kHelHeadWaiters
Can be set by the kernel to request a FutexWake on update.
Definition hel.h:457
HEL_C_LINKAGE HelError helBindKernlet(HelHandle handle, const union HelKernletData *data, size_t numData, HelHandle *boundHandle)
Bind parameters to a kernlet.
HEL_C_LINKAGE HelError helCreateSpace(HelHandle *handle)
Creates a virtual address space that threads can run in.
HEL_C_LINKAGE HelError helCreateOneshotEvent(HelHandle *handle)
Create an event that fires at most once.
static const int kHelProgressWaiters
Can be set by userspace to request a FutexWake on update.
Definition hel.h:475
HEL_C_LINKAGE HelError helCreateUniverse(HelHandle *handle)
Creates a new universe descriptor.
static const int kHelProgressDone
Set by the kernel once it retires the chunk.
Definition hel.h:478
HEL_C_LINKAGE HelError helEnableIo(HelHandle handle)
Enable userspace access to hardware I/O resources.
HEL_C_LINKAGE HelError helCancelAsync(HelHandle queueHandle, uint64_t asyncId)
Cancels an ongoing asynchronous operation.
A single element of a HelQueue.
Definition hel.h:492
unsigned int length
Length of the element in bytes.
Definition hel.h:494
void * context
User-defined value.
Definition hel.h:497
In-memory kernel/user-space queue.
Definition hel.h:460
char padding[4]
Ensures that the buffer is 8-byte aligned.
Definition hel.h:465
int headFutex
Futex for kernel/user-space head synchronization.
Definition hel.h:462
int indexQueue[]
The actual queue.
Definition hel.h:468
Register-related information returned by helQueryRegisterInfo.
Definition hel.h:287
int setSize
Size of the selected register set.
Definition hel.h:289