[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [PATCH v3 20/43] mini-os: implement the memmove/memchr



On Wed, Apr 25, 2018 at 10:10:58AM +0100, Julien Grall wrote:
> 
> 
> On 04/16/2018 07:32 AM, Huang Shijie wrote:
> >This patch is split from the Chen Baozi's old patch:
> >
> >"This activates the ARM code added in the previous patches. On
> >  ARM, Mini-OS will boot and display some output on the console. Tested 
> > with:"
> >
> >Note: The code is copied from FreeBSD code:
> >       freebsd/contrib/ldns/compat/memmove.c
> 
> That's only for memmove. How about memchr?
The memchr is also from the FreeBSD code...

> 
> Also, can you explain in the commit message why you need them?
The FDT code will need them..

Thanks
Huang Shijie
> 
> Cheers,
> 
> >
> >Signed-off-by: Huang Shijie <shijie.huang@xxxxxxx>
> >---
> >  Makefile      |  1 +
> >  lib/memmove.c | 74 
> > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  lib/string.c  | 12 ++++++++++
> >  3 files changed, 87 insertions(+)
> >  create mode 100644 lib/memmove.c
> >
> >diff --git a/Makefile b/Makefile
> >index 6a05de6..3ad2522 100644
> >--- a/Makefile
> >+++ b/Makefile
> >@@ -62,6 +62,7 @@ src-y += lib/math.c
> >  src-y += lib/printf.c
> >  src-y += lib/stack_chk_fail.c
> >  src-y += lib/string.c
> >+src-y += lib/memmove.c
> >  src-y += lib/sys.c
> >  src-y += lib/xmalloc.c
> >  src-$(CONFIG_XENBUS) += lib/xs.c
> >diff --git a/lib/memmove.c b/lib/memmove.c
> >new file mode 100644
> >index 0000000..d5ac036
> >--- /dev/null
> >+++ b/lib/memmove.c
> >@@ -0,0 +1,74 @@
> >+/*
> >+ *     memmove.c: memmove compat implementation.
> >+ *
> >+ *     Copyright (c) 2001-2008, NLnet Labs. All rights reserved.
> >+ *
> >+ * See COPYING for the license.
> >+*/
> >+
> >+/*
> >+Copyright (c) 2005,2006, NLnetLabs
> >+All rights reserved.
> >+
> >+Redistribution and use in source and binary forms, with or without
> >+modification, are permitted provided that the following conditions are met:
> >+
> >+    * Redistributions of source code must retain the above copyright notice,
> >+      this list of conditions and the following disclaimer.
> >+    * 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.
> >+    * Neither the name of NLnetLabs nor the names of its
> >+      contributors may be used to endorse or promote products derived from 
> >this
> >+      software without specific prior written permission.
> >+
> >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 <os.h>
> >+#include <mini-os/lib.h>
> >+
> >+#ifndef HAVE_LIBC
> >+
> >+void *memmove(void *dest, const void *src, size_t n)
> >+{
> >+       uint8_t* from = (uint8_t*) src;
> >+       uint8_t* to = (uint8_t*) dest;
> >+
> >+       if (from == to || n == 0)
> >+               return dest;
> >+       if (to > from && to-from < (int)n) {
> >+               /* to overlaps with from */
> >+               /*  <from......>         */
> >+               /*         <to........>  */
> >+               /* copy in reverse, to avoid overwriting from */
> >+               int i;
> >+               for(i=n-1; i>=0; i--)
> >+                       to[i] = from[i];
> >+               return dest;
> >+       }
> >+       if (from > to  && from-to < (int)n) {
> >+               /* to overlaps with from */
> >+               /*        <from......>   */
> >+               /*  <to........>         */
> >+               /* copy forwards, to avoid overwriting from */
> >+               size_t i;
> >+               for(i=0; i<n; i++)
> >+                       to[i] = from[i];
> >+               return dest;
> >+       }
> >+       memcpy(dest, src, n);
> >+       return dest;
> >+}
> >+
> >+#endif
> >diff --git a/lib/string.c b/lib/string.c
> >index 8b24146..c96ca41 100644
> >--- a/lib/string.c
> >+++ b/lib/string.c
> >@@ -225,4 +225,16 @@ int ffs(int i)
> >     return 0;
> >  }
> >+void *memchr(const void *s, int c, size_t n)
> >+{
> >+    if (n != 0) {
> >+        const unsigned char *p = s;
> >+
> >+        do {
> >+            if (*p++ == (unsigned char)c)
> >+                return ((void *)(uintptr_t)(p - 1));
> >+        } while (--n != 0);
> >+    }
> >+    return (NULL);
> >+}
> >  #endif
> >
> 
> -- 
> Julien Grall

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.