Changeset 86ffa27f in mainline for uspace/lib/c/generic
- Timestamp:
- 2011-08-07T11:21:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cc574511
- Parents:
- 15f3c3f (diff), e8067c0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/c/generic
- Files:
-
- 1 deleted
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/elf/elf_load.c
r15f3c3f r86ffa27f 29 29 */ 30 30 31 /** @addtogroup generic 31 /** @addtogroup generic 32 32 * @{ 33 33 */ … … 49 49 #include <assert.h> 50 50 #include <as.h> 51 #include <elf/elf.h> 51 52 #include <unistd.h> 52 53 #include <fcntl.h> … … 55 56 #include <entry_point.h> 56 57 57 #include "elf.h" 58 #include "elf_load.h" 58 #include <elf/elf_load.h> 59 59 60 60 #define DPRINTF(...) … … 74 74 static int load_segment(elf_ld_t *elf, elf_segment_header_t *entry); 75 75 76 /** Read until the buffer is read in its entirety. */77 static int my_read(int fd, void *buf, size_t len)78 {79 int cnt = 0;80 do {81 buf += cnt;82 len -= cnt;83 cnt = read(fd, buf, len);84 } while ((cnt > 0) && ((len - cnt) > 0));85 86 return cnt;87 }88 89 76 /** Load ELF binary from a file. 90 77 * … … 160 147 int i, rc; 161 148 162 rc = my_read(elf->fd, header, sizeof(elf_header_t));163 if (rc < 0) {149 rc = read_all(elf->fd, header, sizeof(elf_header_t)); 150 if (rc != sizeof(elf_header_t)) { 164 151 DPRINTF("Read error.\n"); 165 152 return EE_INVALID; … … 222 209 + i * sizeof(elf_segment_header_t), SEEK_SET); 223 210 224 rc = my_read(elf->fd, &segment_hdr,211 rc = read_all(elf->fd, &segment_hdr, 225 212 sizeof(elf_segment_header_t)); 226 if (rc < 0) {213 if (rc != sizeof(elf_segment_header_t)) { 227 214 DPRINTF("Read error.\n"); 228 215 return EE_INVALID; … … 244 231 + i * sizeof(elf_section_header_t), SEEK_SET); 245 232 246 rc = my_read(elf->fd, §ion_hdr,233 rc = read_all(elf->fd, §ion_hdr, 247 234 sizeof(elf_section_header_t)); 248 if (rc < 0) {235 if (rc != sizeof(elf_section_header_t)) { 249 236 DPRINTF("Read error.\n"); 250 237 return EE_INVALID; … … 334 321 uintptr_t seg_addr; 335 322 size_t mem_sz; 336 int rc;323 ssize_t rc; 337 324 338 325 bias = elf->bias; … … 412 399 if (now > left) now = left; 413 400 414 rc = my_read(elf->fd, dp, now);415 416 if (rc < 0) {401 rc = read_all(elf->fd, dp, now); 402 403 if (rc != (ssize_t) now) { 417 404 DPRINTF("Read error.\n"); 418 405 return EE_INVALID; -
uspace/lib/c/generic/io/console.c
r15f3c3f r86ffa27f 76 76 bool console_kcon(void) 77 77 { 78 #if 079 78 return __SYSCALL0(SYS_DEBUG_ACTIVATE_CONSOLE); 80 #endif81 82 return false;83 79 } 84 80 -
uspace/lib/c/generic/io/io.c
r15f3c3f r86ffa27f 594 594 } 595 595 596 buf+= now;596 data += 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; 601 602 602 603 if (buf_free == 0) { … … 606 607 } 607 608 } 608 609 if (total_written > 0)610 stream->buf_state = _bs_write;611 609 612 610 if (need_flush) … … 714 712 off64_t ftell(FILE *stream) 715 713 { 714 _fflushbuf(stream); 716 715 return lseek(stream->fd, 0, SEEK_CUR); 717 716 } -
uspace/lib/c/generic/rtld/module.c
r15f3c3f r86ffa27f 35 35 */ 36 36 37 #include <adt/list.h> 38 #include <elf/elf_load.h> 39 #include <fcntl.h> 40 #include <loader/pcb.h> 37 41 #include <stdio.h> 38 42 #include <stdlib.h> 39 43 #include <unistd.h> 40 #include <fcntl.h>41 #include <adt/list.h>42 #include <loader/pcb.h>43 44 44 45 #include <rtld/rtld.h> … … 47 48 #include <rtld/rtld_arch.h> 48 49 #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;98 95 module_t *m; 99 96 const char *p, *soname; … … 110 107 111 108 /* Traverse list of all modules. Not extremely fast, but simple */ 112 DPRINTF("head = %p\n", head); 113 for (cur = head->next; cur != head; cur = cur->next) { 109 list_foreach(runtime_env->modules, cur) { 114 110 DPRINTF("cur = %p\n", cur); 115 111 m = list_get_instance(cur, module_t, modules_link); … … 177 173 178 174 /* Insert into the list of loaded modules */ 179 list_append(&m->modules_link, &runtime_env->modules _head);175 list_append(&m->modules_link, &runtime_env->modules); 180 176 181 177 return m; … … 249 245 void modules_process_relocs(module_t *start) 250 246 { 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) { 247 module_t *m; 248 249 list_foreach(runtime_env->modules, cur) { 257 250 m = list_get_instance(cur, module_t, modules_link); 258 251 … … 268 261 void modules_untag(void) 269 262 { 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) { 263 module_t *m; 264 265 list_foreach(runtime_env->modules, cur) { 276 266 m = list_get_instance(cur, module_t, modules_link); 277 267 m->bfs_tag = false; -
uspace/lib/c/generic/rtld/rtld.c
r15f3c3f r86ffa27f 44 44 { 45 45 runtime_env = &rt_env_static; 46 list_initialize(&runtime_env->modules _head);46 list_initialize(&runtime_env->modules); 47 47 runtime_env->next_bias = 0x2000000; 48 48 runtime_env->program = NULL; -
uspace/lib/c/generic/rtld/symbol.c
r15f3c3f r86ffa27f 38 38 #include <stdlib.h> 39 39 40 #include <elf/elf.h> 40 41 #include <rtld/rtld.h> 41 42 #include <rtld/rtld_debug.h> 42 43 #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 nk_t queue_head;120 list_t queue; 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 _head);134 list_initialize(&queue); 135 135 start->bfs_tag = true; 136 list_append(&start->queue_link, &queue _head);136 list_append(&start->queue_link, &queue); 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 _head)) {142 while (!list_empty(&queue)) { 143 143 /* Pop first element from the queue */ 144 m = list_get_instance( queue_head.next, module_t, queue_link);144 m = list_get_instance(list_first(&queue), 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 _head);164 list_append(&dm->queue_link, &queue); 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 _head))171 list_remove( queue_head.next);170 while (!list_empty(&queue)) 171 list_remove(list_first(&queue)); 172 172 173 173 if (!sym) { -
uspace/lib/c/generic/str.c
r15f3c3f r86ffa27f 544 544 545 545 str_cpy(dest + dstr_size, size - dstr_size, src); 546 } 547 548 /** Convert space-padded ASCII to string. 549 * 550 * Common legacy text encoding in hardware is 7-bit ASCII fitted into 551 * a fixed-with byte buffer (bit 7 always zero), right-padded with spaces 552 * (ASCII 0x20). Convert space-padded ascii to string representation. 553 * 554 * If the text does not fit into the destination buffer, the function converts 555 * as many characters as possible and returns EOVERFLOW. 556 * 557 * If the text contains non-ASCII bytes (with bit 7 set), the whole string is 558 * converted anyway and invalid characters are replaced with question marks 559 * (U_SPECIAL) and the function returns EIO. 560 * 561 * Regardless of return value upon return @a dest will always be well-formed. 562 * 563 * @param dest Destination buffer 564 * @param size Size of destination buffer 565 * @param src Space-padded ASCII. 566 * @param n Size of the source buffer in bytes. 567 * 568 * @return EOK on success, EOVERFLOW if the text does not fit 569 * destination buffer, EIO if the text contains 570 * non-ASCII bytes. 571 */ 572 int spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n) 573 { 574 size_t sidx; 575 size_t didx; 576 size_t dlast; 577 uint8_t byte; 578 int rc; 579 int result; 580 581 /* There must be space for a null terminator in the buffer. */ 582 assert(size > 0); 583 result = EOK; 584 585 didx = 0; 586 dlast = 0; 587 for (sidx = 0; sidx < n; ++sidx) { 588 byte = src[sidx]; 589 if (!ascii_check(byte)) { 590 byte = U_SPECIAL; 591 result = EIO; 592 } 593 594 rc = chr_encode(byte, dest, &didx, size - 1); 595 if (rc != EOK) { 596 assert(rc == EOVERFLOW); 597 dest[didx] = '\0'; 598 return rc; 599 } 600 601 /* Remember dest index after last non-empty character */ 602 if (byte != 0x20) 603 dlast = didx; 604 } 605 606 /* Terminate string after last non-empty character */ 607 dest[dlast] = '\0'; 608 return result; 546 609 } 547 610 -
uspace/lib/c/generic/vfs/vfs.c
r15f3c3f r86ffa27f 417 417 } 418 418 419 /** Read entire buffer. 420 * 421 * In face of short reads this function continues reading until either 422 * the entire buffer is read or no more data is available (at end of file). 423 * 424 * @param fildes File descriptor 425 * @param buf Buffer, @a nbytes bytes long 426 * @param nbytes Number of bytes to read 427 * 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 descriptor 454 * @param buf Data, @a nbytes bytes long 455 * @param nbytes Number of bytes to write 456 * 457 * @return EOK on error, return value from write() if writing 458 * 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 419 481 int fsync(int fildes) 420 482 {
Note:
See TracChangeset
for help on using the changeset viewer.