memory-util: move memzero() to src/fundamental/ to share with UEFI

(and while we are at it, make sure it returns the input pointer as
output)
This commit is contained in:
Lennart Poettering
2023-10-02 15:00:13 +02:00
parent 1e5e902f60
commit 4ac79c2b77
5 changed files with 13 additions and 11 deletions
-7
View 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);
+3 -2
View 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),
+2 -1
View 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;
}
}
+2 -1
View 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)
@@ -11,6 +11,12 @@
#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)