Skip to content

Commit

Permalink
stack: increase size of the interrupt and small syscall stack in debu…
Browse files Browse the repository at this point in the history
…g mode

When building OSv with newer GCC (>= 12) in debug mode, the interrupt
handler running on dedicated stack needs more than 1 page otherwise it
causes overflow. Similarly, the code setting up large syscall stack,
running on small 2K stack runs of of space as well.

To fix this, we increase the interrupt stack size to 8K and small
syscall stack size to 8K when building in debug mode (#ifndef NDEBUG).

Ideally, in long term we should implement some canary-based logic to
detect interrupt stack overflow as the issue #1339 explains.

Ref #1339

Signed-off-by: Waldemar Kozaczuk <[email protected]>
  • Loading branch information
wkozaczuk committed Nov 13, 2024
1 parent 8425481 commit 6ddf46b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions arch/x64/arch-cpu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ struct arch_cpu {
};

struct arch_thread {
#ifndef NDEBUG
char interrupt_stack[4096*2] __attribute__((aligned(16)));
#else
char interrupt_stack[4096] __attribute__((aligned(16)));
#endif
char exception_stack[4096*4] __attribute__((aligned(16)));
};

Expand Down
4 changes: 4 additions & 0 deletions arch/x64/arch-switch.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
// to detect potential tiny stack overflow.
// All application threads pre-allocate tiny syscall stack so there
// is a tiny penalty with this solution.
#ifndef NDEBUG
#define TINY_SYSCALL_STACK_SIZE 2*4096
#else
#define TINY_SYSCALL_STACK_SIZE 2048
#endif
#define TINY_SYSCALL_STACK_DEPTH (TINY_SYSCALL_STACK_SIZE - SYSCALL_STACK_RESERVED_SPACE_SIZE)
//
// The large syscall stack is setup and switched to on first
Expand Down

0 comments on commit 6ddf46b

Please sign in to comment.