pal.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * pal.h
  15. *
  16. * This file contains definition of PAL host ABI.
  17. */
  18. #ifndef PAL_H
  19. #define PAL_H
  20. #include <stdbool.h>
  21. #include <stddef.h>
  22. #include <stdint.h>
  23. #include <stdnoreturn.h>
  24. typedef uint64_t PAL_NUM;
  25. typedef const char * PAL_STR;
  26. typedef void * PAL_PTR;
  27. typedef uint32_t PAL_FLG;
  28. typedef uint32_t PAL_IDX;
  29. typedef bool PAL_BOL;
  30. /* Moved MAX_FDS from <host_kernel>/pal_host.h to here,
  31. * since it is 3, across all host kernels. */
  32. #define MAX_FDS 3
  33. #ifdef IN_PAL
  34. #include <atomic.h>
  35. typedef struct atomic_int PAL_REF;
  36. typedef struct {
  37. PAL_IDX type;
  38. PAL_FLG flags;
  39. } PAL_HDR;
  40. # include "pal_host.h"
  41. # ifndef HANDLE_HDR
  42. # define HANDLE_HDR(handle) (&((handle)->hdr))
  43. # endif
  44. static inline void init_handle_hdr(PAL_HDR *hdr, int pal_type) {
  45. hdr->type = pal_type;
  46. hdr->flags = 0;
  47. }
  48. # define SET_HANDLE_TYPE(handle, t) init_handle_hdr(HANDLE_HDR(handle), pal_type_##t)
  49. # define IS_HANDLE_TYPE(handle, t) (HANDLE_HDR(handle)->type == pal_type_##t)
  50. #else
  51. typedef union pal_handle
  52. {
  53. struct {
  54. PAL_IDX type;
  55. /* the PAL-level reference counting is deprecated */
  56. } hdr;
  57. } * PAL_HANDLE;
  58. # ifndef HANDLE_HDR
  59. # define HANDLE_HDR(handle) (&((handle)->hdr))
  60. # endif
  61. #endif /* !IN_PAL */
  62. #define PAL_LIBOS_TCB_SIZE 256
  63. typedef struct pal_tcb {
  64. struct pal_tcb * self;
  65. /* uint64_t for alignment */
  66. uint64_t libos_tcb[(PAL_LIBOS_TCB_SIZE + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
  67. /* data private to PAL implementation follows this struct. */
  68. } PAL_TCB;
  69. static inline PAL_TCB * pal_get_tcb (void)
  70. {
  71. PAL_TCB * tcb;
  72. __asm__ ("movq %%gs:%c1,%q0"
  73. : "=r" (tcb)
  74. : "i" (offsetof(struct pal_tcb, self)));
  75. return tcb;
  76. }
  77. #ifdef __x86_64__
  78. union pal_csgsfs {
  79. struct {
  80. uint16_t cs;
  81. uint16_t gs;
  82. uint16_t fs;
  83. uint16_t ss;
  84. };
  85. uint64_t csgsfs;
  86. };
  87. /* adopt Linux style fp layout, _libc_fpstate of glibc:
  88. * Because self-contained definition is needed for Pal definition,
  89. * same layout is defined with PAL prefix.
  90. */
  91. #define PAL_FP_XSTATE_MAGIC1 0x46505853U
  92. #define PAL_FP_XSTATE_MAGIC2 0x46505845U
  93. #define PAL_FP_XSTATE_MAGIC2_SIZE (sizeof(PAL_FP_XSTATE_MAGIC2))
  94. enum PAL_XFEATURE {
  95. PAL_XFEATURE_FP,
  96. PAL_XFEATURE_SSE,
  97. PAL_XFEATURE_YMM,
  98. PAL_XFEATURE_BNDREGS,
  99. PAL_XFEATURE_BNDCSR,
  100. PAL_XFEATURE_OPMASK,
  101. PAL_XFEATURE_ZMM_Hi256,
  102. PAL_XFEATURE_Hi16_ZMM,
  103. PAL_XFEATURE_PT,
  104. PAL_XFEATURE_PKRU,
  105. PAL_XFEATURE_MAX,
  106. };
  107. #define PAL_XFEATURE_MASK_FP (1UL << PAL_XFEATURE_FP)
  108. #define PAL_XFEATURE_MASK_SSE (1UL << PAL_XFEATURE_SSE)
  109. #define PAL_XFEATURE_MASK_YMM (1UL << PAL_XFEATURE_YMM)
  110. #define PAL_XFEATURE_MASK_BNDREGS (1UL << PAL_XFEATURE_BNDREGS)
  111. #define PAL_XFEATURE_MASK_BNDCSR (1UL << PAL_XFEATURE_BNDCSR)
  112. #define PAL_XFEATURE_MASK_OPMASK (1UL << PAL_XFEATURE_OPMASK)
  113. #define PAL_XFEATURE_MASK_ZMM_Hi256 (1UL << PAL_XFEATURE_ZMM_Hi256)
  114. #define PAL_XFEATURE_MASK_Hi16_ZMM (1UL << PAL_XFEATURE_Hi16_ZMM)
  115. #define PAL_XFEATURE_MASK_PT (1UL << PAL_XFEATURE_PT)
  116. #define PAL_XFEATURE_MASK_PKRU (1UL << PAL_XFEATURE_PKRU)
  117. #define PAL_XFEATURE_MASK_FPSSE (PAL_XFEATURE_MASK_FP \
  118. | PAL_XFEATURE_MASK_SSE)
  119. #define PAL_XFEATURE_MASK_AVX512 (PAL_XFEATURE_MASK_OPMASK \
  120. | PAL_XFEATURE_MASK_ZMM_Hi256 \
  121. | PAL_XFEATURE_MASK_Hi16_ZMM)
  122. typedef struct {
  123. uint32_t magic1; /* PAL_FP_XSTATE_MAGIC1 */
  124. uint32_t extended_size; /* xsave_size */
  125. uint64_t xfeatures; /* XSAVE feature */
  126. uint32_t xstate_size; /* xsave_size + PAL_FP_STATE_MAGIC2_SIZE */
  127. uint32_t padding[7];
  128. } PAL_FPX_SW_BYTES;
  129. typedef struct {
  130. uint32_t cwd;
  131. uint32_t swd;
  132. uint32_t twd;
  133. uint32_t fip;
  134. uint32_t fcs;
  135. uint32_t foo;
  136. uint32_t fos;
  137. uint32_t st_space[20];
  138. uint8_t ftop;
  139. uint8_t changed;
  140. uint8_t lookahead;
  141. uint8_t no_update;
  142. uint8_t rm;
  143. uint8_t alimit;
  144. void* info; /* struct math_emu_info */
  145. uint32_t entry_eip;
  146. } PAL_SWREGS_STATE;
  147. typedef struct {
  148. uint16_t significand[4];
  149. uint16_t exponent;
  150. uint16_t padding[3];
  151. } PAL_FPXREG;
  152. typedef struct {
  153. uint32_t element[4];
  154. } PAL_XMMREG;
  155. typedef struct {
  156. /* 64-bit FXSAVE format. */
  157. uint16_t cwd;
  158. uint16_t swd;
  159. uint16_t ftw;
  160. uint16_t fop;
  161. uint64_t rip;
  162. uint64_t rdp;
  163. uint32_t mxcsr;
  164. uint32_t mxcr_mask;
  165. PAL_FPXREG st[8];
  166. PAL_XMMREG xmm[16];
  167. union {
  168. uint32_t padding[24];
  169. struct {
  170. uint32_t padding2[12];
  171. PAL_FPX_SW_BYTES sw_reserved;
  172. };
  173. };
  174. } PAL_FPSTATE;
  175. typedef struct {
  176. uint64_t xfeatures;
  177. uint64_t xcomp_bv;
  178. uint64_t reserved[6];
  179. } __attribute__((packed)) PAL_XSTATE_HEADER;
  180. #define PAL_XSTATE_ALIGN 64
  181. typedef struct {
  182. PAL_FPSTATE fpstate;
  183. PAL_XSTATE_HEADER header;
  184. } __attribute__((packed, aligned(PAL_XSTATE_ALIGN))) PAL_XREGS_STATE;
  185. #else
  186. # error "Unsupported architecture"
  187. #endif
  188. typedef struct {
  189. #ifdef __x86_64__
  190. PAL_NUM r8, r9, r10, r11, r12, r13, r14, r15;
  191. PAL_NUM rdi, rsi, rbp, rbx, rdx, rax, rcx;
  192. PAL_NUM rsp, rip;
  193. PAL_NUM efl, csgsfs, err, trapno, oldmask, cr2;
  194. PAL_XREGS_STATE* fpregs;
  195. #else
  196. # error "Unsupported architecture"
  197. #endif
  198. } PAL_CONTEXT;
  199. #define PAL_TRUE true
  200. #define PAL_FALSE false
  201. /********** PAL TYPE DEFINITIONS **********/
  202. enum {
  203. pal_type_file,
  204. pal_type_pipe,
  205. pal_type_pipesrv,
  206. pal_type_pipecli,
  207. pal_type_pipeprv,
  208. pal_type_dev,
  209. pal_type_dir,
  210. pal_type_tcp,
  211. pal_type_tcpsrv,
  212. pal_type_udp,
  213. pal_type_udpsrv,
  214. pal_type_process,
  215. pal_type_thread,
  216. pal_type_mutex,
  217. pal_type_event,
  218. pal_type_eventfd,
  219. PAL_HANDLE_TYPE_BOUND,
  220. };
  221. #define PAL_IDX_POISON ((PAL_IDX)-1) /* PAL identifier poison value */
  222. #define PAL_GET_TYPE(h) (HANDLE_HDR(h)->type)
  223. #define PAL_CHECK_TYPE(h, t) (PAL_GET_TYPE(h) == pal_type_##t)
  224. #define UNKNOWN_HANDLE(handle) (PAL_GET_TYPE(handle) >= PAL_HANDLE_TYPE_BOUND)
  225. typedef struct { PAL_PTR start, end; } PAL_PTR_RANGE;
  226. typedef struct {
  227. PAL_NUM cpu_num;
  228. PAL_STR cpu_vendor;
  229. PAL_STR cpu_brand;
  230. PAL_NUM cpu_family;
  231. PAL_NUM cpu_model;
  232. PAL_NUM cpu_stepping;
  233. PAL_STR cpu_flags;
  234. } PAL_CPU_INFO;
  235. typedef struct {
  236. PAL_NUM mem_total;
  237. } PAL_MEM_INFO;
  238. /********** PAL APIs **********/
  239. typedef struct {
  240. PAL_STR host_type;
  241. /* An identifier of current picoprocess */
  242. PAL_NUM process_id;
  243. PAL_NUM host_id;
  244. /***** Handles and executables *****/
  245. /* program manifest */
  246. PAL_HANDLE manifest_handle;
  247. /* executable name */
  248. PAL_STR executable;
  249. /* handle of parent process */
  250. PAL_HANDLE parent_process;
  251. /* handle of first thread */
  252. PAL_HANDLE first_thread;
  253. /* debug stream */
  254. PAL_HANDLE debug_stream;
  255. /***** Memory layout ******/
  256. /* The range of user address */
  257. PAL_PTR_RANGE user_address;
  258. /* Reserved memory range inside of user address.
  259. * Used for example by SGX for exec area (including memory gap) in the
  260. * middle of the heap. If unused set start == end. */
  261. PAL_PTR_RANGE user_address_hole;
  262. /* address where executable is loaded */
  263. PAL_PTR_RANGE executable_range;
  264. /* manifest preloaded here */
  265. PAL_PTR_RANGE manifest_preload;
  266. /***** Host information *****/
  267. /* Host allocation alignment.
  268. * This currently is (and most likely will always be) indistinguishable from the page size,
  269. * looking from the LibOS perspective. The two values can be different on the PAL level though,
  270. * see e.g. SYSTEM_INFO::dwAllocationGranularity on Windows.
  271. */
  272. PAL_NUM alloc_align;
  273. /* CPU information (only required ones) */
  274. PAL_CPU_INFO cpu_info;
  275. /* Memory information (only required ones) */
  276. PAL_MEM_INFO mem_info;
  277. /* Attestation information */
  278. PAL_STR attestation_status;
  279. PAL_STR attestation_timestamp;
  280. /* Purely for profiling */
  281. PAL_NUM startup_time;
  282. PAL_NUM host_specific_startup_time;
  283. PAL_NUM relocation_time;
  284. PAL_NUM linking_time;
  285. PAL_NUM manifest_loading_time;
  286. PAL_NUM allocation_time;
  287. PAL_NUM tail_startup_time;
  288. PAL_NUM child_creation_time;
  289. } PAL_CONTROL;
  290. #define pal_control (*pal_control_addr())
  291. PAL_CONTROL * pal_control_addr (void);
  292. /* The ABI includes three calls to allocate, free, and modify the
  293. * permission bits on page-base virtual memory. Permissions in-
  294. * clude read, write, execute, and guard. Memory regions can be
  295. * unallocated, reserved, or backed by committed memory
  296. */
  297. /* Memory Allocation Flags */
  298. #define PAL_ALLOC_RESERVE 0x0001 /* Only reserve the memory */
  299. #ifdef IN_PAL
  300. #define PAL_ALLOC_INTERNAL 0x8000
  301. #endif
  302. /* Memory Protection Flags */
  303. #define PAL_PROT_NONE 0x0 /* 0x0 Page can not be accessed. */
  304. #define PAL_PROT_READ 0x1 /* 0x1 Page can be read. */
  305. #define PAL_PROT_WRITE 0x2 /* 0x2 Page can be written. */
  306. #define PAL_PROT_EXEC 0x4 /* 0x4 Page can be executed. */
  307. #define PAL_PROT_WRITECOPY 0x8 /* 0x8 Copy on write */
  308. #define PAL_PROT_MASK 0xF
  309. // If addr != NULL, then the returned region is always exactly at addr.
  310. PAL_PTR
  311. DkVirtualMemoryAlloc (PAL_PTR addr, PAL_NUM size, PAL_FLG alloc_type,
  312. PAL_FLG prot);
  313. void
  314. DkVirtualMemoryFree (PAL_PTR addr, PAL_NUM size);
  315. PAL_BOL
  316. DkVirtualMemoryProtect (PAL_PTR addr, PAL_NUM size, PAL_FLG prot);
  317. /* The ABI includes one call to create a child process and one call to
  318. * terminate the running process. A child process does not inherit
  319. * any objects or memory from its parent process and the parent
  320. * process may not modify the execution of its children. A parent can
  321. * wait for a child to exit using its handle. Parent and child may
  322. * communicate through I/O streams provided by the parent to the
  323. * child at creation
  324. */
  325. #define PAL_PROCESS_MASK 0x0
  326. PAL_HANDLE
  327. DkProcessCreate (PAL_STR uri, PAL_STR * args);
  328. noreturn void
  329. DkProcessExit (PAL_NUM exitCode);
  330. /* The stream ABI includes nine calls to open, read, write, map, unmap,
  331. * truncate, flush, delete and wait for I/O streams and three calls to
  332. * access metadata about an I/O stream. The ABI purposefully does not
  333. * provide an ioctl call. Supported URI schemes include file:, pipe:,
  334. * http:, https:, tcp:, udp:, pipe.srv:, http.srv, tcp.srv:, and udp.srv:.
  335. * The latter four schemes are used to open inbound I/O streams for
  336. * server applications.
  337. */
  338. /* DkStreamOpen
  339. * access_mode: WRONLY or RDONLY or RDWR
  340. * share_flags: permission for the created file
  341. * create_flags: the creation options for the file
  342. * options: other options
  343. */
  344. /* Stream Access Flags */
  345. #define PAL_ACCESS_RDONLY 00
  346. #define PAL_ACCESS_WRONLY 01
  347. #define PAL_ACCESS_RDWR 02
  348. #define PAL_ACCESS_APPEND 04
  349. #define PAL_ACCESS_MASK 07
  350. /* Stream Sharing Flags */
  351. #define PAL_SHARE_GLOBAL_X 01
  352. #define PAL_SHARE_GLOBAL_W 02
  353. #define PAL_SHARE_GLOBAL_R 04
  354. #define PAL_SHARE_GROUP_X 010
  355. #define PAL_SHARE_GROUP_W 020
  356. #define PAL_SHARE_GROUP_R 040
  357. #define PAL_SHARE_OWNER_X 0100
  358. #define PAL_SHARE_OWNER_W 0200
  359. #define PAL_SHARE_OWNER_R 0400
  360. #define PAL_SHARE_MASK 0777
  361. /* Stream Create Flags */
  362. #define PAL_CREATE_TRY 0100 /* Create file if file not exist (O_CREAT) */
  363. #define PAL_CREATE_ALWAYS 0200 /* Create file and fail if file already exist (O_CREAT|O_EXCL) */
  364. #define PAL_CREATE_DUALSTACK 0400 /* Create dual-stack socket (opposite of IPV6_V6ONLY) */
  365. #define PAL_CREATE_MASK 0700
  366. /* Stream Option Flags */
  367. #define PAL_OPTION_NONBLOCK 04000
  368. #define PAL_OPTION_MASK 04000
  369. /* CLOEXEC is generic for any stream.
  370. * SEMAPHORE is specific to eventfd syscall. */
  371. #define PAL_OPTION_CLOEXEC 01000
  372. #define PAL_OPTION_EFD_SEMAPHORE 02000
  373. /* error value of read/write */
  374. #define PAL_STREAM_ERROR ((PAL_NUM)-1L)
  375. #define WITHIN_MASK(val, mask) (((val)|(mask)) == (mask))
  376. PAL_HANDLE
  377. DkStreamOpen (PAL_STR uri, PAL_FLG access, PAL_FLG share_flags,
  378. PAL_FLG create, PAL_FLG options);
  379. PAL_HANDLE
  380. DkStreamWaitForClient (PAL_HANDLE handle);
  381. PAL_NUM
  382. DkStreamRead (PAL_HANDLE handle, PAL_NUM offset, PAL_NUM count,
  383. PAL_PTR buffer, PAL_PTR source, PAL_NUM size);
  384. PAL_NUM
  385. DkStreamWrite (PAL_HANDLE handle, PAL_NUM offset, PAL_NUM count,
  386. PAL_PTR buffer, PAL_STR dest);
  387. #define PAL_DELETE_RD 01
  388. #define PAL_DELETE_WR 02
  389. void
  390. DkStreamDelete (PAL_HANDLE handle, PAL_FLG access);
  391. PAL_PTR
  392. DkStreamMap (PAL_HANDLE handle, PAL_PTR address, PAL_FLG prot,
  393. PAL_NUM offset, PAL_NUM size);
  394. void
  395. DkStreamUnmap (PAL_PTR addr, PAL_NUM size);
  396. /* Sets the length of the file referenced by handle to length. Returns the 0
  397. * on success, a _positive_ errno on failure.
  398. */
  399. PAL_NUM
  400. DkStreamSetLength (PAL_HANDLE handle, PAL_NUM length);
  401. PAL_BOL
  402. DkStreamFlush (PAL_HANDLE handle);
  403. PAL_BOL
  404. DkSendHandle (PAL_HANDLE handle, PAL_HANDLE cargo);
  405. PAL_HANDLE
  406. DkReceiveHandle (PAL_HANDLE handle);
  407. /* stream attribute structure */
  408. typedef struct {
  409. PAL_IDX handle_type;
  410. PAL_BOL disconnected;
  411. PAL_BOL nonblocking;
  412. PAL_BOL readable, writable, runnable;
  413. PAL_BOL secure;
  414. PAL_FLG share_flags;
  415. PAL_NUM pending_size;
  416. PAL_IDX no_of_fds;
  417. PAL_IDX fds[MAX_FDS];
  418. union {
  419. struct {
  420. PAL_NUM linger;
  421. PAL_NUM receivebuf, sendbuf;
  422. PAL_NUM receivetimeout, sendtimeout;
  423. PAL_BOL tcp_cork;
  424. PAL_BOL tcp_keepalive;
  425. PAL_BOL tcp_nodelay;
  426. } socket;
  427. };
  428. } PAL_STREAM_ATTR;
  429. PAL_BOL
  430. DkStreamAttributesQuery (PAL_STR uri, PAL_STREAM_ATTR * attr);
  431. PAL_BOL
  432. DkStreamAttributesQueryByHandle (PAL_HANDLE handle,
  433. PAL_STREAM_ATTR * attr);
  434. PAL_BOL
  435. DkStreamAttributesSetByHandle (PAL_HANDLE handle, PAL_STREAM_ATTR * attr);
  436. PAL_NUM
  437. DkStreamGetName (PAL_HANDLE handle, PAL_PTR buffer, PAL_NUM size);
  438. PAL_BOL
  439. DkStreamChangeName (PAL_HANDLE handle, PAL_STR uri);
  440. /* The ABI supports multithreading through five calls to create,
  441. * sleep, yield the scheduler quantum for, resume execution of, and
  442. * terminate threads, as well as seven calls to create, signal, and
  443. * block on synchronization objects
  444. */
  445. #define PAL_THREAD_MASK 0
  446. PAL_HANDLE
  447. DkThreadCreate (PAL_PTR addr, PAL_PTR param);
  448. // assuming duration to be in microseconds
  449. PAL_NUM
  450. DkThreadDelayExecution (PAL_NUM duration);
  451. void
  452. DkThreadYieldExecution (void);
  453. noreturn void DkThreadExit(PAL_PTR clear_child_tid);
  454. PAL_BOL
  455. DkThreadResume (PAL_HANDLE thread);
  456. /* Exception Handling */
  457. /* arithmetic error (div-by-zero, floating point exception, etc.) */
  458. #define PAL_EVENT_ARITHMETIC_ERROR 1
  459. /* segmentation fault, protection fault, bus fault */
  460. #define PAL_EVENT_MEMFAULT 2
  461. /* illegal instructions */
  462. #define PAL_EVENT_ILLEGAL 3
  463. /* terminated by external program */
  464. #define PAL_EVENT_QUIT 4
  465. /* suspended by external program */
  466. #define PAL_EVENT_SUSPEND 5
  467. /* continued by external program */
  468. #define PAL_EVENT_RESUME 6
  469. /* failure within PAL calls */
  470. #define PAL_EVENT_FAILURE 7
  471. #define PAL_EVENT_NUM_BOUND 8
  472. #define PAL_EVENT_PRIVATE 0x0001 /* upcall specific to thread */
  473. #define PAL_EVENT_RESET 0x0002 /* reset the event upcall */
  474. typedef void (*PAL_EVENT_HANDLER) (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT *);
  475. PAL_BOL
  476. DkSetExceptionHandler (PAL_EVENT_HANDLER handler, PAL_NUM event);
  477. void DkExceptionReturn (PAL_PTR event);
  478. /* parameter: keeping int threadHandle for now (to be in sync with the paper).
  479. * We may want to replace it with a PAL_HANDLE. Ideally, either use PAL_HANDLE
  480. * or threadHandle.
  481. */
  482. /* Create a Mutex.
  483. * initialCount of 0 is totally unlocked; an initialCount of 1
  484. * is initialized to locked. */
  485. PAL_HANDLE
  486. DkMutexCreate (PAL_NUM initialCount);
  487. /* Destroy a mutex using DkObjectClose */
  488. void
  489. DkMutexRelease (PAL_HANDLE mutexHandle);
  490. PAL_HANDLE
  491. DkNotificationEventCreate (PAL_BOL initialState);
  492. PAL_HANDLE
  493. DkSynchronizationEventCreate (PAL_BOL initialState);
  494. void
  495. DkEventSet (PAL_HANDLE eventHandle);
  496. void
  497. DkEventClear (PAL_HANDLE eventHandle);
  498. #define NO_TIMEOUT ((PAL_NUM)-1)
  499. PAL_BOL DkSynchronizationObjectWait(PAL_HANDLE handle, PAL_NUM timeout_us);
  500. #define PAL_WAIT_SIGNAL 1 /* ignored in events */
  501. #define PAL_WAIT_READ 2
  502. #define PAL_WAIT_WRITE 4
  503. #define PAL_WAIT_ERROR 8 /* ignored in events */
  504. PAL_BOL DkStreamsWaitEvents(PAL_NUM count, PAL_HANDLE* handle_array, PAL_FLG* events,
  505. PAL_FLG* ret_events, PAL_NUM timeout_us);
  506. /* Deprecate DkObjectReference */
  507. void DkObjectClose (PAL_HANDLE objectHandle);
  508. /* the ABI includes seven assorted calls to get wall clock
  509. * time, generate cryptographically-strong random bits, flush por-
  510. * tions of instruction caches, increment and decrement the reference
  511. * counts on objects shared between threads, and to coordinate
  512. * threads with the security monitor during process serialization
  513. */
  514. /* assuming the time to be in microseconds */
  515. PAL_NUM
  516. DkSystemTimeQuery (void);
  517. /*
  518. * Cryptographically secure random.
  519. * 0 on success, negative on failure.
  520. */
  521. PAL_NUM
  522. DkRandomBitsRead (PAL_PTR buffer, PAL_NUM size);
  523. PAL_BOL
  524. DkInstructionCacheFlush (PAL_PTR addr, PAL_NUM size);
  525. #define PAL_SEGMENT_FS 0x1
  526. #define PAL_SEGMENT_GS 0x2
  527. PAL_PTR DkSegmentRegister (PAL_FLG reg, PAL_PTR addr);
  528. PAL_NUM DkMemoryAvailableQuota (void);
  529. #define PAL_CPUID_WORD_EAX 0
  530. #define PAL_CPUID_WORD_EBX 1
  531. #define PAL_CPUID_WORD_ECX 2
  532. #define PAL_CPUID_WORD_EDX 3
  533. #define PAL_CPUID_WORD_NUM 4
  534. PAL_BOL
  535. DkCpuIdRetrieve (PAL_IDX leaf, PAL_IDX subleaf, PAL_IDX values[4]);
  536. #ifdef __GNUC__
  537. # define symbol_version_default(real, name, version) \
  538. __asm__ (".symver " #real "," #name "@@" #version "\n")
  539. #else
  540. # define symbol_version_default(real, name, version)
  541. #endif
  542. #endif /* PAL_H */