Changes in / [358dc13:efcebe1] in mainline
- Files:
-
- 30 added
- 18 deleted
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/mips32/src/Makefile
r358dc13 refcebe1 32 32 .PHONY: all clean 33 33 34 all: ../../../../version ../../../../Makefile.co mmon ../../../../Makefile.config ../../../../config.h34 all: ../../../../version ../../../../Makefile.config ../../../../config.h ../../../../config.defs 35 35 -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV) 36 36 $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK) 37 37 38 38 clean: 39 rm -f $(USPACEDIR)/dist/srv/*40 rm -f $(USPACEDIR)/dist/app/*41 rm -f $(USPACEDIR)/dist/cfg/net/*42 43 39 for file in $(RD_SRVS) ; do \ 44 40 rm -f $(USPACEDIR)/dist/srv/`basename $$file` ; \ … … 47 43 rm -f $(USPACEDIR)/dist/app/`basename $$file` ; \ 48 44 done 49 for file in $(NET_CFG) ; do \50 rm -f $(USPACEDIR)/dist/cfg/net/`basename $$file` ; \51 done52 45 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(RAW) $(COMPS).h $(COMPS).c $(LINK) $(INITRD).img $(INITRD).fs 53 46 find . -name '*.o' -follow -exec rm \{\} \; -
boot/arch/mips32/src/Makefile.build
r358dc13 refcebe1 32 32 33 33 include ../../../../version 34 include ../../../../Makefile.common35 34 include ../../../../Makefile.config 35 include ../../../../config.defs 36 36 include Makefile.common 37 37 include Makefile.toolchain … … 77 77 78 78 $(DEPEND): 79 rm -f $(USPACEDIR)/dist/srv/*80 rm -f $(USPACEDIR)/dist/app/*81 rm -f $(USPACEDIR)/dist/cfg/net/*82 83 79 for file in $(RD_SRVS) ; do \ 84 80 cp $$file $(USPACEDIR)/dist/srv/ ; \ … … 86 82 for file in $(RD_APPS) ; do \ 87 83 cp $$file $(USPACEDIR)/dist/app/ ; \ 88 done89 for file in $(NET_CFG) ; do \90 cp $$file $(USPACEDIR)/dist/cfg/net/ ; \91 84 done 92 85 ifeq ($(RDFMT),tmpfs) -
boot/arch/mips32/src/Makefile.toolchain
r358dc13 refcebe1 27 27 # 28 28 29 ## Toolchain configuration 30 # 31 32 ifndef CROSS_PREFIX 33 CROSS_PREFIX = /usr/local 34 endif 35 29 36 BFD_ARCH = mips 37 TARGET = mipsel-linux-gnu 38 TOOLCHAIN_DIR = $(CROSS_PREFIX)/mips32/bin 30 39 31 40 JOBFILE = ../../../../tools/jobfile.py … … 39 48 BFD_NAME = elf32-tradbigmips 40 49 BFD = ecoff-bigmips 50 TOOLCHAIN_DIR = $(CROSS_PREFIX)/mips32eb/bin 51 TARGET = mips-linux-gnu 41 52 endif 42 53 … … 44 55 BFD_NAME = elf32-tradlittlemips 45 56 BFD = binary 57 endif 58 59 ifeq ($(COMPILER),gcc_native) 60 CC = gcc 61 AS = as 62 LD = ld 63 OBJCOPY = objcopy 64 OBJDUMP = objdump 65 endif 66 67 ifeq ($(COMPILER),gcc_cross) 68 CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc 69 AS = $(TOOLCHAIN_DIR)/$(TARGET)-as 70 LD = $(TOOLCHAIN_DIR)/$(TARGET)-ld 71 OBJCOPY = $(TOOLCHAIN_DIR)/$(TARGET)-objcopy 72 OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump 46 73 endif 47 74 -
kernel/generic/include/lib/elf.h
r358dc13 refcebe1 42 42 * current ELF version 43 43 */ 44 #define EV_CURRENT 44 #define EV_CURRENT 1 45 45 46 46 /** 47 47 * ELF types 48 48 */ 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 */ 56 56 57 57 /** 58 58 * ELF machine types 59 59 */ 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 */ 71 71 72 72 /** 73 73 * ELF identification indexes 74 74 */ 75 #define EI_MAG0 76 #define EI_MAG1 77 #define EI_MAG2 78 #define EI_MAG3 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 83 #define EI_ABIVERSION 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 */ 86 86 87 87 /** 88 88 * ELF magic number 89 89 */ 90 #define ELFMAG0 91 #define ELFMAG1 92 #define ELFMAG2 93 #define ELFMAG3 90 #define ELFMAG0 0x7f 91 #define ELFMAG1 'E' 92 #define ELFMAG2 'L' 93 #define ELFMAG3 'F' 94 94 95 95 /** 96 96 * ELF file classes 97 97 */ 98 #define ELFCLASSNONE 99 #define ELFCLASS32 100 #define ELFCLASS64 98 #define ELFCLASSNONE 0 99 #define ELFCLASS32 1 100 #define ELFCLASS64 2 101 101 102 102 /** 103 103 * ELF data encoding types 104 104 */ 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 108 119 109 120 /** 110 121 * ELF section types 111 122 */ 112 #define SHT_NULL 113 #define SHT_PROGBITS 114 #define SHT_SYMTAB 115 #define SHT_STRTAB 116 #define SHT_RELA 117 #define SHT_HASH 118 #define SHT_DYNAMIC 119 #define SHT_NOTE 120 #define SHT_NOBITS 121 #define SHT_REL 122 #define SHT_SHLIB 123 #define SHT_DYNSYM 124 #define SHT_LOOS 125 #define SHT_HIOS 126 #define SHT_LOPROC 127 #define SHT_HIPROC 128 #define SHT_LOUSER 129 #define SHT_HIUSER 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 130 141 131 142 /** 132 143 * ELF section flags 133 144 */ 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 144 150 145 151 /** 146 152 * Symbol binding 147 153 */ 148 #define STB_LOCAL 149 #define STB_GLOBAL 150 #define STB_WEAK 151 #define STB_LOPROC 152 #define STB_HIPROC 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 153 159 154 160 /** 155 161 * Symbol types 156 162 */ 157 #define STT_NOTYPE 158 #define STT_OBJECT 159 #define STT_FUNC 160 #define STT_SECTION 161 #define STT_FILE 162 #define STT_LOPROC 163 #define STT_HIPROC 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 164 170 165 171 /** 166 172 * Program segment types 167 173 */ 168 #define PT_NULL 169 #define PT_LOAD 170 #define PT_DYNAMIC 171 #define PT_INTERP 172 #define PT_NOTE 173 #define PT_SHLIB 174 #define PT_PHDR 175 #define PT_LOPROC 176 #define PT_HIPROC 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 177 183 178 184 /** 179 185 * Program segment attributes. 180 186 */ 181 #define PF_X 182 #define PF_W 183 #define PF_R 187 #define PF_X 1 188 #define PF_W 2 189 #define PF_R 4 184 190 185 191 /** … … 189 195 * ELF object file specifications. They are the only types used 190 196 * in ELF header. 197 * 191 198 */ 192 199 typedef uint64_t elf_xword; … … 200 207 * 201 208 * These types are specific for 32-bit format. 209 * 202 210 */ 203 211 typedef uint32_t elf32_addr; … … 208 216 * 209 217 * These types are specific for 64-bit format. 218 * 210 219 */ 211 220 typedef uint64_t elf64_addr; … … 229 238 elf_half e_shstrndx; 230 239 }; 240 231 241 struct elf64_header { 232 242 uint8_t e_ident[EI_NIDENT]; … … 246 256 }; 247 257 248 /* 258 /** 249 259 * ELF segment header. 250 260 * Segments headers are also known as program headers. … … 260 270 elf_word p_align; 261 271 }; 272 262 273 struct elf64_segment_header { 263 274 elf_word p_type; … … 271 282 }; 272 283 273 /* 284 /** 274 285 * ELF section header 275 286 */ … … 286 297 elf_word sh_entsize; 287 298 }; 299 288 300 struct elf64_section_header { 289 301 elf_word sh_name; … … 299 311 }; 300 312 301 /* 313 /** 302 314 * ELF symbol table entry 303 315 */ … … 310 322 elf_half st_shndx; 311 323 }; 324 312 325 struct elf64_symbol { 313 326 elf_word st_name; … … 319 332 }; 320 333 321 /*322 * ELF note segment entry323 */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 335 334 #ifdef __32_BITS__ 336 335 typedef struct elf32_header elf_header_t; … … 338 337 typedef struct elf32_section_header elf_section_header_t; 339 338 typedef struct elf32_symbol elf_symbol_t; 340 typedef struct elf32_note elf_note_t;341 339 #endif 340 342 341 #ifdef __64_BITS__ 343 342 typedef struct elf64_header elf_header_t; … … 345 344 typedef struct elf64_section_header elf_section_header_t; 346 345 typedef struct elf64_symbol elf_symbol_t; 347 typedef struct elf64_note elf_note_t;348 346 #endif 347 348 extern const char *elf_error(unsigned int rc); 349 349 350 350 /** Interpreter string used to recognize the program loader */ -
kernel/generic/include/mm/as.h
r358dc13 refcebe1 307 307 extern mem_backend_t phys_backend; 308 308 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 317 extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int); 318 309 319 /* Address space area related syscalls. */ 310 320 extern sysarg_t sys_as_area_create(uintptr_t, size_t, unsigned int); -
kernel/generic/src/lib/elf.c
r358dc13 refcebe1 47 47 #include <macros.h> 48 48 #include <arch.h> 49 50 #include <lib/elf_load.h>51 49 52 50 static const char *error_codes[] = { -
kernel/generic/src/proc/program.c
r358dc13 refcebe1 48 48 #include <ipc/ipcrsc.h> 49 49 #include <security/cap.h> 50 #include <lib/elf _load.h>50 #include <lib/elf.h> 51 51 #include <errno.h> 52 52 #include <print.h> -
uspace/app/bdsh/exec.c
r358dc13 refcebe1 52 52 static int try_access(const char *); 53 53 54 const char *search_dir[] = { " /app", "/srv", NULL };54 const char *search_dir[] = { "app", "srv", NULL }; 55 55 56 56 /* work-around for access() */ -
uspace/app/taskdump/elf_core.c
r358dc13 refcebe1 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 * Looking at core files produced by Linux, these don't have section headers, 39 39 * 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 52 48 #include <stdio.h> 53 49 #include <stdlib.h> … … 62 58 #include <udebug.h> 63 59 #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" 67 63 68 64 static off64_t align_foff_up(off64_t, uintptr_t, size_t); 69 static int align_pos(int, size_t);65 static int write_all(int, void *, size_t); 70 66 static int write_mem_area(int, as_area_info_t *, async_sess_t *); 71 67 … … 87 83 */ 88 84 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, 89 async_sess_t *sess , istate_t *istate)85 async_sess_t *sess) 90 86 { 91 87 elf_header_t elf_hdr; … … 94 90 elf_word flags; 95 91 elf_segment_header_t *p_hdr; 96 elf_prstatus_t pr_status;97 elf_note_t note;98 size_t word_size;99 92 100 93 int fd; 101 ssize_t rc;94 int rc; 102 95 unsigned int i; 103 96 104 #ifdef __32_BITS__ 105 word_size = 4; 106 #endif 107 #ifdef __64_BITS__ 108 word_size = 8; 109 #endif 110 memset(&pr_status, 0, sizeof(pr_status)); 111 istate_to_elf_regs(istate, &pr_status.regs); 112 113 n_ph = n + 1; 114 115 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); 116 100 if (p_hdr == NULL) { 117 101 printf("Failed allocating memory.\n"); … … 131 115 * ELF header 132 116 * program headers 133 * note segment134 117 * repeat: 135 118 * (pad for alignment) 136 * core segment119 * segment data 137 120 * end repeat 138 121 */ … … 164 147 foff = elf_hdr.e_phoff + n_ph * sizeof(elf_segment_header_t); 165 148 166 memset(&p_hdr[0], 0, sizeof(p_hdr[0])); 167 p_hdr[0].p_type = PT_NOTE; 168 p_hdr[0].p_offset = foff; 169 p_hdr[0].p_vaddr = 0; 170 p_hdr[0].p_paddr = 0; 171 p_hdr[0].p_filesz = sizeof(elf_note_t) 172 + ALIGN_UP((str_size("CORE") + 1), word_size) 173 + ALIGN_UP(sizeof(elf_prstatus_t), word_size); 174 p_hdr[0].p_memsz = 0; 175 p_hdr[0].p_flags = 0; 176 p_hdr[0].p_align = 1; 177 178 foff += p_hdr[0].p_filesz; 179 180 for (i = 0; i < n; ++i) { 181 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); 182 151 183 152 flags = 0; 184 if (ainfo[i ].flags & AS_AREA_READ)153 if (ainfo[i - 1].flags & AS_AREA_READ) 185 154 flags |= PF_R; 186 if (ainfo[i ].flags & AS_AREA_WRITE)155 if (ainfo[i - 1].flags & AS_AREA_WRITE) 187 156 flags |= PF_W; 188 if (ainfo[i ].flags & AS_AREA_EXEC)157 if (ainfo[i - 1].flags & AS_AREA_EXEC) 189 158 flags |= PF_X; 190 159 191 memset(&p_hdr[i + 1], 0, sizeof(p_hdr[i +1]));192 p_hdr[i +1].p_type = PT_LOAD;193 p_hdr[i +1].p_offset = foff;194 p_hdr[i + 1].p_vaddr = ainfo[i].start_addr;195 p_hdr[i +1].p_paddr = 0;196 p_hdr[i + 1].p_filesz = ainfo[i].size;197 p_hdr[i + 1].p_memsz = ainfo[i].size;198 p_hdr[i +1].p_flags = flags;199 p_hdr[i +1].p_align = PAGE_SIZE;200 201 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; 202 171 } 203 172 204 173 rc = write_all(fd, &elf_hdr, sizeof(elf_hdr)); 205 if (rc != sizeof(elf_hdr)) {174 if (rc != EOK) { 206 175 printf("Failed writing ELF header.\n"); 207 176 free(p_hdr); … … 211 180 for (i = 0; i < n_ph; ++i) { 212 181 rc = write_all(fd, &p_hdr[i], sizeof(p_hdr[i])); 213 if (rc != sizeof(p_hdr[i])) {182 if (rc != EOK) { 214 183 printf("Failed writing program header.\n"); 215 184 free(p_hdr); … … 218 187 } 219 188 220 if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) { 221 printf("Failed writing memory data.\n"); 222 free(p_hdr); 223 return EIO; 224 } 225 226 /* 227 * Write note header 228 */ 229 note.namesz = str_size("CORE") + 1; 230 note.descsz = sizeof(elf_prstatus_t); 231 note.type = NT_PRSTATUS; 232 233 rc = write_all(fd, ¬e, sizeof(elf_note_t)); 234 if (rc != sizeof(elf_note_t)) { 235 printf("Failed writing note header.\n"); 236 free(p_hdr); 237 return EIO; 238 } 239 240 rc = write_all(fd, "CORE", note.namesz); 241 if (rc != (ssize_t) note.namesz) { 242 printf("Failed writing note header.\n"); 243 free(p_hdr); 244 return EIO; 245 } 246 247 rc = align_pos(fd, word_size); 248 if (rc != EOK) { 249 printf("Failed writing note header.\n"); 250 free(p_hdr); 251 return EIO; 252 } 253 254 rc = write_all(fd, &pr_status, sizeof(elf_prstatus_t)); 255 if (rc != sizeof(elf_prstatus_t)) { 256 printf("Failed writing register data.\n"); 257 free(p_hdr); 258 return EIO; 259 } 260 261 for (i = 1; i < n_ph; ++i) { 189 for (i = 0; i < n_ph; ++i) { 262 190 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) { 263 191 printf("Failed writing memory data.\n"); … … 265 193 return EIO; 266 194 } 267 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) {195 if (write_mem_area(fd, &ainfo[i], sess) != EOK) { 268 196 printf("Failed writing memory data.\n"); 269 197 free(p_hdr); … … 282 210 off64_t rva = vaddr % page_size; 283 211 off64_t rfo = foff % page_size; 284 212 285 213 if (rva >= rfo) 286 214 return (foff + (rva - rfo)); 287 215 288 216 return (foff + (page_size + (rva - rfo))); 289 217 } … … 303 231 size_t total; 304 232 uintptr_t addr; 305 ssize_t rc;233 int rc; 306 234 307 235 addr = area->start_addr; … … 317 245 318 246 rc = write_all(fd, buffer, to_copy); 319 if (rc != (ssize_t) to_copy) {247 if (rc != EOK) { 320 248 printf("Failed writing memory contents.\n"); 321 249 return EIO; … … 329 257 } 330 258 331 static int align_pos(int fd, size_t align) 332 { 333 off64_t cur_pos; 334 size_t rem, adv; 335 336 cur_pos = lseek(fd, 0, SEEK_CUR); 337 if (cur_pos < 0) 338 return -1; 339 340 rem = cur_pos % align; 341 adv = align - rem; 342 343 cur_pos = lseek(fd, adv, SEEK_CUR); 344 if (cur_pos < 0) 345 return -1; 259 /** Write until the buffer is written in its entirety. 260 * 261 * This function fails if it cannot write exactly @a len bytes to the file. 262 * 263 * @param fd The file to write to. 264 * @param buf Data, @a len bytes long. 265 * @param len Number of bytes to write. 266 * 267 * @return EOK on error, return value from write() if writing 268 * failed. 269 */ 270 static int write_all(int fd, void *data, size_t len) 271 { 272 int cnt = 0; 273 274 do { 275 data += cnt; 276 len -= cnt; 277 cnt = write(fd, data, len); 278 } while (cnt > 0 && (len - cnt) > 0); 279 280 if (cnt < 0) 281 return cnt; 282 283 if (len - cnt > 0) 284 return EIO; 346 285 347 286 return EOK; 348 287 } 349 288 289 350 290 /** @} 351 291 */ -
uspace/app/taskdump/include/elf_core.h
r358dc13 refcebe1 37 37 38 38 #include <async.h> 39 #include <elf/elf_linux.h>40 #include <libarch/istate.h>41 39 42 40 extern int elf_core_save(const char *, as_area_info_t *, unsigned int, 43 async_sess_t * , istate_t *);41 async_sess_t *); 44 42 45 43 #endif -
uspace/app/taskdump/include/symtab.h
r358dc13 refcebe1 36 36 #define SYMTAB_H_ 37 37 38 #include <elf/elf.h>39 38 #include <sys/types.h> 39 #include <elf.h> 40 40 41 41 typedef struct { -
uspace/app/taskdump/symtab.c
r358dc13 refcebe1 36 36 */ 37 37 38 #include <elf/elf.h>39 38 #include <stdio.h> 40 39 #include <stdlib.h> … … 44 43 #include <fcntl.h> 45 44 45 #include <elf.h> 46 46 #include "include/symtab.h" 47 47 … … 50 50 elf_section_header_t *shdr); 51 51 static int chunk_load(int fd, off64_t start, size_t size, void **ptr); 52 static int read_all(int fd, void *buf, size_t len); 52 53 53 54 /** Load symbol table from an ELF file. … … 89 90 90 91 rc = read_all(fd, &elf_hdr, sizeof(elf_header_t)); 91 if (rc != sizeof(elf_header_t)) {92 if (rc != EOK) { 92 93 printf("failed reading elf header\n"); 93 94 free(stab); … … 311 312 312 313 rc = read_all(fd, sec_hdr, sizeof(elf_section_header_t)); 313 if (rc != sizeof(elf_section_header_t))314 if (rc != EOK) 314 315 return EIO; 315 316 … … 330 331 static int chunk_load(int fd, off64_t start, size_t size, void **ptr) 331 332 { 332 ssize_t rc; 333 off64_t offs; 334 335 offs = lseek(fd, start, SEEK_SET); 336 if (offs == (off64_t) -1) { 333 int rc; 334 335 rc = lseek(fd, start, SEEK_SET); 336 if (rc == (off64_t) -1) { 337 337 printf("failed seeking chunk\n"); 338 338 *ptr = NULL; … … 347 347 348 348 rc = read_all(fd, *ptr, size); 349 if (rc != (ssize_t) size) {349 if (rc != EOK) { 350 350 printf("failed reading chunk\n"); 351 351 free(*ptr); … … 357 357 } 358 358 359 /** Read until the buffer is read in its entirety. 360 * 361 * This function fails if it cannot read exactly @a len bytes from the file. 362 * 363 * @param fd The file to read from. 364 * @param buf Buffer for storing data, @a len bytes long. 365 * @param len Number of bytes to read. 366 * 367 * @return EOK on error, EIO if file is short or return value 368 * from read() if reading failed. 369 */ 370 static int read_all(int fd, void *buf, size_t len) 371 { 372 int cnt = 0; 373 374 do { 375 buf += cnt; 376 len -= cnt; 377 cnt = read(fd, buf, len); 378 } while (cnt > 0 && (len - cnt) > 0); 379 380 if (cnt < 0) 381 return cnt; 382 383 if (len - cnt > 0) 384 return EIO; 385 386 return EOK; 387 } 388 359 389 /** @} 360 390 */ -
uspace/app/taskdump/taskdump.c
r358dc13 refcebe1 34 34 35 35 #include <async.h> 36 #include <elf/elf_linux.h>37 36 #include <stdio.h> 38 37 #include <stdlib.h> … … 73 72 static char *get_app_task_name(void); 74 73 static char *fmt_sym_address(uintptr_t addr); 75 76 static istate_t reg_state;77 74 78 75 int main(int argc, char *argv[]) … … 296 293 if (write_core_file) { 297 294 printf("Writing core file '%s'\n", core_file_name); 298 299 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess, 300 ®_state); 301 295 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess); 302 296 if (rc != EOK) { 303 297 printf("Failed writing core file.\n"); … … 327 321 pc = istate_get_pc(&istate); 328 322 fp = istate_get_fp(&istate); 329 330 /* Save register state for dumping to core file later. */331 reg_state = istate;332 323 333 324 sym_pc = fmt_sym_address(pc); -
uspace/drv/bus/usb/usbmast/bo_trans.c
r358dc13 refcebe1 58 58 * @param tag Command block wrapper tag (automatically compared 59 59 * with answer) 60 * @param cmd SCSI command 60 * @param cmd Command block 61 * @param cmd_size Command block size in bytes 62 * @param ddir Direction in which data will be transferred 63 * @param dbuf Data send/receive buffer 64 * @param dbuf_size Size of the data buffer 65 * @param xferred_size Number of bytes actually transferred 61 66 * 62 67 * @return Error code 63 68 */ 64 int usb_massstor_cmd(usbmast_fun_t *mfun, uint32_t tag, scsi_cmd_t *cmd) 69 static int usb_massstor_cmd(usbmast_fun_t *mfun, uint32_t tag, const void *cmd, 70 size_t cmd_size, usb_direction_t ddir, void *dbuf, size_t dbuf_size, 71 size_t *xferred_size) 65 72 { 66 73 int rc; 67 int retval = EOK;68 74 size_t act_size; 69 75 usb_pipe_t *bulk_in_pipe = mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe; 70 76 usb_pipe_t *bulk_out_pipe = mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe; 71 usb_direction_t ddir;72 void *dbuf;73 size_t dbuf_size;74 75 if (cmd->data_out != NULL && cmd->data_in == NULL) {76 ddir = USB_DIRECTION_OUT;77 dbuf = (void *)cmd->data_out;78 dbuf_size = cmd->data_out_size;79 } else if (cmd->data_out == NULL && cmd->data_in != NULL) {80 ddir = USB_DIRECTION_IN;81 dbuf = cmd->data_in;82 dbuf_size = cmd->data_in_size;83 } else {84 assert(false);85 }86 77 87 78 /* Prepare CBW - command block wrapper */ 88 79 usb_massstor_cbw_t cbw; 89 80 usb_massstor_cbw_prepare(&cbw, tag, dbuf_size, ddir, mfun->lun, 90 cmd ->cdb_size, cmd->cdb);81 cmd_size, cmd); 91 82 92 83 /* Send the CBW. */ 93 MASTLOG("Sending CBW.\n");94 84 rc = usb_pipe_write(bulk_out_pipe, &cbw, sizeof(cbw)); 95 85 MASTLOG("CBW '%s' sent: %s.\n", 96 86 usb_debug_str_buffer((uint8_t *) &cbw, sizeof(cbw), 0), 97 87 str_error(rc)); 98 if (rc != EOK) 99 return EIO;100 101 MASTLOG("Transferring data.\n"); 88 if (rc != EOK) { 89 return rc; 90 } 91 102 92 if (ddir == USB_DIRECTION_IN) { 103 93 /* Recieve data from the device. */ … … 114 104 } 115 105 116 if (rc == ESTALL) { 117 /* Clear stall condition and continue below to read CSW. */ 118 if (ddir == USB_DIRECTION_IN) { 119 usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe, 120 mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe); 121 } else { 122 usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe, 123 mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe); 124 } 125 } else if (rc != EOK) { 126 return EIO; 106 if (rc != EOK) { 107 /* 108 * XXX If the pipe is stalled, we should clear it 109 * and read CSW. 110 */ 111 return rc; 127 112 } 128 113 … … 130 115 usb_massstor_csw_t csw; 131 116 size_t csw_size; 132 MASTLOG("Reading CSW.\n");133 117 rc = usb_pipe_read(bulk_in_pipe, &csw, sizeof(csw), &csw_size); 134 118 MASTLOG("CSW '%s' received (%zu bytes): %s.\n", … … 137 121 if (rc != EOK) { 138 122 MASTLOG("rc != EOK\n"); 139 return EIO;123 return rc; 140 124 } 141 125 142 126 if (csw_size != sizeof(csw)) { 143 127 MASTLOG("csw_size != sizeof(csw)\n"); 144 return E IO;128 return ERANGE; 145 129 } 146 130 147 131 if (csw.dCSWTag != tag) { 148 132 MASTLOG("csw.dCSWTag != tag\n"); 149 return E IO;133 return EBADCHECKSUM; 150 134 } 151 135 … … 153 137 * Determine the actual return value from the CSW. 154 138 */ 155 switch (csw.dCSWStatus) { 156 case cbs_passed: 157 cmd->status = CMDS_GOOD; 158 break; 159 case cbs_failed: 160 MASTLOG("Command failed\n"); 161 cmd->status = CMDS_FAILED; 162 break; 163 case cbs_phase_error: 164 MASTLOG("Phase error\n"); 165 retval = EIO; 166 break; 167 default: 168 retval = EIO; 169 break; 139 if (csw.dCSWStatus != 0) { 140 MASTLOG("csw.dCSWStatus != 0\n"); 141 // FIXME: better error code 142 // FIXME: distinguish 0x01 and 0x02 143 return EXDEV; 170 144 } 171 145 … … 173 147 if (residue > dbuf_size) { 174 148 MASTLOG("residue > dbuf_size\n"); 175 return E IO;149 return ERANGE; 176 150 } 177 151 … … 184 158 */ 185 159 186 if (ddir == USB_DIRECTION_IN) 187 cmd->rcvd_size = dbuf_size - residue; 188 189 return retval; 160 if (xferred_size != NULL) 161 *xferred_size = dbuf_size - residue; 162 163 return EOK; 164 } 165 166 /** Perform data-in command. 167 * 168 * @param mfun Mass storage function 169 * @param tag Command block wrapper tag (automatically compared with 170 * answer) 171 * @param cmd CDB (Command Descriptor) 172 * @param cmd_size CDB length in bytes 173 * @param dbuf Data receive buffer 174 * @param dbuf_size Data receive buffer size in bytes 175 * @param proc_size Number of bytes actually processed by device 176 * 177 * @return Error code 178 */ 179 int usb_massstor_data_in(usbmast_fun_t *mfun, uint32_t tag, const void *cmd, 180 size_t cmd_size, void *dbuf, size_t dbuf_size, size_t *proc_size) 181 { 182 return usb_massstor_cmd(mfun, tag, cmd, cmd_size, USB_DIRECTION_IN, 183 dbuf, dbuf_size, proc_size); 184 } 185 186 /** Perform data-out command. 187 * 188 * @param mfun Mass storage function 189 * @param tag Command block wrapper tag (automatically compared with 190 * answer) 191 * @param cmd CDB (Command Descriptor) 192 * @param cmd_size CDB length in bytes 193 * @param data Command data 194 * @param data_size Size of @a data in bytes 195 * @param proc_size Number of bytes actually processed by device 196 * 197 * @return Error code 198 */ 199 int usb_massstor_data_out(usbmast_fun_t *mfun, uint32_t tag, const void *cmd, 200 size_t cmd_size, const void *data, size_t data_size, size_t *proc_size) 201 { 202 return usb_massstor_cmd(mfun, tag, cmd, cmd_size, USB_DIRECTION_OUT, 203 (void *) data, data_size, proc_size); 190 204 } 191 205 -
uspace/drv/bus/usb/usbmast/bo_trans.h
r358dc13 refcebe1 47 47 #define BULK_OUT_EP 1 48 48 49 typedef enum cmd_status { 50 CMDS_GOOD, 51 CMDS_FAILED 52 } cmd_status_t; 53 54 /** SCSI command. 55 * 56 * Contains (a subset of) the input and output arguments of SCSI 57 * Execute Command procedure call (see SAM-4 chapter 5.1) 58 */ 59 typedef struct { 60 /* 61 * Related to IN fields 62 */ 63 64 /** Command Descriptor Block */ 65 void *cdb; 66 /** CDB size in bytes */ 67 size_t cdb_size; 68 69 /** Outgoing data */ 70 const void *data_out; 71 /** Size of outgoing data in bytes */ 72 size_t data_out_size; 73 74 /* 75 * Related to OUT fields 76 */ 77 78 /** Buffer for incoming data */ 79 void *data_in; 80 /** Size of input buffer in bytes */ 81 size_t data_in_size; 82 83 /** Number of bytes actually received */ 84 size_t rcvd_size; 85 86 /** Status */ 87 cmd_status_t status; 88 } scsi_cmd_t; 89 90 extern int usb_massstor_cmd(usbmast_fun_t *, uint32_t, scsi_cmd_t *); 49 extern int usb_massstor_data_in(usbmast_fun_t *, uint32_t, const void *, 50 size_t, void *, size_t, size_t *); 51 extern int usb_massstor_data_out(usbmast_fun_t *, uint32_t, const void *, 52 size_t, const void *, size_t, size_t *); 91 53 extern int usb_massstor_reset(usbmast_dev_t *); 92 54 extern void usb_massstor_reset_recovery(usbmast_dev_t *); -
uspace/drv/bus/usb/usbmast/cmdw.h
r358dc13 refcebe1 57 57 } __attribute__((packed)) usb_massstor_csw_t; 58 58 59 enum cmd_block_status {60 cbs_passed = 0x00,61 cbs_failed = 0x01,62 cbs_phase_error = 0x0263 };64 65 59 extern void usb_massstor_cbw_prepare(usb_massstor_cbw_t *, uint32_t, uint32_t, 66 60 usb_direction_t, uint8_t, uint8_t, const uint8_t *); -
uspace/drv/bus/usb/usbmast/scsi_ms.c
r358dc13 refcebe1 61 61 } 62 62 63 static void usbmast_dump_sense(usbmast_fun_t *mfun)64 {65 scsi_sense_data_t sense_buf;66 unsigned sense_key;67 int rc;68 69 rc = usbmast_request_sense(mfun, &sense_buf, sizeof(sense_buf));70 if (rc == EOK) {71 sense_key = sense_buf.flags_key & 0x0f;72 printf("Got sense data. Sense key: 0x%x (%s), ASC 0x%02x, "73 "ASCQ 0x%02x.\n", sense_key,74 scsi_get_sense_key_str(sense_key),75 sense_buf.additional_code,76 sense_buf.additional_cqual);77 } else {78 printf("Failed to read sense data.\n");79 }80 }81 82 63 /** Perform SCSI Inquiry command on USB mass storage device. 83 64 * … … 89 70 { 90 71 scsi_std_inquiry_data_t inq_data; 91 s csi_cmd_t cmd;72 size_t response_len; 92 73 scsi_cdb_inquiry_t cdb; 93 74 int rc; … … 97 78 cdb.alloc_len = host2uint16_t_be(sizeof(inq_data)); 98 79 99 memset(&cmd, 0, sizeof(cmd)); 100 cmd.cdb = &cdb; 101 cmd.cdb_size = sizeof(cdb); 102 cmd.data_in = &inq_data; 103 cmd.data_in_size = sizeof(inq_data); 104 105 rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd); 80 rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 81 sizeof(cdb), &inq_data, sizeof(inq_data), &response_len); 106 82 107 83 if (rc != EOK) { 108 usb_log_error("Inquiry transport failed, device %s: %s.\n", 109 mfun->mdev->ddf_dev->name, str_error(rc)); 110 return rc; 111 } 112 113 if (cmd.status != CMDS_GOOD) { 114 usb_log_error("Inquiry command failed, device %s.\n", 115 mfun->mdev->ddf_dev->name); 116 usbmast_dump_sense(mfun); 117 return EIO; 118 } 119 120 if (cmd.rcvd_size < SCSI_STD_INQUIRY_DATA_MIN_SIZE) { 84 usb_log_error("Inquiry failed, device %s: %s.\n", 85 mfun->mdev->ddf_dev->name, str_error(rc)); 86 return rc; 87 } 88 89 if (response_len < SCSI_STD_INQUIRY_DATA_MIN_SIZE) { 121 90 usb_log_error("SCSI Inquiry response too short (%zu).\n", 122 cmd.rcvd_size);91 response_len); 123 92 return EIO; 124 93 } … … 158 127 int usbmast_request_sense(usbmast_fun_t *mfun, void *buf, size_t size) 159 128 { 160 scsi_cmd_t cmd;161 129 scsi_cdb_request_sense_t cdb; 130 size_t data_len; 162 131 int rc; 163 132 … … 166 135 cdb.alloc_len = min(size, SCSI_SENSE_DATA_MAX_SIZE); 167 136 168 memset(&cmd, 0, sizeof(cmd)); 169 cmd.cdb = &cdb; 170 cmd.cdb_size = sizeof(cdb); 171 cmd.data_in = buf; 172 cmd.data_in_size = size; 173 174 rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd); 175 176 if (rc != EOK || cmd.status != CMDS_GOOD) { 137 rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 138 sizeof(cdb), buf, size, &data_len); 139 140 if (rc != EOK) { 177 141 usb_log_error("Request Sense failed, device %s: %s.\n", 178 142 mfun->mdev->ddf_dev->name, str_error(rc)); … … 180 144 } 181 145 182 if ( cmd.rcvd_size< SCSI_SENSE_DATA_MIN_SIZE) {146 if (data_len < SCSI_SENSE_DATA_MIN_SIZE) { 183 147 /* The missing bytes should be considered to be zeroes. */ 184 memset((uint8_t *)buf + cmd.rcvd_size, 0,185 SCSI_SENSE_DATA_MIN_SIZE - cmd.rcvd_size);148 memset((uint8_t *)buf + data_len, 0, 149 SCSI_SENSE_DATA_MIN_SIZE - data_len); 186 150 } 187 151 … … 200 164 uint32_t *block_size) 201 165 { 202 scsi_cmd_t cmd;203 166 scsi_cdb_read_capacity_10_t cdb; 204 167 scsi_read_capacity_10_data_t data; 168 size_t data_len; 205 169 int rc; 206 170 … … 208 172 cdb.op_code = SCSI_CMD_READ_CAPACITY_10; 209 173 210 memset(&cmd, 0, sizeof(cmd)); 211 cmd.cdb = &cdb; 212 cmd.cdb_size = sizeof(cdb); 213 cmd.data_in = &data; 214 cmd.data_in_size = sizeof(data); 215 216 rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd); 217 218 if (rc != EOK) { 219 usb_log_error("Read Capacity (10) transport failed, device %s: %s.\n", 220 mfun->mdev->ddf_dev->name, str_error(rc)); 221 return rc; 222 } 223 224 if (cmd.status != CMDS_GOOD) { 225 usb_log_error("Read Capacity (10) command failed, device %s.\n", 226 mfun->mdev->ddf_dev->name); 227 usbmast_dump_sense(mfun); 228 return EIO; 229 } 230 231 if (cmd.rcvd_size < sizeof(data)) { 174 rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 175 sizeof(cdb), &data, sizeof(data), &data_len); 176 177 if (rc != EOK) { 178 usb_log_error("Read Capacity (10) failed, device %s: %s.\n", 179 mfun->mdev->ddf_dev->name, str_error(rc)); 180 return rc; 181 } 182 183 if (data_len < sizeof(data)) { 232 184 usb_log_error("SCSI Read Capacity response too short (%zu).\n", 233 cmd.rcvd_size);185 data_len); 234 186 return EIO; 235 187 } … … 251 203 int usbmast_read(usbmast_fun_t *mfun, uint64_t ba, size_t nblocks, void *buf) 252 204 { 253 scsi_cmd_t cmd;254 205 scsi_cdb_read_12_t cdb; 255 int rc; 206 size_t data_len; 207 int rc; 208 209 /* XXX Need softstate to store block size. */ 256 210 257 211 if (ba > UINT32_MAX) … … 266 220 cdb.xfer_len = host2uint32_t_be(nblocks); 267 221 268 memset(&cmd, 0, sizeof(cmd)); 269 cmd.cdb = &cdb; 270 cmd.cdb_size = sizeof(cdb); 271 cmd.data_in = buf; 272 cmd.data_in_size = nblocks * mfun->block_size; 273 274 rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd); 275 276 if (rc != EOK) { 277 usb_log_error("Read (12) transport failed, device %s: %s.\n", 278 mfun->mdev->ddf_dev->name, str_error(rc)); 279 return rc; 280 } 281 282 if (cmd.status != CMDS_GOOD) { 283 usb_log_error("Read (12) command failed, device %s.\n", 284 mfun->mdev->ddf_dev->name); 285 usbmast_dump_sense(mfun); 286 return EIO; 287 } 288 289 if (cmd.rcvd_size < nblocks * mfun->block_size) { 222 rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 223 sizeof(cdb), buf, nblocks * mfun->block_size, &data_len); 224 225 if (rc != EOK) { 226 usb_log_error("Read (12) failed, device %s: %s.\n", 227 mfun->mdev->ddf_dev->name, str_error(rc)); 228 return rc; 229 } 230 231 if (data_len < nblocks * mfun->block_size) { 290 232 usb_log_error("SCSI Read response too short (%zu).\n", 291 cmd.rcvd_size);233 data_len); 292 234 return EIO; 293 235 } … … 308 250 const void *data) 309 251 { 310 scsi_cmd_t cmd;311 252 scsi_cdb_write_12_t cdb; 253 size_t sent_len; 312 254 int rc; 313 255 … … 323 265 cdb.xfer_len = host2uint32_t_be(nblocks); 324 266 325 memset(&cmd, 0, sizeof(cmd)); 326 cmd.cdb = &cdb; 327 cmd.cdb_size = sizeof(cdb); 328 cmd.data_out = data; 329 cmd.data_out_size = nblocks * mfun->block_size; 330 331 rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd); 332 333 if (rc != EOK) { 334 usb_log_error("Write (12) transport failed, device %s: %s.\n", 335 mfun->mdev->ddf_dev->name, str_error(rc)); 336 return rc; 337 } 338 339 if (cmd.status != CMDS_GOOD) { 340 usb_log_error("Write (12) command failed, device %s.\n", 341 mfun->mdev->ddf_dev->name); 342 usbmast_dump_sense(mfun); 267 rc = usb_massstor_data_out(mfun, 0xDEADBEEF, (uint8_t *) &cdb, 268 sizeof(cdb), data, nblocks * mfun->block_size, &sent_len); 269 270 if (rc != EOK) { 271 usb_log_error("Write (12) failed, device %s: %s.\n", 272 mfun->mdev->ddf_dev->name, str_error(rc)); 273 return rc; 274 } 275 276 if (sent_len < nblocks * mfun->block_size) { 277 usb_log_error("SCSI Write not all bytes transferred (%zu).\n", 278 sent_len); 343 279 return EIO; 344 280 } -
uspace/lib/c/Makefile
r358dc13 refcebe1 59 59 -include arch/$(UARCH)/Makefile.inc 60 60 61 EXTRA_CFLAGS += -I../../srv/loader/include 62 61 63 GENERIC_SOURCES = \ 62 64 generic/libc.c \ … … 69 71 generic/device/hw_res.c \ 70 72 generic/device/char_dev.c \ 71 generic/elf/elf_load.c \72 73 generic/event.c \ 73 74 generic/errno.c \ … … 133 134 generic/dlfcn.c \ 134 135 generic/rtld/rtld.c \ 136 generic/rtld/elf_load.c \ 135 137 generic/rtld/dynamic.c \ 136 138 generic/rtld/module.c \ -
uspace/lib/c/generic/io/io.c
r358dc13 refcebe1 594 594 } 595 595 596 data+= now;596 buf += now; 597 597 stream->buf_head += now; 598 598 buf_free -= now; 599 599 bytes_left -= now; 600 600 total_written += now; 601 stream->buf_state = _bs_write;602 601 603 602 if (buf_free == 0) { … … 607 606 } 608 607 } 608 609 if (total_written > 0) 610 stream->buf_state = _bs_write; 609 611 610 612 if (need_flush) -
uspace/lib/c/generic/rtld/module.c
r358dc13 refcebe1 35 35 */ 36 36 37 #include <adt/list.h>38 #include <elf/elf_load.h>39 #include <fcntl.h>40 #include <loader/pcb.h>41 37 #include <stdio.h> 42 38 #include <stdlib.h> 43 39 #include <unistd.h> 40 #include <fcntl.h> 41 #include <adt/list.h> 42 #include <loader/pcb.h> 44 43 45 44 #include <rtld/rtld.h> … … 48 47 #include <rtld/rtld_arch.h> 49 48 #include <rtld/module.h> 49 #include <elf_load.h> 50 50 51 51 /** (Eagerly) process all relocation tables in a module. … … 93 93 module_t *module_find(const char *name) 94 94 { 95 link_t *head = &runtime_env->modules_head; 96 97 link_t *cur; 95 98 module_t *m; 96 99 const char *p, *soname; … … 107 110 108 111 /* 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) { 110 114 DPRINTF("cur = %p\n", cur); 111 115 m = list_get_instance(cur, module_t, modules_link); … … 173 177 174 178 /* 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); 176 180 177 181 return m; … … 245 249 void modules_process_relocs(module_t *start) 246 250 { 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) { 250 257 m = list_get_instance(cur, module_t, modules_link); 251 258 … … 261 268 void modules_untag(void) 262 269 { 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) { 266 276 m = list_get_instance(cur, module_t, modules_link); 267 277 m->bfs_tag = false; -
uspace/lib/c/generic/rtld/rtld.c
r358dc13 refcebe1 44 44 { 45 45 runtime_env = &rt_env_static; 46 list_initialize(&runtime_env->modules );46 list_initialize(&runtime_env->modules_head); 47 47 runtime_env->next_bias = 0x2000000; 48 48 runtime_env->program = NULL; -
uspace/lib/c/generic/rtld/symbol.c
r358dc13 refcebe1 38 38 #include <stdlib.h> 39 39 40 #include <elf/elf.h>41 40 #include <rtld/rtld.h> 42 41 #include <rtld/rtld_debug.h> 43 42 #include <rtld/symbol.h> 43 #include <elf.h> 44 44 45 45 /* … … 118 118 module_t *m, *dm; 119 119 elf_symbol_t *sym, *s; 120 li st_t queue;120 link_t queue_head; 121 121 size_t i; 122 122 … … 132 132 133 133 /* Insert root (the program) into the queue and tag it */ 134 list_initialize(&queue );134 list_initialize(&queue_head); 135 135 start->bfs_tag = true; 136 list_append(&start->queue_link, &queue );136 list_append(&start->queue_link, &queue_head); 137 137 138 138 /* If the symbol is found, it will be stored in 'sym' */ … … 140 140 141 141 /* While queue is not empty */ 142 while (!list_empty(&queue )) {142 while (!list_empty(&queue_head)) { 143 143 /* 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); 145 145 list_remove(&m->queue_link); 146 146 … … 162 162 if (dm->bfs_tag == false) { 163 163 dm->bfs_tag = true; 164 list_append(&dm->queue_link, &queue );164 list_append(&dm->queue_link, &queue_head); 165 165 } 166 166 } … … 168 168 169 169 /* 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); 172 172 173 173 if (!sym) { -
uspace/lib/c/generic/vfs/vfs.c
r358dc13 refcebe1 417 417 } 418 418 419 /** Read entire buffer.420 *421 * In face of short reads this function continues reading until either422 * the entire buffer is read or no more data is available (at end of file).423 *424 * @param fildes File descriptor425 * @param buf Buffer, @a nbytes bytes long426 * @param nbytes Number of bytes to read427 *428 * @return On success, positive number of bytes read.429 * On failure, negative error code from read().430 */431 ssize_t read_all(int fildes, void *buf, size_t nbyte)432 {433 ssize_t cnt = 0;434 size_t nread = 0;435 uint8_t *bp = (uint8_t *) buf;436 437 do {438 bp += cnt;439 nread += cnt;440 cnt = read(fildes, bp, nbyte - nread);441 } while (cnt > 0 && (nbyte - nread - cnt) > 0);442 443 if (cnt < 0)444 return cnt;445 446 return nread + cnt;447 }448 449 /** Write entire buffer.450 *451 * This function fails if it cannot write exactly @a len bytes to the file.452 *453 * @param fildes File descriptor454 * @param buf Data, @a nbytes bytes long455 * @param nbytes Number of bytes to write456 *457 * @return EOK on error, return value from write() if writing458 * failed.459 */460 ssize_t write_all(int fildes, const void *buf, size_t nbyte)461 {462 ssize_t cnt = 0;463 ssize_t nwritten = 0;464 const uint8_t *bp = (uint8_t *) buf;465 466 do {467 bp += cnt;468 nwritten += cnt;469 cnt = write(fildes, bp, nbyte - nwritten);470 } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0);471 472 if (cnt < 0)473 return cnt;474 475 if ((ssize_t)nbyte - nwritten - cnt > 0)476 return EIO;477 478 return nbyte;479 }480 481 419 int fsync(int fildes) 482 420 { -
uspace/lib/c/include/rtld/elf_dyn.h
r358dc13 refcebe1 39 39 #include <sys/types.h> 40 40 41 #include <elf /elf.h>41 #include <elf.h> 42 42 #include <libarch/rtld/elf_dyn.h> 43 43 -
uspace/lib/c/include/rtld/rtld.h
r358dc13 refcebe1 49 49 50 50 /** List of all loaded modules including rtld and the program */ 51 li st_t modules;51 link_t modules_head; 52 52 53 53 /** Temporary hack to place each module at different address. */ -
uspace/lib/c/include/rtld/symbol.h
r358dc13 refcebe1 36 36 #define LIBC_RTLD_SYMBOL_H_ 37 37 38 #include <elf/elf.h>39 38 #include <rtld/rtld.h> 39 #include <elf.h> 40 40 41 41 elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod); -
uspace/lib/c/include/unistd.h
r358dc13 refcebe1 63 63 extern ssize_t read(int, void *, size_t); 64 64 65 extern ssize_t read_all(int, void *, size_t);66 extern ssize_t write_all(int, const void *, size_t);67 68 65 extern off64_t lseek(int, off64_t, int); 69 66 extern int ftruncate(int, aoff64_t); -
uspace/lib/scsi/include/scsi/spc.h
r358dc13 refcebe1 179 179 uint8_t additional_len; 180 180 /** Command-specific Information */ 181 uint 32_t cmd_spec;181 uint8_t cmd_spec; 182 182 /** Additional Sense Code */ 183 183 uint8_t additional_code; … … 205 205 SCSI_SK_ABORTED_COMMAND = 0xb, 206 206 SCSI_SK_VOLUME_OVERFLOW = 0xd, 207 SCSI_SK_MISCOMPARE = 0xe, 208 209 SCSI_SK_LIMIT = 0x10 207 SCSI_SK_MISCOMPARE = 0xe 210 208 }; 211 209 212 210 extern const char *scsi_dev_type_str[SCSI_DEV_LIMIT]; 213 extern const char *scsi_sense_key_str[SCSI_SK_LIMIT];214 215 211 extern const char *scsi_get_dev_type_str(unsigned); 216 extern const char *scsi_get_sense_key_str(unsigned);217 212 218 213 #endif -
uspace/lib/scsi/src/spc.c
r358dc13 refcebe1 44 44 }; 45 45 46 const char *scsi_sense_key_str[SCSI_SK_LIMIT] = {47 [SCSI_SK_NO_SENSE] = "No Sense",48 [SCSI_SK_RECOVERED_ERROR] = "Recovered Error",49 [SCSI_SK_NOT_READY] = "Not Ready",50 [SCSI_SK_MEDIUM_ERROR] = "Medium Error",51 [SCSI_SK_HARDWARE_ERROR] = "Hardware Error",52 [SCSI_SK_ILLEGAL_REQUEST] = "Illegal Request",53 [SCSI_SK_UNIT_ATTENTION] = "Unit Attention",54 [SCSI_SK_DATA_PROTECT] = "Data Protect",55 [SCSI_SK_BLANK_CHECK] = "Blank Check",56 [SCSI_SK_VENDOR_SPECIFIC] = "Vendor-specific",57 [SCSI_SK_COPY_ABORTED] = "Copy Aborted",58 [SCSI_SK_ABORTED_COMMAND] = "Aborted Command",59 [SCSI_SK_VOLUME_OVERFLOW] = "Volume Overflow",60 [SCSI_SK_MISCOMPARE] = "Miscompare"61 };62 63 46 /** Get peripheral device type string. 64 47 * … … 70 53 { 71 54 if (dev_type >= SCSI_DEV_LIMIT || scsi_dev_type_str[dev_type] == NULL) 72 return " Unknown";55 return "<unknown>"; 73 56 74 57 return scsi_dev_type_str[dev_type]; 75 58 } 76 77 /** Get sense key string.78 *79 * Return string description of SCSI sense key.80 * The returned string is valid indefinitely, the caller should81 * not attempt to free it.82 */83 const char *scsi_get_sense_key_str(unsigned sense_key)84 {85 if (sense_key >= SCSI_SK_LIMIT || scsi_sense_key_str[sense_key] == NULL)86 return "Unknown";87 88 return scsi_sense_key_str[sense_key];89 }90 -
uspace/srv/devman/devman.c
r358dc13 refcebe1 270 270 } 271 271 272 ssize_t read_bytes = read_all(fd, buf, len);272 ssize_t read_bytes = safe_read(fd, buf, len); 273 273 if (read_bytes <= 0) { 274 log_msg(LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path, 275 read_bytes); 274 log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path); 276 275 goto cleanup; 277 276 } … … 422 421 } 423 422 424 insert_fun_node(tree, fun, str_dup(""), NULL);423 insert_fun_node(tree, fun, clone_string(""), NULL); 425 424 match_id_t *id = create_match_id(); 426 id->id = str_dup("root");425 id->id = clone_string("root"); 427 426 id->score = 100; 428 427 add_match_id(&fun->match_ids, id); -
uspace/srv/devman/util.c
r358dc13 refcebe1 91 91 } 92 92 93 char *clone_string(const char *s) 94 { 95 size_t size = str_size(s) + 1; 96 char *str; 97 98 str = (char *) malloc(size); 99 if (str != NULL) 100 str_cpy(str, size, s); 101 return str; 102 } 103 93 104 void replace_char(char *str, char orig, char repl) 94 105 { … … 100 111 } 101 112 113 ssize_t safe_read(int fd, void *buffer, size_t size) 114 { 115 if (size == 0) { 116 return 0; 117 } 118 119 uint8_t *buf_ptr = (uint8_t *) buffer; 120 121 size_t total_read = 0; 122 while (total_read < size) { 123 ssize_t bytes_read = read(fd, buf_ptr, size - total_read); 124 if (bytes_read < 0) { 125 /* Error. */ 126 return bytes_read; 127 } else if (bytes_read == 0) { 128 /* Possibly end of file. */ 129 break; 130 } else { 131 /* Read at least something. */ 132 buf_ptr += bytes_read; 133 total_read += bytes_read; 134 } 135 } 136 137 return (ssize_t) total_read; 138 } 139 102 140 /** @} 103 141 */ -
uspace/srv/devman/util.h
r358dc13 refcebe1 44 44 extern size_t get_nonspace_len(const char *); 45 45 extern void free_not_null(const void *); 46 extern char *clone_string(const char *); 46 47 extern void replace_char(char *, char, char); 48 49 extern ssize_t safe_read(int, void *, size_t); 47 50 48 51 #endif -
uspace/srv/loader/Makefile
r358dc13 refcebe1 39 39 LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld 40 40 41 EXTRA_CFLAGS = -Iinclude 42 41 43 BINARY = loader 42 44 STATIC_ONLY = y … … 44 46 GENERIC_SOURCES = \ 45 47 main.c \ 48 elf_load.c \ 46 49 interp.s 47 50 -
uspace/srv/loader/main.c
r358dc13 refcebe1 59 59 #include <str.h> 60 60 #include <as.h> 61 #include <elf /elf.h>62 #include <elf /elf_load.h>61 #include <elf.h> 62 #include <elf_load.h> 63 63 64 64 #ifdef CONFIG_RTLD … … 348 348 349 349 /* 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); 352 352 353 353 /* Pointer to program module. Used as root of the module graph. */
Note:
See TracChangeset
for help on using the changeset viewer.