Compare commits
32 Commits
1674c8dbb2
...
97facbed6f
| Author | SHA1 | Date | |
|---|---|---|---|
| 97facbed6f | |||
| 17ab7edca0 | |||
| afb20bf59d | |||
| aa60adf991 | |||
| 9dc3644fc1 | |||
| ccede45ec7 | |||
| 08abe467ea | |||
| ce52afe5b4 | |||
| 52d31002c1 | |||
| d0fdb0268d | |||
| d879a37cb3 | |||
| 87fe2d20ec | |||
| c87e094d7d | |||
| 86d12edd19 | |||
| d8d96777f2 | |||
| 3588bab1d7 | |||
| 651ddf7827 | |||
| aaea926f4d | |||
| 07a1d579ca | |||
| 2795a66985 | |||
| df1662aa10 | |||
| 0f0cc44f7c | |||
| da7b60ca53 | |||
| addd36d237 | |||
| bfd191a336 | |||
| 2413538cb6 | |||
| ede9d39f07 | |||
| ffd28db3de | |||
| a5d99ca248 | |||
| daca537875 | |||
| 68566cd138 | |||
| 497f29fbbc |
+1
-1
@@ -1,6 +1,6 @@
|
||||
[submodule "kernel"]
|
||||
path = kernel
|
||||
url = https://g.wash.red/wash/mango.git
|
||||
url = https://g.wash.red/wash/magenta.git
|
||||
[submodule "sys/ropkg"]
|
||||
path = sys/ropkg
|
||||
url = git@github.com:washh/ropkg.git
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ check_pie_supported()
|
||||
|
||||
set(sys_dir ${CMAKE_CURRENT_BINARY_DIR}/sys)
|
||||
|
||||
set(kernel_name mango_kernel)
|
||||
set(kernel_name magenta_kernel)
|
||||
set(bsp_name rosetta-system.bsp)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
||||
|
||||
@@ -7,7 +7,7 @@ find_program(C_COMPILER x86_64-elf-gcc REQUIRED)
|
||||
find_program(CXX_COMPILER x86_64-elf-g++ REQUIRED)
|
||||
#find_program(ASM_COMPILER x86_64-elf-as REQUIRED)
|
||||
|
||||
add_compile_definitions(__mango__=1 __rosetta__=1)
|
||||
add_compile_definitions(__magenta__=1 __rosetta__=1)
|
||||
|
||||
set(CMAKE_C_COMPILER ${C_COMPILER})
|
||||
set(CMAKE_CXX_COMPILER ${CXX_COMPILER})
|
||||
|
||||
@@ -16,7 +16,7 @@ def successful_boot(boot_log, out):
|
||||
log(out, "Multiple kernel panics!")
|
||||
return 1
|
||||
|
||||
nr_boots = boot_log.count('Mango kernel version')
|
||||
nr_boots = boot_log.count('Magenta kernel version')
|
||||
if nr_boots == 0:
|
||||
log(out, "Kernel didn't start!")
|
||||
return 1
|
||||
|
||||
@@ -2,7 +2,7 @@ set timeout_style=menu
|
||||
set timeout=0
|
||||
|
||||
menuentry "Rosetta (Serial Log)" {
|
||||
multiboot /boot/mango_kernel kernel.early-console=ttyS0
|
||||
multiboot /boot/magenta_kernel kernel.early-console=ttyS0
|
||||
module /boot/rosetta-system.bsp
|
||||
boot
|
||||
}
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@
|
||||
| |--Downloads
|
||||
| \--Documents
|
||||
|--boot
|
||||
| |--mango_kernel
|
||||
| |--magenta_kernel
|
||||
| \--initrd.ec3
|
||||
|--usr
|
||||
| \--lib
|
||||
|
||||
+2
-2
@@ -28,12 +28,12 @@ Rosetta Operating System: Protocols
|
||||
3 Overview
|
||||
----------
|
||||
|
||||
Protocols is a very thin layer overtop of Mango ports. It provides a
|
||||
Protocols is a very thin layer overtop of Magenta ports. It provides a
|
||||
declarative language for describing message layouts in a language-agnostic
|
||||
format, and a tool for generating concrete implementations of protocols in
|
||||
various programming languages.
|
||||
|
||||
Protocols makes heavy use of Mango's I/O vectors facility to avoid performing
|
||||
Protocols makes heavy use of Magenta's I/O vectors facility to avoid performing
|
||||
any dynamic memory allocation or unnecessary copying of data. As often as
|
||||
possible, any parameters you pass to a protocol function will be copied
|
||||
directly into the address space of the recipient. This makes Protocols
|
||||
|
||||
+1
-1
Submodule kernel updated: 278fe39c0d...c90ee285cc
+15
-16
@@ -1,23 +1,23 @@
|
||||
file(GLOB items *)
|
||||
|
||||
set(fx_modules core ds serial)
|
||||
set(fx_assemblies fx.runtime fx.collections fx.serial)
|
||||
set(fx_enable_floating_point 0)
|
||||
set(fx_enable_tests 0)
|
||||
|
||||
add_subdirectory(
|
||||
${CMAKE_SOURCE_DIR}/kernel/libmango
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libmango)
|
||||
${CMAKE_SOURCE_DIR}/kernel/libmagenta
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libmagenta)
|
||||
|
||||
rosetta_wrap_library(
|
||||
NAME libmango
|
||||
NAME libmagenta
|
||||
PUBLIC_INCLUDE_DIRS
|
||||
${CMAKE_SOURCE_DIR}/kernel/libmango/include
|
||||
${CMAKE_SOURCE_DIR}/kernel/libmango/include-user
|
||||
${CMAKE_SOURCE_DIR}/kernel/libmagenta/include
|
||||
${CMAKE_SOURCE_DIR}/kernel/libmagenta/include-user
|
||||
SOURCES ${asm_sources}
|
||||
HEADERS ${headers})
|
||||
|
||||
sysroot_add_library(
|
||||
NAME libmango
|
||||
NAME libmagenta
|
||||
HEADER_DIR /usr/include
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
@@ -29,21 +29,20 @@ foreach(item ${items})
|
||||
add_subdirectory(${item})
|
||||
endforeach (item)
|
||||
|
||||
foreach (module ${fx_modules})
|
||||
target_link_libraries(fx-${module} libc libpthread)
|
||||
target_link_libraries(fx-${module}-s libc-core libc-pthread libmango)
|
||||
target_link_options(fx-${module} PRIVATE -Wl,--soname,libfx-${module}.so)
|
||||
foreach (assembly ${fx_assemblies})
|
||||
target_link_libraries(${assembly} libc libpthread)
|
||||
target_link_options(${assembly} PRIVATE -Wl,--soname,lib${assembly}.so)
|
||||
rosetta_wrap_library(
|
||||
NAME fx-${module}
|
||||
NAME ${assembly}
|
||||
PUBLIC_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/libfx/${module}/include)
|
||||
set_target_properties(fx-${module} fx-${module}-s PROPERTIES
|
||||
set_target_properties(${assembly} PROPERTIES
|
||||
PREFIX "lib")
|
||||
sysroot_add_library(
|
||||
NAME fx-${module}
|
||||
NAME ${assembly}
|
||||
HEADER_DIR /usr/include
|
||||
LIB_DIR /usr/lib)
|
||||
bsp_add_library(
|
||||
NAME fx-${module}
|
||||
NAME ${assembly}
|
||||
LIB_DIR /usr/lib)
|
||||
endforeach (module)
|
||||
endforeach (assembly)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set(source_dirs core malloc io)
|
||||
set(source_dirs core malloc io exec)
|
||||
|
||||
set(public_include_dirs
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
@@ -26,8 +26,8 @@ bsp_add_library(
|
||||
NAME libc
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_link_libraries(libc PRIVATE librosetta libxpc-static interface::fs)
|
||||
target_link_libraries(libc PUBLIC libmango)
|
||||
target_link_libraries(libc PRIVATE librosetta libxpc-static liblaunch-static interface::fs)
|
||||
target_link_libraries(libc PUBLIC libmagenta)
|
||||
target_compile_definitions(libc PRIVATE ENABLE_GLOBAL_HEAP=1)
|
||||
|
||||
add_subdirectory(pthread)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set(source_dirs assert stdio stdlib string errno ctype wctype)
|
||||
set(source_dirs assert stdio stdlib string errno ctype wctype unistd)
|
||||
|
||||
foreach (dir ${source_dirs})
|
||||
file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.c)
|
||||
@@ -26,4 +26,4 @@ sysroot_add_library(
|
||||
HEADER_DIR /usr/include
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_link_libraries(libc-core PRIVATE libmango librosetta)
|
||||
target_link_libraries(libc-core PRIVATE libmagenta librosetta)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <errno.h>
|
||||
#include <mango/status.h>
|
||||
#include <magenta/status.h>
|
||||
|
||||
static int __errno = SUCCESS;
|
||||
|
||||
@@ -11,7 +11,7 @@ int __attribute__((weak)) * __errno_location(void)
|
||||
#if defined(BUILD_STATIC)
|
||||
int __set_errno(int err)
|
||||
{
|
||||
return -err;
|
||||
return err == 0 ? 0 : -err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -20,7 +20,7 @@ int __set_errno(int err)
|
||||
{
|
||||
/* TODO */
|
||||
*__errno_location() = err;
|
||||
return -1;
|
||||
return err == 0 ? 0 : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <mango/task.h>
|
||||
#include <magenta/task.h>
|
||||
|
||||
void abort(void)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <mango/task.h>
|
||||
#include <magenta/task.h>
|
||||
|
||||
void exit(int code)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 1990 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. [rescinded 22 July 1999]
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
intmax_t strtoimax(
|
||||
const char *restrict ptr,
|
||||
char **restrict endptr,
|
||||
register int base)
|
||||
{
|
||||
const char *s = ptr;
|
||||
intmax_t acc;
|
||||
int c;
|
||||
intmax_t cutoff;
|
||||
int neg = 0, any, cutlim;
|
||||
|
||||
do {
|
||||
c = *s++;
|
||||
} while (isspace(c));
|
||||
|
||||
if (c == '-') {
|
||||
neg = 1;
|
||||
c = *s++;
|
||||
} else if (c == '+') {
|
||||
c = *s++;
|
||||
}
|
||||
|
||||
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
|
||||
c = s[1];
|
||||
s += 2;
|
||||
base = 16;
|
||||
}
|
||||
|
||||
if (base == 0) {
|
||||
base = c == '0' ? 8 : 10;
|
||||
}
|
||||
|
||||
cutoff = (intmax_t)INTMAX_MAX / (intmax_t)base;
|
||||
cutlim = (intmax_t)INTMAX_MAX % (intmax_t)base;
|
||||
for (acc = 0, any = 0;; c = *s++) {
|
||||
if (isdigit(c)) {
|
||||
c -= '0';
|
||||
} else if (isalpha(c)) {
|
||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (c >= base) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
|
||||
any = -1;
|
||||
} else {
|
||||
any = 1;
|
||||
acc *= base;
|
||||
acc += c;
|
||||
}
|
||||
}
|
||||
if (any < 0) {
|
||||
acc = INTMAX_MAX;
|
||||
__set_errno(ERANGE);
|
||||
} else if (neg) {
|
||||
acc = -acc;
|
||||
}
|
||||
|
||||
if (endptr != 0) {
|
||||
*endptr = (char *)(any ? s - 1 : ptr);
|
||||
}
|
||||
|
||||
return (acc);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 1990 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. [rescinded 22 July 1999]
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
uintmax_t strtoumax(
|
||||
const char *restrict ptr,
|
||||
char **restrict endptr,
|
||||
register int base)
|
||||
{
|
||||
const char *s = ptr;
|
||||
uintmax_t acc;
|
||||
int c;
|
||||
uintmax_t cutoff;
|
||||
int neg = 0, any, cutlim;
|
||||
|
||||
do {
|
||||
c = *s++;
|
||||
} while (isspace(c));
|
||||
|
||||
if (c == '-') {
|
||||
neg = 1;
|
||||
c = *s++;
|
||||
} else if (c == '+') {
|
||||
c = *s++;
|
||||
}
|
||||
|
||||
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
|
||||
c = s[1];
|
||||
s += 2;
|
||||
base = 16;
|
||||
}
|
||||
|
||||
if (base == 0) {
|
||||
base = c == '0' ? 8 : 10;
|
||||
}
|
||||
|
||||
cutoff = (uintmax_t)UINTMAX_MAX / (uintmax_t)base;
|
||||
cutlim = (uintmax_t)UINTMAX_MAX % (uintmax_t)base;
|
||||
for (acc = 0, any = 0;; c = *s++) {
|
||||
if (isdigit(c)) {
|
||||
c -= '0';
|
||||
} else if (isalpha(c)) {
|
||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (c >= base) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
|
||||
any = -1;
|
||||
} else {
|
||||
any = 1;
|
||||
acc *= base;
|
||||
acc += c;
|
||||
}
|
||||
}
|
||||
if (any < 0) {
|
||||
acc = UINTMAX_MAX;
|
||||
__set_errno(ERANGE);
|
||||
} else if (neg) {
|
||||
acc = -acc;
|
||||
}
|
||||
|
||||
if (endptr != 0) {
|
||||
*endptr = (char *)(any ? s - 1 : ptr);
|
||||
}
|
||||
|
||||
return (acc);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <mango/log.h>
|
||||
#include <magenta/log.h>
|
||||
#include <rosetta/bootstrap.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <errno.h>
|
||||
#include <magenta/task.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
pid_t fork(void)
|
||||
{
|
||||
kern_handle_t new_task = KERN_HANDLE_INVALID,
|
||||
new_space = KERN_HANDLE_INVALID;
|
||||
kern_status_t status = task_duplicate(&new_task, &new_space);
|
||||
if (status != KERN_OK) {
|
||||
return __set_errno(__errno_from_kern_status(status));
|
||||
}
|
||||
|
||||
if (new_task == KERN_HANDLE_INVALID) {
|
||||
/* child task */
|
||||
return 0;
|
||||
}
|
||||
|
||||
tid_t child = 0;
|
||||
task_config_get(new_task, TASK_CFG_ID, &child, sizeof child);
|
||||
|
||||
/* parent task */
|
||||
return child;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
set(source_dirs unistd spawn)
|
||||
|
||||
file(GLOB sources *.c *.h)
|
||||
|
||||
foreach (dir ${source_dirs})
|
||||
file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.c)
|
||||
file(GLOB dir_headers ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.h)
|
||||
|
||||
set(sources ${sources} ${dir_sources})
|
||||
set(headers ${headers} ${dir_headers})
|
||||
endforeach (dir)
|
||||
|
||||
file(GLOB_RECURSE sub_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
|
||||
set(headers ${headers} ${sub_headers})
|
||||
|
||||
set(component_sources ${sources} PARENT_SCOPE)
|
||||
set(component_headers ${headers} PARENT_SCOPE)
|
||||
set(component_public_include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
|
||||
|
||||
rosetta_add_library(STATIC
|
||||
NAME libc-exec
|
||||
PUBLIC_INCLUDE_DIRS
|
||||
${public_include_dirs}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
SOURCES ${sources}
|
||||
HEADERS ${headers})
|
||||
|
||||
sysroot_add_library(
|
||||
NAME libc-exec
|
||||
HEADER_DIR /usr/include
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_link_libraries(libc-exec libc-core libc-io libmagenta liblaunch-static)
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef LIBC_EXEC_SPAWN_FILE_ACTIONS_H_
|
||||
#define LIBC_EXEC_SPAWN_FILE_ACTIONS_H_
|
||||
|
||||
#include <spawn.h>
|
||||
|
||||
struct __posix_spawn_file_actions {
|
||||
long temp[4];
|
||||
};
|
||||
|
||||
_Static_assert(
|
||||
sizeof(struct __posix_spawn_file_actions)
|
||||
<= __POSIX_SPAWN_FILE_ACTIONS_SIZE__,
|
||||
"struct __posix_spawn_file_actions is too big");
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,176 @@
|
||||
#include "file-actions.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <launch.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/task.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <spawn.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static enum launch_status resolve_dependency(
|
||||
struct launch_ctx *ctx,
|
||||
const char *name,
|
||||
kern_handle_t *out,
|
||||
void *arg)
|
||||
{
|
||||
int fd = open(name, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
int err = 0;
|
||||
kern_handle_t image = KERN_HANDLE_INVALID;
|
||||
kern_status_t status = fs_map(
|
||||
fd,
|
||||
PROT_READ | PROT_EXEC,
|
||||
MAP_SHARED | MAP_EXECUTABLE,
|
||||
&err,
|
||||
&image);
|
||||
close(fd);
|
||||
|
||||
if (status != KERN_OK || err != SUCCESS) {
|
||||
return LAUNCH_ERR_CANNOT_RESOLVE_DEPENDENCY;
|
||||
}
|
||||
|
||||
*out = image;
|
||||
return LAUNCH_OK;
|
||||
}
|
||||
|
||||
static size_t count_array_items(char *const items[])
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; items[i]; i++)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
static const char *get_task_name(const char *path)
|
||||
{
|
||||
const char *name = path;
|
||||
for (size_t i = 0; path[i]; i++) {
|
||||
char c = path[i];
|
||||
char c2 = path[i + 1];
|
||||
if (c != '/') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c2 == '\0' || c2 == '/') {
|
||||
continue;
|
||||
}
|
||||
|
||||
name = path + i + 1;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
int posix_spawn(
|
||||
pid_t *restrict pid,
|
||||
const char *restrict path,
|
||||
const posix_spawn_file_actions_t *restrict file_actions,
|
||||
const posix_spawnattr_t *restrict attrp,
|
||||
char *const argv[],
|
||||
char *const envp[])
|
||||
{
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
int err = 0;
|
||||
kern_handle_t image = KERN_HANDLE_INVALID;
|
||||
kern_status_t status = fs_map(
|
||||
fd,
|
||||
PROT_READ | PROT_EXEC,
|
||||
MAP_SHARED | MAP_EXECUTABLE,
|
||||
&err,
|
||||
&image);
|
||||
close(fd);
|
||||
|
||||
if (status != KERN_OK) {
|
||||
return __set_errno(__errno_from_kern_status(status));
|
||||
}
|
||||
|
||||
if (err != SUCCESS) {
|
||||
return __set_errno(err);
|
||||
}
|
||||
|
||||
struct launch_ctx launch;
|
||||
struct launch_result result;
|
||||
|
||||
size_t argc = 0, envc = 0;
|
||||
if (argv) {
|
||||
argc = count_array_items(argv);
|
||||
}
|
||||
|
||||
if (envp) {
|
||||
envc = count_array_items(envp);
|
||||
}
|
||||
|
||||
kern_handle_t self = KERN_HANDLE_INVALID,
|
||||
address_space = KERN_HANDLE_INVALID;
|
||||
|
||||
task_self(&self);
|
||||
task_get_address_space(self, &address_space);
|
||||
|
||||
struct launch_parameters params = {
|
||||
.p_exec_image = image,
|
||||
.p_exec_path = path,
|
||||
.p_parent_task = self,
|
||||
.p_task_name = get_task_name(path),
|
||||
.p_local_address_space = address_space,
|
||||
.p_resolver_arg = NULL,
|
||||
.p_argc = argc,
|
||||
.p_argv = (const char **)argv,
|
||||
.p_envc = envc,
|
||||
.p_envp = (const char **)envp,
|
||||
.p_channel_count = 0,
|
||||
.p_channels = NULL,
|
||||
.p_stdio = {
|
||||
KERN_HANDLE_INVALID,
|
||||
KERN_HANDLE_INVALID,
|
||||
KERN_HANDLE_INVALID,
|
||||
},
|
||||
};
|
||||
|
||||
launch_ctx_init(&launch);
|
||||
launch.ctx_resolve_library = resolve_dependency;
|
||||
|
||||
enum launch_status launch_status = launch_ctx_execute(
|
||||
&launch,
|
||||
¶ms,
|
||||
LAUNCH_F_CLONE_ALL_HANDLES,
|
||||
&result);
|
||||
kern_handle_close(address_space);
|
||||
kern_handle_close(self);
|
||||
kern_handle_close(image);
|
||||
|
||||
switch (launch_status) {
|
||||
case LAUNCH_OK:
|
||||
break;
|
||||
case LAUNCH_ERR_NO_MEMORY:
|
||||
return __set_errno(ENOMEM);
|
||||
case LAUNCH_ERR_INVALID_EXECUTABLE:
|
||||
case LAUNCH_ERR_UNSUPPORTED_EXECUTABLE:
|
||||
case LAUNCH_ERR_MISSING_SYMBOL:
|
||||
case LAUNCH_ERR_INTERPRETER_REQUIRED:
|
||||
return __set_errno(ENOEXEC);
|
||||
case LAUNCH_ERR_CANNOT_RESOLVE_DEPENDENCY:
|
||||
return __set_errno(ENOENT);
|
||||
default:
|
||||
/* TODO */
|
||||
return __set_errno(EPERM);
|
||||
}
|
||||
|
||||
tid_t child_id = 0;
|
||||
task_config_get(result.r_task, TASK_CFG_ID, &child_id, sizeof child_id);
|
||||
|
||||
*pid = child_id;
|
||||
|
||||
return __set_errno(SUCCESS);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define LD_EXTERN extern __attribute__((weak))
|
||||
LD_EXTERN int ld_execl(const char *path, const char *arg1, va_list arg);
|
||||
LD_EXTERN int ld_execlp(const char *file, const char *arg1, va_list arg);
|
||||
LD_EXTERN int ld_execle(const char *path, const char *arg1, va_list arg);
|
||||
LD_EXTERN int ld_execv(const char *path, char *const argv[]);
|
||||
LD_EXTERN int ld_execvp(const char *file, char *const argv[]);
|
||||
LD_EXTERN int ld_execvpe(
|
||||
const char *file,
|
||||
char *const argv[],
|
||||
char *const envp[]);
|
||||
|
||||
int execl(const char *path, const char *arg, ...)
|
||||
{
|
||||
va_list arglist;
|
||||
va_start(arglist, arg);
|
||||
int err = ld_execl(path, arg, arglist);
|
||||
va_end(arglist);
|
||||
|
||||
if (err < 0) {
|
||||
return __set_errno(-err);
|
||||
}
|
||||
|
||||
/* this shouldn't happen */
|
||||
return __set_errno(ENOEXEC);
|
||||
}
|
||||
|
||||
int execlp(const char *file, const char *arg, ...)
|
||||
{
|
||||
va_list arglist;
|
||||
va_start(arglist, arg);
|
||||
int err = ld_execlp(file, arg, arglist);
|
||||
va_end(arglist);
|
||||
|
||||
if (err < 0) {
|
||||
return __set_errno(-err);
|
||||
}
|
||||
|
||||
/* this shouldn't happen */
|
||||
return __set_errno(ENOEXEC);
|
||||
}
|
||||
|
||||
int execle(const char *path, const char *arg, ...)
|
||||
{
|
||||
va_list arglist;
|
||||
va_start(arglist, arg);
|
||||
int err = ld_execle(path, arg, arglist);
|
||||
va_end(arglist);
|
||||
|
||||
if (err < 0) {
|
||||
return __set_errno(-err);
|
||||
}
|
||||
|
||||
/* this shouldn't happen */
|
||||
return __set_errno(ENOEXEC);
|
||||
}
|
||||
|
||||
int execv(const char *path, char *const argv[])
|
||||
{
|
||||
int err = ld_execv(path, argv);
|
||||
|
||||
if (err < 0) {
|
||||
return __set_errno(-err);
|
||||
}
|
||||
|
||||
/* this shouldn't happen */
|
||||
return __set_errno(ENOEXEC);
|
||||
}
|
||||
|
||||
int execvp(const char *file, char *const argv[])
|
||||
{
|
||||
int err = ld_execvp(file, argv);
|
||||
|
||||
if (err < 0) {
|
||||
return __set_errno(-err);
|
||||
}
|
||||
|
||||
/* this shouldn't happen */
|
||||
return __set_errno(ENOEXEC);
|
||||
}
|
||||
|
||||
int execvpe(const char *file, char *const argv[], char *const envp[])
|
||||
{
|
||||
int err = ld_execvpe(file, argv, envp);
|
||||
|
||||
if (err < 0) {
|
||||
return __set_errno(-err);
|
||||
}
|
||||
|
||||
/* this shouldn't happen */
|
||||
return __set_errno(ENOEXEC);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef MATH_H_
|
||||
#define MATH_H_
|
||||
|
||||
/* IEEE positive infinity. */
|
||||
#ifndef INFINITY
|
||||
#define INFINITY (__builtin_inff())
|
||||
#endif
|
||||
|
||||
/* IEEE Not A Number. */
|
||||
#ifndef NAN
|
||||
#define NAN (__builtin_nanf(""))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef SCHED_H_
|
||||
#define SCHED_H_
|
||||
|
||||
#include <time.h>
|
||||
|
||||
struct sched_param {
|
||||
int sched_priority;
|
||||
int sched_ss_low_priority;
|
||||
struct timespec sched_ss_repl_period;
|
||||
struct timespec sched_ss_init_budget;
|
||||
int sched_ss_max_repl;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
#ifndef SIGNAL_H_
|
||||
#define SIGNAL_H_
|
||||
|
||||
#define SIG_IGN 0
|
||||
#define SIG_HOLD 1
|
||||
#define SIG_ERR 2
|
||||
#define SIG_DFL 3
|
||||
|
||||
#define SIGEV_NONE 0
|
||||
#define SIGEV_SIGNAL 1
|
||||
#define SIGEV_THREAD 2
|
||||
|
||||
#define SIGABRT 1
|
||||
#define SIGALRM 2
|
||||
#define SIGBUS 3
|
||||
#define SIGCHLD 4
|
||||
#define SIGCONT 5
|
||||
#define SIGFPE 6
|
||||
#define SIGHUP 7
|
||||
#define SIGILL 8
|
||||
#define SIGINT 9
|
||||
#define SIGKILL 10
|
||||
#define SIGPIPE 11
|
||||
#define SIGQUIT 12
|
||||
#define SIGSEGV 13
|
||||
#define SIGSTOP 14
|
||||
#define SIGTERM 15
|
||||
#define SIGTSTP 16
|
||||
#define SIGTTIN 17
|
||||
#define SIGTTOU 18
|
||||
#define SIGUSR1 19
|
||||
#define SIGUSR2 20
|
||||
#define SIGPOLL 21
|
||||
#define SIGPROF 22
|
||||
#define SIGSYS 23
|
||||
#define SIGTRAP 24
|
||||
#define SIGURG 25
|
||||
#define SIGVTALRM 26
|
||||
#define SIGXCPU 27
|
||||
#define SIGXFSZ 28
|
||||
|
||||
typedef long long sigset_t;
|
||||
|
||||
union sigval {
|
||||
int sival_int;
|
||||
void *sival_ptr;
|
||||
};
|
||||
|
||||
struct sigevent {
|
||||
int sigev_notify;
|
||||
int sigev_signo;
|
||||
union sigval sigev_value;
|
||||
void (*sigev_notify_function)(union sigval);
|
||||
/* TODO pthread_attr_t sigev_notify_attributes */
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,86 @@
|
||||
#ifndef SPAWN_H_
|
||||
#define SPAWN_H_
|
||||
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define __POSIX_SPAWN_FILE_ACTIONS_SIZE__ 32
|
||||
#define __POSIX_SPAWNATTR_SIZE__ 32
|
||||
|
||||
struct sched_param;
|
||||
|
||||
typedef struct posix_spawn_file_actions {
|
||||
char __opaque[__POSIX_SPAWN_FILE_ACTIONS_SIZE__];
|
||||
} posix_spawn_file_actions_t;
|
||||
|
||||
typedef struct posix_spawnattr {
|
||||
char __opaque[__POSIX_SPAWN_FILE_ACTIONS_SIZE__];
|
||||
} posix_spawnattr_t;
|
||||
|
||||
extern int posix_spawn_file_actions_init(
|
||||
posix_spawn_file_actions_t *restrict file_actions);
|
||||
extern int posix_spawn_file_actions_destroy(
|
||||
posix_spawn_file_actions_t *restrict file_actions);
|
||||
extern int posix_spawn_file_actions_addopen(
|
||||
posix_spawn_file_actions_t *restrict file_actions,
|
||||
int fildes,
|
||||
const char *path,
|
||||
int oflag,
|
||||
mode_t mode);
|
||||
extern int posix_spawn_file_actions_addclose(
|
||||
posix_spawn_file_actions_t *restrict file_actions,
|
||||
int fildes);
|
||||
extern int posix_spawn_file_actions_adddup2(
|
||||
posix_spawn_file_actions_t *restrict file_actions,
|
||||
int fildes,
|
||||
int newfildes);
|
||||
|
||||
extern int posix_spawnattr_init(posix_spawnattr_t *restrict attrp);
|
||||
extern int posix_spawnattr_destroy(posix_spawnattr_t *restrict attrp);
|
||||
extern int posix_spawnattr_getflags(
|
||||
const posix_spawnattr_t *restrict attrp,
|
||||
short *restrict flags);
|
||||
extern int posix_spawnattr_setflags(
|
||||
posix_spawnattr_t *restrict attrp,
|
||||
short flags);
|
||||
extern int posix_spawnattr_getschedpolicy(
|
||||
const posix_spawnattr_t *restrict attrp,
|
||||
int *restrict schedpolicy);
|
||||
extern int posix_spawnattr_setschedpolicy(
|
||||
posix_spawnattr_t *restrict attrp,
|
||||
int schedpolicy);
|
||||
extern int posix_spawnattr_getschedparam(
|
||||
const posix_spawnattr_t *restrict attrp,
|
||||
struct sched_param *restrict schedparam);
|
||||
extern int posix_spawnattr_setschedparam(
|
||||
posix_spawnattr_t *restrict attrp,
|
||||
const struct sched_param *restrict schedparam);
|
||||
extern int posix_spawnattr_getpgroup(
|
||||
const posix_spawnattr_t *restrict attrp,
|
||||
pid_t *restrict pgroup);
|
||||
extern int posix_spawnattr_setpgroup(
|
||||
posix_spawnattr_t *restrict attrp,
|
||||
pid_t pgroup);
|
||||
extern int posix_spawnattr_getsigmask(
|
||||
const posix_spawnattr_t *restrict attrp,
|
||||
sigset_t *restrict sigmask);
|
||||
extern int posix_spawnattr_setsigmask(
|
||||
posix_spawnattr_t *restrict attrp,
|
||||
sigset_t sigmask);
|
||||
|
||||
extern int posix_spawn(
|
||||
pid_t *restrict pid,
|
||||
const char *restrict path,
|
||||
const posix_spawn_file_actions_t *restrict file_actions,
|
||||
const posix_spawnattr_t *restrict attrp,
|
||||
char *const argv[],
|
||||
char *const envp[]);
|
||||
extern int posix_spawnp(
|
||||
pid_t *restrict pid,
|
||||
const char *restrict file,
|
||||
const posix_spawn_file_actions_t *restrict file_actions,
|
||||
const posix_spawnattr_t *restrict attrp,
|
||||
char *const argv[],
|
||||
char *const envp[]);
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,7 @@
|
||||
#define STDLIB_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern void abort(void);
|
||||
extern void exit(int result);
|
||||
@@ -27,4 +28,16 @@ extern unsigned long long strtoull(
|
||||
char **restrict str_end,
|
||||
int base);
|
||||
|
||||
extern uintmax_t strtoumax(
|
||||
const char *restrict str,
|
||||
char **restrict endptr,
|
||||
int base);
|
||||
extern intmax_t strtoimax(
|
||||
const char *restrict str,
|
||||
char **restrict str_end,
|
||||
int base);
|
||||
|
||||
extern float strtof(const char *restrict str, char **restrict endptr);
|
||||
extern double strtod(const char *restrict str, char **restrict endptr);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef SYS_MMAN_H_
|
||||
#define SYS_MMAN_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define PROT_NONE 0x00u
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef SYS_REMOTE_H_
|
||||
#define SYS_REMOTE_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
enum sys_remote_id {
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#ifndef SYS_TYPES_H_
|
||||
#define SYS_TYPES_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
|
||||
#define SEEK_SET 0
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
typedef size_t ino_t;
|
||||
typedef long pid_t;
|
||||
typedef long mode_t;
|
||||
|
||||
struct dentry {
|
||||
unsigned long d_ino;
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
#ifndef TIME_H_
|
||||
#define TIME_H_
|
||||
|
||||
typedef long long time_t;
|
||||
|
||||
struct timespec {
|
||||
time_t tv_sec;
|
||||
long long tv_nsec;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,4 +14,13 @@ extern off_t lseek(int fd, off_t offset, int whence);
|
||||
|
||||
extern long getdents(int fd, struct dentry *dirp, unsigned int count);
|
||||
|
||||
extern pid_t fork(void);
|
||||
|
||||
extern int execl(const char *path, const char *arg, ...);
|
||||
extern int execlp(const char *file, const char *arg, ...);
|
||||
extern int execle(const char *path, const char *arg, ...);
|
||||
extern int execv(const char *path, char *const argv[]);
|
||||
extern int execvp(const char *file, char *const argv[]);
|
||||
extern int execvpe(const char *file, char *const argv[], char *const envp[]);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,4 +30,4 @@ sysroot_add_library(
|
||||
HEADER_DIR /usr/include
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_link_libraries(libc-io libc-core interface::fs libxpc-static libmango)
|
||||
target_link_libraries(libc-io libc-core interface::fs libxpc-static libmagenta)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <mango/log.h>
|
||||
#include <magenta/log.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "file.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <mango/futex.h>
|
||||
#include <mango/log.h>
|
||||
#include <magenta/futex.h>
|
||||
#include <magenta/log.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -22,7 +22,6 @@ static long clear_buf(struct __opaque_file *f)
|
||||
|
||||
static long refill_buf(struct __opaque_file *f)
|
||||
{
|
||||
kern_tracef("refill");
|
||||
char *buf = NULL;
|
||||
size_t available = 0;
|
||||
long r = 0;
|
||||
@@ -108,7 +107,6 @@ void __libc_file_lock(struct __opaque_file *f)
|
||||
{
|
||||
kern_futex_t expected = 0;
|
||||
while (1) {
|
||||
kern_tracef("lock=%u (%p)", f->f_lock, f);
|
||||
expected = 0;
|
||||
if (__atomic_compare_exchange_n(
|
||||
&f->f_lock,
|
||||
@@ -117,11 +115,9 @@ void __libc_file_lock(struct __opaque_file *f)
|
||||
0,
|
||||
__ATOMIC_ACQUIRE,
|
||||
__ATOMIC_ACQUIRE)) {
|
||||
kern_tracef("locked=%u (%p)", f->f_lock, f);
|
||||
return;
|
||||
}
|
||||
|
||||
kern_tracef("wait=%u (%p)", expected, f);
|
||||
futex_wait(&f->f_lock, 1, FUTEX_PRIVATE);
|
||||
}
|
||||
}
|
||||
@@ -130,12 +126,10 @@ void __libc_file_unlock(struct __opaque_file *f)
|
||||
{
|
||||
f->f_lock = 0;
|
||||
futex_wake(&f->f_lock, 1, FUTEX_PRIVATE);
|
||||
kern_tracef("unlocked=%u (%p)", f->f_lock, f);
|
||||
}
|
||||
|
||||
static long read_buf(struct __opaque_file *f, void *out, size_t count)
|
||||
{
|
||||
kern_tracef("read_buf(%p, %zu)", out, count);
|
||||
char *dest = out;
|
||||
size_t nr_read = 0;
|
||||
long r = 0;
|
||||
@@ -168,7 +162,6 @@ static long read_buf(struct __opaque_file *f, void *out, size_t count)
|
||||
|
||||
static long read_nobuf(struct __opaque_file *f, void *out, size_t count)
|
||||
{
|
||||
kern_tracef("read_nobuf");
|
||||
return read(f->f_fd, out, count);
|
||||
}
|
||||
|
||||
@@ -286,9 +279,6 @@ static long write_nobuf(struct __opaque_file *f, const void *out, size_t count)
|
||||
|
||||
long __libc_file_write(struct __opaque_file *f, const void *buf, size_t count)
|
||||
{
|
||||
if (f->f_lock != 1) {
|
||||
kern_tracef("file is not locked!!!");
|
||||
}
|
||||
long ret = 0;
|
||||
if (f->f_prev != OP_WRITE) {
|
||||
ret = clear_buf(f);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "ringbuf.h"
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
enum file_flags {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "file.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <mango/log.h>
|
||||
#include <magenta/log.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -45,13 +45,6 @@ int __libc_ringbuf_get_read_buffer(
|
||||
contiguous_capacity = buf->buf_writep - buf->buf_readp;
|
||||
}
|
||||
|
||||
kern_tracef(
|
||||
"OPEN READ: readp=%zu, writep=%zu, max=%zu -> %p cap=%zu",
|
||||
buf->buf_readp,
|
||||
buf->buf_writep,
|
||||
buf->buf_max,
|
||||
buf->buf_ptr + buf->buf_readp,
|
||||
contiguous_capacity);
|
||||
*out_len = contiguous_capacity;
|
||||
|
||||
if (contiguous_capacity == 0) {
|
||||
@@ -74,8 +67,6 @@ void __libc_ringbuf_put_read_buffer(
|
||||
buf->buf_readp = buf->buf_writep = 0;
|
||||
}
|
||||
|
||||
kern_tracef("CLOSE READ: %p r=%zu", *bufp, *len);
|
||||
|
||||
*bufp = NULL;
|
||||
*len = 0;
|
||||
}
|
||||
@@ -101,14 +92,6 @@ int __libc_ringbuf_get_write_buffer(
|
||||
contiguous_capacity = buf->buf_readp - buf->buf_writep - 1;
|
||||
}
|
||||
|
||||
kern_tracef(
|
||||
"OPEN WRITE: readp=%zu, writep=%zu, max=%zu -> %p cap=%zu",
|
||||
buf->buf_readp,
|
||||
buf->buf_writep,
|
||||
buf->buf_max,
|
||||
buf->buf_ptr + buf->buf_readp,
|
||||
contiguous_capacity);
|
||||
|
||||
*out_len = contiguous_capacity;
|
||||
|
||||
if (contiguous_capacity == 0) {
|
||||
@@ -131,12 +114,6 @@ void __libc_ringbuf_put_write_buffer(
|
||||
buf->buf_readp = buf->buf_writep = 0;
|
||||
}
|
||||
|
||||
kern_tracef(
|
||||
"CLOSE WRITE: %p r=%zu (%c)",
|
||||
*bufp,
|
||||
*len,
|
||||
*(char *)(*bufp));
|
||||
|
||||
*bufp = NULL;
|
||||
*len = 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/msg.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/msg.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <sys/remote.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/msg.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/msg.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <sys/remote.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/msg.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/msg.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <sys/remote.h>
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/task.h>
|
||||
#include <mango/vm.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/task.h>
|
||||
#include <magenta/vm.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/task.h>
|
||||
#include <mango/vm.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/task.h>
|
||||
#include <magenta/vm.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/msg.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/msg.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <sys/remote.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/msg.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/msg.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <sys/remote.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/msg.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/msg.h>
|
||||
#include <rosetta/fs.h>
|
||||
#include <sys/remote.h>
|
||||
|
||||
|
||||
@@ -31,4 +31,4 @@ sysroot_add_library(
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_compile_definitions(libc-malloc PRIVATE ENABLE_GLOBAL_HEAP=1)
|
||||
target_link_libraries(libc-malloc libc-core libmango)
|
||||
target_link_libraries(libc-malloc libc-core libmagenta)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "liballoc.h"
|
||||
|
||||
#include <heap/heap.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/log.h>
|
||||
#include <mango/status.h>
|
||||
#include <mango/task.h>
|
||||
#include <mango/vm.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/status.h>
|
||||
#include <magenta/task.h>
|
||||
#include <magenta/vm.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define HEAP_REGION_SIZE 0x40000000
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define HEAP_H_
|
||||
|
||||
#include <heap/_liballoc.h>
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum heap_result {
|
||||
|
||||
@@ -41,6 +41,6 @@ bsp_add_library(
|
||||
NAME libpthread
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_link_libraries(libc-pthread PRIVATE libc-io libmango)
|
||||
target_link_libraries(libpthread PRIVATE libmango)
|
||||
target_link_libraries(libc-pthread PRIVATE libc-io libmagenta)
|
||||
target_link_libraries(libpthread PRIVATE libmagenta)
|
||||
target_link_libraries(libpthread PUBLIC libc)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef PTHREAD_H_
|
||||
#define PTHREAD_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
|
||||
#define __PTHREAD_ATTR_SIZE__ 32
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.code64
|
||||
|
||||
#include "mango/syscall.h"
|
||||
#include "magenta/syscall.h"
|
||||
|
||||
.global __pthread_unmap_exit
|
||||
.type __pthread_unmap_exit, @function
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _THREAD_PTHREAD_H_
|
||||
#define _THREAD_PTHREAD_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
|
||||
enum pthread_flags {
|
||||
THREAD_DETACHED = 0x01u,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "pthread.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <mango/status.h>
|
||||
#include <mango/task.h>
|
||||
#include <magenta/status.h>
|
||||
#include <magenta/task.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "pthread.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/object.h>
|
||||
#include <mango/signal.h>
|
||||
#include <mango/task.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/object.h>
|
||||
#include <magenta/signal.h>
|
||||
#include <magenta/task.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "pthread.h"
|
||||
|
||||
#include <mango/handle.h>
|
||||
#include <mango/task.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/task.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "pthread.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/object.h>
|
||||
#include <mango/signal.h>
|
||||
#include <mango/task.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/object.h>
|
||||
#include <magenta/signal.h>
|
||||
#include <magenta/task.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "pthread.h"
|
||||
|
||||
#include <mango/task.h>
|
||||
#include <mango/types.h>
|
||||
#include <magenta/task.h>
|
||||
#include <magenta/types.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ bsp_add_library(
|
||||
NAME libfs
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_link_libraries(libfs libmango interface::fs libc libxpc)
|
||||
target_link_libraries(libfs-static libmango interface::fs libc-core libxpc-static)
|
||||
target_link_libraries(libfs libmagenta interface::fs libc libxpc)
|
||||
target_link_libraries(libfs-static libmagenta interface::fs libc-core libxpc-static)
|
||||
|
||||
set_target_properties(libfs-static PROPERTIES POSITION_INDEPENDENT_CODE FALSE)
|
||||
|
||||
+23
-8
@@ -9,12 +9,12 @@
|
||||
#include <fs/inode.h>
|
||||
#include <fs/status.h>
|
||||
#include <fs/superblock.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/log.h>
|
||||
#include <mango/object.h>
|
||||
#include <mango/signal.h>
|
||||
#include <mango/task.h>
|
||||
#include <mango/vm.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/object.h>
|
||||
#include <magenta/signal.h>
|
||||
#include <magenta/task.h>
|
||||
#include <magenta/vm.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define TEMP_OBJECT_SIZE 0x10000
|
||||
@@ -211,14 +211,29 @@ static enum fs_status handle_vm_request_detach(
|
||||
}
|
||||
|
||||
kern_tracef(
|
||||
"received vm request (detach) for file %s",
|
||||
mapping->m_file->f_dent->d_name);
|
||||
"received vm request (detach) for file %s (ref=%zu)",
|
||||
mapping->m_file->f_dent->d_name,
|
||||
mapping->m_ref);
|
||||
|
||||
if (mapping->m_ref > 1) {
|
||||
mapping->m_ref--;
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
struct fs_file *f = mapping->m_file;
|
||||
switch (mapping->m_type) {
|
||||
case FILE_MAPPING_PRIVATE:
|
||||
kern_tracef(
|
||||
"destroying private mapping of %s",
|
||||
f->f_dent->d_name);
|
||||
queue_delete(&f->f_mappings, &mapping->m_entry);
|
||||
break;
|
||||
case FILE_MAPPING_SHARED:
|
||||
kern_tracef(
|
||||
"destroying shared mapping of %s",
|
||||
f->f_dent->d_name);
|
||||
f->f_inode->i_shared_mapping = NULL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FS_FILE_H_
|
||||
#define FS_FILE_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct fs_file;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define FS_INODE_H_
|
||||
|
||||
#include <fs/status.h>
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct fs_inode;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _FS_INTERFACE_H_
|
||||
#define _FS_INTERFACE_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <xpc/buffer.h>
|
||||
#include <xpc/context.h>
|
||||
#include <xpc/endpoint.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "../interface.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <mango/status.h>
|
||||
#include <magenta/status.h>
|
||||
|
||||
extern kern_status_t fs_msg_close(
|
||||
xpc_context_t *ctx,
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
#include <fs/context.h>
|
||||
#include <fs/file.h>
|
||||
#include <fs/status.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/log.h>
|
||||
#include <mango/vm.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/vm.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
static int create_file_mapping(
|
||||
@@ -57,6 +58,7 @@ static int create_file_mapping(
|
||||
return __errno_from_kern_status(status);
|
||||
}
|
||||
|
||||
mapping->m_ref = 1;
|
||||
mapping->m_file = f;
|
||||
mapping->m_vmo = vmo;
|
||||
|
||||
@@ -102,14 +104,19 @@ extern kern_status_t fs_msg_map(
|
||||
(flags & MAP_SHARED) ? "shared" : "private",
|
||||
mapping->m_vmo);
|
||||
|
||||
kern_handle_t vmo;
|
||||
kern_handle_transfer(
|
||||
kern_handle_t vmo = KERN_HANDLE_INVALID;
|
||||
kern_status_t status = kern_handle_transfer(
|
||||
KERN_HANDLE_INVALID,
|
||||
mapping->m_vmo,
|
||||
KERN_HANDLE_INVALID,
|
||||
KERN_HANDLE_INVALID,
|
||||
HANDLE_TRANSFER_COPY,
|
||||
&vmo);
|
||||
if (status != KERN_OK) {
|
||||
kern_tracef("kern_handle_transfer failed %d", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
f->f_ref++;
|
||||
|
||||
*out_err = SUCCESS;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <fs/context.h>
|
||||
#include <fs/file.h>
|
||||
#include <fs/status.h>
|
||||
#include <mango/log.h>
|
||||
#include <magenta/log.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern kern_status_t fs_msg_open(
|
||||
|
||||
+5
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
|
||||
struct fs_file;
|
||||
|
||||
@@ -14,6 +14,10 @@ enum file_mapping_type {
|
||||
|
||||
struct file_mapping {
|
||||
enum file_mapping_type m_type;
|
||||
|
||||
/* for shared mappings */
|
||||
size_t m_ref;
|
||||
|
||||
struct fs_file *m_file;
|
||||
kern_handle_t m_vmo;
|
||||
struct queue_entry m_entry;
|
||||
|
||||
+1
-1
Submodule lib/libfx updated: cb39baa233...8c0a31e19b
@@ -21,5 +21,5 @@ bsp_add_library(
|
||||
NAME liblaunch
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_link_libraries(liblaunch-static PRIVATE librosetta libmango libc-core)
|
||||
target_link_libraries(liblaunch PRIVATE librosetta libmango libc)
|
||||
target_link_libraries(liblaunch-static PRIVATE librosetta libmagenta libc-core)
|
||||
target_link_libraries(liblaunch PRIVATE librosetta libmagenta libc)
|
||||
|
||||
+6
-5
@@ -1,9 +1,9 @@
|
||||
#include "elf.h"
|
||||
|
||||
#include <mango/config.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/log.h>
|
||||
#include <mango/vm.h>
|
||||
#include <magenta/config.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/vm.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -174,7 +174,7 @@ static kern_status_t create_exec_regions(struct elf_image *image)
|
||||
if (image->e_remote_space != KERN_HANDLE_INVALID) {
|
||||
status = address_space_reserve(
|
||||
image->e_remote_space,
|
||||
MAP_ADDRESS_ANY,
|
||||
0xF0000000,
|
||||
image->e_total_size,
|
||||
&image->e_remote_base);
|
||||
}
|
||||
@@ -188,6 +188,7 @@ static kern_status_t create_exec_regions(struct elf_image *image)
|
||||
return status;
|
||||
}
|
||||
|
||||
kern_tracef("launch: image base=%zx", image->e_remote_base);
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#define USERBOOT_ELF_H_
|
||||
|
||||
#include <launch.h>
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define ELF_LOAD_ERR -1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef LAUNCH_H_
|
||||
#define LAUNCH_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
|
||||
enum launch_status {
|
||||
LAUNCH_OK,
|
||||
@@ -25,7 +25,8 @@ enum launch_status {
|
||||
};
|
||||
|
||||
enum launch_flags {
|
||||
LAUNCH_F_NONE = 0,
|
||||
LAUNCH_F_NONE = 0x00,
|
||||
LAUNCH_F_CLONE_ALL_HANDLES = 0x01u,
|
||||
};
|
||||
|
||||
struct launch_ctx;
|
||||
|
||||
+11
-4
@@ -2,10 +2,10 @@
|
||||
#include "stack.h"
|
||||
|
||||
#include <launch.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/log.h>
|
||||
#include <mango/task.h>
|
||||
#include <mango/vm.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/task.h>
|
||||
#include <magenta/vm.h>
|
||||
#include <rosetta/bootstrap.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -123,8 +123,15 @@ enum launch_status launch_ctx_execute(
|
||||
size_t name_len = params->p_task_name ? strlen(params->p_task_name) : 0;
|
||||
kern_handle_t remote_task = KERN_HANDLE_INVALID,
|
||||
remote_address_space = KERN_HANDLE_INVALID;
|
||||
task_flags_t task_flags = TASK_F_DEFAULT;
|
||||
|
||||
if (flags & LAUNCH_F_CLONE_ALL_HANDLES) {
|
||||
task_flags |= TASK_F_CLONE_ALL_HANDLES;
|
||||
}
|
||||
|
||||
kstatus = task_create(
|
||||
params->p_parent_task,
|
||||
task_flags,
|
||||
params->p_task_name,
|
||||
name_len,
|
||||
&remote_task,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "stack.h"
|
||||
|
||||
#include <mango/log.h>
|
||||
#include <magenta/log.h>
|
||||
#include <string.h>
|
||||
|
||||
void stack_writer_init(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef LIBLAUNCH_STACK_H_
|
||||
#define LIBLAUNCH_STACK_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
|
||||
struct stack_writer {
|
||||
virt_addr_t w_local_sp;
|
||||
|
||||
@@ -12,4 +12,4 @@ sysroot_add_library(
|
||||
HEADER_DIR /usr/include
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_link_libraries(librosetta PRIVATE libmango)
|
||||
target_link_libraries(librosetta PRIVATE libmagenta)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef ROSETTA_BOOTSTRAP_H_
|
||||
#define ROSETTA_BOOTSTRAP_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
|
||||
enum rosetta_bootstrap_handle_type {
|
||||
RSBS_HANDLE_NONE = 0,
|
||||
|
||||
@@ -22,7 +22,7 @@ sysroot_add_library(
|
||||
HEADER_DIR /usr/include
|
||||
LIB_DIR /usr/lib)
|
||||
|
||||
target_link_libraries(libxpc libmango libc)
|
||||
target_link_libraries(libxpc-static libmango libc-core)
|
||||
target_link_libraries(libxpc libmagenta libc)
|
||||
target_link_libraries(libxpc-static libmagenta libc-core)
|
||||
|
||||
#set_target_properties(libxpc-static PROPERTIES POSITION_INDEPENDENT_CODE FALSE)
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include <mango/status.h>
|
||||
#include <magenta/status.h>
|
||||
#include <string.h>
|
||||
#include <xpc/buffer.h>
|
||||
#include <xpc/msg.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef XPC_BUFFER_H_
|
||||
#define XPC_BUFFER_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stddef.h>
|
||||
#include <xpc/status.h>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef XPC_ENDPOINT_H_
|
||||
#define XPC_ENDPOINT_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
|
||||
typedef struct xpc_endpoint {
|
||||
kern_handle_t e_channel;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef XPC_MSG_H_
|
||||
#define XPC_MSG_H_
|
||||
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <xpc/endpoint.h>
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
#include <mango/msg.h>
|
||||
#include <mango/object.h>
|
||||
#include <mango/signal.h>
|
||||
#include <magenta/msg.h>
|
||||
#include <magenta/object.h>
|
||||
#include <magenta/signal.h>
|
||||
#include <string.h>
|
||||
#include <xpc/msg.h>
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include <mango/status.h>
|
||||
#include <magenta/status.h>
|
||||
#include <xpc/msg.h>
|
||||
#include <xpc/string.h>
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("devmd running %s\n", strerror(EDEADLK));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ file(GLOB sources *.c)
|
||||
add_executable(herdd ${sources})
|
||||
target_link_libraries(herdd
|
||||
libc libc-runtime
|
||||
libmango libpthread liblaunch librosetta
|
||||
fx-core fx-ds fx-serial)
|
||||
libmagenta libpthread liblaunch librosetta
|
||||
fx.runtime fx.collections fx.serial)
|
||||
|
||||
sysroot_add_program(
|
||||
NAME herdd
|
||||
|
||||
+10
-12
@@ -2,13 +2,14 @@
|
||||
#include "queue.h"
|
||||
#include "runlevel.h"
|
||||
#include "service.h"
|
||||
#include "spawn.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <mango/log.h>
|
||||
#include <mango/task.h>
|
||||
#include <fx/string.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/task.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -111,19 +112,15 @@ int main(int argc, const char *argv[], const char *envp[])
|
||||
}
|
||||
|
||||
runlevel_activate(rl);
|
||||
#if 1
|
||||
pid_t child = fork();
|
||||
kern_logf(" fork returned %d", child);
|
||||
|
||||
kern_handle_t new_task = 123, new_space = 456;
|
||||
kern_status_t status = task_duplicate(&new_task, &new_space);
|
||||
kern_logf(
|
||||
" task_duplicate returned %d (%x/%x)",
|
||||
status,
|
||||
new_task,
|
||||
new_space);
|
||||
|
||||
if (new_task == KERN_HANDLE_INVALID) {
|
||||
if (child == 0) {
|
||||
kern_log("this is the child");
|
||||
long r = printf("hello\n");
|
||||
kern_logf("printf returned %ld (%d)", r, (errno));
|
||||
execlp(NULL, NULL);
|
||||
} else {
|
||||
kern_log("this is the parent");
|
||||
long r = printf("goodbye\n");
|
||||
@@ -131,5 +128,6 @@ int main(int argc, const char *argv[], const char *envp[])
|
||||
}
|
||||
|
||||
kern_logf("exiting (%s)", strerror(EFTYPE));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
+43
-22
@@ -4,11 +4,12 @@
|
||||
#include "service.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/array.h>
|
||||
#include <fx/ds/dict.h>
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/collections/hashtable.h>
|
||||
#include <fx/serial.h>
|
||||
#include <mango/log.h>
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <magenta/log.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -22,36 +23,48 @@ struct queue *global_runlevels(void)
|
||||
|
||||
static int parse_runlevel_data(fx_object *in, struct runlevel *out)
|
||||
{
|
||||
if (!fx_object_is_type(in, FX_TYPE_DICT)) {
|
||||
if (!fx_object_is_type(in, FX_TYPE_HASHTABLE)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fx_dict *in_runlevel = fx_dict_at(in, "runlevel");
|
||||
if (!in_runlevel || !fx_object_is_type(in_runlevel, FX_TYPE_DICT)) {
|
||||
const fx_value *runlevel_v = fx_hashtable_get(in, &FX_CSTR("runlevel"));
|
||||
if (!runlevel_v || !fx_value_is_type(runlevel_v, FX_TYPE_HASHTABLE)) {
|
||||
return -1;
|
||||
}
|
||||
fx_hashtable *in_runlevel = NULL;
|
||||
fx_value_get_object(runlevel_v, &in_runlevel);
|
||||
|
||||
fx_string *name = fx_dict_at(in_runlevel, "name");
|
||||
if (!name || !fx_object_is_type(name, FX_TYPE_STRING)) {
|
||||
const fx_value *name_v
|
||||
= fx_hashtable_get(in_runlevel, &FX_CSTR("name"));
|
||||
if (!name_v || !fx_value_is_type(name_v, FX_TYPE_STRING)) {
|
||||
return -1;
|
||||
}
|
||||
fx_string *name = NULL;
|
||||
fx_value_get_object(name_v, &name);
|
||||
|
||||
fx_string *description = fx_dict_at(in_runlevel, "description");
|
||||
if (!description || !fx_object_is_type(description, FX_TYPE_STRING)) {
|
||||
const fx_value *description_v
|
||||
= fx_hashtable_get(in_runlevel, &FX_CSTR("description"));
|
||||
if (!description_v
|
||||
|| !fx_value_is_type(description_v, FX_TYPE_STRING)) {
|
||||
return -1;
|
||||
}
|
||||
fx_string *description = NULL;
|
||||
fx_value_get_object(description_v, &description);
|
||||
|
||||
fx_array *deps = fx_dict_at(in_runlevel, "requires");
|
||||
if (deps && !fx_object_is_type(deps, FX_TYPE_ARRAY)) {
|
||||
const fx_value *deps_v
|
||||
= fx_hashtable_get(in_runlevel, &FX_CSTR("requires"));
|
||||
if (deps_v && !fx_value_is_type(deps_v, FX_TYPE_ARRAY)) {
|
||||
return -1;
|
||||
}
|
||||
fx_array *deps = NULL;
|
||||
fx_value_get_object(deps_v, &deps);
|
||||
|
||||
int ret = 0;
|
||||
size_t dep_count = fx_array_size(deps);
|
||||
fx_iterator *it = fx_iterator_begin(deps);
|
||||
fx_foreach_ptr(fx_string, dep, it)
|
||||
size_t dep_count = fx_array_get_size(deps);
|
||||
const fx_iterator *it = fx_iterator_begin(deps);
|
||||
fx_foreach(dep, it)
|
||||
{
|
||||
if (!fx_object_is_type(dep, FX_TYPE_STRING)) {
|
||||
if (!fx_value_is_type(dep, FX_TYPE_STRING)) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
@@ -66,9 +79,11 @@ static int parse_runlevel_data(fx_object *in, struct runlevel *out)
|
||||
out->rl_requires = calloc(dep_count, sizeof(char *));
|
||||
it = fx_iterator_begin(deps);
|
||||
size_t i = 0;
|
||||
fx_foreach_ptr(fx_string, dep, it)
|
||||
fx_foreach(dep, it)
|
||||
{
|
||||
out->rl_requires[i++] = fx_string_steal(dep);
|
||||
fx_string *str = NULL;
|
||||
fx_value_get_object(dep, &str);
|
||||
out->rl_requires[i++] = fx_string_steal(str);
|
||||
}
|
||||
fx_iterator_unref(it);
|
||||
|
||||
@@ -94,7 +109,7 @@ int runlevel_load(const char *path, struct runlevel **out)
|
||||
|
||||
fx_stream *in = fx_stream_open_fp(fp);
|
||||
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
|
||||
fx_object *data;
|
||||
fx_value data;
|
||||
fx_result result = fx_serial_ctx_deserialise(ctx, in, &data, 0);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
@@ -103,14 +118,20 @@ int runlevel_load(const char *path, struct runlevel **out)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (parse_runlevel_data(data, rl) != 0) {
|
||||
if (!fx_value_is_type(&data, FX_TYPE_HASHTABLE)) {
|
||||
free(rl);
|
||||
errno = EFTYPE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (parse_runlevel_data(data.v_object, rl) != 0) {
|
||||
free(rl);
|
||||
errno = EFTYPE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fx_stream_unref(in);
|
||||
fx_object_unref(data);
|
||||
fx_value_unset(&data);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
|
||||
+67
-26
@@ -3,13 +3,15 @@
|
||||
#include "log.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/array.h>
|
||||
#include <fx/ds/dict.h>
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/collections/hashtable.h>
|
||||
#include <fx/serial.h>
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <launch.h>
|
||||
#include <mango/log.h>
|
||||
#include <magenta/log.h>
|
||||
#include <rosetta/bootstrap.h>
|
||||
#include <spawn.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -23,45 +25,60 @@ struct queue *global_services(void)
|
||||
|
||||
static int parse_service_data(fx_object *in, struct service *out)
|
||||
{
|
||||
if (!fx_object_is_type(in, FX_TYPE_DICT)) {
|
||||
if (!fx_object_is_type(in, FX_TYPE_HASHTABLE)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fx_dict *in_service = fx_dict_at(in, "service");
|
||||
if (!in_service || !fx_object_is_type(in_service, FX_TYPE_DICT)) {
|
||||
const fx_value *service_v = fx_hashtable_get(in, &FX_CSTR("service"));
|
||||
if (!service_v || !fx_value_is_type(service_v, FX_TYPE_HASHTABLE)) {
|
||||
return -1;
|
||||
}
|
||||
fx_hashtable *in_service = NULL;
|
||||
fx_value_get_object(service_v, &in_service);
|
||||
|
||||
fx_dict *in_unit = fx_dict_at(in, "unit");
|
||||
if (!in_unit || !fx_object_is_type(in_unit, FX_TYPE_DICT)) {
|
||||
const fx_value *unit_v = fx_hashtable_get(in, &FX_CSTR("unit"));
|
||||
if (!unit_v || !fx_value_is_type(unit_v, FX_TYPE_HASHTABLE)) {
|
||||
return -1;
|
||||
}
|
||||
fx_hashtable *in_unit = NULL;
|
||||
fx_value_get_object(unit_v, &in_unit);
|
||||
|
||||
fx_string *name = fx_dict_at(in_unit, "name");
|
||||
if (!name || !fx_object_is_type(name, FX_TYPE_STRING)) {
|
||||
const fx_value *name_v = fx_hashtable_get(in_unit, &FX_CSTR("name"));
|
||||
if (!name_v || !fx_value_is_type(name_v, FX_TYPE_STRING)) {
|
||||
return -1;
|
||||
}
|
||||
fx_string *name = NULL;
|
||||
fx_value_get_object(name_v, &name);
|
||||
|
||||
fx_string *description = fx_dict_at(in_unit, "description");
|
||||
if (!description || !fx_object_is_type(description, FX_TYPE_STRING)) {
|
||||
const fx_value *description_v
|
||||
= fx_hashtable_get(in_unit, &FX_CSTR("description"));
|
||||
if (!description_v
|
||||
|| !fx_value_is_type(description_v, FX_TYPE_STRING)) {
|
||||
return -1;
|
||||
}
|
||||
fx_string *description = NULL;
|
||||
fx_value_get_object(description_v, &description);
|
||||
|
||||
fx_string *exec = fx_dict_at(in_service, "exec");
|
||||
if (!description || !fx_object_is_type(description, FX_TYPE_STRING)) {
|
||||
const fx_value *exec_v = fx_hashtable_get(in_service, &FX_CSTR("exec"));
|
||||
if (!exec_v || !fx_value_is_type(exec_v, FX_TYPE_STRING)) {
|
||||
return -1;
|
||||
}
|
||||
fx_string *exec = NULL;
|
||||
fx_value_get_object(exec_v, &exec);
|
||||
|
||||
fx_array *roles = fx_dict_at(in_service, "roles");
|
||||
if (roles && !fx_object_is_type(roles, FX_TYPE_ARRAY)) {
|
||||
const fx_value *roles_v
|
||||
= fx_hashtable_get(in_service, &FX_CSTR("roles"));
|
||||
if (roles_v && !fx_value_is_type(roles_v, FX_TYPE_ARRAY)) {
|
||||
return -1;
|
||||
}
|
||||
fx_array *roles = NULL;
|
||||
fx_value_get_object(roles_v, &roles);
|
||||
|
||||
int ret = 0;
|
||||
fx_iterator *it = fx_iterator_begin(roles);
|
||||
fx_foreach_ptr(fx_string, role, it)
|
||||
const fx_iterator *it = fx_iterator_begin(roles);
|
||||
fx_foreach(v, it)
|
||||
{
|
||||
if (!fx_object_is_type(role, FX_TYPE_STRING)) {
|
||||
if (!fx_value_is_type(v, FX_TYPE_STRING)) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
@@ -74,9 +91,10 @@ static int parse_service_data(fx_object *in, struct service *out)
|
||||
|
||||
it = fx_iterator_begin(roles);
|
||||
size_t i = 0;
|
||||
fx_foreach_ptr(fx_string, role, it)
|
||||
fx_foreach(role, it)
|
||||
{
|
||||
const char *role_cstr = fx_string_get_cstr(role);
|
||||
const char *role_cstr = NULL;
|
||||
fx_value_get_cstr(role, &role_cstr);
|
||||
if (!strcmp(role_cstr, "NamespaceProvider")) {
|
||||
out->s_roles |= SVC_ROLE_NAMESPACE_PROVIDER;
|
||||
}
|
||||
@@ -106,7 +124,7 @@ int service_load(const char *path, struct service **out)
|
||||
|
||||
fx_stream *in = fx_stream_open_fp(fp);
|
||||
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
|
||||
fx_object *data;
|
||||
fx_value data;
|
||||
fx_result result = fx_serial_ctx_deserialise(ctx, in, &data, 0);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
@@ -115,14 +133,21 @@ int service_load(const char *path, struct service **out)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (parse_service_data(data, rl) != 0) {
|
||||
if (!fx_value_is_type(&data, FX_TYPE_HASHTABLE)) {
|
||||
fx_value_unset(&data);
|
||||
free(rl);
|
||||
errno = EFTYPE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (parse_service_data(data.v_object, rl) != 0) {
|
||||
free(rl);
|
||||
errno = EFTYPE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fx_stream_unref(in);
|
||||
fx_object_unref(data);
|
||||
fx_value_unset(&data);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
@@ -150,6 +175,22 @@ int service_start(struct service *svc)
|
||||
{
|
||||
log("Starting %s...", svc->s_description);
|
||||
|
||||
pid_t child = 0;
|
||||
char *const argv[] = {
|
||||
svc->s_name,
|
||||
NULL,
|
||||
};
|
||||
|
||||
int err = posix_spawn(&child, svc->s_exec, NULL, NULL, argv, NULL);
|
||||
|
||||
if (err == 0) {
|
||||
log_ok("Started %s.", svc->s_description);
|
||||
return 0;
|
||||
} else {
|
||||
log_fail(
|
||||
"Failed to start %s (%s)",
|
||||
svc->s_description,
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SERVICE_H_
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
enum service_role {
|
||||
SVC_ROLE_NONE = 0x00u,
|
||||
SVC_ROLE_NAMESPACE_PROVIDER = 0x01u,
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
#include <errno.h>
|
||||
#include <magenta/log.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("nsd running %s\n", strerror(ENOTSUP));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ file(GLOB arch_sources arch/${CMAKE_SYSTEM_PROCESSOR}/*.S)
|
||||
add_executable(bootstrap ${c_sources} ${arch_sources})
|
||||
|
||||
target_link_libraries(bootstrap
|
||||
libmango librosetta
|
||||
libmagenta librosetta
|
||||
libc-core libc-malloc libc-pthread
|
||||
libfs-static
|
||||
liblaunch-static
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#include <fs/file.h>
|
||||
#include <heap/heap.h>
|
||||
#include <launch.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/log.h>
|
||||
#include <mango/msg.h>
|
||||
#include <mango/object.h>
|
||||
#include <mango/task.h>
|
||||
#include <mango/types.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/msg.h>
|
||||
#include <magenta/object.h>
|
||||
#include <magenta/task.h>
|
||||
#include <magenta/types.h>
|
||||
#include <pthread.h>
|
||||
#include <rosetta/bootstrap.h>
|
||||
#include <rosetta/fs.h>
|
||||
|
||||
+3
-3
@@ -6,9 +6,9 @@
|
||||
#include <fs/file.h>
|
||||
#include <fs/inode.h>
|
||||
#include <fs/superblock.h>
|
||||
#include <mango/handle.h>
|
||||
#include <mango/log.h>
|
||||
#include <mango/vm.h>
|
||||
#include <magenta/handle.h>
|
||||
#include <magenta/log.h>
|
||||
#include <magenta/vm.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <fs/context.h>
|
||||
#include <fs/status.h>
|
||||
#include <mango/types.h>
|
||||
#include <magenta/types.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@@ -8,12 +8,16 @@ set_target_properties(ld PROPERTIES
|
||||
SUFFIX ".so")
|
||||
|
||||
target_link_libraries(ld
|
||||
libc-core libc-malloc libc-io libmango librosetta libxpc-static
|
||||
libc-core libc-malloc libc-io libmagenta librosetta libxpc-static
|
||||
interface::fs)
|
||||
|
||||
target_compile_options(ld PRIVATE
|
||||
-fvisibility=hidden
|
||||
-fPIC -fno-stack-protector -nostdlib -ffreestanding)
|
||||
target_link_options(ld PRIVATE
|
||||
-fvisibility=hidden -Wl,--exclude-libs,ALL
|
||||
# -Wl,--entry="_ld_start"
|
||||
-T ${CMAKE_CURRENT_SOURCE_DIR}/arch/${CMAKE_SYSTEM_PROCESSOR}/layout.ld
|
||||
-fPIC -nostdlib -ffreestanding -Wl,-shared)
|
||||
|
||||
sysroot_add_program(
|
||||
|
||||
+249
-23
@@ -1,30 +1,256 @@
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS {
|
||||
.text ALIGN(4K) : {
|
||||
*(.text)
|
||||
*(.rodata)
|
||||
/* Copyright (C) 2014-2025 Free Software Foundation, Inc.
|
||||
Copying and distribution of this script, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved. */
|
||||
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
|
||||
OUTPUT_ARCH(i386:x86-64)
|
||||
ENTRY(_ld_start)
|
||||
SECTIONS
|
||||
{
|
||||
/* Read-only sections, merged into text segment: */
|
||||
PROVIDE(_ld_image_base = . + 1024);
|
||||
. = SEGMENT_START("text-segment", 0) + SIZEOF_HEADERS;
|
||||
/* Place the build-id as close to the ELF headers as possible. This
|
||||
maximises the chance the build-id will be present in core files,
|
||||
which GDB can then use to locate the associated debuginfo file. */
|
||||
.note.gnu.build-id : { *(.note.gnu.build-id) }
|
||||
.hash : { *(.hash) }
|
||||
.gnu.hash : { *(.gnu.hash) }
|
||||
.dynsym : { *(.dynsym) }
|
||||
.dynstr : { *(.dynstr) }
|
||||
.gnu.version : { *(.gnu.version) }
|
||||
.gnu.version_d : { *(.gnu.version_d) }
|
||||
.gnu.version_r : { *(.gnu.version_r) }
|
||||
.rela.dyn :
|
||||
{
|
||||
*(.rela.init)
|
||||
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
|
||||
*(.rela.fini)
|
||||
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
|
||||
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
|
||||
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
|
||||
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
|
||||
*(.rela.ctors)
|
||||
*(.rela.dtors)
|
||||
*(.rela.got)
|
||||
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
|
||||
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
|
||||
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
|
||||
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
|
||||
*(.rela.ifunc)
|
||||
}
|
||||
|
||||
.rodata ALIGN(4K) : {
|
||||
|
||||
.rela.plt :
|
||||
{
|
||||
*(.rela.plt)
|
||||
*(.rela.iplt)
|
||||
}
|
||||
|
||||
.data ALIGN(4K) : {
|
||||
*(.data)
|
||||
*(.bss)
|
||||
*(.dynamic)
|
||||
.relr.dyn : { *(.relr.dyn) }
|
||||
/* Start of the executable code region. */
|
||||
.init :
|
||||
{
|
||||
KEEP (*(SORT_NONE(.init)))
|
||||
}
|
||||
|
||||
.dynamic ALIGN(8) : {
|
||||
*(.dynamic)
|
||||
.plt : { *(.plt) *(.iplt) }
|
||||
.plt.got : { *(.plt.got) }
|
||||
.plt.sec : { *(.plt.sec) }
|
||||
.text :
|
||||
{
|
||||
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
|
||||
*(.text.exit .text.exit.*)
|
||||
*(.text.startup .text.startup.*)
|
||||
*(.text.hot .text.hot.*)
|
||||
*(SORT(.text.sorted.*))
|
||||
*(.text .stub .text.* .gnu.linkonce.t.*)
|
||||
/* .gnu.warning sections are handled specially by elf.em. */
|
||||
*(.gnu.warning)
|
||||
}
|
||||
|
||||
.got.plt ALIGN(4K) : {
|
||||
*(.got.plt)
|
||||
.fini :
|
||||
{
|
||||
KEEP (*(SORT_NONE(.fini)))
|
||||
}
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.interp)
|
||||
PROVIDE (__etext = .);
|
||||
PROVIDE (_etext = .);
|
||||
PROVIDE (etext = .);
|
||||
/* Start of the Read Only Data region. */
|
||||
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
|
||||
.rodata1 : { *(.rodata1) }
|
||||
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
|
||||
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
|
||||
.sframe : ONLY_IF_RO { *(.sframe) *(.sframe.*) }
|
||||
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
|
||||
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
|
||||
/* These sections are generated by the Sun/Oracle C++ compiler. */
|
||||
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
|
||||
/* Various note sections. Placed here so that they are always included
|
||||
in the read-only segment and not treated as orphan sections. The
|
||||
current orphan handling algorithm does place note sections after R/O
|
||||
data, but this is not guaranteed to always be the case. */
|
||||
.note.build-id : { *(.note.build-id) }
|
||||
.note.GNU-stack : { *(.note.GNU-stack) }
|
||||
.note.gnu-property : { *(.note.gnu-property) }
|
||||
.note.ABI-tag : { *(.note.ABI-tag) }
|
||||
.note.package : { *(.note.package) }
|
||||
.note.dlopen : { *(.note.dlopen) }
|
||||
.note.netbsd.ident : { *(.note.netbsd.ident) }
|
||||
.note.openbsd.ident : { *(.note.openbsd.ident) }
|
||||
/* Start of the Read Write Data region. */
|
||||
/* Adjust the address for the data segment. We want to adjust up to
|
||||
the same address within the page on the next page up. */
|
||||
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
|
||||
/* Exception handling. */
|
||||
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
|
||||
.sframe : ONLY_IF_RW { *(.sframe) *(.sframe.*) }
|
||||
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
|
||||
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
|
||||
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
|
||||
/* Thread Local Storage sections. */
|
||||
.tdata :
|
||||
{
|
||||
*(.tdata .tdata.* .gnu.linkonce.td.*)
|
||||
}
|
||||
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
|
||||
.preinit_array :
|
||||
{
|
||||
KEEP (*(.preinit_array))
|
||||
}
|
||||
.init_array :
|
||||
{
|
||||
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
|
||||
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
|
||||
}
|
||||
.fini_array :
|
||||
{
|
||||
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
|
||||
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
|
||||
}
|
||||
.ctors :
|
||||
{
|
||||
/* gcc uses crtbegin.o to find the start of
|
||||
the constructors, so we make sure it is
|
||||
first. Because this is a wildcard, it
|
||||
doesn't matter if the user does not
|
||||
actually link against crtbegin.o; the
|
||||
linker won't look for a file to match a
|
||||
wildcard. The wildcard also means that it
|
||||
doesn't matter which directory crtbegin.o
|
||||
is in. */
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*crtbegin?.o(.ctors))
|
||||
/* We don't want to include the .ctor section from
|
||||
the crtend.o file until after the sorted ctors.
|
||||
The .ctor section from the crtend file contains the
|
||||
end of ctors marker and it must be last */
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
}
|
||||
.dtors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*crtbegin?.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
}
|
||||
.jcr : { KEEP (*(.jcr)) }
|
||||
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
|
||||
.dynamic : { *(.dynamic) }
|
||||
.got : { *(.got) *(.igot) }
|
||||
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
|
||||
.got.plt : { *(.got.plt) *(.igot.plt) }
|
||||
.data :
|
||||
{
|
||||
*(.data .data.* .gnu.linkonce.d.*)
|
||||
SORT(CONSTRUCTORS)
|
||||
}
|
||||
.data1 : { *(.data1) }
|
||||
PROVIDE (_edata = .);
|
||||
PROVIDE (edata = .);
|
||||
. = ALIGN(ALIGNOF(NEXT_SECTION));
|
||||
PROVIDE (__bss_start = .);
|
||||
.bss :
|
||||
{
|
||||
*(.dynbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
/* Align here to ensure that in the common case of there only being one
|
||||
type of .bss section, the section occupies space up to _end.
|
||||
Align after .bss to ensure correct alignment even if the
|
||||
.bss section disappears because there are no input sections.
|
||||
FIXME: Why do we need it? When there is no .bss section, we do not
|
||||
pad the .data section. */
|
||||
. = ALIGN(. != 0 ? 64 / 8 : 1);
|
||||
}
|
||||
.lbss :
|
||||
{
|
||||
*(.dynlbss)
|
||||
*(.lbss .lbss.* .gnu.linkonce.lb.*)
|
||||
*(LARGE_COMMON)
|
||||
}
|
||||
. = ALIGN(64 / 8);
|
||||
/* Start of the Large Data region. */
|
||||
. = SEGMENT_START("ldata-segment", .);
|
||||
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
|
||||
{
|
||||
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
|
||||
}
|
||||
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
|
||||
{
|
||||
*(.ldata .ldata.* .gnu.linkonce.l.*)
|
||||
. = ALIGN(. != 0 ? 64 / 8 : 1);
|
||||
}
|
||||
. = ALIGN(64 / 8);
|
||||
PROVIDE (_end = .);
|
||||
PROVIDE (end = .);
|
||||
PROVIDE(_ld_image_limit = .);
|
||||
. = DATA_SEGMENT_END (.);
|
||||
/* Start of the Tiny Data region. */
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
.comment 0 (INFO) : { *(.comment); LINKER_VERSION; }
|
||||
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
|
||||
/* DWARF debug sections.
|
||||
Symbols in the DWARF debugging sections are relative to the beginning
|
||||
of the section so we begin them at 0. */
|
||||
/* DWARF 1. */
|
||||
.debug 0 : { *(.debug) }
|
||||
.line 0 : { *(.line) }
|
||||
/* GNU DWARF 1 extensions. */
|
||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||
/* DWARF 1.1 and DWARF 2. */
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
/* DWARF 2. */
|
||||
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
/* SGI/MIPS DWARF 2 extensions. */
|
||||
.debug_weaknames 0 : { *(.debug_weaknames) }
|
||||
.debug_funcnames 0 : { *(.debug_funcnames) }
|
||||
.debug_typenames 0 : { *(.debug_typenames) }
|
||||
.debug_varnames 0 : { *(.debug_varnames) }
|
||||
/* DWARF 3. */
|
||||
.debug_pubtypes 0 : { *(.debug_pubtypes) }
|
||||
.debug_ranges 0 : { *(.debug_ranges) }
|
||||
/* DWARF 5. */
|
||||
.debug_addr 0 : { *(.debug_addr) }
|
||||
.debug_line_str 0 : { *(.debug_line_str) }
|
||||
.debug_loclists 0 : { *(.debug_loclists) }
|
||||
.debug_macro 0 : { *(.debug_macro) }
|
||||
.debug_names 0 : { *(.debug_names) }
|
||||
.debug_rnglists 0 : { *(.debug_rnglists) }
|
||||
.debug_str_offsets 0 : { *(.debug_str_offsets) }
|
||||
.debug_sup 0 : { *(.debug_sup) }
|
||||
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
|
||||
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.code64
|
||||
|
||||
.global _start
|
||||
.type _start, @function
|
||||
.global _ld_start
|
||||
.type _ld_start, @function
|
||||
|
||||
.extern main
|
||||
.type main, @function
|
||||
@@ -9,7 +9,10 @@
|
||||
.extern task_exit
|
||||
.type task_exit, @function
|
||||
|
||||
_start:
|
||||
_ld_start:
|
||||
nop
|
||||
mov $0xFFFFFFFF, %rbp
|
||||
|
||||
call main
|
||||
mov %rax, %rdi
|
||||
call task_exit
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user