syscall fixes

This commit is contained in:
2026-10-12 19:05:42 +02:00
parent bc5f01dab6
commit 060983bbf6
5 changed files with 16 additions and 9 deletions
+1
View File
@@ -117,6 +117,7 @@
#define CPUID_7D_AMX_INT8 (1 << 25) #define CPUID_7D_AMX_INT8 (1 << 25)
#define RFLAGS_CF (1u << 0) #define RFLAGS_CF (1u << 0)
#define RFLAGS_BRKI (1u << 1)
#define RFLAGS_PF (1u << 2) #define RFLAGS_PF (1u << 2)
#define RFLAGS_AF (1u << 4) #define RFLAGS_AF (1u << 4)
#define RFLAGS_ZF (1u << 6) #define RFLAGS_ZF (1u << 6)
+3 -2
View File
@@ -66,10 +66,11 @@ void x86_64_cpu_setup(struct percpu* cpu) {
asm_wrmsr(MSR_EFER, asm_rdmsr(MSR_EFER) | MSR_EFER_SCE); asm_wrmsr(MSR_EFER, asm_rdmsr(MSR_EFER) | MSR_EFER_SCE);
union ia32_star star = {0}; union ia32_star star = {0};
star.kernel_cs_ss = offsetof(struct gdt, kernel_code64); star.kernel_cs_ss = offsetof(struct gdt, kernel_code64);
star.user_cs_ss = offsetof(struct gdt, user_code32); star.user_cs_ss = offsetof(struct gdt, user_code32) | CPL_USER;
asm_wrmsr(MSR_STAR, star.value); asm_wrmsr(MSR_STAR, star.value);
asm_wrmsr(MSR_LSTAR, (uint64_t)arch_syscall_stub); asm_wrmsr(MSR_LSTAR, (uint64_t)arch_syscall_stub);
asm_wrmsr(MSR_SFMASK, RFLAGS_AC | RFLAGS_DF | RFLAGS_IF); // Mask all RFLAGS except for BRKI which is reserved.
asm_wrmsr(MSR_SFMASK, ~RFLAGS_BRKI);
// TODO: FRED // TODO: FRED
+4 -2
View File
@@ -58,8 +58,10 @@ void arch_syscall_stub() {
" pop rbx\n" " pop rbx\n"
" pop rax\n" " pop rax\n"
" add rsp, 0x10\n" // Skip .error and .isr fields " add rsp, 0x10\n" // Skip .error and .isr fields
"2:\n" " pop rcx\n" // rip
" mov rsp, gs:%c[user_stack]\n" " add rsp, 0x08\n" // Skip cs
" pop r11\n" // rflags
" pop rsp\n" // rsp
" swapgs\n" " swapgs\n"
" sysretq\n" " sysretq\n"
: :
-2
View File
@@ -97,8 +97,6 @@ subdir('syscalls')
subdir('dev') subdir('dev')
subdir('fs') subdir('fs')
subdir('tests')
configure_file( configure_file(
configuration: cfg, configuration: cfg,
output: 'config.h', output: 'config.h',
+8 -3
View File
@@ -19,10 +19,15 @@ enum syslog_kind : uintptr_t {
struct syscall_ret sys_syslog(enum syslog_kind kind, __user char* message, size_t len) { struct syscall_ret sys_syslog(enum syslog_kind kind, __user char* message, size_t len) {
struct syscall_ret ret = {}; struct syscall_ret ret = {};
const size_t buf_len = MIN(len + 1, 0x1000); const size_t buf_len = MIN(len + 1, 256);
char* buf = mem_alloc(buf_len, ALLOC_NOZERO); char* buf = mem_alloc(buf_len, ALLOC_NOZERO);
usercopy_read(buf, message, buf_len - 1); if (!usercopy_read(buf, message, buf_len - 1)) {
buf[buf_len] = 0; mem_free(buf);
ret.error = EFAULT;
return ret;
}
buf[buf_len - 1] = 0;
const char* log_level; const char* log_level;
switch (kind) { switch (kind) {