grub-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Split of normal mode (version 2)


From: Colin D Bennett
Subject: Re: [PATCH] Split of normal mode (version 2)
Date: Fri, 3 Apr 2009 16:02:40 -0700

On Sat, 04 Apr 2009 00:19:46 +0200
phcoder <address@hidden> wrote:

> > setjmp is required for the switch between rescue mode and normal mode. 
> 
> It isn't. You can just call the corresponding function. What's wrong 
> with such approach?

So you could have something like

-------------
void grub_main ()
{
  //...
  // Try to start up in normal mode
  normal ();
}

void normal ()
{
  // do stuff
  // User asked for rescue mode:
  rescue ();
}

void rescue ()
{
  // do stuff
  // User asked for normal mode:
  normal ();
}
-------------

What if you switch back and forth between normal and rescue mode
many times in a row?  The stack will grow with each call and eventually
the stack will overflow and Bad Things will happen.

Granted, you'd have to switch many times to overflow the stack, but it
is a sub-optimal situation.  You could have something like:

-------------
// In this context, grub_main acts as a dispatcher
// so that normal and rescue mode can be switched without
// unbounded growing of the stack.

enum mode { RESCUE, NORMAL };

void
grub_main ()
{
  enum mode next_mode;
  //...

  // Try to start up in normal mode
  next_mode = NORMAL;
  while (1)
  {
    switch (next_mode)
    {
      case RESCUE:
        next_mode = rescue ();
        break;
      case NORMAL:
        next_mode = normal ();
        break;
      default:
        // Panic!
    }
  }
}

enum mode
normal ()
{
  // do stuff
  // User asked for rescue mode:
  return RESCUE;
}

enum mode
rescue ()
{
  // do stuff
  // User asked for normal mode:
  return NORMAL;
}
-------------


Now you could also return function pointers instead of using
switch/case with enum constants, but it's the same concept.  Then
setjmp is another similar way to do it without implementing a central
dispatcher like grub_main above.

At least that's how I think of it.

Regards,
Colin

Attachment: signature.asc
Description: PGP signature


reply via email to

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