Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site calma.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!sun!calma!radzy From: radzy@calma.UUCP (Tim Radzykewycz) Newsgroups: net.unix-wizards Subject: Re: Prepending _ in C external names necessary? Message-ID: <88@calma.UUCP> Date: Thu, 5-Dec-85 13:40:59 EST Article-I.D.: calma.88 Posted: Thu Dec 5 13:40:59 1985 Date-Received: Sat, 7-Dec-85 04:26:40 EST References: <200@brl-tgr.ARPA> <174@altos86.UUCP> <9113@ritcv.UUCP> Reply-To: radzy@calma.UUCP (Tim Radzykewycz) Distribution: net Organization: GE/Calma Co., R&D Systems Engineering, Milpitas, CA Lines: 49 Summary: In article <9113@ritcv.UUCP> spw2562@ritcv.UUCP (Fishhook) writes: >I don't know if this is tru for all systems, but one system I worked >on passed parameters to system calls using specific registers. Paremeters >to C functions are passed on the stack. Therefore, for the compiler to >call user functions and system calls, it has to know what all the system >calls are. Many flavors of UNIX, and at least some other OS's I know of use special code to make system calls. Generally, this is something like "trap", "emt", "sintr" or the equivalent. These are treated similar to interrupts, in that they cause the state of the processor to change from user to system, change from user stack to system stack, and several other things. With this kind of architecture, the system calls really do have parameters passed on the stack, and the OS grabs the info off of the user stack whenever there is a system call. This eliminates the need for having a separate pair of subroutines, one of which massages the locations of parameters for the other. >The system I worked on treated all system calls as function calls and >had function stubs which moved the stack parameters to the proper registers >then performed the actual system call. Naturally, these stubs are written >in assembly. For this to be possible, the system call has to be different >from the function call. Answer? Prepend every C function call with an >underline, prepend all the function stubs with an underline, DON'T prepend >system calls. Therefore, >[examples given] >Without underscore prepending this would not be possible. The only system I'm familiar with which has this kind of setup is XINU, although I'm certain there are others (perhaps OS-9?). The real point of this followup, though, is that it is still possible to get the functionality that Mr. Wall specified, simply by reversing the scheme: thus, the massaging routine would be named "write", and the underlying system call would be named "_write" (or something similar). This does have the disadvantage of making it possible for someone to write a subroutine whose name conflicts with a system call, but it might be possible to set the name to something which is illegal in C, such as "$write", instead. Of course, that's assuming that the '$' character *is* legal for the assembler. No, underscore prepending isn't the only answer, but it seems to be the most common. I don't see why it's such a big deal. -- Tim (radzy) Radzykewycz, The Incredible Radical Cabbage calma!radzy@ucbvax.ARPA {ucbvax,sun,csd-gould}!calma!radzy