compel: Move memcpy/memcpy/etc stuff in

This is the difference between two commits

	criu-dev/b0f6f293/Unify own memcpy/memset/memcmp
	  master/0367a1fe/Drop prefix from own memcpy/memset/memcmp

that makes criu-dev after rebase on master with latter commit
be the same as it was with former commit before rebase.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Kir Kolyshkin 2017-02-13 13:00:33 +03:00 committed by Andrei Vagin
parent 735ffc1d7e
commit f233b86a02
28 changed files with 105 additions and 130 deletions

View file

@ -1,6 +1,8 @@
.PHONY: .FORCE
CFLAGS := $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS)) -DCR_NOGLIBC
CFLAGS := $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS))
CFLAGS += -DCR_NOGLIBC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
CFLAGS += -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=0
CFLAGS := $(filter-out $(CFLAGS-ASAN),$(CFLAGS))
PLUGIN_ARCH_DIR := compel/arch/$(ARCH)/plugins
@ -48,6 +50,15 @@ std-obj-y += std/string.o
std-obj-y += std/infect.o
std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/parasite-head.o
ifeq ($(SRCARCH),x86)
std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/memcpy.o
endif
ifeq ($(SRCARCH),ppc64)
std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/memcpy.o
std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/memcmp.o
endif
include ./$(PLUGIN_ARCH_DIR)/std/syscalls/Makefile.syscalls
define syscall-priority

View file

@ -21,8 +21,11 @@ extern void __std_printf(int fd, const char *format, ...);
#define std_putchar(c) __std_putc(STDOUT_FILENO, c)
extern unsigned long std_strtoul(const char *nptr, char **endptr, int base);
extern void *std_memcpy(void *to, const void *from, unsigned int n);
extern int std_memcmp(const void *cs, const void *ct, size_t count);
extern int std_strcmp(const char *cs, const char *ct);
extern int std_strncmp(const char *cs, const char *ct, size_t n);
extern void *memcpy(void *dest, const void *src, size_t n);
extern int memcmp(const void *s1, const void *s2, size_t n);
extern void *memset(void *s, int c, size_t n);
#endif /* COMPEL_PLUGIN_STD_STRING_H__ */

View file

@ -16,6 +16,5 @@
#define __sys(foo) sys_##foo
#define __sys_err(ret) ret
#define __memcpy std_memcpy
#include "common/scm-code.c"

View file

@ -1,8 +1,8 @@
#include <stdarg.h>
#include "string.h"
#include "common/bitsperlong.h"
#include <compel/plugins/std/syscall.h>
#include "uapi/std/string.h"
#include <compel/plugins/std/log.h>
#include <compel/loglevels.h>

View file

@ -5,6 +5,8 @@
#include "uapi/std/syscall.h"
#include "uapi/std/string.h"
#include "features.h"
static const char conv_tab[] = "0123456789abcdefghijklmnopqrstuvwxyz";
void __std_putc(int fd, char c)
@ -220,17 +222,33 @@ fin:
return neg ? (unsigned long)-num : (unsigned long)num;
}
void *std_memcpy(void *to, const void *from, unsigned int n)
{
char *tmp = to;
const char *s = from;
while (n--)
*tmp++ = *s++;
/*
* C compiler is free to insert implicit calls to memcmp, memset,
* memcpy and memmove, assuming they are available during linking.
* As the parasite code is not linked with libc, it must provide
* our own implementations of the above functions.
* Surely, these functions can also be called explicitly.
*
* Note: for now, not having memmove() seems OK for both gcc and clang.
*/
#ifndef ARCH_HAS_MEMCPY
void *memcpy(void *to, const void *from, size_t n)
{
size_t i;
unsigned char *cto = to;
const unsigned char *cfrom = from;
for (i = 0; i < n; ++i, ++cto, ++cfrom)
*cto = *cfrom;
return to;
}
#endif
int std_memcmp(const void *cs, const void *ct, size_t count)
#ifndef ARCH_HAS_MEMCMP
int memcmp(const void *cs, const void *ct, size_t count)
{
const unsigned char *su1, *su2;
int res = 0;
@ -240,6 +258,20 @@ int std_memcmp(const void *cs, const void *ct, size_t count)
break;
return res;
}
#endif
#ifndef ARCH_HAS_MEMSET
void *memset(void *s, const int c, size_t count)
{
volatile char *dest = s;
size_t i = 0;
while (i < count)
dest[i++] = (char) c;
return s;
}
#endif
int std_strcmp(const char *cs, const char *ct)
{
@ -255,3 +287,16 @@ int std_strcmp(const char *cs, const char *ct)
}
return 0;
}
int std_strncmp(const char *cs, const char *ct, size_t count)
{
size_t i;
for (i = 0; i < count; i++) {
if (cs[i] != ct[i])
return cs[i] < ct[i] ? -1 : 1;
if (!cs[i])
break;
}
return 0;
}