Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!rutgers!columbia!close.columbia.edu!ji From: ji@close.columbia.edu (John Ioannidis) Newsgroups: comp.unix.wizards Subject: Re: Indirect system call Message-ID: <6612@columbia.edu> Date: 9 Nov 89 04:21:46 GMT References: <28945@shemp.CS.UCLA.EDU> Sender: news@columbia.edu Reply-To: ji@close.UUCP (John Ioannidis) Organization: Columbia University Department of Computer Science Lines: 44 In article <28945@shemp.CS.UCLA.EDU> dieter@lynn.cs.ucla.edu (Dieter Rothmeier) writes: >While browsing through section 2 of the Unix manual, >I came upon the concept of an indirect system call, >as in syscall(2). Now that puzzled me. What might be >the use for such a facility? > Lots of things. For example, you want to redefine some system calls like read() and write() to do something before and after the actual write (like your own profiling, save state like where the file pointer is so that you can checkpoint/restart, etc). ALl you have to do is provide your own read() routine that would be defined like this: read(fd, buf, len) { /* stuff */ syscall(SYS_READ, fd, buf, len); /* more stuff */ } If you are loooking for something more exotic, here's a good one. A long time ago I needed to time Sun system calls (but not have to call the system call 1000 times then divide the times by 1000!). That was on a vintage (serial number 19, I believe) Sun-1/150U (with a Sun-2 CPU) running release 2.0 of Sun's Unix (back then it wasn't called SunOS). So I hacked the indir() sources (that's what the routine is called inside the kernel, if my memory serves me right) to turn on the 8 diagnostic LEDs on the board, then proceed with the system call, then turn them off. Turning them on and off was a matter of three or four 68010 instructions, so that didn't consume much time. Then I hooked up a Logic Analyzer to the 74LS374 that actually drove the eight LEDs, and set it to trigger when its input was all ones. Now, if I wanted to time a system call, I would call it indirectly, and I could just see what was happening on the logic analyzer. Those were the days... /ji In-Real-Life: John "Heldenprogrammer" Ioannidis E-Mail-To: ji@cs.columbia.edu V-Mail-To: +1 212 854 5510 P-Mail-To: 450 Computer Science \n Columbia University \n New York, NY 10027