mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] c23 memset_explicit()
@ 2024-03-19 11:18 Aaron Peter Bachmann
  2024-03-19 13:50 ` Jₑₙₛ Gustedt
  0 siblings, 1 reply; 8+ messages in thread
From: Aaron Peter Bachmann @ 2024-03-19 11:18 UTC (permalink / raw)
  To: musl

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;
+}


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-03-20  7:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-19 11:18 [musl] c23 memset_explicit() Aaron Peter Bachmann
2024-03-19 13:50 ` Jₑₙₛ Gustedt
2024-03-19 14:02   ` Rich Felker
2024-03-19 14:24     ` Jₑₙₛ Gustedt
2024-03-19 15:51     ` Aaron Peter Bachmann
2024-03-19 16:19       ` Rich Felker
2024-03-20  7:42         ` [musl] Re: Potential bug in __res_msend_rc() wrt to union, initialization Aaron Peter Bachmann
2024-03-19 16:37     ` [musl] c23 memset_explicit() NRK

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).