This case sometimes will cause SIGILL signal in arm64 platform.
<<ARM Coretex-A series Programmer's Guide for ARMv8-A>> notes: The ARM architecture does not require the hardware to ensure coherency between instruction caches and memory, even for locations of shared memory.
Therefore, we need flush dcache and icache for self-modifying code.
- https://developer.arm.com/documentation/den0024/a/Caches/Point-of-coherency-...
Signed-off-by: fu.lin fulin10@huawei.com --- test/zdtm/static/maps00.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/test/zdtm/static/maps00.c b/test/zdtm/static/maps00.c index f2da9b9..83533f8 100644 --- a/test/zdtm/static/maps00.c +++ b/test/zdtm/static/maps00.c @@ -173,7 +173,8 @@ static int check_map(struct map *map) if (!sigsetjmp(segv_ret, 1)) { if (map->prot & PROT_WRITE) { - memcpy(map->ptr,test_func, getpagesize()); + memcpy(map->ptr,test_func, ONE_MAP_SIZE); + __builtin___clear_cache(map->ptr, map->ptr+ONE_MAP_SIZE); } else { if (!(map->flag & MAP_ANONYMOUS)) { uint8_t funlen = (uint8_t *)check_map - (uint8_t *)test_func; @@ -184,14 +185,15 @@ static int check_map(struct map *map) } } } - if (!(map->flag & MAP_ANONYMOUS) || map->prot & PROT_WRITE) + if (!(map->flag & MAP_ANONYMOUS) || (map->prot & PROT_WRITE)) { /* Function body has been copied into the mapping */ ((int (*)(void))map->ptr)(); /* perform exec access */ - else + } else { /* No way to copy function body into mapping, * clear exec bit from effective protection */ prot &= PROT_WRITE | PROT_READ | !PROT_EXEC; + } } else prot &= PROT_WRITE | PROT_READ | !PROT_EXEC;