-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This changes a bunch of things that allows building with the musl C lib, provided that `libucontext-dev` and `pkg-config` are installed. Note that installing libucontext makes absolutely zero sense on C libs that do natively provide this deprecated System V API, such as glibc. Hence, it no sane glibc setup is expected to ever have libucontext installed. A main pain point was that argv and argc are expected to be passed to init_fini handlers, but that is actually a glibc extension. This just parses `/proc/self/cmdline` by hand to populate argv and argc during startup, unless running on glibc.
- Loading branch information
Showing
6 changed files
with
103 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,16 @@ | |
* @author Ludwig Knüpfer <[email protected]> | ||
*/ | ||
|
||
/* __USE_GNU for gregs[REG_EIP] access under glibc | ||
* _GNU_SOURCE for REG_EIP and strsignal() under musl */ | ||
#define __USE_GNU | ||
#define _GNU_SOURCE | ||
|
||
#include <err.h> | ||
#include <signal.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
|
||
#ifdef HAVE_VALGRIND_H | ||
#include <valgrind.h> | ||
|
@@ -29,16 +35,12 @@ | |
#define VALGRIND_DEBUG(...) | ||
#endif | ||
|
||
/* __USE_GNU for gregs[REG_EIP] access under Linux */ | ||
#define __USE_GNU | ||
#include <signal.h> | ||
#undef __USE_GNU | ||
|
||
#include "irq.h" | ||
#include "cpu.h" | ||
#include "periph/pm.h" | ||
|
||
#include "native_internal.h" | ||
#include "test_utils/expect.h" | ||
|
||
#define ENABLE_DEBUG 0 | ||
#include "debug.h" | ||
|
@@ -50,6 +52,7 @@ volatile int _native_in_syscall; | |
static sigset_t _native_sig_set, _native_sig_set_dint; | ||
|
||
char __isr_stack[THREAD_STACKSIZE_DEFAULT]; | ||
const size_t __isr_stack_size = sizeof(__isr_stack); | ||
ucontext_t native_isr_context; | ||
ucontext_t *_native_cur_ctx, *_native_isr_ctx; | ||
|
||
|
@@ -58,7 +61,6 @@ volatile int _native_sigpend; | |
int _sig_pipefd[2]; | ||
|
||
static _native_callback_t native_irq_handlers[255]; | ||
char sigalt_stk[SIGSTKSZ]; | ||
|
||
void *thread_isr_stack_pointer(void) | ||
{ | ||
|
@@ -523,8 +525,9 @@ void native_interrupt_init(void) | |
_native_isr_ctx = &native_isr_context; | ||
|
||
static stack_t sigstk; | ||
sigstk.ss_sp = sigalt_stk; | ||
sigstk.ss_size = sizeof(sigalt_stk); | ||
sigstk.ss_sp = malloc(SIGSTKSZ); | ||
expect(sigstk.ss_sp != NULL); | ||
sigstk.ss_size = SIGSTKSZ; | ||
sigstk.ss_flags = 0; | ||
|
||
if (sigaltstack(&sigstk, NULL) < 0) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,16 +21,22 @@ | |
* @author Kaspar Schleiser <[email protected]> | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
|
||
/* __USE_GNU for gregs[REG_EIP] access under glibc | ||
* _GNU_SOURCE for REG_EIP and strsignal() under musl */ | ||
#define __USE_GNU | ||
#define _GNU_SOURCE | ||
|
||
#include <err.h> | ||
#include <signal.h> | ||
#undef __USE_GNU | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
#if USE_LIBUCONTEXT | ||
#include <libucontext/libucontext.h> | ||
#else | ||
#include <ucontext.h> | ||
#include <err.h> | ||
#endif | ||
|
||
#ifdef HAVE_VALGRIND_H | ||
#include <valgrind.h> | ||
|
@@ -45,11 +51,11 @@ | |
|
||
#include <stdlib.h> | ||
|
||
#include "irq.h" | ||
#include "sched.h" | ||
|
||
#include "cpu.h" | ||
#include "cpu_conf.h" | ||
#include "irq.h" | ||
#include "sched.h" | ||
#include "test_utils/expect.h" | ||
|
||
#ifdef MODULE_NETDEV_TAP | ||
#include "netdev_tap.h" | ||
|
@@ -62,7 +68,6 @@ extern netdev_tap_t netdev_tap; | |
#include "debug.h" | ||
|
||
ucontext_t end_context; | ||
char __end_stack[SIGSTKSZ]; | ||
|
||
/** | ||
* make the new context assign `_native_in_isr = 0` before resuming | ||
|
@@ -194,7 +199,7 @@ void cpu_switch_context_exit(void) | |
irq_disable(); | ||
_native_in_isr = 1; | ||
native_isr_context.uc_stack.ss_sp = __isr_stack; | ||
native_isr_context.uc_stack.ss_size = SIGSTKSZ; | ||
native_isr_context.uc_stack.ss_size = __isr_stack_size; | ||
native_isr_context.uc_stack.ss_flags = 0; | ||
makecontext(&native_isr_context, isr_cpu_switch_context_exit, 0); | ||
if (setcontext(&native_isr_context) == -1) { | ||
|
@@ -247,7 +252,7 @@ void thread_yield_higher(void) | |
_native_in_isr = 1; | ||
irq_disable(); | ||
native_isr_context.uc_stack.ss_sp = __isr_stack; | ||
native_isr_context.uc_stack.ss_size = SIGSTKSZ; | ||
native_isr_context.uc_stack.ss_size = __isr_stack_size; | ||
native_isr_context.uc_stack.ss_flags = 0; | ||
makecontext(&native_isr_context, isr_thread_yield, 0); | ||
if (swapcontext(ctx, &native_isr_context) == -1) { | ||
|
@@ -263,13 +268,16 @@ void native_cpu_init(void) | |
err(EXIT_FAILURE, "native_cpu_init: getcontext"); | ||
} | ||
|
||
end_context.uc_stack.ss_sp = __end_stack; | ||
end_context.uc_stack.ss_sp = malloc(SIGSTKSZ); | ||
expect(end_context.uc_stack.ss_sp != NULL); | ||
end_context.uc_stack.ss_size = SIGSTKSZ; | ||
end_context.uc_stack.ss_flags = 0; | ||
makecontext(&end_context, sched_task_exit, 0); | ||
(void) VALGRIND_STACK_REGISTER(__end_stack, __end_stack + sizeof(__end_stack)); | ||
(void)VALGRIND_STACK_REGISTER(end_context.uc_stack.ss_sp, | ||
(char *)end_context.uc_stack.ss_sp + end_context.uc_stack.ss_size); | ||
VALGRIND_DEBUG("VALGRIND_STACK_REGISTER(%p, %p)\n", | ||
(void*)__end_stack, (void*)(__end_stack + sizeof(__end_stack))); | ||
(void*)end_context.uc_stack.ss_sp, | ||
(void*)((char *)end_context.uc_stack.ss_sp + end_context.uc_stack.ss_size)); | ||
|
||
DEBUG("RIOT native cpu initialized.\n"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters