diff --git a/regress/lib/libc/clone/Makefile b/regress/lib/libc/clone/Makefile new file mode 100644 index 000000000000..39cded2ea1c5 --- /dev/null +++ b/regress/lib/libc/clone/Makefile @@ -0,0 +1,18 @@ +# $NetBSD: Makefile,v 1.1 2001/07/17 23:58:30 thorpej Exp $ + +MKMAN=no + +PROG= clonetest +COPTS+=-g + +WARNS?= 1 + +regress: + @if ./clonetest; then \ + echo PASSED; \ + else \ + echo FAILED; \ + exit 1; \ + fi + +.include diff --git a/regress/lib/libc/clone/clonetest.c b/regress/lib/libc/clone/clonetest.c new file mode 100644 index 000000000000..cb2e9df047e1 --- /dev/null +++ b/regress/lib/libc/clone/clonetest.c @@ -0,0 +1,79 @@ +/* $NetBSD: clonetest.c,v 1.1 2001/07/17 23:58:30 thorpej Exp $ */ + +/* + * This file placed in the public domain. + * Jason R. Thorpe, July 16, 2001. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +int newclone(void *); + +int main(int, char *[]); + +#define STACKSIZE (8 * 1024) + +#define FROBVAL 41973 +#define CHILDEXIT 0xa5 + +int +main(int argc, char *argv[]) +{ + void *stack; + __volatile int frobme = 0; + pid_t pid; + int stat; + + stack = mmap(NULL, STACKSIZE, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_PRIVATE|MAP_ANON, -1, (off_t) 0); + if (stack == MAP_FAILED) + err(1, "mmap stack"); + + /* + * XXX FIX ME FOR UPWARD-GROWING STACK + */ + stack = (caddr_t) stack + STACKSIZE; + + printf("parent: stack = %p\n", stack); + fflush(stdout); + + pid = __clone(newclone, stack, + CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD, + (void *) &frobme); + if (pid == -1) + err(1, "clone"); + + while (waitpid(pid, &stat, 0) != pid) + /* spin */ ; + + if (WIFEXITED(stat) == 0) + errx(1, "child didn't exit\n"); + + printf("parent: childexit = 0x%x frobme = %d\n", + WEXITSTATUS(stat), frobme); + + if (WEXITSTATUS(stat) != CHILDEXIT || frobme != FROBVAL) + exit(1); + + exit(0); +} + +int +newclone(void *arg) +{ + int *frobp = arg; + + printf("child: stack ~= %p\n", &frobp); + fflush(stdout); + + *frobp = FROBVAL; + + return (CHILDEXIT); +}