Commit f233b86a authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Andrei Vagin

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: 's avatarKir Kolyshkin <kir@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 735ffc1d
#ifndef __COMPEL_ARCH_FEATURES_H
#define __COMPEL_ARCH_FEATURES_H
#endif /* __COMPEL_ARCH_FEATURES_H */
#ifndef __COMPEL_ARCH_FEATURES_H
#define __COMPEL_ARCH_FEATURES_H
#endif /* __COMPEL_ARCH_FEATURES_H */
#ifndef __CRIU_ARCH_FEATURES_H
#define __CRIU_ARCH_FEATURES_H
#ifndef __COMPEL_ARCH_FEATURES_H
#define __COMPEL_ARCH_FEATURES_H
#define ARCH_HAS_MEMCPY
#define ARCH_HAS_MEMCMP
#endif /* __CRIU_ARCH_FEATURES_H */
#endif /* __COMPEL_ARCH_FEATURES_H */
#ifndef __COMPEL_ARCH_FEATURES_H
#define __COMPEL_ARCH_FEATURES_H
#define ARCH_HAS_MEMCPY
#endif /* __COMPEL_ARCH_FEATURES_H */
.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
......
......@@ -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__ */
......@@ -16,6 +16,5 @@
#define __sys(foo) sys_##foo
#define __sys_err(ret) ret
#define __memcpy std_memcpy
#include "common/scm-code.c"
#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>
......
......@@ -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)
/*
* 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)
{
char *tmp = to;
const char *s = from;
size_t i;
unsigned char *cto = to;
const unsigned char *cfrom = from;
for (i = 0; i < n; ++i, ++cto, ++cfrom)
*cto = *cfrom;
while (n--)
*tmp++ = *s++;
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;
}
......@@ -29,7 +29,6 @@
#define __sys(foo) foo
#define __sys_err(ret) (-errno)
#define __memcpy memcpy
#include "common/scm.h"
#include "common/scm-code.c"
......
#ifndef __CRIU_ARCH_FEATURES_H
#define __CRIU_ARCH_FEATURES_H
#endif /* __CRIU_ARCH_FEATURES_H */
#ifndef __CRIU_ARCH_FEATURES_H
#define __CRIU_ARCH_FEATURES_H
#endif /* __CRIU_ARCH_FEATURES_H */
#include <unistd.h>
#include <string.h>
#include "asm/types.h"
#include <compel/plugins/std/string.h>
#include <compel/plugins/std/syscall.h>
#include "parasite-vdso.h"
#include "log.h"
......
#ifndef __ASM_PARASITE_H__
#define __ASM_PARASITE_H__
#include "asm-generic/string.h"
#include <compel/plugins/std/string.h>
#include <compel/plugins/std/syscall-codes.h>
#include "asm/compat.h"
......@@ -68,11 +68,11 @@ static void arch_get_tls(tls_t *ptls)
{
user_desc_t *d = syscall_mem;
builtin_memset(d, 0, sizeof(user_desc_t));
memset(d, 0, sizeof(user_desc_t));
d->seg_not_present = 1;
d->entry_number = GDT_ENTRY_TLS_MIN + i;
arch_get_user_desc(d);
builtin_memcpy(&ptls->desc[i], d, sizeof(user_desc_t));
memcpy(&ptls->desc[i], d, sizeof(user_desc_t));
}
free_compat_syscall_stack(syscall_mem);
......
#ifndef __CRIU_ARCH_FEATURES_H
#define __CRIU_ARCH_FEATURES_H
#define ARCH_HAS_MEMCPY
#endif /* __CRIU_ARCH_FEATURES_H */
......@@ -5,8 +5,8 @@
#include "restorer.h"
#include "asm/restorer.h"
#include <compel/asm/fpu.h>
#include "asm/string.h"
#include <compel/plugins/std/string.h>
#include <compel/plugins/std/syscall.h>
#include "log.h"
#include "cpu.h"
......@@ -71,7 +71,7 @@ void restore_tls(tls_t *ptls)
if (prepare_stack32(&stack32) < 0)
return;
builtin_memcpy(stack32, desc, sizeof(user_desc_t));
memcpy(stack32, desc, sizeof(user_desc_t));
asm volatile (
" mov %1,%%eax \n"
" mov %2,%%ebx \n"
......
#include "log.h"
#include "asm/restorer.h"
#include <compel/asm/fpu.h>
#include "asm/string.h"
#include "asm/compat.h"
#ifdef CR_NOGLIBC
# include <compel/plugins/std/syscall.h>
# include <compel/plugins/std/string.h>
#else
# ifndef __NR32_rt_sigaction
# define __NR32_rt_sigaction 174
......@@ -38,7 +38,7 @@ int arch_compat_rt_sigaction(void *stack32, int sig, rt_sigaction_t_compat *act)
* To be sure, that sigaction pointer lies under 4G,
* coping it on the bottom of the stack.
*/
builtin_memcpy(stack32, act, sizeof(rt_sigaction_t_compat));
memcpy(stack32, act, sizeof(rt_sigaction_t_compat));
asm volatile ("\t movl %%ebx,%%ebx\n" : :"b"(sig)); /* signum */
asm volatile ("\t movl %%ecx,%%ecx\n" : :"c"(stack32)); /* act */
......
#include <unistd.h>
#include "string.h"
#include "asm/types.h"
#include <compel/plugins/std/string.h>
#include <compel/plugins/std/syscall.h>
#include "parasite-vdso.h"
#include "log.h"
......
......@@ -2,7 +2,6 @@
#define __CR_STRING_H__
#include <sys/types.h>
#include <string.h>
#ifdef CONFIG_HAS_LIBBSD
# include <bsd/string.h>
......@@ -18,6 +17,4 @@ extern size_t strlcpy(char *dest, const char *src, size_t size);
extern size_t strlcat(char *dest, const char *src, size_t count);
#endif
extern int builtin_strncmp(const char *cs, const char *ct, size_t count);
#endif /* __CR_STRING_H__ */
......@@ -26,8 +26,6 @@ CFLAGS += -iquote $(SRC_DIR)/criu/arch/$(ARCH)/include
CFLAGS += -iquote $(SRC_DIR)/criu/include
CFLAGS += -iquote $(SRC_DIR)/include
CFLAGS += -iquote $(SRC_DIR)
CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
CFLAGS += -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=0
ccflags-y += $(COMPEL_UAPI_INCLUDES)
ccflags-y += -DCR_NOGLIBC
......
......@@ -3,7 +3,7 @@ lib-name := pie.lib.a
CFLAGS += -fno-stack-protector -DCR_NOGLIBC -fpie
LDFLAGS += -z noexecstack
lib-y += util.o string.o
lib-y += util.o
ifeq ($(VDSO),y)
lib-y += util-vdso.o parasite-vdso.o ./$(ARCH_DIR)/vdso-pie.o
......@@ -18,8 +18,7 @@ ifeq ($(VDSO),y)
endif
ifeq ($(SRCARCH),ppc64)
lib-y += ./$(ARCH_DIR)/memcpy_power7.o \
./$(ARCH_DIR)/memcmp_64.o ./$(ARCH_DIR)/misc.o
lib-y += ./$(ARCH_DIR)/misc.o
endif
ifeq ($(SRCARCH),x86)
......@@ -27,8 +26,6 @@ ifeq ($(SRCARCH),x86)
lib-y += util-vdso-elf32.o
endif
CFLAGS_util-vdso-elf32.o += -DCONFIG_VDSO_32
lib-y += ./$(ARCH_DIR)/memcpy.o
endif
#
......@@ -49,12 +46,3 @@ ccflags-y += $(COMPEL_UAPI_INCLUDES)
ifeq ($(SRCARCH),arm)
ccflags-y += -marm
endif
ifneq ($(filter-out ia32,$(ARCH)),)
ccflags-y += -DCR_NOGLIBC -fpie -Wa,--noexecstack -fno-stack-protector
else
ccflags-y += -DCR_NOGLIBC -fno-pic -Wa,--noexecstack -fno-stack-protector
endif
ccflags-y += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
ccflags-y += -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=0
......@@ -20,7 +20,6 @@
#include "int.h"
#include "types.h"
#include "common/compiler.h"
#include "string.h"
#include <compel/plugins/std/syscall.h>
#include <compel/plugins/std/log.h>
#include <compel/ksigset.h>
......
#include <string.h>
#include "features.h"
/* C compiler may generate calls to memcmp, memset, memcpy and memmove,
* so it relies on those to be available during linking.
* In case we are not linking our code against glibc, we set CR_NOGLIBC
* and have to provide our own implementations of mem*() functions.
*
* 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
#ifndef ARCH_HAS_MEMCMP
int memcmp(const void *cs, const void *ct, size_t count)
{
const unsigned char *su1, *su2;
int res = 0;
for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
if ((res = *su1 - *su2) != 0)
break;
return res;
}
#endif
int builtin_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;
}
#ifndef ARCH_HAS_MEMSET
void *memset(void *s, const int c, size_t count)
{
char *dest = s;
size_t i = 0;
while (i < count)
dest[i++] = (char) c;
return s;
}
#endif
......@@ -17,13 +17,12 @@
#include "common/bug.h"
#ifdef CR_NOGLIBC
# include "string.h"
# include <compel/plugins/std/string.h>
#else
# include <string.h>
# define builtin_strncmp strncmp
# define std_strncmp strncmp
#endif
#ifdef LOG_PREFIX
# undef LOG_PREFIX
#endif
......@@ -246,7 +245,7 @@ static void parse_elf_symbols(uintptr_t mem, size_t size, Phdr_t *load,
continue;
name = (void *)addr;
if (builtin_strncmp(name, symbol, vdso_symbol_length))
if (std_strncmp(name, symbol, vdso_symbol_length))
continue;
memcpy(t->symbols[i].name, name, vdso_symbol_length);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment