and implement windows variant.
+2013-12-08 Vladimir Serbinenko <phcoder@gmail.com>
+
+ Move OS-dependent mprotect for module loading to grub-core/osdep/*/dl.c
+ and implement windows variant.
+
2013-12-08 Vladimir Serbinenko <phcoder@gmail.com>
Fix mips-emu compilation.
emu = osdep/emuconsole.c;
extra_dist = osdep/unix/emuconsole.c;
extra_dist = osdep/windows/emuconsole.c;
+ emu = osdep/dl.c;
+ extra_dist = osdep/unix/dl.c;
+ extra_dist = osdep/windows/dl.c;
emu = osdep/sleep.c;
emu = osdep/init.c;
emu = osdep/emunet.c;
#define GRUB_MODULES_MACHINE_READONLY
#endif
-#ifdef GRUB_MACHINE_EMU
-#include <sys/mman.h>
-#endif
-
\f
#pragma GCC diagnostic ignored "-Wcast-align"
#endif
#ifdef GRUB_MACHINE_EMU
- if (talign < 8192 * 16)
- talign = 8192 * 16;
- tsize = ALIGN_UP (tsize, 8192 * 16);
-#endif
-
+ mod->base = grub_osdep_dl_memalign (talign, tsize);
+#else
mod->base = grub_memalign (talign, tsize);
+#endif
if (!mod->base)
return grub_errno;
mod->sz = tsize;
ptr = mod->base;
-#ifdef GRUB_MACHINE_EMU
- mprotect (mod->base, tsize, PROT_READ | PROT_WRITE | PROT_EXEC);
-#endif
-
for (i = 0, s = (Elf_Shdr *)((char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (Elf_Shdr *)((char *) s + e->e_shentsize))
grub_free (dep);
}
+#ifdef GRUB_MACHINE_EMU
+ grub_dl_osdep_dl_free (mod->base);
+#else
grub_free (mod->base);
+#endif
grub_free (mod->name);
#ifdef GRUB_MODULES_MACHINE_READONLY
grub_free (mod->symtab);
--- /dev/null
+#if defined (__MINGW32__) || defined (__CYGWIN__)
+#include "windows/dl.c"
+#else
+#include "unix/dl.c"
+#endif
--- /dev/null
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <config-util.h>
+
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <string.h>
+
+void *
+grub_osdep_dl_memalign (grub_size_t align, grub_size_t size)
+{
+ void *ret;
+ if (align < 8192 * 16)
+ align = 8192 * 16;
+ size = ALIGN_UP (size, 8192 * 16);
+
+#if defined(HAVE_POSIX_MEMALIGN)
+ if (posix_memalign (&ret, align, size) != 0)
+ ret = 0;
+#elif defined(HAVE_MEMALIGN)
+ ret = memalign (align, size);
+#else
+#error "Complete this"
+#endif
+
+ if (!ret)
+ {
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+ return NULL;
+ }
+
+ mprotect (ret, size, PROT_READ | PROT_WRITE | PROT_EXEC);
+ return ret;
+}
+
+void
+grub_dl_osdep_dl_free (void *ptr)
+{
+ if (ptr)
+ free (ptr);
+}
--- /dev/null
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <config-util.h>
+
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+void *
+grub_osdep_dl_memalign (grub_size_t align, grub_size_t size)
+{
+ void *ret;
+ if (align > 4096)
+ {
+ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("too large alignment"));
+ return NULL;
+ }
+
+ size = ALIGN_UP (size, 4096);
+
+ ret = VirtualAlloc (NULL, size, MEM_COMMIT | MEM_RESERVE,
+ PAGE_EXECUTE_READWRITE);
+
+ if (!ret)
+ {
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+ return NULL;
+ }
+
+ return ret;
+}
+
+void
+grub_dl_osdep_dl_free (void *ptr)
+{
+ if (!ptr)
+ return;
+ VirtualFree (ptr, 0, MEM_RELEASE);
+}
#define FOR_DL_MODULES(var) FOR_LIST_ELEMENTS ((var), (grub_dl_head))
+#ifdef GRUB_MACHINE_EMU
+void *
+grub_osdep_dl_memalign (grub_size_t align, grub_size_t size);
+void
+grub_dl_osdep_dl_free (void *ptr);
+#endif
+
static inline void
grub_dl_init (grub_dl_t mod)
{