Okay, that part about weak referencing is clear; I initially tried to see the definition of write(), so it now turns out I need the definition of __sys_write. Clear. I have tried to find it, but I found only declarations, can you help me with this one?
The declarations are in
interposing_table.c, if I recall correctly, it is in
/lib/clib/sys/
Code:
#define SLOT(a, b) \
[INTERPOS_##a] = (interpos_func_t)b
interpos_func_t __libc_interposing[INTERPOS_MAX] = {
...,
SLOT(write, __sys_write),
...}
Here I have a couple of questions. First is what does this syntax meant? Square brackets around an identifier, and then assignment, is it expanded in some way by the preprocessor? I understand that ## is concatenation of tokens, but it seems illegitimate C to have such a construct?
This is standard C99 syntax for an array. As you correctly stated, ## equates to concatenation in the pre-processor.
All of the INTERPOS_???? are enums, defined in libc_private.h
So SLOT is called as SLOT(write, __sys_write) or SLOT(accept, __sys_accept) etc. depending on the type of interposition you're handling.
As
unitrunker pointed out, they're elements in an array (hence the enum)
You probably want to read something about interposition:
http://www2.eecs.berkeley.edu/Pubs/TechRpts/1996/CSD-96-920.pdf if you want to understand what it's attempting or are you purely focussed on __sys_write?
And from what we have in
interposing_table.c, it is not clear still where I can find the definition of this ?
If I do not see assembler definition of it, I cannot run it, right?
Edit: I missed this bit.
Ok, the
interposing_table.c contains the array of functions of
__libc_interposing. Which one is called is defined by the macro
INTERPOS_??? that is ultimately, after pre-processing, an enumerated type (an integer from 0 to nn - well actually that's not entirely true but in this circumstance it will suffice).
So,
INTERPOS_accept is enum 0, which activates SLOT(accept, __sys_accept) and runs accept()
If you look in
lib/libthr/thread/thr_syscalls.c in
__thr_interpose_libc(void) you see an entire array of function calls where SLOT(accept); is expanded to:
C:
*(__libc_interposing_slot(INTERPOS_accept)) = (interpos_func_t)__thr_accept;
And so on.
I am not sure what your end goal is here? You want to know the "platform specific" part of write() but to what end?
By your own admission you're lacking in C knowledge (like most of us!), so you're on a steep learning curve understanding the nuances of C as implemented in the kernel and library. I would suggest that's not a good place to start.
But, don't let me dissuade you, I'm just pointing out reality. We can't learn unless we ask questions.