]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
memory-util: move memzero() to src/fundamental/ to share with UEFI
authorLennart Poettering <lennart@poettering.net>
Mon, 2 Oct 2023 11:06:27 +0000 (13:06 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 2 Oct 2023 13:00:13 +0000 (15:00 +0200)
(and while we are at it, make sure it returns the input pointer as
output)

src/basic/memory-util.h
src/boot/efi/measure.c
src/boot/efi/stub.c
src/boot/efi/util.c
src/fundamental/memory-util-fundamental.h

index d26a0918e1adfe0dc2593d1f910ea1da9b8a3443..c350dc1e54b22e0957a23388aad11145c4e1d31f 100644 (file)
@@ -47,13 +47,6 @@ static inline int memcmp_nn(const void *s1, size_t n1, const void *s2, size_t n2
             ?: CMP(n1, n2);
 }
 
-#define memzero(x,l)                                            \
-        ({                                                      \
-                size_t _l_ = (l);                               \
-                if (_l_ > 0)                                    \
-                        memset(x, 0, _l_);                      \
-        })
-
 #define zero(x) (memzero(&(x), sizeof(x)))
 
 bool memeqbyte(uint8_t byte, const void *data, size_t length);
index 677fe640153f55392ba699cd472c86b7e62cb673..6f7282dc7db7ec731fa4baf7fed1a3207132ac48 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "macro-fundamental.h"
 #include "measure.h"
+#include "memory-util-fundamental.h"
 #include "proto/tcg.h"
 #include "tpm2-pcr.h"
 #include "util.h"
@@ -25,7 +26,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log(
 
         desc_len = strsize16(description);
         tcg_event = xmalloc(offsetof(TCG_PCR_EVENT, Event) + desc_len);
-        memset(tcg_event, 0, offsetof(TCG_PCR_EVENT, Event) + desc_len);
+        memzero(tcg_event, offsetof(TCG_PCR_EVENT, Event) + desc_len);
         *tcg_event = (TCG_PCR_EVENT) {
                 .EventSize = desc_len,
                 .PCRIndex = pcrindex,
@@ -63,7 +64,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log(
 
         desc_len = strsize16(description);
         tcg_event = xmalloc(offsetof(EFI_TCG2_EVENT, Event) + desc_len);
-        memset(tcg_event, 0, offsetof(EFI_TCG2_EVENT, Event) + desc_len);
+        memzero(tcg_event, offsetof(EFI_TCG2_EVENT, Event) + desc_len);
         *tcg_event = (EFI_TCG2_EVENT) {
                 .Size = offsetof(EFI_TCG2_EVENT, Event) + desc_len,
                 .Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER),
index 493e7ed4c2ebb9fa6c717fb9379f8dc1cb09bd55..3e133031630cbed36d8ba1714e0ef7d935873fd5 100644 (file)
@@ -6,6 +6,7 @@
 #include "graphics.h"
 #include "linux.h"
 #include "measure.h"
+#include "memory-util-fundamental.h"
 #include "part-discovery.h"
 #include "pe.h"
 #include "proto/shell-parameters.h"
@@ -64,7 +65,7 @@ static EFI_STATUS combine_initrd(
 
                 pad = ALIGN4(initrd_size) - initrd_size;
                 if (pad > 0)  {
-                        memset(p, 0, pad);
+                        memzero(p, pad);
                         p += pad;
                 }
         }
index 685715f36e737e1a00da67c5506ee292a51ff9be..60991d471821a350b85b81d9bd509bdfa52204ee 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include "device-path-util.h"
+#include "memory-util-fundamental.h"
 #include "proto/device-path.h"
 #include "proto/simple-text-io.h"
 #include "ticks.h"
@@ -373,7 +374,7 @@ EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, size_t off, size_t siz
                 return err;
 
         /* Note that chunked_read() changes size to reflect the actual bytes read. */
-        memset(buf + size, 0, extra);
+        memzero(buf + size, extra);
 
         *ret = TAKE_PTR(buf);
         if (ret_size)
index 78e2dbec5985f0ca7d715e533ab3412c407ec8db..1ffacff21a9422145051f89acb11a478b6262f06 100644 (file)
 
 #include "macro-fundamental.h"
 
+#define memzero(x, l)                                           \
+        ({                                                      \
+                size_t _l_ = (l);                               \
+                _l_ > 0 ? memset((x), 0, _l_) : (x);            \
+        })
+
 #if !SD_BOOT && HAVE_EXPLICIT_BZERO
 static inline void *explicit_bzero_safe(void *p, size_t l) {
         if (p && l > 0)