Moved startup handle storage to Magenta ulib
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/handles.h>
|
|
||||||
#include <magenta/vmo.h>
|
#include <magenta/vmo.h>
|
||||||
#include <magenta/limits.h>
|
#include <magenta/limits.h>
|
||||||
|
#include <magenta/misc.h>
|
||||||
#include <magenta/vmar.h>
|
#include <magenta/vmar.h>
|
||||||
|
|
||||||
#define ROUND_UP(x, b) x += (b) - ((x) % (b))
|
#define ROUND_UP(x, b) x += (b) - ((x) % (b))
|
||||||
@@ -22,7 +22,7 @@ void __crt_heap_init(size_t heap_sz)
|
|||||||
&heap_vmo);
|
&heap_vmo);
|
||||||
|
|
||||||
mx_vaddr_t heap = 0;
|
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,
|
MX_VM_PERM_READ | MX_VM_PERM_WRITE,
|
||||||
0, heap_vmo, 0, heap_sz,
|
0, heap_vmo, 0, heap_sz,
|
||||||
&heap);
|
&heap);
|
||||||
@@ -47,10 +47,10 @@ void *__crt_heap_extend(size_t sz)
|
|||||||
mx_vmo_set_size(heap_vmo, heap_sz + sz);
|
mx_vmo_set_size(heap_vmo, heap_sz + sz);
|
||||||
|
|
||||||
mx_vaddr_t vmar_base, alloc_base;
|
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_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,
|
MX_VM_PERM_READ | MX_VM_PERM_WRITE | MX_VM_SPECIFIC,
|
||||||
offset, heap_vmo, heap_sz, sz, &alloc_base);
|
offset, heap_vmo, heap_sz, sz, &alloc_base);
|
||||||
heap_sz += sz;
|
heap_sz += sz;
|
||||||
|
|||||||
@@ -4,24 +4,10 @@
|
|||||||
#include <magenta/errors.h>
|
#include <magenta/errors.h>
|
||||||
#include <magenta/misc.h>
|
#include <magenta/misc.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "sys/handles.h"
|
|
||||||
#include "__init.h"
|
#include "__init.h"
|
||||||
#include "__heap.h"
|
#include "__heap.h"
|
||||||
#include "__fio.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;
|
static const char **environ = NULL;
|
||||||
|
|
||||||
const char **__crt_environ()
|
const char **__crt_environ()
|
||||||
@@ -34,7 +20,7 @@ extern void __crt_run_atexit();
|
|||||||
|
|
||||||
static void parse_args(
|
static void parse_args(
|
||||||
mx_bootstrap_msg_t *args, mx_handle_t *handles,
|
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) {
|
if (args->args_num > 0) {
|
||||||
char *arg_buf = (char *)args + args->args_off;
|
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);
|
uint32_t *hent = (uint32_t *)((char *)args + args->handle_info_off);
|
||||||
|
|
||||||
for (int i = 0; i < hndc; i++) {
|
for (int i = 0; i < hndc; i++) {
|
||||||
switch (MX_B_HND_TYPE(hent[i])) {
|
handles_out[i].info = hent[i];
|
||||||
case MX_B_TASK_SELF:
|
handles_out[i].handle = handles[i];
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,42 +92,23 @@ int __crt_init(mx_handle_t bootstrap)
|
|||||||
|
|
||||||
const char *argv[msg->args_num + 1];
|
const char *argv[msg->args_num + 1];
|
||||||
const char *envp[msg->environ_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;
|
argv[msg->args_num] = NULL;
|
||||||
envp[msg->environ_num] = NULL;
|
envp[msg->environ_num] = NULL;
|
||||||
environ = envp;
|
environ = envp;
|
||||||
|
|
||||||
parse_args(msg, handles, argv, envp, nr_handles, &rt_handles);
|
parse_args(msg, handles, argv, envp, nr_handles, start_handles);
|
||||||
rt_handles.bootstrap = bootstrap;
|
mx_init_startup_handles(start_handles, nr_handles + 1);
|
||||||
|
|
||||||
int ret = main(msg->args_num, argv);
|
int ret = main(msg->args_num, argv);
|
||||||
|
|
||||||
__crt_run_atexit();
|
__crt_run_atexit();
|
||||||
mx_task_kill(rt_handles.task_self, ret);
|
mx_task_kill(mx_get_startup_handle(MX_B_TASK_SELF), ret);
|
||||||
|
|
||||||
/* unreachable */
|
/* unreachable */
|
||||||
hang();
|
hang();
|
||||||
return 0;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef SYS_MAGENTA_SYS_HANDLES_H_
|
|
||||||
#define SYS_MAGENTA_SYS_HANDLES_H_
|
|
||||||
|
|
||||||
#include <magenta/types.h>
|
|
||||||
|
|
||||||
#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
|
|
||||||
Reference in New Issue
Block a user