From 802cb57e34322fa1ce4a89cfa019d9e2181818d8 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Sat, 28 Feb 2009 16:21:25 +0000 Subject: Add memmove() to the kernel, making the kernel compile with Clang. When copying big structures, LLVM generates calls to memmove(), because it may not be able to figure out whether structures overlap. This caused linker errors to occur. memmove() is now implemented using bcopy(). Ideally it would be the other way around, but that can be solved in the future. On ARM we don't do add anything, because it already has memmove(). Discussed on: arch@ Reviewed by: rdivacky --- sys/cddl/compat/opensolaris/sys/sysmacros.h | 4 --- sys/conf/files.amd64 | 1 + sys/conf/files.i386 | 1 + sys/conf/files.ia64 | 1 + sys/conf/files.mips | 1 + sys/conf/files.pc98 | 1 + sys/conf/files.powerpc | 1 + sys/conf/files.sparc64 | 1 + sys/conf/files.sun4v | 1 + sys/gnu/fs/xfs/FreeBSD/xfs_compat.h | 4 --- sys/libkern/memmove.c | 38 +++++++++++++++++++++++++++++ sys/net80211/ieee80211_freebsd.h | 2 -- sys/netgraph/atm/uni/ng_uni_cust.h | 2 -- sys/netgraph/ng_l2tp.c | 3 --- sys/powerpc/booke/pmap.c | 1 - sys/sys/systm.h | 1 + sys/xdr/xdr_mem.c | 2 -- 17 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 sys/libkern/memmove.c (limited to 'sys') diff --git a/sys/cddl/compat/opensolaris/sys/sysmacros.h b/sys/cddl/compat/opensolaris/sys/sysmacros.h index 7f4885bac600..3c1e9b167e3c 100644 --- a/sys/cddl/compat/opensolaris/sys/sysmacros.h +++ b/sys/cddl/compat/opensolaris/sys/sysmacros.h @@ -97,10 +97,6 @@ extern "C" { #define P2SAMEHIGHBIT_TYPED(x, y, type) \ (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y))) -#ifdef _KERNEL -#define memmove(dst, src, size) bcopy((src), (dst), (size)) -#endif - /* * Find highest one bit set. * Returns bit number + 1 of highest bit that is set, otherwise returns 0. diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 index 14312d5bab54..97f5ee5a4f91 100644 --- a/sys/conf/files.amd64 +++ b/sys/conf/files.amd64 @@ -271,4 +271,5 @@ i386/cpufreq/powernow.c optional cpufreq i386/cpufreq/est.c optional cpufreq i386/cpufreq/p4tcc.c optional cpufreq # +libkern/memmove.c standard libkern/memset.c standard diff --git a/sys/conf/files.i386 b/sys/conf/files.i386 index cb9e0dc4eb56..069e3b9256a5 100644 --- a/sys/conf/files.i386 +++ b/sys/conf/files.i386 @@ -366,6 +366,7 @@ kern/imgact_gzip.c optional gzip libkern/divdi3.c standard libkern/ffsl.c standard libkern/flsl.c standard +libkern/memmove.c standard libkern/memset.c standard libkern/moddi3.c standard libkern/qdivrem.c standard diff --git a/sys/conf/files.ia64 b/sys/conf/files.ia64 index 200435bb317b..62e36a5779b0 100644 --- a/sys/conf/files.ia64 +++ b/sys/conf/files.ia64 @@ -130,4 +130,5 @@ libkern/ia64/__umoddi3.S standard libkern/ia64/__umodsi3.S standard libkern/ia64/bswap16.S standard libkern/ia64/bswap32.S standard +libkern/memmove.c standard libkern/memset.c standard diff --git a/sys/conf/files.mips b/sys/conf/files.mips index 7fa0172c9422..1e233d789ef8 100644 --- a/sys/conf/files.mips +++ b/sys/conf/files.mips @@ -82,6 +82,7 @@ libkern/ffsl.c standard libkern/fls.c standard libkern/flsl.c standard libkern/lshrdi3.c standard +libkern/memmove.c standard libkern/moddi3.c standard libkern/qdivrem.c standard libkern/udivdi3.c standard diff --git a/sys/conf/files.pc98 b/sys/conf/files.pc98 index 2d4bcb884ad9..f8c6f0a4923c 100644 --- a/sys/conf/files.pc98 +++ b/sys/conf/files.pc98 @@ -224,6 +224,7 @@ kern/imgact_gzip.c optional gzip libkern/divdi3.c standard libkern/ffsl.c standard libkern/flsl.c standard +libkern/memmove.c standard libkern/memset.c standard libkern/moddi3.c standard libkern/qdivrem.c standard diff --git a/sys/conf/files.powerpc b/sys/conf/files.powerpc index 1ecba9eb0f21..4c4021961794 100644 --- a/sys/conf/files.powerpc +++ b/sys/conf/files.powerpc @@ -63,6 +63,7 @@ libkern/ffsl.c standard libkern/fls.c standard libkern/flsl.c standard libkern/lshrdi3.c standard +libkern/memmove.c standard libkern/memset.c standard libkern/moddi3.c standard libkern/qdivrem.c standard diff --git a/sys/conf/files.sparc64 b/sys/conf/files.sparc64 index 7687f9fae9b6..53077bbf2373 100644 --- a/sys/conf/files.sparc64 +++ b/sys/conf/files.sparc64 @@ -65,6 +65,7 @@ libkern/ffs.c standard libkern/ffsl.c standard libkern/fls.c standard libkern/flsl.c standard +libkern/memmove.c standard sparc64/central/central.c optional central sparc64/ebus/ebus.c optional ebus sparc64/fhc/clkbrd.c optional fhc diff --git a/sys/conf/files.sun4v b/sys/conf/files.sun4v index 384c13a2aea1..d83b0a29d293 100644 --- a/sys/conf/files.sun4v +++ b/sys/conf/files.sun4v @@ -34,6 +34,7 @@ libkern/ffs.c standard libkern/ffsl.c standard libkern/fls.c standard libkern/flsl.c standard +libkern/memmove.c standard sparc64/sparc64/autoconf.c standard sun4v/sun4v/bus_machdep.c standard sun4v/sun4v/clock.c standard diff --git a/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h b/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h index a98a7ee571df..7229f277f13d 100644 --- a/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h +++ b/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h @@ -129,10 +129,6 @@ typedef dev_t os_dev_t; #define copy_from_user(dst, src, len) copyin((src), (dst), (len)) #endif -#ifndef memmove -#define memmove(dst, src, len) bcopy((src), (dst), (len)) -#endif - #ifndef barrier #define barrier() __asm__ __volatile__("": : :"memory") #endif diff --git a/sys/libkern/memmove.c b/sys/libkern/memmove.c new file mode 100644 index 000000000000..9cb26a25fb6c --- /dev/null +++ b/sys/libkern/memmove.c @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 2009 Roman Divacky + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. +*/ + +#include +__FBSDID("$FreeBSD$"); + +#include + +void * +memmove(void *dest, const void *src, size_t n) +{ + + bcopy(src, dest, n); + return (dest); +} diff --git a/sys/net80211/ieee80211_freebsd.h b/sys/net80211/ieee80211_freebsd.h index 065d45c5471b..519e37d938fa 100644 --- a/sys/net80211/ieee80211_freebsd.h +++ b/sys/net80211/ieee80211_freebsd.h @@ -207,8 +207,6 @@ void ieee80211_vap_destroy(struct ieee80211vap *); #define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0) #define time_before_eq(a,b) time_after_eq(b,a) -#define memmove(dst, src, n) ovbcopy(src, dst, n) - struct mbuf *ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen); /* tx path usage */ diff --git a/sys/netgraph/atm/uni/ng_uni_cust.h b/sys/netgraph/atm/uni/ng_uni_cust.h index cf9d3549db5b..4336e57b212d 100644 --- a/sys/netgraph/atm/uni/ng_uni_cust.h +++ b/sys/netgraph/atm/uni/ng_uni_cust.h @@ -146,5 +146,3 @@ size_t unimem_sizes[UNIMEM_TYPES] = { \ [UNIMEM_CALL] = sizeof(struct call), \ [UNIMEM_PARTY] = sizeof(struct party) \ }; - -#define memmove(T, F, L) bcopy((F), (T), (L)) diff --git a/sys/netgraph/ng_l2tp.c b/sys/netgraph/ng_l2tp.c index 46dcba95a4d4..a5bb6280abfe 100644 --- a/sys/netgraph/ng_l2tp.c +++ b/sys/netgraph/ng_l2tp.c @@ -342,9 +342,6 @@ NETGRAPH_INIT(l2tp, &ng_l2tp_typestruct); #define L2TP_SEQ_CHECK(x) do { } while (0) #endif -/* memmove macro */ -#define memmove(d, s, l) bcopy(s, d, l) - /* Whether to use m_copypacket() or m_dup() */ #define L2TP_COPY_MBUF m_copypacket diff --git a/sys/powerpc/booke/pmap.c b/sys/powerpc/booke/pmap.c index 72964f734869..136279d4b306 100644 --- a/sys/powerpc/booke/pmap.c +++ b/sys/powerpc/booke/pmap.c @@ -100,7 +100,6 @@ __FBSDID("$FreeBSD$"); #endif #define TODO panic("%s: not implemented", __func__); -#define memmove(d, s, l) bcopy(s, d, l) #include "opt_sched.h" #ifndef SCHED_4BSD diff --git a/sys/sys/systm.h b/sys/sys/systm.h index eb60a341cbf7..5dba5121beaa 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -186,6 +186,7 @@ void bcopy(const void *from, void *to, size_t len) __nonnull(1) __nonnull(2); void bzero(void *buf, size_t len) __nonnull(1); void *memcpy(void *to, const void *from, size_t len) __nonnull(1) __nonnull(2); +void *memmove(void *dest, const void *src, size_t n) __nonnull(1) __nonnull(2); int copystr(const void * __restrict kfaddr, void * __restrict kdaddr, size_t len, size_t * __restrict lencopied) diff --git a/sys/xdr/xdr_mem.c b/sys/xdr/xdr_mem.c index 121d5d86741a..2dd5b73a79b1 100644 --- a/sys/xdr/xdr_mem.c +++ b/sys/xdr/xdr_mem.c @@ -54,8 +54,6 @@ __FBSDID("$FreeBSD$"); #include #include -#define memmove(dst, src, len) bcopy(src, dst, len) - static void xdrmem_destroy(XDR *); static bool_t xdrmem_getlong_aligned(XDR *, long *); static bool_t xdrmem_putlong_aligned(XDR *, const long *); -- cgit v1.3