Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Tue, 19 Mar 2024 12:18:20 +0100
From: Aaron Peter Bachmann <aaron_ng@...de.at>
To: musl@...ts.openwall.com
Subject: c23 memset_explicit()

I recognized neither
https://git.musl-libc.org/cgit/musl
nor
https://forge.icube.unistra.fr/icps/musl/-/branches
seem to include c23 memset_explicit().
Or it slipped my attention.

So I provide a patch. It compiles but is otherwise untested.
It is trivial enough that you would spot an error when merging.
No guards for c23 as mem is a reserved prefix.
It closely follows explicit_bzero.c. So I assume it fits into the coding 
style musl uses.

Regards, Aaron Peter Bachmann


diff --git a/include/string.h b/include/string.h
index 83e2b946..563b3b0a 100644
--- a/include/string.h
+++ b/include/string.h
@@ -27,6 +27,7 @@ extern "C" {
  void *memcpy (void *__restrict, const void *__restrict, size_t);
  void *memmove (void *, const void *, size_t);
  void *memset (void *, int, size_t);
+void *memset_explicit(void *, int, size_t);
  int memcmp (const void *, const void *, size_t);
  void *memchr (const void *, int, size_t);

diff --git a/src/string/memset_explicit.c b/src/string/memset_explicit.c
new file mode 100644
index 00000000..ac54f0cf
--- /dev/null
+++ b/src/string/memset_explicit.c
@@ -0,0 +1,8 @@
+#include <string.h>
+
+void *memset_explicit(void *d, int c, size_t n)
+{
+       d = memset(d, c, n);
+       __asm__ __volatile__ ("" : : "r"(d) : "memory");
+       return d;
+}

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.