mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Aaron Peter Bachmann <aaron_ng@inode.at>
To: musl@lists.openwall.com
Subject: [musl] c23 memset_explicit()
Date: Tue, 19 Mar 2024 12:18:20 +0100	[thread overview]
Message-ID: <1ad1a194-f2f5-4ae1-9686-67961086e605@inode.at> (raw)

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


             reply	other threads:[~2024-03-19 12:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 11:18 Aaron Peter Bachmann [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1ad1a194-f2f5-4ae1-9686-67961086e605@inode.at \
    --to=aaron_ng@inode.at \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).