Share

parchive

The forum address has changed, you have been automatically redirected. Please update any bookmarks to use the new URL.

Subscribe

Fix for par-v1.1.tar.gz on SPARC

  1. mvaAccepting Donations

    2001-11-29 01:39:28 UTC
    The attached patch corrects an alignment problem on
    SPARC processors. The original version may access
    i64 values that are not aligned at 8 byte
    boundaries if the value of ptr is not a multiple of
    8 in read_pfile. On a SPARC (and probably HP-PA
    and Alpha as well), unaligned access triggers a
    segmentation violation.

    -- mva



    --- rwpar.c.orig Sat Nov 17 21:20:09 2001
    +++ rwpar.c Thu Nov 29 02:21:15 2001
    @@ -225,21 +225,20 @@
    read_pfile(pfile_t *file, u8 *ptr, u16 *path, i64 pl)
    {
    i64 i, l;
    - pfile_entr_t *pf;
    -
    - pf = ((pfile_entr_t *)ptr);
    -
    - i = read_i64(&pf->size);
    - file->status = read_i64(&pf->status);
    - file->file_size = read_i64(&pf->file_size);
    - COPY(file->hash, pf->hash, sizeof(md5));
    - COPY(file->hash_16k, pf->hash_16k, sizeof(md5));
    + pfile_entr_t pf;
    +
    + COPY(&pf, ptr, 1);
    + i = read_i64(&pf.size);
    + file->status = read_i64(&pf.status);
    + file->file_size = read_i64(&pf.file_size);
    + COPY(file->hash, pf.hash, sizeof(md5));
    + COPY(file->hash_16k, pf.hash_16k, sizeof(md5));
    l = (i - FILE_ENTRY_FIX_SIZE) / 2;
    NEW(file->filename, pl + l + 1);
    COPY(file->filename, path, pl);
    - read_u16s(file->filename + pl, &pf->filename, l);
    + read_u16s(file->filename + pl, &pf.filename, l);
    file->filename[l + pl] = 0;
    -
    + COPY(ptr, &pf, 1);
    return i;
    }

  2. mvaAccepting Donations

    2001-11-29 03:17:24 UTC
    Sorry,

    the patch has only 2 errors :-/ Forget it.

    On closer inspection, I don't know why it works
    slightly better on this SunOS 5.6 box. And I don't
    know at all why the original version breaks. Back
    to the debugger...

    -- mva
  3. mvaAccepting Donations

    2001-11-29 03:40:09 UTC
    Another attempt:

    --- rwpar.c.orig Sat Nov 17 21:20:09 2001
    +++ rwpar.c Thu Nov 29 04:32:20 2001
    @@ -232,8 +232,8 @@
    i = read_i64(&pf->size);
    file->status = read_i64(&pf->status);
    file->file_size = read_i64(&pf->file_size);
    - COPY(file->hash, pf->hash, sizeof(md5));
    - COPY(file->hash_16k, pf->hash_16k, sizeof(md5));
    + memmove(file->hash, pf->hash, sizeof(md5));
    + memmove(file->hash_16k, pf->hash_16k, sizeof(md5));
    l = (i - FILE_ENTRY_FIX_SIZE) / 2;
    NEW(file->filename, pl + l + 1);
    COPY(file->filename, path, pl);

    Would anybody venture a guess why using memcpy
    instead of memmove gets me a bus error if ptr%8!=0?
    This is SunOS 5.6 using gcc 2.95.2 on a SPARC.

    The memmove variant works fine. IMO, memcpy should
    work indepedent of alignment. Maybe gcc tries to
    be clever, but gets its optimization wrong.

    -- mva
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.