Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IqscW-0001Wc-A7 for mharc-grub-devel@gnu.org; Sat, 10 Nov 2007 10:51:40 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IqscT-0001WB-UT for grub-devel@gnu.org; Sat, 10 Nov 2007 10:51:37 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IqscS-0001VN-5t for grub-devel@gnu.org; Sat, 10 Nov 2007 10:51:37 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IqscS-0001VK-0b for grub-devel@gnu.org; Sat, 10 Nov 2007 10:51:36 -0500 Received: from smtp-vbr5.xs4all.nl ([194.109.24.25]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IqscR-0004s7-9u for grub-devel@gnu.org; Sat, 10 Nov 2007 10:51:35 -0500 Received: from localhost.localdomain (249-174.surfsnel.dsl.internl.net [145.99.174.249]) by smtp-vbr5.xs4all.nl (8.13.8/8.13.8) with ESMTP id lAAFpXmx058016 for ; Sat, 10 Nov 2007 16:51:34 +0100 (CET) (envelope-from mgerards@xs4all.nl) From: Marco Gerards To: The development of GRUB 2 References: <20071104002124.GA3847@boeglin.org> <17c7a07b047ea8ce974b5d91244227e9@boeglin.org> Mail-Copies-To: mgerards@xs4all.nl Date: Sat, 10 Nov 2007 16:52:08 +0100 In-Reply-To: <17c7a07b047ea8ce974b5d91244227e9@boeglin.org> (Alexandre Boeglin's message of "Tue, 6 Nov 2007 00:10:35 +0100") Message-ID: <878x56hzdj.fsf@xs4all.nl> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 Subject: Re: grub2 efi patches X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Nov 2007 15:51:38 -0000 Alexandre Boeglin writes: > On Sun, 4 Nov 2007 01:21:24 +0100, Alexandre Boeglin > wrote: >> Le Sun, Nov 04, 2007 at 01:04:24AM +0100, Alexandre Boeglin a =E9crit : >>> Sorry, there was a mistake in the previous one ... >> Oops, and line 91 of this one should be > > Hi, here is a "more correct" version of this patch: it also frees the > memory allocated to the options string when appropriate. I should've started with this patch ;-) I can better do a full review again for clarity :-) > Index: include/grub/efi/chainloader.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /sources/grub/grub2/include/grub/efi/chainloader.h,v > retrieving revision 1.2 > diff -u -r1.2 chainloader.h > --- include/grub/efi/chainloader.h 21 Jul 2007 23:32:22 -0000 1.2 > +++ include/grub/efi/chainloader.h 5 Nov 2007 22:58:51 -0000 > @@ -19,6 +19,6 @@ > #ifndef GRUB_EFI_CHAINLOADER_HEADER > #define GRUB_EFI_CHAINLOADER_HEADER 1 >=20=20 > -void grub_chainloader_cmd (const char *filename); > +void grub_chainloader_cmd (int argc, char *argv[]); >=20=20 > #endif /* ! GRUB_EFI_CHAINLOADER_HEADER */ > Index: loader/efi/chainloader.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /sources/grub/grub2/loader/efi/chainloader.c,v > retrieving revision 1.2 > diff -u -r1.2 chainloader.c > --- loader/efi/chainloader.c 21 Jul 2007 23:32:28 -0000 1.2 > +++ loader/efi/chainloader.c 5 Nov 2007 22:58:58 -0000 > @@ -17,8 +17,6 @@ > * along with GRUB. If not, see . > */ >=20=20 > -/* TODO: support load options. */ > - > #include > #include > #include > @@ -38,6 +36,8 @@ >=20=20 > static grub_efi_physical_address_t address; > static grub_efi_uintn_t pages; > +static grub_efi_char16_t *options; > +static grub_efi_uintn_t options_len; > static grub_efi_device_path_t *file_path; > static grub_efi_handle_t image_handle; >=20=20 > @@ -49,6 +49,8 @@ > b =3D grub_efi_system_table->boot_services; > b->unload_image (image_handle); > b->free_pages (address, pages); > + if (options) > + b->free_pool (options); > grub_free (file_path); >=20=20=20=20 > grub_dl_unref (my_mod); > @@ -175,7 +177,7 @@ > } >=20=20 > void > -grub_chainloader_cmd (const char *filename) > +grub_chainloader_cmd (int argc, char *argv[]) > { > grub_file_t file =3D 0; > grub_ssize_t size; > @@ -185,16 +187,47 @@ > grub_device_t dev =3D 0; > grub_efi_device_path_t *dp =3D 0; > grub_efi_loaded_image_t *loaded_image; > + char *filename =3D argv[0]; >=20=20=20=20 > grub_dl_ref (my_mod); >=20=20 > /* Initialize some global variables. */ > address =3D 0; > + options =3D 0; > + options_len =3D 0; > image_handle =3D 0; > file_path =3D 0; >=20=20=20=20 > b =3D grub_efi_system_table->boot_services; >=20=20 > + if (argc =3D=3D 0) > + { > + grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); > + goto fail; > + } The indentation is not right. > + /* copy options */ /* Copy options. */ > + if (argc > 1) > + { The indentation is not right. > + grub_efi_char16_t *p; > + grub_efi_int16_t i; > + grub_efi_uint16_t j; > + for (i =3D 1; i < argc; i++) > + options_len +=3D (grub_strlen (argv[i]) + 1) * sizeof (*options); > + options_len +=3D sizeof (*options); /* \0 */ > + > + status =3D b->allocate_pool (GRUB_EFI_LOADER_DATA, options_len, (voi= d *) &options); > + if (status !=3D GRUB_EFI_SUCCESS) > + goto fail; > + p =3D options; Please use grub_malloc here, I think it should work for what you are doing, right? > + for (i =3D 1; i < argc; i++){ > + *p++ =3D ' '; > + for (j =3D 0; j < grub_strlen (argv[i]) + 1; j++) > + p[j] =3D (grub_efi_char16_t) argv[i][j]; > + } > + } > + > file =3D grub_file_open (filename); > if (! file) > goto fail; > @@ -268,6 +301,10 @@ > } > loaded_image->device_handle =3D dev_handle; >=20=20=20=20 > + if (options_len) > + loaded_image->load_options =3D options; > + loaded_image->load_options_size =3D options_len; The second loaded_image... line seems to be incorrectly indented. > grub_file_close (file); > grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); > return; > @@ -286,16 +323,16 @@ > if (address) > b->free_pages (address, pages); >=20=20=20=20 > + if (options) > + b->free_pool (options); > + > grub_dl_unref (my_mod); > } >=20=20 > static void > grub_rescue_cmd_chainloader (int argc, char *argv[]) > { > - if (argc =3D=3D 0) > - grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); > - else > - grub_chainloader_cmd (argv[0]); > + grub_chainloader_cmd (argc, argv); > } >=20=20 > static const char loader_name[] =3D "chainloader"; > Index: loader/efi/chainloader_normal.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /sources/grub/grub2/loader/efi/chainloader_normal.c,v > retrieving revision 1.2 > diff -u -r1.2 chainloader_normal.c > --- loader/efi/chainloader_normal.c 21 Jul 2007 23:32:28 -0000 1.2 > +++ loader/efi/chainloader_normal.c 5 Nov 2007 22:58:59 -0000 > @@ -26,10 +26,7 @@ > chainloader_command (struct grub_arg_list *state __attribute__ ((unused)= ), > int argc, char **args) > { > - if (argc =3D=3D 0) > - grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); > - else > - grub_chainloader_cmd (args[0]); > + grub_chainloader_cmd (argc, args); > return grub_errno; > }