Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskdump/elf_core.c

    rce04ea44 r6afc9d7  
    5454#include <errno.h>
    5555#include <sys/types.h>
     56#include <sys/stat.h>
    5657#include <unistd.h>
     58#include <fcntl.h>
    5759#include <mem.h>
    5860#include <stdint.h>
     
    6163#include <macros.h>
    6264#include <libarch/istate.h>
    63 #include <vfs/vfs.h>
    6465
    6566#include "elf_core.h"
    6667
    6768static off64_t align_foff_up(off64_t, uintptr_t, size_t);
    68 static int write_mem_area(int, aoff64_t *, as_area_info_t *, async_sess_t *);
     69static int align_pos(int, size_t);
     70static int write_mem_area(int, as_area_info_t *, async_sess_t *);
    6971
    7072#define BUFFER_SIZE 0x1000
     
    9597        elf_note_t note;
    9698        size_t word_size;
    97         aoff64_t pos = 0;
    9899
    99100        int fd;
     
    123124        }
    124125
    125         fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MAY_CREATE,
    126             MODE_WRITE);
     126        fd = open(file_name, O_CREAT | O_WRONLY, 0644);
    127127        if (fd < 0) {
    128128                printf("Failed opening file.\n");
     
    207207        }
    208208
    209         rc = vfs_write(fd, &pos, &elf_hdr, sizeof(elf_hdr));
     209        rc = write(fd, &elf_hdr, sizeof(elf_hdr));
    210210        if (rc != sizeof(elf_hdr)) {
    211211                printf("Failed writing ELF header.\n");
     
    215215
    216216        for (i = 0; i < n_ph; ++i) {
    217                 rc = vfs_write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i]));
     217                rc = write(fd, &p_hdr[i], sizeof(p_hdr[i]));
    218218                if (rc != sizeof(p_hdr[i])) {
    219219                        printf("Failed writing program header.\n");
     
    223223        }
    224224
    225         pos = p_hdr[0].p_offset;
     225        if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) {
     226                printf("Failed writing memory data.\n");
     227                free(p_hdr);
     228                return EIO;
     229        }
    226230
    227231        /*
     
    232236        note.type = NT_PRSTATUS;
    233237
    234         rc = vfs_write(fd, &pos, &note, sizeof(elf_note_t));
     238        rc = write(fd, &note, sizeof(elf_note_t));
    235239        if (rc != sizeof(elf_note_t)) {
    236240                printf("Failed writing note header.\n");
     
    239243        }
    240244
    241         rc = vfs_write(fd, &pos, "CORE", note.namesz);
     245        rc = write(fd, "CORE", note.namesz);
    242246        if (rc != (ssize_t) note.namesz) {
    243247                printf("Failed writing note header.\n");
     
    246250        }
    247251
    248         pos = ALIGN_UP(pos, word_size);
    249 
    250         rc = vfs_write(fd, &pos, &pr_status, sizeof(elf_prstatus_t));
     252        rc = align_pos(fd, word_size);
     253        if (rc != EOK) {
     254                printf("Failed writing note header.\n");
     255                free(p_hdr);
     256                return EIO;
     257        }
     258
     259        rc = write(fd, &pr_status, sizeof(elf_prstatus_t));
    251260        if (rc != sizeof(elf_prstatus_t)) {
    252261                printf("Failed writing register data.\n");
     
    256265
    257266        for (i = 1; i < n_ph; ++i) {
    258                 pos = p_hdr[i].p_offset;
    259                 if (write_mem_area(fd, &pos, &ainfo[i - 1], sess) != EOK) {
     267                if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) {
     268                        printf("Failed writing memory data.\n");
     269                        free(p_hdr);
     270                        return EIO;
     271                }
     272                if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) {
    260273                        printf("Failed writing memory data.\n");
    261274                        free(p_hdr);
     
    284297 *
    285298 * @param fd   File to write to.
    286  * @param pos  Pointer to the position to write to.
    287299 * @param area Memory area info structure.
    288300 * @param sess Debugging session.
     
    291303 *
    292304 */
    293 static int write_mem_area(int fd, aoff64_t *pos, as_area_info_t *area,
    294     async_sess_t *sess)
     305static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess)
    295306{
    296307        size_t to_copy;
     
    310321                }
    311322
    312                 rc = vfs_write(fd, pos, buffer, to_copy);
     323                rc = write(fd, buffer, to_copy);
    313324                if (rc != (ssize_t) to_copy) {
    314325                        printf("Failed writing memory contents.\n");
     
    323334}
    324335
     336static int align_pos(int fd, size_t align)
     337{
     338        off64_t cur_pos;
     339        size_t rem, adv;
     340
     341        cur_pos = lseek(fd, 0, SEEK_CUR);
     342        if (cur_pos < 0)
     343                return -1;
     344
     345        rem = cur_pos % align;
     346        adv = align - rem;
     347
     348        cur_pos = lseek(fd, adv, SEEK_CUR);
     349        if (cur_pos < 0)
     350                return -1;
     351
     352        return EOK;
     353}
     354
    325355/** @}
    326356 */
Note: See TracChangeset for help on using the changeset viewer.