Prefix syscalls with _trusty_* and add stubs in libc.
This change makes it easier to modify the parameter and return types of
these functions. It also makes it easier to port an off-the-shelf libc
to Trusty.
trusty_syscalls.h is updated to reflect changes in stubgen.py - not just
changing the stub names, but also forward declaring structs and including
stdint.h.
Bug: 110159511
Change-Id: Ifb35f37ba720fed8bb9e3518f697cd11100126ad
diff --git a/include/user/trusty_syscalls.h b/include/user/trusty_syscalls.h
index 484b2bf..1994053 100644
--- a/include/user/trusty_syscalls.h
+++ b/include/user/trusty_syscalls.h
@@ -50,32 +50,40 @@
#ifndef ASSEMBLY
+#include <stdint.h>
+
__BEGIN_CDECLS
-long write (uint32_t fd, void *msg, uint32_t size);
-long brk (uint32_t brk);
-long exit_etc (int32_t status, uint32_t flags);
-long read (uint32_t fd, void *msg, uint32_t size);
-long ioctl (uint32_t fd, uint32_t req, void *buf);
-long nanosleep (uint32_t clock_id, uint32_t flags, uint64_t sleep_time);
-long gettime (uint32_t clock_id, uint32_t flags, int64_t *time);
-long mmap (void *uaddr, uint32_t size, uint32_t flags, uint32_t handle);
-long munmap (void *uaddr, uint32_t size);
-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);
-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);
+struct dma_pmem;
+struct ipc_msg;
+struct ipc_msg_info;
+struct uevent;
+struct uuid;
+
+long _trusty_write(uint32_t fd, void *msg, uint32_t size);
+long _trusty_brk(uint32_t brk);
+long _trusty_exit_etc(int32_t status, uint32_t flags);
+long _trusty_read(uint32_t fd, void *msg, uint32_t size);
+long _trusty_ioctl(uint32_t fd, uint32_t req, void *buf);
+long _trusty_nanosleep(uint32_t clock_id, uint32_t flags, uint64_t sleep_time);
+long _trusty_gettime(uint32_t clock_id, uint32_t flags, int64_t *time);
+long _trusty_mmap(void *uaddr, uint32_t size, uint32_t flags, uint32_t handle);
+long _trusty_munmap(void *uaddr, uint32_t size);
+long _trusty_prepare_dma(void *uaddr, uint32_t size, uint32_t flags, struct dma_pmem *pmem);
+long _trusty_finish_dma(void *uaddr, uint32_t size, uint32_t flags);
+long _trusty_port_create(const char *path, uint32_t num_recv_bufs, uint32_t recv_buf_size, uint32_t flags);
+long _trusty_connect(const char *path, uint32_t flags);
+long _trusty_accept(uint32_t handle_id, struct uuid *peer_uuid);
+long _trusty_close(uint32_t handle_id);
+long _trusty_set_cookie(uint32_t handle, void *cookie);
+long _trusty_handle_set_create(void);
+long _trusty_handle_set_ctrl(uint32_t handle, uint32_t cmd, struct uevent *evt);
+long _trusty_wait(uint32_t handle_id, struct uevent *event, uint32_t timeout_msecs);
+long _trusty_wait_any(struct uevent *event, uint32_t timeout_msecs);
+long _trusty_get_msg(uint32_t handle, struct ipc_msg_info *msg_info);
+long _trusty_read_msg(uint32_t handle, uint32_t msg_id, uint32_t offset, struct ipc_msg *msg);
+long _trusty_put_msg(uint32_t handle, uint32_t msg_id);
+long _trusty_send_msg(uint32_t handle, struct ipc_msg *msg);
__END_CDECLS
diff --git a/lib/libc-trusty/arch/arm/trusty_syscall.S b/lib/libc-trusty/arch/arm/trusty_syscall.S
index f4b2932..abc7410 100644
--- a/lib/libc-trusty/arch/arm/trusty_syscall.S
+++ b/lib/libc-trusty/arch/arm/trusty_syscall.S
@@ -26,146 +26,146 @@
#include <asm.h>
#include <trusty_syscalls.h>
-.section .text.write
-FUNCTION(write)
+.section .text._trusty_write
+FUNCTION(_trusty_write)
ldr r12, =__NR_write
swi #0
bx lr
-.section .text.brk
-FUNCTION(brk)
+.section .text._trusty_brk
+FUNCTION(_trusty_brk)
ldr r12, =__NR_brk
swi #0
bx lr
-.section .text.exit_etc
-FUNCTION(exit_etc)
+.section .text._trusty_exit_etc
+FUNCTION(_trusty_exit_etc)
ldr r12, =__NR_exit_etc
swi #0
bx lr
-.section .text.read
-FUNCTION(read)
+.section .text._trusty_read
+FUNCTION(_trusty_read)
ldr r12, =__NR_read
swi #0
bx lr
-.section .text.ioctl
-FUNCTION(ioctl)
+.section .text._trusty_ioctl
+FUNCTION(_trusty_ioctl)
ldr r12, =__NR_ioctl
swi #0
bx lr
-.section .text.nanosleep
-FUNCTION(nanosleep)
+.section .text._trusty_nanosleep
+FUNCTION(_trusty_nanosleep)
ldr r12, =__NR_nanosleep
swi #0
bx lr
-.section .text.gettime
-FUNCTION(gettime)
+.section .text._trusty_gettime
+FUNCTION(_trusty_gettime)
ldr r12, =__NR_gettime
swi #0
bx lr
-.section .text.mmap
-FUNCTION(mmap)
+.section .text._trusty_mmap
+FUNCTION(_trusty_mmap)
ldr r12, =__NR_mmap
swi #0
bx lr
-.section .text.munmap
-FUNCTION(munmap)
+.section .text._trusty_munmap
+FUNCTION(_trusty_munmap)
ldr r12, =__NR_munmap
swi #0
bx lr
-.section .text.prepare_dma
-FUNCTION(prepare_dma)
+.section .text._trusty_prepare_dma
+FUNCTION(_trusty_prepare_dma)
ldr r12, =__NR_prepare_dma
swi #0
bx lr
-.section .text.finish_dma
-FUNCTION(finish_dma)
+.section .text._trusty_finish_dma
+FUNCTION(_trusty_finish_dma)
ldr r12, =__NR_finish_dma
swi #0
bx lr
-.section .text.port_create
-FUNCTION(port_create)
+.section .text._trusty_port_create
+FUNCTION(_trusty_port_create)
ldr r12, =__NR_port_create
swi #0
bx lr
-.section .text.connect
-FUNCTION(connect)
+.section .text._trusty_connect
+FUNCTION(_trusty_connect)
ldr r12, =__NR_connect
swi #0
bx lr
-.section .text.accept
-FUNCTION(accept)
+.section .text._trusty_accept
+FUNCTION(_trusty_accept)
ldr r12, =__NR_accept
swi #0
bx lr
-.section .text.close
-FUNCTION(close)
+.section .text._trusty_close
+FUNCTION(_trusty_close)
ldr r12, =__NR_close
swi #0
bx lr
-.section .text.set_cookie
-FUNCTION(set_cookie)
+.section .text._trusty_set_cookie
+FUNCTION(_trusty_set_cookie)
ldr r12, =__NR_set_cookie
swi #0
bx lr
-.section .text.handle_set_create
-FUNCTION(handle_set_create)
+.section .text._trusty_handle_set_create
+FUNCTION(_trusty_handle_set_create)
ldr r12, =__NR_handle_set_create
swi #0
bx lr
-.section .text.handle_set_ctrl
-FUNCTION(handle_set_ctrl)
+.section .text._trusty_handle_set_ctrl
+FUNCTION(_trusty_handle_set_ctrl)
ldr r12, =__NR_handle_set_ctrl
swi #0
bx lr
-.section .text.wait
-FUNCTION(wait)
+.section .text._trusty_wait
+FUNCTION(_trusty_wait)
ldr r12, =__NR_wait
swi #0
bx lr
-.section .text.wait_any
-FUNCTION(wait_any)
+.section .text._trusty_wait_any
+FUNCTION(_trusty_wait_any)
ldr r12, =__NR_wait_any
swi #0
bx lr
-.section .text.get_msg
-FUNCTION(get_msg)
+.section .text._trusty_get_msg
+FUNCTION(_trusty_get_msg)
ldr r12, =__NR_get_msg
swi #0
bx lr
-.section .text.read_msg
-FUNCTION(read_msg)
+.section .text._trusty_read_msg
+FUNCTION(_trusty_read_msg)
ldr r12, =__NR_read_msg
swi #0
bx lr
-.section .text.put_msg
-FUNCTION(put_msg)
+.section .text._trusty_put_msg
+FUNCTION(_trusty_put_msg)
ldr r12, =__NR_put_msg
swi #0
bx lr
-.section .text.send_msg
-FUNCTION(send_msg)
+.section .text._trusty_send_msg
+FUNCTION(_trusty_send_msg)
ldr r12, =__NR_send_msg
swi #0
bx lr
diff --git a/lib/libc-trusty/arch/x86/64/trusty_syscall.S b/lib/libc-trusty/arch/x86/64/trusty_syscall.S
index 3ffec57..bcf3e11 100644
--- a/lib/libc-trusty/arch/x86/64/trusty_syscall.S
+++ b/lib/libc-trusty/arch/x86/64/trusty_syscall.S
@@ -26,7 +26,7 @@
#include <asm.h>
#include <trusty_syscalls.h>
-FUNCTION(write)
+FUNCTION(_trusty_write)
pushfq
pushq %rbp
pushq %rbx
@@ -42,7 +42,7 @@
popfq
ret
-FUNCTION(brk)
+FUNCTION(_trusty_brk)
pushfq
pushq %rbp
pushq %rbx
@@ -58,7 +58,7 @@
popfq
ret
-FUNCTION(exit_etc)
+FUNCTION(_trusty_exit_etc)
pushfq
pushq %rbp
pushq %rbx
@@ -74,7 +74,7 @@
popfq
ret
-FUNCTION(read)
+FUNCTION(_trusty_read)
pushfq
pushq %rbp
pushq %rbx
@@ -90,7 +90,7 @@
popfq
ret
-FUNCTION(ioctl)
+FUNCTION(_trusty_ioctl)
pushfq
pushq %rbp
pushq %rbx
@@ -106,7 +106,7 @@
popfq
ret
-FUNCTION(nanosleep)
+FUNCTION(_trusty_nanosleep)
pushfq
pushq %rbp
pushq %rbx
@@ -122,7 +122,7 @@
popfq
ret
-FUNCTION(gettime)
+FUNCTION(_trusty_gettime)
pushfq
pushq %rbp
pushq %rbx
@@ -138,7 +138,7 @@
popfq
ret
-FUNCTION(mmap)
+FUNCTION(_trusty_mmap)
pushfq
pushq %rbp
pushq %rbx
@@ -154,7 +154,7 @@
popfq
ret
-FUNCTION(munmap)
+FUNCTION(_trusty_munmap)
pushfq
pushq %rbp
pushq %rbx
@@ -170,7 +170,7 @@
popfq
ret
-FUNCTION(prepare_dma)
+FUNCTION(_trusty_prepare_dma)
pushfq
pushq %rbp
pushq %rbx
@@ -186,7 +186,7 @@
popfq
ret
-FUNCTION(finish_dma)
+FUNCTION(_trusty_finish_dma)
pushfq
pushq %rbp
pushq %rbx
@@ -202,7 +202,7 @@
popfq
ret
-FUNCTION(port_create)
+FUNCTION(_trusty_port_create)
pushfq
pushq %rbp
pushq %rbx
@@ -218,7 +218,7 @@
popfq
ret
-FUNCTION(connect)
+FUNCTION(_trusty_connect)
pushfq
pushq %rbp
pushq %rbx
@@ -234,7 +234,7 @@
popfq
ret
-FUNCTION(accept)
+FUNCTION(_trusty_accept)
pushfq
pushq %rbp
pushq %rbx
@@ -250,7 +250,7 @@
popfq
ret
-FUNCTION(close)
+FUNCTION(_trusty_close)
pushfq
pushq %rbp
pushq %rbx
@@ -266,7 +266,7 @@
popfq
ret
-FUNCTION(set_cookie)
+FUNCTION(_trusty_set_cookie)
pushfq
pushq %rbp
pushq %rbx
@@ -282,7 +282,7 @@
popfq
ret
-FUNCTION(handle_set_create)
+FUNCTION(_trusty_handle_set_create)
pushfq
pushq %rbp
pushq %rbx
@@ -298,7 +298,7 @@
popfq
ret
-FUNCTION(handle_set_ctrl)
+FUNCTION(_trusty_handle_set_ctrl)
pushfq
pushq %rbp
pushq %rbx
@@ -314,7 +314,7 @@
popfq
ret
-FUNCTION(wait)
+FUNCTION(_trusty_wait)
pushfq
pushq %rbp
pushq %rbx
@@ -330,7 +330,7 @@
popfq
ret
-FUNCTION(wait_any)
+FUNCTION(_trusty_wait_any)
pushfq
pushq %rbp
pushq %rbx
@@ -346,7 +346,7 @@
popfq
ret
-FUNCTION(get_msg)
+FUNCTION(_trusty_get_msg)
pushfq
pushq %rbp
pushq %rbx
@@ -362,7 +362,7 @@
popfq
ret
-FUNCTION(read_msg)
+FUNCTION(_trusty_read_msg)
pushfq
pushq %rbp
pushq %rbx
@@ -378,7 +378,7 @@
popfq
ret
-FUNCTION(put_msg)
+FUNCTION(_trusty_put_msg)
pushfq
pushq %rbp
pushq %rbx
@@ -394,7 +394,7 @@
popfq
ret
-FUNCTION(send_msg)
+FUNCTION(_trusty_send_msg)
pushfq
pushq %rbp
pushq %rbx
diff --git a/lib/libc-trusty/exit.c b/lib/libc-trusty/exit.c
index 39b3d5d..e6bed2d 100644
--- a/lib/libc-trusty/exit.c
+++ b/lib/libc-trusty/exit.c
@@ -16,15 +16,16 @@
#include <lk/compiler.h>
#include <stdlib.h>
+#include <trusty_syscalls.h>
#include "atexit.h"
/* HACK: needed temporarily until the syscalls file gets the
* __NO_RETURN annotation */
-__NO_RETURN long exit_etc(int32_t status, uint32_t flags);
+__NO_RETURN long _trusty_exit_etc(int32_t status, uint32_t flags);
__NO_RETURN void exit(int status)
{
- __cxa_finalize();
- exit_etc(status, 0);
+ __cxa_finalize();
+ _trusty_exit_etc(status, 0);
}
diff --git a/lib/libc-trusty/include/sys/mman.h b/lib/libc-trusty/include/sys/mman.h
index fa18398..4876c2c 100644
--- a/lib/libc-trusty/include/sys/mman.h
+++ b/lib/libc-trusty/include/sys/mman.h
@@ -17,6 +17,7 @@
#pragma once
#include <lk/compiler.h>
+#include <stdint.h>
#include <uapi/mm.h>
__BEGIN_CDECLS
diff --git a/lib/libc-trusty/ipc.c b/lib/libc-trusty/ipc.c
new file mode 100644
index 0000000..02b3e19
--- /dev/null
+++ b/lib/libc-trusty/ipc.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <trusty_ipc.h>
+
+#include <trusty_syscalls.h>
+
+long 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)
+{
+ return _trusty_connect(path, flags);
+}
+
+long accept(uint32_t handle_id, struct uuid *peer_uuid)
+{
+ return _trusty_accept(handle_id, peer_uuid);
+}
+
+long close(uint32_t handle_id)
+{
+ return _trusty_close(handle_id);
+}
+
+long set_cookie(uint32_t handle, void *cookie)
+{
+ return _trusty_set_cookie(handle, cookie);
+}
+
+long handle_set_create(void)
+{
+ return _trusty_handle_set_create();
+}
+
+long handle_set_ctrl(uint32_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);
+}
+
+long 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)
+{
+ return _trusty_get_msg(handle, msg_info);
+}
+
+long read_msg(uint32_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)
+{
+ return _trusty_put_msg(handle, msg_id);
+}
+
+long send_msg(uint32_t handle, struct ipc_msg *msg)
+{
+ return _trusty_send_msg(handle, msg);
+}
diff --git a/lib/libc-trusty/malloc.c b/lib/libc-trusty/malloc.c
index 4d19fcd..bad2e53 100644
--- a/lib/libc-trusty/malloc.c
+++ b/lib/libc-trusty/malloc.c
@@ -35,9 +35,15 @@
#define EINVAL ERR_INVALID_ARGS
#include <stdlib.h>
+#include <trusty_syscalls.h>
#include <uapi/err.h>
#include <unistd.h>
+long brk(uint32_t brk)
+{
+ return _trusty_brk(brk);
+}
+
static char *__libc_brk;
#define SBRK_ALIGN 32
diff --git a/lib/libc-trusty/mman.c b/lib/libc-trusty/mman.c
new file mode 100644
index 0000000..81bdfee
--- /dev/null
+++ b/lib/libc-trusty/mman.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/mman.h>
+
+#include <stdint.h>
+#include <trusty_syscalls.h>
+
+long mmap(void *uaddr, uint32_t size, uint32_t flags, uint32_t handle)
+{
+ return _trusty_mmap(uaddr, size, flags, handle);
+}
+
+long munmap(void *uaddr, uint32_t size)
+{
+ return _trusty_munmap(uaddr, size);
+}
+
+long 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)
+{
+ return _trusty_finish_dma(uaddr, size, flags);
+}
diff --git a/lib/libc-trusty/rules.mk b/lib/libc-trusty/rules.mk
index 0c54925..b53b93d 100644
--- a/lib/libc-trusty/rules.mk
+++ b/lib/libc-trusty/rules.mk
@@ -12,8 +12,11 @@
$(LOCAL_DIR)/assert.c \
$(LOCAL_DIR)/atexit.c \
$(LOCAL_DIR)/exit.c \
+ $(LOCAL_DIR)/ipc.c \
$(LOCAL_DIR)/malloc.c \
+ $(LOCAL_DIR)/mman.c \
$(LOCAL_DIR)/stdio.c \
+ $(LOCAL_DIR)/time.c \
$(LOCAL_DIR)/libc_init.c \
$(LOCAL_DIR)/libc_fatal.c \
diff --git a/lib/libc-trusty/stdio.c b/lib/libc-trusty/stdio.c
index 2f4a7d3..37a7577 100644
--- a/lib/libc-trusty/stdio.c
+++ b/lib/libc-trusty/stdio.c
@@ -17,6 +17,7 @@
#include <printf.h>
#include <stdio.h>
#include <string.h>
+#include <trusty_syscalls.h>
#include <uapi/err.h>
#include <unistd.h>
@@ -39,7 +40,7 @@
buffer->data[buffer->pos++] = c;
if (buffer->pos == sizeof(buffer->data) || c == '\n') {
- result = write(fd, buffer->data, buffer->pos);
+ result = _trusty_write(fd, buffer->data, buffer->pos);
buffer->pos = 0;
}
return result;
diff --git a/lib/libc-trusty/time.c b/lib/libc-trusty/time.c
new file mode 100644
index 0000000..1eab5ea
--- /dev/null
+++ b/lib/libc-trusty/time.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <time.h>
+
+#include <trusty_syscalls.h>
+
+long nanosleep(uint32_t clock_id, uint32_t flags, uint64_t sleep_time)
+{
+ return _trusty_nanosleep(clock_id, flags, sleep_time);
+}
+
+long gettime(uint32_t clock_id, uint32_t flags, int64_t *time)
+{
+ return _trusty_gettime(clock_id, flags, time);
+}