diff --git a/Pal/src/db_streams.c b/Pal/src/db_streams.c index 71e1bcdd..df928cc2 100644 --- a/Pal/src/db_streams.c +++ b/Pal/src/db_streams.c @@ -618,7 +618,7 @@ void DkStreamUnmap (PAL_PTR addr, PAL_NUM size) /* _DkStreamSetLength for internal use. This function truncate the stream to certain length. This call might not be support for certain streams */ -uint64_t _DkStreamSetLength (PAL_HANDLE handle, uint64_t length) +int64_t _DkStreamSetLength (PAL_HANDLE handle, uint64_t length) { if (UNKNOWN_HANDLE(handle)) return -PAL_ERROR_BADHANDLE; @@ -643,7 +643,7 @@ DkStreamSetLength (PAL_HANDLE handle, PAL_NUM length) LEAVE_PAL_CALL_RETURN(0); } - uint64_t ret = _DkStreamSetLength(handle, length); + int64_t ret = _DkStreamSetLength(handle, length); if (ret < 0) { _DkRaiseFailure(-ret); diff --git a/Pal/src/host/Linux-SGX/db_events.c b/Pal/src/host/Linux-SGX/db_events.c index 4c70d4e3..2754f6fa 100644 --- a/Pal/src/host/Linux-SGX/db_events.c +++ b/Pal/src/host/Linux-SGX/db_events.c @@ -81,7 +81,7 @@ int _DkEventSet (PAL_HANDLE event, int wakeup) return ret; } -int _DkEventWaitTimeout (PAL_HANDLE event, int timeout) +int _DkEventWaitTimeout (PAL_HANDLE event, uint64_t timeout) { int ret = 0; diff --git a/Pal/src/host/Linux-SGX/db_files.c b/Pal/src/host/Linux-SGX/db_files.c index fa61e66f..ab226c1f 100644 --- a/Pal/src/host/Linux-SGX/db_files.c +++ b/Pal/src/host/Linux-SGX/db_files.c @@ -243,13 +243,13 @@ static int file_map (PAL_HANDLE handle, void ** addr, int prot, } /* 'setlength' operation for file stream. */ -static uint64_t file_setlength (PAL_HANDLE handle, uint64_t length) +static int64_t file_setlength (PAL_HANDLE handle, uint64_t length) { int ret = ocall_ftruncate(handle->file.fd, length); if (ret < 0) return ret; handle->file.total = length; - return length; + return (int64_t) length; } /* 'flush' operation for file stream. */ @@ -330,7 +330,7 @@ static int file_attrsetbyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr) { int fd = HANDLE_HDR(handle)->fds[0]; - int ret = ocall_fchmod(fd, attr->share_flags); + int ret = ocall_fchmod(fd, attr->share_flags | 0600); if (ret < 0) return ret; diff --git a/Pal/src/host/Linux-SGX/db_object.c b/Pal/src/host/Linux-SGX/db_object.c index 56f74195..92dfad34 100644 --- a/Pal/src/host/Linux-SGX/db_object.c +++ b/Pal/src/host/Linux-SGX/db_object.c @@ -42,7 +42,7 @@ /* internally to wait for one object. Also used as a shortcut to wait on events and semaphores */ -static int _DkObjectWaitOne (PAL_HANDLE handle, int timeout) +static int _DkObjectWaitOne (PAL_HANDLE handle, uint64_t timeout) { /* only for all these handle which has a file descriptor, or a eventfd. events and semaphores will skip this part */ @@ -74,7 +74,7 @@ static int _DkObjectWaitOne (PAL_HANDLE handle, int timeout) if (!nfds) return -PAL_ERROR_TRYAGAIN; - unsigned long waittime = timeout; + uint64_t waittime = timeout; int ret = ocall_poll(fds, nfds, timeout >= 0 ? &waittime : NULL); if (ret < 0) return ret; @@ -104,7 +104,7 @@ static int _DkObjectWaitOne (PAL_HANDLE handle, int timeout) /* _DkObjectsWaitAny for internal use. The function wait for any of the handle in the handle array. timeout can be set for the wait. */ -int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, int timeout, +int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, uint64_t timeout, PAL_HANDLE * polled) { if (count <= 0) @@ -180,7 +180,7 @@ int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, int timeout, if (!nfds) return -PAL_ERROR_TRYAGAIN; - unsigned long waittime = timeout; + uint64_t waittime = timeout; ret = ocall_poll(fds, nfds, timeout >= 0 ? &waittime : NULL); if (ret < 0) return ret; diff --git a/Pal/src/host/Linux-SGX/db_semaphore.c b/Pal/src/host/Linux-SGX/db_semaphore.c index 85b46e43..d8ea59aa 100644 --- a/Pal/src/host/Linux-SGX/db_semaphore.c +++ b/Pal/src/host/Linux-SGX/db_semaphore.c @@ -146,7 +146,7 @@ int _DkSemaphoreAcquire (PAL_HANDLE sem, int count) return ret; } -int _DkSemaphoreAcquireTimeout (PAL_HANDLE sem, int count, int timeout) +int _DkSemaphoreAcquireTimeout (PAL_HANDLE sem, int count, uint64_t timeout) { /* Pass it up to the no-timeout version if no timeout requested */ if (timeout == -1) diff --git a/Pal/src/host/Linux-SGX/enclave_ocalls.c b/Pal/src/host/Linux-SGX/enclave_ocalls.c index e24c90bc..6d2a4708 100644 --- a/Pal/src/host/Linux-SGX/enclave_ocalls.c +++ b/Pal/src/host/Linux-SGX/enclave_ocalls.c @@ -425,7 +425,7 @@ int ocall_create_process (const char * uri, } int ocall_futex (int * futex, int op, int val, - const unsigned long * timeout) + const uint64_t * timeout) { int retval = 0; ms_ocall_futex_t * ms; @@ -439,7 +439,7 @@ int ocall_futex (int * futex, int op, int val, ms->ms_futex = futex; ms->ms_op = op; ms->ms_val = val; - ms->ms_timeout = timeout ? *timeout : (unsigned long) -1; + ms->ms_timeout = timeout ? *timeout : OCALL_NO_TIMEOUT; retval = SGX_OCALL(OCALL_FUTEX, ms); OCALL_EXIT(); @@ -718,7 +718,7 @@ int ocall_sleep (unsigned long * microsec) return retval; } -int ocall_poll (struct pollfd * fds, int nfds, unsigned long * timeout) +int ocall_poll (struct pollfd * fds, int nfds, uint64_t * timeout) { int retval = 0; ms_ocall_poll_t * ms; @@ -726,7 +726,7 @@ int ocall_poll (struct pollfd * fds, int nfds, unsigned long * timeout) ms->ms_fds = COPY_TO_USER(fds, sizeof(struct pollfd) * nfds); ms->ms_nfds = nfds; - ms->ms_timeout = timeout ? *timeout : (unsigned long) -1; + ms->ms_timeout = timeout ? *timeout : OCALL_NO_TIMEOUT; retval = SGX_OCALL(OCALL_POLL, ms); if (retval == -EINTR && timeout) diff --git a/Pal/src/host/Linux-SGX/enclave_ocalls.h b/Pal/src/host/Linux-SGX/enclave_ocalls.h index 7baa7f07..64df71e9 100644 --- a/Pal/src/host/Linux-SGX/enclave_ocalls.h +++ b/Pal/src/host/Linux-SGX/enclave_ocalls.h @@ -88,7 +88,7 @@ int ocall_create_process (const char * uri, int procfds[3], unsigned int * pid); -int ocall_futex (int * uaddr, int op, int val, const unsigned long * timeout); +int ocall_futex (int * uaddr, int op, int val, const uint64_t * timeout); int ocall_gettime (unsigned long * microsec); @@ -96,7 +96,7 @@ int ocall_sleep (unsigned long * microsec); int ocall_socketpair (int domain, int type, int protocol, int sockfds[2]); -int ocall_poll (struct pollfd * fds, int nfds, unsigned long * microsec); +int ocall_poll (struct pollfd * fds, int nfds, uint64_t * timeout); int ocall_rename (const char * oldpath, const char * newpath); diff --git a/Pal/src/host/Linux-SGX/ocall_types.h b/Pal/src/host/Linux-SGX/ocall_types.h index 40d85a0b..150b3f35 100644 --- a/Pal/src/host/Linux-SGX/ocall_types.h +++ b/Pal/src/host/Linux-SGX/ocall_types.h @@ -48,6 +48,8 @@ enum { OCALL_NR, }; +#define OCALL_NO_TIMEOUT ((uint64_t) -1) + typedef struct { const char * ms_str; int ms_length; @@ -154,7 +156,7 @@ typedef struct { typedef struct { int * ms_futex; int ms_op, ms_val; - unsigned long ms_timeout; + uint64_t ms_timeout; } ms_ocall_futex_t; typedef struct { @@ -241,7 +243,7 @@ typedef struct { typedef struct { struct pollfd * ms_fds; int ms_nfds; - unsigned long ms_timeout; + uint64_t ms_timeout; } ms_ocall_poll_t; typedef struct { diff --git a/Pal/src/host/Linux-SGX/sgx_enclave.c b/Pal/src/host/Linux-SGX/sgx_enclave.c index 1e6c6c58..859d8629 100644 --- a/Pal/src/host/Linux-SGX/sgx_enclave.c +++ b/Pal/src/host/Linux-SGX/sgx_enclave.c @@ -240,7 +240,7 @@ static int sgx_ocall_futex(void * pms) int ret; ODEBUG(OCALL_FUTEX, ms); struct timespec * ts = NULL; - if (ms->ms_timeout != (unsigned long) -1) { + if (ms->ms_timeout != OCALL_NO_TIMEOUT) { ts = __alloca(sizeof(struct timespec)); ts->tv_sec = ms->ms_timeout / 1000000; ts->tv_nsec = (ms->ms_timeout - ts->tv_sec * 1000000) * 1000; @@ -610,7 +610,7 @@ static int sgx_ocall_poll(void * pms) int ret; ODEBUG(OCALL_POLL, ms); struct timespec * ts = NULL; - if (ms->ms_timeout != (unsigned long) -1) { + if (ms->ms_timeout != OCALL_NO_TIMEOUT) { ts = __alloca(sizeof(struct timespec)); ts->tv_sec = ms->ms_timeout / 1000000; ts->tv_nsec = (ms->ms_timeout - ts->tv_sec * 1000000) * 1000; diff --git a/Pal/src/host/Linux/db_files.c b/Pal/src/host/Linux/db_files.c index cbe00fbc..0b2304c4 100644 --- a/Pal/src/host/Linux/db_files.c +++ b/Pal/src/host/Linux/db_files.c @@ -168,7 +168,7 @@ static int file_map (PAL_HANDLE handle, void ** addr, int prot, } /* 'setlength' operation for file stream. */ -static uint64_t file_setlength (PAL_HANDLE handle, uint64_t length) +static int64_t file_setlength (PAL_HANDLE handle, uint64_t length) { int ret = INLINE_SYSCALL(ftruncate, 2, handle->file.fd, length); @@ -176,7 +176,7 @@ static uint64_t file_setlength (PAL_HANDLE handle, uint64_t length) return (ERRNO(ret) == EINVAL || ERRNO(ret) == EBADF) ? -PAL_ERROR_BADHANDLE : -PAL_ERROR_DENIED; - return length; + return (int64_t) length; } /* 'flush' operation for file stream. */ @@ -258,7 +258,7 @@ static int file_attrsetbyhdl (PAL_HANDLE handle, { int fd = HANDLE_HDR(handle)->fds[0], ret; - ret = INLINE_SYSCALL(fchmod, 2, fd, attr->share_flags); + ret = INLINE_SYSCALL(fchmod, 2, fd, attr->share_flags | 0600); if (IS_ERR(ret)) return unix_to_pal_error(ERRNO(ret)); diff --git a/Pal/src/pal_internal.h b/Pal/src/pal_internal.h index 9578626c..4d6d7e0a 100644 --- a/Pal/src/pal_internal.h +++ b/Pal/src/pal_internal.h @@ -81,7 +81,7 @@ struct handle_ops { /* 'setlength' is used by DkStreamFlush. It truncate the stream to certain size. */ - uint64_t (*setlength) (PAL_HANDLE handle, uint64_t length); + int64_t (*setlength) (PAL_HANDLE handle, uint64_t length); /* 'flush' is used by DkStreamFlush. It syncs the stream to the device */ int (*flush) (PAL_HANDLE handle); @@ -303,7 +303,7 @@ int _DkStreamAttributesQuerybyHandle (PAL_HANDLE hdl, PAL_STREAM_ATTR * attr); int _DkStreamMap (PAL_HANDLE handle, void ** addr, int prot, uint64_t offset, uint64_t size); int _DkStreamUnmap (void * addr, uint64_t size); -uint64_t _DkStreamSetLength (PAL_HANDLE handle, uint64_t length); +int64_t _DkStreamSetLength (PAL_HANDLE handle, uint64_t length); int _DkStreamFlush (PAL_HANDLE handle); int _DkStreamGetName (PAL_HANDLE handle, char * buf, int size); const char * _DkStreamRealpath (PAL_HANDLE hdl);