All of lore.kernel.org
 help / color / mirror / Atom feed
From: Colin D Bennett <colin@gibibit.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Cc: phcoder@gmail.com
Subject: Re: [PATCH] Split of normal mode (version 2)
Date: Fri, 3 Apr 2009 16:02:40 -0700	[thread overview]
Message-ID: <20090403160240.189e35cf@gibibit.com> (raw)
In-Reply-To: <49D68B82.2080001@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1963 bytes --]

On Sat, 04 Apr 2009 00:19:46 +0200
phcoder <phcoder@gmail.com> 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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2009-04-03 23:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-30 17:41 [PATCH] Split of normal mode (version 2) Bean
2009-04-03 18:40 ` Yoshinori K. Okuji
2009-04-03 19:49   ` Bean
2009-04-03 20:12     ` Yoshinori K. Okuji
2009-04-03 22:19       ` phcoder
2009-04-03 23:02         ` Colin D Bennett [this message]
2009-04-05 14:23           ` Yoshinori K. Okuji
2009-04-04  5:06       ` Bean
2009-04-05 14:33         ` Yoshinori K. Okuji
2009-04-05 15:02           ` Bean
2009-04-05 15:43             ` Yoshinori K. Okuji
2009-04-06 16:39               ` Bean
2009-04-07  0:41                 ` Yoshinori K. Okuji
2009-04-09 23:49                 ` Yoshinori K. Okuji
2009-04-10  5:17                   ` Bean
2009-04-10 20:17                     ` Bean
2009-04-11  9:50                       ` Yoshinori K. Okuji
2009-04-11 14:03                         ` Bean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090403160240.189e35cf@gibibit.com \
    --to=colin@gibibit.com \
    --cc=grub-devel@gnu.org \
    --cc=phcoder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.