Re: swsusp critical code rewritten to assembly

Linus Torvalds (torvalds@transmeta.com)
Sun, 10 Nov 2002 11:18:42 -0800 (PST)


On Sun, 10 Nov 2002, Pavel Machek wrote:
>
> do_magic was really too fragile to be written in C. This patch
> rewrites it into assembly, to make sure C compiler does not generate
> stack access and corrupt memory that way. Plus it cleans up suspend.c
> a bit, makes it really free memory it needs, an no longer calls
> drivers from atomic context.

But this still has stuff in C:

> + asm volatile ("movl %0, %%esp" :: "m" (saved_context_esp));
> + asm volatile ("movl %0, %%ebp" :: "m" (saved_context_ebp));
> + asm volatile ("movl %0, %%eax" :: "m" (saved_context_eax));
> + asm volatile ("movl %0, %%ebx" :: "m" (saved_context_ebx));
> + asm volatile ("movl %0, %%ecx" :: "m" (saved_context_ecx));
> + asm volatile ("movl %0, %%edx" :: "m" (saved_context_edx));
> + asm volatile ("movl %0, %%esi" :: "m" (saved_context_esi));
> + asm volatile ("movl %0, %%edi" :: "m" (saved_context_edi));
>
> - fix_processor_context();
> + restore_processor_state();

What's up with that? There's no way you can safely restore regular
registers and _especially_ %%esp from C code, since the compiler may be
using them for other things.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/