diff --git a/Documentation/devel/new-syscall.rst b/Documentation/devel/new-syscall.rst index 7bf6a651d2..d7b00e6920 100644 --- a/Documentation/devel/new-syscall.rst +++ b/Documentation/devel/new-syscall.rst @@ -43,9 +43,9 @@ a |~| few new PAL calls to the existing interface. To add a |~| new PAL call, first modify :file:`pal/include/pal/pal.h`. Define the PAL call:: - bool DkThreadSetCPUAffinity(size_t cpu_num, PAL_IDX* cpu_indexes); + bool PalThreadSetCPUAffinity(size_t cpu_num, PAL_IDX* cpu_indexes); -The naming convention of a |~| PAL call is to start functions with the ``Dk`` +The naming convention of a |~| PAL call is to start functions with the ``Pal`` prefix, followed by a comprehensive name describing the purpose of the PAL call. diff --git a/Documentation/devel/onboarding.rst b/Documentation/devel/onboarding.rst index b14a3742ad..0e9b7bc1a8 100644 --- a/Documentation/devel/onboarding.rst +++ b/Documentation/devel/onboarding.rst @@ -622,11 +622,11 @@ system call that is not implemented in Gramine (recall that ``-38`` is the ``libos/src/bookkeep/shim_thread.c``. - If the system call cannot be resolved entirely inside the LibOS component - of Gramine, and the current set of PAL API functions (``Dk..()`` functions) - is not enough to service this system call, you must add a new PAL API - function (e.g., ``DkSomeNewFunction``). You will need to implement the - entry-point function (``DkSomeNewFunction``) in the common PAL code, as - well as each host-specific function (``_DkSomeNewFunction``) in each + of Gramine, and the current set of PAL API functions (``Pal..()`` + functions) is not enough to service this system call, you must add a new + PAL API function (e.g., ``PalSomeNewFunction``). You will need to implement + the entry-point function (``PalSomeNewFunction``) in the common PAL code, + as well as each host-specific function (``_PalSomeNewFunction``) in each supported host in PAL. Note that Gramine strives to keep the PAL API as small as possible. It is diff --git a/Documentation/glossary.rst b/Documentation/glossary.rst index 6a48656318..09791612bf 100644 --- a/Documentation/glossary.rst +++ b/Documentation/glossary.rst @@ -9,7 +9,7 @@ Glossary Platform Adaptation Layer PAL is the layer of Gramine that implements a narrow Drawbridge-like ABI - interface (with function names starting with the `Dk` prefix) + interface (with function names starting with the `Pal` prefix) .. seealso:: diff --git a/Documentation/pal/host-abi.rst b/Documentation/pal/host-abi.rst index de726cecab..1db55be411 100644 --- a/Documentation/pal/host-abi.rst +++ b/Documentation/pal/host-abi.rst @@ -72,7 +72,7 @@ PAL public state All PALs in Gramine expose a structure that provides static immutable information about the current process and its host. The address of the -structure can be retrieved via :func:`DkGetPalPublicState()` and can be +structure can be retrieved via :func:`PalGetPalPublicState()` and can be memorized in a global variable for ease of use. .. doxygenstruct:: pal_public_state @@ -105,10 +105,10 @@ on page-base virtual memory. Permissions include read, write, execute, and guard. Memory regions can be unallocated, reserved, or backed by committed memory. -.. doxygenfunction:: DkVirtualMemoryAlloc +.. doxygenfunction:: PalVirtualMemoryAlloc :project: pal -.. doxygenfunction:: DkVirtualMemoryFree +.. doxygenfunction:: PalVirtualMemoryFree :project: pal .. doxygentypedef:: pal_alloc_flags_t @@ -116,7 +116,7 @@ memory. .. doxygentypedef:: pal_prot_flags_t :project: pal -.. doxygenfunction:: DkVirtualMemoryProtect +.. doxygenfunction:: PalVirtualMemoryProtect :project: pal @@ -130,9 +130,9 @@ children. A parent can wait for a child to exit using its handle. Parent and child may communicate through I/O streams provided by the parent to the child at creation. -.. doxygenfunction:: DkProcessCreate +.. doxygenfunction:: PalProcessCreate :project: pal -.. doxygenfunction:: DkProcessExit +.. doxygenfunction:: PalProcessExit :project: pal @@ -156,40 +156,40 @@ provide an ioctl call. Supported URI schemes include: The latter four schemes are used to open inbound I/O streams for server applications. -.. doxygenfunction:: DkStreamOpen +.. doxygenfunction:: PalStreamOpen :project: pal -.. doxygenfunction:: DkStreamWaitForClient +.. doxygenfunction:: PalStreamWaitForClient :project: pal -.. doxygenfunction:: DkStreamRead +.. doxygenfunction:: PalStreamRead :project: pal -.. doxygenfunction:: DkStreamWrite +.. doxygenfunction:: PalStreamWrite :project: pal -.. doxygenfunction:: DkStreamDelete +.. doxygenfunction:: PalStreamDelete :project: pal -.. doxygenfunction:: DkStreamMap +.. doxygenfunction:: PalStreamMap :project: pal -.. doxygenfunction:: DkStreamUnmap +.. doxygenfunction:: PalStreamUnmap :project: pal -.. doxygenfunction:: DkStreamSetLength +.. doxygenfunction:: PalStreamSetLength :project: pal -.. doxygenfunction:: DkStreamFlush +.. doxygenfunction:: PalStreamFlush :project: pal -.. doxygenfunction:: DkSendHandle +.. doxygenfunction:: PalSendHandle :project: pal -.. doxygenfunction:: DkReceiveHandle +.. doxygenfunction:: PalReceiveHandle :project: pal -.. doxygenfunction:: DkStreamAttributesQuery +.. doxygenfunction:: PalStreamAttributesQuery :project: pal .. doxygentypedef:: PAL_STREAM_ATTR @@ -197,16 +197,16 @@ applications. .. doxygenstruct:: _PAL_STREAM_ATTR :project: pal -.. doxygenfunction:: DkStreamAttributesQueryByHandle +.. doxygenfunction:: PalStreamAttributesQueryByHandle :project: pal -.. doxygenfunction:: DkStreamAttributesSetByHandle +.. doxygenfunction:: PalStreamAttributesSetByHandle :project: pal -.. doxygenfunction:: DkStreamGetName +.. doxygenfunction:: PalStreamGetName :project: pal -.. doxygenfunction:: DkStreamChangeName +.. doxygenfunction:: PalStreamChangeName :project: pal @@ -247,25 +247,25 @@ Socket handling .. doxygenstruct:: pal_iovec :project: pal -.. doxygenfunction:: DkSocketCreate +.. doxygenfunction:: PalSocketCreate :project: pal -.. doxygenfunction:: DkSocketBind +.. doxygenfunction:: PalSocketBind :project: pal -.. doxygenfunction:: DkSocketListen +.. doxygenfunction:: PalSocketListen :project: pal -.. doxygenfunction:: DkSocketAccept +.. doxygenfunction:: PalSocketAccept :project: pal -.. doxygenfunction:: DkSocketConnect +.. doxygenfunction:: PalSocketConnect :project: pal -.. doxygenfunction:: DkSocketSend +.. doxygenfunction:: PalSocketSend :project: pal -.. doxygenfunction:: DkSocketRecv +.. doxygenfunction:: PalSocketRecv :project: pal @@ -276,16 +276,16 @@ The ABI supports multithreading through five calls to create, sleep, yield the scheduler quantum for, resume execution of, and terminate threads, as well as seven calls to create, signal, and block on synchronization objects. -.. doxygenfunction:: DkThreadCreate +.. doxygenfunction:: PalThreadCreate :project: pal -.. doxygenfunction:: DkThreadYieldExecution +.. doxygenfunction:: PalThreadYieldExecution :project: pal -.. doxygenfunction:: DkThreadExit +.. doxygenfunction:: PalThreadExit :project: pal -.. doxygenfunction:: DkThreadResume +.. doxygenfunction:: PalThreadResume :project: pal @@ -304,32 +304,32 @@ Exception handling .. doxygentypedef:: pal_event_handler_t :project: pal -.. doxygenfunction:: DkSetExceptionHandler +.. doxygenfunction:: PalSetExceptionHandler :project: pal Synchronization ^^^^^^^^^^^^^^^ -.. doxygenfunction:: DkEventCreate +.. doxygenfunction:: PalEventCreate :project: pal -.. doxygenfunction:: DkEventSet +.. doxygenfunction:: PalEventSet :project: pal -.. doxygenfunction:: DkEventClear +.. doxygenfunction:: PalEventClear :project: pal -.. doxygenfunction:: DkEventWait +.. doxygenfunction:: PalEventWait :project: pal Objects ^^^^^^^ -.. doxygenfunction:: DkStreamsWaitEvents +.. doxygenfunction:: PalStreamsWaitEvents :project: pal -.. doxygenfunction:: DkObjectClose +.. doxygenfunction:: PalObjectClose :project: pal Miscellaneous @@ -340,38 +340,38 @@ cryptographically-strong random bits, flush portions of instruction caches, increment and decrement the reference counts on objects shared between threads, and to obtain an attestation report and quote. -.. doxygenfunction:: DkDebugLog +.. doxygenfunction:: PalDebugLog :project: pal -.. doxygenfunction:: DkGetPalPublicState +.. doxygenfunction:: PalGetPalPublicState :project: pal -.. doxygenfunction:: DkSystemTimeQuery +.. doxygenfunction:: PalSystemTimeQuery :project: pal -.. doxygenfunction:: DkRandomBitsRead +.. doxygenfunction:: PalRandomBitsRead :project: pal -.. doxygenfunction:: DkSegmentBaseGet +.. doxygenfunction:: PalSegmentBaseGet :project: pal -.. doxygenfunction:: DkSegmentBaseSet +.. doxygenfunction:: PalSegmentBaseSet :project: pal .. doxygenenum:: pal_segment_reg :project: pal -.. doxygenfunction:: DkMemoryAvailableQuota +.. doxygenfunction:: PalMemoryAvailableQuota :project: pal -.. doxygenfunction:: DkCpuIdRetrieve +.. doxygenfunction:: PalCpuIdRetrieve :project: pal -.. doxygenfunction:: DkAttestationReport +.. doxygenfunction:: PalAttestationReport :project: pal -.. doxygenfunction:: DkAttestationQuote +.. doxygenfunction:: PalAttestationQuote :project: pal -.. doxygenfunction:: DkGetSpecialKey +.. doxygenfunction:: PalGetSpecialKey :project: pal diff --git a/common/src/crypto/adapters/mbedtls_adapter.c b/common/src/crypto/adapters/mbedtls_adapter.c index 676403eaf3..08df96497b 100644 --- a/common/src/crypto/adapters/mbedtls_adapter.c +++ b/common/src/crypto/adapters/mbedtls_adapter.c @@ -21,7 +21,7 @@ #include "pal_error.h" /* This is declared in pal_internal.h, but that can't be included here. */ -int DkRandomBitsRead(void* buffer, size_t size); +int PalRandomBitsRead(void* buffer, size_t size); static int mbedtls_to_pal_error(int error) { switch (error) { @@ -269,7 +269,7 @@ int mbedtls_hardware_poll(void* data, unsigned char* output, size_t len, size_t* assert(output && olen); *olen = 0; - int ret = DkRandomBitsRead(output, len); + int ret = PalRandomBitsRead(output, len); if (ret < 0) return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; @@ -427,7 +427,7 @@ int lib_SSLSave(LIB_SSL_CONTEXT* ssl_ctx, uint8_t* buf, size_t buf_size, size_t* * and expects a return value of 0 for success and nonzero for failure. */ static int random_wrapper(void* private, unsigned char* data, size_t size) { __UNUSED(private); - return DkRandomBitsRead(data, size); + return PalRandomBitsRead(data, size); } int lib_DhInit(LIB_DH_CONTEXT* context) { diff --git a/libos/include/arch/x86_64/shim_tcb-arch.h b/libos/include/arch/x86_64/shim_tcb-arch.h index ea16459e64..e92a509784 100644 --- a/libos/include/arch/x86_64/shim_tcb-arch.h +++ b/libos/include/arch/x86_64/shim_tcb-arch.h @@ -143,7 +143,7 @@ struct libos_xstate { } while (0) static inline void set_tls(uintptr_t tls) { - DkSegmentBaseSet(PAL_SEGMENT_FS, tls); + PalSegmentBaseSet(PAL_SEGMENT_FS, tls); } static inline void set_default_tls(void) { @@ -152,6 +152,6 @@ static inline void set_default_tls(void) { static inline uintptr_t get_tls(void) { uintptr_t addr = 0; - (void)DkSegmentBaseGet(PAL_SEGMENT_FS, &addr); + (void)PalSegmentBaseGet(PAL_SEGMENT_FS, &addr); return addr; } diff --git a/libos/include/shim_checkpoint.h b/libos/include/shim_checkpoint.h index b4c463d812..cb8cd0f98c 100644 --- a/libos/include/shim_checkpoint.h +++ b/libos/include/shim_checkpoint.h @@ -190,7 +190,7 @@ enum { tmp = NEXT_CP_ENTRY(); \ if (!tmp) { \ log_error("cannot find checkpoint entry"); \ - DkProcessExit(1); \ + PalProcessExit(1); \ } \ tmp->cp_val; \ }) @@ -277,7 +277,7 @@ struct libos_cp_map_entry* get_cp_map_entry(void* map, void* addr, bool create); struct libos_cp_map_entry* e = get_cp_map_entry(store->cp_map, obj, true); \ if (!e) { \ log_error("cannot extend checkpoint map buffer"); \ - DkProcessExit(1); \ + PalProcessExit(1); \ } \ e->off = (off); \ } while (0) diff --git a/libos/include/shim_fs.h b/libos/include/shim_fs.h index 69574eff53..c1c4f226b8 100644 --- a/libos/include/shim_fs.h +++ b/libos/include/shim_fs.h @@ -117,8 +117,8 @@ struct libos_fs_ops { * \param flags `mmap` flags (`MAP_*`). * \param offset Offset in file. * - * Maps the file at given address. This might involve mapping directly (`DkStreamMap`), or - * mapping anonymous memory (`DkVirtualMemoryAlloc`) and writing data. + * Maps the file at given address. This might involve mapping directly (`PalStreamMap`), or + * mapping anonymous memory (`PalVirtualMemoryAlloc`) and writing data. * * `addr`, `offset` and `size` must be alloc-aligned (see `IS_ALLOC_ALIGNED*` macros in * `shim_internal.h`). diff --git a/libos/include/shim_lock.h b/libos/include/shim_lock.h index 46b1dd2c36..38d704eedb 100644 --- a/libos/include/shim_lock.h +++ b/libos/include/shim_lock.h @@ -24,18 +24,18 @@ static inline void clear_lock(struct libos_lock* l) { static inline bool create_lock(struct libos_lock* l) { l->owner = 0; - return DkEventCreate(&l->lock, /*init_signaled=*/true, /*auto_clear=*/true) == 0; + return PalEventCreate(&l->lock, /*init_signaled=*/true, /*auto_clear=*/true) == 0; } static inline void destroy_lock(struct libos_lock* l) { - DkObjectClose(l->lock); // TODO: handle errors + PalObjectClose(l->lock); // TODO: handle errors clear_lock(l); } static inline void lock(struct libos_lock* l) { assert(l->lock); - while (DkEventWait(l->lock, /*timeout=*/NULL) < 0) + while (PalEventWait(l->lock, /*timeout=*/NULL) < 0) /* nop */; l->owner = get_cur_tid(); @@ -44,7 +44,7 @@ static inline void lock(struct libos_lock* l) { static inline void unlock(struct libos_lock* l) { assert(l->lock); l->owner = 0; - DkEventSet(l->lock); + PalEventSet(l->lock); } static inline bool locked(struct libos_lock* l) { diff --git a/libos/include/shim_pollable_event.h b/libos/include/shim_pollable_event.h index 0a475a14fd..1119c55d7e 100644 --- a/libos/include/shim_pollable_event.h +++ b/libos/include/shim_pollable_event.h @@ -11,7 +11,7 @@ * These events have binary semaphore semantics: * - `set_pollable_event(e)` sets the semaphore to 1 (regardless of its current state), * - `clear_pollable_event(e)` sets the semaphore to 0 (regardless of its current state). - * Additionally `e->read_handle` can be passed to `DkStreamsWaitEvents` (which is actually the only + * Additionally `e->read_handle` can be passed to `PalStreamsWaitEvents` (which is actually the only * purpose these events exist for). */ diff --git a/libos/include/shim_sync.h b/libos/include/shim_sync.h index ddf0d59e1d..c0997380d0 100644 --- a/libos/include/shim_sync.h +++ b/libos/include/shim_sync.h @@ -147,7 +147,7 @@ #define uthash_fatal(msg) \ do { \ log_error("uthash error: %s", msg); \ - DkProcessExit(1); \ + PalProcessExit(1); \ } while (0) #include "uthash.h" diff --git a/libos/include/shim_thread.h b/libos/include/shim_thread.h index 2c033fca8a..8ab7066b69 100644 --- a/libos/include/shim_thread.h +++ b/libos/include/shim_thread.h @@ -213,7 +213,7 @@ static inline void set_cur_thread(struct libos_thread* thread) { static inline void thread_prepare_wait(void) { struct libos_thread* cur_thread = get_cur_thread(); assert(!is_internal(cur_thread)); - DkEventClear(cur_thread->scheduler_event); + PalEventClear(cur_thread->scheduler_event); } static inline int thread_wait(uint64_t* timeout_us, bool ignore_pending_signals) { @@ -224,12 +224,12 @@ static inline int thread_wait(uint64_t* timeout_us, bool ignore_pending_signals) return -EINTR; } - int ret = DkEventWait(cur_thread->scheduler_event, timeout_us); + int ret = PalEventWait(cur_thread->scheduler_event, timeout_us); return ret == -PAL_ERROR_TRYAGAIN ? -ETIMEDOUT : pal_to_unix_errno(ret); } static inline void thread_wakeup(struct libos_thread* thread) { - DkEventSet(thread->scheduler_event); + PalEventSet(thread->scheduler_event); } /* Adds the thread to the wake-up queue. diff --git a/libos/include/shim_vma.h b/libos/include/shim_vma.h index e242121db2..a7dc6c48c1 100644 --- a/libos/include/shim_vma.h +++ b/libos/include/shim_vma.h @@ -60,13 +60,13 @@ int init_vma(void); * if (bkeep_munmap(ptr, len, is_internal, &tmp_vma) < 0) { * handle_errors(); * } - * if (DkVirtualMemoryFree(ptr, len) < 0) { + * if (PalVirtualMemoryFree(ptr, len) < 0) { * handle_errors(); * } * bkeep_remove_tmp_vma(tmp_vma); * * Such a way of freeing is needed, so that no other thread will map the same memory in the window - * between `bkeep_munmap` and `DkVirtualMemoryFree`. + * between `bkeep_munmap` and `PalVirtualMemoryFree`. */ int bkeep_munmap(void* addr, size_t length, bool is_internal, void** tmp_vma_ptr); void bkeep_remove_tmp_vma(void* vma); diff --git a/libos/src/arch/x86_64/shim_arch_prctl.c b/libos/src/arch/x86_64/shim_arch_prctl.c index 95511fab01..0c45bdb59a 100644 --- a/libos/src/arch/x86_64/shim_arch_prctl.c +++ b/libos/src/arch/x86_64/shim_arch_prctl.c @@ -36,7 +36,7 @@ long libos_syscall_arch_prctl(int code, unsigned long addr) { return 0; case ARCH_GET_FS: - return pal_to_unix_errno(DkSegmentBaseGet(PAL_SEGMENT_FS, (unsigned long*)addr)); + return pal_to_unix_errno(PalSegmentBaseGet(PAL_SEGMENT_FS, (unsigned long*)addr)); /* Emulate ARCH_GET_XCOMP_SUPP, ARCH_GET_XCOMP_PERM, ARCH_REQ_XCOMP_PERM by querying CPUID, * it's safe because the PAL already requested AMX permission at startup. Note that @@ -44,7 +44,7 @@ long libos_syscall_arch_prctl(int code, unsigned long addr) { * enables all it can at startup). */ case ARCH_GET_XCOMP_SUPP: case ARCH_GET_XCOMP_PERM: - ret = DkCpuIdRetrieve(EXTENDED_STATE_LEAF, EXTENDED_STATE_SUBLEAF_FEATURES, values); + ret = PalCpuIdRetrieve(EXTENDED_STATE_LEAF, EXTENDED_STATE_SUBLEAF_FEATURES, values); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -64,7 +64,7 @@ long libos_syscall_arch_prctl(int code, unsigned long addr) { return -EOPNOTSUPP; } - ret = DkCpuIdRetrieve(EXTENDED_STATE_LEAF, EXTENDED_STATE_SUBLEAF_FEATURES, values); + ret = PalCpuIdRetrieve(EXTENDED_STATE_LEAF, EXTENDED_STATE_SUBLEAF_FEATURES, values); if (ret < 0) { return pal_to_unix_errno(ret); } diff --git a/libos/src/arch/x86_64/shim_context.c b/libos/src/arch/x86_64/shim_context.c index b744d61b9c..2241de0c18 100644 --- a/libos/src/arch/x86_64/shim_context.c +++ b/libos/src/arch/x86_64/shim_context.c @@ -41,14 +41,14 @@ uint64_t libos_xstate_size(void) { void libos_xstate_init(void) { unsigned int value[4]; - if (DkCpuIdRetrieve(CPUID_LEAF_PROCINFO, 0, value) < 0) + if (PalCpuIdRetrieve(CPUID_LEAF_PROCINFO, 0, value) < 0) goto out; if (!(value[CPUID_WORD_ECX] & CPUID_FEATURE_XSAVE) || !(value[CPUID_WORD_ECX] & CPUID_FEATURE_OSXSAVE)) goto out; - if (DkCpuIdRetrieve(CPUID_LEAF_XSAVE, 0, value) < 0) + if (PalCpuIdRetrieve(CPUID_LEAF_XSAVE, 0, value) < 0) goto out; uint32_t xsavesize = value[CPUID_WORD_ECX]; diff --git a/libos/src/bookkeep/shim_handle.c b/libos/src/bookkeep/shim_handle.c index 3c2f38b937..37fdf3f1a2 100644 --- a/libos/src/bookkeep/shim_handle.c +++ b/libos/src/bookkeep/shim_handle.c @@ -505,7 +505,7 @@ void put_handle(struct libos_handle* hdl) { #ifdef DEBUG_REF log_debug("handle %p closes PAL handle %p", hdl, hdl->pal_handle); #endif - DkObjectClose(hdl->pal_handle); // TODO: handle errors + PalObjectClose(hdl->pal_handle); // TODO: handle errors hdl->pal_handle = NULL; } diff --git a/libos/src/bookkeep/shim_pid.c b/libos/src/bookkeep/shim_pid.c index 14bafd10a4..54554f2ed9 100644 --- a/libos/src/bookkeep/shim_pid.c +++ b/libos/src/bookkeep/shim_pid.c @@ -129,7 +129,7 @@ IDTYPE get_new_id(IDTYPE move_ownership_to) { if (ipc_change_id_owner(ret_id, move_ownership_to) < 0) { /* Good luck unwinding all of above operations. Better just kill everything. */ log_error("Unrecoverable error in %s:%d", __FILE__, __LINE__); - DkProcessExit(1); + PalProcessExit(1); } } else { if (g_last_used_id == g_last_range->end) { @@ -175,7 +175,7 @@ void release_id(IDTYPE id) { * without fully waiting for this process to end. For more information check * "libos/src/sys/shim_exit.c". Change to `log_error` + `die` after fixing. */ log_warning("IPC pid release failed"); - DkProcessExit(1); + PalProcessExit(1); } free(range); return; diff --git a/libos/src/bookkeep/shim_signal.c b/libos/src/bookkeep/shim_signal.c index 3cca8dfbb4..ce07266e55 100644 --- a/libos/src/bookkeep/shim_signal.c +++ b/libos/src/bookkeep/shim_signal.c @@ -313,7 +313,7 @@ static noreturn void internal_fault(const char* errstr, uintptr_t addr, PAL_CONT g_process_ipc_ids.self_vmid, tid); DEBUG_BREAK_ON_FAILURE(); - DkProcessExit(1); + PalProcessExit(1); } static void arithmetic_error_upcall(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) { @@ -537,11 +537,11 @@ int init_signal_handling(void) { return -EINVAL; } - DkSetExceptionHandler(&arithmetic_error_upcall, PAL_EVENT_ARITHMETIC_ERROR); - DkSetExceptionHandler(&memfault_upcall, PAL_EVENT_MEMFAULT); - DkSetExceptionHandler(&illegal_upcall, PAL_EVENT_ILLEGAL); - DkSetExceptionHandler(&quit_upcall, PAL_EVENT_QUIT); - DkSetExceptionHandler(&interrupted_upcall, PAL_EVENT_INTERRUPTED); + PalSetExceptionHandler(&arithmetic_error_upcall, PAL_EVENT_ARITHMETIC_ERROR); + PalSetExceptionHandler(&memfault_upcall, PAL_EVENT_MEMFAULT); + PalSetExceptionHandler(&illegal_upcall, PAL_EVENT_ILLEGAL); + PalSetExceptionHandler(&quit_upcall, PAL_EVENT_QUIT); + PalSetExceptionHandler(&interrupted_upcall, PAL_EVENT_INTERRUPTED); return 0; } diff --git a/libos/src/bookkeep/shim_thread.c b/libos/src/bookkeep/shim_thread.c index 67f88311cd..3a58257c32 100644 --- a/libos/src/bookkeep/shim_thread.c +++ b/libos/src/bookkeep/shim_thread.c @@ -94,8 +94,8 @@ int alloc_thread_libos_stack(struct libos_thread* thread) { } bool need_mem_free = false; - ret = DkVirtualMemoryAlloc(&addr, LIBOS_THREAD_LIBOS_STACK_SIZE, 0, - LINUX_PROT_TO_PAL(prot, flags)); + ret = PalVirtualMemoryAlloc(&addr, LIBOS_THREAD_LIBOS_STACK_SIZE, 0, + LINUX_PROT_TO_PAL(prot, flags)); if (ret < 0) { ret = pal_to_unix_errno(ret); goto unmap; @@ -103,7 +103,7 @@ int alloc_thread_libos_stack(struct libos_thread* thread) { need_mem_free = true; /* Create a stack guard page. */ - ret = DkVirtualMemoryProtect(addr, PAGE_SIZE, /*prot=*/0); + ret = PalVirtualMemoryProtect(addr, PAGE_SIZE, /*prot=*/0); if (ret < 0) { ret = pal_to_unix_errno(ret); goto unmap; @@ -122,7 +122,7 @@ unmap:; BUG(); } if (need_mem_free) { - if (DkVirtualMemoryFree(addr, LIBOS_THREAD_LIBOS_STACK_SIZE) < 0) { + if (PalVirtualMemoryFree(addr, LIBOS_THREAD_LIBOS_STACK_SIZE) < 0) { BUG(); } } @@ -203,7 +203,8 @@ static int init_main_thread(void) { set_sig_mask(cur_thread, &set); unlock(&cur_thread->lock); - ret = DkEventCreate(&cur_thread->scheduler_event, /*init_signaled=*/false, /*auto_clear=*/true); + ret = PalEventCreate(&cur_thread->scheduler_event, /*init_signaled=*/false, + /*auto_clear=*/true); if (ret < 0) { put_thread(cur_thread); return pal_to_unix_errno(ret);; @@ -300,8 +301,8 @@ struct libos_thread* get_new_thread(void) { unlock(&cur_thread->lock); - int ret = DkEventCreate(&thread->scheduler_event, /*init_signaled=*/false, - /*auto_clear=*/true); + int ret = PalEventCreate(&thread->scheduler_event, /*init_signaled=*/false, + /*auto_clear=*/true); if (ret < 0) { put_thread(thread); return NULL; @@ -355,7 +356,7 @@ void put_thread(struct libos_thread* thread) { addr, (char*)addr + LIBOS_THREAD_LIBOS_STACK_SIZE); BUG(); } - if (DkVirtualMemoryFree(addr, LIBOS_THREAD_LIBOS_STACK_SIZE) < 0) { + if (PalVirtualMemoryFree(addr, LIBOS_THREAD_LIBOS_STACK_SIZE) < 0) { BUG(); } bkeep_remove_tmp_vma(tmp_vma); @@ -364,7 +365,7 @@ void put_thread(struct libos_thread* thread) { free(thread->groups_info.groups); if (thread->pal_handle && thread->pal_handle != g_pal_public_state->first_thread) - DkObjectClose(thread->pal_handle); + PalObjectClose(thread->pal_handle); if (thread->handle_map) { put_handle_map(thread->handle_map); @@ -383,7 +384,7 @@ void put_thread(struct libos_thread* thread) { } if (thread->scheduler_event) { - DkObjectClose(thread->scheduler_event); + PalObjectClose(thread->scheduler_event); } /* `wake_queue` is only meaningful when `thread` is part of some wake up queue (is just @@ -639,7 +640,7 @@ BEGIN_RS_FUNC(thread) { return ret; } - ret = DkEventCreate(&thread->scheduler_event, /*init_signaled=*/false, /*auto_clear=*/true); + ret = PalEventCreate(&thread->scheduler_event, /*init_signaled=*/false, /*auto_clear=*/true); if (ret < 0) { return pal_to_unix_errno(ret); } diff --git a/libos/src/bookkeep/shim_vma.c b/libos/src/bookkeep/shim_vma.c index d1d59a0bc5..2d8ab04f70 100644 --- a/libos/src/bookkeep/shim_vma.c +++ b/libos/src/bookkeep/shim_vma.c @@ -290,7 +290,7 @@ static void* _vma_malloc(size_t size) { return NULL; } - int ret = DkVirtualMemoryAlloc(&addr, size, 0, PAL_PROT_WRITE | PAL_PROT_READ); + int ret = PalVirtualMemoryAlloc(&addr, size, 0, PAL_PROT_WRITE | PAL_PROT_READ); if (ret < 0) { struct libos_vma* vmas_to_free = NULL; @@ -588,7 +588,7 @@ int init_vma(void) { if (gap_max_size / ALLOC_ALIGNMENT >= (1ul << ASLR_BITS)) { size_t gap = 0; - int ret = DkRandomBitsRead(&gap, sizeof(gap)); + int ret = PalRandomBitsRead(&gap, sizeof(gap)); if (ret < 0) { return pal_to_unix_errno(ret); } diff --git a/libos/src/fs/chroot/encrypted.c b/libos/src/fs/chroot/encrypted.c index 167b1e3b5d..d1d4bfe69b 100644 --- a/libos/src/fs/chroot/encrypted.c +++ b/libos/src/fs/chroot/encrypted.c @@ -99,7 +99,7 @@ static int chroot_encrypted_lookup(struct libos_dentry* dent) { /* * We don't know the file type yet, so we can't construct a PAL URI with the right prefix. - * However, "file:" prefix is good enough here: `DkStreamAttributesQuery` will access the file + * However, "file:" prefix is good enough here: `PalStreamAttributesQuery` will access the file * and report the right file type. * * See also the comment in `fs.c:chroot_lookup` (but note that this case is simpler, because we @@ -110,7 +110,7 @@ static int chroot_encrypted_lookup(struct libos_dentry* dent) { goto out; PAL_STREAM_ATTR pal_attr; - ret = DkStreamAttributesQuery(uri, &pal_attr); + ret = PalStreamAttributesQuery(uri, &pal_attr); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -251,13 +251,13 @@ static int chroot_encrypted_mkdir(struct libos_dentry* dent, mode_t perm) { /* This opens a "dir:..." URI */ PAL_HANDLE palhdl; - ret = DkStreamOpen(uri, PAL_ACCESS_RDONLY, HOST_PERM(perm), PAL_CREATE_ALWAYS, - PAL_OPTION_PASSTHROUGH, &palhdl); + ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, HOST_PERM(perm), PAL_CREATE_ALWAYS, + PAL_OPTION_PASSTHROUGH, &palhdl); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; } - DkObjectClose(palhdl); + PalObjectClose(palhdl); inode->type = S_IFDIR; inode->perm = perm; @@ -283,15 +283,15 @@ static int chroot_encrypted_unlink(struct libos_dentry* dent) { return ret; PAL_HANDLE palhdl; - ret = DkStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, - PAL_OPTION_PASSTHROUGH, &palhdl); + ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, + PAL_OPTION_PASSTHROUGH, &palhdl); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; } - ret = DkStreamDelete(palhdl, PAL_DELETE_ALL); - DkObjectClose(palhdl); + ret = PalStreamDelete(palhdl, PAL_DELETE_ALL); + PalObjectClose(palhdl); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -342,16 +342,16 @@ static int chroot_encrypted_chmod(struct libos_dentry* dent, mode_t perm) { goto out; PAL_HANDLE palhdl; - ret = DkStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, - PAL_OPTION_PASSTHROUGH, &palhdl); + ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, + PAL_OPTION_PASSTHROUGH, &palhdl); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; } mode_t host_perm = HOST_PERM(perm); PAL_STREAM_ATTR attr = {.share_flags = host_perm}; - ret = DkStreamAttributesSetByHandle(palhdl, &attr); - DkObjectClose(palhdl); + ret = PalStreamAttributesSetByHandle(palhdl, &attr); + PalObjectClose(palhdl); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; diff --git a/libos/src/fs/chroot/fs.c b/libos/src/fs/chroot/fs.c index cc573af828..3fbe57f477 100644 --- a/libos/src/fs/chroot/fs.c +++ b/libos/src/fs/chroot/fs.c @@ -134,7 +134,7 @@ static int chroot_lookup(struct libos_dentry* dent) { /* * We don't know the file type yet, so we can't construct a PAL URI with the right prefix. In - * most cases, a "file:" prefix is good enough: `DkStreamAttributesQuery` will access the file + * most cases, a "file:" prefix is good enough: `PalStreamAttributesQuery` will access the file * and report the right file type. * * The only exception is when this is the root dentry of a "dev:" mount, i.e. a directly mounted @@ -151,7 +151,7 @@ static int chroot_lookup(struct libos_dentry* dent) { goto out; PAL_STREAM_ATTR pal_attr; - ret = DkStreamAttributesQuery(uri, &pal_attr); + ret = PalStreamAttributesQuery(uri, &pal_attr); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -196,8 +196,8 @@ static int chroot_temp_open(struct libos_dentry* dent, mode_t type, PAL_HANDLE* if (ret < 0) return ret; - ret = DkStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, - /*options=*/0, out_palhdl); + ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, + /*options=*/0, out_palhdl); free(uri); return pal_to_unix_errno(ret); } @@ -219,7 +219,7 @@ static int chroot_do_open(struct libos_handle* hdl, struct libos_dentry* dent, m enum pal_create_mode create = LINUX_OPEN_FLAGS_TO_PAL_CREATE(flags); pal_stream_options_t options = LINUX_OPEN_FLAGS_TO_PAL_OPTIONS(flags); mode_t host_perm = HOST_PERM(perm); - ret = DkStreamOpen(uri, access, host_perm, create, options, &palhdl); + ret = PalStreamOpen(uri, access, host_perm, create, options, &palhdl); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -233,7 +233,7 @@ static int chroot_do_open(struct libos_handle* hdl, struct libos_dentry* dent, m hdl->pos = 0; hdl->pal_handle = palhdl; } else { - DkObjectClose(palhdl); + PalObjectClose(palhdl); } ret = 0; @@ -282,7 +282,7 @@ static int chroot_mkdir(struct libos_dentry* dent, mode_t perm) { static int chroot_flush(struct libos_handle* hdl) { assert(hdl->type == TYPE_CHROOT); - int ret = DkStreamFlush(hdl->pal_handle); + int ret = PalStreamFlush(hdl->pal_handle); return pal_to_unix_errno(ret); } @@ -290,7 +290,7 @@ static ssize_t chroot_read(struct libos_handle* hdl, void* buf, size_t count, fi assert(hdl->type == TYPE_CHROOT); size_t actual_count = count; - int ret = DkStreamRead(hdl->pal_handle, *pos, &actual_count, buf, /*source=*/NULL, /*size=*/0); + int ret = PalStreamRead(hdl->pal_handle, *pos, &actual_count, buf, /*source=*/NULL, /*size=*/0); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -306,7 +306,7 @@ static ssize_t chroot_write(struct libos_handle* hdl, const void* buf, size_t co assert(hdl->type == TYPE_CHROOT); size_t actual_count = count; - int ret = DkStreamWrite(hdl->pal_handle, *pos, &actual_count, (void*)buf, /*dest=*/NULL); + int ret = PalStreamWrite(hdl->pal_handle, *pos, &actual_count, (void*)buf, /*dest=*/NULL); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -333,7 +333,7 @@ static int chroot_mmap(struct libos_handle* hdl, void* addr, size_t size, int pr return -EINVAL; void* actual_addr = addr; - int ret = DkStreamMap(hdl->pal_handle, &actual_addr, pal_prot, offset, size); + int ret = PalStreamMap(hdl->pal_handle, &actual_addr, pal_prot, offset, size); if (ret < 0) return pal_to_unix_errno(ret); @@ -347,7 +347,7 @@ static int chroot_truncate(struct libos_handle* hdl, file_off_t size) { int ret; lock(&hdl->inode->lock); - ret = DkStreamSetLength(hdl->pal_handle, size); + ret = PalStreamSetLength(hdl->pal_handle, size); if (ret == 0) { hdl->inode->size = size; } else { @@ -375,7 +375,7 @@ int chroot_readdir(struct libos_dentry* dent, readdir_callback_t callback, void* while (true) { size_t read_size = buf_size; - ret = DkStreamRead(palhdl, /*offset=*/0, &read_size, buf, /*source=*/NULL, /*size=*/0); + ret = PalStreamRead(palhdl, /*offset=*/0, &read_size, buf, /*source=*/NULL, /*size=*/0); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -413,7 +413,7 @@ int chroot_readdir(struct libos_dentry* dent, readdir_callback_t callback, void* out: free(buf); - DkObjectClose(palhdl); + PalObjectClose(palhdl); return ret; } @@ -428,8 +428,8 @@ int chroot_unlink(struct libos_dentry* dent) { if (ret < 0) return ret; - ret = DkStreamDelete(palhdl, PAL_DELETE_ALL); - DkObjectClose(palhdl); + ret = PalStreamDelete(palhdl, PAL_DELETE_ALL); + PalObjectClose(palhdl); if (ret < 0) return pal_to_unix_errno(ret); @@ -452,8 +452,8 @@ static int chroot_rename(struct libos_dentry* old, struct libos_dentry* new) { if (ret < 0) goto out; - ret = DkStreamChangeName(palhdl, new_uri); - DkObjectClose(palhdl); + ret = PalStreamChangeName(palhdl, new_uri); + PalObjectClose(palhdl); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -480,8 +480,8 @@ static int chroot_chmod(struct libos_dentry* dent, mode_t perm) { mode_t host_perm = HOST_PERM(perm); PAL_STREAM_ATTR attr = {.share_flags = host_perm}; - ret = DkStreamAttributesSetByHandle(palhdl, &attr); - DkObjectClose(palhdl); + ret = PalStreamAttributesSetByHandle(palhdl, &attr); + PalObjectClose(palhdl); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; diff --git a/libos/src/fs/dev/attestation.c b/libos/src/fs/dev/attestation.c index cd9e02f6d1..a6cdfc9e2f 100644 --- a/libos/src/fs/dev/attestation.c +++ b/libos/src/fs/dev/attestation.c @@ -7,7 +7,7 @@ * This file contains the implementation of local- and remote-attestation logic implemented via * `/dev/attestation/{user_report_data, target_info, my_target_info, report, quote}` pseudo-files. * - * The attestation logic uses DkAttestationReport() and DkAttestationQuote() and is generic enough + * The attestation logic uses PalAttestationReport() and PalAttestationQuote() and is generic enough * to support attestation flows similar to Intel SGX. Currently only SGX attestation is used. * * This pseudo-FS interface is not thread-safe. It is the responsibility of the application to @@ -41,9 +41,9 @@ static int init_attestation_struct_sizes(void) { return 0; } - int ret = DkAttestationReport(/*user_report_data=*/NULL, &g_user_report_data_size, - /*target_info=*/NULL, &g_target_info_size, - /*report=*/NULL, &g_report_size); + int ret = PalAttestationReport(/*user_report_data=*/NULL, &g_user_report_data_size, + /*target_info=*/NULL, &g_target_info_size, + /*report=*/NULL, &g_report_size); if (ret < 0) return -EACCES; @@ -104,7 +104,7 @@ static int target_info_save(struct libos_dentry* dent, const char* data, size_t } /*! - * \brief Obtain this enclave's target info via DkAttestationReport(). + * \brief Obtain this enclave's target info via PalAttestationReport(). * * This file `/dev/attestation/my_target_info` can be opened for read and will contain the * target info of this enclave. The resulting target info blob can be passed to another enclave @@ -140,8 +140,8 @@ static int my_target_info_load(struct libos_dentry* dent, char** out_data, size_ /* below invocation returns this enclave's target info because we zeroed out (via calloc) * target_info: it's a hint to function to update target_info with this enclave's info */ - ret = DkAttestationReport(user_report_data, &user_report_data_size, target_info, - &target_info_size, /*report=*/NULL, &report_size); + ret = PalAttestationReport(user_report_data, &user_report_data_size, target_info, + &target_info_size, /*report=*/NULL, &report_size); if (ret < 0) { ret = -EACCES; goto out; @@ -167,7 +167,7 @@ static int my_target_info_load(struct libos_dentry* dent, char** out_data, size_ /*! - * \brief Obtain report via DkAttestationReport() with previously populated user_report_data + * \brief Obtain report via PalAttestationReport() with previously populated user_report_data * and target_info. * * Before opening `/dev/attestation/report` for read, user_report_data must be written into @@ -188,8 +188,8 @@ static int report_load(struct libos_dentry* dent, char** out_data, size_t* out_s if (!report) return -ENOMEM; - ret = DkAttestationReport(&g_user_report_data, &g_user_report_data_size, &g_target_info, - &g_target_info_size, report, &g_report_size); + ret = PalAttestationReport(&g_user_report_data, &g_user_report_data_size, &g_target_info, + &g_target_info_size, report, &g_report_size); if (ret < 0) { free(report); return -EACCES; @@ -227,7 +227,7 @@ static int quote_load(struct libos_dentry* dent, char** out_data, size_t* out_si if (!quote) return -ENOMEM; - ret = DkAttestationQuote(&g_user_report_data, g_user_report_data_size, quote, "e_size); + ret = PalAttestationQuote(&g_user_report_data, g_user_report_data_size, quote, "e_size); if (ret < 0) { free(quote); return -EACCES; diff --git a/libos/src/fs/dev/fs.c b/libos/src/fs/dev/fs.c index 034047fdaa..805e9fb7e7 100644 --- a/libos/src/fs/dev/fs.c +++ b/libos/src/fs/dev/fs.c @@ -48,7 +48,7 @@ static ssize_t dev_zero_read(struct libos_handle* hdl, void* buf, size_t count) static ssize_t dev_random_read(struct libos_handle* hdl, void* buf, size_t count) { __UNUSED(hdl); - int ret = DkRandomBitsRead(buf, count); + int ret = PalRandomBitsRead(buf, count); if (ret < 0) return pal_to_unix_errno(ret); diff --git a/libos/src/fs/eventfd/fs.c b/libos/src/fs/eventfd/fs.c index f0c4b4ad2c..c227e6cd1a 100644 --- a/libos/src/fs/eventfd/fs.c +++ b/libos/src/fs/eventfd/fs.c @@ -20,7 +20,7 @@ static ssize_t eventfd_read(struct libos_handle* hdl, void* buf, size_t count, f return -EINVAL; size_t orig_count = count; - int ret = DkStreamRead(hdl->pal_handle, 0, &count, buf, NULL, 0); + int ret = PalStreamRead(hdl->pal_handle, 0, &count, buf, NULL, 0); ret = pal_to_unix_errno(ret); maybe_epoll_et_trigger(hdl, ret, /*in=*/true, ret == 0 ? count < orig_count : false); if (ret < 0) { @@ -38,7 +38,7 @@ static ssize_t eventfd_write(struct libos_handle* hdl, const void* buf, size_t c return -EINVAL; size_t orig_count = count; - int ret = DkStreamWrite(hdl->pal_handle, 0, &count, (void*)buf, NULL); + int ret = PalStreamWrite(hdl->pal_handle, 0, &count, (void*)buf, NULL); ret = pal_to_unix_errno(ret); maybe_epoll_et_trigger(hdl, ret, /*in=*/false, ret == 0 ? count < orig_count : false); if (ret < 0) { diff --git a/libos/src/fs/pipe/fs.c b/libos/src/fs/pipe/fs.c index 782f1539ff..ca66a32074 100644 --- a/libos/src/fs/pipe/fs.c +++ b/libos/src/fs/pipe/fs.c @@ -92,7 +92,7 @@ static ssize_t pipe_read(struct libos_handle* hdl, void* buf, size_t count, file return -EACCES; size_t orig_count = count; - int ret = DkStreamRead(hdl->pal_handle, 0, &count, buf, NULL, 0); + int ret = PalStreamRead(hdl->pal_handle, 0, &count, buf, NULL, 0); ret = pal_to_unix_errno(ret); maybe_epoll_et_trigger(hdl, ret, /*in=*/true, ret == 0 ? count < orig_count : false); if (ret < 0) { @@ -111,7 +111,7 @@ static ssize_t pipe_write(struct libos_handle* hdl, const void* buf, size_t coun return -EACCES; size_t orig_count = count; - int ret = DkStreamWrite(hdl->pal_handle, 0, &count, (void*)buf, NULL); + int ret = PalStreamWrite(hdl->pal_handle, 0, &count, (void*)buf, NULL); ret = pal_to_unix_errno(ret); maybe_epoll_et_trigger(hdl, ret, /*in=*/false, ret == 0 ? count < orig_count : false); if (ret < 0) { @@ -174,7 +174,7 @@ static int pipe_setflags(struct libos_handle* handle, unsigned int flags, unsign lock(&handle->lock); PAL_STREAM_ATTR attr; - int ret = DkStreamAttributesQueryByHandle(handle->pal_handle, &attr); + int ret = PalStreamAttributesQueryByHandle(handle->pal_handle, &attr); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -183,7 +183,7 @@ static int pipe_setflags(struct libos_handle* handle, unsigned int flags, unsign bool nonblocking = flags & O_NONBLOCK; if (attr.nonblocking != nonblocking) { attr.nonblocking = nonblocking; - ret = DkStreamAttributesSetByHandle(handle->pal_handle, &attr); + ret = PalStreamAttributesSetByHandle(handle->pal_handle, &attr); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; diff --git a/libos/src/fs/proc/info.c b/libos/src/fs/proc/info.c index 16ff8a07d1..d727970e18 100644 --- a/libos/src/fs/proc/info.c +++ b/libos/src/fs/proc/info.c @@ -16,7 +16,7 @@ int proc_meminfo_load(struct libos_dentry* dent, char** out_data, size_t* out_si size_t size, max = 128; char* str = NULL; - assert(g_pal_public_state->mem_total >= DkMemoryAvailableQuota()); + assert(g_pal_public_state->mem_total >= PalMemoryAvailableQuota()); /* * Enumerate minimal set of meminfo stats; as reference workloads that use these stats, we use: @@ -33,8 +33,8 @@ int proc_meminfo_load(struct libos_dentry* dent, char** out_data, size_t* out_si unsigned long val; } meminfo[] = { { "MemTotal: %8lu kB\n", g_pal_public_state->mem_total / 1024 }, - { "MemFree: %8lu kB\n", DkMemoryAvailableQuota() / 1024 }, - { "MemAvailable: %8lu kB\n", DkMemoryAvailableQuota() / 1024 }, + { "MemFree: %8lu kB\n", PalMemoryAvailableQuota() / 1024 }, + { "MemAvailable: %8lu kB\n", PalMemoryAvailableQuota() / 1024 }, { "Buffers: %8lu kB\n", /*dummy value=*/0 }, { "Cached: %8lu kB\n", /*dummy value=*/0 }, { "SwapCached: %8lu kB\n", /*dummy value=*/0 }, @@ -47,7 +47,7 @@ int proc_meminfo_load(struct libos_dentry* dent, char** out_data, size_t* out_si { "Mapped: %8lu kB\n", /*dummy value=*/0 }, { "Shmem: %8lu kB\n", /*dummy value=*/0 }, { "Slab: %8lu kB\n", /*dummy value=*/0 }, - { "Committed_AS: %8lu kB\n", (g_pal_public_state->mem_total - DkMemoryAvailableQuota()) + { "Committed_AS: %8lu kB\n", (g_pal_public_state->mem_total - PalMemoryAvailableQuota()) / 1024 }, { "VmallocTotal: %8lu kB\n", g_pal_public_state->mem_total / 1024 }, { "VmallocUsed: %8lu kB\n", /*dummy value=*/0 }, diff --git a/libos/src/fs/shim_fs_encrypted.c b/libos/src/fs/shim_fs_encrypted.c index 3eaab73050..7aab6ec071 100644 --- a/libos/src/fs/shim_fs_encrypted.c +++ b/libos/src/fs/shim_fs_encrypted.c @@ -27,13 +27,13 @@ static pf_status_t cb_read(pf_handle_t handle, void* buffer, uint64_t offset, si while (remaining > 0) { size_t count = remaining; - int ret = DkStreamRead(pal_handle, offset + buffer_offset, &count, buffer + buffer_offset, - /*source=*/NULL, /*size=*/0); + int ret = PalStreamRead(pal_handle, offset + buffer_offset, &count, buffer + buffer_offset, + /*source=*/NULL, /*size=*/0); if (ret == -PAL_ERROR_INTERRUPTED) continue; if (ret < 0) { - log_warning("%s: DkStreamRead failed: %d", __func__, ret); + log_warning("%s: PalStreamRead failed: %d", __func__, ret); return PF_STATUS_CALLBACK_FAILED; } @@ -57,13 +57,13 @@ static pf_status_t cb_write(pf_handle_t handle, const void* buffer, uint64_t off while (remaining > 0) { size_t count = remaining; - int ret = DkStreamWrite(pal_handle, offset + buffer_offset, &count, - (void*)(buffer + buffer_offset), /*dest=*/NULL); + int ret = PalStreamWrite(pal_handle, offset + buffer_offset, &count, + (void*)(buffer + buffer_offset), /*dest=*/NULL); if (ret == -PAL_ERROR_INTERRUPTED) continue; if (ret < 0) { - log_warning("%s: DkStreamWrite failed: %d", __func__, ret); + log_warning("%s: PalStreamWrite failed: %d", __func__, ret); return PF_STATUS_CALLBACK_FAILED; } @@ -82,9 +82,9 @@ static pf_status_t cb_write(pf_handle_t handle, const void* buffer, uint64_t off static pf_status_t cb_truncate(pf_handle_t handle, uint64_t size) { PAL_HANDLE pal_handle = (PAL_HANDLE)handle; - int ret = DkStreamSetLength(pal_handle, size); + int ret = PalStreamSetLength(pal_handle, size); if (ret < 0) { - log_warning("%s: DkStreamSetLength failed: %d", __func__, ret); + log_warning("%s: PalStreamSetLength failed: %d", __func__, ret); return PF_STATUS_CALLBACK_FAILED; } @@ -128,9 +128,9 @@ static pf_status_t cb_aes_gcm_decrypt(const pf_key_t* key, const pf_iv_t* iv, co } static pf_status_t cb_random(uint8_t* buffer, size_t size) { - int ret = DkRandomBitsRead(buffer, size); + int ret = PalRandomBitsRead(buffer, size); if (ret < 0) { - log_warning("%s: DkRandomBitsRead failed: %d", __func__, ret); + log_warning("%s: PalRandomBitsRead failed: %d", __func__, ret); return PF_STATUS_CALLBACK_FAILED; } return PF_STATUS_SUCCESS; @@ -157,19 +157,19 @@ static int encrypted_file_internal_open(struct libos_encrypted_file* enc, PAL_HA if (!pal_handle) { enum pal_create_mode create_mode = create ? PAL_CREATE_ALWAYS : PAL_CREATE_NEVER; - ret = DkStreamOpen(enc->uri, PAL_ACCESS_RDWR, share_flags, create_mode, - PAL_OPTION_PASSTHROUGH, &pal_handle); + ret = PalStreamOpen(enc->uri, PAL_ACCESS_RDWR, share_flags, create_mode, + PAL_OPTION_PASSTHROUGH, &pal_handle); if (ret < 0) { - log_warning("%s: DkStreamOpen failed: %d", __func__, ret); + log_warning("%s: PalStreamOpen failed: %d", __func__, ret); return pal_to_unix_errno(ret); } } PAL_STREAM_ATTR pal_attr; - ret = DkStreamAttributesQueryByHandle(pal_handle, &pal_attr); + ret = PalStreamAttributesQueryByHandle(pal_handle, &pal_attr); if (ret < 0) { - log_warning("%s: DkStreamAttributesQueryByHandle failed: %d", __func__, ret); - DkObjectClose(pal_handle); + log_warning("%s: PalStreamAttributesQueryByHandle failed: %d", __func__, ret); + PalObjectClose(pal_handle); return pal_to_unix_errno(ret); } size_t size = pal_attr.pending_size; @@ -179,7 +179,7 @@ static int encrypted_file_internal_open(struct libos_encrypted_file* enc, PAL_HA if (!enc->key->is_set) { log_warning("%s: key '%s' is not set", __func__, enc->key->name); unlock(&g_keys_lock); - DkObjectClose(pal_handle); + PalObjectClose(pal_handle); return -EACCES; } pf_status_t pfs = pf_open(pal_handle, path, size, PF_FILE_MODE_READ | PF_FILE_MODE_WRITE, @@ -187,7 +187,7 @@ static int encrypted_file_internal_open(struct libos_encrypted_file* enc, PAL_HA unlock(&g_keys_lock); if (PF_FAILURE(pfs)) { log_warning("%s: pf_open failed: %s", __func__, pf_strerror(pfs)); - DkObjectClose(pal_handle); + PalObjectClose(pal_handle); return -EACCES; } @@ -231,7 +231,7 @@ static void encrypted_file_internal_close(struct libos_encrypted_file* enc) { } enc->pf = NULL; - DkObjectClose(enc->pal_handle); + PalObjectClose(enc->pal_handle); enc->pal_handle = NULL; return; } @@ -401,11 +401,11 @@ int get_or_create_encrypted_files_key(const char* name, if (created && name[0] == '_') { pf_key_t pf_key; size_t size = sizeof(pf_key); - ret = DkGetSpecialKey(name, &pf_key, &size); + ret = PalGetSpecialKey(name, &pf_key, &size); if (ret == 0) { if (size != sizeof(pf_key)) { - log_debug("DkGetSpecialKey(\"%s\") returned wrong size: %zu", name, size); + log_debug("PalGetSpecialKey(\"%s\") returned wrong size: %zu", name, size); ret = -EINVAL; goto out; } @@ -417,7 +417,7 @@ int get_or_create_encrypted_files_key(const char* name, "will not work.", name); /* proceed without setting value */ } else { - log_debug("DkGetSpecialKey(\"%s\") failed: %d", name, ret); + log_debug("PalGetSpecialKey(\"%s\") failed: %d", name, ret); ret = pal_to_unix_errno(ret); goto out; } @@ -642,9 +642,9 @@ int encrypted_file_rename(struct libos_encrypted_file* enc, const char* new_uri) goto out; } - ret = DkStreamChangeName(enc->pal_handle, new_uri); + ret = PalStreamChangeName(enc->pal_handle, new_uri); if (ret < 0) { - log_warning("%s: DkStreamChangeName failed: %d", __func__, ret); + log_warning("%s: PalStreamChangeName failed: %d", __func__, ret); /* We failed to rename the file. Try to restore the name in header. */ pfs = pf_rename(enc->pf, old_path); diff --git a/libos/src/fs/shim_fs_lock.c b/libos/src/fs/shim_fs_lock.c index b3cc708b81..9ccc807ade 100644 --- a/libos/src/fs/shim_fs_lock.c +++ b/libos/src/fs/shim_fs_lock.c @@ -374,7 +374,7 @@ static void posix_lock_process_requests(struct fs_lock* fs_lock) { assert(req->notify.event); assert(req->notify.result); *req->notify.result = result; - DkEventSet(req->notify.event); + PalEventSet(req->notify.event); } else { assert(!req->notify.event); assert(!req->notify.result); @@ -474,7 +474,7 @@ int posix_lock_set(struct libos_dentry* dent, struct posix_lock* pl, bool wait) assert(wait); int result; - ret = DkEventCreate(&event, /*init_signaled=*/false, /*auto_clear=*/false); + ret = PalEventCreate(&event, /*init_signaled=*/false, /*auto_clear=*/false); if (ret < 0) goto out; req->notify.vmid = 0; @@ -495,7 +495,7 @@ int posix_lock_set(struct libos_dentry* dent, struct posix_lock* pl, bool wait) out: unlock(&g_fs_lock_lock); if (event) - DkObjectClose(event); + PalObjectClose(event); return ret; } diff --git a/libos/src/fs/shim_fs_util.c b/libos/src/fs/shim_fs_util.c index 9bf7791334..04485cba57 100644 --- a/libos/src/fs/shim_fs_util.c +++ b/libos/src/fs/shim_fs_util.c @@ -147,7 +147,7 @@ int generic_emulated_mmap(struct libos_handle* hdl, void* addr, size_t size, int pal_prot_flags_t pal_prot_writable = pal_prot | PAL_PROT_WRITE; void* actual_addr = addr; - ret = DkVirtualMemoryAlloc(&actual_addr, size, /*alloc_type=*/0, pal_prot_writable); + ret = PalVirtualMemoryAlloc(&actual_addr, size, /*alloc_type=*/0, pal_prot_writable); if (ret < 0) return pal_to_unix_errno(ret); @@ -174,7 +174,7 @@ int generic_emulated_mmap(struct libos_handle* hdl, void* addr, size_t size, int } if (pal_prot != pal_prot_writable) { - ret = DkVirtualMemoryProtect(addr, size, pal_prot); + ret = PalVirtualMemoryProtect(addr, size, pal_prot); if (ret < 0) { ret = pal_to_unix_errno(ret); goto err; @@ -184,9 +184,9 @@ int generic_emulated_mmap(struct libos_handle* hdl, void* addr, size_t size, int return 0; err:; - int free_ret = DkVirtualMemoryFree(addr, size); + int free_ret = PalVirtualMemoryFree(addr, size); if (free_ret < 0) { - log_debug("%s: DkVirtualMemoryFree failed on cleanup: %d", __func__, free_ret); + log_debug("%s: PalVirtualMemoryFree failed on cleanup: %d", __func__, free_ret); BUG(); } return ret; @@ -205,7 +205,7 @@ int generic_emulated_msync(struct libos_handle* hdl, void* addr, size_t size, in int ret; if (pal_prot != pal_prot_readable) { - ret = DkVirtualMemoryProtect(addr, size, pal_prot_readable); + ret = PalVirtualMemoryProtect(addr, size, pal_prot_readable); if (ret < 0) return pal_to_unix_errno(ret); } @@ -237,9 +237,9 @@ int generic_emulated_msync(struct libos_handle* hdl, void* addr, size_t size, in out: if (pal_prot != pal_prot_readable) { - int protect_ret = DkVirtualMemoryProtect(addr, size, pal_prot); + int protect_ret = PalVirtualMemoryProtect(addr, size, pal_prot); if (protect_ret < 0) { - log_debug("%s: DkVirtualMemoryProtect failed on cleanup: %d", __func__, protect_ret); + log_debug("%s: PalVirtualMemoryProtect failed on cleanup: %d", __func__, protect_ret); BUG(); } } diff --git a/libos/src/fs/socket/fs.c b/libos/src/fs/socket/fs.c index f399ed3107..112d279dd7 100644 --- a/libos/src/fs/socket/fs.c +++ b/libos/src/fs/socket/fs.c @@ -23,7 +23,7 @@ static int close(struct libos_handle* handle) { free(handle->info.sock.peek.buf); /* No need for atomics - we are releasing the last reference, nothing can access it anymore. */ if (handle->info.sock.pal_handle) { - DkObjectClose(handle->info.sock.pal_handle); + PalObjectClose(handle->info.sock.pal_handle); } return 0; } @@ -100,7 +100,7 @@ static int setflags(struct libos_handle* handle, unsigned int flags, unsigned in } PAL_STREAM_ATTR attr; - ret = DkStreamAttributesQueryByHandle(pal_handle, &attr); + ret = PalStreamAttributesQueryByHandle(pal_handle, &attr); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -108,7 +108,7 @@ static int setflags(struct libos_handle* handle, unsigned int flags, unsigned in if (attr.nonblocking != nonblocking) { attr.nonblocking = nonblocking; - ret = DkStreamAttributesSetByHandle(pal_handle, &attr); + ret = PalStreamAttributesSetByHandle(pal_handle, &attr); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; diff --git a/libos/src/fs/tmpfs/fs.c b/libos/src/fs/tmpfs/fs.c index a54cadd6bd..f2e2728cf6 100644 --- a/libos/src/fs/tmpfs/fs.c +++ b/libos/src/fs/tmpfs/fs.c @@ -42,7 +42,7 @@ static int tmpfs_setup_dentry(struct libos_dentry* dent, mode_t type, mode_t per inode->data = mem; uint64_t time_us; - if (DkSystemTimeQuery(&time_us) < 0) { + if (PalSystemTimeQuery(&time_us) < 0) { put_inode(inode); return -EPERM; } @@ -193,7 +193,7 @@ static int tmpfs_rename(struct libos_dentry* old, struct libos_dentry* new) { __UNUSED(new); uint64_t time_us; - if (DkSystemTimeQuery(&time_us) < 0) + if (PalSystemTimeQuery(&time_us) < 0) return -EPERM; /* TODO: this should be done in the syscall handler, not here */ @@ -245,7 +245,7 @@ static ssize_t tmpfs_write(struct libos_handle* hdl, const void* buf, size_t siz assert(hdl->type == TYPE_TMPFS); uint64_t time_us; - if (DkSystemTimeQuery(&time_us) < 0) + if (PalSystemTimeQuery(&time_us) < 0) return -EPERM; struct libos_inode* inode = hdl->inode; @@ -272,7 +272,7 @@ static int tmpfs_truncate(struct libos_handle* hdl, file_off_t size) { int ret; uint64_t time_us; - if (DkSystemTimeQuery(&time_us) < 0) + if (PalSystemTimeQuery(&time_us) < 0) return -EPERM; lock(&hdl->inode->lock); diff --git a/libos/src/ipc/shim_ipc.c b/libos/src/ipc/shim_ipc.c index 3e56635ae0..8203cb5914 100644 --- a/libos/src/ipc/shim_ipc.c +++ b/libos/src/ipc/shim_ipc.c @@ -81,7 +81,7 @@ static void put_ipc_connection(struct libos_ipc_connection* conn) { int64_t ref_count = REF_DEC(conn->ref_count); if (!ref_count) { - DkObjectClose(conn->handle); + PalObjectClose(conn->handle); destroy_lock(&conn->lock); free(conn); } @@ -117,8 +117,8 @@ static int ipc_connect(IDTYPE dest, struct libos_ipc_connection** conn_ptr) { BUG(); } do { - ret = DkStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_IGNORED, - /*options=*/0, &conn->handle); + ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_IGNORED, + /*options=*/0, &conn->handle); } while (ret == -PAL_ERROR_INTERRUPTED); if (ret < 0) { ret = pal_to_unix_errno(ret); @@ -146,7 +146,7 @@ static int ipc_connect(IDTYPE dest, struct libos_ipc_connection** conn_ptr) { destroy_lock(&conn->lock); } if (conn->handle) { - DkObjectClose(conn->handle); + PalObjectClose(conn->handle); } free(conn); } @@ -188,7 +188,7 @@ void remove_outgoing_ipc_connection(IDTYPE dest) { struct ipc_msg_waiter* waiter = container_of(node, struct ipc_msg_waiter, node); if (waiter->dest == dest) { waiter->response_data = NULL; - DkEventSet(waiter->event); + PalEventSet(waiter->event); log_debug("Woke up a thread waiting for a message from a disconnected process"); } node = avl_tree_next(node); @@ -247,7 +247,7 @@ static int wait_for_response(struct ipc_msg_waiter* waiter) { int ret = 0; do { - ret = pal_to_unix_errno(DkEventWait(waiter->event, /*timeout=*/NULL)); + ret = pal_to_unix_errno(PalEventWait(waiter->event, /*timeout=*/NULL)); } while (ret == -EINTR); log_debug("Waiting finished: %d", ret); @@ -264,7 +264,7 @@ int ipc_send_msg_and_get_response(IDTYPE dest, struct libos_ipc_msg* msg, void** .dest = dest, .response_data = NULL, }; - int ret = DkEventCreate(&waiter.event, /*init_signaled=*/false, /*auto_clear=*/false); + int ret = PalEventCreate(&waiter.event, /*init_signaled=*/false, /*auto_clear=*/false); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -300,7 +300,7 @@ int ipc_send_msg_and_get_response(IDTYPE dest, struct libos_ipc_msg* msg, void** avl_tree_delete(&g_msg_waiters_tree, &waiter.node); unlock(&g_msg_waiters_tree_lock); free(waiter.response_data); - DkObjectClose(waiter.event); + PalObjectClose(waiter.event); return ret; } @@ -325,7 +325,7 @@ int ipc_response_callback(IDTYPE src, void* data, uint64_t seq) { struct ipc_msg_waiter* waiter = container_of(node, struct ipc_msg_waiter, node); waiter->response_data = data; - DkEventSet(waiter->event); + PalEventSet(waiter->event); ret = 0; log_debug("Got an IPC response from %u, seq: %lu", src, seq); diff --git a/libos/src/ipc/shim_ipc_worker.c b/libos/src/ipc/shim_ipc_worker.c index 09ca58e668..761acea3aa 100644 --- a/libos/src/ipc/shim_ipc_worker.c +++ b/libos/src/ipc/shim_ipc_worker.c @@ -36,7 +36,7 @@ static LISTP_TYPE(libos_ipc_connection) g_ipc_connections; static size_t g_ipc_connections_cnt = 0; static struct libos_thread* g_worker_thread = NULL; -/* Used by `DkThreadExit` to indicate that the thread really exited and is not using any resources +/* Used by `PalThreadExit` to indicate that the thread really exited and is not using any resources * (e.g. stack) anymore. Awaited to be `0` (thread exited) in `terminate_ipc_worker()`. */ static int g_clear_on_worker_exit = 1; static PAL_HANDLE g_self_ipc_handle = NULL; @@ -110,7 +110,7 @@ static void del_ipc_connection(struct libos_ipc_connection* conn) { LISTP_DEL(conn, &g_ipc_connections, list); g_ipc_connections_cnt--; - DkObjectClose(conn->handle); + PalObjectClose(conn->handle); free(conn); } @@ -136,7 +136,7 @@ static int receive_ipc_messages(struct libos_ipc_connection* conn) { /* Receive at least the message header. */ while (size < sizeof(buf.msg_header)) { size_t tmp_size = sizeof(buf) - size; - int ret = DkStreamRead(conn->handle, /*offset=*/0, &tmp_size, buf.buf + size, NULL, 0); + int ret = PalStreamRead(conn->handle, /*offset=*/0, &tmp_size, buf.buf + size, NULL, 0); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN) { continue; @@ -198,7 +198,7 @@ static int receive_ipc_messages(struct libos_ipc_connection* conn) { ret = ipc_callbacks[msg_code](conn->vmid, msg_data, msg_seq); if (ret < 0) { log_error(LOG_PREFIX "error running IPC callback %u: %d", msg_code, ret); - DkProcessExit(1); + PalProcessExit(1); } } else { log_error(LOG_PREFIX "received unknown IPC msg type: %u", msg_code); @@ -263,7 +263,7 @@ static noreturn void ipc_worker_main(void) { i++; } - int ret = DkStreamsWaitEvents(items_cnt, handles, events, ret_events, /*timeout_us=*/NULL); + int ret = PalStreamsWaitEvents(items_cnt, handles, events, ret_events, /*timeout_us=*/NULL); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED) { /* Generally speaking IPC worker should not be interrupted, but this happens with @@ -271,7 +271,7 @@ static noreturn void ipc_worker_main(void) { continue; } ret = pal_to_unix_errno(ret); - log_error(LOG_PREFIX "DkStreamsWaitEvents failed: %d", ret); + log_error(LOG_PREFIX "PalStreamsWaitEvents failed: %d", ret); goto out_die; } @@ -294,7 +294,7 @@ static noreturn void ipc_worker_main(void) { cur_thread->libos_tcb->tp = NULL; put_thread(cur_thread); - DkThreadExit(&g_clear_on_worker_exit); + PalThreadExit(&g_clear_on_worker_exit); /* Unreachable. */ } @@ -308,18 +308,18 @@ static noreturn void ipc_worker_main(void) { do { /* Although IPC worker thread does not handle any signals (hence it should never be * interrupted), lets handle it for uniformity with the rest of the code. */ - ret = DkStreamWaitForClient(g_self_ipc_handle, &new_handle, /*options=*/0); + ret = PalStreamWaitForClient(g_self_ipc_handle, &new_handle, /*options=*/0); } while (ret == -PAL_ERROR_INTERRUPTED); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error(LOG_PREFIX "DkStreamWaitForClient failed: %d", ret); + log_error(LOG_PREFIX "PalStreamWaitForClient failed: %d", ret); goto out_die; } IDTYPE new_id = 0; ret = read_exact(new_handle, &new_id, sizeof(new_id)); if (ret < 0) { log_error(LOG_PREFIX "receiving id failed: %d", ret); - DkObjectClose(new_handle); + PalObjectClose(new_handle); } else { ret = add_ipc_connection(new_handle, new_id); if (ret < 0) { @@ -356,7 +356,7 @@ static noreturn void ipc_worker_main(void) { } out_die: - DkProcessExit(1); + PalProcessExit(1); } static int ipc_worker_wrapper(void* arg) { @@ -391,7 +391,7 @@ static int create_ipc_worker(void) { } PAL_HANDLE handle = NULL; - ret = DkThreadCreate(ipc_worker_wrapper, NULL, &handle); + ret = PalThreadCreate(ipc_worker_wrapper, NULL, &handle); if (ret < 0) { put_thread(g_worker_thread); g_worker_thread = NULL; @@ -416,6 +416,6 @@ void terminate_ipc_worker(void) { put_thread(g_worker_thread); g_worker_thread = NULL; - DkObjectClose(g_self_ipc_handle); + PalObjectClose(g_self_ipc_handle); g_self_ipc_handle = NULL; } diff --git a/libos/src/net/ip.c b/libos/src/net/ip.c index 68f2439ddc..d53b596104 100644 --- a/libos/src/net/ip.c +++ b/libos/src/net/ip.c @@ -96,7 +96,7 @@ static int create(struct libos_handle* handle) { /* We don't need to take the lock - handle was just created. */ pal_stream_options_t options = handle->flags & O_NONBLOCK ? PAL_OPTION_NONBLOCK : 0; PAL_HANDLE pal_handle = NULL; - int ret = DkSocketCreate(pal_domain, pal_type, options, &pal_handle); + int ret = PalSocketCreate(pal_domain, pal_type, options, &pal_handle); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -116,7 +116,7 @@ static int bind(struct libos_handle* handle, void* addr, size_t addrlen) { struct pal_socket_addr pal_ip_addr; linux_to_pal_sockaddr(addr, &pal_ip_addr); - ret = DkSocketBind(sock->pal_handle, &pal_ip_addr); + ret = PalSocketBind(sock->pal_handle, &pal_ip_addr); if (ret < 0) { return (ret == -PAL_ERROR_STREAMEXIST) ? -EADDRINUSE : pal_to_unix_errno(ret); } @@ -133,22 +133,22 @@ static int listen(struct libos_handle* handle, unsigned int backlog) { return -EOPNOTSUPP; } - return pal_to_unix_errno(DkSocketListen(sock->pal_handle, backlog)); + return pal_to_unix_errno(PalSocketListen(sock->pal_handle, backlog)); } static int accept(struct libos_handle* handle, bool is_nonblocking, struct libos_handle** out_client) { PAL_HANDLE client_pal_handle; struct pal_socket_addr pal_ip_addr = { 0 }; - int ret = DkSocketAccept(handle->info.sock.pal_handle, is_nonblocking ? PAL_OPTION_NONBLOCK : 0, - &client_pal_handle, &pal_ip_addr); + int ret = PalSocketAccept(handle->info.sock.pal_handle, is_nonblocking ? PAL_OPTION_NONBLOCK : 0, + &client_pal_handle, &pal_ip_addr); if (ret < 0) { return pal_to_unix_errno(ret); } struct libos_handle* client_handle = get_new_handle(); if (!client_handle) { - DkObjectClose(client_pal_handle); + PalObjectClose(client_pal_handle); return -ENOMEM; } @@ -202,7 +202,7 @@ static int connect(struct libos_handle* handle, void* addr, size_t addrlen) { /* XXX: this connect is always blocking (regardless of actual setting of nonblockingness on * `sock->pal_handle`. See also the comment in tcp connect implementation in Linux PAL. */ - ret = DkSocketConnect(sock->pal_handle, &pal_remote_addr, &pal_local_addr); + ret = PalSocketConnect(sock->pal_handle, &pal_remote_addr, &pal_local_addr); if (ret < 0) { return ret == -PAL_ERROR_CONNFAILED ? -ECONNREFUSED : pal_to_unix_errno(ret); } @@ -224,13 +224,13 @@ static int disconnect(struct libos_handle* handle) { struct pal_socket_addr pal_ip_addr = { .domain = PAL_DISCONNECT, }; - int ret = DkSocketConnect(sock->pal_handle, &pal_ip_addr, /*local_addr=*/NULL); + int ret = PalSocketConnect(sock->pal_handle, &pal_ip_addr, /*local_addr=*/NULL); return pal_to_unix_errno(ret); } static int set_tcp_option(struct libos_handle* handle, int optname, void* optval, size_t len) { PAL_STREAM_ATTR attr; - int ret = DkStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); + int ret = PalStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -252,7 +252,7 @@ static int set_tcp_option(struct libos_handle* handle, int optname, void* optval return -ENOPROTOOPT; } - ret = DkStreamAttributesSetByHandle(handle->info.sock.pal_handle, &attr); + ret = PalStreamAttributesSetByHandle(handle->info.sock.pal_handle, &attr); return pal_to_unix_errno(ret); } @@ -277,7 +277,7 @@ static int set_ipv4_option(struct libos_handle* handle, int optname, void* optva static int set_ipv6_option(struct libos_handle* handle, int optname, void* optval, size_t len) { PAL_STREAM_ATTR attr; - int ret = DkStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); + int ret = PalStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -302,13 +302,13 @@ static int set_ipv6_option(struct libos_handle* handle, int optname, void* optva return -ENOPROTOOPT; } - ret = DkStreamAttributesSetByHandle(handle->info.sock.pal_handle, &attr); + ret = PalStreamAttributesSetByHandle(handle->info.sock.pal_handle, &attr); return pal_to_unix_errno(ret); } static int set_socket_option(struct libos_handle* handle, int optname, void* optval, size_t len) { PAL_STREAM_ATTR attr; - int ret = DkStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); + int ret = PalStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -329,7 +329,7 @@ static int set_socket_option(struct libos_handle* handle, int optname, void* opt return -ENOPROTOOPT; } - ret = DkStreamAttributesSetByHandle(handle->info.sock.pal_handle, &attr); + ret = PalStreamAttributesSetByHandle(handle->info.sock.pal_handle, &attr); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -367,7 +367,7 @@ static int setsockopt(struct libos_handle* handle, int level, int optname, void* static int get_tcp_option(struct libos_handle* handle, int optname, void* optval, size_t* len) { PAL_STREAM_ATTR attr; - int ret = DkStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); + int ret = PalStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -395,7 +395,7 @@ static int get_tcp_option(struct libos_handle* handle, int optname, void* optval static int get_ipv6_option(struct libos_handle* handle, int optname, void* optval, size_t* len) { PAL_STREAM_ATTR attr; - int ret = DkStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); + int ret = PalStreamAttributesQueryByHandle(handle->info.sock.pal_handle, &attr); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -495,8 +495,8 @@ static int send(struct libos_handle* handle, struct iovec* iov, size_t iov_len, pal_iov[i].iov_len = iov[i].iov_len; } - int ret = DkSocketSend(sock->pal_handle, pal_iov, iov_len, out_size, - addr ? &pal_ip_addr : NULL); + int ret = PalSocketSend(sock->pal_handle, pal_iov, iov_len, out_size, + addr ? &pal_ip_addr : NULL); ret = (ret == -PAL_ERROR_TOOLONG) ? -EMSGSIZE : pal_to_unix_errno(ret); free(pal_iov); return ret; @@ -528,8 +528,8 @@ static int recv(struct libos_handle* handle, struct iovec* iov, size_t iov_len, } struct pal_socket_addr pal_ip_addr; - int ret = DkSocketRecv(handle->info.sock.pal_handle, pal_iov, iov_len, out_total_size, - addr ? &pal_ip_addr : NULL, force_nonblocking); + int ret = PalSocketRecv(handle->info.sock.pal_handle, pal_iov, iov_len, out_total_size, + addr ? &pal_ip_addr : NULL, force_nonblocking); free(pal_iov); if (ret < 0) { return pal_to_unix_errno(ret); diff --git a/libos/src/net/unix.c b/libos/src/net/unix.c index 9dfee3e7f8..523d1431d7 100644 --- a/libos/src/net/unix.c +++ b/libos/src/net/unix.c @@ -138,8 +138,8 @@ static int bind(struct libos_handle* handle, void* addr, size_t addrlen) { unlock(&handle->lock); PAL_HANDLE pal_handle = NULL; - ret = DkStreamOpen(pipe_name, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, options, - &pal_handle); + ret = PalStreamOpen(pipe_name, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, options, + &pal_handle); if (ret < 0) { return (ret == -PAL_ERROR_STREAMEXIST) ? -EADDRINUSE : pal_to_unix_errno(ret); } @@ -178,14 +178,14 @@ static int accept(struct libos_handle* handle, bool is_nonblocking, /* Since this socket is listening, it must have a PAL handle. */ assert(pal_handle); PAL_HANDLE client_pal_handle; - int ret = DkStreamWaitForClient(pal_handle, &client_pal_handle, options); + int ret = PalStreamWaitForClient(pal_handle, &client_pal_handle, options); if (ret < 0) { return pal_to_unix_errno(ret); } struct libos_handle* client_handle = get_new_handle(); if (!client_handle) { - DkObjectClose(client_pal_handle); + PalObjectClose(client_pal_handle); return -ENOMEM; } @@ -247,8 +247,8 @@ static int connect(struct libos_handle* handle, void* addr, size_t addrlen) { unlock(&handle->lock); PAL_HANDLE pal_handle = NULL; - ret = DkStreamOpen(pipe_name, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, options, - &pal_handle); + ret = PalStreamOpen(pipe_name, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, options, + &pal_handle); if (ret < 0) { return (ret == -PAL_ERROR_CONNFAILED) ? -ENOENT : pal_to_unix_errno(ret); } @@ -361,7 +361,7 @@ static int send(struct libos_handle* handle, struct iovec* iov, size_t iov_len, /* `size` is already correct. */ } - int ret = DkStreamWrite(pal_handle, /*offset=*/0, &size, buf, NULL); + int ret = PalStreamWrite(pal_handle, /*offset=*/0, &size, buf, NULL); free(backing_buf); if (ret < 0) { return (ret == -PAL_ERROR_TOOLONG) ? -EMSGSIZE : pal_to_unix_errno(ret); @@ -390,7 +390,7 @@ static int recv(struct libos_handle* handle, struct iovec* iov, size_t iov_len, bool handle_is_nonblocking = handle->flags & O_NONBLOCK; unlock(&handle->lock); if (!handle_is_nonblocking) { - /* `DkStreamRead` has no way of making one-time nonblocking read, so we have no other + /* `PalStreamRead` has no way of making one-time nonblocking read, so we have no other * option but to fail. */ return -EINVAL; } @@ -416,7 +416,7 @@ static int recv(struct libos_handle* handle, struct iovec* iov, size_t iov_len, /* `size` is already correct. */ } - int ret = DkStreamRead(pal_handle, /*offset=*/0, &size, buf, NULL, 0); + int ret = PalStreamRead(pal_handle, /*offset=*/0, &size, buf, NULL, 0); if (ret < 0) { ret = pal_to_unix_errno(ret); } else { diff --git a/libos/src/shim_async.c b/libos/src/shim_async.c index 7f02c15f3b..23416aa5eb 100644 --- a/libos/src/shim_async.c +++ b/libos/src/shim_async.c @@ -61,7 +61,7 @@ int64_t install_async_event(PAL_HANDLE object, uint64_t time, assert(!object || (object && !time)); uint64_t now = 0; - int ret = DkSystemTimeQuery(&now); + int ret = PalSystemTimeQuery(&now); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -149,7 +149,7 @@ static int libos_async_worker(void* arg) { if (notme) { put_thread(self); - DkThreadExit(/*clear_child_tid=*/NULL); + PalThreadExit(/*clear_child_tid=*/NULL); /* UNREACHABLE */ } @@ -186,10 +186,10 @@ static int libos_async_worker(void* arg) { while (true) { uint64_t now = 0; - int ret = DkSystemTimeQuery(&now); + int ret = PalSystemTimeQuery(&now); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error("DkSystemTimeQuery failed with: %d", ret); + log_error("PalSystemTimeQuery failed with: %d", ret); goto out_err; } @@ -279,19 +279,19 @@ static int libos_async_worker(void* arg) { unlock(&async_worker_lock); /* wait on async IO events + install_new_event + next expiring alarm/timer */ - ret = DkStreamsWaitEvents(pals_cnt + 1, pals, pal_events, ret_events, - inf_sleep ? NULL : &sleep_time); + ret = PalStreamsWaitEvents(pals_cnt + 1, pals, pal_events, ret_events, + inf_sleep ? NULL : &sleep_time); if (ret < 0 && ret != -PAL_ERROR_INTERRUPTED && ret != -PAL_ERROR_TRYAGAIN) { ret = pal_to_unix_errno(ret); - log_error("DkStreamsWaitEvents failed with: %d", ret); + log_error("PalStreamsWaitEvents failed with: %d", ret); goto out_err; } bool polled = ret == 0; - ret = DkSystemTimeQuery(&now); + ret = PalSystemTimeQuery(&now); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error("DkSystemTimeQuery failed with: %d", ret); + log_error("PalSystemTimeQuery failed with: %d", ret); goto out_err; } @@ -355,7 +355,7 @@ static int libos_async_worker(void* arg) { free(pals); free(pal_events); - DkThreadExit(/*clear_child_tid=*/NULL); + PalThreadExit(/*clear_child_tid=*/NULL); /* UNREACHABLE */ out_err_unlock: @@ -363,7 +363,7 @@ static int libos_async_worker(void* arg) { out_err: log_error("Terminating the process due to a fatal error in async worker"); put_thread(self); - DkProcessExit(1); + PalProcessExit(1); } /* this should be called with the async_worker_lock held */ @@ -381,7 +381,7 @@ static int create_async_worker(void) { async_worker_state = WORKER_ALIVE; PAL_HANDLE handle = NULL; - int ret = DkThreadCreate(libos_async_worker, new, &handle); + int ret = PalThreadCreate(libos_async_worker, new, &handle); if (ret < 0) { async_worker_thread = NULL; diff --git a/libos/src/shim_checkpoint.c b/libos/src/shim_checkpoint.c index 44cc456053..f03fee03b9 100644 --- a/libos/src/shim_checkpoint.c +++ b/libos/src/shim_checkpoint.c @@ -219,7 +219,7 @@ static int send_memory_on_stream(PAL_HANDLE stream, struct libos_cp_store* store if (!(mem_prot & PAL_PROT_READ) && mem_size > 0) { /* make the area readable */ - ret = DkVirtualMemoryProtect(mem_addr, mem_size, mem_prot | PAL_PROT_READ); + ret = PalVirtualMemoryProtect(mem_addr, mem_size, mem_prot | PAL_PROT_READ); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -229,7 +229,7 @@ static int send_memory_on_stream(PAL_HANDLE stream, struct libos_cp_store* store if (!(mem_prot & PAL_PROT_READ) && mem_size > 0) { /* the area was made readable above; revert to original permissions */ - int ret2 = DkVirtualMemoryProtect(mem_addr, mem_size, mem_prot); + int ret2 = PalVirtualMemoryProtect(mem_addr, mem_size, mem_prot); if (ret2 < 0 && !ret) { ret = pal_to_unix_errno(ret2); } @@ -277,8 +277,8 @@ static int send_handles_on_stream(PAL_HANDLE stream, struct libos_cp_store* stor /* now we can traverse PAL-handle entries in correct order and send them one by one */ for (size_t i = 0; i < entries_cnt; i++) { - /* we need to abort migration if DkSendHandle() returned error, otherwise app may fail */ - ret = DkSendHandle(stream, entries[i]->handle); + /* we need to abort migration if PalSendHandle() returned error, otherwise app may fail */ + ret = PalSendHandle(stream, entries[i]->handle); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -306,7 +306,7 @@ static int receive_memory_on_stream(PAL_HANDLE handle, struct checkpoint_hdr* hd size_t size = (char*)ALLOC_ALIGN_UP_PTR(entry->addr + entry->size) - (char*)addr; pal_prot_flags_t prot = entry->prot; - int ret = DkVirtualMemoryAlloc(&addr, size, 0, prot | PAL_PROT_WRITE); + int ret = PalVirtualMemoryAlloc(&addr, size, 0, prot | PAL_PROT_WRITE); if (ret < 0) { log_error("failed allocating %p-%p", addr, addr + size); return pal_to_unix_errno(ret); @@ -318,7 +318,7 @@ static int receive_memory_on_stream(PAL_HANDLE handle, struct checkpoint_hdr* hd } if (!(prot & PAL_PROT_WRITE)) { - ret = DkVirtualMemoryProtect(addr, size, prot); + ret = PalVirtualMemoryProtect(addr, size, prot); if (ret < 0) { log_error("failed protecting %p-%p", addr, addr + size); return pal_to_unix_errno(ret); @@ -392,8 +392,8 @@ static int receive_handles_on_stream(struct checkpoint_hdr* hdr, void* base, ssi continue; PAL_HANDLE hdl = NULL; - ret = DkReceiveHandle(g_pal_public_state->parent_process, &hdl); - /* need to abort migration if DkReceiveHandle() returned error, otherwise app may fail */ + ret = PalReceiveHandle(g_pal_public_state->parent_process, &hdl); + /* need to abort migration if PalReceiveHandle() returned error, otherwise app may fail */ if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -441,7 +441,7 @@ static void* cp_alloc(void* addr, size_t size) { bkeep_remove_tmp_vma(tmp_vma); } - int ret = DkVirtualMemoryAlloc(&addr, size, 0, PAL_PROT_READ | PAL_PROT_WRITE); + int ret = PalVirtualMemoryAlloc(&addr, size, 0, PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { void* tmp_vma = NULL; if (bkeep_munmap(addr, size, /*is_internal=*/true, &tmp_vma) < 0) { @@ -465,7 +465,7 @@ int create_process_and_send_checkpoint(migrate_func_t migrate_func, /* FIXME: Child process requires some time to initialize before starting to receive checkpoint * data. Parallelizing process creation and checkpointing could improve latency of forking. */ PAL_HANDLE pal_process = NULL; - ret = DkProcessCreate(/*args=*/NULL, &pal_process); + ret = PalProcessCreate(/*args=*/NULL, &pal_process); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -551,7 +551,7 @@ int create_process_and_send_checkpoint(migrate_func_t migrate_func, log_error("failed unmaping checkpoint (ret = %d)", ret); goto out; } - if (DkVirtualMemoryFree((void*)cpstore.base, cpstore.bound) < 0) { + if (PalVirtualMemoryFree((void*)cpstore.base, cpstore.bound) < 0) { BUG(); } bkeep_remove_tmp_vma(tmp_vma); @@ -584,7 +584,7 @@ int create_process_and_send_checkpoint(migrate_func_t migrate_func, ret = 0; out: if (pal_process) - DkObjectClose(pal_process); + PalObjectClose(pal_process); if (ret < 0) { log_error("process creation failed"); @@ -626,7 +626,7 @@ int receive_checkpoint_and_restore(struct checkpoint_hdr* hdr) { mapsize = ALLOC_ALIGN_UP(hdr->size); } - ret = DkVirtualMemoryAlloc(&mapaddr, mapsize, 0, PAL_PROT_READ | PAL_PROT_WRITE); + ret = PalVirtualMemoryAlloc(&mapaddr, mapsize, 0, PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { void* tmp_vma = NULL; if (bkeep_munmap(mapaddr, mapsize, /*is_internal=*/true, &tmp_vma) < 0) @@ -673,7 +673,7 @@ out_fail:; if (bkeep_munmap(mapaddr, mapsize, /*is_internal=*/true, &tmp_vma) < 0) { BUG(); } - if (DkVirtualMemoryFree(mapaddr, mapsize) < 0) { + if (PalVirtualMemoryFree(mapaddr, mapsize) < 0) { BUG(); } bkeep_remove_tmp_vma(tmp_vma); diff --git a/libos/src/shim_debug.c b/libos/src/shim_debug.c index c3fb3df7a4..b69cd1c388 100644 --- a/libos/src/shim_debug.c +++ b/libos/src/shim_debug.c @@ -3,7 +3,7 @@ /* * This file contains code for registering libraries for debugger integration. We report the - * libraries to PAL using `DkDebugMapAdd`/`DkDebugMapRemove`. + * libraries to PAL using `PalDebugMapAdd`/`PalDebugMapRemove`. * * We also keep our own list of reported libraries, so that we can copy them to the child process, * or remove them all (in case of `exec`). @@ -17,7 +17,7 @@ #include "shim_utils.h" void libos_describe_location(uintptr_t addr, char* buf, size_t buf_size) { - DkDebugDescribeLocation(addr, buf, buf_size); + PalDebugDescribeLocation(addr, buf, buf_size); } #ifndef DEBUG @@ -66,7 +66,7 @@ void clean_link_map_list(void) { struct gdb_link_map* tmp; LISTP_FOR_EACH_ENTRY_SAFE(m, tmp, &g_link_map_list, list) { LISTP_DEL(m, &g_link_map_list, list); - DkDebugMapRemove(m->l_addr); + PalDebugMapRemove(m->l_addr); free(m); } @@ -93,7 +93,7 @@ void remove_r_debug(void* addr) { log_debug("%s: removing %s at %p", __func__, m->l_name, addr); LISTP_DEL(m, &g_link_map_list, list); - DkDebugMapRemove(addr); + PalDebugMapRemove(addr); free(m); out: @@ -120,7 +120,7 @@ void append_r_debug(const char* uri, void* addr) { log_debug("%s: adding %s at %p", __func__, uri, addr); LISTP_ADD_TAIL(new, &g_link_map_list, list); - DkDebugMapAdd(uri, addr); + PalDebugMapAdd(uri, addr); out: unlock(&g_link_map_list_lock); @@ -160,7 +160,7 @@ BEGIN_RS_FUNC(gdb_map) { CP_REBASE(m->l_name); LISTP_ADD_TAIL(m, &g_link_map_list, list); - DkDebugMapAdd(m->l_name, m->l_addr); + PalDebugMapAdd(m->l_name, m->l_addr); } END_RS_FUNC(gdb_map) diff --git a/libos/src/shim_init.c b/libos/src/shim_init.c index 616fa6aebb..4f9869b79a 100644 --- a/libos/src/shim_init.c +++ b/libos/src/shim_init.c @@ -41,7 +41,7 @@ struct pal_public_state* g_pal_public_state = NULL; * any thread, even internal. */ noreturn void libos_abort(void) { DEBUG_BREAK_ON_FAILURE(); - DkProcessExit(1); + PalProcessExit(1); } static unsigned pal_errno_to_unix_errno_table[PAL_ERROR_NATIVE_COUNT + 1] = { @@ -120,7 +120,7 @@ void* allocate_stack(size_t size, size_t protect_size, bool user) { } bool need_mem_free = false; - ret = DkVirtualMemoryAlloc(&stack, size + protect_size, 0, /*prot=*/0); + ret = PalVirtualMemoryAlloc(&stack, size + protect_size, 0, /*prot=*/0); if (ret < 0) { goto out_fail; } @@ -134,7 +134,7 @@ void* allocate_stack(size_t size, size_t protect_size, bool user) { goto out_fail; } - if (DkVirtualMemoryProtect(stack + protect_size, size, PAL_PROT_READ | PAL_PROT_WRITE) < 0) { + if (PalVirtualMemoryProtect(stack + protect_size, size, PAL_PROT_READ | PAL_PROT_WRITE) < 0) { goto out_fail; } @@ -146,7 +146,7 @@ out_fail:; BUG(); } if (need_mem_free) { - if (DkVirtualMemoryFree(stack, size + protect_size) < 0) { + if (PalVirtualMemoryFree(stack, size + protect_size) < 0) { BUG(); } } @@ -362,12 +362,12 @@ static int read_environs(const char** envp) { int _err = CALL_INIT(func, ##__VA_ARGS__); \ if (_err < 0) { \ log_error("Error during libos_init() in " #func " (%d)", _err); \ - DkProcessExit(1); \ + PalProcessExit(1); \ } \ } while (0) noreturn void* libos_init(int argc, const char** argv, const char** envp) { - g_pal_public_state = DkGetPalPublicState(); + g_pal_public_state = PalGetPalPublicState(); assert(g_pal_public_state); g_log_level = g_pal_public_state->log_level; @@ -384,7 +384,7 @@ noreturn void* libos_init(int argc, const char** argv, const char** envp) { if (!IS_POWER_OF_2(ALLOC_ALIGNMENT)) { log_error("Error during libos_init(): PAL allocation alignment not a power of 2"); - DkProcessExit(1); + PalProcessExit(1); } g_manifest_root = g_pal_public_state->manifest_root; @@ -409,7 +409,7 @@ noreturn void* libos_init(int argc, const char** argv, const char** envp) { int ret = read_exact(g_pal_public_state->parent_process, &hdr, sizeof(hdr)); if (ret < 0) { log_error("libos_init: failed to read the whole checkpoint header: %d", ret); - DkProcessExit(1); + PalProcessExit(1); } assert(hdr.size); @@ -443,7 +443,7 @@ noreturn void* libos_init(int argc, const char** argv, const char** envp) { int ret = connect_to_process(g_process_ipc_ids.parent_vmid); if (ret < 0) { log_error("libos_init: failed to establish IPC connection to parent: %d", ret); - DkProcessExit(1); + PalProcessExit(1); } /* Send a dummy request causing the IPC leader to connect to this process, so that it is @@ -452,7 +452,7 @@ noreturn void* libos_init(int argc, const char** argv, const char** envp) { ret = ipc_get_id_owner(/*id=*/0, /*out_owner=*/&dummy); if (ret < 0) { log_debug("libos_init: failed to get a connection from IPC leader to us: %d", ret); - DkProcessExit(1); + PalProcessExit(1); } assert(dummy == 0); // Nobody should own ID `0`. @@ -461,14 +461,14 @@ noreturn void* libos_init(int argc, const char** argv, const char** envp) { ret = write_exact(g_pal_public_state->parent_process, &dummy_c, sizeof(dummy_c)); if (ret < 0) { log_error("libos_init: failed to write ready notification: %d", ret); - DkProcessExit(1); + PalProcessExit(1); } /* Wait for parent to settle its adult things. */ ret = read_exact(g_pal_public_state->parent_process, &dummy_c, sizeof(dummy_c)); if (ret < 0) { log_error("libos_init: failed to read parent's confirmation: %d", ret); - DkProcessExit(1); + PalProcessExit(1); } } else { /* !g_pal_public_state->parent_process */ RUN_INIT(init_sync_server); @@ -501,7 +501,7 @@ static int get_256b_random_hex_string(char* buf, size_t size) { if (size < sizeof(random) * 2 + 1) return -ENOMEM; - int ret = DkRandomBitsRead(&random, sizeof(random)); + int ret = PalRandomBitsRead(&random, sizeof(random)); if (ret < 0) return pal_to_unix_errno(ret); @@ -543,8 +543,8 @@ int create_pipe(char* name, char* uri, size_t size, PAL_HANDLE* hdl, bool use_vm if (len >= size) return -ERANGE; - ret = DkStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, - /*options=*/0, &pipe); + ret = PalStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, + /*options=*/0, &pipe); if (ret < 0) { if (!use_vmid_for_name && ret == -PAL_ERROR_STREAMEXIST) { /* tried to create a pipe with random name but it already exists */ diff --git a/libos/src/shim_malloc.c b/libos/src/shim_malloc.c index d02a17a382..b65dc2ce3a 100644 --- a/libos/src/shim_malloc.c +++ b/libos/src/shim_malloc.c @@ -42,7 +42,7 @@ void* __system_malloc(size_t size) { return NULL; } - ret = DkVirtualMemoryAlloc(&addr, alloc_size, 0, PAL_PROT_WRITE | PAL_PROT_READ); + ret = PalVirtualMemoryAlloc(&addr, alloc_size, 0, PAL_PROT_WRITE | PAL_PROT_READ); if (ret < 0) { log_error("failed to allocate memory (%ld)", pal_to_unix_errno(ret)); void* tmp_vma = NULL; @@ -64,7 +64,7 @@ void __system_free(void* addr, size_t size) { if (bkeep_munmap(addr, ALLOC_ALIGN_UP(size), /*is_internal=*/true, &tmp_vma) < 0) { BUG(); } - if (DkVirtualMemoryFree(addr, ALLOC_ALIGN_UP(size)) < 0) { + if (PalVirtualMemoryFree(addr, ALLOC_ALIGN_UP(size)) < 0) { BUG(); } #ifdef ASAN @@ -94,7 +94,7 @@ void* malloc(size_t size) { * condition and must terminate the current process. */ log_error("Out-of-memory in library OS"); - DkProcessExit(1); + PalProcessExit(1); } return mem; diff --git a/libos/src/shim_object.c b/libos/src/shim_object.c index 3b9630bf8d..3f668a2f68 100644 --- a/libos/src/shim_object.c +++ b/libos/src/shim_object.c @@ -4,7 +4,7 @@ int event_wait_with_retry(PAL_HANDLE handle) { int ret; do { - ret = DkEventWait(handle, /*timeout=*/NULL); + ret = PalEventWait(handle, /*timeout=*/NULL); } while (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN); if (ret < 0) { diff --git a/libos/src/shim_pollable_event.c b/libos/src/shim_pollable_event.c index 41b89145e2..51004ad2a2 100644 --- a/libos/src/shim_pollable_event.c +++ b/libos/src/shim_pollable_event.c @@ -22,22 +22,22 @@ int create_pollable_event(struct libos_pollable_event* event) { PAL_HANDLE write_handle; do { - ret = DkStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, - PAL_OPTION_NONBLOCK | PAL_OPTION_CLOEXEC, &write_handle); + ret = PalStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, + PAL_OPTION_NONBLOCK | PAL_OPTION_CLOEXEC, &write_handle); } while (ret == -PAL_ERROR_INTERRUPTED); if (ret < 0) { - log_error("%s: DkStreamOpen failed: %d", __func__, ret); + log_error("%s: PalStreamOpen failed: %d", __func__, ret); ret = pal_to_unix_errno(ret); goto out; } PAL_HANDLE read_handle; do { - ret = DkStreamWaitForClient(srv_handle, &read_handle, PAL_OPTION_NONBLOCK); + ret = PalStreamWaitForClient(srv_handle, &read_handle, PAL_OPTION_NONBLOCK); } while (ret == -PAL_ERROR_INTERRUPTED); if (ret < 0) { - log_error("%s: DkStreamWaitForClient failed: %d", __func__, ret); - DkObjectClose(write_handle); + log_error("%s: PalStreamWaitForClient failed: %d", __func__, ret); + PalObjectClose(write_handle); ret = pal_to_unix_errno(ret); goto out; } @@ -49,11 +49,11 @@ int create_pollable_event(struct libos_pollable_event* event) { ret = 0; out:; - int tmp_ret = pal_to_unix_errno(DkStreamDelete(srv_handle, PAL_DELETE_ALL)); - DkObjectClose(srv_handle); + int tmp_ret = pal_to_unix_errno(PalStreamDelete(srv_handle, PAL_DELETE_ALL)); + PalObjectClose(srv_handle); if (!ret && tmp_ret) { - DkObjectClose(read_handle); - DkObjectClose(write_handle); + PalObjectClose(read_handle); + PalObjectClose(write_handle); /* Clearing just for sanity. */ event->read_handle = NULL; event->write_handle = NULL; @@ -62,8 +62,8 @@ out:; } void destroy_pollable_event(struct libos_pollable_event* event) { - DkObjectClose(event->read_handle); - DkObjectClose(event->write_handle); + PalObjectClose(event->read_handle); + PalObjectClose(event->write_handle); } int set_pollable_event(struct libos_pollable_event* event) { @@ -74,7 +74,7 @@ int set_pollable_event(struct libos_pollable_event* event) { do { char c = 0; size_t size = sizeof(c); - ret = DkStreamWrite(event->write_handle, /*offset=*/0, &size, &c, /*dest=*/NULL); + ret = PalStreamWrite(event->write_handle, /*offset=*/0, &size, &c, /*dest=*/NULL); ret = pal_to_unix_errno(ret); if (ret == 0 && size == 0) { ret = -EINVAL; @@ -97,7 +97,7 @@ int clear_pollable_event(struct libos_pollable_event* event) { do { char buf[0x100]; size_t size = sizeof(buf); - int ret = DkStreamRead(event->read_handle, /*offset=*/0, &size, buf, NULL, 0); + int ret = PalStreamRead(event->read_handle, /*offset=*/0, &size, buf, NULL, 0); ret = pal_to_unix_errno(ret); if (ret == 0 && size == 0) { ret = -EINVAL; diff --git a/libos/src/shim_rtld.c b/libos/src/shim_rtld.c index 488408c970..70ceff62cc 100644 --- a/libos/src/shim_rtld.c +++ b/libos/src/shim_rtld.c @@ -278,8 +278,8 @@ static int execute_loadcmd(const struct loadcmd* c, elf_addr_t base_diff, void* last_page_start = ALLOC_ALIGN_DOWN_PTR(zero_start); if ((c->prot & PROT_WRITE) == 0) { - if ((ret = DkVirtualMemoryProtect(last_page_start, ALLOC_ALIGNMENT, - pal_prot | PAL_PROT_WRITE) < 0)) { + if ((ret = PalVirtualMemoryProtect(last_page_start, ALLOC_ALIGNMENT, + pal_prot | PAL_PROT_WRITE) < 0)) { log_debug("%s: cannot change memory protections", __func__); return pal_to_unix_errno(ret); } @@ -288,7 +288,7 @@ static int execute_loadcmd(const struct loadcmd* c, elf_addr_t base_diff, memset(zero_start, 0, zero_size); if ((c->prot & PROT_WRITE) == 0) { - if ((ret = DkVirtualMemoryProtect(last_page_start, ALLOC_ALIGNMENT, pal_prot) < 0)) { + if ((ret = PalVirtualMemoryProtect(last_page_start, ALLOC_ALIGNMENT, pal_prot) < 0)) { log_debug("%s: cannot change memory protections", __func__); return pal_to_unix_errno(ret); } @@ -308,8 +308,8 @@ static int execute_loadcmd(const struct loadcmd* c, elf_addr_t base_diff, return ret; } - if ((ret = DkVirtualMemoryAlloc(&zero_page_start, zero_page_size, /*alloc_type=*/0, - zero_pal_prot)) < 0) { + if ((ret = PalVirtualMemoryAlloc(&zero_page_start, zero_page_size, /*alloc_type=*/0, + zero_pal_prot)) < 0) { log_debug("%s: cannot map zero-fill pages", __func__); return pal_to_unix_errno(ret); } @@ -947,8 +947,8 @@ static int vdso_map_init(void) { return ret; } - ret = DkVirtualMemoryAlloc(&addr, ALLOC_ALIGN_UP(vdso_so_size), /*alloc_type=*/0, - PAL_PROT_READ | PAL_PROT_WRITE); + ret = PalVirtualMemoryAlloc(&addr, ALLOC_ALIGN_UP(vdso_so_size), /*alloc_type=*/0, + PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -956,7 +956,8 @@ static int vdso_map_init(void) { memcpy(addr, &vdso_so, vdso_so_size); memset(addr + vdso_so_size, 0, ALLOC_ALIGN_UP(vdso_so_size) - vdso_so_size); - ret = DkVirtualMemoryProtect(addr, ALLOC_ALIGN_UP(vdso_so_size), PAL_PROT_READ | PAL_PROT_EXEC); + ret = PalVirtualMemoryProtect(addr, ALLOC_ALIGN_UP(vdso_so_size), + PAL_PROT_READ | PAL_PROT_EXEC); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -1101,10 +1102,10 @@ noreturn void execute_elf_object(struct link_map* exec_map, void* argp, elf_auxv elf_addr_t auxp_extra = (elf_addr_t)&auxp[9]; elf_addr_t random = auxp_extra; /* random 16B for AT_RANDOM */ - ret = DkRandomBitsRead((void*)random, 16); + ret = PalRandomBitsRead((void*)random, 16); if (ret < 0) { - log_error("execute_elf_object: DkRandomBitsRead failed: %d", ret); - DkProcessExit(1); + log_error("execute_elf_object: PalRandomBitsRead failed: %d", ret); + PalProcessExit(1); /* UNREACHABLE */ } auxp[5].a_un.a_val = random; diff --git a/libos/src/shim_utils.c b/libos/src/shim_utils.c index 50192bb541..87efceaa38 100644 --- a/libos/src/shim_utils.c +++ b/libos/src/shim_utils.c @@ -11,7 +11,7 @@ int read_exact(PAL_HANDLE handle, void* buf, size_t size) { size_t read = 0; while (read < size) { size_t tmp_read = size - read; - int ret = DkStreamRead(handle, /*offset=*/0, &tmp_read, (char*)buf + read, NULL, 0); + int ret = PalStreamRead(handle, /*offset=*/0, &tmp_read, (char*)buf + read, NULL, 0); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN) { continue; @@ -29,7 +29,7 @@ int write_exact(PAL_HANDLE handle, void* buf, size_t size) { size_t written = 0; while (written < size) { size_t tmp_written = size - written; - int ret = DkStreamWrite(handle, /*offset=*/0, &tmp_written, (char*)buf + written, NULL); + int ret = PalStreamWrite(handle, /*offset=*/0, &tmp_written, (char*)buf + written, NULL); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN) { continue; diff --git a/libos/src/sync/shim_sync_client.c b/libos/src/sync/shim_sync_client.c index f55860ff1c..49fe30deb5 100644 --- a/libos/src/sync/shim_sync_client.c +++ b/libos/src/sync/shim_sync_client.c @@ -19,7 +19,7 @@ #define FATAL(fmt...) \ do { \ log_error("Fatal error in sync client: " fmt); \ - DkProcessExit(1); \ + PalProcessExit(1); \ } while (0) static bool g_sync_enabled = false; @@ -52,7 +52,7 @@ static void put_sync_handle(struct sync_handle* handle) { free(handle->data); destroy_lock(&handle->use_lock); destroy_lock(&handle->prop_lock); - DkObjectClose(handle->event); + PalObjectClose(handle->event); free(handle); } } @@ -81,13 +81,13 @@ static void sync_wait_without_lock(struct sync_handle* handle) { FATAL("waiting for event"); lock(&handle->prop_lock); if (--handle->n_waiters == 0) - DkEventClear(handle->event); + PalEventClear(handle->event); } static void sync_notify(struct sync_handle* handle) { assert(locked(&handle->prop_lock)); if (handle->n_waiters > 0) - DkEventSet(handle->event); + PalEventSet(handle->event); } static void sync_downgrade(struct sync_handle* handle) { @@ -160,7 +160,7 @@ static int sync_init(struct sync_handle* handle, uint64_t id) { ret = -ENOMEM; goto err; } - if ((ret = DkEventCreate(&handle->event, /*init_signaled=*/false, /*auto_clear=*/false)) < 0) { + if ((ret = PalEventCreate(&handle->event, /*init_signaled=*/false, /*auto_clear=*/false)) < 0) { ret = pal_to_unix_errno(ret); goto err; } @@ -199,7 +199,7 @@ static int sync_init(struct sync_handle* handle, uint64_t id) { if (lock_created(&handle->prop_lock)) destroy_lock(&handle->prop_lock); if (handle->event) - DkObjectClose(handle->event); + PalObjectClose(handle->event); return ret; } diff --git a/libos/src/sync/shim_sync_server.c b/libos/src/sync/shim_sync_server.c index 48dd87bf1a..b510a6475d 100644 --- a/libos/src/sync/shim_sync_server.c +++ b/libos/src/sync/shim_sync_server.c @@ -18,7 +18,7 @@ #define FATAL(fmt...) \ do { \ log_error("Fatal error in sync server: " fmt); \ - DkProcessExit(1); \ + PalProcessExit(1); \ } while(0) DEFINE_LIST(server_lease); diff --git a/libos/src/sys/shim_alarm.c b/libos/src/sys/shim_alarm.c index d98ca47294..caeb094dd0 100644 --- a/libos/src/sys/shim_alarm.c +++ b/libos/src/sys/shim_alarm.c @@ -82,7 +82,7 @@ long libos_syscall_setitimer(int which, struct __kernel_itimerval* value, return -EFAULT; uint64_t setup_time = 0; - int ret = DkSystemTimeQuery(&setup_time); + int ret = PalSystemTimeQuery(&setup_time); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -131,7 +131,7 @@ long libos_syscall_getitimer(int which, struct __kernel_itimerval* value) { return -EFAULT; uint64_t setup_time = 0; - int ret = DkSystemTimeQuery(&setup_time); + int ret = PalSystemTimeQuery(&setup_time); if (ret < 0) { return pal_to_unix_errno(ret); } diff --git a/libos/src/sys/shim_brk.c b/libos/src/sys/shim_brk.c index 304255f3b4..83a1d02e6a 100644 --- a/libos/src/sys/shim_brk.c +++ b/libos/src/sys/shim_brk.c @@ -68,7 +68,7 @@ int init_brk_region(void* brk_start, size_t data_segment_size) { size_t offset = 0; if (!g_pal_public_state->disable_aslr) { - ret = DkRandomBitsRead(&offset, sizeof(offset)); + ret = PalRandomBitsRead(&offset, sizeof(offset)); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -126,7 +126,7 @@ void reset_brk(void) { } if (allocated_size > 0) { - if (DkVirtualMemoryFree(brk_region.brk_start, allocated_size) < 0) { + if (PalVirtualMemoryFree(brk_region.brk_start, allocated_size) < 0) { BUG(); } } @@ -161,7 +161,7 @@ void* libos_syscall_brk(void* _brk) { goto out; } - if (DkVirtualMemoryFree(brk_aligned, size) < 0) { + if (PalVirtualMemoryFree(brk_aligned, size) < 0) { BUG(); } } @@ -189,7 +189,7 @@ void* libos_syscall_brk(void* _brk) { goto out; } - int ret = DkVirtualMemoryAlloc((void**)&brk_current, size, 0, PAL_PROT_READ | PAL_PROT_WRITE); + int ret = PalVirtualMemoryAlloc((void**)&brk_current, size, 0, PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { if (bkeep_mmap_fixed(brk_current, brk_region.brk_end - brk_current, PROT_NONE, MAP_FIXED | VMA_UNMAPPED, NULL, 0, "heap") < 0) { diff --git a/libos/src/sys/shim_clone.c b/libos/src/sys/shim_clone.c index 64cf44d45a..1bc6f80948 100644 --- a/libos/src/sys/shim_clone.c +++ b/libos/src/sys/shim_clone.c @@ -94,7 +94,7 @@ static int clone_implementation_wrapper(void* arg_) { tcb->context.tls = arg->tls; /* Inform the parent thread that we finished initialization. */ - DkEventSet(arg->initialize_event); + PalEventSet(arg->initialize_event); put_thread(my_thread); @@ -376,14 +376,14 @@ long libos_syscall_clone(unsigned long flags, unsigned long user_stack_addr, int if (tmp_ret < 0) { log_debug("Failed to change back ID %u owner: %d", tid, tmp_ret); /* No way to recover gracefully. */ - DkProcessExit(1); + PalProcessExit(1); } /* ... and release it. */ tmp_ret = ipc_release_id_range(tid, tid); if (tmp_ret < 0) { log_debug("Failed to release ID %u: %d", tid, tmp_ret); /* No way to recover gracefully. */ - DkProcessExit(1); + PalProcessExit(1); } } return ret; @@ -416,13 +416,13 @@ long libos_syscall_clone(unsigned long flags, unsigned long user_stack_addr, int struct libos_clone_args new_args; memset(&new_args, 0, sizeof(new_args)); - ret = DkEventCreate(&new_args.create_event, /*init_signaled=*/false, /*auto_clear=*/false); + ret = PalEventCreate(&new_args.create_event, /*init_signaled=*/false, /*auto_clear=*/false); if (ret < 0) { ret = pal_to_unix_errno(ret); goto clone_thread_failed; } - ret = DkEventCreate(&new_args.initialize_event, /*init_signaled=*/false, /*auto_clear=*/false); + ret = PalEventCreate(&new_args.initialize_event, /*init_signaled=*/false, /*auto_clear=*/false); if (ret < 0) { ret = pal_to_unix_errno(ret); goto clone_thread_failed; @@ -438,14 +438,8 @@ long libos_syscall_clone(unsigned long flags, unsigned long user_stack_addr, int new_args.tls = tls; new_args.regs = self->libos_tcb->context.regs; - // Invoke DkThreadCreate to spawn off a child process using the actual - // "clone" system call. DkThreadCreate allocates a stack for the child - // and then runs the given function on that stack However, we want our - // child to run on the Parent allocated stack , so once the DkThreadCreate - // returns .The parent comes back here - however, the child is Happily - // running the function we gave to DkThreadCreate. PAL_HANDLE pal_handle = NULL; - ret = DkThreadCreate(clone_implementation_wrapper, &new_args, &pal_handle); + ret = PalThreadCreate(clone_implementation_wrapper, &new_args, &pal_handle); if (ret < 0) { ret = pal_to_unix_errno(ret); put_thread(new_args.thread); @@ -457,25 +451,25 @@ long libos_syscall_clone(unsigned long flags, unsigned long user_stack_addr, int if (set_parent_tid) *set_parent_tid = thread->tid; - DkEventSet(new_args.create_event); + PalEventSet(new_args.create_event); ret = event_wait_with_retry(new_args.initialize_event); if (ret < 0) { /* XXX: Currently it doesn't seem possible to cleanly handle this error - the child thread * might be running correctly. */ log_error("event_wait_with_retry failed with: %ld", ret); - DkProcessExit(1); + PalProcessExit(1); } - DkObjectClose(new_args.initialize_event); - DkObjectClose(new_args.create_event); + PalObjectClose(new_args.initialize_event); + PalObjectClose(new_args.create_event); put_thread(thread); return tid; clone_thread_failed: if (new_args.create_event) - DkObjectClose(new_args.create_event); + PalObjectClose(new_args.create_event); if (new_args.initialize_event) - DkObjectClose(new_args.initialize_event); + PalObjectClose(new_args.initialize_event); failed: if (thread) put_thread(thread); diff --git a/libos/src/sys/shim_epoll.c b/libos/src/sys/shim_epoll.c index 557af62e9f..e377b1b5ff 100644 --- a/libos/src/sys/shim_epoll.c +++ b/libos/src/sys/shim_epoll.c @@ -138,7 +138,7 @@ void interrupt_epolls(struct libos_handle* handle) { unlock(&handle->lock); log_error("%s: failed to allocate memory for the epoll items array", __func__); /* No way to handle this cleanly. */ - DkProcessExit(1); + PalProcessExit(1); } } @@ -599,8 +599,8 @@ static int do_epoll_wait(int epfd, struct epoll_event* events, int maxevents, in unlock(&epoll->lock); if (!have_pending_signals()) { - ret = DkStreamsWaitEvents(items_count + 1, pal_handles, pal_events, pal_ret_events, - timeout_ms == -1 ? NULL : &timeout_us); + ret = PalStreamsWaitEvents(items_count + 1, pal_handles, pal_events, pal_ret_events, + timeout_ms == -1 ? NULL : &timeout_us); ret = pal_to_unix_errno(ret); } else { ret = -EINTR; diff --git a/libos/src/sys/shim_eventfd.c b/libos/src/sys/shim_eventfd.c index c1cf54de6b..b952e583bf 100644 --- a/libos/src/sys/shim_eventfd.c +++ b/libos/src/sys/shim_eventfd.c @@ -48,8 +48,8 @@ static int create_eventfd(PAL_HANDLE* efd, uint64_t initial_count, int flags) { pal_flags |= flags & EFD_CLOEXEC ? PAL_OPTION_CLOEXEC : 0; pal_flags |= flags & EFD_SEMAPHORE ? PAL_OPTION_EFD_SEMAPHORE : 0; - ret = DkStreamOpen(URI_PREFIX_EVENTFD, PAL_ACCESS_RDWR, /*share_flags=*/0, - PAL_CREATE_IGNORED, pal_flags, &hdl); + ret = PalStreamOpen(URI_PREFIX_EVENTFD, PAL_ACCESS_RDWR, /*share_flags=*/0, + PAL_CREATE_IGNORED, pal_flags, &hdl); if (ret < 0) { log_error("eventfd: creation failure"); return pal_to_unix_errno(ret); @@ -57,7 +57,7 @@ static int create_eventfd(PAL_HANDLE* efd, uint64_t initial_count, int flags) { /* set the initial count */ size_t write_size = sizeof(initial_count); - ret = DkStreamWrite(hdl, /*offset=*/0, &write_size, &initial_count, /*dest=*/NULL); + ret = PalStreamWrite(hdl, /*offset=*/0, &write_size, &initial_count, /*dest=*/NULL); if (ret < 0) { log_error("eventfd: failed to set initial count"); return pal_to_unix_errno(ret); diff --git a/libos/src/sys/shim_exec.c b/libos/src/sys/shim_exec.c index 8beb0e5de4..e1a5f14f08 100644 --- a/libos/src/sys/shim_exec.c +++ b/libos/src/sys/shim_exec.c @@ -58,7 +58,7 @@ noreturn static void __libos_syscall_execve_rtld(void* new_argp, elf_auxv_t* new if (bkeep_munmap(vma->addr, vma->length, !!(vma->flags & VMA_INTERNAL), &tmp_vma) < 0) { BUG(); } - if (DkVirtualMemoryFree(vma->addr, vma->length) < 0) { + if (PalVirtualMemoryFree(vma->addr, vma->length) < 0) { BUG(); } bkeep_remove_tmp_vma(tmp_vma); diff --git a/libos/src/sys/shim_exit.c b/libos/src/sys/shim_exit.c index 887e6f4b1f..f870b9c4fc 100644 --- a/libos/src/sys/shim_exit.c +++ b/libos/src/sys/shim_exit.c @@ -58,7 +58,7 @@ static noreturn void libos_clean_and_exit(int exit_code) { /* TODO: We exit whole libos, but there are some objects that might need cleanup - we should do * a proper cleanup of everything. */ - DkProcessExit(exit_code); + PalProcessExit(exit_code); } noreturn void thread_exit(int error_code, int term_signal) { @@ -85,11 +85,11 @@ noreturn void thread_exit(int error_code, int term_signal) { /* `cleanup_thread` did not get this reference, clean it. We have to be careful, as * this is most likely the last reference and will free this `cur_thread`. */ put_thread(cur_thread); - DkThreadExit(NULL); + PalThreadExit(NULL); /* UNREACHABLE */ } - DkThreadExit(&cur_thread->clear_child_tid_pal); + PalThreadExit(&cur_thread->clear_child_tid_pal); /* UNREACHABLE */ } @@ -121,7 +121,7 @@ static int mark_thread_to_die(struct libos_thread* thread, void* arg) { * set above (but only if we really set that flag). */ if (need_wakeup) { thread_wakeup(thread); - (void)DkThreadResume(thread->pal_handle); // There is nothing we can do on errors. + (void)PalThreadResume(thread->pal_handle); // There is nothing we can do on errors. } return 1; } @@ -133,7 +133,7 @@ bool kill_other_threads(void) { if (walk_thread_list(mark_thread_to_die, get_cur_thread(), /*one_shot=*/false) != -ESRCH) { killed = true; } - DkThreadYieldExecution(); + PalThreadYieldExecution(); /* Wait for all other threads to exit. */ while (!check_last_thread(/*mark_self_dead=*/false)) { @@ -142,7 +142,7 @@ bool kill_other_threads(void) { if (walk_thread_list(mark_thread_to_die, get_cur_thread(), /*one_shot=*/false) != -ESRCH) { killed = true; } - DkThreadYieldExecution(); + PalThreadYieldExecution(); } return killed; diff --git a/libos/src/sys/shim_futex.c b/libos/src/sys/shim_futex.c index 8b967da971..ccdecd2d67 100644 --- a/libos/src/sys/shim_futex.c +++ b/libos/src/sys/shim_futex.c @@ -727,7 +727,7 @@ static int _libos_syscall_futex(uint32_t* uaddr, int op, uint32_t val, void* uti /* For FUTEX_WAIT, timeout is interpreted as a relative value, which differs from other * futex operations, where timeout is interpreted as an absolute value. */ uint64_t current_time = 0; - int ret = DkSystemTimeQuery(¤t_time); + int ret = PalSystemTimeQuery(¤t_time); if (ret < 0) { return pal_to_unix_errno(ret); } diff --git a/libos/src/sys/shim_getrandom.c b/libos/src/sys/shim_getrandom.c index ca6e768e0e..9410986eae 100644 --- a/libos/src/sys/shim_getrandom.c +++ b/libos/src/sys/shim_getrandom.c @@ -22,10 +22,10 @@ long libos_syscall_getrandom(char* buf, size_t count, unsigned int flags) { if (!is_user_memory_writable(buf, count)) return -EFAULT; - /* In theory, DkRandomBitsRead may block on some PALs (which conflicts with GRND_NONBLOCK flag), - * but this shouldn't be possible in practice, so we don't care. + /* In theory, PalRandomBitsRead may block on some PALs (which conflicts with GRND_NONBLOCK + * flag), but this shouldn't be possible in practice, so we don't care. */ - int ret = DkRandomBitsRead(buf, count); + int ret = PalRandomBitsRead(buf, count); if (ret < 0) { ret = pal_to_unix_errno(ret); if (ret == -EINTR) { diff --git a/libos/src/sys/shim_getrlimit.c b/libos/src/sys/shim_getrlimit.c index f39f799661..0cb4e6ec56 100644 --- a/libos/src/sys/shim_getrlimit.c +++ b/libos/src/sys/shim_getrlimit.c @@ -168,8 +168,8 @@ long libos_syscall_sysinfo(struct sysinfo* info) { memset(info, 0, sizeof(*info)); info->totalram = g_pal_public_state->mem_total; info->totalhigh = g_pal_public_state->mem_total; - info->freeram = DkMemoryAvailableQuota(); - info->freehigh = DkMemoryAvailableQuota(); + info->freeram = PalMemoryAvailableQuota(); + info->freehigh = PalMemoryAvailableQuota(); info->mem_unit = 1; info->procs = 1; /* report only this Gramine process */ return 0; diff --git a/libos/src/sys/shim_ioctl.c b/libos/src/sys/shim_ioctl.c index eb055f4b80..4b2a702a30 100644 --- a/libos/src/sys/shim_ioctl.c +++ b/libos/src/sys/shim_ioctl.c @@ -89,7 +89,7 @@ long libos_syscall_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { size = stat.st_size; } else if (hdl->pal_handle) { PAL_STREAM_ATTR attr; - ret = DkStreamAttributesQueryByHandle(hdl->pal_handle, &attr); + ret = PalStreamAttributesQueryByHandle(hdl->pal_handle, &attr); if (ret < 0) { ret = pal_to_unix_errno(ret); break; diff --git a/libos/src/sys/shim_mmap.c b/libos/src/sys/shim_mmap.c index c15e4fb5ce..57dd202e43 100644 --- a/libos/src/sys/shim_mmap.c +++ b/libos/src/sys/shim_mmap.c @@ -173,7 +173,7 @@ void* libos_syscall_mmap(void* addr, size_t length, int prot, int flags, int fd, /* From now on `addr` contains the actual address we want to map (and already bookkeeped). */ if (!hdl) { - ret = DkVirtualMemoryAlloc(&addr, length, 0, LINUX_PROT_TO_PAL(prot, flags)); + ret = PalVirtualMemoryAlloc(&addr, length, 0, LINUX_PROT_TO_PAL(prot, flags)); if (ret < 0) { if (ret == -PAL_ERROR_DENIED) { ret = -EPERM; @@ -239,7 +239,7 @@ long libos_syscall_mprotect(void* addr, size_t length, int prot) { return -EINVAL; } - /* `bkeep_mprotect` and then `DkVirtualMemoryProtect` is racy, but it's hard to do it properly. + /* `bkeep_mprotect` and then `PalVirtualMemoryProtect` is racy, but it's hard to do it properly. * On the other hand if this race happens, it means user app is buggy, so not a huge problem. */ int ret = bkeep_mprotect(addr, length, prot, /*is_internal=*/false); @@ -261,7 +261,7 @@ long libos_syscall_mprotect(void* addr, size_t length, int prot) { } } - ret = DkVirtualMemoryProtect(addr, length, LINUX_PROT_TO_PAL(prot, /*map_flags=*/0)); + ret = PalVirtualMemoryProtect(addr, length, LINUX_PROT_TO_PAL(prot, /*map_flags=*/0)); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -297,7 +297,7 @@ long libos_syscall_munmap(void* addr, size_t length) { return ret; } - if (DkVirtualMemoryFree(addr, length) < 0) { + if (PalVirtualMemoryFree(addr, length) < 0) { BUG(); } diff --git a/libos/src/sys/shim_pipe.c b/libos/src/sys/shim_pipe.c index 32a6215cf3..5e07780f21 100644 --- a/libos/src/sys/shim_pipe.c +++ b/libos/src/sys/shim_pipe.c @@ -35,8 +35,8 @@ static int create_pipes(struct libos_handle* srv, struct libos_handle* cli, int return ret; } - ret = DkStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, - LINUX_OPEN_FLAGS_TO_PAL_OPTIONS(flags), &hdl2); + ret = PalStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, + LINUX_OPEN_FLAGS_TO_PAL_OPTIONS(flags), &hdl2); if (ret < 0) { ret = pal_to_unix_errno(ret); log_error("pipe connection failure"); @@ -44,7 +44,7 @@ static int create_pipes(struct libos_handle* srv, struct libos_handle* cli, int } do { - ret = DkStreamWaitForClient(hdl0, &hdl1, /*options=*/0); + ret = PalStreamWaitForClient(hdl0, &hdl1, /*options=*/0); } while (ret == -PAL_ERROR_INTERRUPTED); if (ret < 0) { ret = pal_to_unix_errno(ret); @@ -80,13 +80,13 @@ static int create_pipes(struct libos_handle* srv, struct libos_handle* cli, int ret = 0; out:; - int tmp_ret = DkStreamDelete(hdl0, PAL_DELETE_ALL); - DkObjectClose(hdl0); + int tmp_ret = PalStreamDelete(hdl0, PAL_DELETE_ALL); + PalObjectClose(hdl0); if (ret || tmp_ret) { if (hdl1) - DkObjectClose(hdl1); + PalObjectClose(hdl1); if (hdl2) - DkObjectClose(hdl2); + PalObjectClose(hdl2); free(srv->uri); srv->uri = NULL; @@ -189,7 +189,7 @@ long libos_syscall_mknodat(int dirfd, const char* pathname, mode_t mode, dev_t d if (!(mode & S_IFMT) || S_ISREG(mode)) { mode &= ~S_IFREG; /* FIXME: Gramine assumes that file is at least readable by owner, in particular, see - * unlink() emulation that uses DkStreamOpen(). We change empty mode to readable + * unlink() emulation that uses PalStreamOpen(). We change empty mode to readable * by user here to allow a consequent unlink. Was detected on LTP mknod tests. */ int fd = libos_syscall_openat(dirfd, pathname, O_CREAT | O_EXCL, mode ?: PERM_r________); if (fd < 0) diff --git a/libos/src/sys/shim_poll.c b/libos/src/sys/shim_poll.c index b590099d44..1df1aa492b 100644 --- a/libos/src/sys/shim_poll.c +++ b/libos/src/sys/shim_poll.c @@ -162,7 +162,7 @@ static long _libos_syscall_poll(struct pollfd* fds, nfds_t nfds, uint64_t* timeo bool polled = false; long error = 0; if (pal_cnt) { - error = DkStreamsWaitEvents(pal_cnt, pals, pal_events, ret_events, timeout_us); + error = PalStreamsWaitEvents(pal_cnt, pals, pal_events, ret_events, timeout_us); polled = error == 0; error = pal_to_unix_errno(error); } diff --git a/libos/src/sys/shim_sched.c b/libos/src/sys/shim_sched.c index da9eaad7a5..9cc4d8c1d8 100644 --- a/libos/src/sys/shim_sched.c +++ b/libos/src/sys/shim_sched.c @@ -19,7 +19,7 @@ #include "shim_thread.h" long libos_syscall_sched_yield(void) { - DkThreadYieldExecution(); + PalThreadYieldExecution(); return 0; } @@ -164,7 +164,7 @@ long libos_syscall_sched_setaffinity(pid_t pid, unsigned int cpumask_size, return -ESRCH; } - ret = DkThreadSetCpuAffinity(thread->pal_handle, cpumask_size, user_mask_ptr); + ret = PalThreadSetCpuAffinity(thread->pal_handle, cpumask_size, user_mask_ptr); if (ret < 0) { put_thread(thread); return pal_to_unix_errno(ret); @@ -213,7 +213,7 @@ long libos_syscall_sched_getaffinity(pid_t pid, unsigned int cpumask_size, } memset(user_mask_ptr, 0, cpumask_size); - ret = DkThreadGetCpuAffinity(thread->pal_handle, bitmask_size_in_bytes, user_mask_ptr); + ret = PalThreadGetCpuAffinity(thread->pal_handle, bitmask_size_in_bytes, user_mask_ptr); if (ret < 0) { put_thread(thread); return pal_to_unix_errno(ret); diff --git a/libos/src/sys/shim_sigaction.c b/libos/src/sys/shim_sigaction.c index 00e41d69ab..621c1c66ce 100644 --- a/libos/src/sys/shim_sigaction.c +++ b/libos/src/sys/shim_sigaction.c @@ -318,7 +318,7 @@ static int _wakeup_one_thread(struct libos_thread* thread, void* arg) { if (!__sigismember(&thread->signal_mask, sig)) { thread_wakeup(thread); - ret = DkThreadResume(thread->pal_handle); + ret = PalThreadResume(thread->pal_handle); if (ret < 0) { ret = pal_to_unix_errno(ret); } else { @@ -462,7 +462,7 @@ int do_kill_thread(IDTYPE sender, IDTYPE tgid, IDTYPE tid, int sig) { } if (thread != get_cur_thread()) { thread_wakeup(thread); - ret = pal_to_unix_errno(DkThreadResume(thread->pal_handle)); + ret = pal_to_unix_errno(PalThreadResume(thread->pal_handle)); } put_thread(thread); diff --git a/libos/src/sys/shim_sleep.c b/libos/src/sys/shim_sleep.c index 0b61546dd7..32a6a03ad0 100644 --- a/libos/src/sys/shim_sleep.c +++ b/libos/src/sys/shim_sleep.c @@ -100,10 +100,10 @@ long libos_syscall_clock_nanosleep(clockid_t clock_id, int flags, struct __kerne uint64_t timeout_us = timespec_to_us(req); if (flags & TIMER_ABSTIME) { uint64_t current_time = 0; - ret = DkSystemTimeQuery(¤t_time); + ret = PalSystemTimeQuery(¤t_time); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error("clock_nanosleep: DkSystemTimeQuery failed with: %d", ret); + log_error("clock_nanosleep: PalSystemTimeQuery failed with: %d", ret); die_or_inf_loop(); } if (timeout_us <= current_time) { diff --git a/libos/src/sys/shim_socket.c b/libos/src/sys/shim_socket.c index 92edb187c6..c788ae658f 100644 --- a/libos/src/sys/shim_socket.c +++ b/libos/src/sys/shim_socket.c @@ -173,7 +173,7 @@ long libos_syscall_socketpair(int family, int type, int protocol, int* sv) { .sun_family = AF_UNIX, }; /* We leave first byte as 0 - abstract UNIX socket. */ - ret = DkRandomBitsRead(&addr.sun_path[1], sizeof(addr.sun_path) - 1); + ret = PalRandomBitsRead(&addr.sun_path[1], sizeof(addr.sun_path) - 1); if (ret < 0) { ret = -EAGAIN; goto out; @@ -1068,7 +1068,7 @@ long libos_syscall_shutdown(int fd, int how) { goto out; } - ret = DkStreamDelete(sock->pal_handle, mode); + ret = PalStreamDelete(sock->pal_handle, mode); if (ret < 0) { ret = pal_to_unix_errno(ret); goto out; @@ -1239,7 +1239,7 @@ static int set_socket_option(struct libos_handle* handle, int optname, char* opt } PAL_STREAM_ATTR attr; - int ret = DkStreamAttributesQueryByHandle(pal_handle, &attr); + int ret = PalStreamAttributesQueryByHandle(pal_handle, &attr); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -1293,7 +1293,7 @@ static int set_socket_option(struct libos_handle* handle, int optname, char* opt break; } - ret = DkStreamAttributesSetByHandle(pal_handle, &attr); + ret = PalStreamAttributesSetByHandle(pal_handle, &attr); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -1412,7 +1412,7 @@ static int get_socket_option(struct libos_handle* handle, int optname, char* opt } PAL_STREAM_ATTR attr; - int ret = DkStreamAttributesQueryByHandle(pal_handle, &attr); + int ret = PalStreamAttributesQueryByHandle(pal_handle, &attr); if (ret < 0) { return pal_to_unix_errno(ret); } diff --git a/libos/src/sys/shim_time.c b/libos/src/sys/shim_time.c index 1f59fc37e8..911c353186 100644 --- a/libos/src/sys/shim_time.c +++ b/libos/src/sys/shim_time.c @@ -22,7 +22,7 @@ long libos_syscall_gettimeofday(struct __kernel_timeval* tv, struct __kernel_tim return -EFAULT; uint64_t time = 0; - int ret = DkSystemTimeQuery(&time); + int ret = PalSystemTimeQuery(&time); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -37,7 +37,7 @@ long libos_syscall_time(time_t* tloc) { return -EFAULT; uint64_t time = 0; - int ret = DkSystemTimeQuery(&time); + int ret = PalSystemTimeQuery(&time); if (ret < 0) { return pal_to_unix_errno(ret); } @@ -69,7 +69,7 @@ long libos_syscall_clock_gettime(clockid_t which_clock, struct timespec* tp) { } uint64_t time = 0; - int ret = DkSystemTimeQuery(&time); + int ret = PalSystemTimeQuery(&time); if (ret < 0) { return pal_to_unix_errno(ret); } diff --git a/libos/src/utils/log.c b/libos/src/utils/log.c index f60eaf6b9a..3bb7aa3bfa 100644 --- a/libos/src/utils/log.c +++ b/libos/src/utils/log.c @@ -77,7 +77,7 @@ void log_setprefix(libos_tcb_t* tcb) { static int buf_write_all(const char* str, size_t size, void* arg) { __UNUSED(arg); - DkDebugLog(str, size); + PalDebugLog(str, size); return 0; } diff --git a/pal/include/host/linux-common/syscall.h b/pal/include/host/linux-common/syscall.h index 27ccac7894..95f9489253 100644 --- a/pal/include/host/linux-common/syscall.h +++ b/pal/include/host/linux-common/syscall.h @@ -11,7 +11,7 @@ long vfork(void) __attribute__((returns_twice)); void gramine_raw_syscalls_code_begin(void); void gramine_raw_syscalls_code_end(void); -noreturn void _DkThreadExit_asm_stub(uint32_t* thread_stack_spinlock, int* clear_child_tid); +noreturn void _PalThreadExit_asm_stub(uint32_t* thread_stack_spinlock, int* clear_child_tid); #define _extend(x) ((unsigned long)(x)) diff --git a/pal/include/pal/pal.h b/pal/include/pal/pal.h index ee15853682..736a30a2b9 100644 --- a/pal/include/pal/pal.h +++ b/pal/include/pal/pal.h @@ -142,7 +142,7 @@ struct pal_public_state { /* We cannot mark this as returning a pointer to `const` object, because LibOS can * change `pal_public_state.topo_info` during checkpoint restore in the child */ -struct pal_public_state* DkGetPalPublicState(void); +struct pal_public_state* PalGetPalPublicState(void); /* * MEMORY ALLOCATION @@ -178,8 +178,8 @@ typedef uint32_t pal_prot_flags_t; /* bitfield */ * differ only in the `NULL` case). * */ -int DkVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_type, - pal_prot_flags_t prot); +int PalVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_type, + pal_prot_flags_t prot); /*! * \brief Deallocate a previously allocated memory mapping. @@ -189,18 +189,18 @@ int DkVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_t * * Both `addr` and `size` must be non-zero and aligned at the allocation alignment. */ -int DkVirtualMemoryFree(void* addr, size_t size); +int PalVirtualMemoryFree(void* addr, size_t size); /*! * \brief Modify the permissions of a previously allocated memory mapping. * * \param addr The address. * \param size The size. - * \param prot See #DkVirtualMemoryAlloc. + * \param prot See #PalVirtualMemoryAlloc. * * Both `addr` and `size` must be non-zero and aligned at the allocation alignment. */ -int DkVirtualMemoryProtect(void* addr, size_t size, pal_prot_flags_t prot); +int PalVirtualMemoryProtect(void* addr, size_t size, pal_prot_flags_t prot); /* * PROCESS CREATION @@ -217,14 +217,14 @@ int DkVirtualMemoryProtect(void* addr, size_t size, pal_prot_flags_t prot); * * TODO: `args` is only used by PAL regression tests, and should be removed at some point. */ -int DkProcessCreate(const char** args, PAL_HANDLE* handle); +int PalProcessCreate(const char** args, PAL_HANDLE* handle); /*! * \brief Terminate all threads in the process immediately. * * \param exit_code The exit value returned to the host. */ -noreturn void DkProcessExit(int exit_code); +noreturn void PalProcessExit(int exit_code); /* * STREAMS @@ -293,8 +293,8 @@ typedef uint32_t pal_stream_options_t; /* bitfield */ * processes. The server side of a pipe can accept any number of connections. If `pipe:` is given * as the URI (i.e., without a name), it will open an anonymous bidirectional pipe. */ -int DkStreamOpen(const char* uri, enum pal_access access, pal_share_flags_t share_flags, - enum pal_create_mode create, pal_stream_options_t options, PAL_HANDLE* handle); +int PalStreamOpen(const char* uri, enum pal_access access, pal_share_flags_t share_flags, + enum pal_create_mode create, pal_stream_options_t options, PAL_HANDLE* handle); /*! * \brief Block until a new connection is accepted and return the PAL handle for the connection. @@ -305,7 +305,7 @@ int DkStreamOpen(const char* uri, enum pal_access access, pal_share_flags_t shar * * This API is only available for handles that are opened with `pipe.srv:...`. */ -int DkStreamWaitForClient(PAL_HANDLE handle, PAL_HANDLE* client, pal_stream_options_t options); +int PalStreamWaitForClient(PAL_HANDLE handle, PAL_HANDLE* client, pal_stream_options_t options); /*! * \brief Read data from an open stream. @@ -322,11 +322,11 @@ int DkStreamWaitForClient(PAL_HANDLE handle, PAL_HANDLE* client, pal_stream_opti * * \returns 0 on success, negative error code on failure. * - * If \p handle is a directory, DkStreamRead fills the buffer with the null-terminated names of the + * If \p handle is a directory, PalStreamRead fills the buffer with the null-terminated names of the * directory entries. */ -int DkStreamRead(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer, char* source, - size_t size); +int PalStreamRead(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer, char* source, + size_t size); /*! * \brief Write data to an open stream. @@ -341,8 +341,8 @@ int DkStreamRead(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer * * \returns 0 on success, negative error code on failure. */ -int DkStreamWrite(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer, - const char* dest); +int PalStreamWrite(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer, + const char* dest); enum pal_delete_mode { PAL_DELETE_ALL, /*!< delete the whole resource / shut down both directions */ @@ -355,21 +355,21 @@ enum pal_delete_mode { * * \param access Which side to shut down (see #pal_delete_mode values). */ -int DkStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode); +int PalStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode); /*! * \brief Map a file to a virtual memory address in the current process. * * \param handle Handle to the stream to be mapped. - * \param[in,out] addr_ptr See #DkVirtualMemoryAlloc. - * \param prot See #DkVirtualMemoryAlloc. + * \param[in,out] addr_ptr See #PalVirtualMemoryAlloc. + * \param prot See #PalVirtualMemoryAlloc. * \param offset Offset in the stream to be mapped. Must be properly aligned. * \param size Size of the requested mapping. Must be non-zero and properly aligned. * * \returns 0 on success, negative error code on failure. */ -int DkStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint64_t offset, - size_t size); +int PalStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint64_t offset, + size_t size); /*! * \brief Unmap virtual memory that is backed by a file stream. @@ -378,21 +378,21 @@ int DkStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint6 * * \returns 0 on success, negative error code on failure. */ -int DkStreamUnmap(void* addr, size_t size); +int PalStreamUnmap(void* addr, size_t size); /*! * \brief Set the length of the file referenced by handle to `length`. * * \returns 0 on success, negative error code on failure. */ -int DkStreamSetLength(PAL_HANDLE handle, uint64_t length); +int PalStreamSetLength(PAL_HANDLE handle, uint64_t length); /*! * \brief Flush the buffer of a file stream. * * \returns 0 on success, negative error code on failure. */ -int DkStreamFlush(PAL_HANDLE handle); +int PalStreamFlush(PAL_HANDLE handle); /*! * \brief Send a PAL handle to a process. @@ -402,7 +402,7 @@ int DkStreamFlush(PAL_HANDLE handle); * * \returns 0 on success, negative error code on failure. */ -int DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo); +int PalSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo); /*! * \brief Receive a handle from another process. @@ -413,7 +413,7 @@ int DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo); * * \returns 0 on success, negative error code on failure. */ -int DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo); +int PalReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo); // TODO: this needs to be redesigned, most of these fields are type specific /* stream attribute structure */ @@ -442,14 +442,14 @@ typedef struct _PAL_STREAM_ATTR { * * This API only applies for URIs such as `%file:...`, `dir:...`, and `dev:...`. */ -int DkStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr); +int PalStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr); /*! * \brief Query the attributes of an open stream. * * This API applies to any stream handle. */ -int DkStreamAttributesQueryByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr); +int PalStreamAttributesQueryByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr); /*! * \brief Set the attributes of an open stream. @@ -457,17 +457,17 @@ int DkStreamAttributesQueryByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr); * Calling this function on the same handle concurrently is not allowed (i.e. callers must ensure * mutual exclusion). */ -int DkStreamAttributesSetByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr); +int PalStreamAttributesSetByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr); /*! * \brief Query the name of an open stream. On success `buffer` contains a null-terminated string. */ -int DkStreamGetName(PAL_HANDLE handle, char* buffer, size_t size); +int PalStreamGetName(PAL_HANDLE handle, char* buffer, size_t size); /*! * \brief This API changes the name of an open stream. */ -int DkStreamChangeName(PAL_HANDLE handle, const char* uri); +int PalStreamChangeName(PAL_HANDLE handle, const char* uri); struct pal_socket_addr { enum pal_socket_domain domain; @@ -502,8 +502,8 @@ struct pal_iovec { * * \returns 0 on success, negative error code on failure. */ -int DkSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, - pal_stream_options_t options, PAL_HANDLE* out_handle); +int PalSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, + pal_stream_options_t options, PAL_HANDLE* out_handle); /*! * \brief Bind a socket to a local address. @@ -516,7 +516,7 @@ int DkSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, * * Can be called only once per socket. */ -int DkSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr); +int PalSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr); /*! * \biref Turn a socket into a listening one. @@ -528,7 +528,7 @@ int DkSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr); * * Can be called multiple times, to change \p backlog. */ -int DkSocketListen(PAL_HANDLE handle, unsigned int backlog); +int PalSocketListen(PAL_HANDLE handle, unsigned int backlog); /*! * \brief Accept a new connection on a socket. @@ -543,8 +543,8 @@ int DkSocketListen(PAL_HANDLE handle, unsigned int backlog); * * This function can be safely called concurrently. */ -int DkSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, - struct pal_socket_addr* out_client_addr); +int PalSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, + struct pal_socket_addr* out_client_addr); /*! * \brief Connect a socket to a remote address. @@ -558,8 +558,8 @@ int DkSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* * * Can also be used to disconnect the socket, if #PAL_DISCONNECT is passed in \p addr. */ -int DkSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, - struct pal_socket_addr* out_local_addr); +int PalSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, + struct pal_socket_addr* out_local_addr); /*! * \brief Send data. @@ -572,10 +572,10 @@ int DkSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, * * \returns 0 on success, negative error code on failure. * - * Data is sent atomically, i.e. data from two `DkSocketSend` calls will not be interleaved. + * Data is sent atomically, i.e. data from two `PalSocketSend` calls will not be interleaved. */ -int DkSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, - struct pal_socket_addr* addr); +int PalSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, + struct pal_socket_addr* addr); /*! * \brief Receive data. @@ -592,10 +592,10 @@ int DkSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_ * * \returns 0 on success, negative error code on failure. * - * Data is received atomically, i.e. data from two `DkSocketRecv` calls will not be interleaved. + * Data is received atomically, i.e. data from two `PalSocketRecv` calls will not be interleaved. */ -int DkSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, - struct pal_socket_addr* addr, bool force_nonblocking); +int PalSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, + struct pal_socket_addr* addr, bool force_nonblocking); /* * Thread creation @@ -608,12 +608,12 @@ int DkSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_ * \param param Pointer argument that is passed to the new thread. * \param[out] handle On success contains the thread handle. */ -int DkThreadCreate(int (*callback)(void*), void* param, PAL_HANDLE* handle); +int PalThreadCreate(int (*callback)(void*), void* param, PAL_HANDLE* handle); /*! * \brief Yield the current thread such that the host scheduler can reschedule it. */ -void DkThreadYieldExecution(void); +void PalThreadYieldExecution(void); /*! * \brief Terminate the current thread. @@ -622,12 +622,12 @@ void DkThreadYieldExecution(void); * turn notifies the parent thread if any); if `clear_child_tid` is NULL, * then PAL doesn't do the clearing. */ -noreturn void DkThreadExit(int* clear_child_tid); +noreturn void PalThreadExit(int* clear_child_tid); /*! * \brief Resume a thread. */ -int DkThreadResume(PAL_HANDLE thread); +int PalThreadResume(PAL_HANDLE thread); /*! * \brief Set the CPU affinity of a thread. @@ -641,7 +641,7 @@ int DkThreadResume(PAL_HANDLE thread); * All bit positions exceeding the count of host CPUs are ignored. Returns an error if no CPUs were * selected. */ -int DkThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask); +int PalThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask); /*! * \brief Get the CPU affinity of a thread. @@ -656,7 +656,7 @@ int DkThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long * must be able to fit all the processors in the host and must be aligned by sizeof(long). For * example, if the host supports 4 CPUs, \a cpumask_size should be 8 bytes. */ -int DkThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask); +int PalThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask); /* * Exception Handling @@ -695,7 +695,7 @@ typedef void (*pal_event_handler_t)(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* * * \param event One of #pal_event values. */ -void DkSetExceptionHandler(pal_event_handler_t handler, enum pal_event event); +void PalSetExceptionHandler(pal_event_handler_t handler, enum pal_event event); /* * Synchronization @@ -710,26 +710,26 @@ void DkSetExceptionHandler(pal_event_handler_t handler, enum pal_event event); * it. * * Creates a handle to an event that resembles WinAPI synchronization events. A thread can set - * (signal) the event using #DkEventSet, clear (unset) it using #DkEventClear or wait until - * the event becomes set (signaled) using #DkEventWait. + * (signal) the event using #PalEventSet, clear (unset) it using #PalEventClear or wait until + * the event becomes set (signaled) using #PalEventWait. */ -int DkEventCreate(PAL_HANDLE* handle, bool init_signaled, bool auto_clear); +int PalEventCreate(PAL_HANDLE* handle, bool init_signaled, bool auto_clear); /*! * \brief Set (signal) an event. * * If the event is already set, does nothing. * - * This function has release semantics and synchronizes with #DkEventWait. + * This function has release semantics and synchronizes with #PalEventWait. */ -void DkEventSet(PAL_HANDLE handle); +void PalEventSet(PAL_HANDLE handle); /*! * \brief Clear (unset) an event. * * If the event is not set, does nothing. */ -void DkEventClear(PAL_HANDLE handle); +void PalEventClear(PAL_HANDLE handle); /*! * \brief Wait for an event handle. @@ -747,9 +747,9 @@ void DkEventClear(PAL_HANDLE handle); * After returning (both successful and not), \p timeout_us will contain the remaining time (time * that need to pass before we hit original \p timeout_us). * - * This function has acquire semantics and synchronizes with #DkEventSet. + * This function has acquire semantics and synchronizes with #PalEventSet. */ -int DkEventWait(PAL_HANDLE handle, uint64_t* timeout_us); +int PalEventWait(PAL_HANDLE handle, uint64_t* timeout_us); typedef uint32_t pal_wait_flags_t; /* bitfield */ #define PAL_WAIT_READ 1 @@ -769,13 +769,13 @@ typedef uint32_t pal_wait_flags_t; /* bitfield */ * * \p timeout_us contains remaining timeout both on successful and failed calls. */ -int DkStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, - pal_wait_flags_t* ret_events, uint64_t* timeout_us); +int PalStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, + pal_wait_flags_t* ret_events, uint64_t* timeout_us); /*! * \brief Close (deallocate) a PAL handle. */ -void DkObjectClose(PAL_HANDLE object_handle); +void PalObjectClose(PAL_HANDLE object_handle); /* * MISC @@ -789,14 +789,14 @@ void DkObjectClose(PAL_HANDLE object_handle); * * \returns 0 on success, negative error code on failure. */ -int DkDebugLog(const void* buffer, size_t size); +int PalDebugLog(const void* buffer, size_t size); /*! * \brief Get the current time. * * \param[out] time On success holds the current time in microseconds. */ -int DkSystemTimeQuery(uint64_t* time); +int PalSystemTimeQuery(uint64_t* time); /*! * \brief Cryptographically secure RNG. @@ -806,7 +806,7 @@ int DkSystemTimeQuery(uint64_t* time); * * \returns 0 on success, negative on failure. */ -int DkRandomBitsRead(void* buffer, size_t size); +int PalRandomBitsRead(void* buffer, size_t size); enum pal_segment_reg { PAL_SEGMENT_FS, @@ -821,7 +821,7 @@ enum pal_segment_reg { * * \returns 0 on success, negative error value on failure. */ -int DkSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr); +int PalSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr); /*! * \brief Set segment register. @@ -831,12 +831,12 @@ int DkSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr); * * \returns 0 on success, negative error value on failure. */ -int DkSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr); +int PalSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr); /*! * \brief Return the amount of currently available memory for LibOS/application usage. */ -size_t DkMemoryAvailableQuota(void); +size_t PalMemoryAvailableQuota(void); /*! * \brief Obtain the attestation report (local) with `user_report_data` embedded into it. @@ -868,9 +868,9 @@ size_t DkMemoryAvailableQuota(void); * The caller may specify `*user_report_data_size`, `*target_info_size`, and `*report_size` as 0 * and other fields as NULL to get PAL-enforced sizes of these three structs. */ -int DkAttestationReport(const void* user_report_data, size_t* user_report_data_size, - void* target_info, size_t* target_info_size, void* report, - size_t* report_size); +int PalAttestationReport(const void* user_report_data, size_t* user_report_data_size, + void* target_info, size_t* target_info_size, void* report, + size_t* report_size); /*! * \brief Obtain the attestation quote with `user_report_data` embedded into it. @@ -887,8 +887,8 @@ int DkAttestationReport(const void* user_report_data, size_t* user_report_data_s * Currently works only for Linux-SGX PAL, where `user_report_data` is a blob of exactly 64B * and `quote` is an SGX quote obtained from Quoting Enclave via AESM service. */ -int DkAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, - size_t* quote_size); +int PalAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, + size_t* quote_size); /*! * \brief Get special key (specific to PAL host). * @@ -903,7 +903,7 @@ int DkAttestationQuote(const void* user_report_data, size_t user_report_data_siz * If a given key is not supported by the current PAL host, the function will return * -PAL_ERROR_NOTIMPLEMENTED. */ -int DkGetSpecialKey(const char* name, void* key, size_t* key_size); +int PalGetSpecialKey(const char* name, void* key, size_t* key_size); #ifdef __GNUC__ #define symbol_version_default(real, name, version) \ @@ -918,14 +918,14 @@ int DkGetSpecialKey(const char* name, void* key, size_t* key_size); * * \param[out] values The array of the results. */ -int DkCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[CPUID_WORD_NUM]); +int PalCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[CPUID_WORD_NUM]); #endif -void DkDebugMapAdd(const char* uri, void* start_addr); -void DkDebugMapRemove(void* start_addr); +void PalDebugMapAdd(const char* uri, void* start_addr); +void PalDebugMapRemove(void* start_addr); /* Describe the code under given address (see `describe_location()` in `callbacks.h`). Without * DEBUG, falls back to raw value ("0x1234"). */ -void DkDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size); +void PalDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size); #undef INSIDE_PAL_H diff --git a/pal/include/pal_internal.h b/pal/include/pal_internal.h index 193f7d923b..53e2116148 100644 --- a/pal/include/pal_internal.h +++ b/pal/include/pal_internal.h @@ -42,16 +42,16 @@ struct handle_ops { /* 'getrealpath' return the real path that represent the handle */ const char* (*getrealpath)(PAL_HANDLE handle); - /* 'getname' is used by DkStreamGetName. It's different from 'getrealpath' */ + /* 'getname' is used by PalStreamGetName. It's different from 'getrealpath' */ int (*getname)(PAL_HANDLE handle, char* buffer, size_t count); - /* 'open' is used by DkStreamOpen. 'handle' is a preallocated handle, 'type' will be a + /* 'open' is used by PalStreamOpen. 'handle' is a preallocated handle, 'type' will be a * normalized prefix, 'uri' is the remaining string of uri. access, share, create, and options - * follow the same flags defined for DkStreamOpen in pal.h. */ + * follow the same flags defined for PalStreamOpen in pal.h. */ int (*open)(PAL_HANDLE* handle, const char* type, const char* uri, enum pal_access access, pal_share_flags_t share, enum pal_create_mode create, pal_stream_options_t options); - /* 'read' and 'write' is used by DkStreamRead and DkStreamWrite, so they have exactly same + /* 'read' and 'write' is used by PalStreamRead and PalStreamWrite, so they have exactly same * prototype as them. */ int64_t (*read)(PAL_HANDLE handle, uint64_t offset, uint64_t count, void* buffer); int64_t (*write)(PAL_HANDLE handle, uint64_t offset, uint64_t count, const void* buffer); @@ -63,7 +63,7 @@ struct handle_ops { int64_t (*writebyaddr)(PAL_HANDLE handle, uint64_t offset, uint64_t count, const void* buffer, const char* addr, size_t addrlen); - /* 'close' and 'delete' is used by DkObjectClose and DkStreamDelete, 'close' will close the + /* 'close' and 'delete' is used by PalObjectClose and PalStreamDelete, 'close' will close the * stream, while 'delete' actually destroy the stream, such as deleting a file or shutting * down a socket */ int (*close)(PAL_HANDLE handle); @@ -79,23 +79,23 @@ struct handle_ops { int (*map)(PAL_HANDLE handle, void** address, pal_prot_flags_t prot, uint64_t offset, uint64_t size); - /* 'setlength' is used by DkStreamFlush. It truncate the stream to certain size. */ + /* 'setlength' is used by PalStreamFlush. It truncate the stream to certain size. */ int64_t (*setlength)(PAL_HANDLE handle, uint64_t length); - /* 'flush' is used by DkStreamFlush. It syncs the stream to the device */ + /* 'flush' is used by PalStreamFlush. It syncs the stream to the device */ int (*flush)(PAL_HANDLE handle); - /* 'waitforclient' is used by DkStreamWaitforClient. It accepts an connection */ + /* 'waitforclient' is used by PalStreamWaitforClient. It accepts an connection */ int (*waitforclient)(PAL_HANDLE server, PAL_HANDLE* client, pal_stream_options_t options); - /* 'attrquery' is used by DkStreamAttributesQuery. It queries the attributes of a stream */ + /* 'attrquery' is used by PalStreamAttributesQuery. It queries the attributes of a stream */ int (*attrquery)(const char* type, const char* uri, PAL_STREAM_ATTR* attr); - /* 'attrquerybyhdl' is used by DkStreamAttributesQueryByHandle. It queries the attributes of + /* 'attrquerybyhdl' is used by PalStreamAttributesQueryByHandle. It queries the attributes of * a stream handle */ int (*attrquerybyhdl)(PAL_HANDLE handle, PAL_STREAM_ATTR* attr); - /* 'attrsetbyhdl' is used by DkStreamAttributesSetByHandle. It queries the attributes of + /* 'attrsetbyhdl' is used by PalStreamAttributesSetByHandle. It queries the attributes of * a stream handle */ int (*attrsetbyhdl)(PAL_HANDLE handle, PAL_STREAM_ATTR* attr); @@ -140,9 +140,9 @@ struct socket_ops { /* * failure notify. The rountine is called whenever a PAL call return error code. As the current - * design of PAL does not return error code directly, we rely on DkAsynchronousEventUpcall to handle - * PAL call error. If the user does not set up a upcall, the error code will be ignored. Ignoring - * PAL error code can be a possible optimization for LibOS. + * design of PAL does not return error code directly, we rely on PalAsynchronousEventUpcall to + * handle PAL call error. If the user does not set up a upcall, the error code will be ignored. + * Ignoring PAL error code can be a possible optimization for LibOS. */ void notify_failure(unsigned long error); @@ -172,108 +172,108 @@ noreturn void pal_main(uint64_t instance_id, PAL_HANDLE parent_process, PAL_HAND /* For initialization */ -void _DkGetAvailableUserAddressRange(void** out_start, void** out_end); -bool _DkCheckMemoryMappable(const void* addr, size_t size); -unsigned long _DkMemoryQuota(void); -unsigned long _DkMemoryAvailableQuota(void); +void _PalGetAvailableUserAddressRange(void** out_start, void** out_end); +bool _PalCheckMemoryMappable(const void* addr, size_t size); +unsigned long _PalMemoryQuota(void); +unsigned long _PalMemoryAvailableQuota(void); // Returns 0 on success, negative PAL code on failure -int _DkGetCPUInfo(struct pal_cpu_info* info); +int _PalGetCPUInfo(struct pal_cpu_info* info); /* Internal DK calls, in case any of the internal routines needs to use them */ -/* DkStream calls */ -int _DkStreamOpen(PAL_HANDLE* handle, const char* uri, enum pal_access access, - pal_share_flags_t share, enum pal_create_mode create, - pal_stream_options_t options); -int _DkStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode); -int64_t _DkStreamRead(PAL_HANDLE handle, uint64_t offset, uint64_t count, void* buf, char* addr, - int addrlen); -int64_t _DkStreamWrite(PAL_HANDLE handle, uint64_t offset, uint64_t count, const void* buf, - const char* addr, int addrlen); -int _DkStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr); -int _DkStreamAttributesQueryByHandle(PAL_HANDLE hdl, PAL_STREAM_ATTR* attr); -int _DkStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint64_t offset, - uint64_t size); -int _DkStreamUnmap(void* addr, uint64_t size); -int64_t _DkStreamSetLength(PAL_HANDLE handle, uint64_t length); -int _DkStreamFlush(PAL_HANDLE handle); -int _DkStreamGetName(PAL_HANDLE handle, char* buf, size_t size); -const char* _DkStreamRealpath(PAL_HANDLE hdl); -int _DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo); -int _DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo); - -int _DkSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, - pal_stream_options_t options, PAL_HANDLE* out_handle); -int _DkSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr); -int _DkSocketListen(PAL_HANDLE handle, unsigned int backlog); -int _DkSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, - struct pal_socket_addr* out_client_addr); -int _DkSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, - struct pal_socket_addr* out_local_addr); -int _DkSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, - struct pal_socket_addr* addr); -int _DkSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, - struct pal_socket_addr* addr, bool force_nonblocking); - -/* DkProcess and DkThread calls */ -int _DkThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param); -noreturn void _DkThreadExit(int* clear_child_tid); -void _DkThreadYieldExecution(void); -int _DkThreadResume(PAL_HANDLE thread_handle); -int _DkProcessCreate(PAL_HANDLE* handle, const char** args); -noreturn void _DkProcessExit(int exit_code); -int _DkThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask); -int _DkThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask); - -/* DkEvent calls */ -int _DkEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear); -void _DkEventSet(PAL_HANDLE handle); -void _DkEventClear(PAL_HANDLE handle); -int _DkEventWait(PAL_HANDLE handle, uint64_t* timeout_us); - -/* DkVirtualMemory calls */ -int _DkVirtualMemoryAlloc(void** addr_ptr, uint64_t size, pal_alloc_flags_t alloc_type, - pal_prot_flags_t prot); -int _DkVirtualMemoryFree(void* addr, uint64_t size); -int _DkVirtualMemoryProtect(void* addr, uint64_t size, pal_prot_flags_t prot); - -/* DkObject calls */ -int _DkObjectClose(PAL_HANDLE object_handle); -int _DkStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, - pal_wait_flags_t* ret_events, uint64_t* timeout_us); - -/* DkException calls & structures */ -pal_event_handler_t _DkGetExceptionHandler(enum pal_event event); +/* PalStream calls */ +int _PalStreamOpen(PAL_HANDLE* handle, const char* uri, enum pal_access access, + pal_share_flags_t share, enum pal_create_mode create, + pal_stream_options_t options); +int _PalStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode); +int64_t _PalStreamRead(PAL_HANDLE handle, uint64_t offset, uint64_t count, void* buf, char* addr, + int addrlen); +int64_t _PalStreamWrite(PAL_HANDLE handle, uint64_t offset, uint64_t count, const void* buf, + const char* addr, int addrlen); +int _PalStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr); +int _PalStreamAttributesQueryByHandle(PAL_HANDLE hdl, PAL_STREAM_ATTR* attr); +int _PalStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint64_t offset, + uint64_t size); +int _PalStreamUnmap(void* addr, uint64_t size); +int64_t _PalStreamSetLength(PAL_HANDLE handle, uint64_t length); +int _PalStreamFlush(PAL_HANDLE handle); +int _PalStreamGetName(PAL_HANDLE handle, char* buf, size_t size); +const char* _PalStreamRealpath(PAL_HANDLE hdl); +int _PalSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo); +int _PalReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo); + +int _PalSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, + pal_stream_options_t options, PAL_HANDLE* out_handle); +int _PalSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr); +int _PalSocketListen(PAL_HANDLE handle, unsigned int backlog); +int _PalSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, + struct pal_socket_addr* out_client_addr); +int _PalSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, + struct pal_socket_addr* out_local_addr); +int _PalSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, + struct pal_socket_addr* addr); +int _PalSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, + struct pal_socket_addr* addr, bool force_nonblocking); + +/* PalProcess and PalThread calls */ +int _PalThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param); +noreturn void _PalThreadExit(int* clear_child_tid); +void _PalThreadYieldExecution(void); +int _PalThreadResume(PAL_HANDLE thread_handle); +int _PalProcessCreate(PAL_HANDLE* handle, const char** args); +noreturn void _PalProcessExit(int exit_code); +int _PalThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask); +int _PalThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask); + +/* PalEvent calls */ +int _PalEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear); +void _PalEventSet(PAL_HANDLE handle); +void _PalEventClear(PAL_HANDLE handle); +int _PalEventWait(PAL_HANDLE handle, uint64_t* timeout_us); + +/* PalVirtualMemory calls */ +int _PalVirtualMemoryAlloc(void** addr_ptr, uint64_t size, pal_alloc_flags_t alloc_type, + pal_prot_flags_t prot); +int _PalVirtualMemoryFree(void* addr, uint64_t size); +int _PalVirtualMemoryProtect(void* addr, uint64_t size, pal_prot_flags_t prot); + +/* PalObject calls */ +int _PalObjectClose(PAL_HANDLE object_handle); +int _PalStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, + pal_wait_flags_t* ret_events, uint64_t* timeout_us); + +/* PalException calls & structures */ +pal_event_handler_t _PalGetExceptionHandler(enum pal_event event); /* other DK calls */ -int _DkSystemTimeQuery(uint64_t* out_usec); +int _PalSystemTimeQuery(uint64_t* out_usec); /* * Cryptographically secure random. * 0 on success, negative on failure. */ -int _DkRandomBitsRead(void* buffer, size_t size); - -double _DkGetBogomips(void); -int _DkSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr); -int _DkSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr); -int _DkCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]); -int _DkAttestationReport(const void* user_report_data, size_t* user_report_data_size, - void* target_info, size_t* target_info_size, void* report, - size_t* report_size); -int _DkAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, - size_t* quote_size); -int _DkGetSpecialKey(const char* name, void* key, size_t* key_size); +int _PalRandomBitsRead(void* buffer, size_t size); + +double _PalGetBogomips(void); +int _PalSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr); +int _PalSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr); +int _PalCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]); +int _PalAttestationReport(const void* user_report_data, size_t* user_report_data_size, + void* target_info, size_t* target_info_size, void* report, + size_t* report_size); +int _PalAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, + size_t* quote_size); +int _PalGetSpecialKey(const char* name, void* key, size_t* key_size); #define INIT_FAIL(msg, ...) \ do { \ log_error("PAL failed at %s:%d: " msg, __FILE__, __LINE__, ##__VA_ARGS__); \ - _DkProcessExit(1); \ + _PalProcessExit(1); \ } while (0) #define INIT_FAIL_MANIFEST(reason) \ do { \ log_error("PAL failed at parsing the manifest: %s", reason); \ - _DkProcessExit(1); \ + _PalProcessExit(1); \ } while (0) void init_slab_mgr(char* mem_pool, size_t mem_pool_size); @@ -291,8 +291,8 @@ void free(void* mem); #error Unsupported compiler #endif -int _DkInitDebugStream(const char* path); -int _DkDebugLog(const void* buf, size_t size); +int _PalInitDebugStream(const char* path); +int _PalDebugLog(const void* buf, size_t size); // TODO(mkow): We should make it cross-object-inlinable, ideally by enabling LTO, less ideally by // pasting it here and making `inline`, but our current linker scripts prevent both. @@ -306,7 +306,7 @@ const char* pal_event_name(enum pal_event event); #define uthash_fatal(msg) \ do { \ log_error("uthash error: %s", msg); \ - _DkProcessExit(1); \ + _PalProcessExit(1); \ } while (0) #include "uthash.h" diff --git a/pal/include/pal_rtld.h b/pal/include/pal_rtld.h index 4f1b892f7e..9a21f5abaa 100644 --- a/pal/include/pal_rtld.h +++ b/pal/include/pal_rtld.h @@ -46,9 +46,9 @@ struct link_map { }; /* for GDB debugging */ -void _DkDebugMapAdd(const char* name, void* addr); -void _DkDebugMapRemove(void* addr); -int _DkDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size); +void _PalDebugMapAdd(const char* name, void* addr); +void _PalDebugMapRemove(void* addr); +int _PalDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size); /* loading ELF binaries */ int setup_pal_binary(void); diff --git a/pal/regression/AttestationReport.c b/pal/regression/AttestationReport.c index ff973f3ff7..fdaa077e83 100644 --- a/pal/regression/AttestationReport.c +++ b/pal/regression/AttestationReport.c @@ -3,7 +3,7 @@ #include "pal_regression.h" #include "sgx_arch.h" -#define ALLOC_ALIGN_UP(addr) ALIGN_UP_POW2(addr, DkGetPalPublicState()->alloc_align) +#define ALLOC_ALIGN_UP(addr) ALIGN_UP_POW2(addr, PalGetPalPublicState()->alloc_align) char zerobuf[sizeof(sgx_report_t)] = {0}; @@ -13,26 +13,26 @@ int main(int argc, char** argv) { size_t user_report_data_size; size_t target_info_size; size_t report_size; - ret = DkAttestationReport(/*user_report_data=*/NULL, &user_report_data_size, - /*target_info=*/NULL, &target_info_size, - /*report=*/NULL, &report_size); + ret = PalAttestationReport(/*user_report_data=*/NULL, &user_report_data_size, + /*target_info=*/NULL, &target_info_size, + /*report=*/NULL, &report_size); if (ret < 0) { - pal_printf("ERROR: DkAttestationReport() to get sizes of SGX structs failed\n"); + pal_printf("ERROR: PalAttestationReport() to get sizes of SGX structs failed\n"); return -1; } if (user_report_data_size != sizeof(sgx_report_data_t)) { - pal_printf("ERROR: DkAttestationReport() returned incorrect user_report_data size\n"); + pal_printf("ERROR: PalAttestationReport() returned incorrect user_report_data size\n"); return -1; } if (target_info_size != sizeof(sgx_target_info_t)) { - pal_printf("ERROR: DkAttestationReport() returned incorrect target_info size\n"); + pal_printf("ERROR: PalAttestationReport() returned incorrect target_info size\n"); return -1; } if (report_size != sizeof(sgx_report_t)) { - pal_printf("ERROR: DkAttestationReport() returned incorrect report size\n"); + pal_printf("ERROR: PalAttestationReport() returned incorrect report size\n"); return -1; } @@ -40,24 +40,24 @@ int main(int argc, char** argv) { user_report_data_size, target_info_size, report_size); void* user_report_data = NULL; - ret = DkVirtualMemoryAlloc(&user_report_data, ALLOC_ALIGN_UP(user_report_data_size), - PAL_ALLOC_INTERNAL, PAL_PROT_READ | PAL_PROT_WRITE); + ret = PalVirtualMemoryAlloc(&user_report_data, ALLOC_ALIGN_UP(user_report_data_size), + PAL_ALLOC_INTERNAL, PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { pal_printf("ERROR: Cannot allocate memory for user_report_data\n"); return -1; } void* target_info = NULL; - ret = DkVirtualMemoryAlloc(&target_info, ALLOC_ALIGN_UP(target_info_size), - PAL_ALLOC_INTERNAL, PAL_PROT_READ | PAL_PROT_WRITE); + ret = PalVirtualMemoryAlloc(&target_info, ALLOC_ALIGN_UP(target_info_size), + PAL_ALLOC_INTERNAL, PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { pal_printf("ERROR: Cannot allocate memory for target_info\n"); return -1; } void* report = NULL; - ret = DkVirtualMemoryAlloc(&report, ALLOC_ALIGN_UP(report_size), - PAL_ALLOC_INTERNAL, PAL_PROT_READ | PAL_PROT_WRITE); + ret = PalVirtualMemoryAlloc(&report, ALLOC_ALIGN_UP(report_size), + PAL_ALLOC_INTERNAL, PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { pal_printf("ERROR: Cannot allocate memory for report\n"); return -1; @@ -67,17 +67,17 @@ int main(int argc, char** argv) { memset(target_info, 0, target_info_size); memset(report, 0, report_size); - ret = DkAttestationReport(user_report_data, &user_report_data_size, target_info, - &target_info_size, report, &report_size); + ret = PalAttestationReport(user_report_data, &user_report_data_size, target_info, + &target_info_size, report, &report_size); if (ret < 0) { - pal_printf("ERROR: DkAttestationReport() to get SGX report failed\n"); + pal_printf("ERROR: PalAttestationReport() to get SGX report failed\n"); return -1; } sgx_report_t* sgx_report = (sgx_report_t*)report; if (memcmp(&sgx_report->body.report_data.d, user_report_data, sizeof(sgx_report->body.report_data.d))) { - pal_printf("ERROR: DkAttestationReport() returned SGX report with wrong report_data\n"); + pal_printf("ERROR: PalAttestationReport() returned SGX report with wrong report_data\n"); return -1; } @@ -86,21 +86,21 @@ int main(int argc, char** argv) { memcmp(&sgx_report->body.reserved3, &zerobuf, sizeof(sgx_report->body.reserved3)) || memcmp(&sgx_report->body.reserved4, &zerobuf, sizeof(sgx_report->body.reserved4))) { - pal_printf("ERROR: DkAttestationReport() returned SGX report with non-zero reserved " + pal_printf("ERROR: PalAttestationReport() returned SGX report with non-zero reserved " "fields\n"); return -1; } - if (DkVirtualMemoryFree(user_report_data, ALLOC_ALIGN_UP(user_report_data_size)) < 0) { - pal_printf("DkVirtualMemoryFree on `user_report_data` failed\n"); + if (PalVirtualMemoryFree(user_report_data, ALLOC_ALIGN_UP(user_report_data_size)) < 0) { + pal_printf("PalVirtualMemoryFree on `user_report_data` failed\n"); return 1; } - if (DkVirtualMemoryFree(target_info, ALLOC_ALIGN_UP(target_info_size)) < 0) { - pal_printf("DkVirtualMemoryFree on `target_info` failed\n"); + if (PalVirtualMemoryFree(target_info, ALLOC_ALIGN_UP(target_info_size)) < 0) { + pal_printf("PalVirtualMemoryFree on `target_info` failed\n"); return 1; } - if (DkVirtualMemoryFree(report, ALLOC_ALIGN_UP(report_size)) < 0) { - pal_printf("DkVirtualMemoryFree on `report` failed\n"); + if (PalVirtualMemoryFree(report, ALLOC_ALIGN_UP(report_size)) < 0) { + pal_printf("PalVirtualMemoryFree on `report` failed\n"); return 1; } diff --git a/pal/regression/Bootstrap.c b/pal/regression/Bootstrap.c index 64244adcba..f1a01a2eb9 100644 --- a/pal/regression/Bootstrap.c +++ b/pal/regression/Bootstrap.c @@ -13,12 +13,12 @@ int main(int argc, char** argv, char** envp) { } /* parent process */ - const struct pal_public_state* pal_public_state = DkGetPalPublicState(); + const struct pal_public_state* pal_public_state = PalGetPalPublicState(); pal_printf("Parent Process: %p\n", pal_public_state->parent_process); /* test debug stream */ const char* msg = "Written to Debug Stream\n"; - int ret = DkDebugLog((char*)msg, strlen(msg)); + int ret = PalDebugLog((char*)msg, strlen(msg)); if (ret < 0) { pal_printf("Failed to write the debug message.\n"); return 1; diff --git a/pal/regression/Directory.c b/pal/regression/Directory.c index 86dc348864..45f393b93e 100644 --- a/pal/regression/Directory.c +++ b/pal/regression/Directory.c @@ -8,46 +8,46 @@ int main(int argc, char** argv, char** envp) { /* test regular directory opening */ PAL_HANDLE dir1 = NULL; - int ret = DkStreamOpen("dir:dir_exist.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, - PAL_CREATE_NEVER, /*options=*/0, &dir1); + int ret = PalStreamOpen("dir:dir_exist.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, + PAL_CREATE_NEVER, /*options=*/0, &dir1); if (ret >= 0 && dir1) { pal_printf("Directory Open Test 1 OK\n"); PAL_STREAM_ATTR attr1; - ret = DkStreamAttributesQueryByHandle(dir1, &attr1); + ret = PalStreamAttributesQueryByHandle(dir1, &attr1); if (ret >= 0) { pal_printf("Query by Handle: type = %d\n", attr1.handle_type); } size_t bytes = sizeof(buffer); - ret = DkStreamRead(dir1, 0, &bytes, buffer, NULL, 0); + ret = PalStreamRead(dir1, 0, &bytes, buffer, NULL, 0); if (ret >= 0 && bytes) { for (char* c = buffer; c < buffer + bytes; c += strlen(c) + 1) if (strlen(c)) pal_printf("Read Directory: %s\n", c); } - DkObjectClose(dir1); + PalObjectClose(dir1); } PAL_HANDLE dir2 = NULL; - ret = DkStreamOpen("dir:./dir_exist.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, - PAL_CREATE_NEVER, /*options=*/0, &dir2); + ret = PalStreamOpen("dir:./dir_exist.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, + PAL_CREATE_NEVER, /*options=*/0, &dir2); if (ret >= 0 && dir2) { pal_printf("Directory Open Test 2 OK\n"); - DkObjectClose(dir2); + PalObjectClose(dir2); } PAL_HANDLE dir3 = NULL; - ret = DkStreamOpen("dir:../regression/dir_exist.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, - PAL_CREATE_NEVER, /*options=*/0, &dir3); + ret = PalStreamOpen("dir:../regression/dir_exist.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, + PAL_CREATE_NEVER, /*options=*/0, &dir3); if (ret >= 0 && dir3) { pal_printf("Directory Open Test 3 OK\n"); - DkObjectClose(dir3); + PalObjectClose(dir3); } PAL_STREAM_ATTR attr2; - ret = DkStreamAttributesQuery("dir:dir_exist.tmp", &attr2); + ret = PalStreamAttributesQuery("dir:dir_exist.tmp", &attr2); if (ret >= 0) { pal_printf("Query: type = %d\n", attr2.handle_type); } @@ -55,42 +55,43 @@ int main(int argc, char** argv, char** envp) { /* test regular directory creation */ PAL_HANDLE dir4 = NULL; - ret = DkStreamOpen("dir:dir_nonexist.tmp", PAL_ACCESS_RDONLY, - PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_X, - PAL_CREATE_ALWAYS, /*options=*/0, &dir4); + ret = PalStreamOpen("dir:dir_nonexist.tmp", PAL_ACCESS_RDONLY, + PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_X, + PAL_CREATE_ALWAYS, /*options=*/0, &dir4); if (ret >= 0 && dir4) { pal_printf("Directory Creation Test 1 OK\n"); - DkObjectClose(dir4); + PalObjectClose(dir4); } PAL_HANDLE dir5 = NULL; - ret = DkStreamOpen("dir:dir_nonexist.tmp", PAL_ACCESS_RDONLY, - PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_X, - PAL_CREATE_ALWAYS, /*options=*/0, &dir5); + ret = PalStreamOpen("dir:dir_nonexist.tmp", PAL_ACCESS_RDONLY, + PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_X, + PAL_CREATE_ALWAYS, /*options=*/0, &dir5); if (ret >= 0) { - DkObjectClose(dir5); + PalObjectClose(dir5); } else { pal_printf("Directory Creation Test 2 OK\n"); } PAL_HANDLE dir6 = NULL; - ret = DkStreamOpen("dir:dir_nonexist.tmp", PAL_ACCESS_RDWR, - PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W, PAL_CREATE_TRY, /*options=*/0, &dir6); + ret = PalStreamOpen("dir:dir_nonexist.tmp", PAL_ACCESS_RDWR, + PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W, PAL_CREATE_TRY, /*options=*/0, + &dir6); if (ret >= 0 && dir6) { pal_printf("Directory Creation Test 3 OK\n"); - DkObjectClose(dir6); + PalObjectClose(dir6); } PAL_HANDLE dir7 = NULL; - ret = DkStreamOpen("dir:dir_delete.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, - PAL_CREATE_NEVER, /*options=*/0, &dir7); + ret = PalStreamOpen("dir:dir_delete.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, + PAL_CREATE_NEVER, /*options=*/0, &dir7); if (ret >= 0 && dir7) { - ret = DkStreamDelete(dir7, PAL_DELETE_ALL); + ret = PalStreamDelete(dir7, PAL_DELETE_ALL); if (ret < 0) { - pal_printf("DkStreamDelete failed\n"); + pal_printf("PalStreamDelete failed\n"); return 1; } - DkObjectClose(dir7); + PalObjectClose(dir7); } return 0; diff --git a/pal/regression/Event.c b/pal/regression/Event.c index 94d9b47dd2..1da4f30eee 100644 --- a/pal/regression/Event.c +++ b/pal/regression/Event.c @@ -21,41 +21,41 @@ static int g_ready = 0; static noreturn int thread_func(void* arg) { PAL_HANDLE sleep_handle = NULL; - CHECK(DkEventCreate(&sleep_handle, /*init_signaled=*/false, /*auto_clear=*/false)); + CHECK(PalEventCreate(&sleep_handle, /*init_signaled=*/false, /*auto_clear=*/false)); PAL_HANDLE event = (PAL_HANDLE)arg; set(&g_ready, 1); wait_for(&g_ready, 2); uint64_t timeout = TIME_US_IN_S; - int ret = DkEventWait(sleep_handle, &timeout); + int ret = PalEventWait(sleep_handle, &timeout); if (ret != -PAL_ERROR_TRYAGAIN || timeout != 0) { pal_printf("Error: unexpected short sleep, remaining time: %lu\n", timeout); - DkProcessExit(1); + PalProcessExit(1); } - DkEventSet(event); + PalEventSet(event); - DkThreadExit(&g_clear_thread_exit); + PalThreadExit(&g_clear_thread_exit); } int main(void) { PAL_HANDLE event = NULL; - CHECK(DkEventCreate(&event, /*init_signaled=*/true, /*auto_clear=*/true)); + CHECK(PalEventCreate(&event, /*init_signaled=*/true, /*auto_clear=*/true)); /* Event is already set, should not sleep. */ - CHECK(DkEventWait(event, /*timeout=*/NULL)); + CHECK(PalEventWait(event, /*timeout=*/NULL)); uint64_t start = 0; - CHECK(DkSystemTimeQuery(&start)); + CHECK(PalSystemTimeQuery(&start)); /* Sleep for one second. */ uint64_t timeout = TIME_US_IN_S; - int ret = DkEventWait(event, &timeout); + int ret = PalEventWait(event, &timeout); if (ret != -PAL_ERROR_TRYAGAIN) { CHECK(-1); } uint64_t end = 0; - CHECK(DkSystemTimeQuery(&end)); + CHECK(PalSystemTimeQuery(&end)); if (end < start) { CHECK(-1); @@ -68,14 +68,14 @@ int main(void) { } PAL_HANDLE thread = NULL; - CHECK(DkThreadCreate(thread_func, event, &thread)); + CHECK(PalThreadCreate(thread_func, event, &thread)); wait_for(&g_ready, 1); set(&g_ready, 2); - CHECK(DkSystemTimeQuery(&start)); - CHECK(DkEventWait(event, /*timeout=*/NULL)); - CHECK(DkSystemTimeQuery(&end)); + CHECK(PalSystemTimeQuery(&start)); + CHECK(PalEventWait(event, /*timeout=*/NULL)); + CHECK(PalSystemTimeQuery(&end)); if (end < start) { CHECK(-1); diff --git a/pal/regression/Exception.c b/pal/regression/Exception.c index e400e764cd..8a8a68f626 100644 --- a/pal/regression/Exception.c +++ b/pal/regression/Exception.c @@ -110,7 +110,7 @@ static void red_zone_test(void) { int main(void) { pal_printf("Stack in main: %p\n", get_stack()); - DkSetExceptionHandler(handler1, PAL_EVENT_ARITHMETIC_ERROR); + PalSetExceptionHandler(handler1, PAL_EVENT_ARITHMETIC_ERROR); __asm__ volatile ( "movq $1, %%rax\n" "cqo\n" @@ -119,7 +119,7 @@ int main(void) { "nop\n" ::: "rax", "rbx", "rdx", "cc"); - DkSetExceptionHandler(handler2, PAL_EVENT_ARITHMETIC_ERROR); + PalSetExceptionHandler(handler2, PAL_EVENT_ARITHMETIC_ERROR); __asm__ volatile ( "movq $1, %%rax\n" "cqo\n" @@ -128,11 +128,11 @@ int main(void) { "nop\n" ::: "rax", "rbx", "rdx", "cc"); - DkSetExceptionHandler(handler3, PAL_EVENT_MEMFAULT); + PalSetExceptionHandler(handler3, PAL_EVENT_MEMFAULT); *(volatile long*)0x1000 = 0; __asm__ volatile("nop"); - DkSetExceptionHandler(handler4, PAL_EVENT_ARITHMETIC_ERROR); + PalSetExceptionHandler(handler4, PAL_EVENT_ARITHMETIC_ERROR); red_zone_test(); return 0; diff --git a/pal/regression/Exception2.c b/pal/regression/Exception2.c index dfb2807f11..d7b2ffcbcb 100644 --- a/pal/regression/Exception2.c +++ b/pal/regression/Exception2.c @@ -13,13 +13,13 @@ static void handler(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) { count++; if (count == 30) - DkProcessExit(0); + PalProcessExit(0); } int main(void) { pal_printf("Enter Main Thread\n"); - DkSetExceptionHandler(handler, PAL_EVENT_ARITHMETIC_ERROR); + PalSetExceptionHandler(handler, PAL_EVENT_ARITHMETIC_ERROR); __asm__ volatile ( "movq $1, %%rax\n" diff --git a/pal/regression/Exit.c b/pal/regression/Exit.c index db873ba4b6..a736f7e358 100644 --- a/pal/regression/Exit.c +++ b/pal/regression/Exit.c @@ -3,5 +3,5 @@ #include "pal_regression.h" int main(int argc, char** argv, char** envp) { - DkProcessExit(112); + PalProcessExit(112); } diff --git a/pal/regression/File.c b/pal/regression/File.c index f028613d2a..1c19bfdd84 100644 --- a/pal/regression/File.c +++ b/pal/regression/File.c @@ -25,26 +25,26 @@ int main(int argc, char** argv, char** envp) { /* test regular file opening */ PAL_HANDLE file1 = NULL; - ret = DkStreamOpen("file:File.manifest", PAL_ACCESS_RDWR, /*share_flags=*/0, - PAL_CREATE_NEVER, /*options=*/0, &file1); + ret = PalStreamOpen("file:File.manifest", PAL_ACCESS_RDWR, /*share_flags=*/0, + PAL_CREATE_NEVER, /*options=*/0, &file1); if (ret >= 0 && file1) { pal_printf("File Open Test 1 OK\n"); /* test file read */ size_t size = sizeof(buffer1); - ret = DkStreamRead(file1, 0, &size, buffer1, NULL, 0); + ret = PalStreamRead(file1, 0, &size, buffer1, NULL, 0); if (ret == 0 && size == sizeof(buffer1)) { print_hex("Read Test 1 (0th - 40th): %s\n", buffer1, size); } size = sizeof(buffer1); - ret = DkStreamRead(file1, 0, &size, buffer1, NULL, 0); + ret = PalStreamRead(file1, 0, &size, buffer1, NULL, 0); if (ret == 0 && size == sizeof(buffer1)) { print_hex("Read Test 2 (0th - 40th): %s\n", buffer1, size); } size = sizeof(buffer2); - ret = DkStreamRead(file1, 200, &size, buffer2, NULL, 0); + ret = PalStreamRead(file1, 200, &size, buffer2, NULL, 0); if (ret == 0 && size == sizeof(buffer2)) { print_hex("Read Test 3 (200th - 240th): %s\n", buffer2, size); } @@ -52,7 +52,7 @@ int main(int argc, char** argv, char** envp) { /* test file attribute query */ PAL_STREAM_ATTR attr1; - ret = DkStreamAttributesQueryByHandle(file1, &attr1); + ret = PalStreamAttributesQueryByHandle(file1, &attr1); if (ret >= 0) { pal_printf("Query by Handle: type = %d, size = %ld\n", attr1.handle_type, attr1.pending_size); @@ -60,8 +60,8 @@ int main(int argc, char** argv, char** envp) { /* test file map */ - void* mem1 = (void*)DkGetPalPublicState()->user_address_start; - ret = DkStreamMap(file1, &mem1, PAL_PROT_READ | PAL_PROT_WRITECOPY, 0, PAGE_SIZE); + void* mem1 = (void*)PalGetPalPublicState()->user_address_start; + ret = PalStreamMap(file1, &mem1, PAL_PROT_READ | PAL_PROT_WRITECOPY, 0, PAGE_SIZE); if (ret >= 0 && mem1) { memcpy(buffer1, mem1, 40); print_hex("Map Test 1 (0th - 40th): %s\n", buffer1, 40); @@ -69,36 +69,36 @@ int main(int argc, char** argv, char** envp) { memcpy(buffer2, mem1 + 200, 40); print_hex("Map Test 2 (200th - 240th): %s\n", buffer2, 40); - ret = DkStreamUnmap(mem1, PAGE_SIZE); + ret = PalStreamUnmap(mem1, PAGE_SIZE); if (ret < 0) { - pal_printf("DkStreamUnmap failed\n"); + pal_printf("PalStreamUnmap failed\n"); return 1; } } else { pal_printf("Map Test 1 & 2: Failed to map buffer\n"); } - DkObjectClose(file1); + PalObjectClose(file1); } PAL_HANDLE file2 = NULL; - ret = DkStreamOpen("file:File.manifest", PAL_ACCESS_RDWR, /*share_flags=*/0, - PAL_CREATE_NEVER, /*options=*/0, &file2); + ret = PalStreamOpen("file:File.manifest", PAL_ACCESS_RDWR, /*share_flags=*/0, + PAL_CREATE_NEVER, /*options=*/0, &file2); if (ret >= 0 && file2) { pal_printf("File Open Test 2 OK\n"); - DkObjectClose(file2); + PalObjectClose(file2); } PAL_HANDLE file3 = NULL; - ret = DkStreamOpen("file:../regression/File.manifest", PAL_ACCESS_RDWR, /*share_flags=*/0, - PAL_CREATE_NEVER, /*options=*/0, &file3); + ret = PalStreamOpen("file:../regression/File.manifest", PAL_ACCESS_RDWR, /*share_flags=*/0, + PAL_CREATE_NEVER, /*options=*/0, &file3); if (ret >= 0 && file3) { pal_printf("File Open Test 3 OK\n"); - DkObjectClose(file3); + PalObjectClose(file3); } PAL_STREAM_ATTR attr2; - ret = DkStreamAttributesQuery("file:File.manifest", &attr2); + ret = PalStreamAttributesQuery("file:File.manifest", &attr2); if (ret >= 0) { pal_printf("Query: type = %d, size = %ld\n", attr2.handle_type, attr2.pending_size); } @@ -106,72 +106,72 @@ int main(int argc, char** argv, char** envp) { /* test regular file creation */ PAL_HANDLE file4 = NULL; - ret = DkStreamOpen("file:file_nonexist.tmp", PAL_ACCESS_RDWR, - PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W, PAL_CREATE_ALWAYS, /*options=*/0, - &file4); + ret = PalStreamOpen("file:file_nonexist.tmp", PAL_ACCESS_RDWR, + PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W, PAL_CREATE_ALWAYS, /*options=*/0, + &file4); if (ret >= 0 && file4) pal_printf("File Creation Test 1 OK\n"); PAL_HANDLE file5 = NULL; - ret = DkStreamOpen("file:file_nonexist.tmp", PAL_ACCESS_RDWR, - PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W, PAL_CREATE_ALWAYS, /*options=*/0, - &file5); + ret = PalStreamOpen("file:file_nonexist.tmp", PAL_ACCESS_RDWR, + PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W, PAL_CREATE_ALWAYS, /*options=*/0, + &file5); if (ret >= 0) { - DkObjectClose(file5); + PalObjectClose(file5); } else { pal_printf("File Creation Test 2 OK\n"); } PAL_HANDLE file6 = NULL; - ret = DkStreamOpen("file:file_nonexist.tmp", PAL_ACCESS_RDWR, - PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W, PAL_CREATE_TRY, /*options=*/0, - &file6); + ret = PalStreamOpen("file:file_nonexist.tmp", PAL_ACCESS_RDWR, + PAL_SHARE_OWNER_R | PAL_SHARE_OWNER_W, PAL_CREATE_TRY, /*options=*/0, + &file6); if (ret >= 0 && file6) { pal_printf("File Creation Test 3 OK\n"); - DkObjectClose(file6); + PalObjectClose(file6); } if (file4) { /* test file writing */ size_t size = sizeof(buffer1); - ret = DkStreamWrite(file4, 0, &size, buffer1, NULL); + ret = PalStreamWrite(file4, 0, &size, buffer1, NULL); if (ret < 0) goto fail_writing; size = sizeof(buffer2); - ret = DkStreamWrite(file4, 0, &size, buffer2, NULL); + ret = PalStreamWrite(file4, 0, &size, buffer2, NULL); if (ret < 0) goto fail_writing; size = sizeof(buffer1); - ret = DkStreamWrite(file4, 200, &size, buffer1, NULL); + ret = PalStreamWrite(file4, 200, &size, buffer1, NULL); if (ret < 0) goto fail_writing; /* test file truncate */ - ret = DkStreamSetLength(file4, DkGetPalPublicState()->alloc_align); + ret = PalStreamSetLength(file4, PalGetPalPublicState()->alloc_align); if (ret < 0) { goto fail_writing; } fail_writing: - DkObjectClose(file4); + PalObjectClose(file4); if (ret < 0) { return 1; } } PAL_HANDLE file7 = NULL; - ret = DkStreamOpen("file:file_delete.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, - PAL_CREATE_NEVER, /*options=*/0, &file7); + ret = PalStreamOpen("file:file_delete.tmp", PAL_ACCESS_RDONLY, /*share_flags=*/0, + PAL_CREATE_NEVER, /*options=*/0, &file7); if (ret >= 0 && file7) { - ret = DkStreamDelete(file7, PAL_DELETE_ALL); + ret = PalStreamDelete(file7, PAL_DELETE_ALL); if (ret < 0) { - pal_printf("DkStreamDelete failed\n"); + pal_printf("PalStreamDelete failed\n"); return 1; } - DkObjectClose(file7); + PalObjectClose(file7); } return 0; diff --git a/pal/regression/File2.c b/pal/regression/File2.c index f60e6e41b6..25f8c21513 100644 --- a/pal/regression/File2.c +++ b/pal/regression/File2.c @@ -9,58 +9,58 @@ int main(int argc, char** argv, char** envp) { pal_printf("Enter Main Thread\n"); PAL_HANDLE out = NULL; - int ret = DkStreamOpen(FILE_URI, PAL_ACCESS_RDWR, PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_R, - PAL_CREATE_TRY, /*options=*/0, &out); + int ret = PalStreamOpen(FILE_URI, PAL_ACCESS_RDWR, PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_R, + PAL_CREATE_TRY, /*options=*/0, &out); if (ret < 0) { - pal_printf("first DkStreamOpen failed\n"); + pal_printf("first PalStreamOpen failed\n"); return 1; } size_t bytes = sizeof(str) - 1; - ret = DkStreamWrite(out, 0, &bytes, str, NULL); + ret = PalStreamWrite(out, 0, &bytes, str, NULL); if (ret < 0 || bytes != sizeof(str) - 1) { - pal_printf("second DkStreamWrite failed\n"); + pal_printf("second PalStreamWrite failed\n"); return 1; } - DkObjectClose(out); + PalObjectClose(out); PAL_HANDLE in = NULL; - ret = DkStreamOpen(FILE_URI, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, - /*options=*/0, &in); + ret = PalStreamOpen(FILE_URI, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, + /*options=*/0, &in); if (ret < 0) { - pal_printf("third DkStreamOpen failed\n"); + pal_printf("third PalStreamOpen failed\n"); return 1; } bytes = sizeof(str); memset(str, 0, bytes); - ret = DkStreamRead(in, 0, &bytes, str, NULL, 0); + ret = PalStreamRead(in, 0, &bytes, str, NULL, 0); if (ret < 0) { - pal_printf("DkStreamRead failed\n"); + pal_printf("PalStreamRead failed\n"); return 1; } if (bytes > sizeof(str) - 1) { - pal_printf("DkStreamRead read more than expected\n"); + pal_printf("PalStreamRead read more than expected\n"); return 1; } str[bytes] = '\0'; pal_printf("%s\n", str); - ret = DkStreamDelete(in, PAL_DELETE_ALL); + ret = PalStreamDelete(in, PAL_DELETE_ALL); if (ret < 0) { - pal_printf("DkStreamDelete failed\n"); + pal_printf("PalStreamDelete failed\n"); return 1; } PAL_HANDLE del = NULL; - ret = DkStreamOpen(FILE_URI, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_NEVER, - /*options=*/0, &del); + ret = PalStreamOpen(FILE_URI, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_NEVER, + /*options=*/0, &del); if (ret >= 0) { - pal_printf("DkStreamDelete did not actually delete\n"); + pal_printf("PalStreamDelete did not actually delete\n"); return 1; } diff --git a/pal/regression/HelloWorld.c b/pal/regression/HelloWorld.c index ebda4a946d..2556123f85 100644 --- a/pal/regression/HelloWorld.c +++ b/pal/regression/HelloWorld.c @@ -7,22 +7,22 @@ int main(int argc, char** argv, char** envp) { pal_printf("start program: HelloWorld\n"); PAL_HANDLE out = NULL; - int ret = DkStreamOpen("dev:tty", PAL_ACCESS_WRONLY, /*share_flags=*/0, PAL_CREATE_NEVER, - /*options=*/0, &out); + int ret = PalStreamOpen("dev:tty", PAL_ACCESS_WRONLY, /*share_flags=*/0, PAL_CREATE_NEVER, + /*options=*/0, &out); if (ret < 0) { - pal_printf("DkStreamOpen failed\n"); + pal_printf("PalStreamOpen failed\n"); return 1; } size_t bytes = sizeof(str) - 1; - ret = DkStreamWrite(out, 0, &bytes, str, NULL); + ret = PalStreamWrite(out, 0, &bytes, str, NULL); if (ret < 0 || bytes != sizeof(str) - 1) { - pal_printf("DkStreamWrite failed\n"); + pal_printf("PalStreamWrite failed\n"); return 1; } - DkObjectClose(out); + PalObjectClose(out); return 0; } diff --git a/pal/regression/Memory.c b/pal/regression/Memory.c index 1df0fe202d..a0c557dca4 100644 --- a/pal/regression/Memory.c +++ b/pal/regression/Memory.c @@ -7,7 +7,7 @@ #include "pal.h" #include "pal_regression.h" -#define UNIT (DkGetPalPublicState()->alloc_align) +#define UNIT (PalGetPalPublicState()->alloc_align) static volatile int count = 0; @@ -32,18 +32,18 @@ static void handler(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) { __attribute_no_sanitize_address int main(int argc, char** argv, char** envp) { volatile int c; - DkSetExceptionHandler(handler, PAL_EVENT_MEMFAULT); + PalSetExceptionHandler(handler, PAL_EVENT_MEMFAULT); void* mem1 = NULL; - int ret = DkVirtualMemoryAlloc(&mem1, UNIT * 4, PAL_ALLOC_INTERNAL, - PAL_PROT_READ | PAL_PROT_WRITE); + int ret = PalVirtualMemoryAlloc(&mem1, UNIT * 4, PAL_ALLOC_INTERNAL, + PAL_PROT_READ | PAL_PROT_WRITE); if (!ret && mem1) pal_printf("Memory Allocation OK\n"); void* mem2 = NULL; - ret = DkVirtualMemoryAlloc(&mem2, UNIT, PAL_ALLOC_INTERNAL, - PAL_PROT_READ | PAL_PROT_WRITE); + ret = PalVirtualMemoryAlloc(&mem2, UNIT, PAL_ALLOC_INTERNAL, + PAL_PROT_READ | PAL_PROT_WRITE); if (!ret && mem2) { c = count; @@ -52,8 +52,8 @@ int main(int argc, char** argv, char** envp) { if (c == count) pal_printf("Memory Allocation Protection (RW) OK\n"); - if (DkVirtualMemoryProtect(mem2, UNIT, PAL_PROT_READ) < 0) { - pal_printf("DkVirtualMemoryProtect on `mem2` failed\n"); + if (PalVirtualMemoryProtect(mem2, UNIT, PAL_PROT_READ) < 0) { + pal_printf("PalVirtualMemoryProtect on `mem2` failed\n"); return 1; } c = count; @@ -62,8 +62,8 @@ int main(int argc, char** argv, char** envp) { if (c == count - 1) pal_printf("Memory Protection (R) OK\n"); - if (DkVirtualMemoryFree(mem2, UNIT) < 0) { - pal_printf("DkVirtualMemoryFree on `mem2` failed\n"); + if (PalVirtualMemoryFree(mem2, UNIT) < 0) { + pal_printf("PalVirtualMemoryFree on `mem2` failed\n"); return 1; } c = count; @@ -73,23 +73,23 @@ int main(int argc, char** argv, char** envp) { pal_printf("Memory Deallocation OK\n"); } - /* TODO: This does not take into account `DkGetPalPublicState()->preloaded_ranges`; we are not allowed - * to ask for memory overlapping with these ranges */ - void* mem3 = (void*)DkGetPalPublicState()->user_address_start; - void* mem4 = (void*)DkGetPalPublicState()->user_address_start + UNIT; + /* TODO: This does not take into account `PalGetPalPublicState()->preloaded_ranges`; we are + * not allowed to ask for memory overlapping with these ranges */ + void* mem3 = (void*)PalGetPalPublicState()->user_address_start; + void* mem4 = (void*)PalGetPalPublicState()->user_address_start + UNIT; - int ret2 = DkVirtualMemoryAlloc(&mem3, UNIT, 0, PAL_PROT_READ | PAL_PROT_WRITE); - ret = DkVirtualMemoryAlloc(&mem4, UNIT, 0, PAL_PROT_READ | PAL_PROT_WRITE); + int ret2 = PalVirtualMemoryAlloc(&mem3, UNIT, 0, PAL_PROT_READ | PAL_PROT_WRITE); + ret = PalVirtualMemoryAlloc(&mem4, UNIT, 0, PAL_PROT_READ | PAL_PROT_WRITE); if (!ret && !ret2 && mem3 && mem4) pal_printf("Memory Allocation with Address OK\n"); /* Testing total memory */ - pal_printf("Total Memory: %lu\n", DkGetPalPublicState()->mem_total); + pal_printf("Total Memory: %lu\n", PalGetPalPublicState()->mem_total); /* Testing available memory (must be within valid range) */ - size_t avail = DkMemoryAvailableQuota(); - if (avail > 0 && avail < DkGetPalPublicState()->mem_total) + size_t avail = PalMemoryAvailableQuota(); + if (avail > 0 && avail < PalGetPalPublicState()->mem_total) pal_printf("Get Memory Available Quota OK\n"); return 0; diff --git a/pal/regression/Misc.c b/pal/regression/Misc.c index 3b2fa3c6bd..a8b78c2bc4 100644 --- a/pal/regression/Misc.c +++ b/pal/regression/Misc.c @@ -5,13 +5,13 @@ int main(int argc, const char** argv, const char** envp) { uint64_t time1 = 0; - if (DkSystemTimeQuery(&time1) < 0) { - pal_printf("DkSystemTimeQuery failed\n"); + if (PalSystemTimeQuery(&time1) < 0) { + pal_printf("PalSystemTimeQuery failed\n"); return 1; } uint64_t time2 = 0; - if (DkSystemTimeQuery(&time2) < 0) { - pal_printf("DkSystemTimeQuery failed\n"); + if (PalSystemTimeQuery(&time2) < 0) { + pal_printf("PalSystemTimeQuery failed\n"); return 1; } @@ -22,27 +22,27 @@ int main(int argc, const char** argv, const char** envp) { pal_printf("Query System Time OK\n"); PAL_HANDLE sleep_handle = NULL; - if (DkEventCreate(&sleep_handle, /*init_signaled=*/false, /*auto_clear=*/false) < 0) { - pal_printf("DkEventCreate failed\n"); + if (PalEventCreate(&sleep_handle, /*init_signaled=*/false, /*auto_clear=*/false) < 0) { + pal_printf("PalEventCreate failed\n"); return 1; } uint64_t time3 = 0; - if (DkSystemTimeQuery(&time3) < 0) { - pal_printf("DkSystemTimeQuery failed\n"); + if (PalSystemTimeQuery(&time3) < 0) { + pal_printf("PalSystemTimeQuery failed\n"); return 1; } uint64_t timeout = 10000; - int ret = DkEventWait(sleep_handle, &timeout); + int ret = PalEventWait(sleep_handle, &timeout); if (ret != -PAL_ERROR_TRYAGAIN) { - pal_printf("DkEventWait failed\n"); + pal_printf("PalEventWait failed\n"); return 1; } uint64_t time4 = 0; - if (DkSystemTimeQuery(&time4) < 0) { - pal_printf("DkSystemTimeQuery failed\n"); + if (PalSystemTimeQuery(&time4) < 0) { + pal_printf("PalSystemTimeQuery failed\n"); return 1; } @@ -52,21 +52,21 @@ int main(int argc, const char** argv, const char** envp) { pal_printf("Delay Execution for 10000 Microseconds OK\n"); uint64_t time5 = 0; - if (DkSystemTimeQuery(&time5) < 0) { - pal_printf("DkSystemTimeQuery failed\n"); + if (PalSystemTimeQuery(&time5) < 0) { + pal_printf("PalSystemTimeQuery failed\n"); return 1; } timeout = 3000000; - ret = DkEventWait(sleep_handle, &timeout); + ret = PalEventWait(sleep_handle, &timeout); if (ret != -PAL_ERROR_TRYAGAIN) { - pal_printf("DkEventWait failed\n"); + pal_printf("PalEventWait failed\n"); return 1; } uint64_t time6 = 0; - if (DkSystemTimeQuery(&time6) < 0) { - pal_printf("DkSystemTimeQuery failed\n"); + if (PalSystemTimeQuery(&time6) < 0) { + pal_printf("PalSystemTimeQuery failed\n"); return 1; } @@ -79,9 +79,9 @@ int main(int argc, const char** argv, const char** envp) { memset(data, 0, sizeof(data)); for (int i = 0; i < 100; i++) { - ret = DkRandomBitsRead(&data[i], sizeof(unsigned long)); + ret = PalRandomBitsRead(&data[i], sizeof(unsigned long)); if (ret < 0) { - pal_printf("DkRandomBitsRead() failed!\n"); + pal_printf("PalRandomBitsRead() failed!\n"); return 1; } } diff --git a/pal/regression/Pie.c b/pal/regression/Pie.c index fd80cc3647..15f98febb6 100644 --- a/pal/regression/Pie.c +++ b/pal/regression/Pie.c @@ -7,22 +7,22 @@ int main(int argc, char** argv, char** envp) { pal_printf("start program: Pie\n"); PAL_HANDLE out = NULL; - int ret = DkStreamOpen("dev:tty", PAL_ACCESS_WRONLY, /*share_flags=*/0, PAL_CREATE_NEVER, - /*options=*/0, &out); + int ret = PalStreamOpen("dev:tty", PAL_ACCESS_WRONLY, /*share_flags=*/0, PAL_CREATE_NEVER, + /*options=*/0, &out); if (ret < 0) { - pal_printf("DkStreamOpen failed\n"); + pal_printf("PalStreamOpen failed\n"); return 1; } size_t bytes = sizeof(str) - 1; - ret = DkStreamWrite(out, 0, &bytes, str, NULL); + ret = PalStreamWrite(out, 0, &bytes, str, NULL); if (ret < 0 || bytes != sizeof(str) - 1) { - pal_printf("DkStreamWrite failed\n"); + pal_printf("PalStreamWrite failed\n"); return 1; } - DkObjectClose(out); + PalObjectClose(out); return 0; } diff --git a/pal/regression/Pipe.c b/pal/regression/Pipe.c index d3f8ff1572..1dd3b65fc2 100644 --- a/pal/regression/Pipe.c +++ b/pal/regression/Pipe.c @@ -10,15 +10,15 @@ int main(int argc, char** argv, char** envp) { int ret; PAL_HANDLE pipe1 = NULL; - ret = DkStreamOpen("pipe.srv:1", PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, - /*options=*/0, &pipe1); + ret = PalStreamOpen("pipe.srv:1", PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, + /*options=*/0, &pipe1); if (ret >= 0 && pipe1) { pal_printf("Pipe Creation 1 OK\n"); // DEP 10/24/16: Try to read some attributes of the pipe PAL_STREAM_ATTR attr; - ret = DkStreamAttributesQueryByHandle(pipe1, &attr); + ret = PalStreamAttributesQueryByHandle(pipe1, &attr); if (ret < 0) { pal_printf("Failed to get any attributes from the pipesrv\n"); return 1; @@ -29,33 +29,33 @@ int main(int argc, char** argv, char** envp) { // Job for another day... PAL_HANDLE pipe2 = NULL; - ret = DkStreamOpen("pipe:1", PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, - /*options=*/0, &pipe2); + ret = PalStreamOpen("pipe:1", PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, + /*options=*/0, &pipe2); if (ret >= 0 && pipe2) { PAL_HANDLE pipe3 = NULL; - ret = DkStreamWaitForClient(pipe1, &pipe3, /*options=*/0); + ret = PalStreamWaitForClient(pipe1, &pipe3, /*options=*/0); if (ret >= 0 && pipe3) { pal_printf("Pipe Connection 1 OK\n"); size_t size = sizeof(buffer1); - ret = DkStreamWrite(pipe3, 0, &size, buffer1, NULL); + ret = PalStreamWrite(pipe3, 0, &size, buffer1, NULL); if (ret == 0 && size > 0) pal_printf("Pipe Write 1 OK\n"); size = sizeof(buffer3); - ret = DkStreamRead(pipe2, 0, &size, buffer3, NULL, 0); + ret = PalStreamRead(pipe2, 0, &size, buffer3, NULL, 0); if (ret == 0 && size > 0) pal_printf("Pipe Read 1: %s\n", buffer3); size = sizeof(buffer2); - ret = DkStreamWrite(pipe2, 0, &size, buffer2, NULL); + ret = PalStreamWrite(pipe2, 0, &size, buffer2, NULL); if (ret == 0 && size > 0) pal_printf("Pipe Write 2 OK\n"); size = sizeof(buffer4); - ret = DkStreamRead(pipe3, 0, &size, buffer4, NULL, 0); + ret = PalStreamRead(pipe3, 0, &size, buffer4, NULL, 0); if (ret == 0 && size > 0) pal_printf("Pipe Read 2: %s\n", buffer4); } diff --git a/pal/regression/Process.c b/pal/regression/Process.c index 785f690b0e..9e8eedb810 100644 --- a/pal/regression/Process.c +++ b/pal/regression/Process.c @@ -18,15 +18,15 @@ int main(int argc, char** argv, char** envp) { } size = sizeof(buffer1); - DkStreamWrite(DkGetPalPublicState()->parent_process, 0, &size, buffer1, NULL); + PalStreamWrite(PalGetPalPublicState()->parent_process, 0, &size, buffer1, NULL); size = sizeof(buffer1); - ret = DkStreamWrite(DkGetPalPublicState()->parent_process, 0, &size, buffer1, NULL); + ret = PalStreamWrite(PalGetPalPublicState()->parent_process, 0, &size, buffer1, NULL); if (ret == 0 && size > 0) pal_printf("Process Write 1 OK\n"); size = sizeof(buffer4); - ret = DkStreamRead(DkGetPalPublicState()->parent_process, 0, &size, buffer4, NULL, 0); + ret = PalStreamRead(PalGetPalPublicState()->parent_process, 0, &size, buffer4, NULL, 0); if (ret == 0 && size > 0) pal_printf("Process Read 2: %s\n", buffer4); @@ -37,24 +37,24 @@ int main(int argc, char** argv, char** envp) { for (int i = 0; i < 3; i++) { pal_printf("Creating process\n"); - ret = DkProcessCreate(args, &children[i]); + ret = PalProcessCreate(args, &children[i]); if (ret == 0 && children[i]) { pal_printf("Process created %d\n", i + 1); size = sizeof(buffer4); - DkStreamRead(children[i], 0, &size, buffer4, NULL, 0); + PalStreamRead(children[i], 0, &size, buffer4, NULL, 0); } } for (int i = 0; i < 3; i++) if (children[i]) { size = sizeof(buffer3); - ret = DkStreamRead(children[i], 0, &size, buffer3, NULL, 0); + ret = PalStreamRead(children[i], 0, &size, buffer3, NULL, 0); if (ret == 0 && size > 0) pal_printf("Process Read 1: %s\n", buffer3); size = sizeof(buffer2); - ret = DkStreamWrite(children[i], 0, &size, buffer2, NULL); + ret = PalStreamWrite(children[i], 0, &size, buffer2, NULL); if (ret == 0 && size > 0) pal_printf("Process Write 2 OK\n"); } diff --git a/pal/regression/Process4.c b/pal/regression/Process4.c index d7a01aa407..1eca9c8f46 100644 --- a/pal/regression/Process4.c +++ b/pal/regression/Process4.c @@ -13,16 +13,16 @@ int main(int argc, char** argv) { if (argc == 1) { PAL_HANDLE pipe_srv = NULL; - int ret = DkStreamOpen("pipe.srv:Process4", PAL_ACCESS_RDWR, /*share_flags=*/0, - PAL_CREATE_IGNORED, /*options=*/0, &pipe_srv); + int ret = PalStreamOpen("pipe.srv:Process4", PAL_ACCESS_RDWR, /*share_flags=*/0, + PAL_CREATE_IGNORED, /*options=*/0, &pipe_srv); if (ret < 0) { - pal_printf("DkStreamOpen(\"pipe.srv\", ...) failed: %d\n", ret); + pal_printf("PalStreamOpen(\"pipe.srv\", ...) failed: %d\n", ret); return 1; } uint64_t time = 0; - if (DkSystemTimeQuery(&time) < 0) { - pal_printf("DkSystemTimeQuery failed\n"); + if (PalSystemTimeQuery(&time) < 0) { + pal_printf("PalSystemTimeQuery failed\n"); return 1; } char time_arg[24]; @@ -31,20 +31,20 @@ int main(int argc, char** argv) { const char* newargs[4] = {"Process4", "0", time_arg, NULL}; PAL_HANDLE proc = NULL; - ret = DkProcessCreate(newargs, &proc); + ret = PalProcessCreate(newargs, &proc); if (ret < 0) pal_printf("Can't create process\n"); - DkObjectClose(proc); + PalObjectClose(proc); PAL_HANDLE pipe = NULL; - ret = DkStreamWaitForClient(pipe_srv, &pipe, /*options=*/0); + ret = PalStreamWaitForClient(pipe_srv, &pipe, /*options=*/0); if (ret < 0) { - pal_printf("DkStreamWaitForClient failed: %d\n", ret); + pal_printf("PalStreamWaitForClient failed: %d\n", ret); } - DkObjectClose(pipe); - DkObjectClose(pipe_srv); + PalObjectClose(pipe); + PalObjectClose(pipe_srv); } else { count = atoi(argv[1]); @@ -56,31 +56,31 @@ int main(int argc, char** argv) { const char* newargs[4] = {"Process4", count_arg, argv[2], NULL}; PAL_HANDLE proc = NULL; - int ret = DkProcessCreate(newargs, &proc); + int ret = PalProcessCreate(newargs, &proc); if (ret < 0) pal_printf("Can't create process\n"); - DkObjectClose(proc); + PalObjectClose(proc); } else { uint64_t end = 0; - if (DkSystemTimeQuery(&end) < 0) { - pal_printf("DkSystemTimeQuery failed\n"); + if (PalSystemTimeQuery(&end) < 0) { + pal_printf("PalSystemTimeQuery failed\n"); return 1; } uint64_t start = atol(argv[2]); pal_printf("wall time = %ld\n", end - start); PAL_HANDLE pipe = NULL; - int ret = DkStreamOpen("pipe:Process4", PAL_ACCESS_RDWR, /*share_flags=*/0, - PAL_CREATE_IGNORED, /*options=*/0, &pipe); + int ret = PalStreamOpen("pipe:Process4", PAL_ACCESS_RDWR, /*share_flags=*/0, + PAL_CREATE_IGNORED, /*options=*/0, &pipe); if (ret < 0) { pal_printf("Failed to open pipe: %d\n", ret); return 1; } - DkObjectClose(pipe); + PalObjectClose(pipe); } } - DkProcessExit(0); + PalProcessExit(0); } diff --git a/pal/regression/Segment.c b/pal/regression/Segment.c index 7fc261f9a9..df58f4a515 100644 --- a/pal/regression/Segment.c +++ b/pal/regression/Segment.c @@ -4,7 +4,7 @@ uintptr_t dummy = (uintptr_t)&dummy; int main(int argc, char** argv, char** envp) { - if (DkSegmentBaseSet(PAL_SEGMENT_FS, dummy) < 0) { + if (PalSegmentBaseSet(PAL_SEGMENT_FS, dummy) < 0) { pal_printf("Error setting FS\n"); return 1; } diff --git a/pal/regression/Symbols.c b/pal/regression/Symbols.c index 609426a6e2..e37b62ffcf 100644 --- a/pal/regression/Symbols.c +++ b/pal/regression/Symbols.c @@ -11,52 +11,52 @@ #define PRINT_SYMBOL(sym) pal_printf("symbol: %s = %p\n", #sym, SYMBOL_ADDR(sym)) int main(int argc, char** argv, char** envp) { - PRINT_SYMBOL(DkVirtualMemoryAlloc); - PRINT_SYMBOL(DkVirtualMemoryFree); - PRINT_SYMBOL(DkVirtualMemoryProtect); - - PRINT_SYMBOL(DkProcessCreate); - PRINT_SYMBOL(DkProcessExit); - - PRINT_SYMBOL(DkStreamOpen); - PRINT_SYMBOL(DkStreamWaitForClient); - PRINT_SYMBOL(DkStreamRead); - PRINT_SYMBOL(DkStreamWrite); - PRINT_SYMBOL(DkStreamDelete); - PRINT_SYMBOL(DkStreamMap); - PRINT_SYMBOL(DkStreamUnmap); - PRINT_SYMBOL(DkStreamSetLength); - PRINT_SYMBOL(DkStreamFlush); - PRINT_SYMBOL(DkSendHandle); - PRINT_SYMBOL(DkReceiveHandle); - PRINT_SYMBOL(DkStreamAttributesQuery); - PRINT_SYMBOL(DkStreamAttributesQueryByHandle); - PRINT_SYMBOL(DkStreamAttributesSetByHandle); - PRINT_SYMBOL(DkStreamGetName); - PRINT_SYMBOL(DkStreamChangeName); - PRINT_SYMBOL(DkStreamsWaitEvents); - - PRINT_SYMBOL(DkThreadCreate); - PRINT_SYMBOL(DkThreadYieldExecution); - PRINT_SYMBOL(DkThreadExit); - PRINT_SYMBOL(DkThreadResume); - - PRINT_SYMBOL(DkSetExceptionHandler); - - PRINT_SYMBOL(DkEventCreate); - PRINT_SYMBOL(DkEventSet); - PRINT_SYMBOL(DkEventClear); - PRINT_SYMBOL(DkEventWait); - - PRINT_SYMBOL(DkObjectClose); - - PRINT_SYMBOL(DkSystemTimeQuery); - PRINT_SYMBOL(DkRandomBitsRead); + PRINT_SYMBOL(PalVirtualMemoryAlloc); + PRINT_SYMBOL(PalVirtualMemoryFree); + PRINT_SYMBOL(PalVirtualMemoryProtect); + + PRINT_SYMBOL(PalProcessCreate); + PRINT_SYMBOL(PalProcessExit); + + PRINT_SYMBOL(PalStreamOpen); + PRINT_SYMBOL(PalStreamWaitForClient); + PRINT_SYMBOL(PalStreamRead); + PRINT_SYMBOL(PalStreamWrite); + PRINT_SYMBOL(PalStreamDelete); + PRINT_SYMBOL(PalStreamMap); + PRINT_SYMBOL(PalStreamUnmap); + PRINT_SYMBOL(PalStreamSetLength); + PRINT_SYMBOL(PalStreamFlush); + PRINT_SYMBOL(PalSendHandle); + PRINT_SYMBOL(PalReceiveHandle); + PRINT_SYMBOL(PalStreamAttributesQuery); + PRINT_SYMBOL(PalStreamAttributesQueryByHandle); + PRINT_SYMBOL(PalStreamAttributesSetByHandle); + PRINT_SYMBOL(PalStreamGetName); + PRINT_SYMBOL(PalStreamChangeName); + PRINT_SYMBOL(PalStreamsWaitEvents); + + PRINT_SYMBOL(PalThreadCreate); + PRINT_SYMBOL(PalThreadYieldExecution); + PRINT_SYMBOL(PalThreadExit); + PRINT_SYMBOL(PalThreadResume); + + PRINT_SYMBOL(PalSetExceptionHandler); + + PRINT_SYMBOL(PalEventCreate); + PRINT_SYMBOL(PalEventSet); + PRINT_SYMBOL(PalEventClear); + PRINT_SYMBOL(PalEventWait); + + PRINT_SYMBOL(PalObjectClose); + + PRINT_SYMBOL(PalSystemTimeQuery); + PRINT_SYMBOL(PalRandomBitsRead); #if defined(__x86_64__) - PRINT_SYMBOL(DkSegmentBaseGet); - PRINT_SYMBOL(DkSegmentBaseSet); + PRINT_SYMBOL(PalSegmentBaseGet); + PRINT_SYMBOL(PalSegmentBaseSet); #endif - PRINT_SYMBOL(DkMemoryAvailableQuota); + PRINT_SYMBOL(PalMemoryAvailableQuota); return 0; } diff --git a/pal/regression/Thread.c b/pal/regression/Thread.c index 5fc586ce8b..552b18735e 100644 --- a/pal/regression/Thread.c +++ b/pal/regression/Thread.c @@ -14,16 +14,16 @@ static noreturn int callback(void* args) { while (count < 10) { while (!(count % 2)) { - DkThreadYieldExecution(); + PalThreadYieldExecution(); } count++; } pal_printf("Threads Run in Parallel OK\n"); - if (DkSegmentBaseSet(PAL_SEGMENT_FS, (uintptr_t)&private2) < 0) { + if (PalSegmentBaseSet(PAL_SEGMENT_FS, (uintptr_t)&private2) < 0) { pal_printf("Failed to set FS\n"); - DkThreadExit(/*clear_child_tid=*/NULL); + PalThreadExit(/*clear_child_tid=*/NULL); } const char* ptr2; @@ -31,12 +31,12 @@ static noreturn int callback(void* args) { pal_printf("Private Message (FS Segment) 2: %s\n", ptr2); count = 100; - DkThreadExit(/*clear_child_tid=*/NULL); + PalThreadExit(/*clear_child_tid=*/NULL); /* UNREACHABLE */ } int main(void) { - if (DkSegmentBaseSet(PAL_SEGMENT_FS, (uintptr_t)&private1) < 0) { + if (PalSegmentBaseSet(PAL_SEGMENT_FS, (uintptr_t)&private1) < 0) { pal_printf("Failed to set FS\n"); return 1; } @@ -46,7 +46,7 @@ int main(void) { PAL_HANDLE thread1 = NULL; char arg[] = "Hello World"; - int ret = DkThreadCreate(callback, arg, &thread1); + int ret = PalThreadCreate(callback, arg, &thread1); if (ret < 0) return 1; @@ -54,13 +54,13 @@ int main(void) { while (count < 9) { while (!!(count % 2)) { - DkThreadYieldExecution(); + PalThreadYieldExecution(); } count++; } while (count != 100) { - DkThreadYieldExecution(); + PalThreadYieldExecution(); } pal_printf("Child Thread Exited\n"); return 0; diff --git a/pal/regression/Thread2.c b/pal/regression/Thread2.c index c62e7b9a70..fe455e4d84 100644 --- a/pal/regression/Thread2.c +++ b/pal/regression/Thread2.c @@ -25,11 +25,11 @@ static int thread3_run(void* args) { thread3_started = true; - pal_printf("Exiting thread 3 by DkThreadExit.\n"); + pal_printf("Exiting thread 3 by PalThreadExit.\n"); // Ensure that the compiler can't know that this should never return. if (dummy_true) { - DkThreadExit(/*clear_child_tid=*/NULL); + PalThreadExit(/*clear_child_tid=*/NULL); /* UNREACHABLE */ } @@ -54,24 +54,24 @@ int main(void) { pal_printf("Thread 1 (main) started.\n"); PAL_HANDLE sleep_handle = NULL; - if (DkEventCreate(&sleep_handle, /*init_signaled=*/false, /*auto_clear=*/false) < 0) { - pal_printf("DkEventCreate failed\n"); + if (PalEventCreate(&sleep_handle, /*init_signaled=*/false, /*auto_clear=*/false) < 0) { + pal_printf("PalEventCreate failed\n"); return 1; } PAL_HANDLE thread2 = NULL; - int ret = DkThreadCreate(thread2_run, NULL, &thread2); + int ret = PalThreadCreate(thread2_run, NULL, &thread2); if (ret < 0) { - pal_printf("DkThreadCreate failed for thread 2.\n"); + pal_printf("PalThreadCreate failed for thread 2.\n"); return 1; } // 1 s should be enough even on a very busy system to start a thread and // then exit it again including all cleanup. uint64_t timeout = 1000000; - ret = DkEventWait(sleep_handle, &timeout); + ret = PalEventWait(sleep_handle, &timeout); if (ret != -PAL_ERROR_TRYAGAIN) { - pal_printf("DkEventWait failed\n"); + pal_printf("PalEventWait failed\n"); return 1; } @@ -80,16 +80,16 @@ int main(void) { } PAL_HANDLE thread3 = NULL; - ret = DkThreadCreate(thread3_run, NULL, &thread3); + ret = PalThreadCreate(thread3_run, NULL, &thread3); if (ret < 0) { - pal_printf("DkThreadCreate failed for thread 3.\n"); + pal_printf("PalThreadCreate failed for thread 3.\n"); return 1; } timeout = 1000000; - ret = DkEventWait(sleep_handle, &timeout); + ret = PalEventWait(sleep_handle, &timeout); if (ret != -PAL_ERROR_TRYAGAIN) { - pal_printf("DkEventWait failed\n"); + pal_printf("PalEventWait failed\n"); return 1; } @@ -98,16 +98,16 @@ int main(void) { } PAL_HANDLE thread4 = NULL; - ret = DkThreadCreate(thread4_run, NULL, &thread4); + ret = PalThreadCreate(thread4_run, NULL, &thread4); if (ret < 0) { - pal_printf("DkThreadCreate failed for thread 4.\n"); + pal_printf("PalThreadCreate failed for thread 4.\n"); return 1; } timeout = 1000000; - ret = DkEventWait(sleep_handle, &timeout); + ret = PalEventWait(sleep_handle, &timeout); if (ret != -PAL_ERROR_TRYAGAIN) { - pal_printf("DkEventWait failed\n"); + pal_printf("PalEventWait failed\n"); return 1; } diff --git a/pal/regression/avl_tree_test.c b/pal/regression/avl_tree_test.c index 15802f4f82..760baaeb1c 100644 --- a/pal/regression/avl_tree_test.c +++ b/pal/regression/avl_tree_test.c @@ -12,7 +12,7 @@ #define EXIT_UNBALANCED() \ do { \ pal_printf("Unbalanced tree at: %u\n", __LINE__); \ - DkProcessExit(1); \ + PalProcessExit(1); \ } while (0) static uint32_t _seed; @@ -96,7 +96,7 @@ static void try_node_swap(struct avl_tree_node* node, struct avl_tree_node* swap size_t size = get_tree_size(tree.root); if (size != ELEMENTS_COUNT) { pal_printf("Tree has %lu elements instead of %u!", size, ELEMENTS_COUNT); - DkProcessExit(1); + PalProcessExit(1); } avl_tree_swap_node(&tree, swap_node, node); @@ -109,7 +109,7 @@ static void try_node_swap(struct avl_tree_node* node, struct avl_tree_node* swap size = get_tree_size(tree.root); if (size != ELEMENTS_COUNT) { pal_printf("Tree has %lu elements instead of %u!", size, ELEMENTS_COUNT); - DkProcessExit(1); + PalProcessExit(1); } } @@ -128,7 +128,7 @@ static void do_test(int32_t (*get_num)(void)) { size_t size = get_tree_size(tree.root); if (size != ELEMENTS_COUNT) { pal_printf("Tree has %lu elements instead of %u!", size, ELEMENTS_COUNT); - DkProcessExit(1); + PalProcessExit(1); } struct avl_tree_node* node = avl_tree_first(&tree); @@ -137,7 +137,7 @@ static void do_test(int32_t (*get_num)(void)) { while (node) { if (prev && node2struct(prev)->key > node2struct(node)->key) { pal_printf("Found two elements in wrong order!\n"); - DkProcessExit(1); + PalProcessExit(1); } prev = node; node = avl_tree_next(node); @@ -146,7 +146,7 @@ static void do_test(int32_t (*get_num)(void)) { if (size != ELEMENTS_COUNT) { pal_printf("Tree iteration from the beginning walked through %lu elements instead of %u!", size, ELEMENTS_COUNT); - DkProcessExit(1); + PalProcessExit(1); } node = avl_tree_last(&tree); @@ -155,7 +155,7 @@ static void do_test(int32_t (*get_num)(void)) { while (node) { if (next && node2struct(node)->key > node2struct(next)->key) { pal_printf("Found two elements in wrong order while iterating backwards!\n"); - DkProcessExit(1); + PalProcessExit(1); } next = node; node = avl_tree_prev(node); @@ -164,7 +164,7 @@ static void do_test(int32_t (*get_num)(void)) { if (size != ELEMENTS_COUNT) { pal_printf("Tree iteration from the end walked through %lu elements instead of %u!", size, ELEMENTS_COUNT); - DkProcessExit(1); + PalProcessExit(1); } static_assert(ELEMENTS_COUNT >= 3, "This code needs at least 3 elements in the tree!"); @@ -192,7 +192,7 @@ static void do_test(int32_t (*get_num)(void)) { pal_printf("NULL"); } pal_printf("\n"); - DkProcessExit(1); + PalProcessExit(1); } /* get_num returns int32_t, but tmp.key is a int64_t, so this cannot overflow. */ @@ -219,7 +219,7 @@ static void do_test(int32_t (*get_num)(void)) { /* These two are equivalent, it's just an assert. */ if (!found || !node) { pal_printf("avl_tree_lower_bound has not found the next element!\n"); - DkProcessExit(1); + PalProcessExit(1); } avl_tree_delete(&tree, &tmp.node); @@ -273,7 +273,7 @@ static void test_ordering(void) { /* These nodes are all a part of array `t`. */ if ((uintptr_t)prev >= (uintptr_t)node) { pal_printf("Wrong ordering of nodes: %p %p\n", prev, node); - DkProcessExit(1); + PalProcessExit(1); } prev = node; node = avl_tree_next(prev); @@ -300,7 +300,7 @@ int main(void) { pal_printf("Done!\n"); uint32_t seed = 0; - if (DkRandomBitsRead(&seed, sizeof(seed)) < 0) { + if (PalRandomBitsRead(&seed, sizeof(seed)) < 0) { pal_printf("Getting a seed failed\n"); return 1; } diff --git a/pal/regression/crt_init/arch/x86_64/user_start.S b/pal/regression/crt_init/arch/x86_64/user_start.S index 79cfee0d08..1b38e85efc 100644 --- a/pal/regression/crt_init/arch/x86_64/user_start.S +++ b/pal/regression/crt_init/arch/x86_64/user_start.S @@ -23,6 +23,6 @@ _start: callq *main@GOTPCREL(%rip) mov %rax, %rdi - callq *DkProcessExit@GOTPCREL(%rip) + callq *PalProcessExit@GOTPCREL(%rip) .cfi_endproc diff --git a/pal/regression/manifest.template b/pal/regression/manifest.template index 2b389e3659..c54d75d4b9 100644 --- a/pal/regression/manifest.template +++ b/pal/regression/manifest.template @@ -4,7 +4,7 @@ loader.insecure__use_cmdline_argv = true sgx.debug = true -# PAL tests use `DkVirtualMemoryAlloc(PAL_ALLOC_INTERNAL)` which must allocate in the PAL-internal +# PAL tests use `PalVirtualMemoryAlloc(PAL_ALLOC_INTERNAL)` which must allocate in the PAL-internal # part of the Gramine memory loader.pal_internal_mem_size = "64M" @@ -12,7 +12,7 @@ sgx.nonpie_binary = true # all tests are currently non-PIE unless overridden sgx.allowed_files = [ "file:test.txt", # for File2 test - "file:to_send.tmp", # for DkSendHandle test + "file:to_send.tmp", # for PalSendHandle test ] sgx.trusted_files = [ diff --git a/pal/regression/pal_regression.h b/pal/regression/pal_regression.h index 983b132e6d..014e058e5d 100644 --- a/pal/regression/pal_regression.h +++ b/pal/regression/pal_regression.h @@ -12,7 +12,7 @@ void __attribute__((format(printf, 2, 3))) _log(int level, const char* fmt, ...) __typeof__(x) _x = (x); \ if (_x < 0) { \ pal_printf("Error at %s (line %d): %d\n", #x, __LINE__, _x); \ - DkProcessExit(1); \ + PalProcessExit(1); \ } \ _x; \ }) diff --git a/pal/regression/printf_test.c b/pal/regression/printf_test.c index b1d7c35c2f..637cc32077 100644 --- a/pal/regression/printf_test.c +++ b/pal/regression/printf_test.c @@ -4,7 +4,7 @@ #define FAIL(fmt...) ({ \ pal_printf(fmt); \ pal_printf("\n"); \ - DkProcessExit(1); \ + PalProcessExit(1); \ }) #define TEST(output_str, fmt...) ({ \ @@ -91,14 +91,14 @@ int main(void) { * terminated at two pages boundary, where the second page has no read permission. If * the precision limit is not respected, `snprintf` will access data at the second page and * crash the process. */ - int ret = DkVirtualMemoryAlloc((void**)&ptr, 2 * PAGE_SIZE, PAL_ALLOC_INTERNAL, - PAL_PROT_READ | PAL_PROT_WRITE); + int ret = PalVirtualMemoryAlloc((void**)&ptr, 2 * PAGE_SIZE, PAL_ALLOC_INTERNAL, + PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { - FAIL("DkVirtualMemoryAlloc failed: %d", ret); + FAIL("PalVirtualMemoryAlloc failed: %d", ret); } - ret = DkVirtualMemoryProtect(ptr + PAGE_SIZE, PAGE_SIZE, /*prot=*/0); + ret = PalVirtualMemoryProtect(ptr + PAGE_SIZE, PAGE_SIZE, /*prot=*/0); if (ret < 0) { - FAIL("DkVirtualMemoryProtect failed: %d", ret); + FAIL("PalVirtualMemoryProtect failed: %d", ret); } memset(ptr + PAGE_SIZE - 7, 'a', 7); diff --git a/pal/regression/send_handle.c b/pal/regression/send_handle.c index 2e855dd3d3..70ef127d28 100644 --- a/pal/regression/send_handle.c +++ b/pal/regression/send_handle.c @@ -14,21 +14,21 @@ static void write_all(PAL_HANDLE handle, int type, char* buf, size_t size) { case PAL_TYPE_FILE: case PAL_TYPE_PIPE: case PAL_TYPE_PIPECLI: - CHECK(DkStreamWrite(handle, 0, &this_size, buf + i, NULL)); + CHECK(PalStreamWrite(handle, 0, &this_size, buf + i, NULL)); break; case PAL_TYPE_SOCKET:; struct pal_iovec iov = { .iov_base = buf + i, .iov_len = this_size, }; - CHECK(DkSocketSend(handle, &iov, 1, &this_size, /*addr=*/NULL)); + CHECK(PalSocketSend(handle, &iov, 1, &this_size, /*addr=*/NULL)); break; default: BUG(); } if (!this_size) { pal_printf("Remote end closed the handle!\n"); - DkProcessExit(1); + PalProcessExit(1); } i += this_size; } @@ -41,22 +41,22 @@ static void read_all(PAL_HANDLE handle, int type, char* buf, size_t size) { switch (type) { case PAL_TYPE_FILE: case PAL_TYPE_PIPE: - CHECK(DkStreamRead(handle, 0, &this_size, buf + i, NULL, 0)); + CHECK(PalStreamRead(handle, 0, &this_size, buf + i, NULL, 0)); break; case PAL_TYPE_SOCKET:; struct pal_iovec iov = { .iov_base = buf + i, .iov_len = this_size, }; - CHECK(DkSocketRecv(handle, &iov, 1, &this_size, /*addr=*/NULL, - /*force_nonblocking=*/false)); + CHECK(PalSocketRecv(handle, &iov, 1, &this_size, /*addr=*/NULL, + /*force_nonblocking=*/false)); break; default: BUG(); } if (!this_size) { pal_printf("Remote end closed the handle!\n"); - DkProcessExit(1); + PalProcessExit(1); } i += this_size; } @@ -72,37 +72,37 @@ static void recv_and_check(PAL_HANDLE handle, int type) { read_all(handle, type, buf, sizeof(buf)); if (memcmp(buf, MSG, sizeof(buf))) { pal_printf("%s: got invalid message: %s\n", __func__, buf); - DkProcessExit(1); + PalProcessExit(1); } } static void set_reuseaddr(PAL_HANDLE handle) { PAL_STREAM_ATTR attr; - CHECK(DkStreamAttributesQueryByHandle(handle, &attr)); + CHECK(PalStreamAttributesQueryByHandle(handle, &attr)); attr.socket.reuseaddr = true; - CHECK(DkStreamAttributesSetByHandle(handle, &attr)); + CHECK(PalStreamAttributesSetByHandle(handle, &attr)); } static void do_parent(void) { PAL_HANDLE child_process; const char* args[] = { "send_handle", "child", NULL }; - CHECK(DkProcessCreate(args, &child_process)); + CHECK(PalProcessCreate(args, &child_process)); PAL_HANDLE handle; /* pipe.srv handle */ - CHECK(DkStreamOpen("pipe.srv:1", PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, - /*options=*/0, &handle)); - CHECK(DkSendHandle(child_process, handle)); - DkObjectClose(handle); + CHECK(PalStreamOpen("pipe.srv:1", PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, + /*options=*/0, &handle)); + CHECK(PalSendHandle(child_process, handle)); + PalObjectClose(handle); - CHECK(DkStreamOpen("pipe:1", PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, - /*options=*/0, &handle)); + CHECK(PalStreamOpen("pipe:1", PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED, + /*options=*/0, &handle)); recv_and_check(handle, PAL_TYPE_PIPE); - DkObjectClose(handle); + PalObjectClose(handle); /* TCP socket */ - CHECK(DkSocketCreate(PAL_IPV4, PAL_SOCKET_TCP, /*options=*/0, &handle)); + CHECK(PalSocketCreate(PAL_IPV4, PAL_SOCKET_TCP, /*options=*/0, &handle)); struct pal_socket_addr addr = { .domain = PAL_IPV4, .ipv4 = { @@ -111,18 +111,18 @@ static void do_parent(void) { }, }; set_reuseaddr(handle); - CHECK(DkSocketBind(handle, &addr)); - CHECK(DkSocketListen(handle, /*backlog=*/3)); - CHECK(DkSendHandle(child_process, handle)); - DkObjectClose(handle); + CHECK(PalSocketBind(handle, &addr)); + CHECK(PalSocketListen(handle, /*backlog=*/3)); + CHECK(PalSendHandle(child_process, handle)); + PalObjectClose(handle); - CHECK(DkSocketCreate(PAL_IPV4, PAL_SOCKET_TCP, /*options=*/0, &handle)); - CHECK(DkSocketConnect(handle, &addr, /*local_addr=*/NULL)); + CHECK(PalSocketCreate(PAL_IPV4, PAL_SOCKET_TCP, /*options=*/0, &handle)); + CHECK(PalSocketConnect(handle, &addr, /*local_addr=*/NULL)); recv_and_check(handle, PAL_TYPE_SOCKET); - DkObjectClose(handle); + PalObjectClose(handle); /* UDP IPv6 socket */ - CHECK(DkSocketCreate(PAL_IPV6, PAL_SOCKET_UDP, /*options=*/0, &handle)); + CHECK(PalSocketCreate(PAL_IPV6, PAL_SOCKET_UDP, /*options=*/0, &handle)); addr = (struct pal_socket_addr) { .domain = PAL_IPV6, .ipv6 = { @@ -131,50 +131,50 @@ static void do_parent(void) { }, }; set_reuseaddr(handle); - CHECK(DkSocketBind(handle, &addr)); - CHECK(DkSendHandle(child_process, handle)); - DkObjectClose(handle); + CHECK(PalSocketBind(handle, &addr)); + CHECK(PalSendHandle(child_process, handle)); + PalObjectClose(handle); - CHECK(DkSocketCreate(PAL_IPV6, PAL_SOCKET_UDP, /*options=*/0, &handle)); - CHECK(DkSocketConnect(handle, &addr, /*local_addr=*/NULL)); + CHECK(PalSocketCreate(PAL_IPV6, PAL_SOCKET_UDP, /*options=*/0, &handle)); + CHECK(PalSocketConnect(handle, &addr, /*local_addr=*/NULL)); write_msg(handle, PAL_TYPE_SOCKET); - DkObjectClose(handle); + PalObjectClose(handle); /* file handle */ - CHECK(DkStreamOpen("file:to_send.tmp", PAL_ACCESS_RDWR, /*share_flags=*/0600, PAL_CREATE_TRY, - /*options=*/0, &handle)); + CHECK(PalStreamOpen("file:to_send.tmp", PAL_ACCESS_RDWR, /*share_flags=*/0600, PAL_CREATE_TRY, + /*options=*/0, &handle)); write_msg(handle, PAL_TYPE_FILE); - CHECK(DkSendHandle(child_process, handle)); - DkObjectClose(handle); + CHECK(PalSendHandle(child_process, handle)); + PalObjectClose(handle); } static void do_child(void) { PAL_HANDLE handle; /* pipe.srv handle */ - CHECK(DkReceiveHandle(DkGetPalPublicState()->parent_process, &handle)); + CHECK(PalReceiveHandle(PalGetPalPublicState()->parent_process, &handle)); PAL_HANDLE client_handle; - CHECK(DkStreamWaitForClient(handle, &client_handle, /*options=*/0)); - DkObjectClose(handle); + CHECK(PalStreamWaitForClient(handle, &client_handle, /*options=*/0)); + PalObjectClose(handle); write_msg(client_handle, PAL_TYPE_PIPECLI); - DkObjectClose(client_handle); + PalObjectClose(client_handle); /* TCP socket */ - CHECK(DkReceiveHandle(DkGetPalPublicState()->parent_process, &handle)); - CHECK(DkSocketAccept(handle, /*options=*/0, &client_handle, /*out_client_addr=*/NULL)); - DkObjectClose(handle); + CHECK(PalReceiveHandle(PalGetPalPublicState()->parent_process, &handle)); + CHECK(PalSocketAccept(handle, /*options=*/0, &client_handle, /*out_client_addr=*/NULL)); + PalObjectClose(handle); write_msg(client_handle, PAL_TYPE_SOCKET); - DkObjectClose(client_handle); + PalObjectClose(client_handle); /* UDP IPv6 socket */ - CHECK(DkReceiveHandle(DkGetPalPublicState()->parent_process, &handle)); + CHECK(PalReceiveHandle(PalGetPalPublicState()->parent_process, &handle)); recv_and_check(handle, PAL_TYPE_SOCKET); - DkObjectClose(handle); + PalObjectClose(handle); /* file handle */ - CHECK(DkReceiveHandle(DkGetPalPublicState()->parent_process, &handle)); + CHECK(PalReceiveHandle(PalGetPalPublicState()->parent_process, &handle)); recv_and_check(handle, PAL_TYPE_FILE); - DkObjectClose(handle); + PalObjectClose(handle); } int main(int argc, char* argv[]) { diff --git a/pal/regression/test_pal.py b/pal/regression/test_pal.py index df4134c935..83d650771e 100644 --- a/pal/regression/test_pal.py +++ b/pal/regression/test_pal.py @@ -144,45 +144,45 @@ def test_140_missing_executable_and_manifest(self): class TC_02_Symbols(RegressionTestCase): ALL_SYMBOLS = [ - 'DkVirtualMemoryAlloc', - 'DkVirtualMemoryFree', - 'DkVirtualMemoryProtect', - 'DkProcessCreate', - 'DkProcessExit', - 'DkStreamOpen', - 'DkStreamWaitForClient', - 'DkStreamRead', - 'DkStreamWrite', - 'DkStreamDelete', - 'DkStreamMap', - 'DkStreamUnmap', - 'DkStreamSetLength', - 'DkStreamFlush', - 'DkSendHandle', - 'DkReceiveHandle', - 'DkStreamAttributesQuery', - 'DkStreamAttributesQueryByHandle', - 'DkStreamAttributesSetByHandle', - 'DkStreamGetName', - 'DkStreamChangeName', - 'DkThreadCreate', - 'DkThreadYieldExecution', - 'DkThreadExit', - 'DkThreadResume', - 'DkSetExceptionHandler', - 'DkEventCreate', - 'DkEventSet', - 'DkEventClear', - 'DkEventWait', - 'DkStreamsWaitEvents', - 'DkObjectClose', - 'DkSystemTimeQuery', - 'DkRandomBitsRead', - 'DkMemoryAvailableQuota', + 'PalVirtualMemoryAlloc', + 'PalVirtualMemoryFree', + 'PalVirtualMemoryProtect', + 'PalProcessCreate', + 'PalProcessExit', + 'PalStreamOpen', + 'PalStreamWaitForClient', + 'PalStreamRead', + 'PalStreamWrite', + 'PalStreamDelete', + 'PalStreamMap', + 'PalStreamUnmap', + 'PalStreamSetLength', + 'PalStreamFlush', + 'PalSendHandle', + 'PalReceiveHandle', + 'PalStreamAttributesQuery', + 'PalStreamAttributesQueryByHandle', + 'PalStreamAttributesSetByHandle', + 'PalStreamGetName', + 'PalStreamChangeName', + 'PalThreadCreate', + 'PalThreadYieldExecution', + 'PalThreadExit', + 'PalThreadResume', + 'PalSetExceptionHandler', + 'PalEventCreate', + 'PalEventSet', + 'PalEventClear', + 'PalEventWait', + 'PalStreamsWaitEvents', + 'PalObjectClose', + 'PalSystemTimeQuery', + 'PalRandomBitsRead', + 'PalMemoryAvailableQuota', ] if ON_X86: - ALL_SYMBOLS.append('DkSegmentBaseGet') - ALL_SYMBOLS.append('DkSegmentBaseSet') + ALL_SYMBOLS.append('PalSegmentBaseGet') + ALL_SYMBOLS.append('PalSegmentBaseSet') def test_000_symbols(self): _, stderr = self.run_binary(['Symbols']) @@ -417,7 +417,7 @@ def test_510_thread2(self): # Thread Cleanup: Exit by return. self.assertIn('Thread 2 ok.', stderr) - # Thread Cleanup: Exit by DkThreadExit. + # Thread Cleanup: Exit by PalThreadExit. self.assertIn('Thread 3 ok.', stderr) self.assertNotIn('Exiting thread 3 failed.', stderr) @@ -431,7 +431,7 @@ def test_511_thread2_exitless(self): # Thread Cleanup: Exit by return. self.assertIn('Thread 2 ok.', stderr) - # Thread Cleanup: Exit by DkThreadExit. + # Thread Cleanup: Exit by PalThreadExit. self.assertIn('Thread 3 ok.', stderr) self.assertNotIn('Exiting thread 3 failed.', stderr) diff --git a/pal/regression/utils.c b/pal/regression/utils.c index 291cdb3dae..2973161369 100644 --- a/pal/regression/utils.c +++ b/pal/regression/utils.c @@ -5,7 +5,7 @@ // pal_printf() is required by PAL regression tests. static int buf_write_all(const char* str, size_t size, void* arg) { __UNUSED(arg); - DkDebugLog(str, size); + PalDebugLog(str, size); return 0; } @@ -36,7 +36,7 @@ void _log(int level, const char* fmt, ...) { } noreturn void abort(void) { - DkProcessExit(131); /* ENOTRECOVERABLE = 131 */ + PalProcessExit(131); /* ENOTRECOVERABLE = 131 */ } /* We just need these symbols for `printf`, but they won't be used in runtime. */ diff --git a/pal/src/arch/x86_64/pal_cpuid.c b/pal/src/arch/x86_64/pal_cpuid.c index 1fe7745d51..6034f871c7 100644 --- a/pal/src/arch/x86_64/pal_cpuid.c +++ b/pal/src/arch/x86_64/pal_cpuid.c @@ -55,7 +55,7 @@ static const char* const g_cpu_flags[] = { "pbe", // "pending break event" }; -int _DkGetCPUInfo(struct pal_cpu_info* ci) { +int _PalGetCPUInfo(struct pal_cpu_info* ci) { unsigned int words[CPUID_WORD_NUM]; int rv = 0; char* flags = NULL; @@ -67,7 +67,7 @@ int _DkGetCPUInfo(struct pal_cpu_info* ci) { if (!vendor_id) return -PAL_ERROR_NOMEM; - _DkCpuIdRetrieve(0, 0, words); + _PalCpuIdRetrieve(0, 0, words); FOUR_CHARS_VALUE(&vendor_id[0], words[CPUID_WORD_EBX]); FOUR_CHARS_VALUE(&vendor_id[4], words[CPUID_WORD_EDX]); FOUR_CHARS_VALUE(&vendor_id[8], words[CPUID_WORD_ECX]); @@ -80,16 +80,16 @@ int _DkGetCPUInfo(struct pal_cpu_info* ci) { rv = -PAL_ERROR_NOMEM; goto out_err; } - _DkCpuIdRetrieve(0x80000002, 0, words); + _PalCpuIdRetrieve(0x80000002, 0, words); memcpy(&brand[ 0], words, sizeof(unsigned int) * CPUID_WORD_NUM); - _DkCpuIdRetrieve(0x80000003, 0, words); + _PalCpuIdRetrieve(0x80000003, 0, words); memcpy(&brand[16], words, sizeof(unsigned int) * CPUID_WORD_NUM); - _DkCpuIdRetrieve(0x80000004, 0, words); + _PalCpuIdRetrieve(0x80000004, 0, words); memcpy(&brand[32], words, sizeof(unsigned int) * CPUID_WORD_NUM); brand[BRAND_SIZE - 1] = '\0'; ci->cpu_brand = brand; - _DkCpuIdRetrieve(1, 0, words); + _PalCpuIdRetrieve(1, 0, words); ci->cpu_family = BIT_EXTRACT_LE(words[CPUID_WORD_EAX], 8, 12); ci->cpu_model = BIT_EXTRACT_LE(words[CPUID_WORD_EAX], 4, 8); ci->cpu_stepping = BIT_EXTRACT_LE(words[CPUID_WORD_EAX], 0, 4); @@ -133,7 +133,7 @@ int _DkGetCPUInfo(struct pal_cpu_info* ci) { flags[flen ? flen - 1 : 0] = 0; ci->cpu_flags = flags; - ci->cpu_bogomips = _DkGetBogomips(); + ci->cpu_bogomips = _PalGetBogomips(); if (ci->cpu_bogomips == 0.0) { log_warning("bogomips could not be retrieved, passing 0.0 to the application"); } diff --git a/pal/src/db_events.c b/pal/src/db_events.c index 33d7a8bee6..3e5dfc8841 100644 --- a/pal/src/db_events.c +++ b/pal/src/db_events.c @@ -7,22 +7,22 @@ #include "pal.h" #include "pal_internal.h" -int DkEventCreate(PAL_HANDLE* handle, bool init_signaled, bool auto_clear) { +int PalEventCreate(PAL_HANDLE* handle, bool init_signaled, bool auto_clear) { *handle = NULL; - return _DkEventCreate(handle, init_signaled, auto_clear); + return _PalEventCreate(handle, init_signaled, auto_clear); } -void DkEventSet(PAL_HANDLE handle) { +void PalEventSet(PAL_HANDLE handle) { assert(handle && HANDLE_HDR(handle)->type == PAL_TYPE_EVENT); - _DkEventSet(handle); + _PalEventSet(handle); } -void DkEventClear(PAL_HANDLE handle) { +void PalEventClear(PAL_HANDLE handle) { assert(handle && HANDLE_HDR(handle)->type == PAL_TYPE_EVENT); - _DkEventClear(handle); + _PalEventClear(handle); } -int DkEventWait(PAL_HANDLE handle, uint64_t* timeout_us) { +int PalEventWait(PAL_HANDLE handle, uint64_t* timeout_us) { assert(handle && HANDLE_HDR(handle)->type == PAL_TYPE_EVENT); - return _DkEventWait(handle, timeout_us); + return _PalEventWait(handle, timeout_us); } diff --git a/pal/src/db_exception.c b/pal/src/db_exception.c index e12f8ee2cb..bd0a2a791c 100644 --- a/pal/src/db_exception.c +++ b/pal/src/db_exception.c @@ -13,11 +13,11 @@ static pal_event_handler_t g_handlers[PAL_EVENT_NUM_BOUND] = {0}; -pal_event_handler_t _DkGetExceptionHandler(enum pal_event event) { +pal_event_handler_t _PalGetExceptionHandler(enum pal_event event) { return __atomic_load_n(&g_handlers[event], __ATOMIC_ACQUIRE); } -void DkSetExceptionHandler(pal_event_handler_t handler, enum pal_event event) { +void PalSetExceptionHandler(pal_event_handler_t handler, enum pal_event event) { assert(handler && event != PAL_EVENT_NO_EVENT && event < ARRAY_SIZE(g_handlers)); __atomic_store_n(&g_handlers[event], handler, __ATOMIC_RELEASE); @@ -27,7 +27,7 @@ void DkSetExceptionHandler(pal_event_handler_t handler, enum pal_event event) { * functions and by assert.h's assert() defined in the common library. Thus it might be called by * any PAL thread. */ noreturn void pal_abort(void) { - _DkProcessExit(1); + _PalProcessExit(1); } const char* pal_event_name(enum pal_event event) { diff --git a/pal/src/db_main.c b/pal/src/db_main.c index cc14007efe..01bb15a661 100644 --- a/pal/src/db_main.c +++ b/pal/src/db_main.c @@ -23,7 +23,7 @@ struct pal_public_state g_pal_public_state = { .log_level = PAL_LOG_DEFAULT_LEVEL, }; -struct pal_public_state* DkGetPalPublicState(void) { +struct pal_public_state* PalGetPalPublicState(void) { return &g_pal_public_state; } @@ -295,7 +295,7 @@ static void configure_logging(void) { INIT_FAIL_MANIFEST("Cannot parse 'loader.log_file'"); if (log_file && log_level > LOG_LEVEL_NONE) { - ret = _DkInitDebugStream(log_file); + ret = _PalInitDebugStream(log_file); if (ret < 0) INIT_FAIL("Cannot open log file: %d", ret); @@ -315,11 +315,11 @@ static int load_cstring_array(const char* uri, const char*** res) { const char** array = NULL; int ret; - ret = _DkStreamOpen(&hdl, uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, - /*options=*/0); + ret = _PalStreamOpen(&hdl, uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, + /*options=*/0); if (ret < 0) return ret; - ret = _DkStreamAttributesQueryByHandle(hdl, &attr); + ret = _PalStreamAttributesQueryByHandle(hdl, &attr); if (ret < 0) goto out_fail; size_t file_size = attr.pending_size; @@ -328,7 +328,7 @@ static int load_cstring_array(const char* uri, const char*** res) { ret = -PAL_ERROR_NOMEM; goto out_fail; } - ret = _DkStreamRead(hdl, 0, file_size, buf, NULL, 0); + ret = _PalStreamRead(hdl, 0, file_size, buf, NULL, 0); if (ret < 0) goto out_fail; if (file_size > 0 && buf[file_size - 1] != '\0') { @@ -354,10 +354,10 @@ static int load_cstring_array(const char* uri, const char*** res) { *(argv_it++) = buf + i + 1; } *res = array; - return _DkObjectClose(hdl); + return _PalObjectClose(hdl); out_fail: - (void)_DkObjectClose(hdl); + (void)_PalObjectClose(hdl); free(buf); free(array); return ret; @@ -374,7 +374,7 @@ noreturn void pal_main(uint64_t instance_id, /* current instance id */ const char** environments /* environment variables */) { if (!instance_id) { assert(!parent_process); - if (_DkRandomBitsRead(&instance_id, sizeof(instance_id)) < 0) { + if (_PalRandomBitsRead(&instance_id, sizeof(instance_id)) < 0) { INIT_FAIL("Could not generate random instance_id"); } } @@ -520,13 +520,13 @@ noreturn void pal_main(uint64_t instance_id, /* current instance id */ g_pal_public_state.first_thread = first_thread; g_pal_public_state.disable_aslr = disable_aslr; - _DkGetAvailableUserAddressRange(&g_pal_public_state.user_address_start, - &g_pal_public_state.user_address_end); + _PalGetAvailableUserAddressRange(&g_pal_public_state.user_address_start, + &g_pal_public_state.user_address_end); - if (_DkGetCPUInfo(&g_pal_public_state.cpu_info) < 0) { + if (_PalGetCPUInfo(&g_pal_public_state.cpu_info) < 0) { goto out_fail; } - g_pal_public_state.mem_total = _DkMemoryQuota(); + g_pal_public_state.mem_total = _PalMemoryQuota(); if (toml_key_exists(g_pal_public_state.manifest_root, "fs.experimental__enable_sysfs_topology")) { diff --git a/pal/src/db_memory.c b/pal/src/db_memory.c index ad89b74dbe..25139a8b73 100644 --- a/pal/src/db_memory.c +++ b/pal/src/db_memory.c @@ -10,8 +10,8 @@ #include "pal_error.h" #include "pal_internal.h" -int DkVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_type, - pal_prot_flags_t prot) { +int PalVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_type, + pal_prot_flags_t prot) { assert(addr_ptr); void* map_addr = *addr_ptr; @@ -19,7 +19,7 @@ int DkVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_t return -PAL_ERROR_INVAL; } - if (map_addr && _DkCheckMemoryMappable(map_addr, size)) { + if (map_addr && _PalCheckMemoryMappable(map_addr, size)) { return -PAL_ERROR_DENIED; } @@ -31,10 +31,10 @@ int DkVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_t return -PAL_ERROR_INVAL; } - return _DkVirtualMemoryAlloc(addr_ptr, size, alloc_type, prot); + return _PalVirtualMemoryAlloc(addr_ptr, size, alloc_type, prot); } -int DkVirtualMemoryFree(void* addr, size_t size) { +int PalVirtualMemoryFree(void* addr, size_t size) { if (!addr || !size) { return -PAL_ERROR_INVAL; } @@ -43,14 +43,14 @@ int DkVirtualMemoryFree(void* addr, size_t size) { return -PAL_ERROR_INVAL; } - if (_DkCheckMemoryMappable(addr, size)) { + if (_PalCheckMemoryMappable(addr, size)) { return -PAL_ERROR_DENIED; } - return _DkVirtualMemoryFree(addr, size); + return _PalVirtualMemoryFree(addr, size); } -int DkVirtualMemoryProtect(void* addr, size_t size, pal_prot_flags_t prot) { +int PalVirtualMemoryProtect(void* addr, size_t size, pal_prot_flags_t prot) { if (!addr || !size) { return -PAL_ERROR_INVAL; } @@ -59,11 +59,11 @@ int DkVirtualMemoryProtect(void* addr, size_t size, pal_prot_flags_t prot) { return -PAL_ERROR_INVAL; } - if (_DkCheckMemoryMappable(addr, size)) { + if (_PalCheckMemoryMappable(addr, size)) { return -PAL_ERROR_DENIED; } - return _DkVirtualMemoryProtect(addr, size, prot); + return _PalVirtualMemoryProtect(addr, size, prot); } int add_preloaded_range(uintptr_t start, uintptr_t end, const char* comment) { diff --git a/pal/src/db_misc.c b/pal/src/db_misc.c index 0c3e2d839d..b78e813f45 100644 --- a/pal/src/db_misc.c +++ b/pal/src/db_misc.c @@ -8,46 +8,46 @@ #include "pal.h" #include "pal_internal.h" -int DkSystemTimeQuery(uint64_t* time) { - return _DkSystemTimeQuery(time); +int PalSystemTimeQuery(uint64_t* time) { + return _PalSystemTimeQuery(time); } -int DkRandomBitsRead(void* buffer, size_t size) { - return _DkRandomBitsRead(buffer, size); +int PalRandomBitsRead(void* buffer, size_t size) { + return _PalRandomBitsRead(buffer, size); } #if defined(__x86_64__) -int DkSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { - return _DkSegmentBaseGet(reg, addr); +int PalSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { + return _PalSegmentBaseGet(reg, addr); } -int DkSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr) { - return _DkSegmentBaseSet(reg, addr); +int PalSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr) { + return _PalSegmentBaseSet(reg, addr); } #endif -size_t DkMemoryAvailableQuota(void) { - return _DkMemoryAvailableQuota(); +size_t PalMemoryAvailableQuota(void) { + return _PalMemoryAvailableQuota(); } #if defined(__x86_64__) -int DkCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) { - return _DkCpuIdRetrieve(leaf, subleaf, values); +int PalCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) { + return _PalCpuIdRetrieve(leaf, subleaf, values); } #endif -int DkAttestationReport(const void* user_report_data, size_t* user_report_data_size, - void* target_info, size_t* target_info_size, void* report, - size_t* report_size) { - return _DkAttestationReport(user_report_data, user_report_data_size, target_info, +int PalAttestationReport(const void* user_report_data, size_t* user_report_data_size, + void* target_info, size_t* target_info_size, void* report, + size_t* report_size) { + return _PalAttestationReport(user_report_data, user_report_data_size, target_info, target_info_size, report, report_size); } -int DkAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, - size_t* quote_size) { - return _DkAttestationQuote(user_report_data, user_report_data_size, quote, quote_size); +int PalAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, + size_t* quote_size) { + return _PalAttestationQuote(user_report_data, user_report_data_size, quote, quote_size); } -int DkGetSpecialKey(const char* name, void* key, size_t* key_size) { - return _DkGetSpecialKey(name, key, key_size); +int PalGetSpecialKey(const char* name, void* key, size_t* key_size) { + return _PalGetSpecialKey(name, key, key_size); } diff --git a/pal/src/db_object.c b/pal/src/db_object.c index 83b232ed1c..fc5752b2e1 100644 --- a/pal/src/db_object.c +++ b/pal/src/db_object.c @@ -9,7 +9,7 @@ #include "pal_error.h" #include "pal_internal.h" -int _DkObjectClose(PAL_HANDLE object_handle) { +int _PalObjectClose(PAL_HANDLE object_handle) { const struct handle_ops* ops = HANDLE_OPS(object_handle); if (!ops) return -PAL_ERROR_BADHANDLE; @@ -22,7 +22,7 @@ int _DkObjectClose(PAL_HANDLE object_handle) { /* * Chia-Che 12/7/2017: - * _DkObjectClose will free the object, unless the handle has a 'close' operation, and the + * _PalObjectClose will free the object, unless the handle has a 'close' operation, and the * operation returns a non-zero value (e.g., 1 for skipping free() or -ERRNO). */ if (!ret) @@ -32,24 +32,24 @@ int _DkObjectClose(PAL_HANDLE object_handle) { } /* - * TODO: whole LibOS assumes this never returns errors. We need to either make `_DkObjectClose` + * TODO: whole LibOS assumes this never returns errors. We need to either make `_PalObjectClose` * never fail (from a quick look at the code, seems like it cannot return errors in practice) or * make this return an `int` and handle errors in all call sites (hard to do; in most places we * cannot handle them in a meaningful way). */ -/* PAL call DkObjectClose: Close the given object handle. */ -void DkObjectClose(PAL_HANDLE object_handle) { +/* PAL call PalObjectClose: Close the given object handle. */ +void PalObjectClose(PAL_HANDLE object_handle) { assert(object_handle); - _DkObjectClose(object_handle); + _PalObjectClose(object_handle); } -int DkStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, - pal_wait_flags_t* ret_events, uint64_t* timeout_us) { +int PalStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, + pal_wait_flags_t* ret_events, uint64_t* timeout_us) { for (size_t i = 0; i < count; i++) { assert(handle_array[i]); assert(!UNKNOWN_HANDLE(handle_array[i])); } - return _DkStreamsWaitEvents(count, handle_array, events, ret_events, timeout_us); + return _PalStreamsWaitEvents(count, handle_array, events, ret_events, timeout_us); } diff --git a/pal/src/db_process.c b/pal/src/db_process.c index 08e5f4f3dd..deaf5a2a21 100644 --- a/pal/src/db_process.c +++ b/pal/src/db_process.c @@ -12,12 +12,12 @@ #include "pal.h" #include "pal_internal.h" -int DkProcessCreate(const char** args, PAL_HANDLE* handle) { +int PalProcessCreate(const char** args, PAL_HANDLE* handle) { *handle = NULL; - return _DkProcessCreate(handle, args); + return _PalProcessCreate(handle, args); } -noreturn void DkProcessExit(int exitcode) { - _DkProcessExit(exitcode); +noreturn void PalProcessExit(int exitcode) { + _PalProcessExit(exitcode); die_or_inf_loop(); } diff --git a/pal/src/db_rtld.c b/pal/src/db_rtld.c index eab495a422..7f98a4acd8 100644 --- a/pal/src/db_rtld.c +++ b/pal/src/db_rtld.c @@ -286,7 +286,7 @@ static int perform_relocations(struct link_map* map) { } /* `elf_file_buf` contains the beginning of ELF file (at least ELF header and all program headers); - * we don't bother undoing _DkStreamMap() and _DkVirtualMemoryAlloc() in case of failure. */ + * we don't bother undoing _PalStreamMap() and _PalVirtualMemoryAlloc() in case of failure. */ static int create_and_relocate_entrypoint(PAL_HANDLE handle, const char* elf_file_buf) { int ret; struct loadcmd* loadcmds = NULL; @@ -294,7 +294,7 @@ static int create_and_relocate_entrypoint(PAL_HANDLE handle, const char* elf_fil elf_addr_t l_relro_addr = 0x0; size_t l_relro_size = 0; - const char* name = _DkStreamRealpath(handle); + const char* name = _PalStreamRealpath(handle); if (!name) return -PAL_ERROR_INVAL; @@ -381,14 +381,14 @@ static int create_and_relocate_entrypoint(PAL_HANDLE handle, const char* elf_fil * Note that we allocate memory to cover LOAD segments starting from offset 0, not from the * first segment's p_vaddr. This is to ensure that l_base_diff will not be less than 0. * - * FIXME: We (ab)use _DkStreamMap() because _DkVirtualMemoryAlloc() cannot be used to + * FIXME: We (ab)use _PalStreamMap() because _PalVirtualMemoryAlloc() cannot be used to * allocate memory at PAL-chosen address (it expects `map_addr` to be fixed). Note * that `PAL_PROT_WRITECOPY` is specified to prevent allocating memory in untrusted * memory in case of Linux-SGX PAL (see linux-sgx/db_files.c:file_map). */ void* map_addr = NULL; - ret = _DkStreamMap(handle, &map_addr, /*prot=*/PAL_PROT_WRITECOPY, /*offset=*/0, - loadcmds[loadcmds_cnt - 1].alloc_end); + ret = _PalStreamMap(handle, &map_addr, /*prot=*/PAL_PROT_WRITECOPY, /*offset=*/0, + loadcmds[loadcmds_cnt - 1].alloc_end); if (ret < 0) { log_error("Failed to allocate memory for all LOAD segments of DYN ELF file"); goto out; @@ -408,7 +408,7 @@ static int create_and_relocate_entrypoint(PAL_HANDLE handle, const char* elf_fil void* map_addr = (void*)(c->start + g_entrypoint_map.l_base_diff); size_t map_size = c->map_end - c->start; - ret = _DkStreamMap(handle, &map_addr, c->prot | PAL_PROT_WRITECOPY, c->map_off, map_size); + ret = _PalStreamMap(handle, &map_addr, c->prot | PAL_PROT_WRITECOPY, c->map_off, map_size); if (ret < 0) { log_error("Failed to map segment from ELF file"); goto out; @@ -424,7 +424,8 @@ static int create_and_relocate_entrypoint(PAL_HANDLE handle, const char* elf_fil continue; void* map_rest = (void*)c->map_end; - ret = _DkVirtualMemoryAlloc(&map_rest, c->alloc_end - c->map_end, /*alloc_type=*/0, c->prot); + ret = _PalVirtualMemoryAlloc(&map_rest, c->alloc_end - c->map_end, /*alloc_type=*/0, + c->prot); if (ret < 0) { log_error("Failed to zero-fill the rest of segment from ELF file"); goto out; @@ -447,15 +448,15 @@ static int create_and_relocate_entrypoint(PAL_HANDLE handle, const char* elf_fil * (need to first change memory permissions to writable and then revert permissions back) */ for (size_t i = 0; i < loadcmds_cnt; i++) { struct loadcmd* c = &loadcmds[i]; - ret = _DkVirtualMemoryProtect((void*)c->start, c->alloc_end - c->start, - c->prot | PAL_PROT_WRITE); + ret = _PalVirtualMemoryProtect((void*)c->start, c->alloc_end - c->start, + c->prot | PAL_PROT_WRITE); if (ret < 0) { log_error("Failed to add write memory protection on the segment from ELF file"); goto out; } /* zero out uninitialized but allocated part of the loaded segment (note that part of - * segment allocated via _DkVirtualMemoryAlloc() is already zeroed out) */ + * segment allocated via _PalVirtualMemoryAlloc() is already zeroed out) */ if (ALLOC_ALIGN_UP(c->data_end) > c->data_end) memset((void*)c->data_end, 0, ALLOC_ALIGN_UP(c->data_end) - c->data_end); } @@ -468,7 +469,7 @@ static int create_and_relocate_entrypoint(PAL_HANDLE handle, const char* elf_fil for (size_t i = 0; i < loadcmds_cnt; i++) { struct loadcmd* c = &loadcmds[i]; - ret = _DkVirtualMemoryProtect((void*)c->start, c->alloc_end - c->start, c->prot); + ret = _PalVirtualMemoryProtect((void*)c->start, c->alloc_end - c->start, c->prot); if (ret < 0) { log_error("Failed to revert write memory protection on the segment from ELF file"); goto out; @@ -479,7 +480,7 @@ static int create_and_relocate_entrypoint(PAL_HANDLE handle, const char* elf_fil l_relro_addr += g_entrypoint_map.l_base_diff; elf_addr_t start = ALLOC_ALIGN_DOWN(l_relro_addr); elf_addr_t end = ALLOC_ALIGN_UP(l_relro_addr + l_relro_size); - ret = _DkVirtualMemoryProtect((void*)start, end - start, PAL_PROT_READ); + ret = _PalVirtualMemoryProtect((void*)start, end - start, PAL_PROT_READ); if (ret < 0) { log_error("Failed to apply read-only memory protection on the RELRO memory area"); goto out; @@ -501,12 +502,12 @@ int load_entrypoint(const char* uri) { PAL_HANDLE handle; char buf[1024]; /* must be enough to hold ELF header and all its program headers */ - ret = _DkStreamOpen(&handle, uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, - /*options=*/0); + ret = _PalStreamOpen(&handle, uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER, + /*options=*/0); if (ret < 0) return ret; - ret = _DkStreamRead(handle, 0, sizeof(buf), buf, NULL, 0); + ret = _PalStreamRead(handle, 0, sizeof(buf), buf, NULL, 0); if (ret < 0) { log_error("Reading ELF file failed"); goto out; @@ -555,11 +556,11 @@ int load_entrypoint(const char* uri) { #ifdef DEBUG assert(g_entrypoint_map.l_name); - _DkDebugMapAdd(g_entrypoint_map.l_name, (void*)g_entrypoint_map.l_base_diff); + _PalDebugMapAdd(g_entrypoint_map.l_name, (void*)g_entrypoint_map.l_base_diff); #endif out: - _DkObjectClose(handle); + _PalObjectClose(handle); return ret; } @@ -610,7 +611,7 @@ void set_pal_binary_name(const char* name) { * a result, if we load a binary that is an encrypted file, it will be reported here, but GDB (and * other tools) will fail to load it. */ -void DkDebugMapAdd(const char* uri, void* start_addr) { +void PalDebugMapAdd(const char* uri, void* start_addr) { #ifndef DEBUG __UNUSED(uri); __UNUSED(start_addr); @@ -620,25 +621,25 @@ void DkDebugMapAdd(const char* uri, void* start_addr) { const char* realname = uri + URI_PREFIX_FILE_LEN; - _DkDebugMapAdd(realname, start_addr); + _PalDebugMapAdd(realname, start_addr); #endif } -void DkDebugMapRemove(void* start_addr) { +void PalDebugMapRemove(void* start_addr) { #ifndef DEBUG __UNUSED(start_addr); #else - _DkDebugMapRemove(start_addr); + _PalDebugMapRemove(start_addr); #endif } -void DkDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size) { +void PalDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size) { pal_describe_location(addr, buf, buf_size); } void pal_describe_location(uintptr_t addr, char* buf, size_t buf_size) { #ifdef DEBUG - if (_DkDebugDescribeLocation(addr, buf, buf_size) == 0) + if (_PalDebugDescribeLocation(addr, buf, buf_size) == 0) return; #endif default_describe_location(addr, buf, buf_size); diff --git a/pal/src/db_sockets.c b/pal/src/db_sockets.c index 1f7b202231..1a8f2c9184 100644 --- a/pal/src/db_sockets.c +++ b/pal/src/db_sockets.c @@ -6,41 +6,41 @@ #include "pal.h" #include "pal_internal.h" -int DkSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, - pal_stream_options_t options, PAL_HANDLE* out_handle) { - return _DkSocketCreate(domain, type, options, out_handle); +int PalSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, + pal_stream_options_t options, PAL_HANDLE* out_handle) { + return _PalSocketCreate(domain, type, options, out_handle); } -int DkSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { +int PalSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { assert(PAL_GET_TYPE(handle) == PAL_TYPE_SOCKET); - return _DkSocketBind(handle, addr); + return _PalSocketBind(handle, addr); } -int DkSocketListen(PAL_HANDLE handle, unsigned int backlog) { +int PalSocketListen(PAL_HANDLE handle, unsigned int backlog) { assert(PAL_GET_TYPE(handle) == PAL_TYPE_SOCKET); - return _DkSocketListen(handle, backlog); + return _PalSocketListen(handle, backlog); } -int DkSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, - struct pal_socket_addr* out_client_addr) { +int PalSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, + struct pal_socket_addr* out_client_addr) { assert(PAL_GET_TYPE(handle) == PAL_TYPE_SOCKET); - return _DkSocketAccept(handle, options, out_client, out_client_addr); + return _PalSocketAccept(handle, options, out_client, out_client_addr); } -int DkSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, - struct pal_socket_addr* local_addr) { +int PalSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, + struct pal_socket_addr* local_addr) { assert(PAL_GET_TYPE(handle) == PAL_TYPE_SOCKET); - return _DkSocketConnect(handle, addr, local_addr); + return _PalSocketConnect(handle, addr, local_addr); } -int DkSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, - struct pal_socket_addr* addr) { +int PalSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, + struct pal_socket_addr* addr) { assert(PAL_GET_TYPE(handle) == PAL_TYPE_SOCKET); - return _DkSocketSend(handle, iov, iov_len, out_size, addr); + return _PalSocketSend(handle, iov, iov_len, out_size, addr); } -int DkSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, - struct pal_socket_addr* addr, bool force_nonblocking) { +int PalSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, + struct pal_socket_addr* addr, bool force_nonblocking) { assert(PAL_GET_TYPE(handle) == PAL_TYPE_SOCKET); - return _DkSocketRecv(handle, iov, iov_len, out_total_size, addr, force_nonblocking); + return _PalSocketRecv(handle, iov, iov_len, out_total_size, addr, force_nonblocking); } diff --git a/pal/src/db_streams.c b/pal/src/db_streams.c index fbea800c74..4d16835c58 100644 --- a/pal/src/db_streams.c +++ b/pal/src/db_streams.c @@ -108,9 +108,9 @@ static int parse_stream_uri(const char** uri, char** prefix, struct handle_ops** return 0; } -int _DkStreamOpen(PAL_HANDLE* handle, const char* uri, enum pal_access access, - pal_share_flags_t share, enum pal_create_mode create, - pal_stream_options_t options) { +int _PalStreamOpen(PAL_HANDLE* handle, const char* uri, enum pal_access access, + pal_share_flags_t share, enum pal_create_mode create, + pal_stream_options_t options) { struct handle_ops* ops = NULL; char* type = NULL; @@ -127,21 +127,21 @@ int _DkStreamOpen(PAL_HANDLE* handle, const char* uri, enum pal_access access, return ret; } -/* PAL call DkStreamOpen: Open stream based on uri, as given access/share/ - * create/options flags. DkStreamOpen return a PAL_HANDLE to access the +/* PAL call PalStreamOpen: Open stream based on uri, as given access/share/ + * create/options flags. PalStreamOpen return a PAL_HANDLE to access the * stream in `handle` argument. * * FIXME: Currently `share` must match 1-1 to Linux open() `mode` argument. This isn't really * portable and will cause problems when implementing other PALs. */ -int DkStreamOpen(const char* uri, enum pal_access access, pal_share_flags_t share, - enum pal_create_mode create, pal_stream_options_t options, PAL_HANDLE* handle) { +int PalStreamOpen(const char* uri, enum pal_access access, pal_share_flags_t share, + enum pal_create_mode create, pal_stream_options_t options, PAL_HANDLE* handle) { *handle = NULL; - return _DkStreamOpen(handle, uri, access, share, create, options); + return _PalStreamOpen(handle, uri, access, share, create, options); } -static int _DkStreamWaitForClient(PAL_HANDLE handle, PAL_HANDLE* client, - pal_stream_options_t options) { +static int _PalStreamWaitForClient(PAL_HANDLE handle, PAL_HANDLE* client, + pal_stream_options_t options) { if (UNKNOWN_HANDLE(handle)) return -PAL_ERROR_BADHANDLE; @@ -155,12 +155,12 @@ static int _DkStreamWaitForClient(PAL_HANDLE handle, PAL_HANDLE* client, return ops->waitforclient(handle, client, options); } -int DkStreamWaitForClient(PAL_HANDLE handle, PAL_HANDLE* client, pal_stream_options_t options) { +int PalStreamWaitForClient(PAL_HANDLE handle, PAL_HANDLE* client, pal_stream_options_t options) { *client = NULL; - return _DkStreamWaitForClient(handle, client, options); + return _PalStreamWaitForClient(handle, client, options); } -int _DkStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode) { +int _PalStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode) { const struct handle_ops* ops = HANDLE_OPS(handle); if (!ops) @@ -172,16 +172,16 @@ int _DkStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode) { return ops->delete(handle, delete_mode); } -int DkStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode) { +int PalStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode) { assert(handle); - return _DkStreamDelete(handle, delete_mode); + return _PalStreamDelete(handle, delete_mode); } -/* _DkStreamRead for internal use. Read from stream as absolute offset. - The actual behavior of stream read is defined by handler */ -int64_t _DkStreamRead(PAL_HANDLE handle, uint64_t offset, uint64_t count, void* buf, char* addr, - int addrlen) { +/* _PalStreamRead for internal use. Read from stream as absolute offset. + * The actual behavior of stream read is defined by handler */ +int64_t _PalStreamRead(PAL_HANDLE handle, uint64_t offset, uint64_t count, void* buf, char* addr, + int addrlen) { const struct handle_ops* ops = HANDLE_OPS(handle); if (!ops) @@ -204,14 +204,14 @@ int64_t _DkStreamRead(PAL_HANDLE handle, uint64_t offset, uint64_t count, void* return ret; } -int DkStreamRead(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer, char* source, - size_t size) { +int PalStreamRead(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer, char* source, + size_t size) { if (!handle) { return -PAL_ERROR_INVAL; } - int64_t ret = _DkStreamRead(handle, offset, *count, buffer, size ? source : NULL, - source ? size : 0); + int64_t ret = _PalStreamRead(handle, offset, *count, buffer, size ? source : NULL, + source ? size : 0); if (ret < 0) { return ret; @@ -221,10 +221,10 @@ int DkStreamRead(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer return 0; } -/* _DkStreamWrite for internal use, write to stream at absolute offset. +/* _PalStreamWrite for internal use, write to stream at absolute offset. * The actual behavior of stream write is defined by handler. */ -int64_t _DkStreamWrite(PAL_HANDLE handle, uint64_t offset, uint64_t count, const void* buf, - const char* addr, int addrlen) { +int64_t _PalStreamWrite(PAL_HANDLE handle, uint64_t offset, uint64_t count, const void* buf, + const char* addr, int addrlen) { const struct handle_ops* ops = HANDLE_OPS(handle); if (!ops) @@ -247,13 +247,13 @@ int64_t _DkStreamWrite(PAL_HANDLE handle, uint64_t offset, uint64_t count, const return ret; } -int DkStreamWrite(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer, - const char* dest) { +int PalStreamWrite(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer, + const char* dest) { if (!handle) { return -PAL_ERROR_INVAL; } - int64_t ret = _DkStreamWrite(handle, offset, *count, buffer, dest, dest ? strlen(dest) : 0); + int64_t ret = _PalStreamWrite(handle, offset, *count, buffer, dest, dest ? strlen(dest) : 0); if (ret < 0) { return ret; @@ -263,9 +263,9 @@ int DkStreamWrite(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffe return 0; } -/* _DkStreamAttributesQuery of internal use. The function query attribute - of streams by their URI */ -int _DkStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr) { +/* _PalStreamAttributesQuery of internal use. The function query attribute of streams by their + * URI */ +int _PalStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr) { struct handle_ops* ops = NULL; char* type = NULL; @@ -284,14 +284,14 @@ int _DkStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr) { return ret; } -int DkStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr) { +int PalStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr) { if (!uri || !attr) { return -PAL_ERROR_INVAL; } PAL_STREAM_ATTR attr_buf; - int ret = _DkStreamAttributesQuery(uri, &attr_buf); + int ret = _PalStreamAttributesQuery(uri, &attr_buf); if (ret < 0) { return ret; @@ -301,9 +301,9 @@ int DkStreamAttributesQuery(const char* uri, PAL_STREAM_ATTR* attr) { return 0; } -/* _DkStreamAttributesQueryByHandle for internal use. Query attribute - of streams by their handle */ -int _DkStreamAttributesQueryByHandle(PAL_HANDLE hdl, PAL_STREAM_ATTR* attr) { +/* _PalStreamAttributesQueryByHandle for internal use. Query attribute of streams by their + * handle */ +int _PalStreamAttributesQueryByHandle(PAL_HANDLE hdl, PAL_STREAM_ATTR* attr) { const struct handle_ops* ops = HANDLE_OPS(hdl); if (!ops) @@ -315,15 +315,15 @@ int _DkStreamAttributesQueryByHandle(PAL_HANDLE hdl, PAL_STREAM_ATTR* attr) { return ops->attrquerybyhdl(hdl, attr); } -int DkStreamAttributesQueryByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) { +int PalStreamAttributesQueryByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) { if (!handle || !attr) { return -PAL_ERROR_INVAL; } - return _DkStreamAttributesQueryByHandle(handle, attr); + return _PalStreamAttributesQueryByHandle(handle, attr); } -int DkStreamAttributesSetByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) { +int PalStreamAttributesSetByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) { if (!handle || !attr) { return -PAL_ERROR_INVAL; } @@ -340,7 +340,7 @@ int DkStreamAttributesSetByHandle(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) { return ops->attrsetbyhdl(handle, attr); } -int _DkStreamGetName(PAL_HANDLE handle, char* buffer, size_t size) { +int _PalStreamGetName(PAL_HANDLE handle, char* buffer, size_t size) { const struct handle_ops* ops = HANDLE_OPS(handle); if (!ops) @@ -358,18 +358,18 @@ int _DkStreamGetName(PAL_HANDLE handle, char* buffer, size_t size) { return ret; } -int DkStreamGetName(PAL_HANDLE handle, char* buffer, size_t size) { +int PalStreamGetName(PAL_HANDLE handle, char* buffer, size_t size) { if (!handle || !buffer || !size) { return -PAL_ERROR_INVAL; } - return _DkStreamGetName(handle, buffer, size); + return _PalStreamGetName(handle, buffer, size); } -/* _DkStreamMap for internal use. Map specific handle to certain memory, - with given protection, offset and size */ -int _DkStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint64_t offset, - uint64_t size) { +/* _PalStreamMap for internal use. Map specific handle to certain memory, with given protection, + * offset and size */ +int _PalStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint64_t offset, + uint64_t size) { assert(IS_ALLOC_ALIGNED(offset)); void* addr = *addr_ptr; int ret; @@ -391,8 +391,8 @@ int _DkStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint return 0; } -int DkStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint64_t offset, - size_t size) { +int PalStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint64_t offset, + size_t size) { assert(addr_ptr); void* map_addr = *addr_ptr; @@ -412,28 +412,28 @@ int DkStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, uint6 return -PAL_ERROR_INVAL; } - if (_DkCheckMemoryMappable(map_addr, size)) { + if (_PalCheckMemoryMappable(map_addr, size)) { return -PAL_ERROR_DENIED; } - return _DkStreamMap(handle, addr_ptr, prot, offset, size); + return _PalStreamMap(handle, addr_ptr, prot, offset, size); } -int DkStreamUnmap(void* addr, size_t size) { +int PalStreamUnmap(void* addr, size_t size) { if (!addr || !IS_ALLOC_ALIGNED_PTR(addr) || !size || !IS_ALLOC_ALIGNED(size)) { return -PAL_ERROR_INVAL; } - if (_DkCheckMemoryMappable(addr, size)) { + if (_PalCheckMemoryMappable(addr, size)) { return -PAL_ERROR_DENIED; } - return _DkStreamUnmap(addr, size); + return _PalStreamUnmap(addr, size); } -/* _DkStreamSetLength for internal use. This function truncate the stream - to certain length. This call might not be support for certain streams */ -int64_t _DkStreamSetLength(PAL_HANDLE handle, uint64_t length) { +/* _PalStreamSetLength for internal use. This function truncate the stream to certain length. This + * call might not be support for certain streams */ +int64_t _PalStreamSetLength(PAL_HANDLE handle, uint64_t length) { const struct handle_ops* ops = HANDLE_OPS(handle); if (!ops) @@ -445,12 +445,12 @@ int64_t _DkStreamSetLength(PAL_HANDLE handle, uint64_t length) { return ops->setlength(handle, length); } -int DkStreamSetLength(PAL_HANDLE handle, uint64_t length) { +int PalStreamSetLength(PAL_HANDLE handle, uint64_t length) { if (!handle) { return -PAL_ERROR_INVAL; } - int64_t ret = _DkStreamSetLength(handle, length); + int64_t ret = _PalStreamSetLength(handle, length); if (ret < 0) { return ret; @@ -460,9 +460,9 @@ int DkStreamSetLength(PAL_HANDLE handle, uint64_t length) { return 0; } -/* _DkStreamFlush for internal use. This function sync up the handle with - devices. Some streams may not support this operations. */ -int _DkStreamFlush(PAL_HANDLE handle) { +/* _PalStreamFlush for internal use. This function sync up the handle with devices. Some streams may + * not support this operations. */ +int _PalStreamFlush(PAL_HANDLE handle) { if (UNKNOWN_HANDLE(handle)) return -PAL_ERROR_BADHANDLE; @@ -477,32 +477,32 @@ int _DkStreamFlush(PAL_HANDLE handle) { return ops->flush(handle); } -int DkStreamFlush(PAL_HANDLE handle) { +int PalStreamFlush(PAL_HANDLE handle) { if (!handle) { return -PAL_ERROR_INVAL; } - return _DkStreamFlush(handle); + return _PalStreamFlush(handle); } -int DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { +int PalSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { if (!target_process || !cargo) { return -PAL_ERROR_INVAL; } - return _DkSendHandle(target_process, cargo); + return _PalSendHandle(target_process, cargo); } -int DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { +int PalReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { if (!source_process) { return -PAL_ERROR_INVAL; } *out_cargo = NULL; - return _DkReceiveHandle(source_process, out_cargo); + return _PalReceiveHandle(source_process, out_cargo); } -int DkStreamChangeName(PAL_HANDLE hdl, const char* uri) { +int PalStreamChangeName(PAL_HANDLE hdl, const char* uri) { struct handle_ops* ops = NULL; char* type = NULL; int ret; @@ -527,9 +527,9 @@ int DkStreamChangeName(PAL_HANDLE hdl, const char* uri) { return ret; } -/* _DkStreamRealpath is used to obtain the real path of a stream. Some - streams may not have a real path. */ -const char* _DkStreamRealpath(PAL_HANDLE hdl) { +/* _PalStreamRealpath is used to obtain the real path of a stream. Some streams may not have a real + * path. */ +const char* _PalStreamRealpath(PAL_HANDLE hdl) { const struct handle_ops* ops = HANDLE_OPS(hdl); if (!ops || !ops->getrealpath) @@ -538,6 +538,6 @@ const char* _DkStreamRealpath(PAL_HANDLE hdl) { return ops->getrealpath(hdl); } -int DkDebugLog(const void* buffer, size_t size) { - return _DkDebugLog(buffer, size); +int PalDebugLog(const void* buffer, size_t size) { + return _PalDebugLog(buffer, size); } diff --git a/pal/src/db_threading.c b/pal/src/db_threading.c index 9ca289a8c1..853ee61668 100644 --- a/pal/src/db_threading.c +++ b/pal/src/db_threading.c @@ -9,36 +9,36 @@ #include "pal_error.h" #include "pal_internal.h" -/* PAL call DkThreadCreate: create a thread inside the current process */ -int DkThreadCreate(int (*callback)(void*), void* param, PAL_HANDLE* handle) { +/* PAL call PalThreadCreate: create a thread inside the current process */ +int PalThreadCreate(int (*callback)(void*), void* param, PAL_HANDLE* handle) { *handle = NULL; - return _DkThreadCreate(handle, callback, param); + return _PalThreadCreate(handle, callback, param); } -/* PAL call DkThreadYieldExecution. Yield the execution of the current thread. */ -void DkThreadYieldExecution(void) { - _DkThreadYieldExecution(); +/* PAL call PalThreadYieldExecution. Yield the execution of the current thread. */ +void PalThreadYieldExecution(void) { + _PalThreadYieldExecution(); } -/* PAL call DkThreadExit: simply exit the current thread no matter what */ -noreturn void DkThreadExit(int* clear_child_tid) { - _DkThreadExit(clear_child_tid); +/* PAL call PalThreadExit: simply exit the current thread no matter what */ +noreturn void PalThreadExit(int* clear_child_tid) { + _PalThreadExit(clear_child_tid); /* UNREACHABLE */ } -/* PAL call DkThreadResume: resume the execution of a thread which is delayed before */ -int DkThreadResume(PAL_HANDLE thread_handle) { +/* PAL call PalThreadResume: resume the execution of a thread which is delayed before */ +int PalThreadResume(PAL_HANDLE thread_handle) { if (!thread_handle || HANDLE_HDR(thread_handle)->type != PAL_TYPE_THREAD) { return -PAL_ERROR_INVAL; } - return _DkThreadResume(thread_handle); + return _PalThreadResume(thread_handle); } -int DkThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { - return _DkThreadSetCpuAffinity(thread, cpumask_size, cpu_mask); +int PalThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { + return _PalThreadSetCpuAffinity(thread, cpumask_size, cpu_mask); } -int DkThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { - return _DkThreadGetCpuAffinity(thread, cpumask_size, cpu_mask); +int PalThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { + return _PalThreadGetCpuAffinity(thread, cpumask_size, cpu_mask); } diff --git a/pal/src/host/linux-common/arch/x86_64/syscall.S b/pal/src/host/linux-common/arch/x86_64/syscall.S index b876a8fe86..073af39474 100644 --- a/pal/src/host/linux-common/arch/x86_64/syscall.S +++ b/pal/src/host/linux-common/arch/x86_64/syscall.S @@ -98,9 +98,9 @@ syscall_rt_sigreturn: syscall .cfi_endproc -.global _DkThreadExit_asm_stub -.type _DkThreadExit_asm_stub, @function -_DkThreadExit_asm_stub: +.global _PalThreadExit_asm_stub +.type _PalThreadExit_asm_stub, @function +_PalThreadExit_asm_stub: .cfi_startproc movl $0, (%rdi) /* spinlock_unlock(&g_thread_stack_lock) */ cmp $0, %rsi /* check if clear_child_tid != NULL */ diff --git a/pal/src/host/linux-common/bogomips.c b/pal/src/host/linux-common/bogomips.c index 1da869b314..95193a42df 100644 --- a/pal/src/host/linux-common/bogomips.c +++ b/pal/src/host/linux-common/bogomips.c @@ -57,7 +57,7 @@ static double sanitize_bogomips_value(double v) { return v; } -double _DkGetBogomips(void) { +double _PalGetBogomips(void) { /* Although the whole file might not fit in this size, the first cpu description should. */ char buf[2048]; ssize_t len; diff --git a/pal/src/host/linux-sgx/db_events.c b/pal/src/host/linux-sgx/db_events.c index ee52a62cbc..a0c7c25cb2 100644 --- a/pal/src/host/linux-sgx/db_events.c +++ b/pal/src/host/linux-sgx/db_events.c @@ -15,7 +15,7 @@ #include "pal_linux_error.h" #include "spinlock.h" -int _DkEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear) { +int _PalEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear) { PAL_HANDLE handle = calloc(1, HANDLE_SIZE(event)); if (!handle) { return -PAL_ERROR_NOMEM; @@ -37,7 +37,7 @@ int _DkEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear) return 0; } -void _DkEventSet(PAL_HANDLE handle) { +void _PalEventSet(PAL_HANDLE handle) { spinlock_lock(&handle->event.lock); handle->event.signaled = true; __atomic_store_n(handle->event.signaled_untrusted, 1, __ATOMIC_RELEASE); @@ -57,7 +57,7 @@ void _DkEventSet(PAL_HANDLE handle) { } } -void _DkEventClear(PAL_HANDLE handle) { +void _PalEventClear(PAL_HANDLE handle) { spinlock_lock(&handle->event.lock); handle->event.signaled = false; __atomic_store_n(handle->event.signaled_untrusted, 0, __ATOMIC_RELEASE); @@ -66,7 +66,7 @@ void _DkEventClear(PAL_HANDLE handle) { /* We use `handle->event.signaled` as the source of truth whether the event was signaled. * `handle->event.signaled_untrusted` acts only as a futex sleeping word. */ -int _DkEventWait(PAL_HANDLE handle, uint64_t* timeout_us) { +int _PalEventWait(PAL_HANDLE handle, uint64_t* timeout_us) { bool added_to_count = false; while (1) { spinlock_lock(&handle->event.lock); diff --git a/pal/src/host/linux-sgx/db_exception.c b/pal/src/host/linux-sgx/db_exception.c index 02fa377c29..fa11e62df0 100644 --- a/pal/src/host/linux-sgx/db_exception.c +++ b/pal/src/host/linux-sgx/db_exception.c @@ -120,10 +120,10 @@ static void emulate_rdtsc_and_print_warning(sgx_cpu_context_t* uc) { } uint64_t usec; - int res = _DkSystemTimeQuery(&usec); + int res = _PalSystemTimeQuery(&usec); if (res < 0) { - log_error("_DkSystemTimeQuery() failed in unrecoverable context, exiting."); - _DkProcessExit(1); + log_error("_PalSystemTimeQuery() failed in unrecoverable context, exiting."); + _PalProcessExit(1); } /* FIXME: Ideally, we would like to scale microseconds back to RDTSC clock cycles */ uc->rdx = (uint32_t)(usec >> 32); @@ -137,7 +137,7 @@ static bool handle_ud(sgx_cpu_context_t* uc) { if (instr[0] == 0x0f && instr[1] == 0xa2) { /* cpuid */ unsigned int values[4]; - if (!_DkCpuIdRetrieve(uc->rax & 0xffffffff, uc->rcx & 0xffffffff, values)) { + if (!_PalCpuIdRetrieve(uc->rax & 0xffffffff, uc->rcx & 0xffffffff, values)) { uc->rip += 2; uc->rax = values[0]; uc->rbx = values[1]; @@ -179,8 +179,8 @@ static bool handle_ud(sgx_cpu_context_t* uc) { } /* perform exception handling inside the enclave */ -void _DkExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, - PAL_XREGS_STATE* xregs_state) { +void _PalExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, + PAL_XREGS_STATE* xregs_state) { assert(IS_ALIGNED_PTR(xregs_state, PAL_XSTATE_ALIGN)); union { @@ -194,13 +194,13 @@ void _DkExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, event_num = exit_info; if (event_num <= 0 || event_num >= PAL_EVENT_NUM_BOUND) { log_error("Illegal exception reported by untrusted PAL: %d", event_num); - _DkProcessExit(1); + _PalProcessExit(1); } } else { switch (ei.info.vector) { case SGX_EXCEPTION_VECTOR_BR: log_error("Handling #BR exceptions is currently unsupported by Gramine"); - _DkProcessExit(1); + _PalProcessExit(1); break; case SGX_EXCEPTION_VECTOR_UD: if (handle_ud(uc)) { @@ -241,7 +241,7 @@ void _DkExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, log_debug("(untrusted PAL sent PAL event 0x%x)", ei.intval); } - _DkProcessExit(1); + _PalProcessExit(1); } PAL_CONTEXT ctx; @@ -265,7 +265,7 @@ void _DkExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, break; } - pal_event_handler_t upcall = _DkGetExceptionHandler(event_num); + pal_event_handler_t upcall = _PalGetExceptionHandler(event_num); if (upcall) { (*upcall)(ADDR_IN_PAL(uc->rip), addr, &ctx); } @@ -276,20 +276,20 @@ void _DkExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, /* TODO: remove this function (SGX signal handling needs to be revisited) * actually what is the point of this function? * Tracked in https://github.com/gramineproject/gramine/issues/84. */ -noreturn void _DkHandleExternalEvent(long event_, sgx_cpu_context_t* uc, - PAL_XREGS_STATE* xregs_state) { +noreturn void _PalHandleExternalEvent(long event_, sgx_cpu_context_t* uc, + PAL_XREGS_STATE* xregs_state) { assert(IS_ALIGNED_PTR(xregs_state, PAL_XSTATE_ALIGN)); enum pal_event event = event_; if (event != PAL_EVENT_QUIT && event != PAL_EVENT_INTERRUPTED) { log_error("Illegal exception reported by untrusted PAL: %d", event); - _DkProcessExit(1); + _PalProcessExit(1); } PAL_CONTEXT ctx; save_pal_context(&ctx, uc, xregs_state); - pal_event_handler_t upcall = _DkGetExceptionHandler(event); + pal_event_handler_t upcall = _PalGetExceptionHandler(event); if (upcall) { (*upcall)(ADDR_IN_PAL(uc->rip), /*addr=*/0, &ctx); } diff --git a/pal/src/host/linux-sgx/db_main.c b/pal/src/host/linux-sgx/db_main.c index 2b1a26789c..342467e733 100644 --- a/pal/src/host/linux-sgx/db_main.c +++ b/pal/src/host/linux-sgx/db_main.c @@ -30,12 +30,12 @@ struct pal_linuxsgx_state g_pal_linuxsgx_state; PAL_SESSION_KEY g_master_key = {0}; -/* Limit of PAL memory available for _DkVirtualMemoryAlloc(PAL_ALLOC_INTERNAL) */ +/* Limit of PAL memory available for _PalVirtualMemoryAlloc(PAL_ALLOC_INTERNAL) */ size_t g_pal_internal_mem_size = PAL_INITIAL_MEM_SIZE; const size_t g_page_size = PRESET_PAGESIZE; -void _DkGetAvailableUserAddressRange(void** out_start, void** out_end) { +void _PalGetAvailableUserAddressRange(void** out_start, void** out_end) { *out_start = g_pal_linuxsgx_state.heap_min; *out_end = g_pal_linuxsgx_state.heap_max; @@ -428,9 +428,9 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* } uint64_t start_time; - ret = _DkSystemTimeQuery(&start_time); + ret = _PalSystemTimeQuery(&start_time); if (ret < 0) { - log_error("_DkSystemTimeQuery() failed: %d", ret); + log_error("_PalSystemTimeQuery() failed: %d", ret); ocall_exit(1, /*is_exitgroup=*/true); } @@ -475,7 +475,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* } /* Set up page allocator and slab manager. There is no need to provide any initial memory pool, - * because the slab manager can use normal allocations (`_DkVirtualMemoryAlloc`) right away. */ + * because the slab manager can use normal allocations (`_PalVirtualMemoryAlloc`) right away. */ init_slab_mgr(/*mem_pool=*/NULL, /*mem_pool_size=*/0); init_untrusted_slab_mgr(); @@ -514,9 +514,9 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* /* initialize master key (used for pipes' encryption for all enclaves of an application); it * will be overwritten below in init_child_process() with inherited-from-parent master key if * this enclave is child */ - ret = _DkRandomBitsRead(&g_master_key, sizeof(g_master_key)); + ret = _PalRandomBitsRead(&g_master_key, sizeof(g_master_key)); if (ret < 0) { - log_error("_DkRandomBitsRead failed: %d", ret); + log_error("_PalRandomBitsRead failed: %d", ret); ocall_exit(1, /*is_exitgroup=*/true); } @@ -651,9 +651,9 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* SET_ENCLAVE_TLS(thread, &first_thread->thread); uint64_t stack_protector_canary; - ret = _DkRandomBitsRead(&stack_protector_canary, sizeof(stack_protector_canary)); + ret = _PalRandomBitsRead(&stack_protector_canary, sizeof(stack_protector_canary)); if (ret < 0) { - log_error("_DkRandomBitsRead failed: %d", ret); + log_error("_PalRandomBitsRead failed: %d", ret); ocall_exit(1, /*is_exitgroup=*/true); } pal_set_tcb_stack_canary(stack_protector_canary); diff --git a/pal/src/host/linux-sgx/db_memory.c b/pal/src/host/linux-sgx/db_memory.c index 85984616c6..017ee89a41 100644 --- a/pal/src/host/linux-sgx/db_memory.c +++ b/pal/src/host/linux-sgx/db_memory.c @@ -15,20 +15,20 @@ extern struct atomic_int g_allocated_pages; -bool _DkCheckMemoryMappable(const void* addr, size_t size) { +bool _PalCheckMemoryMappable(const void* addr, size_t size) { if (addr < DATA_END && addr + size > TEXT_START) { log_error("Address %p-%p is not mappable", addr, addr + size); return true; } - /* FIXME: this function is almost useless now; note that _DkVirtualMemoryAlloc() checks whether + /* FIXME: this function is almost useless now; note that _PalVirtualMemoryAlloc() checks whether * [addr, addr + size) overlaps with VMAs and errors out */ return false; } -int _DkVirtualMemoryAlloc(void** addr_ptr, uint64_t size, pal_alloc_flags_t alloc_type, - pal_prot_flags_t prot) { +int _PalVirtualMemoryAlloc(void** addr_ptr, uint64_t size, pal_alloc_flags_t alloc_type, + pal_prot_flags_t prot) { __UNUSED(prot); assert(WITHIN_MASK(alloc_type, PAL_ALLOC_MASK)); @@ -50,7 +50,7 @@ int _DkVirtualMemoryAlloc(void** addr_ptr, uint64_t size, pal_alloc_flags_t allo return 0; } -int _DkVirtualMemoryFree(void* addr, uint64_t size) { +int _PalVirtualMemoryFree(void* addr, uint64_t size) { if (sgx_is_completely_within_enclave(addr, size)) { int ret = free_enclave_pages(addr, size); if (ret < 0) { @@ -63,7 +63,7 @@ int _DkVirtualMemoryFree(void* addr, uint64_t size) { return 0; } -int _DkVirtualMemoryProtect(void* addr, uint64_t size, pal_prot_flags_t prot) { +int _PalVirtualMemoryProtect(void* addr, uint64_t size, pal_prot_flags_t prot) { __UNUSED(addr); __UNUSED(size); __UNUSED(prot); @@ -84,15 +84,15 @@ int _DkVirtualMemoryProtect(void* addr, uint64_t size, pal_prot_flags_t prot) { int64_t t = 0; if (__atomic_compare_exchange_n(&at_cnt.counter, &t, 1, /*weak=*/false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED)) - log_warning("DkVirtualMemoryProtect is unimplemented in Linux-SGX PAL"); + log_warning("PalVirtualMemoryProtect is unimplemented in Linux-SGX PAL"); return 0; } -uint64_t _DkMemoryQuota(void) { +uint64_t _PalMemoryQuota(void) { return g_pal_linuxsgx_state.heap_max - g_pal_linuxsgx_state.heap_min; } -uint64_t _DkMemoryAvailableQuota(void) { +uint64_t _PalMemoryAvailableQuota(void) { return (g_pal_linuxsgx_state.heap_max - g_pal_linuxsgx_state.heap_min) - __atomic_load_n(&g_allocated_pages.counter, __ATOMIC_SEQ_CST) * g_page_size; } diff --git a/pal/src/host/linux-sgx/db_misc.c b/pal/src/host/linux-sgx/db_misc.c index 1e61108555..a97ba00c2c 100644 --- a/pal/src/host/linux-sgx/db_misc.c +++ b/pal/src/host/linux-sgx/db_misc.c @@ -48,7 +48,7 @@ void init_tsc(void) { } /* TODO: result comes from the untrusted host, introduce some schielding */ -int _DkSystemTimeQuery(uint64_t* out_usec) { +int _PalSystemTimeQuery(uint64_t* out_usec) { int ret; if (!g_tsc_hz) { @@ -273,14 +273,14 @@ static void sanitize_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) if (values[CPUID_WORD_EDX] != 0) { log_error("Non-null EDX value in Processor Extended State Enum CPUID leaf"); - _DkProcessExit(1); + _PalProcessExit(1); } if (extension_enabled(xfrm, subleaf)) { if (values[CPUID_WORD_EAX] != g_cpu_extension_sizes[subleaf] || values[CPUID_WORD_EBX] != g_cpu_extension_offsets[subleaf]) { log_error("Unexpected values in Processor Extended State Enum CPUID leaf"); - _DkProcessExit(1); + _PalProcessExit(1); } } else { /* SGX enclave doesn't use this CPU extension, pretend it doesn't exist by @@ -298,7 +298,7 @@ static void sanitize_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) if (!IS_IN_RANGE_INCL(values[CPUID_WORD_EAX], 1, 16) || values[CPUID_WORD_EBX] != 0 || values[CPUID_WORD_ECX] != 0 || values[CPUID_WORD_EDX] != 0) { log_error("Unexpected values in Tile Information CPUID Leaf (subleaf=0x0)"); - _DkProcessExit(1); + _PalProcessExit(1); } } else { /* EAX = 1DH, ECX > 0: subleaf for each supported palette, returns palette limits */ @@ -315,7 +315,7 @@ static void sanitize_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) || (values[CPUID_WORD_ECX] >> 16) != 0 || values[CPUID_WORD_EDX] != 0) { log_error("Unexpected values in Tile Information CPUID Leaf (subleaf=%#x)", subleaf); - _DkProcessExit(1); + _PalProcessExit(1); } } } else if (leaf == AMX_TMUL_INFO_LEAF) { @@ -329,7 +329,7 @@ static void sanitize_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) || values[CPUID_WORD_ECX] != 0 || values[CPUID_WORD_EDX] != 0) { log_error("Unexpected values in TMUL Information CPUID Leaf"); - _DkProcessExit(1); + _PalProcessExit(1); } } } @@ -337,10 +337,10 @@ static void sanitize_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) struct cpuid_leaf { unsigned int leaf; bool zero_subleaf; /* if subleaf is not used by this leaf, then CPUID instruction expects it to - be explicitly zeroed out (see _DkCpuIdRetrieve() implementation below) */ + * be explicitly zeroed out (see _PalCpuIdRetrieve() implementation below) */ bool cache; /* if leaf + subleaf pair is constant across all cores and sockets, then we - can add the returned CPUID values of this pair to the local cache (see - _DkCpuIdRetrieve() implementation below) */ + * can add the returned CPUID values of this pair to the local cache (see + * _PalCpuIdRetrieve() implementation below) */ }; /* NOTE: some CPUID leaves/subleaves may theoretically return different values when accessed from @@ -399,7 +399,7 @@ static const struct cpuid_leaf cpuid_known_leaves[] = { /* extended CPUID leaf functions end here */ }; -int _DkCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) { +int _PalCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) { uint64_t xfrm = g_pal_linuxsgx_state.enclave_info.attributes.xfrm; /* A few basic leaves are considered reserved and always return zeros; see corresponding EAX @@ -473,12 +473,12 @@ int _DkCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) { return 0; fail: log_error("Unrecognized leaf/subleaf in CPUID (EAX=0x%x, ECX=0x%x). Exiting...", leaf, subleaf); - _DkProcessExit(1); + _PalProcessExit(1); } -int _DkAttestationReport(const void* user_report_data, size_t* user_report_data_size, - void* target_info, size_t* target_info_size, void* report, - size_t* report_size) { +int _PalAttestationReport(const void* user_report_data, size_t* user_report_data_size, + void* target_info, size_t* target_info_size, void* report, + size_t* report_size) { __sgx_mem_aligned sgx_report_data_t stack_report_data = {0}; __sgx_mem_aligned sgx_target_info_t stack_target_info = {0}; __sgx_mem_aligned sgx_report_t stack_report = {0}; @@ -533,8 +533,8 @@ int _DkAttestationReport(const void* user_report_data, size_t* user_report_data_ return 0; } -int _DkAttestationQuote(const void* user_report_data, size_t user_report_data_size, - void* quote, size_t* quote_size) { +int _PalAttestationQuote(const void* user_report_data, size_t user_report_data_size, + void* quote, size_t* quote_size) { int ret; if (user_report_data_size != sizeof(sgx_report_data_t)) @@ -559,7 +559,7 @@ int _DkAttestationQuote(const void* user_report_data, size_t user_report_data_si } sgx_quote_nonce_t nonce; - ret = _DkRandomBitsRead(&nonce, sizeof(nonce)); + ret = _PalRandomBitsRead(&nonce, sizeof(nonce)); if (ret < 0) return ret; @@ -587,7 +587,7 @@ int _DkAttestationQuote(const void* user_report_data, size_t user_report_data_si return 0; } -int _DkGetSpecialKey(const char* name, void* key, size_t* key_size) { +int _PalGetSpecialKey(const char* name, void* key, size_t* key_size) { sgx_key_128bit_t sgx_key; if (*key_size < sizeof(sgx_key)) @@ -630,7 +630,7 @@ ssize_t read_file_buffer(const char* filename, char* buf, size_t buf_size) { bool is_tsc_usable(void) { uint32_t words[CPUID_WORD_NUM]; - _DkCpuIdRetrieve(CPUID_LEAF_INVARIANT_TSC, 0, words); + _PalCpuIdRetrieve(CPUID_LEAF_INVARIANT_TSC, 0, words); return words[CPUID_WORD_EDX] & 1 << 8; } @@ -638,7 +638,7 @@ bool is_tsc_usable(void) { uint64_t get_tsc_hz(void) { uint32_t words[CPUID_WORD_NUM]; - _DkCpuIdRetrieve(CPUID_LEAF_TSC_FREQ, 0, words); + _PalCpuIdRetrieve(CPUID_LEAF_TSC_FREQ, 0, words); if (!words[CPUID_WORD_EAX] || !words[CPUID_WORD_EBX]) { /* TSC/core crystal clock ratio is not enumerated, can't use RDTSC for accurate time */ return 0; @@ -654,7 +654,7 @@ uint64_t get_tsc_hz(void) { /* some Intel CPUs do not report nominal frequency of crystal clock, let's calculate it * based on Processor Frequency Information Leaf (CPUID 16H); this leaf always exists if * TSC Frequency Leaf exists; logic is taken from Linux 5.11's arch/x86/kernel/tsc.c */ - _DkCpuIdRetrieve(CPUID_LEAF_PROC_FREQ, 0, words); + _PalCpuIdRetrieve(CPUID_LEAF_PROC_FREQ, 0, words); if (!words[CPUID_WORD_EAX]) { /* processor base frequency (in MHz) is not enumerated, can't calculate frequency */ return 0; @@ -666,7 +666,7 @@ uint64_t get_tsc_hz(void) { return base_frequency_mhz * 1000000; } -int _DkRandomBitsRead(void* buffer, size_t size) { +int _PalRandomBitsRead(void* buffer, size_t size) { uint32_t rand; for (size_t i = 0; i < size; i += sizeof(rand)) { rand = rdrand(); @@ -675,7 +675,7 @@ int _DkRandomBitsRead(void* buffer, size_t size) { return 0; } -int _DkSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { +int _PalSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { switch (reg) { case PAL_SEGMENT_FS: *addr = GET_ENCLAVE_TLS(fsbase); @@ -688,7 +688,7 @@ int _DkSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { } } -int _DkSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr) { +int _PalSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr) { switch (reg) { case PAL_SEGMENT_FS: SET_ENCLAVE_TLS(fsbase, addr); diff --git a/pal/src/host/linux-sgx/db_object.c b/pal/src/host/linux-sgx/db_object.c index 9583b12e78..57a970341d 100644 --- a/pal/src/host/linux-sgx/db_object.c +++ b/pal/src/host/linux-sgx/db_object.c @@ -13,8 +13,8 @@ #include "pal_internal.h" #include "pal_linux_error.h" -int _DkStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, - pal_wait_flags_t* ret_events, uint64_t* timeout_us) { +int _PalStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, + pal_wait_flags_t* ret_events, uint64_t* timeout_us) { if (count == 0) return 0; diff --git a/pal/src/host/linux-sgx/db_pipes.c b/pal/src/host/linux-sgx/db_pipes.c index 955d6f7abb..64685b690e 100644 --- a/pal/src/host/linux-sgx/db_pipes.c +++ b/pal/src/host/linux-sgx/db_pipes.c @@ -53,23 +53,23 @@ static noreturn int thread_handshake_func(void* param) { LISTP_FOR_EACH_ENTRY_SAFE(thread_to_gc, tmp, &g_handshake_helper_thread_list, list) { if (__atomic_load_n(&thread_to_gc->clear_on_thread_exit, __ATOMIC_ACQUIRE) == 0) { LISTP_DEL(thread_to_gc, &g_handshake_helper_thread_list, list); - _DkObjectClose(thread_to_gc->thread_hdl); + _PalObjectClose(thread_to_gc->thread_hdl); free(thread_to_gc); } } spinlock_unlock(&g_handshake_helper_thread_list_lock); - int ret = _DkStreamSecureInit(handle, handle->pipe.is_server, &handle->pipe.session_key, - (LIB_SSL_CONTEXT**)&handle->pipe.ssl_ctx, NULL, 0); + int ret = _PalStreamSecureInit(handle, handle->pipe.is_server, &handle->pipe.session_key, + (LIB_SSL_CONTEXT**)&handle->pipe.ssl_ctx, NULL, 0); if (ret < 0) { log_error("Failed to initialize secure pipe %s: %d", handle->pipe.name.str, ret); - _DkProcessExit(1); + _PalProcessExit(1); } struct handshake_helper_thread* thread = malloc(sizeof(*thread)); if (!thread) { log_error("Failed to allocate helper handshake thread list item"); - _DkProcessExit(1); + _PalProcessExit(1); } /* parent thread associates this child thread with the pipe handle during `pipe_connect()` */ @@ -87,7 +87,7 @@ static noreturn int thread_handshake_func(void* param) { spinlock_unlock(&g_handshake_helper_thread_list_lock); __atomic_store_n(&handle->pipe.handshake_done, true, __ATOMIC_RELEASE); - _DkThreadExit(/*clear_child_tid=*/&thread->clear_on_thread_exit); + _PalThreadExit(/*clear_child_tid=*/&thread->clear_on_thread_exit); /* UNREACHABLE */ } @@ -198,8 +198,8 @@ static int pipe_waitforclient(PAL_HANDLE handle, PAL_HANDLE* client, pal_stream_ return -PAL_ERROR_DENIED; } - ret = _DkStreamSecureInit(clnt, clnt->pipe.is_server, &clnt->pipe.session_key, - (LIB_SSL_CONTEXT**)&clnt->pipe.ssl_ctx, NULL, 0); + ret = _PalStreamSecureInit(clnt, clnt->pipe.is_server, &clnt->pipe.session_key, + (LIB_SSL_CONTEXT**)&clnt->pipe.ssl_ctx, NULL, 0); if (ret < 0) { ocall_close(clnt->pipe.fd); free(clnt); @@ -273,7 +273,7 @@ static int pipe_connect(PAL_HANDLE* handle, const char* name, pal_stream_options * and assumes that client and server are two parallel entities (e.g., two threads) */ PAL_HANDLE thread_hdl; - ret = _DkThreadCreate(&thread_hdl, thread_handshake_func, /*param=*/hdl); + ret = _PalThreadCreate(&thread_hdl, thread_handshake_func, /*param=*/hdl); if (ret < 0) { ocall_close(hdl->pipe.fd); free(hdl); @@ -354,8 +354,8 @@ static int64_t pipe_read(PAL_HANDLE handle, uint64_t offset, uint64_t len, void* if (!handle->pipe.ssl_ctx) return -PAL_ERROR_NOTCONNECTION; - bytes = _DkStreamSecureRead(handle->pipe.ssl_ctx, buffer, len, - /*is_blocking=*/!handle->pipe.nonblocking); + bytes = _PalStreamSecureRead(handle->pipe.ssl_ctx, buffer, len, + /*is_blocking=*/!handle->pipe.nonblocking); return bytes; } @@ -384,8 +384,8 @@ static int64_t pipe_write(PAL_HANDLE handle, uint64_t offset, uint64_t len, cons if (!handle->pipe.ssl_ctx) return -PAL_ERROR_NOTCONNECTION; - bytes = _DkStreamSecureWrite(handle->pipe.ssl_ctx, buffer, len, - /*is_blocking=*/!handle->pipe.nonblocking); + bytes = _PalStreamSecureWrite(handle->pipe.ssl_ctx, buffer, len, + /*is_blocking=*/!handle->pipe.nonblocking); return bytes; } @@ -402,7 +402,7 @@ static int pipe_close(PAL_HANDLE handle) { CPU_RELAX(); if (handle->pipe.ssl_ctx) { - _DkStreamSecureFree((LIB_SSL_CONTEXT*)handle->pipe.ssl_ctx); + _PalStreamSecureFree((LIB_SSL_CONTEXT*)handle->pipe.ssl_ctx); handle->pipe.ssl_ctx = NULL; } ocall_close(handle->pipe.fd); diff --git a/pal/src/host/linux-sgx/db_process.c b/pal/src/host/linux-sgx/db_process.c index 0793e9dc53..2c986a20d7 100644 --- a/pal/src/host/linux-sgx/db_process.c +++ b/pal/src/host/linux-sgx/db_process.c @@ -68,7 +68,7 @@ * * (1) A session key needs to be shared only between the parent and child enclaves. * - * See the implementation in _DkStreamKeyExchange(). When initializing a secure stream, both + * See the implementation in _PalStreamKeyExchange(). When initializing a secure stream, both * ends of the stream needs to use Diffie-Hellman to establish a session key. The hashes over * the established DH session key are used to identify the connection (via SHA256(K_e || tag1) * for parent enclave A and via SHA256(K_e || tag2) for child enclave B to prevent @@ -77,7 +77,7 @@ * * (2) Both the parent and child enclaves need to be proven by the Intel CPU. * - * See the implementation in _DkStreamReportRequest() and _DkStreamReportRespond(). The two + * See the implementation in _PalStreamReportRequest() and _PalStreamReportRespond(). The two * ends of the stream need to exchange SGX local attestation reports signed by the Intel CPUs * to prove themselves to be running inside enclaves on the same platform. The local * attestation reports contain no secret information and can be verified cryptographically, @@ -126,7 +126,7 @@ bool is_peer_enclave_ok(sgx_report_body_t* peer_enclave_info, return true; } -int _DkProcessCreate(PAL_HANDLE* handle, const char** args) { +int _PalProcessCreate(PAL_HANDLE* handle, const char** args) { int stream_fd; int nargs = 0, ret; @@ -151,30 +151,30 @@ int _DkProcessCreate(PAL_HANDLE* handle, const char** args) { __sgx_mem_aligned sgx_report_data_t parent_report_data = {0}; __sgx_mem_aligned sgx_report_data_t child_report_data = {0}; - ret = _DkStreamKeyExchange(child, &child->process.session_key, &parent_report_data, - &child_report_data); + ret = _PalStreamKeyExchange(child, &child->process.session_key, &parent_report_data, + &child_report_data); if (ret < 0) goto failed; - ret = _DkStreamReportRequest(child, &parent_report_data, &child_report_data); + ret = _PalStreamReportRequest(child, &parent_report_data, &child_report_data); if (ret < 0) goto failed; - ret = _DkStreamSecureInit(child, child->process.is_server, &child->process.session_key, - (LIB_SSL_CONTEXT**)&child->process.ssl_ctx, NULL, 0); + ret = _PalStreamSecureInit(child, child->process.is_server, &child->process.session_key, + (LIB_SSL_CONTEXT**)&child->process.ssl_ctx, NULL, 0); if (ret < 0) goto failed; /* securely send the master key to child in the newly established SSL session */ - ret = _DkStreamSecureWrite(child->process.ssl_ctx, (uint8_t*)&g_master_key, - sizeof(g_master_key), /*is_blocking=*/!child->process.nonblocking); + ret = _PalStreamSecureWrite(child->process.ssl_ctx, (uint8_t*)&g_master_key, + sizeof(g_master_key), /*is_blocking=*/!child->process.nonblocking); if (ret != sizeof(g_master_key)) goto failed; /* Send this Gramine instance ID. */ uint64_t instance_id = g_pal_common_state.instance_id; - ret = _DkStreamSecureWrite(child->process.ssl_ctx, (uint8_t*)&instance_id, sizeof(instance_id), - /*is_blocking=*/!child->process.nonblocking); + ret = _PalStreamSecureWrite(child->process.ssl_ctx, (uint8_t*)&instance_id, sizeof(instance_id), + /*is_blocking=*/!child->process.nonblocking); if (ret != sizeof(instance_id)) { goto failed; } @@ -206,29 +206,29 @@ int init_child_process(int parent_stream_fd, PAL_HANDLE* out_parent_handle, __sgx_mem_aligned sgx_report_data_t child_report_data = {0}; __sgx_mem_aligned sgx_report_data_t parent_report_data = {0}; - int ret = _DkStreamKeyExchange(parent, &parent->process.session_key, - &parent_report_data, &child_report_data); + int ret = _PalStreamKeyExchange(parent, &parent->process.session_key, + &parent_report_data, &child_report_data); if (ret < 0) goto out_error; - ret = _DkStreamReportRespond(parent, &child_report_data, &parent_report_data); + ret = _PalStreamReportRespond(parent, &child_report_data, &parent_report_data); if (ret < 0) goto out_error; - ret = _DkStreamSecureInit(parent, parent->process.is_server, &parent->process.session_key, - (LIB_SSL_CONTEXT**)&parent->process.ssl_ctx, NULL, 0); + ret = _PalStreamSecureInit(parent, parent->process.is_server, &parent->process.session_key, + (LIB_SSL_CONTEXT**)&parent->process.ssl_ctx, NULL, 0); if (ret < 0) goto out_error; /* securely receive the master key from parent in the newly established SSL session */ - ret = _DkStreamSecureRead(parent->process.ssl_ctx, (uint8_t*)&g_master_key, - sizeof(g_master_key), /*is_blocking=*/!parent->process.nonblocking); + ret = _PalStreamSecureRead(parent->process.ssl_ctx, (uint8_t*)&g_master_key, + sizeof(g_master_key), /*is_blocking=*/!parent->process.nonblocking); if (ret != sizeof(g_master_key)) goto out_error; uint64_t instance_id; - ret = _DkStreamSecureRead(parent->process.ssl_ctx, (uint8_t*)&instance_id, sizeof(instance_id), - /*is_blocking=*/!parent->process.nonblocking); + ret = _PalStreamSecureRead(parent->process.ssl_ctx, (uint8_t*)&instance_id, sizeof(instance_id), + /*is_blocking=*/!parent->process.nonblocking); if (ret != sizeof(instance_id)) { goto out_error; } @@ -242,9 +242,9 @@ int init_child_process(int parent_stream_fd, PAL_HANDLE* out_parent_handle, return ret < 0 ? ret : -PAL_ERROR_DENIED; } -noreturn void _DkProcessExit(int exitcode) { +noreturn void _PalProcessExit(int exitcode) { if (exitcode) - log_debug("DkProcessExit: Returning exit code %d", exitcode); + log_debug("PalProcessExit: Returning exit code %d", exitcode); ocall_exit(exitcode, /*is_exitgroup=*/true); /* Unreachable. */ } @@ -255,8 +255,8 @@ static int64_t proc_read(PAL_HANDLE handle, uint64_t offset, uint64_t count, voi ssize_t bytes; if (handle->process.ssl_ctx) { - bytes = _DkStreamSecureRead(handle->process.ssl_ctx, buffer, count, - /*is_blocking=*/!handle->process.nonblocking); + bytes = _PalStreamSecureRead(handle->process.ssl_ctx, buffer, count, + /*is_blocking=*/!handle->process.nonblocking); } else { bytes = ocall_read(handle->process.stream, buffer, count); bytes = bytes < 0 ? unix_to_pal_error(bytes) : bytes; @@ -271,8 +271,8 @@ static int64_t proc_write(PAL_HANDLE handle, uint64_t offset, uint64_t count, co ssize_t bytes; if (handle->process.ssl_ctx) { - bytes = _DkStreamSecureWrite(handle->process.ssl_ctx, buffer, count, - /*is_blocking=*/!handle->process.nonblocking); + bytes = _PalStreamSecureWrite(handle->process.ssl_ctx, buffer, count, + /*is_blocking=*/!handle->process.nonblocking); } else { bytes = ocall_write(handle->process.stream, buffer, count); bytes = bytes < 0 ? unix_to_pal_error(bytes) : bytes; @@ -288,7 +288,7 @@ static int proc_close(PAL_HANDLE handle) { } if (handle->process.ssl_ctx) { - _DkStreamSecureFree((LIB_SSL_CONTEXT*)handle->process.ssl_ctx); + _PalStreamSecureFree((LIB_SSL_CONTEXT*)handle->process.ssl_ctx); handle->process.ssl_ctx = NULL; } diff --git a/pal/src/host/linux-sgx/db_rtld.c b/pal/src/host/linux-sgx/db_rtld.c index 1d344c6f75..c276101b93 100644 --- a/pal/src/host/linux-sgx/db_rtld.c +++ b/pal/src/host/linux-sgx/db_rtld.c @@ -10,7 +10,7 @@ * - pal-sgx and libraries it uses (outside enclave) - handled by ld.so and reported by it (through * _r_debug mechanism) * - libpal.so (in enclave) - reported in sgx_main.c before enclave start - * - LibOS, application, libc... (in enclave) - reported through DkDebugMap* + * - LibOS, application, libc... (in enclave) - reported through PalDebugMap* * * In addition, we report executable memory mappings to the profiling subsystem. */ @@ -18,14 +18,14 @@ #include "pal_linux.h" #include "pal_rtld.h" -void _DkDebugMapAdd(const char* name, void* addr) { +void _PalDebugMapAdd(const char* name, void* addr) { ocall_debug_map_add(name, addr); } -void _DkDebugMapRemove(void* addr) { +void _PalDebugMapRemove(void* addr) { ocall_debug_map_remove(addr); } -int _DkDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size) { +int _PalDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size) { return ocall_debug_describe_location(addr, buf, buf_size); } diff --git a/pal/src/host/linux-sgx/db_sockets.c b/pal/src/host/linux-sgx/db_sockets.c index 54f3991e64..923c898ee9 100644 --- a/pal/src/host/linux-sgx/db_sockets.c +++ b/pal/src/host/linux-sgx/db_sockets.c @@ -88,8 +88,8 @@ static PAL_HANDLE create_sock_handle(int fd, enum pal_socket_domain domain, return handle; } -int _DkSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, - pal_stream_options_t options, PAL_HANDLE* out_handle) { +int _PalSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, + pal_stream_options_t options, PAL_HANDLE* out_handle) { int linux_domain; int linux_type; switch (domain) { @@ -220,7 +220,7 @@ static int tcp_accept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDL if (out_client_addr) { int ret = verify_ip_addr(client->sock.domain, &sa_storage, linux_addrlen); if (ret < 0) { - _DkObjectClose(client); + _PalObjectClose(client); return ret; } @@ -482,7 +482,7 @@ static int recv(PAL_HANDLE handle, struct pal_iovec* pal_iov, size_t iov_len, unsigned int flags = force_nonblocking ? MSG_DONTWAIT : 0; if (handle->sock.type == PAL_SOCKET_UDP) { /* Reads from PAL UDP sockets always return the full packed length. See also the definition - * of `DkSocketRecv`. */ + * of `PalSocketRecv`. */ flags |= MSG_TRUNC; } ssize_t ret = ocall_recv(handle->sock.fd, iov, iov_len, addr ? &sa_storage : NULL, @@ -576,7 +576,7 @@ void fixup_socket_handle_after_deserialization(PAL_HANDLE handle) { } } -int _DkSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { +int _PalSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { if (!handle->sock.ops->bind) { return -PAL_ERROR_NOTSUPPORT; } @@ -584,39 +584,39 @@ int _DkSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { return handle->sock.ops->bind(handle, addr); } -int _DkSocketListen(PAL_HANDLE handle, unsigned int backlog) { +int _PalSocketListen(PAL_HANDLE handle, unsigned int backlog) { if (!handle->sock.ops->listen) { return -PAL_ERROR_NOTSUPPORT; } return handle->sock.ops->listen(handle, backlog); } -int _DkSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, - struct pal_socket_addr* out_client_addr) { +int _PalSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, + struct pal_socket_addr* out_client_addr) { if (!handle->sock.ops->accept) { return -PAL_ERROR_NOTSUPPORT; } return handle->sock.ops->accept(handle, options, out_client, out_client_addr); } -int _DkSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, - struct pal_socket_addr* out_local_addr) { +int _PalSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, + struct pal_socket_addr* out_local_addr) { if (!handle->sock.ops->connect) { return -PAL_ERROR_NOTSUPPORT; } return handle->sock.ops->connect(handle, addr, out_local_addr); } -int _DkSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, - struct pal_socket_addr* addr) { +int _PalSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, + struct pal_socket_addr* addr) { if (!handle->sock.ops->send) { return -PAL_ERROR_NOTSUPPORT; } return handle->sock.ops->send(handle, iov, iov_len, out_size, addr); } -int _DkSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, - struct pal_socket_addr* addr, bool force_nonblocking) { +int _PalSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, + struct pal_socket_addr* addr, bool force_nonblocking) { if (!handle->sock.ops->recv) { return -PAL_ERROR_NOTSUPPORT; } diff --git a/pal/src/host/linux-sgx/db_streams.c b/pal/src/host/linux-sgx/db_streams.c index 181ed4509e..830a45376f 100644 --- a/pal/src/host/linux-sgx/db_streams.c +++ b/pal/src/host/linux-sgx/db_streams.c @@ -33,9 +33,9 @@ struct hdl_header { size_t data_size; /* total size of serialized PAL handle */ }; -/* _DkStreamUnmap for internal use. Unmap stream at certain memory address. - The memory is unmapped as a whole.*/ -int _DkStreamUnmap(void* addr, uint64_t size) { +/* _PalStreamUnmap for internal use. Unmap stream at certain memory address. The memory is unmapped + * as a whole.*/ +int _PalStreamUnmap(void* addr, uint64_t size) { return free_enclave_pages(addr, size); } @@ -59,7 +59,7 @@ static ssize_t handle_serialize(PAL_HANDLE handle, void** data) { /* session key is part of handle but need to serialize SSL context */ if (handle->pipe.ssl_ctx) { free_d = true; - ret = _DkStreamSecureSave(handle->pipe.ssl_ctx, (const uint8_t**)&d, &dsz); + ret = _PalStreamSecureSave(handle->pipe.ssl_ctx, (const uint8_t**)&d, &dsz); if (ret < 0) return -PAL_ERROR_DENIED; } @@ -81,7 +81,7 @@ static ssize_t handle_serialize(PAL_HANDLE handle, void** data) { /* session key is part of handle but need to serialize SSL context */ if (handle->process.ssl_ctx) { free_d = true; - ret = _DkStreamSecureSave(handle->process.ssl_ctx, (const uint8_t**)&d, &dsz); + ret = _PalStreamSecureSave(handle->process.ssl_ctx, (const uint8_t**)&d, &dsz); if (ret < 0) return -PAL_ERROR_DENIED; } @@ -135,9 +135,9 @@ static int handle_deserialize(PAL_HANDLE* handle, const void* data, size_t size, case PAL_TYPE_PIPECLI: /* session key is part of handle but need to deserialize SSL context */ hdl->pipe.fd = host_fd; /* correct host FD must be passed to SSL context */ - ret = _DkStreamSecureInit(hdl, hdl->pipe.is_server, &hdl->pipe.session_key, - (LIB_SSL_CONTEXT**)&hdl->pipe.ssl_ctx, - (const uint8_t*)hdl + hdlsz, size - hdlsz); + ret = _PalStreamSecureInit(hdl, hdl->pipe.is_server, &hdl->pipe.session_key, + (LIB_SSL_CONTEXT**)&hdl->pipe.ssl_ctx, + (const uint8_t*)hdl + hdlsz, size - hdlsz); if (ret < 0) { free(hdl); return -PAL_ERROR_DENIED; @@ -156,9 +156,9 @@ static int handle_deserialize(PAL_HANDLE* handle, const void* data, size_t size, case PAL_TYPE_PROCESS: /* session key is part of handle but need to deserialize SSL context */ hdl->process.stream = host_fd; /* correct host FD must be passed to SSL context */ - ret = _DkStreamSecureInit(hdl, hdl->process.is_server, &hdl->process.session_key, - (LIB_SSL_CONTEXT**)&hdl->process.ssl_ctx, - (const uint8_t*)hdl + hdlsz, size - hdlsz); + ret = _PalStreamSecureInit(hdl, hdl->process.is_server, &hdl->process.session_key, + (LIB_SSL_CONTEXT**)&hdl->process.ssl_ctx, + (const uint8_t*)hdl + hdlsz, size - hdlsz); if (ret < 0) { free(hdl); return -PAL_ERROR_DENIED; @@ -175,7 +175,7 @@ static int handle_deserialize(PAL_HANDLE* handle, const void* data, size_t size, return 0; } -int _DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { +int _PalSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { if (HANDLE_HDR(target_process)->type != PAL_TYPE_PROCESS) return -PAL_ERROR_BADHANDLE; @@ -229,9 +229,9 @@ int _DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { /* finally send the serialized cargo as payload (possibly encrypted) */ if (target_process->process.ssl_ctx) { - ret = _DkStreamSecureWrite(target_process->process.ssl_ctx, (uint8_t*)hdl_data, - hdl_hdr.data_size, - /*is_blocking=*/!target_process->process.nonblocking); + ret = _PalStreamSecureWrite(target_process->process.ssl_ctx, (uint8_t*)hdl_data, + hdl_hdr.data_size, + /*is_blocking=*/!target_process->process.nonblocking); } else { ret = ocall_write(fd, hdl_data, hdl_hdr.data_size); ret = ret < 0 ? unix_to_pal_error(ret) : ret; @@ -241,7 +241,7 @@ int _DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { return ret < 0 ? ret : 0; } -int _DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { +int _PalReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { if (HANDLE_HDR(source_process)->type != PAL_TYPE_PROCESS) return -PAL_ERROR_BADHANDLE; @@ -259,7 +259,7 @@ int _DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { return unix_to_pal_error(ret); if ((size_t)ret != sizeof(hdl_hdr)) { - /* This check is to shield from a Iago attack. We know that ocall_send() in _DkSendHandle() + /* This check is to shield from a Iago attack. We know that ocall_send() in _PalSendHandle() * transfers the message atomically, and that our ocall_recv() receives it atomically. So * the only valid values for ret must be zero or the size of the header. */ if (!ret) @@ -285,9 +285,9 @@ int _DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { char hdl_data[hdl_hdr.data_size]; if (source_process->process.ssl_ctx) { - ret = _DkStreamSecureRead(source_process->process.ssl_ctx, - (uint8_t*)hdl_data, hdl_hdr.data_size, - /*is_blocking=*/!source_process->process.nonblocking); + ret = _PalStreamSecureRead(source_process->process.ssl_ctx, + (uint8_t*)hdl_data, hdl_hdr.data_size, + /*is_blocking=*/!source_process->process.nonblocking); } else { ret = ocall_read(fd, hdl_data, hdl_hdr.data_size); ret = ret < 0 ? unix_to_pal_error(ret) : ret; @@ -324,7 +324,7 @@ int _DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { return 0; } -int _DkInitDebugStream(const char* path) { +int _PalInitDebugStream(const char* path) { int ret; if (g_log_fd != PAL_LOG_DEFAULT_FD) { @@ -341,7 +341,7 @@ int _DkInitDebugStream(const char* path) { return 0; } -int _DkDebugLog(const void* buf, size_t size) { +int _PalDebugLog(const void* buf, size_t size) { if (g_log_fd < 0) return -PAL_ERROR_BADHANDLE; diff --git a/pal/src/host/linux-sgx/db_threading.c b/pal/src/host/linux-sgx/db_threading.c index 2a846a4dc1..6ca42e836a 100644 --- a/pal/src/host/linux-sgx/db_threading.c +++ b/pal/src/host/linux-sgx/db_threading.c @@ -73,20 +73,20 @@ void pal_start_thread(void) { /* each newly-created thread (including the first thread) has its own random stack canary */ uint64_t stack_protector_canary; - int ret = _DkRandomBitsRead(&stack_protector_canary, sizeof(stack_protector_canary)); + int ret = _PalRandomBitsRead(&stack_protector_canary, sizeof(stack_protector_canary)); if (ret < 0) { - log_error("_DkRandomBitsRead() failed (%d)", ret); - _DkProcessExit(1); + log_error("_PalRandomBitsRead() failed (%d)", ret); + _PalProcessExit(1); } pal_set_tcb_stack_canary(stack_protector_canary); PAL_TCB* pal_tcb = pal_get_tcb(); memset(&pal_tcb->libos_tcb, 0, sizeof(pal_tcb->libos_tcb)); callback((void*)param); - _DkThreadExit(/*clear_child_tid=*/NULL); + _PalThreadExit(/*clear_child_tid=*/NULL); /* UNREACHABLE */ } -int _DkThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param) { +int _PalThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param) { int ret; PAL_HANDLE new_thread = calloc(1, HANDLE_SIZE(thread)); if (!new_thread) @@ -136,14 +136,13 @@ int _DkThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param) { return ret; } -/* PAL call DkThreadYieldExecution. Yield the execution - of the current thread. */ -void _DkThreadYieldExecution(void) { +/* PAL call PalThreadYieldExecution. Yield the execution of the current thread. */ +void _PalThreadYieldExecution(void) { ocall_sched_yield(); } -/* _DkThreadExit for internal use: Thread exiting */ -noreturn void _DkThreadExit(int* clear_child_tid) { +/* _PalThreadExit for internal use: Thread exiting */ +noreturn void _PalThreadExit(int* clear_child_tid) { struct pal_handle_thread* exiting_thread = GET_ENCLAVE_TLS(thread); /* thread is ready to exit, must inform LibOS by erasing clear_child_tid; @@ -162,17 +161,17 @@ noreturn void _DkThreadExit(int* clear_child_tid) { ocall_exit(0, /*is_exitgroup=*/false); } -int _DkThreadResume(PAL_HANDLE thread_handle) { +int _PalThreadResume(PAL_HANDLE thread_handle) { int ret = ocall_resume_thread(thread_handle->thread.tcs); return ret < 0 ? unix_to_pal_error(ret) : ret; } -int _DkThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { +int _PalThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { int ret = ocall_sched_setaffinity(thread->thread.tcs, cpumask_size, cpu_mask); return ret < 0 ? unix_to_pal_error(ret) : ret; } -int _DkThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { +int _PalThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { int ret = ocall_sched_getaffinity(thread->thread.tcs, cpumask_size, cpu_mask); return ret < 0 ? unix_to_pal_error(ret) : ret; } diff --git a/pal/src/host/linux-sgx/enclave_entry.S b/pal/src/host/linux-sgx/enclave_entry.S index d7ff17d0d7..96bf777438 100644 --- a/pal/src/host/linux-sgx/enclave_entry.S +++ b/pal/src/host/linux-sgx/enclave_entry.S @@ -40,7 +40,7 @@ # Note that stage-1 exception handler has only minimal asm code and doesn't call any C functions. # Its sole purpose is to prepare the stage-2 handler by: # - copying the interrupted SSA[0] context on the stack ("CPU context") -# - rewiring the SSA[0] context to point to _DkExceptionHandler() +# - rewiring the SSA[0] context to point to _PalExceptionHandler() # - invoking EEXIT (so that untrusted runtime can perform ERESUME) #include "sgx_arch.h" @@ -273,12 +273,12 @@ enclave_entry: # Calling the stage-2 exception handler (CSSA=0) while SGX_PRE_OCALL_STACK != 0 would be # problematic because stage-2 handler could issue nested OCALLs. This would mean the # SGX_PRE_OCALL_STACK logic would need to handle nesting. So we don't set up the stage-2 handler - # (i.e, the _DkExceptionHandler() function). + # (i.e, the _PalExceptionHandler() function). # # Instead if we're in such situation, we emulate it as if RIP reached to the safe point, # .Lcssa0_ocall_return_after_stack_restore. In other words, the stage-1 handler jumps to the # regular returning-from-OCALL flow (CSSA=0) with RSI= which forces that flow - # to call _DkHandleExternalEvent() before proceeding with normal enclave code. + # to call _PalHandleExternalEvent() before proceeding with normal enclave code. # # Ocall sequence: # 1. call sgx_ocall() @@ -289,7 +289,7 @@ enclave_entry: # 6. .Lcssa0_ocall_return: # 7. (RSP, SGX_STACK) = (SGX_STACK, 0): restore trusted stack # 8. .Lcssa0_ocall_return_after_stack_restore: - # 9. call _DkHandleExternalEvent() if interrupted + # 9. call _PalHandleExternalEvent() if interrupted # 10. return from sgx_ocall() to the caller # # It is also required that sgx_ocall() be atomic wrt async exception. When host async signal @@ -332,7 +332,7 @@ enclave_entry: # CASE A. We are right-before EEXIT for ocall in between [.Lcssa0_ocall_eexit_prepare, # .Lcssa0_ocall_eexit_done) -- skip EEXIT as if ocall returned EINTR. # - # If there is a registered signal handler for the current exception, _DkHandleExternalEvent() + # If there is a registered signal handler for the current exception, _PalHandleExternalEvent() # will be called (and thus we need to save RDI = ) before returning from ocall. movq $-EINTR, SGX_GPR_RDI(%rbx) # return value for .Lcssa0_ocall_return @@ -351,7 +351,7 @@ enclave_entry: # # Set RSI = and move RIP to .Lcssa0_ocall_return_after_stack_restore, such # that regular returning-from-OCALL flow (CSSA=0) will notice the external event and will call - # _DkHandleExternalEvent() to handle the exception. + # _PalHandleExternalEvent() to handle the exception. # # Note that either we fell-through from Case A and RDI was already set to the -EINTR return # value, or we are indeed in Case C and RDI already contains the successful OCALL result. @@ -369,7 +369,7 @@ enclave_entry: .Lcssa1_exception_during_enclave_run: # The thread got interrupted outside of ocall handling (see above for that special case). We - # inject a call to _DkExceptionHandler() into the interrupted thread to handle exception in + # inject a call to _PalExceptionHandler() into the interrupted thread to handle exception in # stage-2 handler (on ERESUME). # The last instructions of _restore_sgx_context() need to be atomic for the code below (see @@ -417,7 +417,7 @@ enclave_entry: # the stack pointer up here to undo the move down below. addq $RED_ZONE_SIZE, %rsi - # Setup stack for stage-2 handler _DkExceptionHandler(). + # Setup stack for stage-2 handler _PalExceptionHandler(). # # Stack layout: # 8-bytes padding: (8 mod 16) bytes aligned for x86 ABI @@ -426,7 +426,7 @@ enclave_entry: # padding: (if necessary) # RED_ZONE: (unless newly switching to signal stack) # - # NOTE: there is no saved RIP on the stack (to return) because _DkExceptionHandler() calls + # NOTE: there is no saved RIP on the stack (to return) because _PalExceptionHandler() calls # _restore_sgx_context(). #define STACK_PADDING_SIZE (PAL_FP_XSTATE_MAGIC2_SIZE + 8) @@ -452,7 +452,7 @@ enclave_entry: andq $~(PAL_XSTATE_ALIGN - 1), %rsi subq $SGX_CPU_CONTEXT_XSTATE_ALIGN_SUB, %rsi - # Rewire SSA0: pass 1st arg to _DkExceptionHandler(): + # Rewire SSA0: pass 1st arg to _PalExceptionHandler(): # - exit info (in RDI, either trusted SSA[0].GPRSGX.EXITINFO or possibly-malicious # "external event") # @@ -497,7 +497,7 @@ enclave_entry: movq SGX_GPR_RIP(%rbx), %rdi movq %rdi, SGX_CPU_CONTEXT_RIP(%rsi) - # Rewire SSA0: pass more args to _DkExceptionHandler(): + # Rewire SSA0: pass more args to _PalExceptionHandler(): # - pointer to sgx_cpu_context_t (SSA[0].GPRSGX.RSI, 2nd arg) # - pointer to PAL_XREGS_STATE (SSA[0].GPRSGX.RDX, 3rd arg) movq %rsi, SGX_GPR_RSI(%rbx) @@ -524,8 +524,8 @@ enclave_entry: # - clear RFLAGS.AC to prevent the #AC-fault side channel andq $(~(RFLAGS_DF | RFLAGS_AC)), SGX_GPR_RFLAGS(%rbx) - # Rewire SSA0: SSA[0].GPRSGX.RIP points to _DkExceptionHandler() - leaq _DkExceptionHandler(%rip), %rdi + # Rewire SSA0: SSA[0].GPRSGX.RIP points to _PalExceptionHandler() + leaq _PalExceptionHandler(%rip), %rdi movq %rdi, SGX_GPR_RIP(%rbx) # copy the whole SSA[0].XSAVE region to the CPU context's XSAVE on stack; @@ -753,7 +753,7 @@ sgx_ocall: jmp _restore_sgx_context 2: - # there was some event, call _DkHandleExternalEvent(event, uc, xregs_state) + # there was some event, call _PalHandleExternalEvent(event, uc, xregs_state) # clear the Alignment Check flag to prevent #AC-fault side channel pushfq @@ -767,7 +767,7 @@ sgx_ocall: movq %rsi, %rdi # external event (1st arg) movq %rsp, %rsi # SGX context (2nd arg) leaq SGX_CPU_CONTEXT_SIZE(%rsp), %rdx # xregs_state (3rd arg) - callq _DkHandleExternalEvent + callq _PalHandleExternalEvent FAIL_LOOP # cannot be reached diff --git a/pal/src/host/linux-sgx/enclave_framework.c b/pal/src/host/linux-sgx/enclave_framework.c index 10f6e58b5b..6c1b7943e0 100644 --- a/pal/src/host/linux-sgx/enclave_framework.c +++ b/pal/src/host/linux-sgx/enclave_framework.c @@ -346,7 +346,7 @@ int load_trusted_or_allowed_file(struct trusted_file* tf, PAL_HANDLE file, bool if (!uri) return -PAL_ERROR_NOMEM; - ret = _DkStreamGetName(file, uri, URI_MAX); + ret = _PalStreamGetName(file, uri, URI_MAX); if (ret < 0) { free(uri); return ret; @@ -941,9 +941,9 @@ static int hash_over_session_key(const PAL_SESSION_KEY* session_key, const char* return lib_SHA256Final(&sha, (uint8_t*)out_hash); } -int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* out_key, - sgx_report_data_t* out_parent_report_data, - sgx_report_data_t* out_child_report_data) { +int _PalStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* out_key, + sgx_report_data_t* out_parent_report_data, + sgx_report_data_t* out_child_report_data) { int ret; LIB_DH_CONTEXT context; @@ -966,7 +966,7 @@ int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* out_key, goto out; for (int64_t bytes = 0, total = 0; total < (int64_t)sizeof(my_public); total += bytes) { - bytes = _DkStreamWrite(stream, 0, sizeof(my_public) - total, my_public + total, NULL, 0); + bytes = _PalStreamWrite(stream, 0, sizeof(my_public) - total, my_public + total, NULL, 0); if (bytes < 0) { if (bytes == -PAL_ERROR_INTERRUPTED || bytes == -PAL_ERROR_TRYAGAIN) { bytes = 0; @@ -978,7 +978,8 @@ int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* out_key, } for (int64_t bytes = 0, total = 0; total < (int64_t)sizeof(peer_public); total += bytes) { - bytes = _DkStreamRead(stream, 0, sizeof(peer_public) - total, peer_public + total, NULL, 0); + bytes = _PalStreamRead(stream, 0, sizeof(peer_public) - total, peer_public + total, NULL, + 0); if (bytes < 0) { if (bytes == -PAL_ERROR_INTERRUPTED || bytes == -PAL_ERROR_TRYAGAIN) { bytes = 0; @@ -1039,8 +1040,8 @@ int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* out_key, * We refer to this enclave as A and to the other enclave as B, e.g., A is this parent enclave and B * is the child enclave in the fork case (for more info, see comments in db_process.c). */ -int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, - sgx_report_data_t* peer_report_data) { +int _PalStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, + sgx_report_data_t* peer_report_data) { __sgx_mem_aligned sgx_target_info_t target_info; __sgx_mem_aligned sgx_report_t report; uint64_t bytes; @@ -1056,8 +1057,8 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, sizeof(sgx_attributes_t)); for (bytes = 0, ret = 0; bytes < SGX_TARGETINFO_FILLED_SIZE; bytes += ret) { - ret = _DkStreamWrite(stream, 0, SGX_TARGETINFO_FILLED_SIZE - bytes, - ((void*)&target_info) + bytes, NULL, 0); + ret = _PalStreamWrite(stream, 0, SGX_TARGETINFO_FILLED_SIZE - bytes, + ((void*)&target_info) + bytes, NULL, 0); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN) { ret = 0; @@ -1070,7 +1071,7 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, /* B -> A: report[B -> A] */ for (bytes = 0, ret = 0; bytes < sizeof(report); bytes += ret) { - ret = _DkStreamRead(stream, 0, sizeof(report) - bytes, ((void*)&report) + bytes, NULL, 0); + ret = _PalStreamRead(stream, 0, sizeof(report) - bytes, ((void*)&report) + bytes, NULL, 0); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN) { ret = 0; @@ -1109,7 +1110,7 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, } for (bytes = 0, ret = 0; bytes < sizeof(report); bytes += ret) { - ret = _DkStreamWrite(stream, 0, sizeof(report) - bytes, ((void*)&report) + bytes, NULL, 0); + ret = _PalStreamWrite(stream, 0, sizeof(report) - bytes, ((void*)&report) + bytes, NULL, 0); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN) { ret = 0; @@ -1123,7 +1124,7 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, return 0; out: - _DkStreamDelete(stream, PAL_DELETE_ALL); + _PalStreamDelete(stream, PAL_DELETE_ALL); return ret; } @@ -1133,8 +1134,8 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, * We refer to this enclave as B and to the other enclave as A, e.g., B is this child enclave and A * is the parent enclave in the fork case (for more info, see comments in db_process.c). */ -int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* my_report_data, - sgx_report_data_t* peer_report_data) { +int _PalStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* my_report_data, + sgx_report_data_t* peer_report_data) { __sgx_mem_aligned sgx_target_info_t target_info; __sgx_mem_aligned sgx_report_t report; uint64_t bytes; @@ -1146,8 +1147,8 @@ int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* my_report_data, /* A -> B: targetinfo[A] */ for (bytes = 0, ret = 0; bytes < SGX_TARGETINFO_FILLED_SIZE; bytes += ret) { - ret = _DkStreamRead(stream, 0, SGX_TARGETINFO_FILLED_SIZE - bytes, - ((void*)&target_info) + bytes, NULL, 0); + ret = _PalStreamRead(stream, 0, SGX_TARGETINFO_FILLED_SIZE - bytes, + ((void*)&target_info) + bytes, NULL, 0); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN) { ret = 0; @@ -1166,7 +1167,7 @@ int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* my_report_data, } for (bytes = 0, ret = 0; bytes < sizeof(report); bytes += ret) { - ret = _DkStreamWrite(stream, 0, sizeof(report) - bytes, ((void*)&report) + bytes, NULL, 0); + ret = _PalStreamWrite(stream, 0, sizeof(report) - bytes, ((void*)&report) + bytes, NULL, 0); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN) { ret = 0; @@ -1179,7 +1180,7 @@ int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* my_report_data, /* A -> B: report[A -> B] */ for (bytes = 0, ret = 0; bytes < sizeof(report); bytes += ret) { - ret = _DkStreamRead(stream, 0, sizeof(report) - bytes, ((void*)&report) + bytes, NULL, 0); + ret = _PalStreamRead(stream, 0, sizeof(report) - bytes, ((void*)&report) + bytes, NULL, 0); if (ret < 0) { if (ret == -PAL_ERROR_INTERRUPTED || ret == -PAL_ERROR_TRYAGAIN) { ret = 0; @@ -1209,13 +1210,13 @@ int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* my_report_data, return 0; out: - _DkStreamDelete(stream, PAL_DELETE_ALL); + _PalStreamDelete(stream, PAL_DELETE_ALL); return ret; } -int _DkStreamSecureInit(PAL_HANDLE stream, bool is_server, PAL_SESSION_KEY* session_key, - LIB_SSL_CONTEXT** out_ssl_ctx, const uint8_t* buf_load_ssl_ctx, - size_t buf_size) { +int _PalStreamSecureInit(PAL_HANDLE stream, bool is_server, PAL_SESSION_KEY* session_key, + LIB_SSL_CONTEXT** out_ssl_ctx, const uint8_t* buf_load_ssl_ctx, + size_t buf_size) { int stream_fd; if (HANDLE_HDR(stream)->type == PAL_TYPE_PROCESS) @@ -1256,13 +1257,13 @@ int _DkStreamSecureInit(PAL_HANDLE stream, bool is_server, PAL_SESSION_KEY* sess return 0; } -int _DkStreamSecureFree(LIB_SSL_CONTEXT* ssl_ctx) { +int _PalStreamSecureFree(LIB_SSL_CONTEXT* ssl_ctx) { lib_SSLFree(ssl_ctx); free(ssl_ctx); return 0; } -int _DkStreamSecureRead(LIB_SSL_CONTEXT* ssl_ctx, uint8_t* buf, size_t len, bool is_blocking) { +int _PalStreamSecureRead(LIB_SSL_CONTEXT* ssl_ctx, uint8_t* buf, size_t len, bool is_blocking) { int ret = lib_SSLRead(ssl_ctx, buf, len); if (is_blocking && ret == -PAL_ERROR_TRYAGAIN) { /* mbedTLS wrappers collapse host errors `EAGAIN` and `EINTR` into one error PAL @@ -1273,17 +1274,17 @@ int _DkStreamSecureRead(LIB_SSL_CONTEXT* ssl_ctx, uint8_t* buf, size_t len, bool return ret; } -int _DkStreamSecureWrite(LIB_SSL_CONTEXT* ssl_ctx, const uint8_t* buf, size_t len, - bool is_blocking) { +int _PalStreamSecureWrite(LIB_SSL_CONTEXT* ssl_ctx, const uint8_t* buf, size_t len, + bool is_blocking) { int ret = lib_SSLWrite(ssl_ctx, buf, len); if (is_blocking && ret == -PAL_ERROR_TRYAGAIN) { - /* See the explanation in `_DkStreamSecureRead`. */ + /* See the explanation in `_PalStreamSecureRead`. */ return -PAL_ERROR_INTERRUPTED; } return ret; } -int _DkStreamSecureSave(LIB_SSL_CONTEXT* ssl_ctx, const uint8_t** obuf, size_t* olen) { +int _PalStreamSecureSave(LIB_SSL_CONTEXT* ssl_ctx, const uint8_t** obuf, size_t* olen) { assert(obuf); assert(olen); diff --git a/pal/src/host/linux-sgx/enclave_ocalls.c b/pal/src/host/linux-sgx/enclave_ocalls.c index e5287bc83e..27ae7ad07f 100644 --- a/pal/src/host/linux-sgx/enclave_ocalls.c +++ b/pal/src/host/linux-sgx/enclave_ocalls.c @@ -359,7 +359,7 @@ int ocall_cpuid(unsigned int leaf, unsigned int subleaf, unsigned int values[4]) if (retval < 0) { log_error("OCALL_CPUID returned an error (impossible on benign host)"); - _DkProcessExit(1); + _PalProcessExit(1); } if (!retval) { @@ -1682,7 +1682,7 @@ int ocall_gettime(uint64_t* microsec_ptr) { if (microsec < last_microsec_before_ocall) { /* Probably a malicious host. */ log_error("OCALL_GETTIME returned time value smaller than in the previous call"); - _DkProcessExit(1); + _PalProcessExit(1); } /* Update `last_microsec`. */ uint64_t expected_microsec = last_microsec_before_ocall; diff --git a/pal/src/host/linux-sgx/enclave_pages.c b/pal/src/host/linux-sgx/enclave_pages.c index cc5526c003..4a19c6139f 100644 --- a/pal/src/host/linux-sgx/enclave_pages.c +++ b/pal/src/host/linux-sgx/enclave_pages.c @@ -11,7 +11,7 @@ struct atomic_int g_allocated_pages; /* list of VMAs of used memory areas kept in DESCENDING order; note that preallocated PAL internal * memory relies on this descending order of allocations (from high addresses to low), see - * _DkGetAvailableUserAddressRange() for more details */ + * _PalGetAvailableUserAddressRange() for more details */ DEFINE_LIST(heap_vma); struct heap_vma { LIST_TYPE(heap_vma) list; diff --git a/pal/src/host/linux-sgx/pal_host.h b/pal/src/host/linux-sgx/pal_host.h index 1d95f3fb94..89aa3428f5 100644 --- a/pal/src/host/linux-sgx/pal_host.h +++ b/pal/src/host/linux-sgx/pal_host.h @@ -149,5 +149,5 @@ typedef struct { * writable respectively. If none of these is set, then the handle has no host-level fd. */ #define PAL_HANDLE_FD_READABLE 1 #define PAL_HANDLE_FD_WRITABLE 2 -/* Set if an error was seen on this handle. Currently only set by `_DkStreamsWaitEvents`. */ +/* Set if an error was seen on this handle. Currently only set by `_PalStreamsWaitEvents`. */ #define PAL_HANDLE_FD_ERROR 4 diff --git a/pal/src/host/linux-sgx/pal_linux.h b/pal/src/host/linux-sgx/pal_linux.h index 41d788ee76..9086929761 100644 --- a/pal/src/host/linux-sgx/pal_linux.h +++ b/pal/src/host/linux-sgx/pal_linux.h @@ -98,11 +98,11 @@ void save_xregs(PAL_XREGS_STATE* xsave_area); void restore_xregs(const PAL_XREGS_STATE* xsave_area); noreturn void _restore_sgx_context(sgx_cpu_context_t* uc, PAL_XREGS_STATE* xsave_area); -void _DkExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, - PAL_XREGS_STATE* xregs_state); +void _PalExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, + PAL_XREGS_STATE* xregs_state); /* `event_` is actually of `enum pal_event` type, but we call it from assembly, so we need to know * its underlying type. */ -void _DkHandleExternalEvent(long event_, sgx_cpu_context_t* uc, PAL_XREGS_STATE* xregs_state); +void _PalHandleExternalEvent(long event_, sgx_cpu_context_t* uc, PAL_XREGS_STATE* xregs_state); bool is_tsc_usable(void); uint64_t get_tsc_hz(void); @@ -164,9 +164,9 @@ bool is_peer_enclave_ok(sgx_report_body_t* peer_enclave_info, /* perform Diffie-Hellman to establish a session key and also produce a hash over (K_e || tag1) for * parent enclave A and a hash over (K_e || tag2) for child enclave B; see also top-level comment in * db_process.c */ -int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* out_key, - sgx_report_data_t* out_parent_report_data, - sgx_report_data_t* out_child_report_data); +int _PalStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* out_key, + sgx_report_data_t* out_parent_report_data, + sgx_report_data_t* out_child_report_data); /*! * \brief Request a local report on an RPC stream (typically called by parent enclave). @@ -176,8 +176,8 @@ int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* out_key, * \param peer_report_data User-defined data expected in the incoming SGX report. * \return 0 on success, negative error code otherwise. */ -int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, - sgx_report_data_t* peer_report_data); +int _PalStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, + sgx_report_data_t* peer_report_data); /*! * \brief Respond with a local report on an RPC stream (typically called by child enclave). @@ -187,17 +187,17 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* my_report_data, * \param peer_report_data User-defined data expected in the incoming SGX report. * \return 0 on success, negative error code otherwise. */ -int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* my_report_data, - sgx_report_data_t* peer_report_data); - -int _DkStreamSecureInit(PAL_HANDLE stream, bool is_server, PAL_SESSION_KEY* session_key, - LIB_SSL_CONTEXT** out_ssl_ctx, const uint8_t* buf_load_ssl_ctx, - size_t buf_size); -int _DkStreamSecureFree(LIB_SSL_CONTEXT* ssl_ctx); -int _DkStreamSecureRead(LIB_SSL_CONTEXT* ssl_ctx, uint8_t* buf, size_t len, bool is_blocking); -int _DkStreamSecureWrite(LIB_SSL_CONTEXT* ssl_ctx, const uint8_t* buf, size_t len, - bool is_blocking); -int _DkStreamSecureSave(LIB_SSL_CONTEXT* ssl_ctx, const uint8_t** obuf, size_t* olen); +int _PalStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* my_report_data, + sgx_report_data_t* peer_report_data); + +int _PalStreamSecureInit(PAL_HANDLE stream, bool is_server, PAL_SESSION_KEY* session_key, + LIB_SSL_CONTEXT** out_ssl_ctx, const uint8_t* buf_load_ssl_ctx, + size_t buf_size); +int _PalStreamSecureFree(LIB_SSL_CONTEXT* ssl_ctx); +int _PalStreamSecureRead(LIB_SSL_CONTEXT* ssl_ctx, uint8_t* buf, size_t len, bool is_blocking); +int _PalStreamSecureWrite(LIB_SSL_CONTEXT* ssl_ctx, const uint8_t* buf, size_t len, + bool is_blocking); +int _PalStreamSecureSave(LIB_SSL_CONTEXT* ssl_ctx, const uint8_t** obuf, size_t* olen); void fixup_socket_handle_after_deserialization(PAL_HANDLE handle); diff --git a/pal/src/host/linux-sgx/sgx_main.c b/pal/src/host/linux-sgx/sgx_main.c index b3369be748..a1e58a41bc 100644 --- a/pal/src/host/linux-sgx/sgx_main.c +++ b/pal/src/host/linux-sgx/sgx_main.c @@ -579,7 +579,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ #ifdef DEBUG /* - * Report libpal map. All subsequent files will be reported via DkDebugMapAdd(), but this + * Report libpal map. All subsequent files will be reported via PalDebugMapAdd(), but this * one has to be handled separately. * * We report it here, before enclave start (as opposed to setup_pal_binary()), because we want diff --git a/pal/src/host/linux-sgx/sgx_profile.c b/pal/src/host/linux-sgx/sgx_profile.c index 9f24ebff21..421950701c 100644 --- a/pal/src/host/linux-sgx/sgx_profile.c +++ b/pal/src/host/linux-sgx/sgx_profile.c @@ -345,8 +345,8 @@ void sgx_profile_report_elf(const char* filename, void* addr) { goto out_close; } - // Perform a simple sanity check to verify if this looks like ELF (see TODO for DkDebugMapAdd in - // pal/src/db_rtld.c). + // Perform a simple sanity check to verify if this looks like ELF (see TODO for PalDebugMapAdd + // in pal/src/db_rtld.c). const elf_ehdr_t* ehdr = elf_addr; diff --git a/pal/src/host/linux/arch/x86_64/db_arch_misc.c b/pal/src/host/linux/arch/x86_64/db_arch_misc.c index 6da1ccc481..ab45eeab0f 100644 --- a/pal/src/host/linux/arch/x86_64/db_arch_misc.c +++ b/pal/src/host/linux/arch/x86_64/db_arch_misc.c @@ -10,7 +10,7 @@ #include "cpu.h" #include "pal_linux.h" -int _DkSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { +int _PalSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { switch (reg) { case PAL_SEGMENT_FS: return unix_to_pal_error(DO_SYSCALL(arch_prctl, ARCH_GET_FS, (unsigned long*)addr)); @@ -22,7 +22,7 @@ int _DkSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { } } -int _DkSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr) { +int _PalSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr) { switch (reg) { case PAL_SEGMENT_FS: return unix_to_pal_error(DO_SYSCALL(arch_prctl, ARCH_SET_FS, (unsigned long)addr)); @@ -34,7 +34,7 @@ int _DkSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr) { } } -int _DkCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) { +int _PalCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) { cpuid(leaf, subleaf, values); return 0; } diff --git a/pal/src/host/linux/db_events.c b/pal/src/host/linux/db_events.c index d75311c934..49e2617218 100644 --- a/pal/src/host/linux/db_events.c +++ b/pal/src/host/linux/db_events.c @@ -16,7 +16,7 @@ #include "pal_internal.h" #include "pal_linux_error.h" -int _DkEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear) { +int _PalEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear) { PAL_HANDLE handle = calloc(1, HANDLE_SIZE(event)); if (!handle) { return -PAL_ERROR_NOMEM; @@ -32,14 +32,14 @@ int _DkEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear) return 0; } -void _DkEventSet(PAL_HANDLE handle) { +void _PalEventSet(PAL_HANDLE handle) { spinlock_lock(&handle->event.lock); __atomic_store_n(&handle->event.signaled, 1, __ATOMIC_RELEASE); bool need_wake = handle->event.waiters_cnt > 0; spinlock_unlock(&handle->event.lock); if (need_wake) { /* We could just use `FUTEX_WAKE`, but using `FUTEX_WAKE_BITSET` is more consistent with - * `FUTEX_WAIT_BITSET` in `_DkEventWait`. */ + * `FUTEX_WAIT_BITSET` in `_PalEventWait`. */ int ret = DO_SYSCALL(futex, &handle->event.signaled, FUTEX_WAKE_BITSET, handle->event.auto_clear ? 1 : INT_MAX, NULL, NULL, FUTEX_BITSET_MATCH_ANY); @@ -49,13 +49,13 @@ void _DkEventSet(PAL_HANDLE handle) { } } -void _DkEventClear(PAL_HANDLE handle) { +void _PalEventClear(PAL_HANDLE handle) { spinlock_lock(&handle->event.lock); __atomic_store_n(&handle->event.signaled, 0, __ATOMIC_RELEASE); spinlock_unlock(&handle->event.lock); } -int _DkEventWait(PAL_HANDLE handle, uint64_t* timeout_us) { +int _PalEventWait(PAL_HANDLE handle, uint64_t* timeout_us) { int ret; struct timespec timeout = { 0 }; if (timeout_us) { diff --git a/pal/src/host/linux/db_exception.c b/pal/src/host/linux/db_exception.c index a25fa30d64..ed2358e097 100644 --- a/pal/src/host/linux/db_exception.c +++ b/pal/src/host/linux/db_exception.c @@ -74,7 +74,7 @@ static enum pal_event signal_to_pal_event(int sig) { */ static void perform_signal_handling(enum pal_event event, bool is_in_pal, uintptr_t addr, ucontext_t* uc) { - pal_event_handler_t upcall = _DkGetExceptionHandler(event); + pal_event_handler_t upcall = _PalGetExceptionHandler(event); if (!upcall) return; @@ -112,7 +112,7 @@ static void handle_sync_signal(int signum, siginfo_t* info, struct ucontext* uc) log_error("Unexpected %s occurred inside %s (%s, PID = %u, TID = %ld)", event_name, in_vdso ? "VDSO" : "PAL", buf, g_pal_linux_state.host_pid, DO_SYSCALL(gettid)); - _DkProcessExit(1); + _PalProcessExit(1); } static void handle_async_signal(int signum, siginfo_t* info, struct ucontext* uc) { diff --git a/pal/src/host/linux/db_main.c b/pal/src/host/linux/db_main.c index e6f1b10c8c..8f9cc3b989 100644 --- a/pal/src/host/linux/db_main.c +++ b/pal/src/host/linux/db_main.c @@ -34,8 +34,8 @@ char* g_libpal_path = NULL; struct pal_linux_state g_pal_linux_state; /* for internal PAL objects, Gramine first uses pre-allocated g_mem_pool and then falls back to - * _DkVirtualMemoryAlloc(PAL_ALLOC_INTERNAL); the amount of available PAL internal memory is limited - * by the variable below */ + * _PalVirtualMemoryAlloc(PAL_ALLOC_INTERNAL); the amount of available PAL internal memory is + * limited by the variable below */ size_t g_pal_internal_mem_size = 0; char* g_pal_internal_mem_addr = NULL; @@ -85,7 +85,7 @@ static void read_info_from_stack(void* initial_rsp, int* out_argc, const char*** *out_envp = envp; } -void _DkGetAvailableUserAddressRange(void** out_start, void** out_end) { +void _PalGetAvailableUserAddressRange(void** out_start, void** out_end) { void* end_addr = (void*)ALLOC_ALIGN_DOWN_PTR(TEXT_START); void* start_addr = (void*)MMAP_MIN_ADDR; @@ -117,7 +117,7 @@ noreturn static void print_usage_and_exit(const char* argv_0) { "\tChildren: %s child args...", self, self); log_always("This is an internal interface. Use pal_loader to launch applications in Gramine."); - _DkProcessExit(1); + _PalProcessExit(1); } #ifdef ASAN @@ -168,9 +168,9 @@ noreturn void pal_linux_main(void* initial_rsp, void* fini_callback) { INIT_FAIL("Relocation of the PAL binary failed: %d", ret); uint64_t start_time; - ret = _DkSystemTimeQuery(&start_time); + ret = _PalSystemTimeQuery(&start_time); if (ret < 0) - INIT_FAIL("_DkSystemTimeQuery() failed: %d", ret); + INIT_FAIL("_PalSystemTimeQuery() failed: %d", ret); call_init_array(); diff --git a/pal/src/host/linux/db_memory.c b/pal/src/host/linux/db_memory.c index 441b3ababe..7d507bea81 100644 --- a/pal/src/host/linux/db_memory.c +++ b/pal/src/host/linux/db_memory.c @@ -32,7 +32,7 @@ static size_t g_pal_internal_mem_used = 0; static spinlock_t g_pal_internal_mem_lock = INIT_SPINLOCK_UNLOCKED; -bool _DkCheckMemoryMappable(const void* addr, size_t size) { +bool _PalCheckMemoryMappable(const void* addr, size_t size) { if (addr < DATA_END && addr + size > TEXT_START) { log_error("Address %p-%p is not mappable", addr, addr + size); return true; @@ -40,8 +40,8 @@ bool _DkCheckMemoryMappable(const void* addr, size_t size) { return false; } -int _DkVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_type, - pal_prot_flags_t prot) { +int _PalVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_type, + pal_prot_flags_t prot) { assert(WITHIN_MASK(alloc_type, PAL_ALLOC_MASK)); assert(WITHIN_MASK(prot, PAL_PROT_MASK)); @@ -79,12 +79,12 @@ int _DkVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_ return 0; } -int _DkVirtualMemoryFree(void* addr, size_t size) { +int _PalVirtualMemoryFree(void* addr, size_t size) { int ret = DO_SYSCALL(munmap, addr, size); return ret < 0 ? unix_to_pal_error(ret) : 0; } -int _DkVirtualMemoryProtect(void* addr, size_t size, pal_prot_flags_t prot) { +int _PalVirtualMemoryProtect(void* addr, size_t size, pal_prot_flags_t prot) { int ret = DO_SYSCALL(mprotect, addr, size, PAL_PROT_TO_LINUX(prot)); return ret < 0 ? unix_to_pal_error(ret) : 0; } @@ -137,7 +137,7 @@ static int read_proc_meminfo(const char* key, unsigned long* val) { return ret; } -unsigned long _DkMemoryQuota(void) { +unsigned long _PalMemoryQuota(void) { if (g_pal_linux_state.memory_quota == (unsigned long)-1) return 0; @@ -153,7 +153,7 @@ unsigned long _DkMemoryQuota(void) { return (g_pal_linux_state.memory_quota = quota * 1024); } -unsigned long _DkMemoryAvailableQuota(void) { +unsigned long _PalMemoryAvailableQuota(void) { unsigned long quota = 0; if (read_proc_meminfo("MemFree", "a) < 0) return 0; diff --git a/pal/src/host/linux/db_misc.c b/pal/src/host/linux/db_misc.c index 4bda74df15..f99bf22583 100644 --- a/pal/src/host/linux/db_misc.c +++ b/pal/src/host/linux/db_misc.c @@ -25,7 +25,7 @@ int init_random(void) { return 0; } -int _DkSystemTimeQuery(uint64_t* out_usec) { +int _PalSystemTimeQuery(uint64_t* out_usec) { struct timespec time; int ret; @@ -43,7 +43,7 @@ int _DkSystemTimeQuery(uint64_t* out_usec) { return 0; } -int _DkRandomBitsRead(void* buffer, size_t size) { +int _PalRandomBitsRead(void* buffer, size_t size) { assert(g_rand_fd != -1); int ret = read_all(g_rand_fd, buffer, size); if (ret < 0) @@ -52,9 +52,9 @@ int _DkRandomBitsRead(void* buffer, size_t size) { return 0; } -int _DkAttestationReport(const void* user_report_data, size_t* user_report_data_size, - void* target_info, size_t* target_info_size, void* report, - size_t* report_size) { +int _PalAttestationReport(const void* user_report_data, size_t* user_report_data_size, + void* target_info, size_t* target_info_size, void* report, + size_t* report_size) { __UNUSED(user_report_data); __UNUSED(user_report_data_size); __UNUSED(target_info); @@ -64,8 +64,8 @@ int _DkAttestationReport(const void* user_report_data, size_t* user_report_data_ return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, - size_t* quote_size) { +int _PalAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, + size_t* quote_size) { __UNUSED(user_report_data); __UNUSED(user_report_data_size); __UNUSED(quote); @@ -73,7 +73,7 @@ int _DkAttestationQuote(const void* user_report_data, size_t user_report_data_si return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkGetSpecialKey(const char* name, void* key, size_t* key_size) { +int _PalGetSpecialKey(const char* name, void* key, size_t* key_size) { __UNUSED(name); __UNUSED(key); __UNUSED(key_size); diff --git a/pal/src/host/linux/db_object.c b/pal/src/host/linux/db_object.c index 2ca3828097..8f1f464f55 100644 --- a/pal/src/host/linux/db_object.c +++ b/pal/src/host/linux/db_object.c @@ -12,8 +12,8 @@ #include "pal_internal.h" #include "pal_linux_error.h" -int _DkStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, - pal_wait_flags_t* ret_events, uint64_t* timeout_us) { +int _PalStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, + pal_wait_flags_t* ret_events, uint64_t* timeout_us) { int ret; uint64_t remaining_time_us = timeout_us ? *timeout_us : 0; diff --git a/pal/src/host/linux/db_process.c b/pal/src/host/linux/db_process.c index caee61ebf5..95ff2b6804 100644 --- a/pal/src/host/linux/db_process.c +++ b/pal/src/host/linux/db_process.c @@ -102,7 +102,7 @@ static int child_process(struct proc_param* proc_param) { die_or_inf_loop(); } -int _DkProcessCreate(PAL_HANDLE* handle, const char** args) { +int _PalProcessCreate(PAL_HANDLE* handle, const char** args) { PAL_HANDLE parent_handle = NULL; PAL_HANDLE child_handle = NULL; struct proc_args* proc_args = NULL; @@ -203,10 +203,10 @@ int _DkProcessCreate(PAL_HANDLE* handle, const char** args) { free(exec_data); free(proc_args); if (parent_handle) - _DkObjectClose(parent_handle); + _PalObjectClose(parent_handle); if (ret < 0) { if (child_handle) - _DkObjectClose(child_handle); + _PalObjectClose(child_handle); } return ret; } @@ -261,7 +261,7 @@ void init_child_process(int parent_stream_fd, PAL_HANDLE* parent_handle, char** free(data); } -noreturn void _DkProcessExit(int exitcode) { +noreturn void _PalProcessExit(int exitcode) { DO_SYSCALL(exit_group, exitcode); die_or_inf_loop(); } diff --git a/pal/src/host/linux/db_rtld.c b/pal/src/host/linux/db_rtld.c index 1b08acb066..99cbf668f9 100644 --- a/pal/src/host/linux/db_rtld.c +++ b/pal/src/host/linux/db_rtld.c @@ -9,7 +9,7 @@ * Overview of ELF files used in this host: * - libpal.so - used as main executable, so it doesn't need to be reported separately * - vDSO - virtual library loaded by host Linux, doesn't need to be reported - * - LibOS, application, libc... - reported through DkDebugMap* + * - LibOS, application, libc... - reported through PalDebugMap* */ #include "api.h" @@ -26,13 +26,13 @@ bool is_in_vdso(uintptr_t addr) { return (g_vdso_start || g_vdso_end) && g_vdso_start <= addr && addr < g_vdso_end; } -void _DkDebugMapAdd(const char* name, void* addr) { +void _PalDebugMapAdd(const char* name, void* addr) { int ret = debug_map_add(name, addr); if (ret < 0) log_error("debug_map_add(%s, %p) failed: %d", name, addr, ret); } -void _DkDebugMapRemove(void* addr) { +void _PalDebugMapRemove(void* addr) { int ret = debug_map_remove(addr); if (ret < 0) log_error("debug_map_remove(%p) failed: %d", addr, ret); @@ -65,6 +65,6 @@ int setup_vdso(elf_addr_t base_addr) { return 0; } -int _DkDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size) { +int _PalDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size) { return debug_describe_location(addr, buf, buf_size); } diff --git a/pal/src/host/linux/db_sockets.c b/pal/src/host/linux/db_sockets.c index 837d3bc547..aeb1532291 100644 --- a/pal/src/host/linux/db_sockets.c +++ b/pal/src/host/linux/db_sockets.c @@ -79,8 +79,8 @@ static PAL_HANDLE create_sock_handle(int fd, enum pal_socket_domain domain, return handle; } -int _DkSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, - pal_stream_options_t options, PAL_HANDLE* out_handle) { +int _PalSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, + pal_stream_options_t options, PAL_HANDLE* out_handle) { int linux_domain; int linux_type; switch (domain) { @@ -530,7 +530,7 @@ static int recv(PAL_HANDLE handle, struct pal_iovec* pal_iov, size_t iov_len, unsigned int flags = force_nonblocking ? MSG_DONTWAIT : 0; if (handle->sock.type == PAL_SOCKET_UDP) { /* Reads from PAL UDP sockets always return the full packed length. See also the definition - * of `DkSocketRecv`. */ + * of `PalSocketRecv`. */ flags |= MSG_TRUNC; } struct msghdr msg = { @@ -624,7 +624,7 @@ void fixup_socket_handle_after_deserialization(PAL_HANDLE handle) { } } -int _DkSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { +int _PalSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { if (!handle->sock.ops->bind) { return -PAL_ERROR_NOTSUPPORT; } @@ -632,39 +632,39 @@ int _DkSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { return handle->sock.ops->bind(handle, addr); } -int _DkSocketListen(PAL_HANDLE handle, unsigned int backlog) { +int _PalSocketListen(PAL_HANDLE handle, unsigned int backlog) { if (!handle->sock.ops->listen) { return -PAL_ERROR_NOTSUPPORT; } return handle->sock.ops->listen(handle, backlog); } -int _DkSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, - struct pal_socket_addr* out_client_addr) { +int _PalSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, + struct pal_socket_addr* out_client_addr) { if (!handle->sock.ops->accept) { return -PAL_ERROR_NOTSUPPORT; } return handle->sock.ops->accept(handle, options, out_client, out_client_addr); } -int _DkSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, - struct pal_socket_addr* out_local_addr) { +int _PalSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, + struct pal_socket_addr* out_local_addr) { if (!handle->sock.ops->connect) { return -PAL_ERROR_NOTSUPPORT; } return handle->sock.ops->connect(handle, addr, out_local_addr); } -int _DkSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, - struct pal_socket_addr* addr) { +int _PalSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, + struct pal_socket_addr* addr) { if (!handle->sock.ops->send) { return -PAL_ERROR_NOTSUPPORT; } return handle->sock.ops->send(handle, iov, iov_len, out_size, addr); } -int _DkSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, - struct pal_socket_addr* addr, bool force_nonblocking) { +int _PalSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, + struct pal_socket_addr* addr, bool force_nonblocking) { if (!handle->sock.ops->recv) { return -PAL_ERROR_NOTSUPPORT; } diff --git a/pal/src/host/linux/db_streams.c b/pal/src/host/linux/db_streams.c index 71013a5331..9b8ea52bac 100644 --- a/pal/src/host/linux/db_streams.c +++ b/pal/src/host/linux/db_streams.c @@ -38,9 +38,9 @@ int handle_set_cloexec(PAL_HANDLE handle, bool enable) { return 0; } -/* _DkStreamUnmap for internal use. Unmap stream at certain memory address. - The memory is unmapped as a whole.*/ -int _DkStreamUnmap(void* addr, uint64_t size) { +/* _PalStreamUnmap for internal use. Unmap stream at certain memory address. The memory is unmapped + * as a whole.*/ +int _PalStreamUnmap(void* addr, uint64_t size) { /* Just let the kernel tell us if the mapping isn't good. */ int ret = DO_SYSCALL(munmap, addr, size); @@ -137,7 +137,7 @@ int handle_deserialize(PAL_HANDLE* handle, const void* data, size_t size) { return 0; } -int _DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { +int _PalSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { if (HANDLE_HDR(target_process)->type != PAL_TYPE_PROCESS) return -PAL_ERROR_BADHANDLE; @@ -202,7 +202,7 @@ int _DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { return ret < 0 ? unix_to_pal_error(ret) : 0; } -int _DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { +int _PalReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { if (HANDLE_HDR(source_process)->type != PAL_TYPE_PROCESS) return -PAL_ERROR_BADHANDLE; @@ -224,7 +224,7 @@ int _DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { return unix_to_pal_error(ret); if ((size_t)ret != sizeof(hdl_hdr)) { - /* This check is to shield from a Iago attack. We know that sendmsg() in _DkSendHandle() + /* This check is to shield from a Iago attack. We know that sendmsg() in _PalSendHandle() * transfers the message atomically, and that our recvmsg() receives it atomically. So * the only valid values for ret must be zero or the size of the header. */ if (!ret) @@ -270,7 +270,7 @@ int _DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { return 0; } -int _DkInitDebugStream(const char* path) { +int _PalInitDebugStream(const char* path) { int ret; if (g_log_fd != PAL_LOG_DEFAULT_FD) { @@ -287,7 +287,7 @@ int _DkInitDebugStream(const char* path) { return 0; } -int _DkDebugLog(const void* buf, size_t size) { +int _PalDebugLog(const void* buf, size_t size) { if (g_log_fd < 0) return -PAL_ERROR_BADHANDLE; diff --git a/pal/src/host/linux/db_threading.c b/pal/src/host/linux/db_threading.c index b91cd39292..45d5c11434 100644 --- a/pal/src/host/linux/db_threading.c +++ b/pal/src/host/linux/db_threading.c @@ -22,7 +22,7 @@ /* Linux PAL cannot use mmap/unmap to manage thread stacks because this may overlap with * g_pal_public_state.user_address_{start,end}. Linux PAL also cannot just use malloc/free because - * DkThreadExit needs to use raw system calls and inline asm. Thus, we resort to recycling thread + * PalThreadExit needs to use raw system calls and inline asm. Thus, we resort to recycling thread * stacks allocated by previous threads and not used anymore. This still leaks memory but at least * it is bounded by the maximum number of simultaneously executing threads. Note that main thread * is not a part of this mechanism (it only allocates a tiny altstack). */ @@ -83,7 +83,7 @@ int pal_thread_init(void* tcbptr) { /* we inherited the parent's GS register which we shouldn't use in the child thread, but GCC's * stack protector will look for a canary at gs:[0x8] in functions called below (e.g., - * _DkRandomBitsRead), so let's install a default canary in the child's TCB */ + * _PalRandomBitsRead), so let's install a default canary in the child's TCB */ pal_tcb_set_stack_canary(&tcb->common, STACK_PROTECTOR_CANARY_DEFAULT); ret = pal_set_tcb(&tcb->common); if (ret < 0) @@ -91,7 +91,7 @@ int pal_thread_init(void* tcbptr) { /* each newly-created thread (including the first thread) has its own random stack canary */ uint64_t stack_protector_canary; - ret = _DkRandomBitsRead(&stack_protector_canary, sizeof(stack_protector_canary)); + ret = _PalRandomBitsRead(&stack_protector_canary, sizeof(stack_protector_canary)); if (ret < 0) return -EPERM; @@ -117,10 +117,10 @@ int pal_thread_init(void* tcbptr) { static noreturn void pal_thread_exit_wrapper(int ret_val) { __UNUSED(ret_val); - _DkThreadExit(/*clear_child_tid=*/NULL); + _PalThreadExit(/*clear_child_tid=*/NULL); } -int _DkThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param) { +int _PalThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param) { int ret = 0; PAL_HANDLE hdl = NULL; void* stack = get_thread_stack(); @@ -183,15 +183,14 @@ int _DkThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param) { return ret; } -/* PAL call DkThreadYieldExecution. Yield the execution - of the current thread. */ -void _DkThreadYieldExecution(void) { +/* Yield the execution of the current thread. */ +void _PalThreadYieldExecution(void) { DO_SYSCALL(sched_yield); } -/* _DkThreadExit for internal use: Thread exiting */ +/* _PalThreadExit for internal use: Thread exiting */ __attribute_no_sanitize_address -noreturn void _DkThreadExit(int* clear_child_tid) { +noreturn void _PalThreadExit(int* clear_child_tid) { PAL_TCB_LINUX* tcb = get_tcb_linux(); PAL_HANDLE handle = tcb->handle; assert(handle); @@ -230,7 +229,7 @@ noreturn void _DkThreadExit(int* clear_child_tid) { * 2. Set *clear_child_tid = 0 if clear_child_tid != NULL * (we thus inform LibOS, where async worker thread is waiting on this to wake up parent) * 3. Exit thread - * All of these happen in `_DkThreadExit_asm_stub`. + * All of these happen in `_PalThreadExit_asm_stub`. */ static_assert(sizeof(g_thread_stack_lock.lock) == 4, "unexpected g_thread_stack_lock.lock size"); @@ -238,10 +237,10 @@ noreturn void _DkThreadExit(int* clear_child_tid) { "lock is not naturally aligned in g_thread_stack_lock"); static_assert(sizeof(*clear_child_tid) == 4, "unexpected clear_child_tid size"); - _DkThreadExit_asm_stub(&g_thread_stack_lock.lock, clear_child_tid); + _PalThreadExit_asm_stub(&g_thread_stack_lock.lock, clear_child_tid); } -int _DkThreadResume(PAL_HANDLE thread_handle) { +int _PalThreadResume(PAL_HANDLE thread_handle) { int ret = DO_SYSCALL(tgkill, g_pal_linux_state.host_pid, thread_handle->thread.tid, SIGCONT); if (ret < 0) @@ -250,13 +249,13 @@ int _DkThreadResume(PAL_HANDLE thread_handle) { return 0; } -int _DkThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { +int _PalThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { int ret = DO_SYSCALL(sched_setaffinity, thread->thread.tid, cpumask_size, cpu_mask); return ret < 0 ? unix_to_pal_error(ret) : ret; } -int _DkThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { +int _PalThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { int ret = DO_SYSCALL(sched_getaffinity, thread->thread.tid, cpumask_size, cpu_mask); return ret < 0 ? unix_to_pal_error(ret) : ret; diff --git a/pal/src/host/linux/pal_host.h b/pal/src/host/linux/pal_host.h index 5d108da1ec..1808c474ab 100644 --- a/pal/src/host/linux/pal_host.h +++ b/pal/src/host/linux/pal_host.h @@ -117,7 +117,7 @@ typedef struct { * writable respectively. If none of these is set, then the handle has no host-level fd. */ #define PAL_HANDLE_FD_READABLE 1 #define PAL_HANDLE_FD_WRITABLE 2 -/* Set if an error was seen on this handle. Currently only set by `_DkStreamsWaitEvents`. */ +/* Set if an error was seen on this handle. Currently only set by `_PalStreamsWaitEvents`. */ #define PAL_HANDLE_FD_ERROR 4 int arch_do_rt_sigprocmask(int sig, int how); diff --git a/pal/src/host/skeleton/db_events.c b/pal/src/host/skeleton/db_events.c index 9df9b58511..5788522518 100644 --- a/pal/src/host/skeleton/db_events.c +++ b/pal/src/host/skeleton/db_events.c @@ -9,19 +9,19 @@ #include "pal_error.h" #include "pal_internal.h" -int _DkEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear) { +int _PalEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear) { return -PAL_ERROR_NOTIMPLEMENTED; } -void _DkEventSet(PAL_HANDLE handle) { +void _PalEventSet(PAL_HANDLE handle) { assert(0); } -void _DkEventClear(PAL_HANDLE handle) { +void _PalEventClear(PAL_HANDLE handle) { assert(0); } -int _DkEventWait(PAL_HANDLE handle, uint64_t* timeout_us) { +int _PalEventWait(PAL_HANDLE handle, uint64_t* timeout_us) { return -PAL_ERROR_NOTIMPLEMENTED; } diff --git a/pal/src/host/skeleton/db_main.c b/pal/src/host/skeleton/db_main.c index 99eb2907e7..e125ec2320 100644 --- a/pal/src/host/skeleton/db_main.c +++ b/pal/src/host/skeleton/db_main.c @@ -14,6 +14,6 @@ /* must implement "pal_start", and call "pal_main" inside */ void pal_start(void); -void _DkGetAvailableUserAddressRange(void** out_start, void** out_end) { +void _PalGetAvailableUserAddressRange(void** out_start, void** out_end) { /* needs to be implemented */ } diff --git a/pal/src/host/skeleton/db_memory.c b/pal/src/host/skeleton/db_memory.c index 59919be6f9..2f4e85a3a9 100644 --- a/pal/src/host/skeleton/db_memory.c +++ b/pal/src/host/skeleton/db_memory.c @@ -10,27 +10,27 @@ #include "pal_error.h" #include "pal_internal.h" -bool _DkCheckMemoryMappable(const void* addr, size_t size) { +bool _PalCheckMemoryMappable(const void* addr, size_t size) { return true; } -int _DkVirtualMemoryAlloc(void** addr_ptr, uint64_t size, pal_alloc_flags_t alloc_type, - pal_prot_flags_t prot) { +int _PalVirtualMemoryAlloc(void** addr_ptr, uint64_t size, pal_alloc_flags_t alloc_type, + pal_prot_flags_t prot) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkVirtualMemoryFree(void* addr, uint64_t size) { +int _PalVirtualMemoryFree(void* addr, uint64_t size) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkVirtualMemoryProtect(void* addr, uint64_t size, pal_prot_flags_t prot) { +int _PalVirtualMemoryProtect(void* addr, uint64_t size, pal_prot_flags_t prot) { return -PAL_ERROR_NOTIMPLEMENTED; } -unsigned long _DkMemoryQuota(void) { +unsigned long _PalMemoryQuota(void) { return 0; } -unsigned long _DkMemoryAvailableQuota(void) { +unsigned long _PalMemoryAvailableQuota(void) { return 0; } diff --git a/pal/src/host/skeleton/db_misc.c b/pal/src/host/skeleton/db_misc.c index f141c4d94d..54be97ef02 100644 --- a/pal/src/host/skeleton/db_misc.c +++ b/pal/src/host/skeleton/db_misc.c @@ -11,29 +11,29 @@ #include "pal_error.h" #include "pal_internal.h" -int _DkSystemTimeQuery(uint64_t* out_usec) { +int _PalSystemTimeQuery(uint64_t* out_usec) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkRandomBitsRead(void* buffer, size_t size) { +int _PalRandomBitsRead(void* buffer, size_t size) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { +int _PalSegmentBaseGet(enum pal_segment_reg reg, uintptr_t* addr) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr) { +int _PalSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) { +int _PalCpuIdRetrieve(uint32_t leaf, uint32_t subleaf, uint32_t values[4]) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkAttestationReport(const void* user_report_data, size_t* user_report_data_size, - void* target_info, size_t* target_info_size, void* report, - size_t* report_size) { +int _PalAttestationReport(const void* user_report_data, size_t* user_report_data_size, + void* target_info, size_t* target_info_size, void* report, + size_t* report_size) { __UNUSED(user_report_data); __UNUSED(user_report_data_size); __UNUSED(target_info); @@ -43,8 +43,8 @@ int _DkAttestationReport(const void* user_report_data, size_t* user_report_data_ return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, - size_t* quote_size) { +int _PalAttestationQuote(const void* user_report_data, size_t user_report_data_size, void* quote, + size_t* quote_size) { __UNUSED(user_report_data); __UNUSED(user_report_data_size); __UNUSED(quote); @@ -52,14 +52,14 @@ int _DkAttestationQuote(const void* user_report_data, size_t user_report_data_si return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkGetSpecialKey(const char* name, void* key, size_t* key_size) { +int _PalGetSpecialKey(const char* name, void* key, size_t* key_size) { __UNUSED(name); __UNUSED(key); __UNUSED(key_size); return -PAL_ERROR_NOTIMPLEMENTED; } -double _DkGetBogomips(void) { +double _PalGetBogomips(void) { /* this has to be implemented */ return 0.0; } diff --git a/pal/src/host/skeleton/db_object.c b/pal/src/host/skeleton/db_object.c index ef7d69d69b..4ca257f912 100644 --- a/pal/src/host/skeleton/db_object.c +++ b/pal/src/host/skeleton/db_object.c @@ -10,7 +10,7 @@ #include "pal_error.h" #include "pal_internal.h" -int _DkStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, - pal_wait_flags_t* ret_events, uint64_t* timeout_us) { +int _PalStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_t* events, + pal_wait_flags_t* ret_events, uint64_t* timeout_us) { return -PAL_ERROR_NOTIMPLEMENTED; } diff --git a/pal/src/host/skeleton/db_process.c b/pal/src/host/skeleton/db_process.c index f58c422e34..98920062e7 100644 --- a/pal/src/host/skeleton/db_process.c +++ b/pal/src/host/skeleton/db_process.c @@ -14,11 +14,11 @@ #include "pal_error.h" #include "pal_internal.h" -int _DkProcessCreate(PAL_HANDLE* handle, const char** args) { +int _PalProcessCreate(PAL_HANDLE* handle, const char** args) { return -PAL_ERROR_NOTIMPLEMENTED; } -noreturn void _DkProcessExit(int exitcode) { +noreturn void _PalProcessExit(int exitcode) { die_or_inf_loop(); } diff --git a/pal/src/host/skeleton/db_rtld.c b/pal/src/host/skeleton/db_rtld.c index 8c70b04a23..368d1b0d2b 100644 --- a/pal/src/host/skeleton/db_rtld.c +++ b/pal/src/host/skeleton/db_rtld.c @@ -9,11 +9,11 @@ #include "pal_rtld.h" -void _DkDebugMapAdd(const char* name, void* addr) {} +void _PalDebugMapAdd(const char* name, void* addr) {} -void _DkDebugMapRemove(void* addr) {} +void _PalDebugMapRemove(void* addr) {} -int _DkDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size) { +int _PalDebugDescribeLocation(uintptr_t addr, char* buf, size_t buf_size) { __UNUSED(addr); __UNUSED(buf); __UNUSED(buf_size); diff --git a/pal/src/host/skeleton/db_sockets.c b/pal/src/host/skeleton/db_sockets.c index e5a948cbc6..b93db8c633 100644 --- a/pal/src/host/skeleton/db_sockets.c +++ b/pal/src/host/skeleton/db_sockets.c @@ -5,35 +5,35 @@ #include "pal_internal.h" -int _DkSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, - pal_stream_options_t options, PAL_HANDLE* out_handle) { +int _PalSocketCreate(enum pal_socket_domain domain, enum pal_socket_type type, + pal_stream_options_t options, PAL_HANDLE* out_handle) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { +int _PalSocketBind(PAL_HANDLE handle, struct pal_socket_addr* addr) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSocketListen(PAL_HANDLE handle, unsigned int backlog) { +int _PalSocketListen(PAL_HANDLE handle, unsigned int backlog) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, - struct pal_socket_addr* out_client_addr) { +int _PalSocketAccept(PAL_HANDLE handle, pal_stream_options_t options, PAL_HANDLE* out_client, + struct pal_socket_addr* out_client_addr) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, - struct pal_socket_addr* local_addr) { +int _PalSocketConnect(PAL_HANDLE handle, struct pal_socket_addr* addr, + struct pal_socket_addr* local_addr) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, - struct pal_socket_addr* addr) { +int _PalSocketSend(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_size, + struct pal_socket_addr* addr) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, - struct pal_socket_addr* addr, bool force_nonblocking) { +int _PalSocketRecv(PAL_HANDLE handle, struct pal_iovec* iov, size_t iov_len, size_t* out_total_size, + struct pal_socket_addr* addr, bool force_nonblocking) { return -PAL_ERROR_NOTIMPLEMENTED; } diff --git a/pal/src/host/skeleton/db_streams.c b/pal/src/host/skeleton/db_streams.c index 3a3521040f..5d521f3188 100644 --- a/pal/src/host/skeleton/db_streams.c +++ b/pal/src/host/skeleton/db_streams.c @@ -10,22 +10,22 @@ #include "pal_error.h" #include "pal_internal.h" -int _DkStreamUnmap(void* addr, uint64_t size) { +int _PalStreamUnmap(void* addr, uint64_t size) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { +int _PalSendHandle(PAL_HANDLE target_process, PAL_HANDLE cargo) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { +int _PalReceiveHandle(PAL_HANDLE source_process, PAL_HANDLE* out_cargo) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkInitDebugStream(const char* path) { +int _PalInitDebugStream(const char* path) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkDebugLog(const void* buf, size_t size) { +int _PalDebugLog(const void* buf, size_t size) { return -PAL_ERROR_NOTIMPLEMENTED; } diff --git a/pal/src/host/skeleton/db_threading.c b/pal/src/host/skeleton/db_threading.c index 42f96425e9..51e1eb6551 100644 --- a/pal/src/host/skeleton/db_threading.c +++ b/pal/src/host/skeleton/db_threading.c @@ -10,34 +10,33 @@ #include "pal_error.h" #include "pal_internal.h" -/* _DkThreadCreate for internal use. Create an internal thread - inside the current process. The arguments callback and param - specify the starting function and parameters */ -int _DkThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param) { +/* _PalThreadCreate for internal use. Create an internal thread inside the current process. The + * arguments callback and param specify the starting function and parameters. */ +int _PalThreadCreate(PAL_HANDLE* handle, int (*callback)(void*), void* param) { return -PAL_ERROR_NOTIMPLEMENTED; } -/* PAL call DkThreadYieldExecution. Yield the execution +/* PAL call PalThreadYieldExecution. Yield the execution of the current thread. */ -void _DkThreadYieldExecution(void) { +void _PalThreadYieldExecution(void) { /* needs to be implemented */ } -/* _DkThreadExit for internal use: Thread exiting */ -noreturn void _DkThreadExit(int* clear_child_tid) { +/* _PalThreadExit for internal use: Thread exiting */ +noreturn void _PalThreadExit(int* clear_child_tid) { /* needs to be implemented */ die_or_inf_loop(); } -int _DkThreadResume(PAL_HANDLE thread_handle) { +int _PalThreadResume(PAL_HANDLE thread_handle) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { +int _PalThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { +int _PalThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask) { return -PAL_ERROR_NOTIMPLEMENTED; } diff --git a/pal/src/pal-symbols b/pal/src/pal-symbols index 0ac3430ea3..60faef0ceb 100644 --- a/pal/src/pal-symbols +++ b/pal/src/pal-symbols @@ -1,55 +1,55 @@ -DkVirtualMemoryAlloc -DkVirtualMemoryFree -DkVirtualMemoryProtect -DkThreadCreate -DkThreadYieldExecution -DkThreadExit -DkThreadResume -DkThreadSetCpuAffinity -DkThreadGetCpuAffinity -DkEventCreate -DkEventSet -DkEventClear -DkEventWait -DkStreamsWaitEvents -DkStreamOpen -DkStreamRead -DkStreamWrite -DkStreamMap -DkStreamUnmap -DkStreamSetLength -DkStreamFlush -DkStreamDelete -DkSocketCreate -DkSocketBind -DkSocketListen -DkSocketAccept -DkSocketConnect -DkSocketSend -DkSocketRecv -DkSendHandle -DkReceiveHandle -DkStreamWaitForClient -DkStreamGetName -DkStreamAttributesQueryByHandle -DkStreamAttributesQuery -DkProcessCreate -DkProcessExit -DkSystemTimeQuery -DkRandomBitsRead -DkCpuIdRetrieve -DkObjectClose -DkSetExceptionHandler -DkSegmentBaseGet -DkSegmentBaseSet -DkStreamChangeName -DkStreamAttributesSetByHandle -DkMemoryAvailableQuota -DkDebugMapAdd -DkDebugMapRemove -DkDebugDescribeLocation -DkAttestationReport -DkAttestationQuote -DkGetSpecialKey -DkDebugLog -DkGetPalPublicState +PalVirtualMemoryAlloc +PalVirtualMemoryFree +PalVirtualMemoryProtect +PalThreadCreate +PalThreadYieldExecution +PalThreadExit +PalThreadResume +PalThreadSetCpuAffinity +PalThreadGetCpuAffinity +PalEventCreate +PalEventSet +PalEventClear +PalEventWait +PalStreamsWaitEvents +PalStreamOpen +PalStreamRead +PalStreamWrite +PalStreamMap +PalStreamUnmap +PalStreamSetLength +PalStreamFlush +PalStreamDelete +PalSocketCreate +PalSocketBind +PalSocketListen +PalSocketAccept +PalSocketConnect +PalSocketSend +PalSocketRecv +PalSendHandle +PalReceiveHandle +PalStreamWaitForClient +PalStreamGetName +PalStreamAttributesQueryByHandle +PalStreamAttributesQuery +PalProcessCreate +PalProcessExit +PalSystemTimeQuery +PalRandomBitsRead +PalCpuIdRetrieve +PalObjectClose +PalSetExceptionHandler +PalSegmentBaseGet +PalSegmentBaseSet +PalStreamChangeName +PalStreamAttributesSetByHandle +PalMemoryAvailableQuota +PalDebugMapAdd +PalDebugMapRemove +PalDebugDescribeLocation +PalAttestationReport +PalAttestationQuote +PalGetSpecialKey +PalDebugLog +PalGetPalPublicState diff --git a/pal/src/printf.c b/pal/src/printf.c index 6d989391bf..03b6edb518 100644 --- a/pal/src/printf.c +++ b/pal/src/printf.c @@ -8,7 +8,7 @@ static int buf_write_all(const char* str, size_t size, void* arg) { __UNUSED(arg); - _DkDebugLog(str, size); + _PalDebugLog(str, size); return 0; } diff --git a/pal/src/slab.c b/pal/src/slab.c index 3e16dd1e80..dba10c6d89 100644 --- a/pal/src/slab.c +++ b/pal/src/slab.c @@ -63,11 +63,11 @@ static inline void* __malloc(size_t size) { /* We could not use `g_mem_pool`, let's fall back to PAL-internal allocations. PAL allocator * must be careful though because LibOS doesn't know about PAL-internal memory, limited via * manifest option `loader.pal_internal_mem_size` and thus this malloc may return -ENOMEM. */ - int ret = _DkVirtualMemoryAlloc(&addr, ALLOC_ALIGN_UP(size), PAL_ALLOC_INTERNAL, - PAL_PROT_READ | PAL_PROT_WRITE); + int ret = _PalVirtualMemoryAlloc(&addr, ALLOC_ALIGN_UP(size), PAL_ALLOC_INTERNAL, + PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { log_error("*** Out-of-memory in PAL (try increasing `loader.pal_internal_mem_size`) ***"); - _DkProcessExit(1); + _PalProcessExit(1); } #ifdef ASAN asan_poison_region((uintptr_t)addr, ALLOC_ALIGN_UP(size), ASAN_POISON_HEAP_LEFT_REDZONE); @@ -106,7 +106,7 @@ static inline void __free(void* addr, size_t size) { asan_unpoison_region((uintptr_t)addr, ALLOC_ALIGN_UP(size)); #endif - _DkVirtualMemoryFree(addr, ALLOC_ALIGN_UP(size)); + _PalVirtualMemoryFree(addr, ALLOC_ALIGN_UP(size)); } static SLAB_MGR g_slab_mgr = NULL; @@ -149,7 +149,7 @@ void* malloc(size_t size) { * condition and must terminate the current process. */ log_error("******** Out-of-memory in PAL ********"); - _DkProcessExit(1); + _PalProcessExit(1); } return ptr; }