Re: [PATCH v2] lib/decompress_unxz.c: removing all memory helper functions

From
Lasse Collin <lasse.collin@tukaani.org>
Date
2012-06-12 16:18:17
Also in
linux-arm-kernel, lkml
Reply to
T Makphaibulchoke, 2012-06-12
On 2012-06-11 T Makphaibulchoke wrote:
quoted hunk ↗ jump to hunk
--- /dev/null
+++ b/lib/boot/mem.c
@@ -0,0 +1,58 @@
+/*
+ * Small subset of simple memory helper functions required by different
+ * compressors for preboot environment.
+ */
+
+#include <linux/string.h>
+
+#ifndef __HAVE_PREBOOT_ARCH_MEMCPY
+void *memcpy(void *__dest, __const void *__src, size_t __n)
+{
+	return __builtin_memcpy(__dest, __src, __n);
+}
+#endif
GCC will replace __builtin_memcpy above with a call to memcpy, creating
an infinite loop. I confirmed this on x86_64 by first uncommenting the
memcpy from arch/x86/boot/compressed/string.c.

You need to provide a memcpy implementation yourself without using
__builtin functions. For example, copy the memcpy implementation from
lib/string.c.
quoted hunk ↗ jump to hunk
+#ifndef __HAVE_PREBOOT_ARCH_MEMMOVE
+void *memmove(void *__dest, __const void *__src, size_t count)
+{
+	unsigned char *d = __dest;
+	const unsigned char *s = __src;
+
+	if (__dest = __src)
+		return __dest;
+
+	if (__dest < __src)
+		return memcpy(__dest, __src, count);
+
+	while (count--)
+		d[count] = s[count];
+	return __dest;
+}
+#endif
The use of memcpy when __dest < __src is OK with some memcpy
implementations, but in a generic case it isn't guaranteed to work.
I think it would be better to just copy memmove from lib/string.c.

-- 
Lasse Collin  |  IRC: Larhzu @ IRCnet & Freenode
Thread (18 messages) 18 messages, 9 authors, last reply 2012-06-14
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help