bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grub 0.90 prevents Standby in Windows


From: erich
Subject: Re: grub 0.90 prevents Standby in Windows
Date: Fri, 26 Oct 2001 15:02:32 -0700

Thierry Laronde <address@hidden> wrote:

> On Fri, Oct 26, 2001 at 12:09:36PM -0700, address@hidden wrote:
> 
> > I'm for it.  ;-)
> > 
> > I think Okuji's idea of a "hook", to keep things simple and extensible,
> > is a good one (that way, each bit of code can be included with no
> > reference to others and no messy "#define"'s to remove unwanted ones).
> > 
> > I'm presuming this takes the form of a function pointer, perhaps called
> > "boot_hook", which gets called prior to the final boot stage, after
> > all the checks have been made.  To take advantage of it, each bit of
> > code that wanted to do this would replace the value of "boot_hook" with
> > it's own function, which, at the end, calls the previous value.
...
> > You just call "boot_hook", each one calls the next, until the final one
> > calls the real boot function it redirected from.
> 
> Nice idea. With some care about "dependencies" of changes [every
> function is an atomic one, that is put the system back in a state
> independant from other changes]. 
> As noted by Okuji, the problem, as always, will be that without dynamic
> memory allocation we will have to allocate a fix size array of
> structures like :
> 
> struct restore_function {
>       int id; /* for example an enum {RESTORE_FOO, RESTORE_BAR,...} */
>       int (* pf) ();
>       struct restore_function *next;
> };    
> 
> id being there in order to be sure that we don't invoke a function
> twice.

Hmm, well, I think the above is more complex than necessary, since you'd
need to search the chain, etc.


What I was getting at above was:


        void final_boot_func(void)
        {
                /* whatever needs to be done for final booting... */
        }

        void (*boot_hook)(void) = final_boot_func;


Then each case does:

        void (*my_hook)(void) = NULL;

        void my_boot_func(void)
        {
                /* do your restoration of config here... */

                (*my_hook)();
        }

        ...

    [in your code where you want to install the hook]

        if (my_hook == NULL) {
                my_hook = boot_hook;
                boot_hook = my_boot_func;
        }


    If each case was only possibly executed once, then you can
    remove the if check above.


That's the whole thing.  There is no return value because the
"final_boot_func" doesn't even return.

If you really want a parameter, then you can pass a "void *" type
or something.  You can cast these as pointers of any type, or as
an integral type easily enough.  In this case you'd have the 2 main
globals be:

        void (*boot_hook)(void);
        void *boot_hook_param;

And just have 2 variables you switch each time instead of one.

But I'd say unless we know we need the parameter, go with just the
function with no parameter.  It's easy to retrofit if/when necessary.


--
    Erich Stefan Boleyn     <address@hidden>     http://www.uruk.org/
"Reality is truly stranger than fiction; Probably why fiction is so popular"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]