Changeset 2d7a5fe in mainline


Ignore:
Timestamp:
2006-06-06T15:42:36Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ae3f1709
Parents:
e269c53
Message:

Generic version of memcpy that is resistent towards unaligned memory accesses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • generic/src/lib/memstr.c

    re269c53 r2d7a5fe  
    4141#include <memstr.h>
    4242#include <arch/types.h>
     43#include <align.h>
    4344
    4445/** Copy block of memory
     
    5758        int i, j;
    5859       
    59         for (i = 0; i < cnt/sizeof(__native); i++)
    60                 ((__native *) dst)[i] = ((__native *) src)[i];
     60        if (ALIGN_UP((__address) src, sizeof(__native)) != (__address) src ||
     61                ALIGN_UP((__address) dst, sizeof(__native)) != (__address) dst) {
     62                for (i = 0; i < cnt; i++)
     63                        ((__u8 *) dst)[i] = ((__u8 *) src)[i];
     64        } else {
     65       
     66                for (i = 0; i < cnt/sizeof(__native); i++)
     67                        ((__native *) dst)[i] = ((__native *) src)[i];
    6168               
    62         for (j = 0; j < cnt%sizeof(__native); j++)
    63                 ((__u8 *)(((__native *) dst) + i))[j] = ((__u8 *)(((__native *) src) + i))[j];
     69                for (j = 0; j < cnt%sizeof(__native); j++)
     70                        ((__u8 *)(((__native *) dst) + i))[j] = ((__u8 *)(((__native *) src) + i))[j];
     71        }
    6472               
    6573        return (char *)src;
Note: See TracChangeset for help on using the changeset viewer.