1 // SPDX-License-Identifier: GPL-2.0
11 #define MIN_REDZONE 128
12 #define BUFLEN (MAX_LEN+MAX_OFFSET+2*MIN_REDZONE)
15 unsigned long COPY_LOOP(void *to
, const void *from
, unsigned long size
);
17 static void do_one(char *src
, char *dst
, unsigned long src_off
,
18 unsigned long dst_off
, unsigned long len
, void *redzone
,
25 srcp
= src
+ MIN_REDZONE
+ src_off
;
26 dstp
= dst
+ MIN_REDZONE
+ dst_off
;
28 memset(src
, POISON
, BUFLEN
);
29 memset(dst
, POISON
, BUFLEN
);
30 memcpy(srcp
, fill
, len
);
32 ret
= COPY_LOOP(dstp
, srcp
, len
);
33 if (ret
&& ret
!= (unsigned long)dstp
) {
34 printf("(%p,%p,%ld) returned %ld\n", dstp
, srcp
, len
, ret
);
38 if (memcmp(dstp
, srcp
, len
)) {
39 printf("(%p,%p,%ld) miscompare\n", dstp
, srcp
, len
);
41 for (i
= 0; i
< len
; i
++)
42 printf("%02x ", srcp
[i
]);
44 for (i
= 0; i
< len
; i
++)
45 printf("%02x ", dstp
[i
]);
50 if (memcmp(dst
, redzone
, dstp
- dst
)) {
51 printf("(%p,%p,%ld) redzone before corrupted\n",
56 if (memcmp(dstp
+len
, redzone
, dst
+BUFLEN
-(dstp
+len
))) {
57 printf("(%p,%p,%ld) redzone after corrupted\n",
63 int test_copy_loop(void)
65 char *src
, *dst
, *redzone
, *fill
;
66 unsigned long len
, src_off
, dst_off
;
69 src
= memalign(BUFLEN
, BUFLEN
);
70 dst
= memalign(BUFLEN
, BUFLEN
);
71 redzone
= malloc(BUFLEN
);
72 fill
= malloc(BUFLEN
);
74 if (!src
|| !dst
|| !redzone
|| !fill
) {
75 fprintf(stderr
, "malloc failed\n");
79 memset(redzone
, POISON
, BUFLEN
);
81 /* Fill with sequential bytes */
82 for (i
= 0; i
< BUFLEN
; i
++)
85 for (len
= 1; len
< MAX_LEN
; len
++) {
86 for (src_off
= 0; src_off
< MAX_OFFSET
; src_off
++) {
87 for (dst_off
= 0; dst_off
< MAX_OFFSET
; dst_off
++) {
88 do_one(src
, dst
, src_off
, dst_off
, len
,
99 return test_harness(test_copy_loop
, str(COPY_LOOP
));