Clean up type signatures of syscalls.
Instead of returning long values, prefer int.
If a function returns a byte count or an error, return ssize_t.
Make handle_t signed so that it can be used as a return value with
possible error.
If an argument is a handle, make it a handle_t rather than uint32_t.
This makes the signature of close(...) compatible with POSIX.
Bug: 138738352
Change-Id: Iac2ec408c70e8fd37f857d834693e5aa3feb2c33
diff --git a/include/user/trusty_ipc.h b/include/user/trusty_ipc.h
index a40d0eb..4959522 100644
--- a/include/user/trusty_ipc.h
+++ b/include/user/trusty_ipc.h
@@ -35,12 +35,12 @@
* handle_t is an opaque 32 bit value that is used to reference an
* object (like ipc port or channel) in kernel space
*/
-typedef uint32_t handle_t;
+typedef int32_t handle_t;
/*
* Invalid IPC handle
*/
-#define INVALID_IPC_HANDLE (0xFFFFFFFFu)
+#define INVALID_IPC_HANDLE ((handle_t)-1)
/*
* Specify this timeout value to wait forever.
@@ -110,7 +110,7 @@
* about event.
*/
typedef struct uevent {
- uint32_t handle; /* handle this event is related too */
+ handle_t handle; /* handle this event is related too */
uint32_t event; /* combination of IPC_HANDLE_POLL_XXX flags */
void* cookie; /* cookie aasociated with handle */
} uevent_t;
@@ -118,24 +118,24 @@
#define UEVENT_INITIAL_VALUE(event) \
{ 0, 0, 0 }
-long port_create(const char* path,
- uint32_t num_recv_bufs,
- uint32_t recv_buf_size,
- uint32_t flags);
-long connect(const char* path, uint32_t flags);
-long accept(uint32_t handle_id, uuid_t* peer_uuid);
-long close(uint32_t handle_id);
-long set_cookie(uint32_t handle, void* cookie);
-long handle_set_create(void);
-long handle_set_ctrl(uint32_t handle, uint32_t cmd, struct uevent* evt);
-long wait(uint32_t handle_id, uevent_t* event, uint32_t timeout_msecs);
-long wait_any(uevent_t* event, uint32_t timeout_msecs);
-long get_msg(uint32_t handle, ipc_msg_info_t* msg_info);
-long read_msg(uint32_t handle,
- uint32_t msg_id,
- uint32_t offset,
- ipc_msg_t* msg);
-long put_msg(uint32_t handle, uint32_t msg_id);
-long send_msg(uint32_t handle, ipc_msg_t* msg);
+handle_t port_create(const char* path,
+ uint32_t num_recv_bufs,
+ uint32_t recv_buf_size,
+ uint32_t flags);
+handle_t connect(const char* path, uint32_t flags);
+handle_t accept(handle_t handle, uuid_t* peer_uuid);
+int close(handle_t handle);
+int set_cookie(handle_t handle, void* cookie);
+handle_t handle_set_create(void);
+int handle_set_ctrl(handle_t handle, uint32_t cmd, struct uevent* evt);
+int wait(handle_t handle, uevent_t* event, uint32_t timeout_msecs);
+int wait_any(uevent_t* event, uint32_t timeout_msecs);
+int get_msg(handle_t handle, ipc_msg_info_t* msg_info);
+ssize_t read_msg(handle_t handle,
+ uint32_t msg_id,
+ uint32_t offset,
+ ipc_msg_t* msg);
+int put_msg(handle_t handle, uint32_t msg_id);
+ssize_t send_msg(handle_t handle, ipc_msg_t* msg);
__END_CDECLS
diff --git a/lib/libc-trusty/include/sys/mman.h b/lib/libc-trusty/include/sys/mman.h
index 2627631..67c094a 100644
--- a/lib/libc-trusty/include/sys/mman.h
+++ b/lib/libc-trusty/include/sys/mman.h
@@ -28,11 +28,11 @@
#endif
/* Trusty specific. */
-long prepare_dma(void* uaddr,
- uint32_t size,
- uint32_t flags,
- struct dma_pmem* pmem);
-long finish_dma(void* uaddr, uint32_t size, uint32_t flags);
+int prepare_dma(void* uaddr,
+ uint32_t size,
+ uint32_t flags,
+ struct dma_pmem* pmem);
+int finish_dma(void* uaddr, uint32_t size, uint32_t flags);
#ifdef __cplusplus
}
diff --git a/lib/libc-trusty/ipc.c b/lib/libc-trusty/ipc.c
index 8a2f651..649086f 100644
--- a/lib/libc-trusty/ipc.c
+++ b/lib/libc-trusty/ipc.c
@@ -18,60 +18,60 @@
#include <trusty_syscalls.h>
-long port_create(const char* path,
- uint32_t num_recv_bufs,
- uint32_t recv_buf_size,
- uint32_t flags) {
+handle_t port_create(const char* path,
+ uint32_t num_recv_bufs,
+ uint32_t recv_buf_size,
+ uint32_t flags) {
return _trusty_port_create(path, num_recv_bufs, recv_buf_size, flags);
}
-long connect(const char* path, uint32_t flags) {
+handle_t connect(const char* path, uint32_t flags) {
return _trusty_connect(path, flags);
}
-long accept(uint32_t handle_id, struct uuid* peer_uuid) {
- return _trusty_accept(handle_id, peer_uuid);
+handle_t accept(handle_t handle, struct uuid* peer_uuid) {
+ return _trusty_accept(handle, peer_uuid);
}
-long close(uint32_t handle_id) {
- return _trusty_close(handle_id);
+int close(handle_t handle) {
+ return _trusty_close(handle);
}
-long set_cookie(uint32_t handle, void* cookie) {
+int set_cookie(handle_t handle, void* cookie) {
return _trusty_set_cookie(handle, cookie);
}
-long handle_set_create(void) {
+handle_t handle_set_create(void) {
return _trusty_handle_set_create();
}
-long handle_set_ctrl(uint32_t handle, uint32_t cmd, struct uevent* evt) {
+int handle_set_ctrl(handle_t handle, uint32_t cmd, struct uevent* evt) {
return _trusty_handle_set_ctrl(handle, cmd, evt);
}
-long wait(uint32_t handle_id, struct uevent* event, uint32_t timeout_msecs) {
- return _trusty_wait(handle_id, event, timeout_msecs);
+int wait(handle_t handle, struct uevent* event, uint32_t timeout_msecs) {
+ return _trusty_wait(handle, event, timeout_msecs);
}
-long wait_any(struct uevent* event, uint32_t timeout_msecs) {
+int wait_any(struct uevent* event, uint32_t timeout_msecs) {
return _trusty_wait_any(event, timeout_msecs);
}
-long get_msg(uint32_t handle, struct ipc_msg_info* msg_info) {
+int get_msg(handle_t handle, struct ipc_msg_info* msg_info) {
return _trusty_get_msg(handle, msg_info);
}
-long read_msg(uint32_t handle,
- uint32_t msg_id,
- uint32_t offset,
- struct ipc_msg* msg) {
+ssize_t read_msg(handle_t handle,
+ uint32_t msg_id,
+ uint32_t offset,
+ struct ipc_msg* msg) {
return _trusty_read_msg(handle, msg_id, offset, msg);
}
-long put_msg(uint32_t handle, uint32_t msg_id) {
+int put_msg(handle_t handle, uint32_t msg_id) {
return _trusty_put_msg(handle, msg_id);
}
-long send_msg(uint32_t handle, struct ipc_msg* msg) {
+ssize_t send_msg(handle_t handle, struct ipc_msg* msg) {
return _trusty_send_msg(handle, msg);
}
diff --git a/lib/libc-trusty/mman.c b/lib/libc-trusty/mman.c
index f71f6ad..eef0b54 100644
--- a/lib/libc-trusty/mman.c
+++ b/lib/libc-trusty/mman.c
@@ -40,8 +40,7 @@
return MAP_FAILED;
}
- result =
- (void*)_trusty_mmap(uaddr, size, (uint32_t)flags, (uint32_t)handle);
+ result = (void*)_trusty_mmap(uaddr, size, (uint32_t)flags, (int32_t)handle);
if (IS_ERR(result)) {
return MAP_FAILED;
}
@@ -52,13 +51,13 @@
return _trusty_munmap(uaddr, size);
}
-long prepare_dma(void* uaddr,
- uint32_t size,
- uint32_t flags,
- struct dma_pmem* pmem) {
+int prepare_dma(void* uaddr,
+ uint32_t size,
+ uint32_t flags,
+ struct dma_pmem* pmem) {
return _trusty_prepare_dma(uaddr, size, flags, pmem);
}
-long finish_dma(void* uaddr, uint32_t size, uint32_t flags) {
+int finish_dma(void* uaddr, uint32_t size, uint32_t flags) {
return _trusty_finish_dma(uaddr, size, flags);
}