Changes in / [c936c7f:6c69d19] in mainline


Ignore:
Files:
15 added
33 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    rc936c7f r6c69d19  
    553553! CONFIG_WRITE_CORE_FILES (n/y)
    554554
    555 % Include development files (headers, libraries)
    556 ! [RDFMT=tmpfs] CONFIG_DEVEL_FILES (n/y)
    557 
    558555% Strip binaries
    559556! CONFIG_STRIP_BINARIES (n/y)
     
    564561% Barebone build with essential binaries only
    565562! CONFIG_BAREBONE (n/y)
    566 
    567 % Build pcc binaries
    568 ! CONFIG_PCC (n/y)
    569 
    570 % Build binutils binaries
    571 ! CONFIG_BINUTILS (n/y)
    572563
    573564% Line debugging information
  • Makefile

    rc936c7f r6c69d19  
    100100distclean: clean
    101101        rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc release/HelenOS-*
    102         cd ./uspace/app/binutils/; ./distclean.sh
    103102
    104103clean:
  • boot/Makefile

    rc936c7f r6c69d19  
    5858                cp "$$file" "$(DIST_PATH)/lib/" ; \
    5959        done
    60 ifeq ($(CONFIG_DEVEL_FILES), y)
    61         mkdir "$(DIST_PATH)/inc/c/"
    62         cp -r -L "$(USPACE_PATH)/lib/c/include/." "$(DIST_PATH)/inc/c/"
    63         cat "$(USPACE_PATH)/lib/c/arch/$(UARCH)/_link.ld" | sed 's/^STARTUP(.*)$$//g' > "$(DIST_PATH)/inc/_link.ld"
    64 endif
    6560        for file in $(RD_APPS) ; do \
    6661                cp "$$file" "$(DIST_PATH)/app/" ; \
     
    9691        rm -rf $(USPACE_PATH)/dist/drv/*
    9792        rm -f $(USPACE_PATH)/dist/lib/*
    98         rm -rf $(USPACE_PATH)/dist/inc/*
    9993        rm -f $(USPACE_PATH)/dist/app/*
    10094        rm -f $(USPACE_PATH)/dist/cfg/net/*
  • boot/Makefile.common

    rc936c7f r6c69d19  
    122122RD_LIBS =
    123123
    124 ifeq ($(CONFIG_DEVEL_FILES), y)
    125         RD_LIBS += \
    126                 $(USPACE_PATH)/lib/c/libc.a \
    127                 $(USPACE_PATH)/lib/softint/libsoftint.a \
    128                 $(USPACE_PATH)/lib/softfloat/libsoftfloat.a
    129 endif
    130 
    131124ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
    132125        RD_LIBS += \
     
    145138        $(USPACE_PATH)/app/blkdump/blkdump \
    146139        $(USPACE_PATH)/app/bnchmark/bnchmark \
     140        $(USPACE_PATH)/app/cc/cc \
     141        $(USPACE_PATH)/app/ccom/ccom \
     142        $(USPACE_PATH)/app/ccom/mkext/cc_mkext \
     143        $(USPACE_PATH)/app/cpp/cpp \
    147144        $(USPACE_PATH)/app/dltest/dltest \
    148145        $(USPACE_PATH)/app/dltest2/dltest2 \
     
    173170        $(USPACE_PATH)/app/websrv/websrv
    174171
    175 ifeq ($(CONFIG_PCC),y)
    176 RD_APPS_NON_ESSENTIAL += \
    177         $(USPACE_PATH)/app/cc/cc \
    178         $(USPACE_PATH)/app/ccom/ccom \
    179         $(USPACE_PATH)/app/ccom/mkext/cc_mkext \
    180         $(USPACE_PATH)/app/cpp/cpp
    181 endif
    182 
    183 ifeq ($(CONFIG_BINUTILS),y)
    184 RD_APPS_NON_ESSENTIAL += \
    185         $(USPACE_PATH)/app/binutils/bin/as \
    186         $(USPACE_PATH)/app/binutils/bin/ld
    187 endif
    188 
    189172ifneq ($(CONFIG_BAREBONE),y)
    190173NET_CFG = \
  • kernel/generic/include/lib/elf.h

    rc936c7f r6c69d19  
    4242 * current ELF version
    4343 */
    44 #define EV_CURRENT      1
     44#define EV_CURRENT  1
    4545
    4646/**
    4747 * ELF types
    4848 */
    49 #define ET_NONE         0       /* No type */
    50 #define ET_REL          1       /* Relocatable file */
    51 #define ET_EXEC         2       /* Executable */
    52 #define ET_DYN          3       /* Shared object */
    53 #define ET_CORE         4       /* Core */
    54 #define ET_LOPROC       0xff00  /* Processor specific */
    55 #define ET_HIPROC       0xffff  /* Processor specific */
     49#define ET_NONE    0       /* No type */
     50#define ET_REL     1       /* Relocatable file */
     51#define ET_EXEC    2       /* Executable */
     52#define ET_DYN     3       /* Shared object */
     53#define ET_CORE    4       /* Core */
     54#define ET_LOPROC  0xff00  /* Processor specific */
     55#define ET_HIPROC  0xffff  /* Processor specific */
    5656
    5757/**
    5858 * ELF machine types
    5959 */
    60 #define EM_NO           0       /* No machine */
    61 #define EM_SPARC        2       /* SPARC */
    62 #define EM_386          3       /* i386 */
    63 #define EM_MIPS         8       /* MIPS RS3000 */
    64 #define EM_MIPS_RS3_LE  10      /* MIPS RS3000 LE */
    65 #define EM_PPC          20      /* PPC32 */
    66 #define EM_PPC64        21      /* PPC64 */
    67 #define EM_ARM          40      /* ARM */
    68 #define EM_SPARCV9      43      /* SPARC64 */
    69 #define EM_IA_64        50      /* IA-64 */
    70 #define EM_X86_64       62      /* AMD64/EMT64 */
     60#define EM_NO           0   /* No machine */
     61#define EM_SPARC        2   /* SPARC */
     62#define EM_386          3   /* i386 */
     63#define EM_MIPS         8   /* MIPS RS3000 */
     64#define EM_MIPS_RS3_LE  10  /* MIPS RS3000 LE */
     65#define EM_PPC          20  /* PPC32 */
     66#define EM_PPC64        21  /* PPC64 */
     67#define EM_ARM          40  /* ARM */
     68#define EM_SPARCV9      43  /* SPARC64 */
     69#define EM_IA_64        50  /* IA-64 */
     70#define EM_X86_64       62  /* AMD64/EMT64 */
    7171
    7272/**
    7373 * ELF identification indexes
    7474 */
    75 #define EI_MAG0         0
    76 #define EI_MAG1         1
    77 #define EI_MAG2         2
    78 #define EI_MAG3         3
    79 #define EI_CLASS        4               /* File class */
    80 #define EI_DATA         5               /* Data encoding */
    81 #define EI_VERSION      6               /* File version */
    82 #define EI_OSABI        7
    83 #define EI_ABIVERSION   8
    84 #define EI_PAD          9               /* Start of padding bytes */
    85 #define EI_NIDENT       16              /* ELF identification table size */
     75#define EI_MAG0        0
     76#define EI_MAG1        1
     77#define EI_MAG2        2
     78#define EI_MAG3        3
     79#define EI_CLASS       4   /* File class */
     80#define EI_DATA        5   /* Data encoding */
     81#define EI_VERSION     6   /* File version */
     82#define EI_OSABI       7
     83#define EI_ABIVERSION  8
     84#define EI_PAD         9   /* Start of padding bytes */
     85#define EI_NIDENT      16  /* ELF identification table size */
    8686
    8787/**
    8888 * ELF magic number
    8989 */
    90 #define ELFMAG0         0x7f
    91 #define ELFMAG1         'E'
    92 #define ELFMAG2         'L'
    93 #define ELFMAG3         'F'
     90#define ELFMAG0  0x7f
     91#define ELFMAG1  'E'
     92#define ELFMAG2  'L'
     93#define ELFMAG3  'F'
    9494
    9595/**
    9696 * ELF file classes
    9797 */
    98 #define ELFCLASSNONE    0
    99 #define ELFCLASS32      1
    100 #define ELFCLASS64      2
     98#define ELFCLASSNONE  0
     99#define ELFCLASS32    1
     100#define ELFCLASS64    2
    101101
    102102/**
    103103 * ELF data encoding types
    104104 */
    105 #define ELFDATANONE     0
    106 #define ELFDATA2LSB     1               /* Least significant byte first (little endian) */
    107 #define ELFDATA2MSB     2               /* Most signigicant byte first (big endian) */
     105#define ELFDATANONE  0
     106#define ELFDATA2LSB  1  /* Least significant byte first (little endian) */
     107#define ELFDATA2MSB  2  /* Most signigicant byte first (big endian) */
     108
     109/**
     110 * ELF error return codes
     111 */
     112#define EE_OK             0  /* No error */
     113#define EE_INVALID        1  /* Invalid ELF image */
     114#define EE_MEMORY         2  /* Cannot allocate address space */
     115#define EE_INCOMPATIBLE   3  /* ELF image is not compatible with current architecture */
     116#define EE_UNSUPPORTED    4  /* Non-supported ELF (e.g. dynamic ELFs) */
     117#define EE_LOADER         5  /* The image is actually a program loader */
     118#define EE_IRRECOVERABLE  6
    108119
    109120/**
    110121 * ELF section types
    111122 */
    112 #define SHT_NULL                0
    113 #define SHT_PROGBITS            1
    114 #define SHT_SYMTAB              2
    115 #define SHT_STRTAB              3
    116 #define SHT_RELA                4
    117 #define SHT_HASH                5
    118 #define SHT_DYNAMIC             6
    119 #define SHT_NOTE                7
    120 #define SHT_NOBITS              8
    121 #define SHT_REL                 9
    122 #define SHT_SHLIB               10
    123 #define SHT_DYNSYM              11
    124 #define SHT_LOOS                0x60000000
    125 #define SHT_HIOS                0x6fffffff
    126 #define SHT_LOPROC              0x70000000
    127 #define SHT_HIPROC              0x7fffffff
    128 #define SHT_LOUSER              0x80000000
    129 #define SHT_HIUSER              0xffffffff
     123#define SHT_NULL      0
     124#define SHT_PROGBITS  1
     125#define SHT_SYMTAB    2
     126#define SHT_STRTAB    3
     127#define SHT_RELA      4
     128#define SHT_HASH      5
     129#define SHT_DYNAMIC   6
     130#define SHT_NOTE      7
     131#define SHT_NOBITS    8
     132#define SHT_REL       9
     133#define SHT_SHLIB     10
     134#define SHT_DYNSYM    11
     135#define SHT_LOOS      0x60000000
     136#define SHT_HIOS      0x6fffffff
     137#define SHT_LOPROC    0x70000000
     138#define SHT_HIPROC    0x7fffffff
     139#define SHT_LOUSER    0x80000000
     140#define SHT_HIUSER    0xffffffff
    130141
    131142/**
    132143 * ELF section flags
    133144 */
    134 #define SHF_WRITE               0x1
    135 #define SHF_ALLOC               0x2
    136 #define SHF_EXECINSTR           0x4
    137 #define SHF_TLS                 0x400
    138 #define SHF_MASKPROC            0xf0000000
    139 
    140 /** Macros for decomposing elf_symbol.st_info into binging and type */
    141 #define ELF_ST_BIND(i)          ((i) >> 4)
    142 #define ELF_ST_TYPE(i)          ((i) & 0x0f)
    143 #define ELF_ST_INFO(b, t)       (((b) << 4) + ((t) & 0x0f))
     145#define SHF_WRITE      0x1
     146#define SHF_ALLOC      0x2
     147#define SHF_EXECINSTR  0x4
     148#define SHF_TLS        0x400
     149#define SHF_MASKPROC   0xf0000000
    144150
    145151/**
    146152 * Symbol binding
    147153 */
    148 #define STB_LOCAL               0
    149 #define STB_GLOBAL              1
    150 #define STB_WEAK                2
    151 #define STB_LOPROC              13
    152 #define STB_HIPROC              15
     154#define STB_LOCAL   0
     155#define STB_GLOBAL  1
     156#define STB_WEAK    2
     157#define STB_LOPROC  13
     158#define STB_HIPROC  15
    153159
    154160/**
    155161 * Symbol types
    156162 */
    157 #define STT_NOTYPE              0
    158 #define STT_OBJECT              1
    159 #define STT_FUNC                2
    160 #define STT_SECTION             3
    161 #define STT_FILE                4
    162 #define STT_LOPROC              13
    163 #define STT_HIPROC              15
     163#define STT_NOTYPE   0
     164#define STT_OBJECT   1
     165#define STT_FUNC     2
     166#define STT_SECTION  3
     167#define STT_FILE     4
     168#define STT_LOPROC   13
     169#define STT_HIPROC   15
    164170
    165171/**
    166172 * Program segment types
    167173 */
    168 #define PT_NULL                 0
    169 #define PT_LOAD                 1
    170 #define PT_DYNAMIC              2
    171 #define PT_INTERP               3
    172 #define PT_NOTE                 4
    173 #define PT_SHLIB                5
    174 #define PT_PHDR                 6
    175 #define PT_LOPROC               0x70000000
    176 #define PT_HIPROC               0x7fffffff
     174#define PT_NULL     0
     175#define PT_LOAD     1
     176#define PT_DYNAMIC  2
     177#define PT_INTERP   3
     178#define PT_NOTE     4
     179#define PT_SHLIB    5
     180#define PT_PHDR     6
     181#define PT_LOPROC   0x70000000
     182#define PT_HIPROC   0x7fffffff
    177183
    178184/**
    179185 * Program segment attributes.
    180186 */
    181 #define PF_X    1
    182 #define PF_W    2
    183 #define PF_R    4
     187#define PF_X  1
     188#define PF_W  2
     189#define PF_R  4
    184190
    185191/**
     
    189195 * ELF object file specifications. They are the only types used
    190196 * in ELF header.
     197 *
    191198 */
    192199typedef uint64_t elf_xword;
     
    200207 *
    201208 * These types are specific for 32-bit format.
     209 *
    202210 */
    203211typedef uint32_t elf32_addr;
     
    208216 *
    209217 * These types are specific for 64-bit format.
     218 *
    210219 */
    211220typedef uint64_t elf64_addr;
     
    229238        elf_half e_shstrndx;
    230239};
     240
    231241struct elf64_header {
    232242        uint8_t e_ident[EI_NIDENT];
     
    246256};
    247257
    248 /*
     258/**
    249259 * ELF segment header.
    250260 * Segments headers are also known as program headers.
     
    260270        elf_word p_align;
    261271};
     272
    262273struct elf64_segment_header {
    263274        elf_word p_type;
     
    271282};
    272283
    273 /*
     284/**
    274285 * ELF section header
    275286 */
     
    286297        elf_word sh_entsize;
    287298};
     299
    288300struct elf64_section_header {
    289301        elf_word sh_name;
     
    299311};
    300312
    301 /*
     313/**
    302314 * ELF symbol table entry
    303315 */
     
    310322        elf_half st_shndx;
    311323};
     324
    312325struct elf64_symbol {
    313326        elf_word st_name;
     
    319332};
    320333
    321 /*
    322  * ELF note segment entry
    323  */
    324 struct elf32_note {
    325         elf_word namesz;
    326         elf_word descsz;
    327         elf_word type;
    328 };
    329 struct elf64_note {
    330         elf_xword namesz;
    331         elf_xword descsz;
    332         elf_xword type;
    333 };
    334 
    335334#ifdef __32_BITS__
    336335typedef struct elf32_header elf_header_t;
     
    338337typedef struct elf32_section_header elf_section_header_t;
    339338typedef struct elf32_symbol elf_symbol_t;
    340 typedef struct elf32_note elf_note_t;
    341339#endif
     340
    342341#ifdef __64_BITS__
    343342typedef struct elf64_header elf_header_t;
     
    345344typedef struct elf64_section_header elf_section_header_t;
    346345typedef struct elf64_symbol elf_symbol_t;
    347 typedef struct elf64_note elf_note_t;
    348346#endif
     347
     348extern const char *elf_error(unsigned int rc);
    349349
    350350/** Interpreter string used to recognize the program loader */
  • kernel/generic/include/mm/as.h

    rc936c7f r6c69d19  
    307307extern mem_backend_t phys_backend;
    308308
     309/**
     310 * This flags is passed when running the loader, otherwise elf_load()
     311 * would return with a EE_LOADER error code.
     312 *
     313 */
     314#define ELD_F_NONE    0
     315#define ELD_F_LOADER  1
     316
     317extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);
     318
    309319/* Address space area related syscalls. */
    310320extern sysarg_t sys_as_area_create(uintptr_t, size_t, unsigned int);
  • kernel/generic/src/lib/elf.c

    rc936c7f r6c69d19  
    4747#include <macros.h>
    4848#include <arch.h>
    49 
    50 #include <lib/elf_load.h>
    5149
    5250static const char *error_codes[] = {
  • kernel/generic/src/proc/program.c

    rc936c7f r6c69d19  
    4848#include <ipc/ipcrsc.h>
    4949#include <security/cap.h>
    50 #include <lib/elf_load.h>
     50#include <lib/elf.h>
    5151#include <errno.h>
    5252#include <print.h>
  • uspace/Makefile

    rc936c7f r6c69d19  
    3737        app/blkdump \
    3838        app/bnchmark \
     39        app/cc \
     40        app/ccom \
     41        app/ccom/mkext \
     42        app/cpp \
    3943        app/edit \
    4044        app/ext2info \
     
    111115        drv/bus/usb/vhc
    112116
    113 ifeq ($(CONFIG_PCC),y)
    114 DIRS += \
    115         app/cc \
    116         app/ccom \
    117         app/ccom/mkext \
    118         app/cpp
    119 endif
    120 
    121 ifeq ($(CONFIG_BINUTILS),y)
    122 DIRS += \
    123         app/binutils
    124 endif
    125 
    126117## Networking
    127118#
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    rc936c7f r6c69d19  
    169169               
    170170                /* fill the name field */
    171                 tosort[nbdirs].name = (char *) malloc(str_size(dp->d_name) + 1);
     171                tosort[nbdirs].name = (char *) malloc(str_length(dp->d_name) + 1);
    172172                if (!tosort[nbdirs].name) {
    173173                        cli_error(CL_ENOMEM, "ls: failed to scan %s", d);
    174174                        goto out;
    175175                }
    176 
    177                 str_cpy(tosort[nbdirs].name, str_size(dp->d_name) + 1, dp->d_name);
     176               
     177                str_cpy(tosort[nbdirs].name, str_length(dp->d_name) + 1, dp->d_name);
    178178                len = snprintf(buff, PATH_MAX - 1, "%s/%s", d, tosort[nbdirs].name);
    179179                buff[len] = '\0';
  • uspace/app/bdsh/exec.c

    rc936c7f r6c69d19  
    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/bdsh/input.c

    rc936c7f r6c69d19  
    169169                new_iostate.stdout = to;
    170170        }
    171 
    172         if (str_cmp(actual_cmd[0], "batch") == 0 && actual_cmd[1] != NULL) {
    173                 FILE *batch = fopen(actual_cmd[1], "r");
    174                 if (batch == NULL) {
    175                         printf("Cannot open file %s\n", actual_cmd[1]);
    176                         rc = errno;
    177                 } else {
    178                         cliuser_t fusr;
    179                         fusr.name = usr->name;
    180                         fusr.cwd = usr->cwd;
    181                         fusr.prompt = usr->prompt;
    182                         fusr.line = malloc(INPUT_MAX + 1);
    183                         char *cur = fusr.line;
    184                         char *end = fusr.line + INPUT_MAX;
    185                         int c = fgetc(batch);
    186                         while (fusr.line != NULL) {
    187                                 if (c == '\n' || c == EOF || cur == end) {
    188                                         *cur = '\0';
    189                                         if (cur == fusr.line) {
    190                                                 /* skip empty line */
    191                                                 rc = 0;
    192                                                 free(cur);
    193                                         } else {
    194                                                 printf(">%s\n", fusr.line);
    195                                                 rc = process_input(&fusr);
    196                                                 /* fusr->line was freed by process_input() */
    197                                         }
    198                                         if (rc == 0 && c != EOF) {
    199                                                 fusr.line = malloc(INPUT_MAX + 1);
    200                                                 cur = fusr.line;
    201                                                 end = fusr.line + INPUT_MAX;
    202                                         } else {
    203                                                 break;
    204                                         }
    205                                 } else {
    206                                         *cur++ = c;
    207                                 }
    208                                 c = fgetc(batch);
    209                         }
    210                         fclose(batch);
    211                 }
    212         } else {
    213                 rc = run_command(actual_cmd, usr, &new_iostate);
    214         }       
     171       
     172        rc = run_command(cmd, usr, &new_iostate);
    215173       
    216174finit_with_files:
  • uspace/app/init/init.c

    rc936c7f r6c69d19  
    294294       
    295295#ifdef CONFIG_MOUNT_DATA
    296         /* Make sure fat is running. */
    297         if (str_cmp(STRING(RDFMT), "fat") != 0) {
    298                 srv_start("/srv/fat");
    299         }
    300296        mount_data();
    301297#else
  • uspace/app/taskdump/elf_core.c

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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/app/tetris/tetris.c

    rc936c7f r6c69d19  
    291291                for (j = i + 1; j <= 5; j++) {
    292292                        if (keys[i] == keys[j])
    293                                 errx(1, "%s", "duplicate command keys specified.");
     293                                errx(1, "duplicate command keys specified.");
    294294                }
    295295               
  • uspace/lib/c/Makefile

    rc936c7f r6c69d19  
    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/arch/ia32/include/atomic.h

    rc936c7f r6c69d19  
    4343{
    4444        asm volatile (
    45                 "lock incl %0\n"
    46                 : "+m" (val->count)
     45                "lock incl %[count]\n"
     46                : [count] "+m" (val->count)
    4747        );
    4848}
     
    5151{
    5252        asm volatile (
    53                 "lock decl %0\n"
    54                 : "+m" (val->count)
     53                "lock decl %[count]\n"
     54                : [count] "+m" (val->count)
    5555        );
    5656}
     
    6161       
    6262        asm volatile (
    63                 "lock xaddl %1, %0\n"
    64                 : "+m" (val->count),
    65                   "+r" (r)
     63                "lock xaddl %[r], %[count]\n"
     64                : [count] "+m" (val->count),
     65                  [r] "+r" (r)
    6666        );
    6767       
     
    7474       
    7575        asm volatile (
    76                 "lock xaddl %1, %0\n"
    77                 : "+m" (val->count),
    78                   "+r" (r)
     76                "lock xaddl %[r], %[count]\n"
     77                : [count] "+m" (val->count),
     78                  [r] "+r" (r)
    7979        );
    8080       
  • uspace/lib/c/arch/ia32/include/ddi.h

    rc936c7f r6c69d19  
    4444       
    4545        asm volatile (
    46                 "inb %w1, %b0\n"
    47                 : "=a" (val)
    48                 : "d" (port)
     46                "inb %w[port], %b[val]\n"
     47                : [val] "=a" (val)
     48                : [port] "d" (port)
    4949        );
    5050       
     
    5757       
    5858        asm volatile (
    59                 "inw %w1, %w0\n"
    60                 : "=a" (val)
    61                 : "d" (port)
     59                "inw %w[port], %w[val]\n"
     60                : [val] "=a" (val)
     61                : [port] "d" (port)
    6262        );
    6363       
     
    7070       
    7171        asm volatile (
    72                 "inl %w1, %0\n"
    73                 : "=a" (val)
    74                 : "d" (port)
     72                "inl %w[port], %[val]\n"
     73                : [val] "=a" (val)
     74                : [port] "d" (port)
    7575        );
    7676       
     
    8181{
    8282        asm volatile (
    83                 "outb %b0, %w1\n"
    84                 :: "a" (val), "d" (port)
     83                "outb %b[val], %w[port]\n"
     84                :: [val] "a" (val), [port] "d" (port)
    8585        );
    8686}
     
    8989{
    9090        asm volatile (
    91                 "outw %w0, %w1\n"
    92                 :: "a" (val), "d" (port)
     91                "outw %w[val], %w[port]\n"
     92                :: [val] "a" (val), [port] "d" (port)
    9393        );
    9494}
     
    9797{
    9898        asm volatile (
    99                 "outl %0, %w1\n"
    100                 :: "a" (val), "d" (port)
     99                "outl %[val], %w[port]\n"
     100                :: [val] "a" (val), [port] "d" (port)
    101101        );
    102102}
  • uspace/lib/c/generic/io/io.c

    rc936c7f r6c69d19  
    594594                }
    595595               
    596                 data += now;
     596                buf += now;
    597597                stream->buf_head += now;
    598598                buf_free -= now;
    599599                bytes_left -= now;
    600600                total_written += now;
    601                 stream->buf_state = _bs_write;
    602601               
    603602                if (buf_free == 0) {
     
    607606                }
    608607        }
     608       
     609        if (total_written > 0)
     610                stream->buf_state = _bs_write;
    609611
    610612        if (need_flush)
  • uspace/lib/c/generic/rtld/module.c

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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

    rc936c7f r6c69d19  
    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.