10 #define MIN_REDZONE 128
11 #define BUFLEN (MAX_LEN+MAX_OFFSET+2*MIN_REDZONE)
14 unsigned long COPY_LOOP(void *to
, const void *from
, unsigned long size
);
16 static void do_one(char *src
, char *dst
, unsigned long src_off
,
17 unsigned long dst_off
, unsigned long len
, void *redzone
,
24 srcp
= src
+ MIN_REDZONE
+ src_off
;
25 dstp
= dst
+ MIN_REDZONE
+ dst_off
;
27 memset(src
, POISON
, BUFLEN
);
28 memset(dst
, POISON
, BUFLEN
);
29 memcpy(srcp
, fill
, len
);
31 ret
= COPY_LOOP(dstp
, srcp
, len
);
32 if (ret
&& ret
!= (unsigned long)dstp
) {
33 printf("(%p,%p,%ld) returned %ld\n", dstp
, srcp
, len
, ret
);
37 if (memcmp(dstp
, srcp
, len
)) {
38 printf("(%p,%p,%ld) miscompare\n", dstp
, srcp
, len
);
40 for (i
= 0; i
< len
; i
++)
41 printf("%02x ", srcp
[i
]);
43 for (i
= 0; i
< len
; i
++)
44 printf("%02x ", dstp
[i
]);
49 if (memcmp(dst
, redzone
, dstp
- dst
)) {
50 printf("(%p,%p,%ld) redzone before corrupted\n",
55 if (memcmp(dstp
+len
, redzone
, dst
+BUFLEN
-(dstp
+len
))) {
56 printf("(%p,%p,%ld) redzone after corrupted\n",
62 int test_copy_loop(void)
64 char *src
, *dst
, *redzone
, *fill
;
65 unsigned long len
, src_off
, dst_off
;
68 src
= memalign(BUFLEN
, BUFLEN
);
69 dst
= memalign(BUFLEN
, BUFLEN
);
70 redzone
= malloc(BUFLEN
);
71 fill
= malloc(BUFLEN
);
73 if (!src
|| !dst
|| !redzone
|| !fill
) {
74 fprintf(stderr
, "malloc failed\n");
78 memset(redzone
, POISON
, BUFLEN
);
80 /* Fill with sequential bytes */
81 for (i
= 0; i
< BUFLEN
; i
++)
84 for (len
= 1; len
< MAX_LEN
; len
++) {
85 for (src_off
= 0; src_off
< MAX_OFFSET
; src_off
++) {
86 for (dst_off
= 0; dst_off
< MAX_OFFSET
; dst_off
++) {
87 do_one(src
, dst
, src_off
, dst_off
, len
,
98 return test_harness(test_copy_loop
, str(COPY_LOOP
));