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
This commit is contained in:
Ed Schouten 2009-02-28 16:21:25 +00:00
parent b57fd79960
commit 802cb57e34
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=189170
17 changed files with 47 additions and 18 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

38
sys/libkern/memmove.c Normal file
View File

@ -0,0 +1,38 @@
/*-
* Copyright (c) 2009 Roman Divacky <rdivacky@FreeBSD.org>
* 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 <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/libkern.h>
void *
memmove(void *dest, const void *src, size_t n)
{
bcopy(src, dest, n);
return (dest);
}

View File

@ -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 */

View File

@ -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))

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -54,8 +54,6 @@ __FBSDID("$FreeBSD$");
#include <rpc/types.h>
#include <rpc/xdr.h>
#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 *);