| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <string.h> |
| 6 |
#include <stdint.h> |
| 7 |
#include <stdbool.h> |
| 8 |
#include <asan.h> |
| 9 |
|
| 10 |
typedef uint32_t op_t; |
| 11 |
|
| 12 |
void *memset(void *dstpp, int c, size_t len) |
| 13 |
{ |
| 14 |
int d0; |
| 15 |
unsigned long dstp = (unsigned long)dstpp; |
| 16 |
|
| 17 |
#if (ENV_SEPARATE_ROMSTAGE && CONFIG(ASAN_IN_ROMSTAGE)) || \ |
| 18 |
(ENV_RAMSTAGE && CONFIG(ASAN_IN_RAMSTAGE)) |
| 19 |
check_memory_region((unsigned long)dstpp, len, true, _RET_IP_); |
| 20 |
#endif |
| 21 |
|
| 22 |
|
| 23 |
register op_t x asm("ax"); |
| 24 |
|
| 25 |
x = (unsigned char)c; |
| 26 |
|
| 27 |
|
| 28 |
asm volatile("cld"); |
| 29 |
|
| 30 |
|
| 31 |
if (len >= 12) { |
| 32 |
|
| 33 |
x |= (x << 8); |
| 34 |
x |= (x << 16); |
| 35 |
|
| 36 |
|
| 37 |
len -= (-dstp) % sizeof(op_t); |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
asm volatile( |
| 46 |
"rep\n" |
| 47 |
"stosb" : |
| 48 |
"=D" (dstp), "=c" (d0) : |
| 49 |
"0" (dstp), "1" ((-dstp) % sizeof(op_t)), "a" (x) : |
| 50 |
"memory"); |
| 51 |
|
| 52 |
|
| 53 |
asm volatile( |
| 54 |
"rep\n" |
| 55 |
"stosl" : |
| 56 |
"=D" (dstp), "=c" (d0) : |
| 57 |
"0" (dstp), "1" (len / sizeof(op_t)), "a" (x) : |
| 58 |
"memory"); |
| 59 |
len %= sizeof(op_t); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
asm volatile( |
| 64 |
"rep\n" |
| 65 |
"stosb" : |
| 66 |
"=D" (dstp), "=c" (d0) : |
| 67 |
"0" (dstp), "1" (len), "a" (x) : |
| 68 |
"memory"); |
| 69 |
|
| 70 |
return dstpp; |
| 71 |
} |