From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KaYUi-0004yd-4A for mharc-grub-devel@gnu.org; Tue, 02 Sep 2008 12:12:40 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KaYUg-0004xo-QB for grub-devel@gnu.org; Tue, 02 Sep 2008 12:12:38 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KaYUf-0004xI-TB for grub-devel@gnu.org; Tue, 02 Sep 2008 12:12:38 -0400 Received: from [199.232.76.173] (port=46146 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KaYUf-0004x7-LP for grub-devel@gnu.org; Tue, 02 Sep 2008 12:12:37 -0400 Received: from fg-out-1718.google.com ([72.14.220.155]:8866) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KaYUf-0008Lh-91 for grub-devel@gnu.org; Tue, 02 Sep 2008 12:12:37 -0400 Received: by fg-out-1718.google.com with SMTP id l26so1612001fgb.30 for ; Tue, 02 Sep 2008 09:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :x-enigmail-version:content-type; bh=/B1w7vjccKDJepZSSJchKYhq0y0FK80t7UE/WABjzuA=; b=RmVRqGK8RrZ4sWMmQ54ipJDLz2juICkKxVrv/2gio2fxd4eYQ3KvyswqptabeFCtx1 wGLSY/PekeLn3BLT7Azj4jvaAzdADFf1fNS6UQ+sl7JqCImMMLOvxkyagf1822urCUII 5MyFrQp56xMXSZJ1d6JDTo2w4zYHGCZP8cW2E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; b=cd8Itfd5VO1ZpiglgBm3+ZW5vh5SRoHOJ7FPZ5PlsnwAb0Mq7JKUVPu5h/TZFzsKhD qq4W8Qaho6GQBj3oSnWxSisZ/La0gFAmq60DAj1XAYcSfZcz5X4bwi0QnHPqIFEM0I12 41E0mjQMWRUdZNpgfovYQu0imA7NInalTLvcg= Received: by 10.86.66.11 with SMTP id o11mr5762464fga.25.1220371956513; Tue, 02 Sep 2008 09:12:36 -0700 (PDT) Received: from ?192.168.1.15? ( [83.76.170.177]) by mx.google.com with ESMTPS id d6sm7231801fga.2.2008.09.02.09.12.33 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 02 Sep 2008 09:12:35 -0700 (PDT) Message-ID: <48BD65EE.8040500@gmail.com> Date: Tue, 02 Sep 2008 18:12:30 +0200 From: phcoder User-Agent: Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: The development of GRUB 2 References: <48BD4C52.6040308@gmail.com> <1220367299.23879.15.camel@localhost> <48BD62BE.7090507@gmail.com> In-Reply-To: <48BD62BE.7090507@gmail.com> X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------000102030600040805070406" X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: Re: Sendkey patch 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: Tue, 02 Sep 2008 16:12:39 -0000 This is a multi-part message in MIME format. --------------000102030600040805070406 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sorry, forgot to attach phcoder wrote: > Hello, again > I had a look at your patch. In some mail it was suggested that kernel > patch should be split from module that uses it. So I resend the kernel > part of my patch. Another question is whether we need some kind of > abortion procedure (like in your patch) if a preboot hook fails. > Javier Martín wrote: >> An interface like this is implemented in another patch in "discussion", >> my drivemap patch (see the August list archives). As yours, it is >> linked-list based and very similar in the prototypes. I haven't checked >> if your code has any kind of errors/corner cases, > > I checked and found that I didn't check if grub_malloc succeeded > >> but it seems terser >> than mine even though it's a bit more difficult to understand because >> you use double pointers to avoid my handling of the head case. I don't >> understand the purpose of doubly-linking the list though... >> > The goal is to avoid walking through list when deleting an entry from it. >>> Whether we need also interface for adding "postboot" commands? (in case >>> boot_function returns) >> I don't think it would offer a lot of functionality because most loaders >> don't return on failure, they just get stuck or their payload >> triple-faults and reboots. > > It's the case for i386-pc loaders but not the case of some other targets > (e.g. EFI). So the question remains. > > Vladimir Serbinenko --------------000102030600040805070406 Content-Type: text/x-diff; name="preboot.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="preboot.patch" Index: kern/loader.c =================================================================== --- kern/loader.c (revision 1845) +++ kern/loader.c (working copy) @@ -22,12 +22,46 @@ #include #include + static grub_err_t (*grub_loader_boot_func) (void); static grub_err_t (*grub_loader_unload_func) (void); static int grub_loader_noreturn; static int grub_loader_loaded; +static struct grub_preboot_t *grub_loader_preboots=0; + +struct grub_preboot_t * +grub_loader_add_preboot (grub_err_t (*preboot_func) (int)) +{ + struct grub_preboot_t **cur=&grub_loader_preboots; + if (!preboot_func) + return 0; + while (*cur) + cur=&((*cur)->next); + *cur=(struct grub_preboot_t *)grub_malloc (sizeof (struct grub_preboot_t)); + if (!*cur) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, "hook not added"); + return 0; + } + (*cur)->prev_pointer=cur; + (*cur)->next=0; + (*cur)->preboot_func=preboot_func; + return *cur; +} + +void +grub_loader_remove_preboot (struct grub_preboot_t *p) +{ + if (!p) + return; + *(p->prev_pointer)=p->next; + if (p->next) + (p->next)->prev_pointer=p->prev_pointer; + grub_free (p); +} + int grub_loader_is_loaded (void) { @@ -64,11 +98,19 @@ grub_err_t grub_loader_boot (void) { + struct grub_preboot_t *iter=grub_loader_preboots; if (! grub_loader_loaded) return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel"); if (grub_loader_noreturn) grub_machine_fini (); + + while (iter) + { + if (iter->preboot_func) + iter->preboot_func (grub_loader_noreturn); + iter=iter->next; + } return (grub_loader_boot_func) (); } Index: include/grub/loader.h =================================================================== --- include/grub/loader.h (revision 1845) +++ include/grub/loader.h (working copy) @@ -25,6 +25,14 @@ #include #include +struct grub_preboot_t +{ + grub_err_t (*preboot_func) (int); + struct grub_preboot_t *next; + struct grub_preboot_t **prev_pointer; +}; + + /* Check if a loader is loaded. */ int EXPORT_FUNC(grub_loader_is_loaded) (void); @@ -37,6 +45,12 @@ /* Unset current loader, if any. */ void EXPORT_FUNC(grub_loader_unset) (void); +/*Add a preboot function*/ +struct grub_preboot_t *EXPORT_FUNC(grub_loader_add_preboot) (grub_err_t (*preboot_func) (int noreturn)); + +/*Remove given preboot function*/ +void EXPORT_FUNC(grub_loader_remove_preboot) (struct grub_preboot_t *p); + /* Call the boot hook in current loader. This may or may not return, depending on the setting by grub_loader_set. */ grub_err_t EXPORT_FUNC(grub_loader_boot) (void); --------------000102030600040805070406--