From 1c78d18acb20c5f4b47af7e9daec2bbc74826dc7 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 27 Aug 2021 17:46:25 +0100 Subject: [PATCH] sclog: wrap memmove. I had a testsc run fail because of alignment-dependent control flow divergence in a glibc function with 'memmove' in the name, which appears to have been an accident of different memory allocation between two runs of the test in question. sclog was already giving special handling to memset for the same reason, so it's no trouble to add memmove to the same list of functions that are treated as an opaque primitive for logging purposes. --- test/sclog/sclog.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/sclog/sclog.c b/test/sclog/sclog.c index 2d2adbf4..f12a0280 100644 --- a/test/sclog/sclog.c +++ b/test/sclog/sclog.c @@ -269,6 +269,38 @@ static void wrap_memset_pre(void *wrapctx, void **user_data) } } +/* + * Similarly to the above, wrap some versions of memmove. + */ +static void wrap_memmove_pre(void *wrapctx, void **user_data) +{ + uint was_already_paused = logging_paused++; + + if (outfile == INVALID_FILE || was_already_paused) + return; + + const void *daddr = drwrap_get_arg(wrapctx, 0); + const void *saddr = drwrap_get_arg(wrapctx, 1); + size_t size = (size_t)drwrap_get_arg(wrapctx, 2); + + + struct allocation *alloc; + + dr_fprintf(outfile, "memmove %"PRIuMAX" ", (uintmax_t)size); + if (!(alloc = find_allocation(daddr))) { + dr_fprintf(outfile, "to %"PRIxMAX" ", (uintmax_t)daddr); + } else { + dr_fprintf(outfile, "to allocations[%"PRIuPTR"] + %"PRIxMAX" ", + alloc->index, (uintmax_t)(daddr - alloc->start)); + } + if (!(alloc = find_allocation(saddr))) { + dr_fprintf(outfile, "from %"PRIxMAX"\n", (uintmax_t)saddr); + } else { + dr_fprintf(outfile, "from allocations[%"PRIuPTR"] + %"PRIxMAX"\n", + alloc->index, (uintmax_t)(saddr - alloc->start)); + } +} + /* * Common post-wrapper function for memset and free, whose entire * function is to unpause the logging. @@ -565,6 +597,7 @@ static void load_module( TRY_WRAP("realloc", wrap_realloc_pre, wrap_alloc_post); TRY_WRAP("free", wrap_free_pre, unpause_post); TRY_WRAP("memset", wrap_memset_pre, unpause_post); + TRY_WRAP("memmove", wrap_memmove_pre, unpause_post); /* * More strangely named versions of standard C library @@ -585,6 +618,8 @@ static void load_module( TRY_WRAP("__GI___libc_free", wrap_free_pre, unpause_post); TRY_WRAP("__memset_sse2_unaligned", wrap_memset_pre, unpause_post); TRY_WRAP("__memset_sse2", wrap_memset_pre, unpause_post); + TRY_WRAP("__memmove_avx_unaligned_erms", wrap_memmove_pre, + unpause_post); TRY_WRAP("cfree", wrap_free_pre, unpause_post); } }