Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
[PAL] Make pal_type_* enum values uppercase
Browse files Browse the repository at this point in the history
Also remove SET_HANDLE_TYPE and IS_HANDLE_TYPE macros for grepability.

Signed-off-by: Borys Popławski <[email protected]>
  • Loading branch information
boryspoplawski authored and mkow committed Sep 6, 2021
1 parent 4f0e5ef commit 33a68bc
Show file tree
Hide file tree
Showing 27 changed files with 245 additions and 249 deletions.
8 changes: 4 additions & 4 deletions LibOS/shim/src/fs/chroot/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 238,23 @@ static int __query_attr(struct shim_dentry* dent, struct shim_file_data* data,
mode_t type;
/* need to correct the data type */
switch (pal_attr.handle_type) {
case pal_type_file:
case PAL_TYPE_FILE:
data->type = FILE_REGULAR;
type = S_IFREG;
break;
case pal_type_dir:
case PAL_TYPE_DIR:
data->type = FILE_DIR;
type = S_IFDIR;
break;
case pal_type_dev:
case PAL_TYPE_DEV:
if (strstartswith(qstrgetstr(&data->host_uri) static_strlen(URI_PREFIX_DEV), "tty")) {
data->type = FILE_TTY;
} else {
data->type = FILE_DEV;
}
type = S_IFCHR;
break;
case pal_type_pipe:
case PAL_TYPE_PIPE:
log_warning("trying to access '%s' which is a host-level FIFO (named pipe); "
"Graphene supports only named pipes created by Graphene processes",
qstrgetstr(&data->host_uri));
Expand Down
34 changes: 15 additions & 19 deletions Pal/include/pal/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 72,6 @@ static inline void init_handle_hdr(PAL_HDR* hdr, int pal_type) {
hdr->flags = 0;
}

#define SET_HANDLE_TYPE(handle, t) init_handle_hdr(HANDLE_HDR(handle), pal_type_##t)
#define IS_HANDLE_TYPE(handle, t) (HANDLE_HDR(handle)->type == pal_type_##t)

#else
typedef union pal_handle {
struct {
Expand All @@ -93,27 90,26 @@ typedef union pal_handle {

/********** PAL TYPE DEFINITIONS **********/
enum {
pal_type_file,
pal_type_pipe,
pal_type_pipesrv,
pal_type_pipecli,
pal_type_pipeprv,
pal_type_dev,
pal_type_dir,
pal_type_tcp,
pal_type_tcpsrv,
pal_type_udp,
pal_type_udpsrv,
pal_type_process,
pal_type_thread,
pal_type_event,
pal_type_eventfd,
PAL_TYPE_FILE,
PAL_TYPE_PIPE,
PAL_TYPE_PIPESRV,
PAL_TYPE_PIPECLI,
PAL_TYPE_PIPEPRV,
PAL_TYPE_DEV,
PAL_TYPE_DIR,
PAL_TYPE_TCP,
PAL_TYPE_TCPSRV,
PAL_TYPE_UDP,
PAL_TYPE_UDPSRV,
PAL_TYPE_PROCESS,
PAL_TYPE_THREAD,
PAL_TYPE_EVENT,
PAL_TYPE_EVENTFD,
PAL_HANDLE_TYPE_BOUND,
};

#define PAL_IDX_POISON ((PAL_IDX)-1) /* PAL identifier poison value */
#define PAL_GET_TYPE(h) (HANDLE_HDR(h)->type)
#define PAL_CHECK_TYPE(h, t) (PAL_GET_TYPE(h) == pal_type_##t)
#define UNKNOWN_HANDLE(handle) (PAL_GET_TYPE(handle) >= PAL_HANDLE_TYPE_BOUND)

typedef struct PAL_PTR_RANGE_ {
Expand Down
6 changes: 3 additions & 3 deletions Pal/regression/SendHandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,7 @@ int main(int argc, char** argv) {
memset(buffer, 0, 20);

switch (PAL_GET_TYPE(handles[i])) {
case pal_type_pipesrv: {
case PAL_TYPE_PIPESRV: {
PAL_HANDLE pipe = NULL;
ret = DkStreamWaitForClient(handles[i], &pipe);

Expand All @@ -38,7 38,7 @@ int main(int argc, char** argv) {
break;
}

case pal_type_udpsrv: {
case PAL_TYPE_UDPSRV: {
char uri[20];

size = sizeof(buffer);
Expand All @@ -49,7 49,7 @@ int main(int argc, char** argv) {
break;
}

case pal_type_file:
case PAL_TYPE_FILE:
size = sizeof(buffer);
ret = DkStreamRead(handles[i], 0, &size, buffer, NULL, 0);
if (ret == 0 && size > 0)
Expand Down
6 changes: 3 additions & 3 deletions Pal/src/db_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 13,16 @@ int DkEventCreate(PAL_HANDLE* handle, bool init_signaled, bool auto_clear) {
}

void DkEventSet(PAL_HANDLE handle) {
assert(handle && IS_HANDLE_TYPE(handle, event));
assert(handle && HANDLE_HDR(handle)->type == PAL_TYPE_EVENT);
_DkEventSet(handle);
}

void DkEventClear(PAL_HANDLE handle) {
assert(handle && IS_HANDLE_TYPE(handle, event));
assert(handle && HANDLE_HDR(handle)->type == PAL_TYPE_EVENT);
_DkEventClear(handle);
}

int DkEventWait(PAL_HANDLE handle, uint64_t* timeout_us) {
assert(handle && IS_HANDLE_TYPE(handle, event));
assert(handle && HANDLE_HDR(handle)->type == PAL_TYPE_EVENT);
return _DkEventWait(handle, timeout_us);
}
30 changes: 15 additions & 15 deletions Pal/src/db_streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 27,21 @@ extern struct handle_ops g_event_ops;
extern struct handle_ops g_eventfd_ops;

const struct handle_ops* g_pal_handle_ops[PAL_HANDLE_TYPE_BOUND] = {
[pal_type_file] = &g_file_ops,
[pal_type_pipe] = &g_pipe_ops,
[pal_type_pipesrv] = &g_pipe_ops,
[pal_type_pipecli] = &g_pipe_ops,
[pal_type_pipeprv] = &g_pipeprv_ops,
[pal_type_dev] = &g_dev_ops,
[pal_type_dir] = &g_dir_ops,
[pal_type_tcp] = &g_tcp_ops,
[pal_type_tcpsrv] = &g_tcp_ops,
[pal_type_udp] = &g_udp_ops,
[pal_type_udpsrv] = &g_udpsrv_ops,
[pal_type_process] = &g_proc_ops,
[pal_type_thread] = &g_thread_ops,
[pal_type_event] = &g_event_ops,
[pal_type_eventfd] = &g_eventfd_ops,
[PAL_TYPE_FILE] = &g_file_ops,
[PAL_TYPE_PIPE] = &g_pipe_ops,
[PAL_TYPE_PIPESRV] = &g_pipe_ops,
[PAL_TYPE_PIPECLI] = &g_pipe_ops,
[PAL_TYPE_PIPEPRV] = &g_pipeprv_ops,
[PAL_TYPE_DEV] = &g_dev_ops,
[PAL_TYPE_DIR] = &g_dir_ops,
[PAL_TYPE_TCP] = &g_tcp_ops,
[PAL_TYPE_TCPSRV] = &g_tcp_ops,
[PAL_TYPE_UDP] = &g_udp_ops,
[PAL_TYPE_UDPSRV] = &g_udpsrv_ops,
[PAL_TYPE_PROCESS] = &g_proc_ops,
[PAL_TYPE_THREAD] = &g_thread_ops,
[PAL_TYPE_EVENT] = &g_event_ops,
[PAL_TYPE_EVENTFD] = &g_eventfd_ops,
};

/* parse_stream_uri scan the uri, seperate prefix and search for
Expand Down
2 changes: 1 addition & 1 deletion Pal/src/db_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 30,7 @@ noreturn void DkThreadExit(PAL_PTR clear_child_tid) {

/* PAL call DkThreadResume: resume the execution of a thread which is delayed before */
int DkThreadResume(PAL_HANDLE threadHandle) {
if (!threadHandle || !IS_HANDLE_TYPE(threadHandle, thread)) {
if (!threadHandle || HANDLE_HDR(threadHandle)->type != PAL_TYPE_THREAD) {
return -PAL_ERROR_INVAL;
}

Expand Down
16 changes: 8 additions & 8 deletions Pal/src/host/Linux-SGX/db_devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 37,7 @@ static int dev_open(PAL_HANDLE* handle, const char* type, const char* uri, int a
if (!hdl)
return -PAL_ERROR_NOMEM;

SET_HANDLE_TYPE(hdl, dev);
init_handle_hdr(HANDLE_HDR(hdl), PAL_TYPE_DEV);

if (!strcmp(uri, "tty")) {
/* special case of "dev:tty" device which is the standard input standard output */
Expand Down Expand Up @@ -86,7 86,7 @@ static int dev_open(PAL_HANDLE* handle, const char* type, const char* uri, int a
}

static int64_t dev_read(PAL_HANDLE handle, uint64_t offset, uint64_t size, void* buffer) {
if (offset || !IS_HANDLE_TYPE(handle, dev))
if (offset || HANDLE_HDR(handle)->type != PAL_TYPE_DEV)
return -PAL_ERROR_INVAL;

if (!(HANDLE_HDR(handle)->flags & RFD(0)))
Expand All @@ -100,7 100,7 @@ static int64_t dev_read(PAL_HANDLE handle, uint64_t offset, uint64_t size, void*
}

static int64_t dev_write(PAL_HANDLE handle, uint64_t offset, uint64_t size, const void* buffer) {
if (offset || !IS_HANDLE_TYPE(handle, dev))
if (offset || HANDLE_HDR(handle)->type != PAL_TYPE_DEV)
return -PAL_ERROR_INVAL;

if (!(HANDLE_HDR(handle)->flags & WFD(0)))
Expand All @@ -114,7 114,7 @@ static int64_t dev_write(PAL_HANDLE handle, uint64_t offset, uint64_t size, cons
}

static int dev_close(PAL_HANDLE handle) {
if (!IS_HANDLE_TYPE(handle, dev))
if (HANDLE_HDR(handle)->type != PAL_TYPE_DEV)
return -PAL_ERROR_INVAL;

/* currently we just assign `0`/`1` FDs without duplicating, so close is a no-op for them */
Expand All @@ -127,7 127,7 @@ static int dev_close(PAL_HANDLE handle) {
}

static int dev_flush(PAL_HANDLE handle) {
if (!IS_HANDLE_TYPE(handle, dev))
if (HANDLE_HDR(handle)->type != PAL_TYPE_DEV)
return -PAL_ERROR_INVAL;

if (handle->dev.fd != PAL_IDX_POISON) {
Expand Down Expand Up @@ -173,13 173,13 @@ static int dev_attrquery(const char* type, const char* uri, PAL_STREAM_ATTR* att
ocall_close(fd);
}

attr->handle_type = pal_type_dev;
attr->handle_type = PAL_TYPE_DEV;
attr->nonblocking = PAL_FALSE;
return 0;
}

static int dev_attrquerybyhdl(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) {
if (!IS_HANDLE_TYPE(handle, dev))
if (HANDLE_HDR(handle)->type != PAL_TYPE_DEV)
return -PAL_ERROR_INVAL;

if (handle->dev.fd == 0 || handle->dev.fd == 1) {
Expand All @@ -203,7 203,7 @@ static int dev_attrquerybyhdl(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) {
attr->pending_size = stat_buf.st_size;
}

attr->handle_type = pal_type_dev;
attr->handle_type = PAL_TYPE_DEV;
attr->nonblocking = handle->dev.nonblocking;
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions Pal/src/host/Linux-SGX/db_eventfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 57,7 @@ static int eventfd_pal_open(PAL_HANDLE* handle, const char* type, const char* ur
ocall_close(fd);
return -PAL_ERROR_NOMEM;
}
SET_HANDLE_TYPE(hdl, eventfd);
init_handle_hdr(HANDLE_HDR(hdl), PAL_TYPE_EVENTFD);

/* Note: using index 0, given that there is only 1 eventfd FD per pal-handle. */
HANDLE_HDR(hdl)->flags = RFD(0) | WFD(0);
Expand All @@ -73,7 73,7 @@ static int64_t eventfd_pal_read(PAL_HANDLE handle, uint64_t offset, uint64_t len
if (offset)
return -PAL_ERROR_INVAL;

if (!IS_HANDLE_TYPE(handle, eventfd))
if (HANDLE_HDR(handle)->type != PAL_TYPE_EVENTFD)
return -PAL_ERROR_NOTCONNECTION;

if (len < sizeof(uint64_t))
Expand All @@ -94,7 94,7 @@ static int64_t eventfd_pal_write(PAL_HANDLE handle, uint64_t offset, uint64_t le
if (offset)
return -PAL_ERROR_INVAL;

if (!IS_HANDLE_TYPE(handle, eventfd))
if (HANDLE_HDR(handle)->type != PAL_TYPE_EVENTFD)
return -PAL_ERROR_NOTCONNECTION;

if (len < sizeof(uint64_t))
Expand Down Expand Up @@ -144,7 144,7 @@ static int eventfd_pal_attrquerybyhdl(PAL_HANDLE handle, PAL_STREAM_ATTR* attr)
}

static int eventfd_pal_close(PAL_HANDLE handle) {
if (IS_HANDLE_TYPE(handle, eventfd)) {
if (HANDLE_HDR(handle)->type == PAL_TYPE_EVENTFD) {
if (handle->eventfd.fd != PAL_IDX_POISON) {
ocall_close(handle->eventfd.fd);
handle->eventfd.fd = PAL_IDX_POISON;
Expand Down
2 changes: 1 addition & 1 deletion Pal/src/host/Linux-SGX/db_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,7 @@ int _DkEventCreate(PAL_HANDLE* handle_ptr, bool init_signaled, bool auto_clear)
return -PAL_ERROR_NOMEM;
}

SET_HANDLE_TYPE(handle, event);
init_handle_hdr(HANDLE_HDR(handle), PAL_TYPE_EVENT);
handle->event.signaled_untrusted = malloc_untrusted(sizeof(*handle->event.signaled_untrusted));
if (!handle->event.signaled_untrusted) {
free(handle);
Expand Down
18 changes: 9 additions & 9 deletions Pal/src/host/Linux-SGX/db_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 66,7 @@ static int file_open(PAL_HANDLE* handle, const char* type, const char* uri, int
return -PAL_ERROR_NOMEM;
}

SET_HANDLE_TYPE(hdl, file);
init_handle_hdr(HANDLE_HDR(hdl), PAL_TYPE_FILE);
HANDLE_HDR(hdl)->flags |= RFD(0) | WFD(0);

memcpy((char*)hdl HANDLE_SIZE(file), normpath, normpath_size);
Expand Down Expand Up @@ -625,15 625,15 @@ static int file_flush(PAL_HANDLE handle) {

static inline int file_stat_type(struct stat* stat) {
if (S_ISREG(stat->st_mode))
return pal_type_file;
return PAL_TYPE_FILE;
if (S_ISDIR(stat->st_mode))
return pal_type_dir;
return PAL_TYPE_DIR;
if (S_ISCHR(stat->st_mode))
return pal_type_dev;
return PAL_TYPE_DEV;
if (S_ISFIFO(stat->st_mode))
return pal_type_pipe;
return PAL_TYPE_PIPE;
if (S_ISSOCK(stat->st_mode))
return pal_type_dev;
return PAL_TYPE_DEV;

return 0;
}
Expand Down Expand Up @@ -720,7 720,7 @@ static int file_attrquery(const char* type, const char* uri, PAL_STREAM_ATTR* at

/* For protected files return the data size, not real FS size */
struct protected_file* pf = get_protected_file(path);
if (pf && attr->handle_type != pal_type_dir) {
if (pf && attr->handle_type != PAL_TYPE_DIR) {
/* protected files should be regular files */
if (S_ISFIFO(stat_buf.st_mode)) {
ret = -PAL_ERROR_DENIED;
Expand Down Expand Up @@ -757,7 757,7 @@ static int file_attrquerybyhdl(PAL_HANDLE handle, PAL_STREAM_ATTR* attr) {

file_attrcopy(attr, &stat_buf);

if (attr->handle_type != pal_type_dir) {
if (attr->handle_type != PAL_TYPE_DIR) {
/* For protected files return the data size, not real FS size */
struct protected_file* pf = find_protected_file_handle(handle);
if (pf) {
Expand Down Expand Up @@ -874,7 874,7 @@ static int dir_open(PAL_HANDLE* handle, const char* type, const char* uri, int a
ocall_close(fd);
return -PAL_ERROR_NOMEM;
}
SET_HANDLE_TYPE(hdl, dir);
init_handle_hdr(HANDLE_HDR(hdl), PAL_TYPE_DIR);
HANDLE_HDR(hdl)->flags |= RFD(0);
hdl->dir.fd = fd;
char* path = (void*)hdl HANDLE_SIZE(dir);
Expand Down
2 changes: 1 addition & 1 deletion Pal/src/host/Linux-SGX/db_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 733,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char*
log_error("Out of memory");
ocall_exit(1, true);
}
SET_HANDLE_TYPE(first_thread, thread);
init_handle_hdr(HANDLE_HDR(first_thread), PAL_TYPE_THREAD);
first_thread->thread.tcs = g_enclave_base GET_ENCLAVE_TLS(tcs_offset);
/* child threads are assigned TIDs 2,3,...; see pal_start_thread() */
first_thread->thread.tid = 1;
Expand Down
Loading

0 comments on commit 33a68bc

Please sign in to comment.