Prepending _ in C external names necessary?
Fishhook
spw2562 at ritcv.UUCP
Thu Dec 5 06:28:54 AEST 1985
[munch crunch]
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.
UNLESS...
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,
...
write(fd,&data,bytes) in C becomes
...
...
pushl fd,- at sp or whatever, push the args to stack
...
calls _write and call the function
...
And the library _write function stub is
...
_write: address of function
movl + at sp,d1 or whatever, move function args from
... stack to proper registers
calls write do the actual system call - no '_'
... and do the stuff to return the value it gets
from the system call
Without underscore prepending this would not be possible.
==============================================================================
Steve Wall @ Rochester Institute of Technology
USnail: 6675 Crosby Rd, Lockport, NY 14094, USA
Usenet: ..!rochester!ritcv!spw2562 (Fishhook) Unix 4.2 BSD
BITNET: SPW2562 at RITVAXC (Snoopy) VAX/VMS 4.2
Voice: Yell "Hey Steve!"
Disclaimer: What I just said may or may not have anything to do
with what I was actually thinking...
More information about the Comp.unix.wizards
mailing list