From owner-freebsd-hackers Wed Oct 25 12:28:38 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id MAA07497 for hackers-outgoing; Wed, 25 Oct 1995 12:28:38 -0700 Received: from terra.Sarnoff.COM (terra.sarnoff.com [130.33.11.203]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id MAA07483 for ; Wed, 25 Oct 1995 12:28:35 -0700 Received: (from rminnich@localhost) by terra.Sarnoff.COM (8.6.12/8.6.12) id PAA29138; Wed, 25 Oct 1995 15:27:15 -0400 Date: Wed, 25 Oct 1995 15:27:15 -0400 (EDT) From: "Ron G. Minnich" To: Theo de Raadt , hackers@freebsd.org Subject: rfork part 3: library code Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@freebsd.org Precedence: bulk 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 #include #include #include 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".