Added Magenta heap support
This commit is contained in:
8
photon/libc/sys/magenta/__heap.h
Normal file
8
photon/libc/sys/magenta/__heap.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef SYS_MAGENTA_HEAP_H_
|
||||||
|
#define SYS_MAGENTA_HEAP_H_
|
||||||
|
|
||||||
|
#include "__init.h"
|
||||||
|
|
||||||
|
extern int __heap_init(struct __proc_start_info *info);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -9,6 +9,8 @@ struct __proc_start_info {
|
|||||||
mx_handle_t err;
|
mx_handle_t err;
|
||||||
int argc;
|
int argc;
|
||||||
const char **argv;
|
const char **argv;
|
||||||
|
mx_handle_t heap;
|
||||||
|
void *heap_map_base;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
set(photon_platform_extra_source_dirs libmagenta/libmagenta)
|
set(photon_platform_extra_source_dirs libmagenta/libmagenta)
|
||||||
set(photon_platform_extra_include_dirs libmagenta/libmagenta/arch/${machine})
|
set(photon_platform_extra_include_dirs
|
||||||
|
libmagenta/libmagenta
|
||||||
|
libmagenta/libmagenta/arch/${machine})
|
||||||
set(photon_platform_libs magenta)
|
set(photon_platform_libs magenta)
|
||||||
|
|||||||
41
photon/libc/sys/magenta/heap.c
Normal file
41
photon/libc/sys/magenta/heap.c
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#include <magenta.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "__init.h"
|
||||||
|
#include "__heap.h"
|
||||||
|
|
||||||
|
#define ROUND_UP(x, b) x += (b) - ((x) % (b))
|
||||||
|
|
||||||
|
static uintptr_t heap_start = 0;
|
||||||
|
static uintptr_t heap_end = 0;
|
||||||
|
static size_t heap_sz = 0;
|
||||||
|
static mx_handle_t heap_segment = MX_NULL_HANDLE;
|
||||||
|
|
||||||
|
int __heap_init(struct __proc_start_info *info)
|
||||||
|
{
|
||||||
|
heap_start = (uintptr_t)info->heap_map_base;
|
||||||
|
heap_end = (uintptr_t)info + sizeof(*info);
|
||||||
|
ROUND_UP(heap_end, 0x1000);
|
||||||
|
heap_segment = info->heap;
|
||||||
|
|
||||||
|
unsigned long sz = 0;
|
||||||
|
mx_segment_get_size(heap_segment, &sz);
|
||||||
|
heap_sz = sz;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *__extend_heap(size_t sz)
|
||||||
|
{
|
||||||
|
if (sz == 0) {
|
||||||
|
return (void *)(heap_end + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *start = (void *)heap_start;
|
||||||
|
|
||||||
|
uintptr_t ret = heap_end;
|
||||||
|
mx_segment_set_size(heap_segment, heap_sz + sz);
|
||||||
|
mx_segment_map(heap_segment, 0, heap_sz + sz, &start);
|
||||||
|
heap_end += sz;
|
||||||
|
return (void *)ret;
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "init.h"
|
#include "__init.h"
|
||||||
|
#include "__heap.h"
|
||||||
#include "__fio.h"
|
#include "__fio.h"
|
||||||
|
|
||||||
extern int main(int, const char **);
|
extern int main(int, const char **);
|
||||||
@@ -6,5 +7,6 @@ extern int main(int, const char **);
|
|||||||
int __crt_init(struct __proc_start_info *info)
|
int __crt_init(struct __proc_start_info *info)
|
||||||
{
|
{
|
||||||
__fio_init(info->in, info->out, info->err);
|
__fio_init(info->in, info->out, info->err);
|
||||||
|
__heap_init(info);
|
||||||
return main(info->argc, info->argv);
|
return main(info->argc, info->argv);
|
||||||
}
|
}
|
||||||
|
|||||||
Submodule photon/libc/sys/magenta/libmagenta updated: 04ccced9d4...51e77c9cfd
Reference in New Issue
Block a user