I have an emulated runtime environment where I am handling certain functions outside of the guest. One of the functions is a strlen function, which can read memory potentially up to SSIZE_MAX / PTRDIFF_MAX bytes1
size_t strlen(const char* str)
{
register const char* a0 asm("a0") = str;
register size_t a0_out asm("a0");
register long syscall_id asm("a7") = SYSCALL_STRLEN;
asm volatile ("ecall" : "=r"(a0_out) :
"r"(a0), "m"(*(const char(*)[4096]) a0), "r"(syscall_id));
return a0_out;
}
The problem I am having is that while GCC is happy when I remove the magic 4096, Clang isn't. GCC treats the size as (I assume) unbounded, but for Clang that simply would not compile, so I am forced to put a number there, I believe.
Is the magic 4096 a problem? What options do I have here?
Footnote 1: In GNU C object sizes are limited to less than SIZE_MAX to make pointer subtraction easy / efficient.