![]() All descriptors in a Linux filesystem, belonging to a particular process, are stored in /proc/PROCESS_ID/fd/FD_NUMBER. Well, the file is somewhere in the memory, and we already have a descriptor to it. So all you need, is to use that descriptor to write elf contents to the memory region, then execute it. Accessing the file…įrom the previous subsection, you now have an idea for getting a file descriptor to a memory location. What this function does, simply put, is provide you the file descriptor to some location in the memory, and you can then use this descriptor to do any of the standard file operations that you normally do, like read, write, or in this case, even execute! So yes, although the ‘file’ would be in a memory, since Linux treats it as a file, it allows you to execute it, just like a ‘normal’ file. Memory is a file in Linux, like everything else. Therefore, files created by memfd_create() have the same semantics as other anonymous memory allocations such as those allocated using mmap(2) with the MAP_ANONYMOUS flag. Anonymous memory is used for all backing pages of the file. Once all references to the file are dropped, it is automatically released. However, unlike a regular file, it lives in RAM and has a volatile backing storage. The file behaves like a regular file, and so can be modified, truncated, memory-mapped, and so on. Memfd_create() creates an anonymous file and returns a file descriptor that refers to it. The memfd_create function allows you to do exactly this. This, added to how Linux processes such ‘memory files’, makes it very easy to load and execute elfs from memory. As opposed, everything in Linux is a file, including memory itself. In Windows, you basically have everything treated as an object. Getting the basics down Since everything is a file… This is due to how Linux handles everything: in files. Table 5.In Windows, loading an executable and then running it completely from memory, is quite complicated lots of complicated stuff is involved (at least for me).ĭoing so in Linux, however, is fairly easier, and requires no custom loaders. Variables used in relocation fields provides details on the variables used in relocation fields: Relocation against a non-preemptible ifunc symbolģ2-bit relative offset to a function or its PLT entry Instruction can be relaxed, paired with a normal relocation at the same address The alignment boundary is specified by the addend rounded up to the next power of two. The addend indicates the number of bytes occupied by nop instructions at the relocation offset. TLS LE thread pointer usage, %tprel_add(symbol)Īlignment statement. Low 12 bits of TLS LE thread pointer offset, %tprel_lo(symbol) High 20 bits of TLS LE thread pointer offset, %tprel_hi(symbol) Low 12 bits of 32-bit absolute address, %lo(symbol) High 20 bits of 32-bit absolute address, %hi(symbol) Low 12 bits of a 32-bit PC-relative, %pcrel_lo(address of %pcrel_hi), the addend must be 0 High 20 bits of 32-bit PC-relative reference, %pcrel_hi(symbol) High 20 bits of 32-bit PC-relative TLS GD GOT reference, macro la.tls.gd High 20 bits of 32-bit PC-relative TLS IE GOT access, macro la.tls.ie High 20 bits of 32-bit PC-relative GOT access, %got_pcrel_hi(symbol) Indicates the symbol associated with a PLT entryĭeprecated, please use CALL_PLT instead 32-bit PC-relative function call, macros call, tailģ2-bit PC-relative function call, macros call, tail (PIC) Must be in executable not allowed in shared library Symbols can be found in Calculation Symbols DescriptionĪdditional information about the relocationĪdjust a link address (A) to its load address (B + A) A static relocation relocates a location in a relocatable file, processed by a static linker.Ī dynamic relocation relocates a location in an executable or shared object, processed by a run-time linker.īoth: Some relocation types are used by both static relocations and dynamic relocations.ĭescribes the set of bits affected by this relocation see Field Symbols for the definitions of the individual types Calculationįormula for how to resolve the relocation value definitions of the
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |