[libj6] Fix a memcpy return address bug

My `REP.MOVSB` `memcpy` implementation had marked its C++ variable
constraints as output instead of input, causing the compiler to emit
code to copy the values of `$rsi` and `$rdi` back into the `src` and
`dst` pointers, so after the copy `dst` pointed to the memory just
beyond what had been copied.

Very few places actually used the return value from `memcpy`, so this
went unnoticed for a bit..
This commit is contained in:
Justin C. Miller
2023-07-12 19:46:02 -07:00
parent 5d1fdd0e81
commit 778e766f6b

View File

@@ -7,9 +7,12 @@
using namespace j6; using namespace j6;
using namespace __j6libc; using namespace __j6libc;
void *memcpy(void * restrict s1, const void * restrict s2, size_t n) { void *memcpy(void * restrict dst, const void * restrict src, size_t n) {
asm volatile ("rep movsb" : "+D"(s1), "+S"(s2), "+c"(n) :: "memory"); asm volatile ("rep movsb"
return s1; :
: "D"(dst), "S"(src), "c"(n)
: "memory");
return dst;
} }
static void memmove_dispatch(char *s1, const char *s2, size_t n) { static void memmove_dispatch(char *s1, const char *s2, size_t n) {