diff --git a/Makefile b/Makefile index dab704af6b..fcc55e2986 100644 --- a/Makefile +++ b/Makefile @@ -371,7 +371,8 @@ $(out)/bsd/%.o: INCLUDES += -isystem bsd/ # for machine/ $(out)/bsd/%.o: INCLUDES += -isystem bsd/$(arch) -configuration-defines = conf-preempt conf-debug_memory conf-logger_debug conf-debug_elf +configuration-defines = conf-preempt conf-debug_memory conf-logger_debug conf-debug_elf \ + conf-lazy_stack conf-lazy_stack_invariant configuration = $(foreach cf,$(configuration-defines), \ -D$(cf:conf-%=CONF_%)=$($(cf))) diff --git a/arch/aarch64/arch.hh b/arch/aarch64/arch.hh index abee09845c..6756ed2c4d 100644 --- a/arch/aarch64/arch.hh +++ b/arch/aarch64/arch.hh @@ -20,6 +20,20 @@ namespace arch { #define INSTR_SIZE_MIN 4 #define ELF_IMAGE_START (OSV_KERNEL_VM_BASE + 0x10000) +#if CONF_lazy_stack +inline void ensure_next_stack_page() { + u64 i, offset = -4096; + asm volatile("ldr %0, [sp, %1]" : "=r"(i) : "r"(offset)); +} + +inline void ensure_next_two_stack_pages() { + u64 i, offset = -4096; + asm volatile("ldr %0, [sp, %1]" : "=r"(i) : "r"(offset)); + offset = -8192; + asm volatile("ldr %0, [sp, %1]" : "=r"(i) : "r"(offset)); +} +#endif + inline void irq_disable() { processor::irq_disable(); diff --git a/arch/x64/arch.hh b/arch/x64/arch.hh index 17df5f5c01..0ecc123c2a 100644 --- a/arch/x64/arch.hh +++ b/arch/x64/arch.hh @@ -20,6 +20,19 @@ namespace arch { #define INSTR_SIZE_MIN 1 #define ELF_IMAGE_START OSV_KERNEL_BASE +#if CONF_lazy_stack +inline void ensure_next_stack_page() { + char i; + asm volatile("movb -4096(%%rsp), %0" : "=r"(i)); +} + +inline void ensure_next_two_stack_pages() { + char i; + asm volatile("movb -4096(%%rsp), %0" : "=r"(i)); + asm volatile("movb -8192(%%rsp), %0" : "=r"(i)); +} +#endif + inline void irq_disable() { processor::cli(); diff --git a/conf/base.mk b/conf/base.mk index b4415a7464..6b40da9fc2 100644 --- a/conf/base.mk +++ b/conf/base.mk @@ -13,3 +13,6 @@ conf-DEBUG_BUILD=0 conf-debug_elf=0 conf_hide_symbols=0 conf_linker_extra_options= + +conf-lazy_stack=0 +conf-lazy_stack_invariant=0