diff --git a/include/grub/i386/memory.h.moved b/include/grub/i386/memory.h.moved new file mode 100644 index 000000000..a0f3192b8 --- /dev/null +++ b/include/grub/i386/memory.h.moved @@ -0,0 +1,30 @@ +/* memory.h - describe the memory map */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2007,2008 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 . + */ + +#ifndef GRUB_MEMORY_CPU_HEADER +#define GRUB_MEMORY_CPU_HEADER 1 + +/* The flag for protected mode. */ +#define GRUB_MEMORY_CPU_CR0_PE_ON 0x1 +#define GRUB_MEMORY_CPU_CR4_PAE_ON 0x00000040 +#define GRUB_MEMORY_CPU_CR0_PAGING_ON 0x80000000 +#define GRUB_MEMORY_CPU_AMD64_MSR 0xc0000080 +#define GRUB_MEMORY_CPU_AMD64_MSR_ON 0x00000100 + +#endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/i386/relocator.h.moved b/include/grub/i386/relocator.h.moved new file mode 100644 index 000000000..ef7fe23aa --- /dev/null +++ b/include/grub/i386/relocator.h.moved @@ -0,0 +1,41 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 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 . + */ + +#ifndef GRUB_RELOCATOR_CPU_HEADER +#define GRUB_RELOCATOR_CPU_HEADER 1 + +#include +#include + +struct grub_relocator32_state +{ + grub_uint32_t esp; + grub_uint32_t eax; + grub_uint32_t ebx; + grub_uint32_t ecx; + grub_uint32_t edx; + grub_uint32_t eip; +}; + +void *grub_relocator32_alloc (grub_size_t size); +grub_err_t grub_relocator32_boot (void *relocator, grub_uint32_t dest, + struct grub_relocator32_state state); +void *grub_relocator32_realloc (void *relocator, grub_size_t size); +void grub_relocator32_free (void *relocator); + +#endif /* ! GRUB_RELOCATOR_CPU_HEADER */ diff --git a/lib/i386/relocator.c.moved b/lib/i386/relocator.c.moved new file mode 100644 index 000000000..ae7caf28b --- /dev/null +++ b/lib/i386/relocator.c.moved @@ -0,0 +1,102 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 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 . + */ + +#include +#include + +#include +#include +#include + +#include + +extern grub_uint8_t grub_relocator32_forward_start; +extern grub_uint8_t grub_relocator32_forward_end; +extern grub_uint8_t grub_relocator32_backward_start; +extern grub_uint8_t grub_relocator32_backward_end; + +extern grub_uint32_t grub_relocator32_backward_dest; +extern grub_uint32_t grub_relocator32_backward_size; +extern grub_addr_t grub_relocator32_backward_src; + +extern grub_uint32_t grub_relocator32_forward_dest; +extern grub_uint32_t grub_relocator32_forward_size; +extern grub_addr_t grub_relocator32_forward_src; + +extern grub_uint32_t grub_relocator32_forward_eax; +extern grub_uint32_t grub_relocator32_forward_ebx; +extern grub_uint32_t grub_relocator32_forward_ecx; +extern grub_uint32_t grub_relocator32_forward_edx; +extern grub_uint32_t grub_relocator32_forward_eip; +extern grub_uint32_t grub_relocator32_forward_esp; + +extern grub_uint32_t grub_relocator32_backward_eax; +extern grub_uint32_t grub_relocator32_backward_ebx; +extern grub_uint32_t grub_relocator32_backward_ecx; +extern grub_uint32_t grub_relocator32_backward_edx; +extern grub_uint32_t grub_relocator32_backward_eip; +extern grub_uint32_t grub_relocator32_backward_esp; + +#define RELOCATOR_SIZEOF(x) (&grub_relocator32_##x##_end - &grub_relocator32_##x##_start) +#define RELOCATOR_ALIGN 16 +#define PREFIX(x) grub_relocator32_ ## x + +static void +write_call_relocator_bw (void *ptr, void *src, grub_uint32_t dest, + grub_size_t size, struct grub_relocator32_state state) +{ + grub_relocator32_backward_dest = dest; + grub_relocator32_backward_src = PTR_TO_UINT64 (src); + grub_relocator32_backward_size = size; + + grub_relocator32_backward_eax = state.eax; + grub_relocator32_backward_ebx = state.ebx; + grub_relocator32_backward_ecx = state.ecx; + grub_relocator32_backward_edx = state.edx; + grub_relocator32_backward_eip = state.eip; + grub_relocator32_backward_esp = state.esp; + + grub_memmove (ptr, + &grub_relocator32_backward_start, + RELOCATOR_SIZEOF (backward)); + ((void (*) (void)) ptr) (); +} + +static void +write_call_relocator_fw (void *ptr, void *src, grub_uint32_t dest, + grub_size_t size, struct grub_relocator32_state state) +{ + + grub_relocator32_forward_dest = dest; + grub_relocator32_forward_src = PTR_TO_UINT64 (src); + grub_relocator32_forward_size = size; + + grub_relocator32_forward_eax = state.eax; + grub_relocator32_forward_ebx = state.ebx; + grub_relocator32_forward_ecx = state.ecx; + grub_relocator32_forward_edx = state.edx; + grub_relocator32_forward_eip = state.eip; + grub_relocator32_forward_esp = state.esp; + + grub_memmove (ptr, + &grub_relocator32_forward_start, + RELOCATOR_SIZEOF (forward)); + ((void (*) (void)) ptr) (); +} + +#include "../relocator.c" diff --git a/lib/i386/relocator_asm.S b/lib/i386/relocator_asm.S index 343991d3d..bd25143e8 100644 --- a/lib/i386/relocator_asm.S +++ b/lib/i386/relocator_asm.S @@ -208,7 +208,7 @@ RELOCATOR_VARIABLE (edx) .byte 0xea RELOCATOR_VARIABLE (eip) .long 0 - .word 0x08 + .word CODE_SEGMENT /* GDT. Copied from loader/i386/linux.c. */ .p2align 4 diff --git a/lib/i386/relocator_backward.S.moved b/lib/i386/relocator_backward.S.moved new file mode 100644 index 000000000..06913470e --- /dev/null +++ b/lib/i386/relocator_backward.S.moved @@ -0,0 +1,2 @@ +#define BACKWARD +#include "relocator_asm.S" diff --git a/lib/relocator.c b/lib/relocator.c index bebf7ada9..54b8c1a17 100644 --- a/lib/relocator.c +++ b/lib/relocator.c @@ -16,15 +16,17 @@ * along with GRUB. If not, see . */ +#define MAX_OVERHEAD ((RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) \ + + (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN) \ + + (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) \ + + (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN)) + void * PREFIX (alloc) (grub_size_t size) { char *playground; - playground = grub_malloc ((RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) - + size - + (RELOCATOR_SIZEOF (backward) + - RELOCATOR_ALIGN)); + playground = grub_malloc (size + MAX_OVERHEAD); if (!playground) return 0; @@ -40,10 +42,7 @@ PREFIX (realloc) (void *relocator, grub_size_t size) playground = (char *) relocator - RELOCATOR_SIZEOF (forward); - playground = grub_realloc (playground, - (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) - + size - + (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN)); + playground = grub_realloc (playground, size + MAX_OVERHEAD); if (!playground) return 0; @@ -73,6 +72,25 @@ PREFIX (boot) (void *relocator, grub_uint32_t dest, "Relocator: source: %p, destination: 0x%x, size: 0x%x\n", relocator, dest, size); + /* Very unlikely condition: Relocator may risk overwrite itself. + Just move it a bit up. */ + if ((grub_uint8_t *) UINT_TO_PTR (dest) - (grub_uint8_t *) relocator + < (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN) + && (grub_uint8_t *) UINT_TO_PTR (dest) - (grub_uint8_t *) relocator + > - (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN)) + { + void *relocator_new = ((grub_uint8_t *) relocator) + + (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) + + (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN); + grub_dprintf ("relocator", "Overwrite condition detected moving " + "relocator from %p to %p\n", relocator, relocator_new); + grub_memmove (relocator_new, relocator, + (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) + + size + + (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN)); + relocator = relocator_new; + } + if (UINT_TO_PTR (dest) >= relocator) { int overhead; diff --git a/po/ca.po b/po/ca.po index 948cb4f52..a72601c84 100644 --- a/po/ca.po +++ b/po/ca.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: GNU GRUB\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-11-25 23:02+0100\n" +"POT-Creation-Date: 2009-11-25 23:35+0100\n" "PO-Revision-Date: 2009-11-17 12:26+0100\n" "Last-Translator: Robert Millan \n" "Language-Team: None \n" @@ -14,33 +14,38 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -#: util/grub-mkrawimage.c:66 +#: util/i386/pc/grub-mkimage.c:65 msgid "the core image is too small" msgstr "" -#: util/grub-mkrawimage.c:78 +#: util/i386/pc/grub-mkimage.c:77 msgid "cannot compress the kernel image" msgstr "" -#: util/grub-mkrawimage.c:152 -msgid "prefix too long" +#: util/i386/pc/grub-mkimage.c:138 +msgid "prefix is too long" msgstr "" -#: util/grub-mkrawimage.c:236 +#: util/i386/pc/grub-mkimage.c:206 msgid "the core image is too big" msgstr "" -#: util/grub-mkrawimage.c:241 +#: util/i386/pc/grub-mkimage.c:211 #, c-format msgid "diskboot.img size must be %u bytes" msgstr "" -#: util/grub-mkrawimage.c:315 +#: util/i386/pc/grub-mkimage.c:284 #, c-format msgid "Core image is too big (%p > %p)\n" msgstr "" -#: util/grub-mkrawimage.c:424 +#: util/i386/pc/grub-mkimage.c:321 util/i386/pc/grub-setup.c:589 +#, c-format +msgid "Try ``%s --help'' for more information.\n" +msgstr "Proveu «%s --help» per a obtenir més informació.\n" + +#: util/i386/pc/grub-mkimage.c:323 #, c-format msgid "" "Usage: grub-mkimage [OPTION]... [MODULES]\n" @@ -50,13 +55,16 @@ msgid "" " -d, --directory=DIR use images and modules under DIR [default=%s]\n" " -p, --prefix=DIR set grub_prefix directory [default=%s]\n" " -m, --memdisk=FILE embed FILE as a memdisk image\n" -" -f, --font=FILE embed FILE as a boot font\n" " -c, --config=FILE embed FILE as boot config\n" " -o, --output=FILE output a generated image to FILE [default=stdout]\n" -" -O, --format=FORMAT generate an image in format [default=" +" -h, --help display this message and exit\n" +" -V, --version print version information and exit\n" +" -v, --verbose print verbose messages\n" +"\n" +"Report bugs to <%s>.\n" msgstr "" -#: util/grub-mkrawimage.c:566 +#: util/i386/pc/grub-mkimage.c:429 #, c-format msgid "cannot open %s" msgstr "" @@ -186,11 +194,6 @@ msgstr "" msgid "Cannot open `%s'" msgstr "" -#: util/i386/pc/grub-setup.c:589 -#, c-format -msgid "Try ``%s --help'' for more information.\n" -msgstr "Proveu «%s --help» per a obtenir més informació.\n" - #: util/i386/pc/grub-setup.c:591 #, c-format msgid "" diff --git a/po/id.po b/po/id.po index b77677332..69692a003 100644 --- a/po/id.po +++ b/po/id.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: grub 1.97+20091122\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-11-25 23:02+0100\n" +"POT-Creation-Date: 2009-11-25 23:35+0100\n" "PO-Revision-Date: 2009-11-22 20:00+0700\n" "Last-Translator: Arif E. Nugroho \n" "Language-Team: Indonesian \n" @@ -15,35 +15,39 @@ msgstr "" "Content-Type: text/plain; charset=ISO-8859-1\n" "Content-Transfer-Encoding: 8bit\n" -#: util/grub-mkrawimage.c:66 +#: util/i386/pc/grub-mkimage.c:65 msgid "the core image is too small" msgstr "image core terlalu kecil" -#: util/grub-mkrawimage.c:78 +#: util/i386/pc/grub-mkimage.c:77 msgid "cannot compress the kernel image" msgstr "tidak dapat mengkompress image kernel" -#: util/grub-mkrawimage.c:152 -#, fuzzy -msgid "prefix too long" +#: util/i386/pc/grub-mkimage.c:138 +msgid "prefix is too long" msgstr "awalan terlalu panjang" -#: util/grub-mkrawimage.c:236 +#: util/i386/pc/grub-mkimage.c:206 msgid "the core image is too big" msgstr "image core terlalu besar" -#: util/grub-mkrawimage.c:241 +#: util/i386/pc/grub-mkimage.c:211 #, c-format msgid "diskboot.img size must be %u bytes" msgstr "besar diskboot.img seharusnya %u bytes" -#: util/grub-mkrawimage.c:315 +#: util/i386/pc/grub-mkimage.c:284 #, c-format msgid "Core image is too big (%p > %p)\n" msgstr "Image core terlalu besar (%p >%p)\n" -#: util/grub-mkrawimage.c:424 -#, fuzzy, c-format +#: util/i386/pc/grub-mkimage.c:321 util/i386/pc/grub-setup.c:589 +#, c-format +msgid "Try ``%s --help'' for more information.\n" +msgstr "Coba ``%s --help'' untuk informasi lebih lanjut.\n" + +#: util/i386/pc/grub-mkimage.c:323 +#, c-format msgid "" "Usage: grub-mkimage [OPTION]... [MODULES]\n" "\n" @@ -52,10 +56,13 @@ msgid "" " -d, --directory=DIR use images and modules under DIR [default=%s]\n" " -p, --prefix=DIR set grub_prefix directory [default=%s]\n" " -m, --memdisk=FILE embed FILE as a memdisk image\n" -" -f, --font=FILE embed FILE as a boot font\n" " -c, --config=FILE embed FILE as boot config\n" " -o, --output=FILE output a generated image to FILE [default=stdout]\n" -" -O, --format=FORMAT generate an image in format [default=" +" -h, --help display this message and exit\n" +" -V, --version print version information and exit\n" +" -v, --verbose print verbose messages\n" +"\n" +"Report bugs to <%s>.\n" msgstr "" "Penggunaan: grub-mkimage [PILIHAN]... [MODUL]\n" "\n" @@ -73,7 +80,7 @@ msgstr "" "\n" "Laporkan bugs ke <%s>.\n" -#: util/grub-mkrawimage.c:566 +#: util/i386/pc/grub-mkimage.c:429 #, c-format msgid "cannot open %s" msgstr "tidak dapat membuka %s" @@ -223,11 +230,6 @@ msgstr "Gagal untuk membaca sektor selanjutnya dari image core" msgid "Cannot open `%s'" msgstr "Tidak dapat membuka `%s'" -#: util/i386/pc/grub-setup.c:589 -#, c-format -msgid "Try ``%s --help'' for more information.\n" -msgstr "Coba ``%s --help'' untuk informasi lebih lanjut.\n" - #: util/i386/pc/grub-setup.c:591 #, c-format msgid "" diff --git a/po/zh_CN.po b/po/zh_CN.po index e78d28ac4..8858f0a6a 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: grub 1.97+20091122\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-11-25 23:02+0100\n" +"POT-Creation-Date: 2009-11-25 23:35+0100\n" "PO-Revision-Date: 2009-11-23 18:36+0800\n" "Last-Translator: Aron Xu \n" "Language-Team: Chinese (simplified) %p)\n" msgstr "核心映像太大(%p > %p)\n" -#: util/grub-mkrawimage.c:424 +#: util/i386/pc/grub-mkimage.c:321 util/i386/pc/grub-setup.c:589 +#, c-format +msgid "Try ``%s --help'' for more information.\n" +msgstr "请尝试运行 ``%s --help'' 以获得更多信息。\n" + +#: util/i386/pc/grub-mkimage.c:323 #, c-format msgid "" "Usage: grub-mkimage [OPTION]... [MODULES]\n" @@ -54,13 +58,16 @@ msgid "" " -d, --directory=DIR use images and modules under DIR [default=%s]\n" " -p, --prefix=DIR set grub_prefix directory [default=%s]\n" " -m, --memdisk=FILE embed FILE as a memdisk image\n" -" -f, --font=FILE embed FILE as a boot font\n" " -c, --config=FILE embed FILE as boot config\n" " -o, --output=FILE output a generated image to FILE [default=stdout]\n" -" -O, --format=FORMAT generate an image in format [default=" +" -h, --help display this message and exit\n" +" -V, --version print version information and exit\n" +" -v, --verbose print verbose messages\n" +"\n" +"Report bugs to <%s>.\n" msgstr "" -#: util/grub-mkrawimage.c:566 +#: util/i386/pc/grub-mkimage.c:429 #, c-format msgid "cannot open %s" msgstr "无法打开 %s" @@ -190,11 +197,6 @@ msgstr "" msgid "Cannot open `%s'" msgstr "无法打开 `%s'" -#: util/i386/pc/grub-setup.c:589 -#, c-format -msgid "Try ``%s --help'' for more information.\n" -msgstr "请尝试运行 ``%s --help'' 以获得更多信息。\n" - #: util/i386/pc/grub-setup.c:591 #, c-format msgid ""