Changeset 368ee04 in mainline for uspace/app/taskdump/elf_core.c


Ignore:
Timestamp:
2017-04-05T18:10:39Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
93ad8166
Parents:
39f892a9 (diff), 2166728 (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.
Message:

Merge from lp:~jakub/helenos/vfs-2.5-cherrypick

This merge cherry-picks some of the changesets from Jiri Zarevucky's:

lp:~zarevucky-jiri/helenos/vfs-2.5

and then continues independently, yet sometime in a similar vein.

Roughly speaking, Jiri's branch is merged entirely up to its revision
1926 and then cherry-picked on and off until its revision 1965. Among
these changes are:

  • relativization of the API,
  • client-side roots,
  • server-side mounts,
  • inbox for passing arbitrary files from parent to child,
  • some streamlining and cleanup.

Additional changes include:

  • addressing issues introduced by the above changes,
  • client-side I/O cursors (file positions),
  • all HelenOS file system APIs begin with the vfs_ prefix and can be used after including vfs/vfs.h,
  • removal of some POSIX-ish headers and definitions,
  • additional cleanup.
File:
1 edited

Legend:

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

    r39f892a9 r368ee04  
    5454#include <errno.h>
    5555#include <sys/types.h>
    56 #include <sys/stat.h>
    5756#include <unistd.h>
    58 #include <fcntl.h>
    5957#include <mem.h>
    6058#include <stdint.h>
     
    6361#include <macros.h>
    6462#include <libarch/istate.h>
     63#include <vfs/vfs.h>
    6564
    6665#include "elf_core.h"
    6766
    6867static off64_t align_foff_up(off64_t, uintptr_t, size_t);
    69 static int align_pos(int, size_t);
    70 static int write_mem_area(int, as_area_info_t *, async_sess_t *);
     68static int write_mem_area(int, aoff64_t *, as_area_info_t *, async_sess_t *);
    7169
    7270#define BUFFER_SIZE 0x1000
     
    9795        elf_note_t note;
    9896        size_t word_size;
     97        aoff64_t pos = 0;
    9998
    10099        int fd;
     
    124123        }
    125124
    126         fd = open(file_name, O_CREAT | O_WRONLY, 0644);
     125        fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MAY_CREATE,
     126            MODE_WRITE);
    127127        if (fd < 0) {
    128128                printf("Failed opening file.\n");
     
    207207        }
    208208
    209         rc = write(fd, &elf_hdr, sizeof(elf_hdr));
     209        rc = vfs_write(fd, &pos, &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 = write(fd, &p_hdr[i], sizeof(p_hdr[i]));
     217                rc = vfs_write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i]));
    218218                if (rc != sizeof(p_hdr[i])) {
    219219                        printf("Failed writing program header.\n");
     
    223223        }
    224224
    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         }
     225        pos = p_hdr[0].p_offset;
    230226
    231227        /*
     
    236232        note.type = NT_PRSTATUS;
    237233
    238         rc = write(fd, &note, sizeof(elf_note_t));
     234        rc = vfs_write(fd, &pos, &note, sizeof(elf_note_t));
    239235        if (rc != sizeof(elf_note_t)) {
    240236                printf("Failed writing note header.\n");
     
    243239        }
    244240
    245         rc = write(fd, "CORE", note.namesz);
     241        rc = vfs_write(fd, &pos, "CORE", note.namesz);
    246242        if (rc != (ssize_t) note.namesz) {
    247243                printf("Failed writing note header.\n");
     
    250246        }
    251247
    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));
     248        pos = ALIGN_UP(pos, word_size);
     249
     250        rc = vfs_write(fd, &pos, &pr_status, sizeof(elf_prstatus_t));
    260251        if (rc != sizeof(elf_prstatus_t)) {
    261252                printf("Failed writing register data.\n");
     
    265256
    266257        for (i = 1; i < n_ph; ++i) {
    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) {
     258                pos = p_hdr[i].p_offset;
     259                if (write_mem_area(fd, &pos, &ainfo[i - 1], sess) != EOK) {
    273260                        printf("Failed writing memory data.\n");
    274261                        free(p_hdr);
     
    297284 *
    298285 * @param fd   File to write to.
     286 * @param pos  Pointer to the position to write to.
    299287 * @param area Memory area info structure.
    300288 * @param sess Debugging session.
     
    303291 *
    304292 */
    305 static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess)
     293static int write_mem_area(int fd, aoff64_t *pos, as_area_info_t *area,
     294    async_sess_t *sess)
    306295{
    307296        size_t to_copy;
     
    321310                }
    322311
    323                 rc = write(fd, buffer, to_copy);
     312                rc = vfs_write(fd, pos, buffer, to_copy);
    324313                if (rc != (ssize_t) to_copy) {
    325314                        printf("Failed writing memory contents.\n");
     
    334323}
    335324
    336 static 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 
    355325/** @}
    356326 */
Note: See TracChangeset for help on using the changeset viewer.