Skip to content

Commit

Permalink
Remove PAL_NUM type
Browse files Browse the repository at this point in the history
Signed-off-by: Mariusz Zaborski <[email protected]>
  • Loading branch information
oshogbo authored and mkow committed May 30, 2022
1 parent 3f2478b commit d6dda21
Show file tree
Hide file tree
Showing 27 changed files with 129 additions and 135 deletions.
2 changes: 1 addition & 1 deletion Documentation/devel/new-syscall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ 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(PAL_NUM cpu_num, PAL_IDX* cpu_indexes);
bool DkThreadSetCPUAffinity(size_t cpu_num, PAL_IDX* cpu_indexes);

The naming convention of a |~| PAL call is to start functions with the ``Dk``
prefix, followed by a comprehensive name describing the purpose of the PAL
Expand Down
2 changes: 0 additions & 2 deletions Documentation/pal/host-abi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ may be variable-sized.
Basic types
"""""""""""

.. doxygentypedef:: PAL_NUM
:project: pal
.. doxygentypedef:: PAL_IDX
:project: pal

Expand Down
14 changes: 7 additions & 7 deletions LibOS/shim/src/bookkeep/shim_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ static bool context_is_libos(PAL_CONTEXT* context) {
return (uintptr_t)&__load_address <= ip && ip < (uintptr_t)&__load_address_end;
}

static noreturn void internal_fault(const char* errstr, PAL_NUM addr, PAL_CONTEXT* context) {
static noreturn void internal_fault(const char* errstr, uintptr_t addr, PAL_CONTEXT* context) {
IDTYPE tid = get_cur_tid();
PAL_NUM ip = pal_context_get_ip(context);
uintptr_t ip = pal_context_get_ip(context);

char buf[LOCATION_BUF_SIZE];
shim_describe_location(ip, buf, sizeof(buf));
Expand All @@ -316,7 +316,7 @@ static noreturn void internal_fault(const char* errstr, PAL_NUM addr, PAL_CONTEX
DkProcessExit(1);
}

static void arithmetic_error_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context) {
static void arithmetic_error_upcall(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) {
__UNUSED(is_in_pal);
assert(!is_in_pal);
assert(context);
Expand All @@ -335,7 +335,7 @@ static void arithmetic_error_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* c
}
}

static void memfault_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context) {
static void memfault_upcall(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) {
__UNUSED(is_in_pal);
assert(!is_in_pal);
assert(context);
Expand Down Expand Up @@ -451,7 +451,7 @@ bool is_user_string_readable(const char* addr) {
}
}

static void illegal_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context) {
static void illegal_upcall(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) {
__UNUSED(is_in_pal);
assert(!is_in_pal);
assert(context);
Expand Down Expand Up @@ -481,7 +481,7 @@ static void illegal_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context) {
/* else syscall was emulated. */
}

static void quit_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context) {
static void quit_upcall(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) {
__UNUSED(addr);

if (!g_inject_host_signal_enabled) {
Expand All @@ -504,7 +504,7 @@ static void quit_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context) {
handle_signal(context);
}

static void interrupted_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context) {
static void interrupted_upcall(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) {
__UNUSED(addr);

/* "interrupted" signal may occur during LibOS thread initialization (at which point
Expand Down
6 changes: 3 additions & 3 deletions LibOS/shim/src/shim_checkpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static int receive_memory_on_stream(PAL_HANDLE handle, struct checkpoint_hdr* hd
log_debug("memory entry [%p]: %p-%p", entry, entry->addr, entry->addr + entry->size);

void* addr = ALLOC_ALIGN_DOWN_PTR(entry->addr);
PAL_NUM size = (char*)ALLOC_ALIGN_UP_PTR(entry->addr + entry->size) - (char*)addr;
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);
Expand Down Expand Up @@ -599,7 +599,7 @@ int receive_checkpoint_and_restore(struct checkpoint_hdr* hdr) {

void* base = hdr->addr;
void* mapaddr = ALLOC_ALIGN_DOWN_PTR(base);
PAL_NUM mapsize = (char*)ALLOC_ALIGN_UP_PTR(base + hdr->size) - (char*)mapaddr;
size_t mapsize = (char*)ALLOC_ALIGN_UP_PTR(base + hdr->size) - (char*)mapaddr;

/* first try allocating at address used by parent process */
if (g_pal_public_state->user_address_start <= mapaddr &&
Expand All @@ -624,7 +624,7 @@ int receive_checkpoint_and_restore(struct checkpoint_hdr* hdr) {
}

mapaddr = base;
mapsize = (PAL_NUM)ALLOC_ALIGN_UP(hdr->size);
mapsize = ALLOC_ALIGN_UP(hdr->size);
}

ret = DkVirtualMemoryAlloc(&mapaddr, mapsize, 0, PAL_PROT_READ | PAL_PROT_WRITE);
Expand Down
2 changes: 1 addition & 1 deletion LibOS/shim/src/sys/shim_eventfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int create_eventfd(PAL_HANDLE* efd, uint64_t initial_count, int flags) {
}

/* set the initial count */
PAL_NUM write_size = sizeof(initial_count);
size_t write_size = sizeof(initial_count);
ret = DkStreamWrite(hdl, /*offset=*/0, &write_size, &initial_count, /*dest=*/NULL);
if (ret < 0) {
log_error("eventfd: failed to set initial count");
Expand Down
14 changes: 7 additions & 7 deletions Pal/include/arch/x86_64/pal-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ static inline unsigned long count_ulong_bits_set(unsigned long x) {
struct pal_cpu_info {
const char* cpu_vendor;
const char* cpu_brand;
PAL_NUM cpu_family;
PAL_NUM cpu_model;
PAL_NUM cpu_stepping;
uint64_t cpu_family;
uint64_t cpu_model;
uint64_t cpu_stepping;
double cpu_bogomips;
const char* cpu_flags;
};
Expand Down Expand Up @@ -240,17 +240,17 @@ typedef int64_t arch_syscall_arg_t;
(context)->r9


static inline void pal_context_set_ip(PAL_CONTEXT* context, PAL_NUM insnptr) {
static inline void pal_context_set_ip(PAL_CONTEXT* context, uintptr_t insnptr) {
context->rip = insnptr;
}
static inline PAL_NUM pal_context_get_ip(PAL_CONTEXT* context) {
static inline uintptr_t pal_context_get_ip(PAL_CONTEXT* context) {
return context->rip;
}

static inline void pal_context_set_sp(PAL_CONTEXT* context, PAL_NUM sp) {
static inline void pal_context_set_sp(PAL_CONTEXT* context, uintptr_t sp) {
context->rsp = sp;
}
static inline PAL_NUM pal_context_get_sp(PAL_CONTEXT* context) {
static inline uintptr_t pal_context_get_sp(PAL_CONTEXT* context) {
return context->rsp;
}

Expand Down
59 changes: 29 additions & 30 deletions Pal/include/pal/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* declare a dependency on it. */
typedef struct toml_table_t toml_table_t;

typedef uint64_t PAL_NUM; /*!< a number */
typedef uint32_t PAL_IDX; /*!< an index */

/* maximum length of pipe/FIFO name (should be less than Linux sockaddr_un.sun_path = 108) */
Expand Down Expand Up @@ -120,7 +119,7 @@ struct pal_public_state {
* looking from the LibOS perspective. The two values can be different on the PAL level though,
* see e.g. SYSTEM_INFO::dwAllocationGranularity on Windows.
*/
PAL_NUM alloc_align;
size_t alloc_align;

size_t mem_total;

Expand Down Expand Up @@ -166,7 +165,7 @@ typedef uint32_t pal_prot_flags_t; /* bitfield */
* differ only in the `NULL` case).
*
*/
int DkVirtualMemoryAlloc(void** addr_ptr, PAL_NUM size, pal_alloc_flags_t alloc_type,
int DkVirtualMemoryAlloc(void** addr_ptr, size_t size, pal_alloc_flags_t alloc_type,
pal_prot_flags_t prot);

/*!
Expand All @@ -177,7 +176,7 @@ int DkVirtualMemoryAlloc(void** addr_ptr, PAL_NUM size, pal_alloc_flags_t alloc_
*
* Both `addr` and `size` must be non-zero and aligned at the allocation alignment.
*/
int DkVirtualMemoryFree(void* addr, PAL_NUM size);
int DkVirtualMemoryFree(void* addr, size_t size);

/*!
* \brief Modify the permissions of a previously allocated memory mapping.
Expand All @@ -188,7 +187,7 @@ int DkVirtualMemoryFree(void* addr, PAL_NUM size);
*
* Both `addr` and `size` must be non-zero and aligned at the allocation alignment.
*/
int DkVirtualMemoryProtect(void* addr, PAL_NUM size, pal_prot_flags_t prot);
int DkVirtualMemoryProtect(void* addr, size_t size, pal_prot_flags_t prot);

/*
* PROCESS CREATION
Expand All @@ -212,7 +211,7 @@ int DkProcessCreate(const char** args, PAL_HANDLE* handle);
*
* \param exit_code The exit value returned to the host.
*/
noreturn void DkProcessExit(PAL_NUM exit_code);
noreturn void DkProcessExit(int exit_code);

/*
* STREAMS
Expand Down Expand Up @@ -319,8 +318,8 @@ int DkStreamWaitForClient(PAL_HANDLE handle, PAL_HANDLE* client, pal_stream_opti
* If \p handle is a directory, DkStreamRead fills the buffer with the null-terminated names of the
* directory entries.
*/
int DkStreamRead(PAL_HANDLE handle, PAL_NUM offset, PAL_NUM* count, void* buffer, char* source,
PAL_NUM size);
int DkStreamRead(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer, char* source,
size_t size);

/*!
* \brief Write data to an open stream.
Expand All @@ -335,7 +334,7 @@ int DkStreamRead(PAL_HANDLE handle, PAL_NUM offset, PAL_NUM* count, void* buffer
*
* \returns 0 on success, negative error code on failure.
*/
int DkStreamWrite(PAL_HANDLE handle, PAL_NUM offset, PAL_NUM* count, void* buffer,
int DkStreamWrite(PAL_HANDLE handle, uint64_t offset, size_t* count, void* buffer,
const char* dest);

enum pal_delete_mode {
Expand All @@ -362,8 +361,8 @@ int DkStreamDelete(PAL_HANDLE handle, enum pal_delete_mode delete_mode);
*
* \returns 0 on success, negative error code on failure.
*/
int DkStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, PAL_NUM offset,
PAL_NUM size);
int DkStreamMap(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.
Expand All @@ -372,14 +371,14 @@ int DkStreamMap(PAL_HANDLE handle, void** addr_ptr, pal_prot_flags_t prot, PAL_N
*
* \returns 0 on success, negative error code on failure.
*/
int DkStreamUnmap(void* addr, PAL_NUM size);
int DkStreamUnmap(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, PAL_NUM length);
int DkStreamSetLength(PAL_HANDLE handle, uint64_t length);

/*!
* \brief Flush the buffer of a file stream.
Expand Down Expand Up @@ -414,11 +413,11 @@ typedef struct _PAL_STREAM_ATTR {
PAL_IDX handle_type;
bool nonblocking;
pal_share_flags_t share_flags;
PAL_NUM pending_size;
size_t pending_size;
union {
struct {
PAL_NUM linger;
PAL_NUM receivebuf, sendbuf;
uint64_t linger;
size_t receivebuf, sendbuf;
uint64_t receivetimeout_us, sendtimeout_us;
bool tcp_cork;
bool tcp_keepalive;
Expand Down Expand Up @@ -449,7 +448,7 @@ int DkStreamAttributesSetByHandle(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, PAL_NUM size);
int DkStreamGetName(PAL_HANDLE handle, char* buffer, size_t size);

/*!
* \brief This API changes the name of an open stream.
Expand Down Expand Up @@ -500,7 +499,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, PAL_NUM cpumask_size, unsigned long* cpu_mask);
int DkThreadSetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask);

/*!
* \brief Get the CPU affinity of a thread.
Expand All @@ -515,7 +514,7 @@ int DkThreadSetCpuAffinity(PAL_HANDLE thread, PAL_NUM cpumask_size, unsigned lon
* 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, PAL_NUM cpumask_size, unsigned long* cpu_mask);
int DkThreadGetCpuAffinity(PAL_HANDLE thread, size_t cpumask_size, unsigned long* cpu_mask);

/*
* Exception Handling
Expand Down Expand Up @@ -547,7 +546,7 @@ enum pal_event {
* \param addr Address of the exception (meaningful only for sync exceptions).
* \param context CPU context at the moment of exception.
*/
typedef void (*pal_event_handler_t)(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context);
typedef void (*pal_event_handler_t)(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context);

/*!
* \brief Set the handler for the specific exception event.
Expand Down Expand Up @@ -591,7 +590,7 @@ void DkEventSet(PAL_HANDLE handle);
void DkEventClear(PAL_HANDLE handle);

/*! block until the handle's event is triggered */
#define NO_TIMEOUT ((PAL_NUM)-1)
#define NO_TIMEOUT ((uint64_t)-1)

/*!
* \brief Wait for an event handle.
Expand Down Expand Up @@ -651,14 +650,14 @@ void DkObjectClose(PAL_HANDLE object_handle);
*
* \returns 0 on success, negative error code on failure.
*/
int DkDebugLog(const void* buffer, PAL_NUM size);
int DkDebugLog(const void* buffer, size_t size);

/*!
* \brief Get the current time.
*
* \param[out] time On success holds the current time in microseconds.
*/
int DkSystemTimeQuery(PAL_NUM* time);
int DkSystemTimeQuery(uint64_t* time);

/*!
* \brief Cryptographically secure RNG.
Expand All @@ -668,7 +667,7 @@ int DkSystemTimeQuery(PAL_NUM* time);
*
* \returns 0 on success, negative on failure.
*/
int DkRandomBitsRead(void* buffer, PAL_NUM size);
int DkRandomBitsRead(void* buffer, size_t size);

enum pal_segment_reg {
PAL_SEGMENT_FS,
Expand Down Expand Up @@ -698,7 +697,7 @@ int DkSegmentBaseSet(enum pal_segment_reg reg, uintptr_t addr);
/*!
* \brief Return the amount of currently available memory for LibOS/application usage.
*/
PAL_NUM DkMemoryAvailableQuota(void);
size_t DkMemoryAvailableQuota(void);

/*!
* \brief Obtain the attestation report (local) with `user_report_data` embedded into it.
Expand Down Expand Up @@ -730,9 +729,9 @@ PAL_NUM 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, PAL_NUM* user_report_data_size,
void* target_info, PAL_NUM* target_info_size, void* report,
PAL_NUM* report_size);
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);

/*!
* \brief Obtain the attestation quote with `user_report_data` embedded into it.
Expand All @@ -749,8 +748,8 @@ int DkAttestationReport(const void* user_report_data, PAL_NUM* user_report_data_
* 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, PAL_NUM user_report_data_size, void* quote,
PAL_NUM* quote_size);
int DkAttestationQuote(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).
*
Expand Down
14 changes: 7 additions & 7 deletions Pal/include/pal_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ 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, PAL_NUM cpumask_size, unsigned long* cpu_mask);
int _DkThreadGetCpuAffinity(PAL_HANDLE thread, PAL_NUM cpumask_size, unsigned long* cpu_mask);
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);
Expand Down Expand Up @@ -227,11 +227,11 @@ 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, PAL_NUM* user_report_data_size,
void* target_info, PAL_NUM* target_info_size, void* report,
PAL_NUM* report_size);
int _DkAttestationQuote(const void* user_report_data, PAL_NUM user_report_data_size, void* quote,
PAL_NUM* quote_size);
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);

#define INIT_FAIL(exitcode, reason) \
Expand Down
Loading

0 comments on commit d6dda21

Please sign in to comment.