From 32ea741bd1d6cb1f2cfbc4e56d2ffd75850cbed1 Mon Sep 17 00:00:00 2001 From: Daniel Grumberg Date: Sun, 25 Oct 2020 09:46:21 +0000 Subject: [PATCH] Add fast-path for memset, memcpy, and memmove The additional "calls" to __klee_handle_mem* are intercepted by the klee SpecialFunctionHandler and implement the intended functionality directly in concrete cases. --- libc/string/memcpy.c | 6 ++++++ libc/string/memmove.c | 5 +++++ libc/string/memset.c | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/libc/string/memcpy.c b/libc/string/memcpy.c index dc2986778..40f17437e 100644 --- a/libc/string/memcpy.c +++ b/libc/string/memcpy.c @@ -15,8 +15,14 @@ libc_hidden_proto(Wmemcpy) +char __klee_handle_memcpy(void *, const void *, size_t); + Wvoid *Wmemcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n) { + + if (__klee_handle_memcpy(s1, s2, n)) + return s1; + register Wchar *r1 = s1; register const Wchar *r2 = s2; diff --git a/libc/string/memmove.c b/libc/string/memmove.c index 3cdcca116..27c175297 100644 --- a/libc/string/memmove.c +++ b/libc/string/memmove.c @@ -14,8 +14,13 @@ libc_hidden_proto(memmove) # define Wmemmove memmove #endif +char __klee_handle_memmove(void *, const void *, size_t); + Wvoid *Wmemmove(Wvoid *s1, const Wvoid *s2, size_t n) { + if(__klee_handle_memmove(s1, s2, n)) + return s1; + #ifdef __BCC__ register Wchar *s = (Wchar *) s1; register const Wchar *p = (const Wchar *) s2; diff --git a/libc/string/memset.c b/libc/string/memset.c index 2f3fc271d..54efaf1b6 100644 --- a/libc/string/memset.c +++ b/libc/string/memset.c @@ -14,8 +14,13 @@ libc_hidden_proto(memset) # define Wmemset memset #endif +char __klee_handle_memset(void *, int, size_t); + Wvoid *Wmemset(Wvoid *s, Wint c, size_t n) { + if (__klee_handle_memset(s, c, n)) + return s; + register Wuchar *p = (Wuchar *) s; #ifdef __BCC__ /* bcc can optimize the counter if it thinks it is a pointer... */