mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
Merge pull request #17 from monkuous/rewrite
various fixes and new ports
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
#include <arch/context.h>
|
||||
#include <stdbool.h>
|
||||
#include <arch/cpuid.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <logging.h>
|
||||
|
||||
#define XCR0_X87 (1ull << 0)
|
||||
#define XCR0_SSE (1ull << 1)
|
||||
#define XCR0_AVX (1ull << 2)
|
||||
#define XCR0_AVX512 (7ull << 5)
|
||||
|
||||
#define XCR0_MASK (XCR0_AVX512 | XCR0_AVX | XCR0_SSE | XCR0_X87)
|
||||
|
||||
static enum {
|
||||
FXSAVE,
|
||||
XSAVE,
|
||||
XSAVEOPT,
|
||||
} xsave_method;
|
||||
size_t arch_xsave_size;
|
||||
static uint64_t xcr0_value;
|
||||
static scache_t *xsave_cache;
|
||||
|
||||
typedef struct {
|
||||
uint16_t fcw;
|
||||
uint16_t fsw;
|
||||
uint8_t ftw;
|
||||
uint8_t reserved1;
|
||||
uint16_t fop;
|
||||
uint64_t fip;
|
||||
uint64_t fdp;
|
||||
uint32_t mxcsr;
|
||||
uint32_t mxcsr_mask;
|
||||
struct {
|
||||
uint64_t data[2];
|
||||
} mm[8];
|
||||
struct {
|
||||
uint64_t data[2];
|
||||
} xmm[16];
|
||||
uint64_t reserved2[6];
|
||||
uint64_t unused[6];
|
||||
} fxsave_area_t;
|
||||
|
||||
void arch_extracontext_detect(void) {
|
||||
if (!arch_xsave_size) {
|
||||
if (cpuid_base_max_leaf() >= 0x0d) {
|
||||
xsave_method = XSAVE;
|
||||
|
||||
cpuid_results_t results;
|
||||
cpuid_with_ecx(0x0d, 0, &results);
|
||||
xcr0_value = ((uint64_t)results.edx << 32) | results.eax;
|
||||
xcr0_value &= XCR0_MASK;
|
||||
} else {
|
||||
xsave_method = FXSAVE;
|
||||
arch_xsave_size = 512;
|
||||
}
|
||||
}
|
||||
|
||||
if (xsave_method == FXSAVE) return;
|
||||
|
||||
size_t cr4;
|
||||
asm volatile("mov %%cr4, %0" : "=r" (cr4));
|
||||
cr4 |= (1u << 18);
|
||||
asm volatile("mov %0, %%cr4" :: "r" (cr4));
|
||||
|
||||
uint32_t low = xcr0_value;
|
||||
uint32_t high = xcr0_value >> 32;
|
||||
asm volatile("xsetbv" :: "a" (low), "d" (high), "c" (0u));
|
||||
|
||||
if (!arch_xsave_size) {
|
||||
// after xsetbv ebx is updated to the size of the context for the enabled features
|
||||
cpuid_results_t results;
|
||||
cpuid_with_ecx(0x0d, 0, &results);
|
||||
arch_xsave_size = results.ebx;
|
||||
|
||||
cpuid_with_ecx(0x0d, 1, &results);
|
||||
if (results.eax & 1) xsave_method = XSAVEOPT;
|
||||
}
|
||||
}
|
||||
|
||||
int arch_extracontext_init(extracontext_t *context) {
|
||||
if (!xsave_cache) {
|
||||
xsave_cache = slab_newcache(arch_xsave_size, xsave_method == FXSAVE ? 16 : 64, NULL, NULL);
|
||||
__assert(xsave_cache);
|
||||
}
|
||||
|
||||
context->xsave = slab_allocate(xsave_cache);
|
||||
if (!context->xsave) return 1;
|
||||
|
||||
// all sse exceptions masked
|
||||
// initialise the x87 FPU state as it would be after the FNINIT instruction
|
||||
memset(context->xsave, 0, arch_xsave_size);
|
||||
fxsave_area_t *area = context->xsave;
|
||||
area->mxcsr = 0x1f80;
|
||||
area->fcw = 0x37f;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void arch_extracontext_free(extracontext_t *context) {
|
||||
slab_free(xsave_cache, context->xsave);
|
||||
}
|
||||
|
||||
void arch_extracontext_save(extracontext_t *context) {
|
||||
context->gsbase = rdmsr(MSR_KERNELGSBASE);
|
||||
context->fsbase = rdmsr(MSR_FSBASE);
|
||||
|
||||
switch (xsave_method) {
|
||||
case FXSAVE: asm("fxsaveq %0" ::"m"(*(char(*)[arch_xsave_size])context->xsave) : "memory"); break;
|
||||
case XSAVE: asm("xsaveq %0" ::"m"(*(char(*)[arch_xsave_size])context->xsave), "d"(-1), "a"(-1) : "memory"); break;
|
||||
case XSAVEOPT: asm("xsaveoptq %0" ::"m"(*(char(*)[arch_xsave_size])context->xsave), "d"(-1), "a"(-1) : "memory"); break;
|
||||
}
|
||||
}
|
||||
|
||||
void arch_extracontext_load(extracontext_t *context) {
|
||||
wrmsr(MSR_KERNELGSBASE, context->gsbase);
|
||||
wrmsr(MSR_FSBASE, context->fsbase);
|
||||
|
||||
switch (xsave_method) {
|
||||
case FXSAVE: asm("fxrstorq %0" ::"m"(*(char(*)[arch_xsave_size])context->xsave) : "memory"); break;
|
||||
case XSAVE:
|
||||
case XSAVEOPT: asm("xrstorq %0" ::"m"(*(char(*)[arch_xsave_size])context->xsave), "d"(-1), "a"(-1) : "memory"); break;
|
||||
}
|
||||
}
|
||||
|
||||
void arch_extracontext_copy(extracontext_t *dst, const extracontext_t *src) {
|
||||
// XXX is this behavior correct? ucontext doesnt seem to save it on linux and so it will not be saved
|
||||
dst->gsbase = src->gsbase;
|
||||
dst->fsbase = src->fsbase;
|
||||
memcpy(dst->xsave, src->xsave, arch_xsave_size);
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <arch/idt.h>
|
||||
#include <arch/gdt.h>
|
||||
#include <kernel/dpc.h>
|
||||
#include <arch/context.h>
|
||||
|
||||
#define EFER_SYSCALLENABLE 1
|
||||
|
||||
@@ -251,6 +252,7 @@ static void arch_early(void) {
|
||||
arch_idt_reload();
|
||||
interrupt_register(0xfd, (void *)infinite_loop, NULL, IPL_IGNORE);
|
||||
dpc_init();
|
||||
arch_extracontext_detect();
|
||||
}
|
||||
|
||||
INIT_ROUTINE_DEFINE(arch_early, INIT_ROUTINE_FLAGS_NONE, arch_early)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <arch/smp.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/init.h>
|
||||
#include <arch/context.h>
|
||||
|
||||
DEFINE_KERNEL_ARGUMENT(nosmp, bool);
|
||||
|
||||
@@ -35,6 +36,7 @@ static void cpuwakeup(struct limine_smp_info *info) {
|
||||
arch_idt_reload();
|
||||
interrupt_register(0xfd, (void *)cpuwakeuphalt, NULL, IPL_IGNORE);
|
||||
dpc_init();
|
||||
arch_extracontext_detect();
|
||||
arch_mmu_apswitch();
|
||||
vmm_apinit();
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#define AT_PHDR 3
|
||||
#define AT_PHENT 4
|
||||
#define AT_PHNUM 5
|
||||
#define AT_PAGESZ 6
|
||||
#define AT_ENTRY 9
|
||||
#define AT_SECURE 23
|
||||
#define AT_EXECFN 31
|
||||
@@ -43,6 +44,7 @@ typedef struct {
|
||||
auxv64_t entry;
|
||||
auxv64_t execfn;
|
||||
auxv64_t secure;
|
||||
auxv64_t pagesz;
|
||||
auxv64_t null;
|
||||
} auxv64list_t;
|
||||
|
||||
|
||||
@@ -41,10 +41,11 @@ typedef struct {
|
||||
typedef struct {
|
||||
uint64_t gsbase;
|
||||
uint64_t fsbase;
|
||||
__attribute__((aligned(16))) uint8_t fx[512];
|
||||
uint32_t mxcsr;
|
||||
void *xsave;
|
||||
} extracontext_t;
|
||||
|
||||
extern size_t arch_xsave_size;
|
||||
|
||||
#define CTX_INIT(x,u,interrupts) \
|
||||
if (u) { \
|
||||
(x)->cs = 0x23; \
|
||||
@@ -55,15 +56,6 @@ typedef struct {
|
||||
} \
|
||||
(x)->rflags = interrupts ? 0x200 : 0;
|
||||
|
||||
// all sse exceptions masked
|
||||
// initialise the x87 FPU state as it would be after the FNINIT instruction
|
||||
#define CTX_XINIT(x, u) {\
|
||||
(x)->mxcsr = 0x1f80; \
|
||||
*((uint16_t *)&(x)->fx[0]) = 0x37f; \
|
||||
*((uint16_t *)&(x)->fx[2]) = 0; \
|
||||
(x)->fx[4] = 0; \
|
||||
}
|
||||
|
||||
#define CTX_SP(x) (x)->rsp
|
||||
#define CTX_IP(x) (x)->rip
|
||||
#define CTX_RET(x) (x)->rax
|
||||
@@ -81,43 +73,36 @@ typedef struct {
|
||||
void arch_context_switch(context_t *context);
|
||||
int arch_context_saveandcall(void (*fn)(context_t *context, void *argument), void *stack, void *argument);
|
||||
|
||||
void arch_extracontext_detect(void);
|
||||
|
||||
int arch_extracontext_init(extracontext_t *context);
|
||||
void arch_extracontext_free(extracontext_t *context);
|
||||
void arch_extracontext_save(extracontext_t *context);
|
||||
void arch_extracontext_load(extracontext_t *context);
|
||||
void arch_extracontext_copy(extracontext_t *dst, const extracontext_t *src);
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// kernelgsbase is set as user because they'll be swapped in the context switch
|
||||
#define ARCH_CONTEXT_SWITCHTHREAD(x) \
|
||||
current_cpu()->ist.rsp0 = (uint64_t)(x)->kernelstacktop; \
|
||||
wrmsr(MSR_KERNELGSBASE, (x)->extracontext.gsbase); \
|
||||
wrmsr(MSR_FSBASE, (x)->extracontext.fsbase); \
|
||||
asm("fxrstor (%%rax)" : : "a"(&(x)->extracontext.fx[0])); \
|
||||
asm("ldmxcsr (%%rax)" : : "a"(&(x)->extracontext.mxcsr)); \
|
||||
arch_extracontext_load(&(x)->extracontext); \
|
||||
arch_context_switch(&thread->context);
|
||||
|
||||
#define ARCH_CONTEXT_THREADSAVE(t, c) \
|
||||
memcpy(&(t)->context, c, sizeof(context_t)); \
|
||||
(t)->extracontext.gsbase = rdmsr(MSR_KERNELGSBASE); \
|
||||
(t)->extracontext.fsbase = rdmsr(MSR_FSBASE); \
|
||||
asm("fxsave (%%rax)" : : "a"(&(t)->extracontext.fx[0])); \
|
||||
asm("stmxcsr (%%rax)" : : "a"(&(t)->extracontext.mxcsr));
|
||||
arch_extracontext_save(&(t)->extracontext);
|
||||
|
||||
#define ARCH_CONTEXT_THREADLOAD(t, c) \
|
||||
memcpy(c, &(t)->context, sizeof(context_t)); \
|
||||
current_cpu()->ist.rsp0 = (uint64_t)(t)->kernelstacktop; \
|
||||
wrmsr(MSR_KERNELGSBASE, (t)->extracontext.gsbase); \
|
||||
wrmsr(MSR_FSBASE, (t)->extracontext.fsbase); \
|
||||
asm("fxrstor (%%rax)" : : "a"(&(t)->extracontext.fx[0])); \
|
||||
asm("ldmxcsr (%%rax)" : : "a"(&(t)->extracontext.mxcsr));
|
||||
arch_extracontext_load(&(t)->extracontext);
|
||||
|
||||
#define ARCH_EXTRACONTEXT_LOAD(c) \
|
||||
wrmsr(MSR_KERNELGSBASE, (c)->gsbase); \
|
||||
wrmsr(MSR_FSBASE, (c)->fsbase); \
|
||||
asm("fxrstor (%%rax)" : : "a"(&(c)->fx[0])); \
|
||||
asm("ldmxcsr (%%rax)" : : "a"(&(c)->mxcsr));
|
||||
arch_extracontext_load(c);
|
||||
|
||||
#define ARCH_EXTRACONTEXT_SAVE(c) \
|
||||
(c)->gsbase = rdmsr(MSR_KERNELGSBASE); \
|
||||
(c)->fsbase = rdmsr(MSR_FSBASE); \
|
||||
asm("fxsave (%%rax)" : : "a"(&(c)->fx[0])); \
|
||||
asm("stmxcsr (%%rax)" : : "a"(&(c)->mxcsr));
|
||||
arch_extracontext_save(c);
|
||||
|
||||
#define ARCH_CONTEXT_INTSTATUS(x) ((x)->rflags & 0x200 ? true : false)
|
||||
#define ARCH_CONTEXT_ISUSER(x) ((x)->cs == 0x23)
|
||||
|
||||
@@ -56,9 +56,15 @@ typedef struct {
|
||||
context_t context;
|
||||
extracontext_t extracontext;
|
||||
siginfo_t siginfo;
|
||||
uint8_t xsave[];
|
||||
} sigframe_t;
|
||||
|
||||
#define ARCH_SIGFRAME_GET_UCONTEXT_POINTER(x) (&(x)->uc_flags)
|
||||
#define ARCH_SIGFRAME_SIZE (sizeof(sigframe_t) + arch_xsave_size)
|
||||
|
||||
static inline void arch_sigframe_init(sigframe_t *sigframe) {
|
||||
sigframe->extracontext.xsave = sigframe->xsave;
|
||||
}
|
||||
|
||||
static inline void arch_sigframe_prepare_mcontext(void *stack, sigframe_t *sigframe) {
|
||||
context_t *context = &sigframe->context;
|
||||
@@ -89,7 +95,8 @@ static inline void arch_sigframe_prepare_mcontext(void *stack, sigframe_t *sigfr
|
||||
gregs[MCONTEXT_REG_OLDMASK] = 0;
|
||||
gregs[MCONTEXT_REG_CR2] = context->cr2;
|
||||
|
||||
sigframe->mcontext.fpu_state_p = &((sigframe_t *)stack)->extracontext.fx;
|
||||
extracontext->xsave = ((sigframe_t *)stack)->xsave;
|
||||
sigframe->mcontext.fpu_state_p = extracontext->xsave;
|
||||
}
|
||||
|
||||
static inline void arch_sigframe_get_context_from_mcontext(sigframe_t *sigframe) {
|
||||
|
||||
@@ -385,6 +385,13 @@ int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result, cred_t *cre
|
||||
size_t len = min(strlen(tty->name) + 1, TTY_NAME_MAX);
|
||||
return USERCOPY_POSSIBLY_TO_USER(arg, tty->name, len);
|
||||
}
|
||||
case FIONREAD: {
|
||||
MUTEX_ACQUIRE(&tty->readmutex);
|
||||
int count = RINGBUFFER_DATACOUNT(&tty->readbuffer);
|
||||
MUTEX_RELEASE(&tty->readmutex);
|
||||
int status = USERCOPY_POSSIBLY_TO_USER(arg, &count, sizeof(count));
|
||||
return status;
|
||||
}
|
||||
default:
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
@@ -163,11 +163,13 @@ int elf_load(vnode_t *vnode, void *base, void **entry, char **interpreter, auxv6
|
||||
auxv64->phent.type = AT_PHENT;
|
||||
auxv64->entry.type = AT_ENTRY;
|
||||
auxv64->secure.type = AT_SECURE;
|
||||
auxv64->pagesz.type = AT_PAGESZ;
|
||||
|
||||
auxv64->secure.val = 0; // set later by whoever called elf_load
|
||||
auxv64->phnum.val = header.phcount;
|
||||
auxv64->phent.val = header.phsize;
|
||||
auxv64->entry.val = header.entry + (uintptr_t)base;
|
||||
auxv64->pagesz.val = PAGE_SIZE;
|
||||
*entry = (void *)(header.entry + (uintptr_t)base);
|
||||
|
||||
__assert(header.phsize == sizeof(elfph64_t));
|
||||
|
||||
+15
-14
@@ -540,7 +540,7 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
|
||||
// get where in memory to put the frame
|
||||
#if ARCH_SIGNAL_STACK_GROWS_DOWNWARDS == 1
|
||||
void *stack = altstack ? (void *)((uintptr_t)altstack + thread->signals.stack.size) : (void *)CTX_SP(context);
|
||||
stack = (void *)((((uintptr_t)stack - ARCH_SIGNAL_REDZONE_SIZE - sizeof(sigframe_t)) & ~0xfl) - 0x8);
|
||||
stack = (void *)((((uintptr_t)stack - ARCH_SIGNAL_REDZONE_SIZE - ARCH_SIGFRAME_SIZE) & ~0xfl) - 0x8);
|
||||
#else
|
||||
#error unsupported
|
||||
#endif
|
||||
@@ -553,35 +553,36 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
|
||||
}
|
||||
|
||||
// configure stack frame
|
||||
sigframe_t sigframe;
|
||||
sigframe.restorer = action->restorer;
|
||||
sigframe_t *sigframe = __builtin_alloca(ARCH_SIGFRAME_SIZE);
|
||||
arch_sigframe_init(sigframe);
|
||||
sigframe->restorer = action->restorer;
|
||||
if (altstack) {
|
||||
memcpy(&sigframe.oldstack, &thread->signals.stack, sizeof(stack_t));
|
||||
memcpy(&sigframe->oldstack, &thread->signals.stack, sizeof(stack_t));
|
||||
memset(&thread->signals.stack, 0, sizeof(stack_t));
|
||||
} else {
|
||||
memset(&sigframe.oldstack, 0, sizeof(stack_t));
|
||||
memset(&sigframe->oldstack, 0, sizeof(stack_t));
|
||||
}
|
||||
|
||||
if (thread->signals.hasreturnmask) {
|
||||
// if we were waiting in signal_suspend, push the old mask into the return frame
|
||||
// of the first signal and set it to not act this way the next check
|
||||
memcpy(&sigframe.oldmask, &thread->signals.returnmask, sizeof(sigset_t));
|
||||
memcpy(&sigframe->oldmask, &thread->signals.returnmask, sizeof(sigset_t));
|
||||
thread->signals.hasreturnmask = false;
|
||||
} else {
|
||||
// else, just push the current mask
|
||||
memcpy(&sigframe.oldmask, &thread->signals.mask, sizeof(sigset_t));
|
||||
memcpy(&sigframe->oldmask, &thread->signals.mask, sizeof(sigset_t));
|
||||
}
|
||||
memcpy(&sigframe.context, context, sizeof(context_t));
|
||||
memcpy(&sigframe.extracontext, &thread->extracontext, sizeof(extracontext_t));
|
||||
memcpy(&sigframe->context, context, sizeof(context_t));
|
||||
arch_extracontext_copy(&sigframe->extracontext, &thread->extracontext);
|
||||
|
||||
arch_sigframe_prepare_mcontext(stack, &sigframe);
|
||||
arch_sigframe_prepare_mcontext(stack, sigframe);
|
||||
|
||||
memset(&sigframe.siginfo, 0, sizeof(siginfo_t));
|
||||
memset(&sigframe->siginfo, 0, sizeof(siginfo_t));
|
||||
if (signal == SIGSEGV)
|
||||
sigframe.siginfo.__si_fields.__sigfault.si_addr = CTX_TRAP_ADDR(context);
|
||||
sigframe->siginfo.__si_fields.__sigfault.si_addr = CTX_TRAP_ADDR(context);
|
||||
|
||||
if (usercopy_touser(stack, &sigframe, sizeof(sigframe_t))) {
|
||||
printf("signal: bad user stack %p (altstack %p) handling signal %d trapno %lu\n", stack, altstack, signal, sigframe.mcontext.gregs[MCONTEXT_REG_TRAPNO]);
|
||||
if (usercopy_touser(stack, sigframe, ARCH_SIGFRAME_SIZE)) {
|
||||
printf("signal: bad user stack %p (altstack %p) handling signal %d trapno %lu\n", stack, altstack, signal, sigframe->mcontext.gregs[MCONTEXT_REG_TRAPNO]);
|
||||
THREAD_LEAVE(thread);
|
||||
PROCESS_LEAVE(proc);
|
||||
interrupt_set(true);
|
||||
|
||||
@@ -9,31 +9,26 @@
|
||||
|
||||
// this expects CTX_SP to be pointing to the signal frame
|
||||
__attribute__((noreturn)) void syscall_sigreturn(context_t *context) {
|
||||
sigframe_t sigframe;
|
||||
int error = usercopy_fromuser(&sigframe, (void *)CTX_SP(context), sizeof(sigframe_t));
|
||||
if (error || ARCH_CONTEXT_ISUSER(&sigframe.context) == false) {
|
||||
sigframe_t *sigframe = __builtin_alloca(ARCH_SIGFRAME_SIZE);
|
||||
int error = usercopy_fromuser(sigframe, (void *)CTX_SP(context), ARCH_SIGFRAME_SIZE);
|
||||
if (error || ARCH_CONTEXT_ISUSER(&sigframe->context) == false) {
|
||||
printf("syscall_sigreturn: bad return stack or bad return information\n");
|
||||
proc_terminate(SIGSEGV);
|
||||
}
|
||||
|
||||
interrupt_set(false);
|
||||
signal_altstack(current_thread(), &sigframe.oldstack, NULL);
|
||||
signal_changemask(current_thread(), SIG_SETMASK, &sigframe.oldmask, NULL);
|
||||
signal_altstack(current_thread(), &sigframe->oldstack, NULL);
|
||||
signal_changemask(current_thread(), SIG_SETMASK, &sigframe->oldmask, NULL);
|
||||
|
||||
arch_sigframe_get_context_from_mcontext(&sigframe);
|
||||
arch_sigframe_get_context_from_mcontext(sigframe);
|
||||
|
||||
__assert(ARCH_CONTEXT_ISUSER(&sigframe.context));
|
||||
__assert(ARCH_CONTEXT_ISUSER(&sigframe->context));
|
||||
|
||||
#ifdef __x86_64__
|
||||
// XXX is this behavior correct? ucontext doesnt seem to save it on linux and so it will not be saved
|
||||
sigframe.extracontext.gsbase = rdmsr(MSR_KERNELGSBASE);
|
||||
sigframe.extracontext.fsbase = rdmsr(MSR_FSBASE);
|
||||
#endif
|
||||
memcpy(¤t_thread()->extracontext, &sigframe.extracontext, sizeof(extracontext_t));
|
||||
arch_extracontext_copy(¤t_thread()->extracontext, &sigframe->extracontext);
|
||||
ARCH_CONTEXT_THREADLOAD(current_thread(), context);
|
||||
|
||||
interrupt_set(true);
|
||||
arch_context_switch(&sigframe.context);
|
||||
arch_context_switch(&sigframe->context);
|
||||
|
||||
// if we were to return normally, CTX_RET and CTX_ERRNO would be corrupted,
|
||||
// so we will manually call arch_context_switch, which will jump to the right userland code
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <kernel/proc.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <logging.h>
|
||||
#include <arch/context.h>
|
||||
|
||||
static scache_t *thread_cache;
|
||||
|
||||
@@ -17,8 +18,14 @@ thread_t *sched_newthread(void *ip, size_t kstacksize, int nice, proc_t *proc, v
|
||||
|
||||
memset(thread, 0, sizeof(thread_t));
|
||||
|
||||
if (arch_extracontext_init(&thread->extracontext)) {
|
||||
slab_free(thread_cache, thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
thread->kernelstack = vmm_map(NULL, kstacksize, VMM_FLAGS_ALLOCATE, ARCH_MMU_FLAGS_WRITE | ARCH_MMU_FLAGS_READ | ARCH_MMU_FLAGS_NOEXEC, NULL);
|
||||
if (thread->kernelstack == NULL) {
|
||||
arch_extracontext_free(&thread->extracontext);
|
||||
slab_free(thread_cache, thread);
|
||||
return NULL;
|
||||
}
|
||||
@@ -37,7 +44,6 @@ thread_t *sched_newthread(void *ip, size_t kstacksize, int nice, proc_t *proc, v
|
||||
}
|
||||
|
||||
CTX_INIT(&thread->context, proc != NULL, true);
|
||||
CTX_XINIT(&thread->extracontext, proc != NULL);
|
||||
CTX_SP(&thread->context) = proc ? (ctxreg_t)ustack : (ctxreg_t)thread->kernelstacktop;
|
||||
CTX_IP(&thread->context) = (ctxreg_t)ip;
|
||||
SPINLOCK_INIT(thread->sleeplock);
|
||||
@@ -52,6 +58,7 @@ thread_t *sched_newthread(void *ip, size_t kstacksize, int nice, proc_t *proc, v
|
||||
|
||||
void sched_destroythread(thread_t *thread) {
|
||||
vmm_unmap(thread->kernelstack, thread->kernelstacksize, 0);
|
||||
arch_extracontext_free(&thread->extracontext);
|
||||
slab_free(thread_cache, thread);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
diff -urN --no-dereference jna-clean/build.xml jna-workdir/build.xml
|
||||
--- jna-clean/build.xml
|
||||
+++ jna-workdir/build.xml
|
||||
@@ -939,6 +939,9 @@
|
||||
<condition property="make.OS" value="OS=android">
|
||||
<matches pattern="^android-" string="${os.prefix}"/>
|
||||
</condition>
|
||||
+ <condition property="make.OS" value="OS=astral">
|
||||
+ <matches pattern="^astral-" string="${os.prefix}"/>
|
||||
+ </condition>
|
||||
<property name="make.OS" value="IGNORE="/>
|
||||
<!-- Ensure Makefile ARCH property properly set for darwin -->
|
||||
<condition property="ARCH" value="aarch64">
|
||||
diff -urN --no-dereference jna-clean/native/Makefile jna-workdir/native/Makefile
|
||||
--- jna-clean/native/Makefile
|
||||
+++ jna-workdir/native/Makefile
|
||||
@@ -32,7 +32,7 @@
|
||||
# NDK_PLATFORM below or set it in your environment.
|
||||
#
|
||||
# The windows build requires a cygwin installation. The build will use MSVC
|
||||
-# for compilation if cl.exe is found on the PATH, otherwise the build will fall
|
||||
+# for compilation if cl.exe is found on the PATH, otherwise the build will fall
|
||||
# back to mingw.
|
||||
|
||||
# Systems which support POSIX signals may be able to support VM crash
|
||||
@@ -118,7 +118,7 @@
|
||||
ALIBDIR=/usr/lib
|
||||
ifeq ($(ARCH),arm)
|
||||
PREFIX=arm-linux-androideabi-
|
||||
-COPT+= -mthumb-interwork -march=armv5te -mtune=xscale -msoft-float -fstack-protector
|
||||
+COPT+= -mthumb-interwork -march=armv5te -mtune=xscale -msoft-float -fstack-protector
|
||||
HOST=arm-linux-eabi
|
||||
else
|
||||
ifeq ($(ARCH),armv7)
|
||||
@@ -234,7 +234,7 @@
|
||||
ifeq ($(USE_MSVC),true)
|
||||
# MS compiler
|
||||
CC=$(FFI_SRC)/msvcc.sh
|
||||
-CDEFINES+=-DHAVE_PROTECTION
|
||||
+CDEFINES+=-DHAVE_PROTECTION
|
||||
ifneq ($(DYNAMIC_LIBFFI),true)
|
||||
CDEFINES+=-DUSE_STATIC_RTL
|
||||
endif
|
||||
@@ -396,13 +396,13 @@
|
||||
DARWIN_ARCH=$(ARCH)
|
||||
ifeq ($(ARCH),aarch64)
|
||||
DARWIN_ARCH=arm64
|
||||
-else
|
||||
+else
|
||||
ifeq ($(ARCH),x86-64)
|
||||
DARWIN_ARCH=x86_64
|
||||
else
|
||||
ifeq ($(ARCH),x86)
|
||||
DARWIN_ARCH=x86
|
||||
-else
|
||||
+else
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@@ -455,6 +455,19 @@
|
||||
LIBS=
|
||||
endif
|
||||
|
||||
+ifeq ($(OS),astral)
|
||||
+PCFLAGS+=-fPIC
|
||||
+CDEFINES+=-DHAVE_PROTECTION
|
||||
+HOST_CONFIG=--host=x86_64-astral
|
||||
+JAVA_INCLUDES+=-I"$(JAVA_HOME)/include/linux"
|
||||
+ifeq ($(DYNAMIC_LIBFFI),true)
|
||||
+LDFLAGS+=-Wl,-soname,$@
|
||||
+else
|
||||
+# Ensure we bind to local libffi symbols
|
||||
+LDFLAGS+=-Wl,-soname,$@,-Bsymbolic
|
||||
+endif
|
||||
+endif
|
||||
+
|
||||
# Unfortunately, we have to use different libffi include files depending on
|
||||
# the target, so we can't do a simple universal build on darwin. Do
|
||||
# separate builds, then merge the results.
|
||||
@@ -473,7 +486,7 @@
|
||||
cp $(LIBRARY) $(INSTALLDIR)
|
||||
|
||||
ifeq ($(ARCH), amd64)
|
||||
-$(DLLCB): dll-callback.c
|
||||
+$(DLLCB): dll-callback.c
|
||||
$(MINGW) -DDEFINE_CALLBACKS -c $< $(COUT)
|
||||
endif
|
||||
|
||||
@@ -505,7 +518,7 @@
|
||||
$(LD) $(LDFLAGS) $< $(TESTDEP) $(LIBS)
|
||||
|
||||
ifneq ($(DYNAMIC_LIBFFI),true)
|
||||
-$(FFI_LIB):
|
||||
+$(FFI_LIB):
|
||||
@mkdir -p $(FFI_BUILD)
|
||||
@if [ ! -f $(FFI_SRC)/configure ]; then \
|
||||
echo "Generating configure"; \
|
||||
diff -urN --no-dereference jna-clean/src/com/sun/jna/Platform.java jna-workdir/src/com/sun/jna/Platform.java
|
||||
--- jna-clean/src/com/sun/jna/Platform.java
|
||||
+++ jna-workdir/src/com/sun/jna/Platform.java
|
||||
@@ -42,6 +42,7 @@
|
||||
public static final int GNU = 9;
|
||||
public static final int KFREEBSD = 10;
|
||||
public static final int NETBSD = 11;
|
||||
+ public static final int ASTRAL = 13;
|
||||
|
||||
/** Whether read-only (final) fields within Structures are supported. */
|
||||
public static final boolean RO_FIELDS;
|
||||
@@ -110,6 +111,9 @@
|
||||
else if (osName.equalsIgnoreCase("netbsd")) {
|
||||
osType = NETBSD;
|
||||
}
|
||||
+ else if (osName.startsWith("Astral")) {
|
||||
+ osType = ASTRAL;
|
||||
+ }
|
||||
else {
|
||||
osType = UNSPECIFIED;
|
||||
}
|
||||
@@ -175,6 +179,9 @@
|
||||
public static final boolean iskFreeBSD() {
|
||||
return osType == KFREEBSD;
|
||||
}
|
||||
+ public static final boolean isAstral() {
|
||||
+ return osType == ASTRAL;
|
||||
+ }
|
||||
public static final boolean isX11() {
|
||||
// TODO: check filesystem for /usr/X11 or some other X11-specific test
|
||||
return !Platform.isWindows() && !Platform.isMac();
|
||||
@@ -341,6 +348,9 @@
|
||||
case Platform.KFREEBSD:
|
||||
osPrefix = "kfreebsd-" + arch;
|
||||
break;
|
||||
+ case Platform.ASTRAL:
|
||||
+ osPrefix = "astral-" + arch;
|
||||
+ break;
|
||||
default:
|
||||
osPrefix = name.toLowerCase();
|
||||
int space = osPrefix.indexOf(" ");
|
||||
@@ -0,0 +1,13 @@
|
||||
diff -urN --no-dereference libffi-clean/src/closures.c libffi-workdir/src/closures.c
|
||||
--- libffi-clean/src/closures.c
|
||||
+++ libffi-workdir/src/closures.c
|
||||
@@ -139,6 +139,9 @@
|
||||
executable memory. */
|
||||
# define FFI_MMAP_EXEC_WRIT 1
|
||||
# endif
|
||||
+# if defined(__astral__)
|
||||
+# define FFI_MMAP_EXEC_WRIT 1
|
||||
+# endif
|
||||
#endif
|
||||
|
||||
#if FFI_MMAP_EXEC_WRIT && !defined FFI_MMAP_EXEC_SELINUX
|
||||
File diff suppressed because it is too large
Load Diff
@@ -551,9 +551,20 @@ index 5c57cf8..cb2d97f 100644
|
||||
|
||||
void tdestroy(void *root, void (*free_node)(void *)) {
|
||||
diff --git mlibc-clean/options/rtld/generic/main.cpp mlibc-workdir/options/rtld/generic/main.cpp
|
||||
index b2db152..e6438fe 100644
|
||||
index b2db152..244ad4b 100644
|
||||
--- mlibc-clean/options/rtld/generic/main.cpp
|
||||
+++ mlibc-workdir/options/rtld/generic/main.cpp
|
||||
@@ -636,8 +636,8 @@ void *__dlapi_open(const char *file, int flags, void *returnAddress) {
|
||||
// In order to know which RUNPATH / RPATH to process, we must find the calling object.
|
||||
SharedObject *origin = initialRepository->findCaller(returnAddress);
|
||||
if (!origin) {
|
||||
- mlibc::panicLogger() << "rtld: unable to determine calling object of dlopen "
|
||||
- << "(ra = " << returnAddress << ")" << frg::endlog;
|
||||
+ // When we can't find the origin, assume it's the main executable (copies glibc behavior)
|
||||
+ origin = executableSO;
|
||||
}
|
||||
|
||||
objectResult = initialRepository->requestObjectWithName(file, origin, newScope, !isGlobal, rts);
|
||||
@@ -681,6 +681,9 @@ void *__dlapi_open(const char *file, int flags, void *returnAddress) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
name=glfw
|
||||
revision=1
|
||||
from_source=glfw
|
||||
imagedeps="build-essential"
|
||||
hostdeps="xgcc xbinutils cmake pkgconfig"
|
||||
deps="base libx11 libxext libxi libxrandr libxrender libxt libxtst xorgproto libiconv libxcursor libxxf86vm libxinerama"
|
||||
|
||||
configure() {
|
||||
cmake \
|
||||
-DCMAKE_TOOLCHAIN_FILE=${base_dir}/util/cmake \
|
||||
-DCMAKE_INSTALL_PREFIX=${prefix} \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_LIBDIR=lib \
|
||||
-DBUILD_SHARED_LIBS=ON \
|
||||
-DGLFW_BUILD_WAYLAND=OFF \
|
||||
${source_dir}
|
||||
}
|
||||
|
||||
build() {
|
||||
make -j${parallelism}
|
||||
}
|
||||
|
||||
package() {
|
||||
DESTDIR=${dest_dir} make install
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
name=jna
|
||||
revision=1
|
||||
from_source=jna
|
||||
imagedeps="build-essential zip unzip file ant openjdk-8-jdk"
|
||||
hostdeps="xgcc xbinutils"
|
||||
deps="base openjdk17"
|
||||
|
||||
configure() {
|
||||
cp -rp "${source_dir}/." .
|
||||
}
|
||||
|
||||
build() {
|
||||
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 ant \
|
||||
-DCC=x86_64-astral-gcc \
|
||||
-Dos.prefix=linux-x86-64 \
|
||||
-Djre.arch=x86-64 \
|
||||
-Djdk.home="${sysroot_dir}/usr/lib/jvm/java-17" \
|
||||
-Dbuild-native=true \
|
||||
-Ddynlink.native=true \
|
||||
dist
|
||||
}
|
||||
|
||||
package() {
|
||||
mkdir -p "${dest_dir}${prefix}/share/jna"
|
||||
cp build/jna.jar "${dest_dir}${prefix}/share/jna"
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
name=lwjgl3
|
||||
revision=1
|
||||
from_source=lwjgl3
|
||||
imagedeps="build-essential zip unzip file ant openjdk-8-jdk"
|
||||
hostdeps="xgcc xbinutils libstdc++-v3 pkgconfig autoconf"
|
||||
deps="base cups freetype fontconfig libpng libjpeg-turbo zlib libx11 libxext libxi libxrandr libxrender libxt libxtst xorgproto libiconv libffi libxcursor libxxf86vm openjdk17 glfw openal"
|
||||
allow_network=yes
|
||||
|
||||
configure() {
|
||||
cp -rp "${source_dir}/." .
|
||||
}
|
||||
|
||||
_call_ant() {
|
||||
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 ant \
|
||||
-Dgcc.prefix=x86_64-astral- \
|
||||
-Dbuild.arch=x64 \
|
||||
-Dplatform=astral \
|
||||
-Djni.headers="${sysroot_dir}/usr/lib/jvm/java-17/include" \
|
||||
-Dbinding.nfd=false \
|
||||
-Dbinding.tootle=false \
|
||||
-Dbinding.remotery=false \
|
||||
-Dbinding.assimp=false \
|
||||
-Dbinding.bgfx=false \
|
||||
-Dbinding.harfbuzz=false \
|
||||
-Dbinding.hwloc=false \
|
||||
-Dbinding.ktx=false \
|
||||
-Dbinding.openvr=false \
|
||||
-Dbinding.openxr=false \
|
||||
-Dbinding.opus=false \
|
||||
-Dbinding.shaderc=false \
|
||||
-Dbinding.spvc=false \
|
||||
-Dbinding.nanovg=false \
|
||||
-Djavadoc.skip=true \
|
||||
"$@"
|
||||
}
|
||||
|
||||
build() {
|
||||
_call_ant compile-templates generate compile
|
||||
_call_ant -Dbuild.offline=true compile-native
|
||||
yes | _call_ant -Dbuild.offline=true release
|
||||
}
|
||||
|
||||
package() {
|
||||
mkdir -vp "${dest_dir}${prefix}/share/lwjgl3"
|
||||
find bin/RELEASE -type f -name '*.jar' ! -name '*-sources.jar' -exec cp '{}' "${dest_dir}${prefix}/share/lwjgl3" ';'
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
name=openal
|
||||
revision=1
|
||||
from_source=openal
|
||||
imagedeps="build-essential cmake"
|
||||
hostdeps="xgcc xbinutils libstdc++-v3 pkgconfig"
|
||||
deps="base alsa-lib"
|
||||
|
||||
configure() {
|
||||
cmake \
|
||||
-DCMAKE_TOOLCHAIN_FILE=${base_dir}/util/cmake \
|
||||
-DCMAKE_INSTALL_PREFIX=${prefix} \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_LIBDIR=lib \
|
||||
${source_dir}
|
||||
}
|
||||
|
||||
build() {
|
||||
make -j${parallelism}
|
||||
}
|
||||
|
||||
package() {
|
||||
DESTDIR=${dest_dir} make install
|
||||
}
|
||||
@@ -10,7 +10,7 @@ prepare() {
|
||||
rm -f io/printf.c
|
||||
rm -f include/printf.h
|
||||
rm -rf flanterm
|
||||
curl https://raw.githubusercontent.com/limine-bootloader/limine-protocol/refs/heads/trunk/include/limine.h > include/limine.h
|
||||
curl https://raw.githubusercontent.com/limine-bootloader/limine-protocol/4607d68cbdbe653885937fb3178449588addb799/include/limine.h > include/limine.h
|
||||
pushd /tmp/
|
||||
wget https://github.com/mpaland/printf/archive/refs/tags/v4.0.0.tar.gz
|
||||
tar -xf v4.0.0.tar.gz
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
name=glfw
|
||||
version=3.4
|
||||
source_method=tarball
|
||||
tarball_url="https://github.com/glfw/glfw/archive/refs/tags/${version}.tar.gz"
|
||||
tarball_sha512=39ad7a4521267fbebc35d2ff0c389a56236ead5fa4bdff33db113bd302f70f5f2869ff4e6db1979512e1542813292dff5a482e94dfce231750f0746c301ae9ed
|
||||
prepare() {
|
||||
true
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
name=jna
|
||||
version=5.13.0
|
||||
source_method=tarball
|
||||
tarball_url="https://github.com/java-native-access/jna/archive/refs/tags/${version}.tar.gz"
|
||||
tarball_sha512=aefd0becc03bb7fd753e8c5cdcbcb20f6d590125a5fb03048bef0024e826ab0254b750e22a8bb26bea38cc89262ad45e5030b666cb2c857b01b15a6a55379a0f
|
||||
prepare() {
|
||||
true
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
name=lwjgl3
|
||||
version=3.3.3
|
||||
source_method=tarball
|
||||
tarball_url="https://github.com/LWJGL/lwjgl3/archive/refs/tags/${version}.tar.gz"
|
||||
tarball_sha512=739a8bcadc0b4008326b9a90fcbc90076308baa0e38649454b8747187611d355d454e4c0396d1a9f4ea3c1ac515ec8f7ae0ff6607fb0dab825d035c6a83873b7
|
||||
prepare() {
|
||||
true
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
name=openal
|
||||
version=1.21.0
|
||||
source_method=tarball
|
||||
tarball_url="https://github.com/kcat/openal-soft/archive/refs/tags/openal-soft-${version}.tar.gz"
|
||||
tarball_sha512=0c8159e25d9776469478c5ec577fd123c87822a22fc1da978b4e99a7fc1a5ed29ea2a53dc975cc311f72660114a7f8ab75fd9b080d93ac2a280b424c1c66d497
|
||||
prepare() {
|
||||
true
|
||||
}
|
||||
Reference in New Issue
Block a user