Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Oct 1995 15:27:15 -0400 (EDT)
From:      "Ron G. Minnich" <rminnich@Sarnoff.COM>
To:        Theo de Raadt <deraadt@theos.com>, hackers@freebsd.org
Subject:   rfork part 3: library code
Message-ID:  <Pine.SUN.3.91.951025151815.29062B-100000@terra>

next in thread | raw e-mail | index | archive | help
All this function does is: 
1)minherit the data space
2) call rfork with zero as the options value
3) return values. Only funniness is that you have to fake the return 0 
   to kid behavior of fork(), so there's fooling around with getpid() before
   the call and testing of return values after the call.

Also, there's a call to something called 'syscallfind' in here for the
modload case. IF anyone wants that code let me know. It uses modstat code
to find the named syscall number. 

There you are. rfork in 3 parts. Questions to me.

ron

#include <stdio.h>
#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_inherit.h>

int minherit(caddr_t, unsigned int, int);

int
rfork(int i)
{
	extern int end, sbrk();
	int pid, newpid;
	/* until it's a real syscall, we have to fake the zero-return */
	unsigned long start, last;
	static int rfsyscallnum = -1;

        if (rfsyscallnum < 0)
                rfsyscallnum = syscallfind("rfork");
        if (rfsyscallnum < 0) {
                perror("rfork syscallfind");
                return -1;
        }

	/* for the modload version, we don't get two return values, 
	 * so we have to fake the fork 'return 0 to kid' behavior
	 */
	pid = getpid();

	start = (unsigned long) ctob(btoc(&end));
	last  = sbrk(0);
	/* the man page lies: 
	 * it won't return page-aligned values from sbrk
	 * the seg is actually several pages larger!
	 */
	last = ctob(btoc(last)+4);
	/* may be nothing to share, ignore return errors */

	if (minherit(start, last-start, VM_INHERIT_SHARE) < 0)
		perror("minherit failed");

	newpid =  syscall(rfsyscallnum,i);

	if (newpid == pid)
		newpid = 0;
	return newpid;
}


Ron Minnich                |Like a knife through Daddy's heart: 
rminnich@earth.sarnoff.com |"Don't make fun of Windows, daddy! It takes care
(609)-734-3120             | of all my files and it's reliable and I like it".





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SUN.3.91.951025151815.29062B-100000>