Index: b/grub/asmstub.c =================================================================== --- a/grub/asmstub.c +++ b/grub/asmstub.c @@ -42,6 +42,12 @@ #include #include #include +#include + +#include +#ifndef PAGESIZE +#define PAGESIZE 4096 +#endif #ifdef __linux__ # include /* ioctl */ @@ -148,6 +154,22 @@ assert (grub_scratch_mem == 0); scratch = malloc (0x100000 + EXTENDED_MEMSIZE + 15); assert (scratch); + + { + char *p; + int ret; + + /* Align to a multiple of PAGESIZE, assumed to be a power of two. */ + p = (char *) (((long) scratch) & ~(PAGESIZE - 1)); + + /* The simulated stack needs to be executable, since GCC uses stack + * trampolines to implement nested functions. + */ + ret = mprotect (p, 0x100000 + EXTENDED_MEMSIZE + 15, + PROT_READ | PROT_WRITE | PROT_EXEC); + assert (ret == 0); + } + grub_scratch_mem = (char *) ((((int) scratch) >> 4) << 4); /* FIXME: simulate the memory holes using mprot, if available. */