From dd62b2b10671c2b141ef75b848467d8351b5bfee Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 5 Jan 2022 12:06:34 -0500 Subject: [PATCH] =?UTF-8?q?[kservice]=20=E5=A2=9E=E5=8A=A0RT=5FKSERVICE=5F?= =?UTF-8?q?USING=5FSTDLIB=5FMEMSET=20RT=5FKSERVICE=5FUSING=5FSTDLIB=5FMEMC?= =?UTF-8?q?PY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtthread.h | 10 ++++++++++ src/Kconfig | 10 ++++++++++ src/kservice.c | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/include/rtthread.h b/include/rtthread.h index 4d4c93fd5e..45a7655be9 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -596,8 +596,12 @@ int *_rt_errno(void); int __rt_ffs(int value); +#ifndef RT_KSERVICE_USING_STDLIB_MEMSET void *rt_memset(void *src, int c, rt_ubase_t n); +#endif /* RT_KSERVICE_USING_STDLIB_MEMSET */ +#ifndef RT_KSERVICE_USING_STDLIB_MEMCPY void *rt_memcpy(void *dest, const void *src, rt_ubase_t n); +#endif /* RT_KSERVICE_USING_STDLIB_MEMCPY */ char *rt_strdup(const char *s); #ifndef RT_KSERVICE_USING_STDLIB @@ -612,6 +616,12 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct); rt_size_t rt_strlen(const char *src); #else #include +#ifdef RT_KSERVICE_USING_STDLIB_MEMSET +#define rt_memset(s, c, count) memset(s, c, count) +#endif /* RT_KSERVICE_USING_STDLIB_MEMSET */ +#ifdef RT_KSERVICE_USING_STDLIB_MEMCPY +#define rt_memcpy(dst, src, count) memcpy(dst, src, count) +#endif /* RT_KSERVICE_USING_STDLIB_MEMCPY */ #define rt_memmove(dest, src, n) memmove(dest, src, n) #define rt_memcmp(cs, ct, count) memcmp(cs, ct, count) #define rt_strstr(str1, str2) strstr(str1, str2) diff --git a/src/Kconfig b/src/Kconfig index dda7f08032..69edd20641 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -135,6 +135,16 @@ menu "kservice optimization" bool "Enable kservice to use standard C library" default n + if RT_KSERVICE_USING_STDLIB + config RT_KSERVICE_USING_STDLIB_MEMCPY + bool "Use memcpy to replace rt_memcpy (faster, but not safe)" + default n + + config RT_KSERVICE_USING_STDLIB_MEMSET + bool "Use memset to replace rt_memset (faster, but not safe)" + default n + endif + config RT_KSERVICE_USING_TINY_SIZE bool "Enable kservice to use tiny size" default n diff --git a/src/kservice.c b/src/kservice.c index ca4fb9c088..459109ce75 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -116,6 +116,7 @@ int *_rt_errno(void) } RTM_EXPORT(_rt_errno); +#ifndef RT_KSERVICE_USING_STDLIB_MEMSET /** * This function will set the content of memory to specified value. * @@ -201,7 +202,9 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count) #endif /* RT_KSERVICE_USING_TINY_SIZE */ } RTM_EXPORT(rt_memset); +#endif /* RT_KSERVICE_USING_STDLIB_MEMSET */ +#ifndef RT_KSERVICE_USING_STDLIB_MEMCPY /** * This function will copy memory content from source address to destination address. * @@ -285,6 +288,7 @@ RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count) #endif /* RT_KSERVICE_USING_TINY_SIZE */ } RTM_EXPORT(rt_memcpy); +#endif /* RT_KSERVICE_USING_STDLIB_MEMCPY */ #ifndef RT_KSERVICE_USING_STDLIB