From: Marc Fiuczynski Date: Fri, 28 Jan 2005 05:09:30 +0000 (+0000) Subject: moved stackoverflow checking out of mainline files X-Git-Tag: before-fedora-2_6_18-1_2239_FC5-vs2_0_2_2-rc6-merge~281 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=a3277795332eac2b562d2244307ade952ede7966;p=linux-2.6.git moved stackoverflow checking out of mainline files --- diff --git a/arch/i386/kernel/Makefile b/arch/i386/kernel/Makefile index 41fe596ed..34662b987 100644 --- a/arch/i386/kernel/Makefile +++ b/arch/i386/kernel/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_ACPI_SRAT) += srat.o obj-$(CONFIG_HPET_TIMER) += time_hpet.o obj-$(CONFIG_EFI) += efi.o efi_stub.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o +obj-$(CONFIG_X86_STACK_CHECK) += dstackdump.o dstack.o stackoverflow.o EXTRA_AFLAGS := -traditional -m32 diff --git a/arch/i386/kernel/dstack.S b/arch/i386/kernel/dstack.S new file mode 100644 index 000000000..cef679947 --- /dev/null +++ b/arch/i386/kernel/dstack.S @@ -0,0 +1,63 @@ +/* + * linux/arch/i386/dstack.S + * + * Copyright (C) 2005 Marc E. Fiuczynski + */ + +/* + * dstack.s contains the system specific support for stack overflows + * and discontiguous stack support. + */ + +#include +#include +#include +#include +#include +#include +#include + +.data +.globl stack_overflowed +stack_overflowed: + .long 0 +.text + +ENTRY(mcount) +#warning stack check enabled + push %eax + movl $(THREAD_SIZE - 1),%eax + andl %esp,%eax + cmpl $STACK_WARN,%eax + jle 1f +2: + popl %eax + ret +1: + /* prevent infinite recursion from call to mcount from the + * stack_overflow function. Need to revisit this code for + * SMP based systems. + */ + lock; btsl $0,stack_overflowed + jc 2b + + /* prepare to jmp to stack_overflow directly, as if it were + * called directly by the caller of mcount. + */ + pushl %ebp + pushl %ebx + pushl %esi + pushl %edi + + call stack_overflow + /* Note that stack_overflow() will clear the stack_overflowed + * variable. + */ + + popl %edi + popl %esi + popl %ebx + popl %ebp + + popl %eax + ret diff --git a/arch/i386/kernel/dstackdump.c b/arch/i386/kernel/dstackdump.c new file mode 100644 index 000000000..9aad728e7 --- /dev/null +++ b/arch/i386/kernel/dstackdump.c @@ -0,0 +1,41 @@ +/* + * linux/arch/i386/kernel/stackoverflow.c + * + * Copyright (C) 2005 Marc E. Fiuczynski + * + */ + +/* + * This file handles the architecture-dependent parts of stack overflow handling... + */ + +#include +#include +#include +#include + +void dstackdump(void) +{ + unsigned long esp = current_stack_pointer(); + int panicing = ((esp&(THREAD_SIZE-1)) <= STACK_PANIC); + + oops_in_progress = 1; + printk( "esp: 0x%lx masked: 0x%lx STACK_PANIC:0x%lx %d %d\n", + esp, (esp&(THREAD_SIZE-1)), STACK_PANIC, + (((esp&(THREAD_SIZE-1)) <= STACK_PANIC)), panicing); + + show_trace(current,(void*)esp); + + if (panicing) + panic("stack overflow\n"); + + oops_in_progress = 0; + + /* Just let it happen once per task, as otherwise it goes nuts + * in printing stack traces. This means that I need to dump + * the stack_overflowed boolean into the task or thread_info + * structure. For now just turn it off all together. + */ + + /* stack_overflowed = 0; */ +} diff --git a/arch/i386/kernel/entry.S b/arch/i386/kernel/entry.S index b52697129..9f6ccd5a9 100644 --- a/arch/i386/kernel/entry.S +++ b/arch/i386/kernel/entry.S @@ -917,55 +917,7 @@ ENTRY(sys_call_table) #ifdef USE_IOPRIO_SYSCALLS .long sys_ioprio_set /* 285 */ .long sys_ioprio_get -#else -#warning MEF not includig sys_ioprio_{set,get} syscalls #endif syscall_table_size=(.-sys_call_table) -#ifdef CONFIG_X86_STACK_CHECK -.data -.globl stack_overflowed -stack_overflowed: - .long 0 -.text - -ENTRY(mcount) -#warning stack check enabled - push %eax - movl $(THREAD_SIZE - 1),%eax - andl %esp,%eax - cmpl $STACK_WARN,%eax - jle 1f -2: - popl %eax - ret -1: - /* prevent infinite recursion from call to mcount from the - * stack_overflow function. Need to revisit this code for - * SMP based systems. - */ - lock; btsl $0,stack_overflowed - jc 2b - - /* prepare to jmp to stack_overflow directly, as if it were - * called directly by the caller of mcount. - */ - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - - call stack_overflow - /* Note that stack_overflow() will clear the stack_overflowed - * variable. - */ - - popl %edi - popl %esi - popl %ebx - popl %ebp - - popl %eax - ret -#endif diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c index 6c00d694a..1e35bf32c 100644 --- a/arch/i386/kernel/process.c +++ b/arch/i386/kernel/process.c @@ -221,31 +221,6 @@ static int __init idle_setup (char *str) __setup("idle=", idle_setup); -void stack_overflow(void) -{ - unsigned long esp = current_stack_pointer(); - int panicing = ((esp&(THREAD_SIZE-1)) <= STACK_PANIC); - - oops_in_progress = 1; - printk( "esp: 0x%lx masked: 0x%lx STACK_PANIC:0x%lx %d %d\n", - esp, (esp&(THREAD_SIZE-1)), STACK_PANIC, - (((esp&(THREAD_SIZE-1)) <= STACK_PANIC)), panicing); - show_trace(current,(void*)esp); - - if (panicing) - panic("stack overflow\n"); - - oops_in_progress = 0; - - /* Just let it happen once per task, as otherwise it goes nuts - * in printing stack traces. This means that I need to dump - * the stack_overflowed boolean into the task or thread_info - * structure. For now just turn it off all together. - */ - - /* stack_overflowed = 0; */ -} - void show_regs(struct pt_regs * regs) { unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L; diff --git a/arch/i386/kernel/stackoverflow.c b/arch/i386/kernel/stackoverflow.c new file mode 100644 index 000000000..f9b9f6f90 --- /dev/null +++ b/arch/i386/kernel/stackoverflow.c @@ -0,0 +1,40 @@ +/* + * linux/arch/i386/kernel/stackoverflow.c + * + * Copyright (C) 2005 Marc E. Fiuczynski + * + */ + +/* + * This file handles the architecture-dependent parts of stack overflow handling... + */ + +#include +#include +#include +#include + +void stack_overflow(void) +{ + unsigned long esp = current_stack_pointer(); + int panicing = ((esp&(THREAD_SIZE-1)) <= STACK_PANIC); + + oops_in_progress = 1; + printk( "esp: 0x%lx masked: 0x%lx STACK_PANIC:0x%lx %d %d\n", + esp, (esp&(THREAD_SIZE-1)), STACK_PANIC, + (((esp&(THREAD_SIZE-1)) <= STACK_PANIC)), panicing); + show_trace(current,(void*)esp); + + if (panicing) + panic("stack overflow\n"); + + oops_in_progress = 0; + + /* Just let it happen once per task, as otherwise it goes nuts + * in printing stack traces. This means that I need to dump + * the stack_overflowed boolean into the task or thread_info + * structure. For now just turn it off all together. + */ + + /* stack_overflowed = 0; */ +}