Skip to content

Commit 24c8954

Browse files
committed
Stack alignment issues...
1 parent b8d1b5e commit 24c8954

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

kernel/src/kernel/tasking/elf/elf_tls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ void elfTlsCreateMasterImage(g_fd file, g_process* process, g_elf_object* rootOb
9494
process->tlsMaster.location = tlsStart;
9595
process->tlsMaster.size = size;
9696
process->tlsMaster.userThreadOffset = rootObject->tlsMaster.userThreadOffset;
97-
logInfo("%! created TLS master: %h, size: %h, uTO: %x", "elf", process->tlsMaster.location, process->tlsMaster.size, process->tlsMaster.userThreadOffset);
97+
logDebug("%! created TLS master: %h, size: %h, uTO: %x", "elf", process->tlsMaster.location, process->tlsMaster.size, process->tlsMaster.userThreadOffset);
9898
}

kernel/src/kernel/tasking/tasking_state.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@
2525
void taskingStateReset(g_task* task, g_address rip, g_security_level entryLevel)
2626
{
2727
g_processor_state* state;
28-
if(entryLevel == G_SECURITY_LEVEL_KERNEL && task->securityLevel > G_SECURITY_LEVEL_KERNEL)
28+
if(task->securityLevel > G_SECURITY_LEVEL_KERNEL)
2929
state = (g_processor_state*) (task->interruptStack.end - sizeof(g_processor_state));
3030
else
3131
state = (g_processor_state*) (task->stack.end - sizeof(g_processor_state));
32-
3332
task->state = state;
3433

3534
memorySetBytes((void*) task->state, 0, sizeof(g_processor_state));
3635
state->rflags = 0x20202;
37-
state->rsp = (g_virtual_address) task->state;
36+
37+
if(entryLevel > G_SECURITY_LEVEL_KERNEL)
38+
state->rsp = task->stack.end - 0x8; // TODO Find out why BOTH this and alignment in crt0 is required
39+
else
40+
state->rsp = (g_virtual_address) task->state;
3841

3942
if(entryLevel == G_SECURITY_LEVEL_KERNEL)
4043
{

libc/crt/x86_64/crt0.S

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,8 @@
2727

2828
# The <_start> function is where the kernel starts the execution.
2929
_start:
30-
mov %rsp, %rax
31-
and $0xf, %rax
32-
jz _skipAlignment
33-
34-
sub %rax, %rsp
35-
add $16, %rsp
36-
37-
_skipAlignment:
30+
xorq %rbp, %rbp
31+
andq $-16, %rsp
3832
call __g_main
3933

4034
# Endless loop, for the case that bad things happen

0 commit comments

Comments
 (0)