File files/EDLF64.draft changed (mode: 100644) (index 90f01d6..e6fa9a0) |
... |
... |
Endianness is the one from the CPU. Offsets 0->edlf_hdr_bytes_n-1 are obviously |
17 |
17 |
A loader64 instance will keep a registry of what was loaded via reference counting. Usually, there |
A loader64 instance will keep a registry of what was loaded via reference counting. Usually, there |
18 |
18 |
will be only one static instance of loader64 per process inited by the process_entry function. |
will be only one static instance of loader64 per process inited by the process_entry function. |
19 |
19 |
|
|
20 |
|
0x00 uint64_t (*open)( /*INPUT*/ void *pathname, /* we presume the pathname is self-sizing */ |
|
|
20 |
|
uint64_t loader64_open( /*INPUT*/ void *pathname, /* we presume the pathname is self-sizing */ |
21 |
21 |
/*OUTPUT*/ uint64_t *handle, void **start); |
/*OUTPUT*/ uint64_t *handle, void **start); |
22 |
22 |
|
|
23 |
23 |
Must be reentrant/thread safe. |
Must be reentrant/thread safe. |
|
... |
... |
will be only one static instance of loader64 per process inited by the process_e |
40 |
40 |
NOTE: we use a handle, that to avoid to have to map a start virtual address to some loader |
NOTE: we use a handle, that to avoid to have to map a start virtual address to some loader |
41 |
41 |
internals (for instance, the handle could be directly an offset into such internals). |
internals (for instance, the handle could be directly an offset into such internals). |
42 |
42 |
|
|
43 |
|
0x08 uint64_t (*close)(/*INPUT*/ uint64_t handle); |
|
|
43 |
|
uint64_t loader64_close(/*INPUT*/ uint64_t handle); |
44 |
44 |
|
|
45 |
45 |
Must be reentrant/thread safe. Return 0 if ok, non-zero if something wrong did happen while |
Must be reentrant/thread safe. Return 0 if ok, non-zero if something wrong did happen while |
46 |
46 |
closing the edlf64 file. |
closing the edlf64 file. |
|
... |
... |
will be only one static instance of loader64 per process inited by the process_e |
50 |
50 |
|
|
51 |
51 |
Init/fini functions have the responsibility to keep the dynamic library state consistent (for |
Init/fini functions have the responsibility to keep the dynamic library state consistent (for |
52 |
52 |
instance using reference counting like a loader instance). |
instance using reference counting like a loader instance). |
53 |
|
---- |
|
54 |
|
0x10 loader64_bytes_n. |
|
55 |
53 |
==================================================================================================== |
==================================================================================================== |
56 |
54 |
EDLF64 is about loading only one RWX memory segment. |
EDLF64 is about loading only one RWX memory segment. |
57 |
55 |
==================================================================================================== |
==================================================================================================== |
58 |
56 |
A EDLF64 executable may honor the following environment variable in order to lookup for dynamic |
A EDLF64 executable may honor the following environment variable in order to lookup for dynamic |
59 |
57 |
libraries. Of course, only on platforms where it is possible. Such incompatible platforms should |
libraries. Of course, only on platforms where it is possible. Such incompatible platforms should |
60 |
|
defines their own EDLF64_LIBRARY_PATH. |
|
|
58 |
|
defines their own "EDLF64_LIBRARY_PATH way". |
61 |
59 |
|
|
62 |
60 |
EDLF64_LIBRARY_PATH environment variable to lookup for EDLF64 dynamic libraries: byte string |
EDLF64_LIBRARY_PATH environment variable to lookup for EDLF64 dynamic libraries: byte string |
63 |
61 |
ending with a 0x00 byte. Each path from EDLF64_LIBRARY_PATH is prepended to a dynamic library name. |
ending with a 0x00 byte. Each path from EDLF64_LIBRARY_PATH is prepended to a dynamic library name. |
|
... |
... |
mostly the same than the SYSV ABI (arg has no argc). The process_entry function |
80 |
78 |
its stack:could be a "mmap" system call or a part of the "bss", namely from the extra memory past |
its stack:could be a "mmap" system call or a part of the "bss", namely from the extra memory past |
81 |
79 |
the end of the loaded file (including a guard memory page or not), or blunty book some room into the |
the end of the loaded file (including a guard memory page or not), or blunty book some room into the |
82 |
80 |
file, etc. |
file, etc. |
83 |
|
On "mmap/munmap" platforms, process_info must be cleanely munmap-able. Other platforms may implement |
|
84 |
|
another mechanism to let process_entry remove/free/reuse such bytes from the process. |
|
|
81 |
|
On "mmap/munmap" platforms, process_info must be cleanely munmap-able. Other platform types may |
|
82 |
|
implement other mechanisms to let process_entry remove/free/reuse such bytes from the process. |
85 |
83 |
|
|
86 |
84 |
For the executable, you may need its path in order to load private dynamic libraries based on |
For the executable, you may need its path in order to load private dynamic libraries based on |
87 |
85 |
its file system location. On linux it is possible only if the /proc file system is mounted and it |
its file system location. On linux it is possible only if the /proc file system is mounted and it |
|
... |
... |
variable). |
92 |
90 |
==================================================================================================== |
==================================================================================================== |
93 |
91 |
C prototype of resolve function: |
C prototype of resolve function: |
94 |
92 |
|
|
95 |
|
uint64_t resolve( /*INPUT*/ uint64_t *symbol_id, |
|
96 |
|
/*OUTPUT*/ void **symbol_virtual_address); |
|
|
93 |
|
uint64_t resolve( |
|
94 |
|
/*INPUT*/ uint64_t *symbol_id, |
|
95 |
|
/*OUTPUT*/ void **symbol_virtual_address); |
97 |
96 |
|
|
98 |
97 |
symbol_id is a 64bits unique id identifying a symbol (similar to kernel syscalls). Like kernel |
symbol_id is a 64bits unique id identifying a symbol (similar to kernel syscalls). Like kernel |
99 |
98 |
syscalls, those symbol ids must be _EXTREMELY_ stable in time. You could segment the id space with |
syscalls, those symbol ids must be _EXTREMELY_ stable in time. You could segment the id space with |
|
... |
... |
categories (init calls, fini calls, etc, 64bits is huge). |
101 |
100 |
Return 0 if ok, with the virtual address of the symbol via the symbol_virtual_address argument. |
Return 0 if ok, with the virtual address of the symbol via the symbol_virtual_address argument. |
102 |
101 |
==================================================================================================== |
==================================================================================================== |
103 |
102 |
Recommended C prototype of an init function: |
Recommended C prototype of an init function: |
104 |
|
uint64_t init( /*INPUT*/ void *process_info,uint64_t process_info_bytes_n,void *pathname, |
|
105 |
|
void *loader64, |
|
106 |
|
/*OUTPUT*/ void **fini)); |
|
|
103 |
|
uint64_t init( |
|
104 |
|
/*INPUT*/ void *process_info, uint64_t process_info_bytes_n, void *pathname, |
|
105 |
|
uint64_t (*loader64_open)(void *pathname, uint64_t *handle, void **start), |
|
106 |
|
uint64_t (*loader64_close)(uint64_t handle), |
|
107 |
|
/*OUTPUT*/ void (**fini)(void)); |
107 |
108 |
|
|
108 |
109 |
The process_info here may be a variant from the one provided by the kernel to process_entry. |
The process_info here may be a variant from the one provided by the kernel to process_entry. |
109 |
|
Pathname is a pointer on the pathname used to load this edlf file. If successful, it should return |
|
110 |
|
0. Do not expect process_info to stay in memory after the call. |
|
|
110 |
|
Pathname is a pointer on the pathname used to load this edlf64 file. If successful, it should return |
|
111 |
|
0. Do not expect process_info to stay in memory after the call. On x64/x86_64 with the SYSV ABI, if |
|
112 |
|
going with more than 6 parameters, just init a transient structure to pass the whole data to work |
|
113 |
|
around some ABI kludge. |
111 |
114 |
|
|
112 |
115 |
Alternative C prototype of an init function: |
Alternative C prototype of an init function: |
113 |
|
uint64_t init( /*INPUT*/ void *process_info,uint64_t process_info_bytes_n,int fd, |
|
114 |
|
void *loader64, |
|
115 |
|
/*OUTPUT*/ void **fini)); |
|
|
116 |
|
uint64_t init( |
|
117 |
|
/*INPUT*/ void *process_info, uint64_t process_info_bytes_n, int fd, |
|
118 |
|
uint64_t (*loader64_open)(void *pathname, uint64_t *handle, void **start), |
|
119 |
|
uint64_t (*loader64_close)(uint64_t handle), |
|
120 |
|
/*OUTPUT*/ void (**fini)(void)); |
116 |
121 |
|
|
117 |
122 |
Same thing than the previous one, but with the process file descriptor used to load/mmap the edlf64 |
Same thing than the previous one, but with the process file descriptor used to load/mmap the edlf64 |
118 |
123 |
file instead of the pathname. You could even add the directory file descriptor. |
file instead of the pathname. You could even add the directory file descriptor. |