From e94e6f4bd91c92c7e1cc21d82ed9320dd722add2 Mon Sep 17 00:00:00 2001 From: Petar Jovanovic Date: Fri, 28 Jun 2019 15:41:37 +0000 Subject: mips: avoid calling memcpy() from memmove() for MIPS arch This is a follow up to an incorrect fix for memmove() problem in: commit 785dee78552f9ad06819bf7eb1adc05b43110842 Author: Petar Jovanovic Date: Mon May 6 13:29:02 2019 +0000 mips: fix memmove() call when __ARCH_HAS_BWD_MEMCPY__ is not defined Calling memcpy from memmove should be skipped in two cases: a) if arch's memcpy uses a backward copying (e.g. SH4) b) if arch's memcpy is not fully safe for overlapping regions (MIPS) Signed-off-by: Petar Jovanovic --- libc/string/generic/memmove.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libc/string/generic/memmove.c b/libc/string/generic/memmove.c index 1ac018013..5389cc029 100644 --- a/libc/string/generic/memmove.c +++ b/libc/string/generic/memmove.c @@ -23,8 +23,9 @@ #include "memcopy.h" #include "pagecopy.h" -#ifndef __ARCH_HAS_BWD_MEMCPY__ +#if defined(__ARCH_HAS_BWD_MEMCPY__) || defined(__mips__) /* generic-opt memmove assumes memcpy does forward copying! */ +/* also needed for MIPS as its memcpy does not support overlapping regions */ #include "_memcpy_fwd.c" #endif @@ -224,8 +225,11 @@ void *memmove (void *dest, const void *src, size_t len) Reduces the working set. */ if (dstp - srcp >= len) /* *Unsigned* compare! */ { -#ifdef __ARCH_HAS_BWD_MEMCPY__ - /* Backward memcpy implementation can be used */ + /* Calling memcpy() from memmove() should be skipped in two cases: + * a) if arch's memcpy uses a backward copying (SH4) + * b) if arch's memcpy is not fully safe for overlapping regions (MIPS) + */ +#if !defined(__ARCH_HAS_BWD_MEMCPY_) && !defined(__mips__) memcpy(dest, src, len); #else /* Copy from the beginning to the end. */ -- cgit v1.2.3