/*@ * @deftypefun int jit_writeelf_write_section (jit_writeelf_t @var{writeelf}, const char *@var{name}, jit_int @var{type}, const void *@var{buf}, unsigned int @var{len}, int @var{discardable}) * Write auxillary data to a section called @var{name}. If @var{type} * is not zero, then it indicates an ELF section type. This is used * by virtual machines to store auxillary data that can be retrieved * later using @code{jit_readelf_get_section}. If the section already * contains data, then this will append the new data. If @var{discardable} * is non-zero, then it is OK for this section to be discarded when the * ELF binary is stripped. Returns zero if out of memory or the * parameters are invalid. * @end deftypefun @*/ int jit_writeelf_write_section (jit_writeelf_t writeelf, const char *name, jit_int type, const void *buf, unsigned int len, int discardable) { jit_section_t section; if(!writeelf || !name) { return 0; } if(!type) { /* Application-specific section type, for storing unspecified data */ type = (jit_int)(SHT_LOUSER + 0x1234); } if(discardable) { section = get_section(writeelf, name, type, 0, 1, 1); } else { section = get_section(writeelf, name, type, SHF_ALLOC, 1, 1); } if(!section) { return 0; } if(len > 0) { return add_to_section(section, buf, len);; } else { return 1; } }
/* * Add an entry to the dynamic linking information section. */ static int add_dyn_info (jit_writeelf_t writeelf, int type, Elf_Addr value, int modify_existing) { jit_section_t section; Elf_Dyn dyn; /* Get or create the ".dynamic" section */ section = get_section(writeelf, ".dynamic", SHT_DYNAMIC, SHF_WRITE | SHF_ALLOC, sizeof(Elf_Dyn), sizeof(Elf_Dyn)); if(!section) { return 0; } /* See if we already have this entry, and modify it as appropriate */ if(modify_existing) { Elf_Dyn *existing = (Elf_Dyn *)(section->data); unsigned int num = section->data_len / sizeof(Elf_Dyn); while(num > 0) { if(existing->d_tag == type) { existing->d_un.d_ptr = value; return 1; } ++existing; --num; } } /* Format the dynamic entry */ jit_memzero(&dyn, sizeof(dyn)); dyn.d_tag = type; dyn.d_un.d_ptr = value; /* Add the entry to the section's contents */ return add_to_section(section, &dyn, sizeof(dyn)); }
static __inline__ void parse_rw_file(rw_file *fp, gchar *p) { gint line_terminated = 0; rw_section *rw_sec = NULL; gchar *sec_b = NULL, *sec_e = NULL; gchar *name = NULL, *value = NULL; while (*p) { if (*p == ' ' || *p == '\t') { ++p; continue; } if (*p == '\r' || *p == '\n') { *p = 0; if (name && rw_sec) add_to_section(rw_sec, name, value); if (sec_b) { if (!sec_e) { g_free(rw_sec); rw_sec = NULL; } else *sec_e = 0; } sec_b = NULL; sec_e = NULL; name = NULL; value = NULL; line_terminated = 0; ++p; continue; } if (line_terminated) { ++p; continue; } if (*p == '[') { if (!name && !sec_b) //'[' not in name or value. { if (rw_sec) add_one_section(fp, rw_sec); rw_sec = g_new0(rw_section, 1); sec_b = p + 1; rw_sec->name = sec_b; } ++p; continue; } if (*p == ']') { sec_e = p; ++p; continue; } if (*p == '=') { *p = 0; if (name) value = p + 1; ++p; continue; } if (*p == '#') { line_terminated = 1; *p++ = 0; continue; } if (!sec_b && !name) name = p; ++p; continue; } if (rw_sec) add_one_section(fp, rw_sec); }