Changes in / [1facf8e:0803134] in mainline


Ignore:
Location:
uspace
Files:
5 added
14 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/exec.c

    r1facf8e r0803134  
    5252static int try_access(const char *);
    5353
    54 const char *search_dir[] = { "/app", "/srv", NULL };
     54const char *search_dir[] = { "app", "srv", NULL };
    5555
    5656/* work-around for access() */
  • uspace/app/taskdump/elf_core.c

    r1facf8e r0803134  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2010 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838 * Looking at core files produced by Linux, these don't have section headers,
    3939 * only program headers, although objdump shows them as having sections.
    40  * Basically at the beginning there should be a note segment followed
    41  * by one loadable segment per memory area.
    42  *
    43  * The note segment contains a series of records with register state,
    44  * process info etc. We only write one record NT_PRSTATUS which contains
    45  * process/register state (anything which is not register state we fill
    46  * with zeroes).
    47  */
    48 
    49 #include <align.h>
    50 #include <elf/elf.h>
    51 #include <elf/elf_linux.h>
     40 * Basically at the beginning there should be a note segment (which we
     41 * do not write) and one loadable segment per memory area (which we do write).
     42 *
     43 * The note segment probably contains register state, etc. -- we don't
     44 * deal with these yet. Nevertheless you can use these core files with
     45 * objdump or gdb.
     46 */
     47
    5248#include <stdio.h>
    5349#include <stdlib.h>
     
    6258#include <udebug.h>
    6359#include <macros.h>
    64 #include <libarch/istate.h>
    65 
    66 #include "elf_core.h"
     60
     61#include <elf.h>
     62#include "include/elf_core.h"
    6763
    6864static off64_t align_foff_up(off64_t, uintptr_t, size_t);
    69 static int write_all(int, const void *, size_t);
    70 static int align_pos(int, size_t);
     65static int write_all(int, void *, size_t);
    7166static int write_mem_area(int, as_area_info_t *, async_sess_t *);
    7267
     
    8883 */
    8984int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n,
    90     async_sess_t *sess, istate_t *istate)
     85    async_sess_t *sess)
    9186{
    9287        elf_header_t elf_hdr;
     
    9590        elf_word flags;
    9691        elf_segment_header_t *p_hdr;
    97         elf_prstatus_t pr_status;
    98         elf_note_t note;
    99         size_t word_size;
    10092
    10193        int fd;
     
    10395        unsigned int i;
    10496
    105 #ifdef __32_BITS__
    106         word_size = 4;
    107 #endif
    108 #ifdef __64_BITS__
    109         word_size = 8;
    110 #endif
    111         memset(&pr_status, 0, sizeof(pr_status));
    112         istate_to_elf_regs(istate, &pr_status.regs);
    113 
    114         n_ph = n + 1;
    115 
    116         p_hdr = malloc(sizeof(elf_segment_header_t) * n_ph);
     97        n_ph = n;
     98
     99        p_hdr = malloc(sizeof(elf_segment_header_t) * n);
    117100        if (p_hdr == NULL) {
    118101                printf("Failed allocating memory.\n");
     
    132115         *      ELF header
    133116         *      program headers
    134          *      note segment
    135117         * repeat:
    136118         *      (pad for alignment)
    137          *      core segment
     119         *      segment data
    138120         * end repeat
    139121         */
     
    165147        foff = elf_hdr.e_phoff + n_ph * sizeof(elf_segment_header_t);
    166148
    167         memset(&p_hdr[0], 0, sizeof(p_hdr[0]));
    168         p_hdr[0].p_type = PT_NOTE;
    169         p_hdr[0].p_offset = foff;
    170         p_hdr[0].p_vaddr = 0;
    171         p_hdr[0].p_paddr = 0;
    172         p_hdr[0].p_filesz = sizeof(elf_note_t)
    173             + ALIGN_UP((str_size("CORE") + 1), word_size)
    174             + ALIGN_UP(sizeof(elf_prstatus_t), word_size);
    175         p_hdr[0].p_memsz = 0;
    176         p_hdr[0].p_flags = 0;
    177         p_hdr[0].p_align = 1;
    178 
    179         foff += p_hdr[0].p_filesz;
    180 
    181         for (i = 0; i < n; ++i) {
    182                 foff = align_foff_up(foff, ainfo[i].start_addr, PAGE_SIZE);
     149        for (i = 1; i <= n; ++i) {
     150                foff = align_foff_up(foff, ainfo[i - 1].start_addr, PAGE_SIZE);
    183151
    184152                flags = 0;
    185                 if (ainfo[i].flags & AS_AREA_READ)
     153                if (ainfo[i - 1].flags & AS_AREA_READ)
    186154                        flags |= PF_R;
    187                 if (ainfo[i].flags & AS_AREA_WRITE)
     155                if (ainfo[i - 1].flags & AS_AREA_WRITE)
    188156                        flags |= PF_W;
    189                 if (ainfo[i].flags & AS_AREA_EXEC)
     157                if (ainfo[i - 1].flags & AS_AREA_EXEC)
    190158                        flags |= PF_X;
    191159
    192                 memset(&p_hdr[i + 1], 0, sizeof(p_hdr[i + 1]));
    193                 p_hdr[i + 1].p_type = PT_LOAD;
    194                 p_hdr[i + 1].p_offset = foff;
    195                 p_hdr[i + 1].p_vaddr = ainfo[i].start_addr;
    196                 p_hdr[i + 1].p_paddr = 0;
    197                 p_hdr[i + 1].p_filesz = ainfo[i].size;
    198                 p_hdr[i + 1].p_memsz = ainfo[i].size;
    199                 p_hdr[i + 1].p_flags = flags;
    200                 p_hdr[i + 1].p_align = PAGE_SIZE;
    201 
    202                 foff += ainfo[i].size;
     160                memset(&p_hdr[i - 1], 0, sizeof(p_hdr[i - 1]));
     161                p_hdr[i - 1].p_type = PT_LOAD;
     162                p_hdr[i - 1].p_offset = foff;
     163                p_hdr[i - 1].p_vaddr = ainfo[i - 1].start_addr;
     164                p_hdr[i - 1].p_paddr = 0;
     165                p_hdr[i - 1].p_filesz = ainfo[i - 1].size;
     166                p_hdr[i - 1].p_memsz = ainfo[i - 1].size;
     167                p_hdr[i - 1].p_flags = flags;
     168                p_hdr[i - 1].p_align = PAGE_SIZE;
     169
     170                foff += ainfo[i - 1].size;
    203171        }
    204172
     
    219187        }
    220188
    221         if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) {
    222                 printf("Failed writing memory data.\n");
    223                 free(p_hdr);
    224                 return EIO;
    225         }
    226 
    227         /*
    228          * Write note header
    229          */
    230         note.namesz = str_size("CORE") + 1;
    231         note.descsz = sizeof(elf_prstatus_t);
    232         note.type = NT_PRSTATUS;
    233 
    234         rc = write_all(fd, &note, sizeof(elf_note_t));
    235         if (rc != EOK) {
    236                 printf("Failed writing note header.\n");
    237                 free(p_hdr);
    238                 return EIO;
    239         }
    240 
    241         rc = write_all(fd, "CORE", note.namesz);
    242         if (rc != EOK) {
    243                 printf("Failed writing note header.\n");
    244                 free(p_hdr);
    245                 return EIO;
    246         }
    247 
    248         rc = align_pos(fd, word_size);
    249         if (rc != EOK) {
    250                 printf("Failed writing note header.\n");
    251                 free(p_hdr);
    252                 return EIO;
    253         }
    254 
    255         rc = write_all(fd, &pr_status, sizeof(elf_prstatus_t));
    256         if (rc != EOK) {
    257                 printf("Failed writing register data.\n");
    258                 free(p_hdr);
    259                 return EIO;
    260         }
    261 
    262         for (i = 1; i < n_ph; ++i) {
     189        for (i = 0; i < n_ph; ++i) {
    263190                if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) {
    264191                        printf("Failed writing memory data.\n");
     
    266193                        return EIO;
    267194                }
    268                 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) {
     195                if (write_mem_area(fd, &ainfo[i], sess) != EOK) {
    269196                        printf("Failed writing memory data.\n");
    270197                        free(p_hdr);
     
    283210        off64_t rva = vaddr % page_size;
    284211        off64_t rfo = foff % page_size;
    285 
     212       
    286213        if (rva >= rfo)
    287214                return (foff + (rva - rfo));
    288 
     215       
    289216        return (foff + (page_size + (rva - rfo)));
    290217}
     
    341268 *                      failed.
    342269 */
    343 static int write_all(int fd, const void *data, size_t len)
     270static int write_all(int fd, void *data, size_t len)
    344271{
    345272        int cnt = 0;
     
    360287}
    361288
    362 static int align_pos(int fd, size_t align)
    363 {
    364         off64_t cur_pos;
    365         size_t rem, adv;
    366 
    367         cur_pos = lseek(fd, 0, SEEK_CUR);
    368         if (cur_pos < 0)
    369                 return -1;
    370 
    371         rem = cur_pos % align;
    372         adv = align - rem;
    373 
    374         cur_pos = lseek(fd, adv, SEEK_CUR);
    375         if (cur_pos < 0)
    376                 return -1;
    377 
    378         return EOK;
    379 }
    380289
    381290/** @}
  • uspace/app/taskdump/include/elf_core.h

    r1facf8e r0803134  
    3737
    3838#include <async.h>
    39 #include <elf/elf_linux.h>
    40 #include <libarch/istate.h>
    4139
    4240extern int elf_core_save(const char *, as_area_info_t *, unsigned int,
    43     async_sess_t *, istate_t *);
     41    async_sess_t *);
    4442
    4543#endif
  • uspace/app/taskdump/include/symtab.h

    r1facf8e r0803134  
    3636#define SYMTAB_H_
    3737
    38 #include <elf/elf.h>
    3938#include <sys/types.h>
     39#include <elf.h>
    4040
    4141typedef struct {
  • uspace/app/taskdump/symtab.c

    r1facf8e r0803134  
    3636 */
    3737
    38 #include <elf/elf.h>
    3938#include <stdio.h>
    4039#include <stdlib.h>
     
    4443#include <fcntl.h>
    4544
     45#include <elf.h>
    4646#include "include/symtab.h"
    4747
  • uspace/app/taskdump/taskdump.c

    r1facf8e r0803134  
    3434
    3535#include <async.h>
    36 #include <elf/elf_linux.h>
    3736#include <stdio.h>
    3837#include <stdlib.h>
     
    7372static char *get_app_task_name(void);
    7473static char *fmt_sym_address(uintptr_t addr);
    75 
    76 static istate_t reg_state;
    7774
    7875int main(int argc, char *argv[])
     
    296293        if (write_core_file) {
    297294                printf("Writing core file '%s'\n", core_file_name);
    298 
    299                 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess,
    300                     &reg_state);
    301 
     295                rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess);
    302296                if (rc != EOK) {
    303297                        printf("Failed writing core file.\n");
     
    327321        pc = istate_get_pc(&istate);
    328322        fp = istate_get_fp(&istate);
    329 
    330         /* Save register state for dumping to core file later. */
    331         reg_state = istate;
    332323
    333324        sym_pc = fmt_sym_address(pc);
  • uspace/lib/c/Makefile

    r1facf8e r0803134  
    5959-include arch/$(UARCH)/Makefile.inc
    6060
     61EXTRA_CFLAGS += -I../../srv/loader/include
     62
    6163GENERIC_SOURCES = \
    6264        generic/libc.c \
     
    6971        generic/device/hw_res.c \
    7072        generic/device/char_dev.c \
    71         generic/elf/elf_load.c \
    7273        generic/event.c \
    7374        generic/errno.c \
     
    133134                generic/dlfcn.c \
    134135                generic/rtld/rtld.c \
     136                generic/rtld/elf_load.c \
    135137                generic/rtld/dynamic.c \
    136138                generic/rtld/module.c \
  • uspace/lib/c/generic/rtld/module.c

    r1facf8e r0803134  
    3535 */
    3636
    37 #include <adt/list.h>
    38 #include <elf/elf_load.h>
    39 #include <fcntl.h>
    40 #include <loader/pcb.h>
    4137#include <stdio.h>
    4238#include <stdlib.h>
    4339#include <unistd.h>
     40#include <fcntl.h>
     41#include <adt/list.h>
     42#include <loader/pcb.h>
    4443
    4544#include <rtld/rtld.h>
     
    4847#include <rtld/rtld_arch.h>
    4948#include <rtld/module.h>
     49#include <elf_load.h>
    5050
    5151/** (Eagerly) process all relocation tables in a module.
     
    9393module_t *module_find(const char *name)
    9494{
     95        link_t *head = &runtime_env->modules_head;
     96
     97        link_t *cur;
    9598        module_t *m;
    9699        const char *p, *soname;
     
    107110
    108111        /* Traverse list of all modules. Not extremely fast, but simple */
    109         list_foreach(runtime_env->modules, cur) {
     112        DPRINTF("head = %p\n", head);
     113        for (cur = head->next; cur != head; cur = cur->next) {
    110114                DPRINTF("cur = %p\n", cur);
    111115                m = list_get_instance(cur, module_t, modules_link);
     
    173177
    174178        /* Insert into the list of loaded modules */
    175         list_append(&m->modules_link, &runtime_env->modules);
     179        list_append(&m->modules_link, &runtime_env->modules_head);
    176180
    177181        return m;
     
    245249void modules_process_relocs(module_t *start)
    246250{
    247         module_t *m;
    248 
    249         list_foreach(runtime_env->modules, cur) {
     251        link_t *head = &runtime_env->modules_head;
     252
     253        link_t *cur;
     254        module_t *m;
     255
     256        for (cur = head->next; cur != head; cur = cur->next) {
    250257                m = list_get_instance(cur, module_t, modules_link);
    251258
     
    261268void modules_untag(void)
    262269{
    263         module_t *m;
    264 
    265         list_foreach(runtime_env->modules, cur) {
     270        link_t *head = &runtime_env->modules_head;
     271
     272        link_t *cur;
     273        module_t *m;
     274
     275        for (cur = head->next; cur != head; cur = cur->next) {
    266276                m = list_get_instance(cur, module_t, modules_link);
    267277                m->bfs_tag = false;
  • uspace/lib/c/generic/rtld/rtld.c

    r1facf8e r0803134  
    4444{
    4545        runtime_env = &rt_env_static;
    46         list_initialize(&runtime_env->modules);
     46        list_initialize(&runtime_env->modules_head);
    4747        runtime_env->next_bias = 0x2000000;
    4848        runtime_env->program = NULL;
  • uspace/lib/c/generic/rtld/symbol.c

    r1facf8e r0803134  
    3838#include <stdlib.h>
    3939
    40 #include <elf/elf.h>
    4140#include <rtld/rtld.h>
    4241#include <rtld/rtld_debug.h>
    4342#include <rtld/symbol.h>
     43#include <elf.h>
    4444
    4545/*
     
    118118        module_t *m, *dm;
    119119        elf_symbol_t *sym, *s;
    120         list_t queue;
     120        link_t queue_head;
    121121        size_t i;
    122122
     
    132132
    133133        /* Insert root (the program) into the queue and tag it */
    134         list_initialize(&queue);
     134        list_initialize(&queue_head);
    135135        start->bfs_tag = true;
    136         list_append(&start->queue_link, &queue);
     136        list_append(&start->queue_link, &queue_head);
    137137
    138138        /* If the symbol is found, it will be stored in 'sym' */
     
    140140
    141141        /* While queue is not empty */
    142         while (!list_empty(&queue)) {
     142        while (!list_empty(&queue_head)) {
    143143                /* Pop first element from the queue */
    144                 m = list_get_instance(list_first(&queue), module_t, queue_link);
     144                m = list_get_instance(queue_head.next, module_t, queue_link);
    145145                list_remove(&m->queue_link);
    146146
     
    162162                        if (dm->bfs_tag == false) {
    163163                                dm->bfs_tag = true;
    164                                 list_append(&dm->queue_link, &queue);
     164                                list_append(&dm->queue_link, &queue_head);
    165165                        }
    166166                }
     
    168168
    169169        /* Empty the queue so that we leave it in a clean state */
    170         while (!list_empty(&queue))
    171                 list_remove(list_first(&queue));
     170        while (!list_empty(&queue_head))
     171                list_remove(queue_head.next);
    172172
    173173        if (!sym) {
  • uspace/lib/c/include/rtld/elf_dyn.h

    r1facf8e r0803134  
    3939#include <sys/types.h>
    4040
    41 #include <elf/elf.h>
     41#include <elf.h>
    4242#include <libarch/rtld/elf_dyn.h>
    4343
  • uspace/lib/c/include/rtld/rtld.h

    r1facf8e r0803134  
    4949
    5050        /** List of all loaded modules including rtld and the program */
    51         list_t modules;
     51        link_t modules_head;
    5252
    5353        /** Temporary hack to place each module at different address. */
  • uspace/lib/c/include/rtld/symbol.h

    r1facf8e r0803134  
    3636#define LIBC_RTLD_SYMBOL_H_
    3737
    38 #include <elf/elf.h>
    3938#include <rtld/rtld.h>
     39#include <elf.h>
    4040
    4141elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod);
  • uspace/srv/loader/Makefile

    r1facf8e r0803134  
    3939LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld
    4040
     41EXTRA_CFLAGS = -Iinclude
     42
    4143BINARY = loader
    4244STATIC_ONLY = y
     
    4446GENERIC_SOURCES = \
    4547        main.c \
     48        elf_load.c \
    4649        interp.s
    4750
  • uspace/srv/loader/main.c

    r1facf8e r0803134  
    5959#include <str.h>
    6060#include <as.h>
    61 #include <elf/elf.h>
    62 #include <elf/elf_load.h>
     61#include <elf.h>
     62#include <elf_load.h>
    6363
    6464#ifdef CONFIG_RTLD
     
    348348
    349349        /* Initialize list of loaded modules */
    350         list_initialize(&runtime_env->modules);
    351         list_append(&prog_mod.modules_link, &runtime_env->modules);
     350        list_initialize(&runtime_env->modules_head);
     351        list_append(&prog_mod.modules_link, &runtime_env->modules_head);
    352352
    353353        /* Pointer to program module. Used as root of the module graph. */
Note: See TracChangeset for help on using the changeset viewer.