fread(3)/fwrite(3) don't call read(2)/write(2)
Yubin Ruan
ablacktshirt@gmail.com
Wed Oct 11 15:07:00 GMT 2017
Hi glibc developers,
I am looking into some internals of glibc's implementation of
fread/fwrite, but surprisingly found that fread/fwrite don't invoke
the "public available" read/write system call interface, while
instead, invoke some "vtable"-related function handles.
I got very confused with that and am very curious whether fread/fwrite
will eventually "drill down" to some
"xxx_internal_read"/"xxx_internal_write" functionns, like this:
fwrite(...)
-> _IO_sputn(...)
-> ...
-> xxx_internal_write(...)
(the same goes for fread())
I think that is also the same for glibc's implementation of write(2):
write(...)
-> ...
-> ...
-> xxx_internal_write(...)
(that says, both fwrite() and write() will drill down to the same
xxx_internal_write())
Unfortunately the full implementation of fwrite() and write() are both
auto-generated by some scripts when glibc is compiled[1]. I have
traced fwrite() down but can find nothing valuable. The only thing
that provides me some insights is this macro (in "libio/libioP.h"):
# define _IO_JUMPS_FUNC(THIS) \
(IO_validate_vtable \
(*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
+ (THIS)->_vtable_offset)))
which I think tries to invoke some functions inside `struct FILE'. But
in neither `struct FILE' nor 'struct _IO_FILE' can I such function
pointers. Are those pointers also auto-generated?
I will be very thankful if someone can enlighten me ;-)
Yubin
[1]: I know that is true for read/write, but not sure whether that is
true for fread/fwrite
More information about the Libc-help
mailing list