diff --git a/photon/libc/sys/magenta/heap.c b/photon/libc/sys/magenta/heap.c index 2b91a29..7c421d5 100644 --- a/photon/libc/sys/magenta/heap.c +++ b/photon/libc/sys/magenta/heap.c @@ -1,9 +1,9 @@ #include #include #include -#include #include #include +#include #include #define ROUND_UP(x, b) x += (b) - ((x) % (b)) @@ -22,7 +22,7 @@ void __crt_heap_init(size_t heap_sz) &heap_vmo); mx_vaddr_t heap = 0; - mx_vmar_map(m_get_handle(M_HND_VMAR_ROOT), + mx_vmar_map(mx_get_startup_handle(MX_B_VMAR_ROOT), MX_VM_PERM_READ | MX_VM_PERM_WRITE, 0, heap_vmo, 0, heap_sz, &heap); @@ -47,10 +47,10 @@ void *__crt_heap_extend(size_t sz) mx_vmo_set_size(heap_vmo, heap_sz + sz); mx_vaddr_t vmar_base, alloc_base; - mx_vmar_bounds(m_get_handle(M_HND_VMAR_ROOT), &vmar_base, NULL); + mx_vmar_bounds(mx_get_startup_handle(MX_B_VMAR_ROOT), &vmar_base, NULL); mx_vaddr_t offset = heap_end - vmar_base; - mx_vmar_map(m_get_handle(M_HND_VMAR_ROOT), + mx_vmar_map(mx_get_startup_handle(MX_B_VMAR_ROOT), MX_VM_PERM_READ | MX_VM_PERM_WRITE | MX_VM_SPECIFIC, offset, heap_vmo, heap_sz, sz, &alloc_base); heap_sz += sz; diff --git a/photon/libc/sys/magenta/init.c b/photon/libc/sys/magenta/init.c index 6038af5..acf3a88 100644 --- a/photon/libc/sys/magenta/init.c +++ b/photon/libc/sys/magenta/init.c @@ -4,24 +4,10 @@ #include #include #include -#include "sys/handles.h" #include "__init.h" #include "__heap.h" #include "__fio.h" -struct handles { - mx_handle_t task_self; - mx_handle_t task_vmar; - mx_handle_t exec_vmar; - mx_handle_t stack_vmo; - mx_handle_t vdso_vmo; - mx_handle_t exec_vmo; - mx_handle_t ldsvc; - mx_handle_t bootstrap; -}; - -static struct handles rt_handles; - static const char **environ = NULL; const char **__crt_environ() @@ -34,7 +20,7 @@ extern void __crt_run_atexit(); static void parse_args( mx_bootstrap_msg_t *args, mx_handle_t *handles, - const char **argv, const char **envp, int hndc, struct handles *out) + const char **argv, const char **envp, int hndc, mx_bootstrap_handle_t *handles_out) { if (args->args_num > 0) { char *arg_buf = (char *)args + args->args_off; @@ -73,36 +59,8 @@ static void parse_args( uint32_t *hent = (uint32_t *)((char *)args + args->handle_info_off); for (int i = 0; i < hndc; i++) { - switch (MX_B_HND_TYPE(hent[i])) { - case MX_B_TASK_SELF: - out->task_self = handles[i]; - break; - case MX_B_VMO_VDSO: - out->vdso_vmo = handles[i]; - break; - case MX_B_VMO_STACK: - out->stack_vmo = handles[i]; - break; - case MX_B_VMAR_ROOT: - out->task_vmar = handles[i]; - break; - case MX_B_VMAR_EXEC: - out->exec_vmar = handles[i]; - break; - case MX_B_VMO_EXECUTABLE: - out->exec_vmo = handles[i]; - break; - case MX_B_TUNNEL_LDSVC: - out->ldsvc = handles[i]; - break; -#if 0 - case MX_B_VMO_BOOTDATA: - out->bootfs_vmo = handles[i]; - break; -#endif - default: - break; - } + handles_out[i].info = hent[i]; + handles_out[i].handle = handles[i]; } } @@ -134,42 +92,23 @@ int __crt_init(mx_handle_t bootstrap) const char *argv[msg->args_num + 1]; const char *envp[msg->environ_num + 1]; + mx_bootstrap_handle_t start_handles[nr_handles + 1]; + start_handles[nr_handles].handle = bootstrap; + start_handles[nr_handles].info = MX_B_HND(MX_B_TUNNEL_BTSTP, 0); + argv[msg->args_num] = NULL; envp[msg->environ_num] = NULL; environ = envp; - parse_args(msg, handles, argv, envp, nr_handles, &rt_handles); - rt_handles.bootstrap = bootstrap; + parse_args(msg, handles, argv, envp, nr_handles, start_handles); + mx_init_startup_handles(start_handles, nr_handles + 1); int ret = main(msg->args_num, argv); __crt_run_atexit(); - mx_task_kill(rt_handles.task_self, ret); + mx_task_kill(mx_get_startup_handle(MX_B_TASK_SELF), ret); /* unreachable */ hang(); return 0; } - -mx_handle_t m_get_handle(unsigned int type) -{ - switch (type) { - case M_HND_VMAR_ROOT: - return rt_handles.task_vmar; - case M_HND_VMAR_EXEC: - return rt_handles.exec_vmar; - case M_HND_VMO_EXEC: - return rt_handles.exec_vmo; - case M_HND_VMO_VDSO: - return rt_handles.vdso_vmo; - case M_HND_TASK_SELF: - return rt_handles.task_self; - case M_HND_TNL_LDSVC: - return rt_handles.ldsvc; - case M_HND_TNL_BTSTP: - return rt_handles.bootstrap; - default: - return MX_NULL_HANDLE; - } -} - diff --git a/photon/libc/sys/magenta/sys/handles.h b/photon/libc/sys/magenta/sys/handles.h deleted file mode 100644 index c9fc248..0000000 --- a/photon/libc/sys/magenta/sys/handles.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SYS_MAGENTA_SYS_HANDLES_H_ -#define SYS_MAGENTA_SYS_HANDLES_H_ - -#include - -#define M_HND_VMAR_ROOT 0x01u -#define M_HND_VMAR_EXEC 0x02u -#define M_HND_VMO_EXEC 0x03u -#define M_HND_VMO_VDSO 0x04u -#define M_HND_TNL_LDSVC 0x05u -#define M_HND_TNL_BTSTP 0x06u -#define M_HND_TASK_SELF 0x07u - -extern mx_handle_t m_get_handle(unsigned int type); - -#endif