This is the mail archive of the libc-hacker@cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

A test for vfork


Here is a test for vfork which should tell you if it is implemented
correctly.  Especially the generic source linux/vfork.c is unusable for
machines that put the return pc on the stack (like ix86).  Remember that
the stack is shared between the parent and the child, thus any function
call in the child will clobber the return pc from vfork of the parent.
See the existing implementations under sysdeps/unix for hints.

Andreas.

----------------------------------------------------------------------
#include <stdio.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>

void noop (void);

int
main (void)
{
  int pid;

  printf ("Before vfork\n");
  fflush (stdout);
  pid = vfork ();
  if (pid == 0)
    {
      /* This will clobber the return pc from vfork in the parent on
	 machines where it is stored on the stack, if vfork wasn't
	 implemented correctly, */
      noop ();
      _exit (2);
    }
  else if (pid < 0)
    error (1, errno, "vfork");
  printf ("After vfork (parent)\n");
  wait (0);
  exit (0);
}

void noop () {}
----------------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]