Skip to content

Commit ac33d37

Browse files
committed
lkl: remove string functions duplicate implementation
Now that we have the ability to set kernel config options per host built we can avoid duplicating the implementation for string functions that may be provided by the host (e.g. memcpy, memset). Signed-off-by: Octavian Purdila <[email protected]>
1 parent 0d9fd6f commit ac33d37

File tree

4 files changed

+41
-46
lines changed

4 files changed

+41
-46
lines changed

arch/lkl/Kconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,24 @@ config BUILTIN_CMDLINE
182182
image and used at boot time. The command line provided to
183183
lkl_start_kernel is appended to this string to form the full
184184
command line.
185+
186+
config LKL_HOST_MEMCPY
187+
bool "Host provides memcpy"
188+
default n
189+
help
190+
This options should be set (in tools/lkl/Makefile.autoconf)
191+
if the host provides a memcpy implementation.
192+
193+
config LKL_HOST_MEMSET
194+
bool "Host provides memset"
195+
default n
196+
help
197+
This options should be set (in tools/lkl/Makefile.autoconf)
198+
if the host provides a memset implementation.
199+
200+
config LKL_HOST_MEMMOVE
201+
bool "Host provides memmove"
202+
default n
203+
help
204+
This options should be set (in tools/lkl/Makefile.autoconf)
205+
if the host provides a memmove implementation.

arch/lkl/include/asm/string.h

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,35 @@
77

88
/* use __mem* names to avoid conflict with KASAN's mem* functions. */
99

10+
#ifdef CONFIG_LKL_HOST_MEMCPY
1011
#define __HAVE_ARCH_MEMCPY
1112
extern void *memcpy(void *dest, const void *src, size_t count);
1213
static inline void *__memcpy(void *dest, const void *src, size_t count)
1314
{
14-
char *tmp = dest;
15-
const char *s = src;
16-
17-
if (lkl_ops->memcpy)
18-
return lkl_ops->memcpy(dest, src, count);
19-
20-
/* from lib/string.c */
21-
22-
while (count--)
23-
*tmp++ = *s++;
24-
return dest;
15+
return lkl_ops->memcpy(dest, src, count);
2516
}
17+
#define memcpy(dst, src, len) __memcpy(dst, src, len)
18+
#endif
2619

20+
#ifdef CONFIG_LKL_HOST_MEMSET
2721
#define __HAVE_ARCH_MEMSET
2822
extern void *memset(void *s, int c, size_t count);
2923
static inline void *__memset(void *s, int c, size_t count)
3024
{
31-
char *xs = s;
32-
33-
if (lkl_ops->memset)
34-
return lkl_ops->memset(s, c, count);
35-
36-
/* from lib/string.c */
37-
38-
while (count--)
39-
*xs++ = c;
40-
return s;
25+
return lkl_ops->memset(s, c, count);
4126
}
27+
#define memset(s, c, n) __memset(s, c, n)
28+
#endif
4229

30+
#ifdef CONFIG_LKL_HOST_MEMSET
4331
#define __HAVE_ARCH_MEMMOVE
4432
extern void *memmove(void *dest, const void *src, size_t count);
4533
static inline void *__memmove(void *dest, const void *src, size_t count)
4634
{
47-
char *tmp;
48-
const char *s;
49-
50-
if (lkl_ops->memmove)
51-
return lkl_ops->memmove(dest, src, count);
52-
53-
/* from lib/string.c */
54-
55-
if (dest <= src) {
56-
tmp = dest;
57-
s = src;
58-
while (count--)
59-
*tmp++ = *s++;
60-
} else {
61-
tmp = dest;
62-
tmp += count;
63-
s = src;
64-
s += count;
65-
while (count--)
66-
*--tmp = *--s;
67-
}
68-
return dest;
35+
return lkl_ops->memmove(dest, src, count);
6936
}
70-
71-
#define memcpy(dst, src, len) __memcpy(dst, src, len)
72-
#define memset(s, c, n) __memset(s, c, n)
7337
#define memmove(dst, src, len) __memmove(dst, src, len)
38+
#endif
7439

7540
#if defined(CONFIG_KASAN)
7641

arch/lkl/lib/string.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@
1414
#undef memset
1515
#undef memmove
1616

17+
#ifdef __HAVE_ARCH_MEMCPY
1718
__visible void *memcpy(void *dest, const void *src, size_t count)
1819
{
1920
return __memcpy(dest, src, count);
2021
}
2122
EXPORT_SYMBOL(memcpy);
23+
#endif
2224

25+
#ifdef __HAVE_ARCH_MEMSET
2326
__visible void *memset(void *s, int c, size_t count)
2427
{
2528
return __memset(s, c, count);
2629
}
2730
EXPORT_SYMBOL(memset);
31+
#endif
2832

33+
#ifdef __HAVE_ARCH_MEMMOVE
2934
__visible void *memmove(void *dest, const void *src, size_t count)
3035
{
3136
return __memmove(dest, src, count);
3237
}
3338
EXPORT_SYMBOL(memmove);
39+
#endif
3440

3541
#endif

tools/lkl/Makefile.autoconf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ define posix_host
8989
$(if $(filter $(1),elf32-i386),$(call set_autoconf_var,I386,y))
9090
$(if $(strip $(call find_include,jsmn.h)),$(call set_autoconf_var,JSMN,y))
9191
$(if $(filter %,$(zpoline)),$(call zpoline_conf,$(zpoline)))
92+
$(call set_kernel_config,LKL_HOST_MEMCPY,y)
93+
$(call set_kernel_config,LKL_HOST_MEMSET,y)
94+
$(call set_kernel_config,LKL_HOST_MEMMOVE,y)
9295
endef
9396

9497
define nt64_host

0 commit comments

Comments
 (0)