#include #include #include "psxmsg.h" #include #include #include #include #include #include #include #include "tsttmp.h" // defines DbgPrint as printf extern int errno; VOID p0(VOID); VOID p1(VOID); VOID ex0(VOID); VOID a0(VOID); VOID s0(VOID); VOID call0(VOID); VOID f1(VOID); VOID f2(VOID); VOID p0foo(VOID); CONTEXT a0JumpBuff; int _CRTAPI1 main(int argc, char *argv[]) { pid_t self; PCH p,t; PTEB ThreadInfo; ThreadInfo = NtCurrentTeb(); self = getpid(); DbgPrint("tstfork: My pid is %lx Argc = %lx\n",self,argc); DbgPrint("tstfork: StackBase %lx\n",ThreadInfo->NtTib.StackBase); DbgPrint("tstfork: StackLimit %lx\n",ThreadInfo->NtTib.StackLimit); DbgPrint("tstfork: ClientId %lx.%lx\n",ThreadInfo->ClientId.UniqueProcess,ThreadInfo->ClientId.UniqueThread); while(argc--){ p = *argv++; t = p; while(*t++); DbgPrint("Argv --> %s\n",p); } p0(); p1(); ex0(); a0(); s0(); call0(); f1(); f2(); _exit(2); return 1; } VOID p0foo(){} ULONG p0touch( IN PUCHAR pch, IN ULONG nb ) { ULONG ct = 0; DbgPrint("p0touch: pch %lx nb %lx\n",pch,nb); while (nb--) { ct += *pch++; } return ct; } VOID p0() { int fildes[2]; int psxst; UCHAR buffer[525]; UCHAR buf[525]; int i; for(i=0;i<525;i++){ buf[i] = (char)(i&255); } DbgPrint("p0:++\n"); // // Create a pipe // psxst = pipe(fildes); if ( psxst ) { DbgPrint("p0: pipe() failed st = %lx errno %lx\n",psxst,errno); return; } DbgPrint("p0: fildes[0] = %lx filedes[1] = %lx\n",fildes[0],fildes[1]); // // Test write followed by read // psxst = write(fildes[1],"Hello World\n",13); if ( psxst < 0 ) { DbgPrint("p0: write() failed st = %lx errno %lx\n",psxst,errno); return; } DbgPrint("p0: write() success transfered %lx bytes to fd %lx\n",psxst,fildes[1]); psxst = read(fildes[0],buffer,32); if ( psxst < 0 ) { DbgPrint("p0: read() failed st = %lx errno %lx\n",psxst,errno); return; } p0touch(buffer,psxst); DbgPrint("p0: read() success transfered %lx bytes from fd %lx %s\n",psxst,fildes[1],buffer); // // End write followed by read // // // assume parents read will happen before childs write. // parents first read blocks testing write unblocks read // if ( !fork() ) { DbgPrint("p0:child pid %lx\n",getpid()); DbgPrint("p0:child writing\n"); sleep(8); psxst = write(fildes[1],"From Child\n\0",12); if ( psxst < 0 ) { DbgPrint("p0:child write() failed st = %lx errno %lx\n",psxst,errno); return; } DbgPrint("p0:child write() success transfered %lx bytes to fd %lx\n",psxst,fildes[1]); psxst = write(fildes[1],"Small Write\n\0",13); if ( psxst < 0 ) { DbgPrint("p0:child write() failed st = %lx errno %lx\n",psxst,errno); return; } DbgPrint("p0:child write() success transfered %lx bytes to fd %lx\n",psxst,fildes[1]); // // this write should block and get unblocked when read of // previous write completes // p0foo(); psxst = write(fildes[1],buf,514); if ( psxst < 0 ) { DbgPrint("p0:child write() failed st = %lx errno %lx\n",psxst,errno); return; } DbgPrint("p0:child write() success transfered %lx bytes to fd %lx\n",psxst,fildes[1]); _exit(1); } DbgPrint("p0:parent reading\n"); psxst = read(fildes[0],buffer,12); if ( psxst < 0 ) { DbgPrint("p0:parent read() failed st = %lx errno %lx\n",psxst,errno); return; } p0touch(buffer,psxst); DbgPrint("p0:parent read() success transfered %lx bytes from fd %lx %s\n",psxst,fildes[1],buffer); DbgPrint("p0:parent sleeping\n"); sleep(12); DbgPrint("p0:parent back from sleep\n"); DbgPrint("p0:parent reading\n"); psxst = read(fildes[0],buffer,13); if ( psxst < 0 ) { DbgPrint("p0:parent read() failed st = %lx errno %lx\n",psxst,errno); return; } p0touch(buffer,psxst); DbgPrint("p0:parent read() success transfered %lx bytes from fd %lx %s\n",psxst,fildes[1],buffer); psxst = read(fildes[0],buffer,512); if ( psxst < 0 ) { DbgPrint("p0:parent read() failed st = %lx errno %lx\n",psxst,errno); return; } DbgPrint("p0:parent read() success transfered %lx bytes from fd %lx\n",psxst,fildes[1]); for(i=0;i