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

Re: [Minios-devel] [PATCH 17/40] mini-os: implement the memmove/memchr



Hello,

Huang Shijie, on ven. 03 nov. 2017 03:11:54 +0000, 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: this code is BSD copyright, and the code is originally come from
> NLnet Labs.

Which BSD? There are several variants, we are not allowed to confuse
them.

C-codewise,

Reviewed-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>

> Change-Id: Ife7830d4ba6a8b6e3e93622e1a469ae1cf620c39
> Jira: ENTOS-247
> Signed-off-by: Huang Shijie <shijie.huang@xxxxxxx>
> ---
>  Makefile      |  1 +
>  lib/memmove.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
>  lib/string.c  | 12 ++++++++++++
>  3 files changed, 57 insertions(+)
>  create mode 100644 lib/memmove.c
> 
> diff --git a/Makefile b/Makefile
> index 88315c4..43075e1 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -61,6 +61,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..28f2706
> --- /dev/null
> +++ b/lib/memmove.c
> @@ -0,0 +1,44 @@
> +/*
> + *     memmove.c: memmove compat implementation.
> + *
> + *     Copyright (c) 2001-2008, NLnet Labs. All rights reserved.
> + *
> + * See COPYING for the license.
> +*/
> +#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
> -- 
> 2.7.4
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@xxxxxxxxxxxxxxxxxxxx
> https://lists.xenproject.org/cgi-bin/mailman/listinfo/minios-devel

-- 
Samuel
<S> KK1 a 1 conseil de comment s'attaquer a du code java ou ya plus de 50 
classes ? par kel bout ?
<B> le troisième
 -+- #ens-mim en stage -+-

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

 


Rackspace

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