summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2016-10-18 14:41:22 -0700
committerRandall Spangler <rspangler@chromium.org>2016-11-06 02:33:50 +0000
commit559a110f33b7ebe8d950f1c2de6b3b89791f862b (patch)
tree7853ac7a1f8a47cc981613e632f55cdc7dc33974
parent47eeaa6e4a03d2689c9b1b46fc9b0b0b04ace3a6 (diff)
downloadvboot-559a110f33b7ebe8d950f1c2de6b3b89791f862b.tar.gz
vboot: use malloc and free directly
Originally, vboot1 code used VbExMalloc() and VbExFree() since it needed to talk to EFI firmware that didn't have standard malloc() and free(). Now, coreboot and depthcharge implement them as wrappers around those standard calls. vboot2 code already calls them directly, so let vboot1 code do that too. BUG=chromium:611535 BRANCH=none TEST=make runtests; emerge-kevin coreboot depthcharge Change-Id: I49ad0e32e38d278dc3589bfaf494bcf0e4b0a4bd Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/400905
-rw-r--r--Makefile9
-rw-r--r--cgpt/cgpt_add.c2
-rw-r--r--firmware/include/gbb_access.h6
-rw-r--r--firmware/include/vboot_api.h18
-rw-r--r--firmware/lib/gpt_misc.c16
-rw-r--r--firmware/lib/include/utility.h6
-rw-r--r--firmware/lib/region-fw.c4
-rw-r--r--firmware/lib/region-kernel.c16
-rw-r--r--firmware/lib/vboot_api_kernel.c14
-rw-r--r--firmware/lib/vboot_audio.c4
-rw-r--r--firmware/lib/vboot_display.c6
-rw-r--r--firmware/lib/vboot_kernel.c10
-rw-r--r--firmware/stub/tpm_lite_stub.c1
-rw-r--r--firmware/stub/vboot_api_stub.c2
-rw-r--r--firmware/stub/vboot_api_stub_disk.c5
-rw-r--r--firmware/stub/vboot_api_stub_init.c4
-rw-r--r--firmware/stub/vboot_api_stub_region.c3
-rw-r--r--firmware/stub/vboot_api_stub_sf.c142
-rw-r--r--firmware/stub/vboot_api_stub_static_sf.c39
-rw-r--r--firmware/stub/vboot_api_stub_stream.c6
-rw-r--r--host/lib/include/host_common.h6
-rw-r--r--tests/cgptlib_test.c1
-rw-r--r--tests/rollback_index2_tests.c2
-rw-r--r--tests/rollback_index3_tests.c2
-rw-r--r--tests/test_common.h3
-rw-r--r--tests/vb20_rsa_padding_tests.c3
-rw-r--r--tests/vb2_rsa_utility_tests.c2
-rw-r--r--tests/vboot_api_devmode_tests.c13
-rw-r--r--tests/vboot_api_kernel2_tests.c3
-rw-r--r--tests/vboot_api_kernel3_tests.c3
-rw-r--r--tests/vboot_api_kernel4_tests.c3
-rw-r--r--tests/vboot_api_kernel5_tests.c3
-rw-r--r--tests/vboot_api_kernel6_tests.c3
-rw-r--r--tests/vboot_api_kernel_tests.c3
-rw-r--r--tests/vboot_audio_tests.c13
-rw-r--r--tests/vboot_common_tests.c3
-rw-r--r--tests/vboot_display_tests.c7
-rw-r--r--tests/vboot_kernel_tests.c3
-rw-r--r--tests/vboot_nvstorage_test.c12
-rw-r--r--tests/vboot_region_tests.c12
-rw-r--r--utility/verify_data.c2
41 files changed, 56 insertions, 359 deletions
diff --git a/Makefile b/Makefile
index 157ef139..01dd2035 100644
--- a/Makefile
+++ b/Makefile
@@ -410,9 +410,6 @@ VBINIT_SRCS += \
firmware/stub/vboot_api_stub_init.c \
firmware/stub/vboot_api_stub_region.c
-VBSF_SRCS += \
- firmware/stub/vboot_api_stub_sf.c
-
VBSLK_SRCS += \
firmware/stub/vboot_api_stub.c \
firmware/stub/vboot_api_stub_disk.c \
@@ -503,7 +500,6 @@ HOSTLIB_SRCS = \
firmware/stub/vboot_api_stub.c \
firmware/stub/vboot_api_stub_disk.c \
firmware/stub/vboot_api_stub_init.c \
- firmware/stub/vboot_api_stub_sf.c \
futility/dump_kernel_config_lib.c \
host/arch/${ARCH}/lib/crossystem_arch.c \
host/lib/crossystem.c \
@@ -532,7 +528,6 @@ TINYHOSTLIB_SRCS = \
firmware/lib/utility_string.c \
firmware/stub/vboot_api_stub.c \
firmware/stub/vboot_api_stub_disk.c \
- firmware/stub/vboot_api_stub_sf.c \
futility/dump_kernel_config_lib.c \
host/lib/extract_vmlinuz.c
@@ -690,11 +685,7 @@ FUTIL_SRCS = \
FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
-# Workaround for TODO(crbug.com/437107).
-FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
-
FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
- ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
${FUTIL_STATIC_CMD_LIST:%.c=%.o}
FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c
index 3808255a..4e0506e9 100644
--- a/cgpt/cgpt_add.c
+++ b/cgpt/cgpt_add.c
@@ -4,8 +4,6 @@
#include <string.h>
-#define _STUB_IMPLEMENTATION_
-
#include "cgpt.h"
#include "cgpt_params.h"
#include "cgptlib_internal.h"
diff --git a/firmware/include/gbb_access.h b/firmware/include/gbb_access.h
index b94d0cdb..965f7fac 100644
--- a/firmware/include/gbb_access.h
+++ b/firmware/include/gbb_access.h
@@ -32,7 +32,7 @@ VbError_t VbGbbReadHeader_static(VbCommonParams *cparams,
*
* @param cparams Vboot common parameters
* @param keyp Returns a pointer to the key. The caller must call
- * VbExFree() on the key when finished with it.
+ * free() on the key when finished with it.
* @return VBERROR_... error, VBERROR_SUCCESS on success,
*/
VbError_t VbGbbReadRootKey(VbCommonParams *cparams,
@@ -43,7 +43,7 @@ VbError_t VbGbbReadRootKey(VbCommonParams *cparams,
*
* @param cparams Vboot common parameters
* @param keyp Returns a pointer to the key. The caller must call
- * VbExFree() on the key when finished with it.
+ * free() on the key when finished with it.
* @return VBERROR_... error, VBERROR_SUCCESS on success,
*/
VbError_t VbGbbReadRecoveryKey(VbCommonParams *cparams,
@@ -62,7 +62,7 @@ VbError_t VbGbbReadBmpHeader(VbCommonParams *cparams,
/**
* Read a image from the GBB
*
- * The caller must call VbExFree() on *image_datap when finished with it.
+ * The caller must call free() on *image_datap when finished with it.
*
* @param cparams Vboot common parameters
* @param localization Localization/language number
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index 75b20f38..a6121e92 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -388,24 +388,6 @@ void VbExDebug(const char *format, ...)
__attribute__ ((format (__printf__, 1, 2)));
/*****************************************************************************/
-/* Memory (from utility.h) */
-
-/**
- * Allocate [size] bytes and return a pointer to the allocated memory. Abort
- * on error; this always either returns a good pointer or never returns.
- *
- * If any of the firmware API implementations require aligned data (for
- * example, disk access on ARM), all pointers returned by VbExMalloc() must
- * also be aligned.
- */
-void *VbExMalloc(size_t size);
-
-/**
- * Free memory pointed to by [ptr] previously allocated by VbExMalloc().
- */
-void VbExFree(void *ptr);
-
-/*****************************************************************************/
/* Timer and delay (first two from utility.h) */
/**
diff --git a/firmware/lib/gpt_misc.c b/firmware/lib/gpt_misc.c
index d843b21e..3b079444 100644
--- a/firmware/lib/gpt_misc.c
+++ b/firmware/lib/gpt_misc.c
@@ -32,11 +32,11 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
gptdata->ignored = 0;
/* Allocate all buffers */
- gptdata->primary_header = (uint8_t *)VbExMalloc(gptdata->sector_bytes);
+ gptdata->primary_header = (uint8_t *)malloc(gptdata->sector_bytes);
gptdata->secondary_header =
- (uint8_t *)VbExMalloc(gptdata->sector_bytes);
- gptdata->primary_entries = (uint8_t *)VbExMalloc(max_entries_bytes);
- gptdata->secondary_entries = (uint8_t *)VbExMalloc(max_entries_bytes);
+ (uint8_t *)malloc(gptdata->sector_bytes);
+ gptdata->primary_entries = (uint8_t *)malloc(max_entries_bytes);
+ gptdata->secondary_entries = (uint8_t *)malloc(max_entries_bytes);
if (gptdata->primary_header == NULL ||
gptdata->secondary_header == NULL ||
@@ -204,13 +204,13 @@ int WriteAndFreeGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
fail:
/* Avoid leaking memory on disk write failure */
if (gptdata->primary_header)
- VbExFree(gptdata->primary_header);
+ free(gptdata->primary_header);
if (gptdata->primary_entries)
- VbExFree(gptdata->primary_entries);
+ free(gptdata->primary_entries);
if (gptdata->secondary_entries)
- VbExFree(gptdata->secondary_entries);
+ free(gptdata->secondary_entries);
if (gptdata->secondary_header)
- VbExFree(gptdata->secondary_header);
+ free(gptdata->secondary_header);
/* Success */
return ret;
diff --git a/firmware/lib/include/utility.h b/firmware/lib/include/utility.h
index 9f191701..589685b1 100644
--- a/firmware/lib/include/utility.h
+++ b/firmware/lib/include/utility.h
@@ -69,10 +69,4 @@ uint32_t Uint64ToString(char *buf, uint32_t bufsize, uint64_t value,
*/
uint32_t StrnAppend(char *dest, const char *src, uint32_t destlen);
-/* Ensure that only our stub implementations are used, not standard C */
-#ifndef _STUB_IMPLEMENTATION_
-#define malloc _do_not_use_standard_malloc
-#define free _do_not_use_standard_free
-#endif
-
#endif /* VBOOT_REFERENCE_UTILITY_H_ */
diff --git a/firmware/lib/region-fw.c b/firmware/lib/region-fw.c
index e2c6488a..2bc1a690 100644
--- a/firmware/lib/region-fw.c
+++ b/firmware/lib/region-fw.c
@@ -33,10 +33,10 @@ static VbError_t VbGbbReadKey(VbCommonParams *cparams, uint32_t offset,
size = hdr.key_offset + hdr.key_size;
if (size < sizeof(hdr))
size = sizeof(hdr);
- key = VbExMalloc(size);
+ key = malloc(size);
ret = VbRegionReadData(cparams, VB_REGION_GBB, offset, size, key);
if (ret) {
- VbExFree(key);
+ free(key);
return ret;
}
diff --git a/firmware/lib/region-kernel.c b/firmware/lib/region-kernel.c
index c87db427..96d9cb6f 100644
--- a/firmware/lib/region-kernel.c
+++ b/firmware/lib/region-kernel.c
@@ -36,11 +36,11 @@ VbError_t VbGbbReadBmpHeader(VbCommonParams *cparams, BmpBlockHeader *hdr_ret)
if (0 == gbb->bmpfv_size)
return VBERROR_INVALID_GBB;
- hdr = VbExMalloc(sizeof(*hdr));
+ hdr = malloc(sizeof(*hdr));
ret = VbRegionReadGbb(cparams, gbb->bmpfv_offset,
sizeof(BmpBlockHeader), hdr);
if (ret) {
- VbExFree(hdr);
+ free(hdr);
return ret;
}
@@ -52,7 +52,7 @@ VbError_t VbGbbReadBmpHeader(VbCommonParams *cparams, BmpBlockHeader *hdr_ret)
(hdr->minor_version > BMPBLOCK_MINOR_VERSION))) {
VBDEBUG(("VbGbbReadBmpHeader(): "
"invalid/too new bitmap header\n"));
- VbExFree(hdr);
+ free(hdr);
return VBERROR_INVALID_BMPFV;
}
cparams->bmp = hdr;
@@ -136,26 +136,26 @@ VbError_t VbGbbReadImage(VbCommonParams *cparams,
if (data_size) {
void *orig_data;
- data = VbExMalloc(image_info->compressed_size);
+ data = malloc(image_info->compressed_size);
ret = VbRegionReadGbb(cparams, data_offset,
image_info->compressed_size, data);
if (ret) {
- VbExFree(data);
+ free(data);
return ret;
}
if (image_info->compression != COMPRESS_NONE) {
uint32_t inoutsize = image_info->original_size;
- orig_data = VbExMalloc(image_info->original_size);
+ orig_data = malloc(image_info->original_size);
ret = VbExDecompress(data,
image_info->compressed_size,
image_info->compression,
orig_data, &inoutsize);
data_size = inoutsize;
- VbExFree(data);
+ free(data);
data = orig_data;
if (ret) {
- VbExFree(data);
+ free(data);
return ret;
}
}
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index 53f8b0ed..f264fb7f 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -1060,11 +1060,11 @@ void VbApiKernelFree(VbCommonParams *cparams)
{
/* VbSelectAndLoadKernel() always allocates this, tests don't */
if (cparams->gbb) {
- VbExFree(cparams->gbb);
+ free(cparams->gbb);
cparams->gbb = NULL;
}
if (cparams->bmp) {
- VbExFree(cparams->bmp);
+ free(cparams->bmp);
cparams->bmp = NULL;
}
}
@@ -1110,7 +1110,7 @@ VbError_t VbSelectAndLoadKernel(VbCommonParams *cparams,
memset(kparams->partition_guid, 0, sizeof(kparams->partition_guid));
cparams->bmp = NULL;
- cparams->gbb = VbExMalloc(sizeof(*cparams->gbb));
+ cparams->gbb = malloc(sizeof(*cparams->gbb));
retval = VbGbbReadHeader_static(cparams, cparams->gbb);
if (VBERROR_SUCCESS != retval)
goto VbSelectAndLoadKernel_exit;
@@ -1360,7 +1360,7 @@ VbError_t VbVerifyMemoryBootImage(VbCommonParams *cparams,
/* Read GBB Header */
cparams->bmp = NULL;
- cparams->gbb = VbExMalloc(sizeof(*cparams->gbb));
+ cparams->gbb = malloc(sizeof(*cparams->gbb));
retval = VbGbbReadHeader_static(cparams, cparams->gbb);
if (VBERROR_SUCCESS != retval) {
VBDEBUG(("Gbb read header failed.\n"));
@@ -1403,7 +1403,7 @@ VbError_t VbVerifyMemoryBootImage(VbCommonParams *cparams,
retval = VBERROR_INVALID_KERNEL_FOUND;
/* Allocate work buffer */
- workbuf = (uint8_t *)VbExMalloc(VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE);
+ workbuf = (uint8_t *)malloc(VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE);
if (!workbuf)
goto fail;
vb2_workbuf_init(&wb, workbuf, VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE);
@@ -1502,9 +1502,9 @@ VbError_t VbVerifyMemoryBootImage(VbCommonParams *cparams,
fail:
VbApiKernelFree(cparams);
if (NULL != kernel_subkey)
- VbExFree(kernel_subkey);
+ free(kernel_subkey);
if (NULL != workbuf)
- VbExFree(workbuf);
+ free(workbuf);
return retval;
}
diff --git a/firmware/lib/vboot_audio.c b/firmware/lib/vboot_audio.c
index bc974953..8f311710 100644
--- a/firmware/lib/vboot_audio.c
+++ b/firmware/lib/vboot_audio.c
@@ -170,7 +170,7 @@ static void VbGetDevMusicNotes(VbAudioContext *audio, int use_short)
}
/* Looks good. Allocate the space (plus one) and copy it over. */
- notebuf = VbExMalloc((hdr->count + 1) * sizeof(VbDevMusicNote));
+ notebuf = malloc((hdr->count + 1) * sizeof(VbDevMusicNote));
memcpy(notebuf, hdr->notes, hdr->count * sizeof(VbDevMusicNote));
count = hdr->count;
@@ -296,5 +296,5 @@ void VbAudioClose(VbAudioContext *audio)
{
VbExBeep(0,0);
if (audio->free_notes_when_done)
- VbExFree(audio->music_notes);
+ free(audio->music_notes);
}
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index 2f3a15e1..adbeaa9f 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -298,7 +298,7 @@ VbError_t VbDisplayScreenFromGBB(VbCommonParams *cparams, uint32_t screen,
retval = VBERROR_INVALID_GBB;
}
- VbExFree(fullimage);
+ free(fullimage);
if (VBERROR_SUCCESS != retval)
goto VbDisplayScreenFromGBB_exit;
@@ -645,7 +645,7 @@ VbError_t VbDisplayDebugInfo(VbCommonParams *cparams, VbNvContext *vncptr)
ret = VbGbbReadRootKey(cparams, &key);
if (!ret) {
FillInSha1Sum(sha1sum, key);
- VbExFree(key);
+ free(key);
used += StrnAppend(buf + used, "\ngbb.rootkey: ",
DEBUG_INFO_SIZE - used);
used += StrnAppend(buf + used, sha1sum,
@@ -655,7 +655,7 @@ VbError_t VbDisplayDebugInfo(VbCommonParams *cparams, VbNvContext *vncptr)
ret = VbGbbReadRecoveryKey(cparams, &key);
if (!ret) {
FillInSha1Sum(sha1sum, key);
- VbExFree(key);
+ free(key);
used += StrnAppend(buf + used, "\ngbb.recovery_key: ",
DEBUG_INFO_SIZE - used);
used += StrnAppend(buf + used, sha1sum,
diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c
index 4e0d3e48..65792e92 100644
--- a/firmware/lib/vboot_kernel.c
+++ b/firmware/lib/vboot_kernel.c
@@ -147,12 +147,12 @@ VbError_t LoadKernel(LoadKernelParams *params, VbCommonParams *cparams)
}
/* Allocate kernel header buffers */
- kbuf = (uint8_t *)VbExMalloc(KBUF_SIZE);
+ kbuf = (uint8_t *)malloc(KBUF_SIZE);
if (!kbuf)
goto bad_gpt;
/* Allocate work buffer */
- workbuf = (uint8_t *)VbExMalloc(VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE);
+ workbuf = (uint8_t *)malloc(VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE);
if (!workbuf)
goto bad_gpt;
vb2_workbuf_init(&wb, workbuf, VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE);
@@ -558,9 +558,9 @@ bad_kernel:
bad_gpt:
/* Free buffers */
if (workbuf)
- VbExFree(workbuf);
+ free(workbuf);
if (kbuf)
- VbExFree(kbuf);
+ free(kbuf);
/* Write and free GPT data */
WriteAndFreeGptData(params->disk_handle, &gpt);
@@ -613,7 +613,7 @@ LoadKernelExit:
params->shared_data_size = shared->data_used;
if (free_kernel_subkey)
- VbExFree(kernel_subkey);
+ free(kernel_subkey);
return retval;
}
diff --git a/firmware/stub/tpm_lite_stub.c b/firmware/stub/tpm_lite_stub.c
index 4d88d169..c6996df3 100644
--- a/firmware/stub/tpm_lite_stub.c
+++ b/firmware/stub/tpm_lite_stub.c
@@ -8,7 +8,6 @@
#include <stdint.h>
-#define _STUB_IMPLEMENTATION_
#include "tlcl.h"
#include "tlcl_internal.h"
#include "utility.h"
diff --git a/firmware/stub/vboot_api_stub.c b/firmware/stub/vboot_api_stub.c
index 7bc4cb86..717c0f8d 100644
--- a/firmware/stub/vboot_api_stub.c
+++ b/firmware/stub/vboot_api_stub.c
@@ -7,8 +7,6 @@
#include <stdint.h>
-#define _STUB_IMPLEMENTATION_
-
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/firmware/stub/vboot_api_stub_disk.c b/firmware/stub/vboot_api_stub_disk.c
index a7570c3b..e23b54a8 100644
--- a/firmware/stub/vboot_api_stub_disk.c
+++ b/firmware/stub/vboot_api_stub_disk.c
@@ -5,11 +5,8 @@
* Stub implementations of disk APIs.
*/
-#include <stdint.h>
-
-#define _STUB_IMPLEMENTATION_
-
#include <stdarg.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/firmware/stub/vboot_api_stub_init.c b/firmware/stub/vboot_api_stub_init.c
index 214387a2..e26390dc 100644
--- a/firmware/stub/vboot_api_stub_init.c
+++ b/firmware/stub/vboot_api_stub_init.c
@@ -5,11 +5,9 @@
* Stub implementations of firmware-provided API functions.
*/
-#include <stdint.h>
-
-#define _STUB_IMPLEMENTATION_
#include <stdarg.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/firmware/stub/vboot_api_stub_region.c b/firmware/stub/vboot_api_stub_region.c
index 07142035..f462fe4e 100644
--- a/firmware/stub/vboot_api_stub_region.c
+++ b/firmware/stub/vboot_api_stub_region.c
@@ -6,9 +6,6 @@
*/
#include <stdint.h>
-
-#define _STUB_IMPLEMENTATION_
-
#include <stdlib.h>
#include "vboot_api.h"
diff --git a/firmware/stub/vboot_api_stub_sf.c b/firmware/stub/vboot_api_stub_sf.c
deleted file mode 100644
index 76d45ee8..00000000
--- a/firmware/stub/vboot_api_stub_sf.c
+++ /dev/null
@@ -1,142 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Stub implementations of firmware-provided API functions.
- */
-
-/* Musl doesn't have execinfo.h.
- TODO(dje): Add a replacement (libunwind) if/when fnl needs it. */
-#ifdef HAVE_EXECINFO_H
-#include <execinfo.h>
-#endif
-
-#include <stdint.h>
-
-#define _STUB_IMPLEMENTATION_
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-
-#include "vboot_api.h"
-
-#define MAX_STACK_LEVELS 10
-
-
-/* Keep track of nodes that are currently allocated */
-struct alloc_node {
- struct alloc_node *next;
- void *ptr;
- size_t size;
-#ifdef HAVE_EXECINFO_H
- void *bt_buffer[MAX_STACK_LEVELS];
- int bt_levels;
-#endif
-};
-
-static struct alloc_node *alloc_head;
-
-#ifdef HAVE_EXECINFO_H
-static void print_stacktrace(void)
-{
- void *buffer[MAX_STACK_LEVELS];
- int levels = backtrace(buffer, MAX_STACK_LEVELS);
-
- // print to stderr (fd = 2), and remove this function from the trace
- backtrace_symbols_fd(buffer + 1, levels - 1, 2);
-}
-#endif
-
-void *VbExMalloc(size_t size)
-{
- struct alloc_node *node;
- void *p = malloc(size);
-
- if (!p) {
- /* Fatal Error. We must abort. */
- abort();
- }
-
- node = malloc(sizeof(*node));
- if (!node)
- abort();
- node->next = alloc_head;
- node->ptr = p;
- node->size = size;
-#ifdef HAVE_EXECINFO_H
- node->bt_levels = backtrace(node->bt_buffer, MAX_STACK_LEVELS);
-#endif
- alloc_head = node;
-
- return p;
-}
-
-static struct alloc_node **find_node(void *ptr)
-{
- struct alloc_node **nodep;
-
- for (nodep = &alloc_head; *nodep; nodep = &(*nodep)->next)
- if ((*nodep)->ptr == ptr)
- return nodep;
-
- return NULL;
-}
-
-void VbExFree(void *ptr)
-{
- struct alloc_node **nodep, *next;
-
- nodep = find_node(ptr);
- if (nodep) {
- next = (*nodep)->next;
- free(*nodep);
- *nodep = next;
- } else {
- fprintf(stderr, "\n>>>>>> Invalid VbExFree() %p\n", ptr);
- fflush(stderr);
-#ifdef HAVE_EXECINFO_H
- print_stacktrace();
-#endif
- /*
- * Fall through and do the free() so we get normal error
- * handling.
- */
- }
-
- free(ptr);
-}
-
-VbError_t VbExHashFirmwareBody(VbCommonParams *cparams,
- uint32_t firmware_index)
-{
- return VBERROR_SUCCESS;
-}
-
-int vboot_api_stub_check_memory(void)
-{
- struct alloc_node *node, *next;
-
- if (!alloc_head)
- return 0;
-
- /*
- * Make sure we free all our memory so that valgrind doesn't complain
- * about leaked memory.
- */
- fprintf(stderr, "\nWarning, some allocations not freed:");
- for (node = alloc_head; node; node = next) {
- next = node->next;
- fprintf(stderr, "\nptr=%p, size=%zd\n", node->ptr, node->size);
- fflush(stderr);
-#ifdef HAVE_EXECINFO_H
- backtrace_symbols_fd(node->bt_buffer + 1, node->bt_levels - 1,
- 2);
-#endif
- free(node);
- }
-
- return -1;
-}
diff --git a/firmware/stub/vboot_api_stub_static_sf.c b/firmware/stub/vboot_api_stub_static_sf.c
deleted file mode 100644
index c266177d..00000000
--- a/firmware/stub/vboot_api_stub_static_sf.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Workaround for TODO(crbug.com/437107). Remove this file when it's fixed.
- */
-
-#define _STUB_IMPLEMENTATION_
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "vboot_api.h"
-
-void *VbExMalloc(size_t size)
-{
- void *p = malloc(size);
-
- if (!p) {
- /* Fatal Error. We must abort. */
- abort();
- }
-
- return p;
-}
-void VbExFree(void *ptr)
-{
- free(ptr);
-}
-
-
-/*
- * This file should be used only when building the static version of futility,
- * so let's intentionally break any tests that link with it by accident.
- */
-int vboot_api_stub_check_memory(void)
-{
- return -1;
-}
diff --git a/firmware/stub/vboot_api_stub_stream.c b/firmware/stub/vboot_api_stub_stream.c
index 525c8f78..c65259d3 100644
--- a/firmware/stub/vboot_api_stub_stream.c
+++ b/firmware/stub/vboot_api_stub_stream.c
@@ -7,8 +7,6 @@
#include <stdint.h>
-#define _STUB_IMPLEMENTATION_
-
#include "vboot_api.h"
/* The stub implementation assumes 512-byte disk sectors */
@@ -36,7 +34,7 @@ VbError_t VbExStreamOpen(VbExDiskHandle_t handle, uint64_t lba_start,
return VBERROR_UNKNOWN;
}
- s = VbExMalloc(sizeof(*s));
+ s = malloc(sizeof(*s));
s->handle = handle;
s->sector = lba_start;
s->sectors_left = lba_count;
@@ -82,6 +80,6 @@ void VbExStreamClose(VbExStream_t stream)
if (!s)
return;
- VbExFree(s);
+ free(s);
return;
}
diff --git a/host/lib/include/host_common.h b/host/lib/include/host_common.h
index 7a347a8f..7fde53ba 100644
--- a/host/lib/include/host_common.h
+++ b/host/lib/include/host_common.h
@@ -8,12 +8,6 @@
#ifndef VBOOT_REFERENCE_HOST_COMMON_H_
#define VBOOT_REFERENCE_HOST_COMMON_H_
-/*
- * Host is allowed direct use of stdlib funcs such as malloc() and free(),
- * since it's using the stub implementation from firmware/lib/stub.
- */
-#define _STUB_IMPLEMENTATION_
-
#include "host_key.h"
#include "host_key2.h"
#include "host_keyblock.h"
diff --git a/tests/cgptlib_test.c b/tests/cgptlib_test.c
index f1a91cdc..c0147e16 100644
--- a/tests/cgptlib_test.c
+++ b/tests/cgptlib_test.c
@@ -13,7 +13,6 @@
#include "crc32_test.h"
#include "gpt.h"
#include "test_common.h"
-#define _STUB_IMPLEMENTATION_
#include "utility.h"
/*
diff --git a/tests/rollback_index2_tests.c b/tests/rollback_index2_tests.c
index a1fdf0c7..290f69eb 100644
--- a/tests/rollback_index2_tests.c
+++ b/tests/rollback_index2_tests.c
@@ -10,8 +10,6 @@
#include <stdlib.h>
#include <string.h>
-#define _STUB_IMPLEMENTATION_ /* So we can use memset() ourselves */
-
#include "2crc8.h"
#include "rollback_index.h"
#include "test_common.h"
diff --git a/tests/rollback_index3_tests.c b/tests/rollback_index3_tests.c
index 46863fbd..19c13931 100644
--- a/tests/rollback_index3_tests.c
+++ b/tests/rollback_index3_tests.c
@@ -10,8 +10,6 @@
#include <stdlib.h>
#include <string.h>
-#define _STUB_IMPLEMENTATION_ /* So we can use memset() ourselves */
-
#include "rollback_index.h"
#include "test_common.h"
diff --git a/tests/test_common.h b/tests/test_common.h
index 0e2c8d6c..25f39d9c 100644
--- a/tests/test_common.h
+++ b/tests/test_common.h
@@ -127,9 +127,6 @@ int test_succ(int result,
#define COL_RED "\x1b[0;31m"
#define COL_STOP "\x1b[m"
-/* Check that all memory allocations were freed */
-int vboot_api_stub_check_memory(void);
-
/* Abort if asprintf fails. */
#define xasprintf(...) \
do { \
diff --git a/tests/vb20_rsa_padding_tests.c b/tests/vb20_rsa_padding_tests.c
index c506572d..dbfdc38f 100644
--- a/tests/vb20_rsa_padding_tests.c
+++ b/tests/vb20_rsa_padding_tests.c
@@ -3,12 +3,9 @@
* found in the LICENSE file.
*/
-
#include <stdint.h>
#include <stdio.h>
-#define _STUB_IMPLEMENTATION_
-
#include "file_keys.h"
#include "rsa_padding_test.h"
#include "test_common.h"
diff --git a/tests/vb2_rsa_utility_tests.c b/tests/vb2_rsa_utility_tests.c
index 9fe1b7e1..796f09d0 100644
--- a/tests/vb2_rsa_utility_tests.c
+++ b/tests/vb2_rsa_utility_tests.c
@@ -7,8 +7,6 @@
#include <stdint.h>
#include <stdio.h>
-#define _STUB_IMPLEMENTATION_
-
#include "2sysincludes.h"
#include "2common.h"
diff --git a/tests/vboot_api_devmode_tests.c b/tests/vboot_api_devmode_tests.c
index be8cdf94..abd8e858 100644
--- a/tests/vboot_api_devmode_tests.c
+++ b/tests/vboot_api_devmode_tests.c
@@ -324,15 +324,8 @@ static void VbBootDeveloperSoundTest(void) {
}
-int main(int argc, char* argv[]) {
- int error_code = 0;
-
+int main(int argc, char* argv[])
+{
VbBootDeveloperSoundTest();
-
- if (!gTestSuccess)
- error_code = 255;
- if (vboot_api_stub_check_memory())
- error_code = 255;
-
- return error_code;
+ return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_api_kernel2_tests.c b/tests/vboot_api_kernel2_tests.c
index c0f31b46..8a566367 100644
--- a/tests/vboot_api_kernel2_tests.c
+++ b/tests/vboot_api_kernel2_tests.c
@@ -718,8 +718,5 @@ int main(void)
VbBootDevTest();
VbBootRecTest();
- if (vboot_api_stub_check_memory())
- return 255;
-
return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_api_kernel3_tests.c b/tests/vboot_api_kernel3_tests.c
index 0a47fa8b..3eddb739 100644
--- a/tests/vboot_api_kernel3_tests.c
+++ b/tests/vboot_api_kernel3_tests.c
@@ -426,8 +426,5 @@ int main(void)
{
VbSoftwareSyncTest();
- if (vboot_api_stub_check_memory())
- return 255;
-
return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_api_kernel4_tests.c b/tests/vboot_api_kernel4_tests.c
index 26f92726..2672c4e7 100644
--- a/tests/vboot_api_kernel4_tests.c
+++ b/tests/vboot_api_kernel4_tests.c
@@ -255,8 +255,5 @@ int main(void)
{
VbSlkTest();
- if (vboot_api_stub_check_memory())
- return 255;
-
return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_api_kernel5_tests.c b/tests/vboot_api_kernel5_tests.c
index d752f6b7..8633f7e7 100644
--- a/tests/vboot_api_kernel5_tests.c
+++ b/tests/vboot_api_kernel5_tests.c
@@ -306,8 +306,5 @@ int main(void)
{
VerifyMemoryBootImageTest();
- if (vboot_api_stub_check_memory())
- return 255;
-
return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_api_kernel6_tests.c b/tests/vboot_api_kernel6_tests.c
index 42bd279c..a24cde80 100644
--- a/tests/vboot_api_kernel6_tests.c
+++ b/tests/vboot_api_kernel6_tests.c
@@ -55,8 +55,5 @@ int main(void)
VbUnlockDeviceTest();
VbLockDeviceTest();
- if (vboot_api_stub_check_memory())
- return 255;
-
return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_api_kernel_tests.c b/tests/vboot_api_kernel_tests.c
index 78cc6cf6..0baf4dff 100644
--- a/tests/vboot_api_kernel_tests.c
+++ b/tests/vboot_api_kernel_tests.c
@@ -323,8 +323,5 @@ int main(void)
{
VbTryLoadKernelTest();
- if (vboot_api_stub_check_memory())
- return 255;
-
return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_audio_tests.c b/tests/vboot_audio_tests.c
index 4cc6ab28..c392c0d9 100644
--- a/tests/vboot_audio_tests.c
+++ b/tests/vboot_audio_tests.c
@@ -216,16 +216,9 @@ static void VbAudioTest(void) {
}
-int main(int argc, char* argv[]) {
- int error_code = 0;
-
+int main(int argc, char* argv[])
+{
VbAudioTest();
- if (!gTestSuccess)
- error_code = 255;
-
- if (vboot_api_stub_check_memory())
- error_code = 255;
-
- return error_code;
+ return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_common_tests.c b/tests/vboot_common_tests.c
index 8e005260..8ca49a68 100644
--- a/tests/vboot_common_tests.c
+++ b/tests/vboot_common_tests.c
@@ -232,8 +232,5 @@ int main(int argc, char* argv[])
PublicKeyTest();
VbSharedDataTest();
- if (vboot_api_stub_check_memory())
- return 255;
-
return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_display_tests.c b/tests/vboot_display_tests.c
index 99d14f21..ff036d23 100644
--- a/tests/vboot_display_tests.c
+++ b/tests/vboot_display_tests.c
@@ -63,9 +63,9 @@ static void ResetMocks(void)
/*
* Note, VbApiKernelFree() expects this to be allocated by
- * VbExMalloc(), so we cannot just assign it staticly.
+ * malloc(), so we cannot just assign it staticly.
*/
- cparams.gbb = VbExMalloc(sizeof(*gbb));
+ cparams.gbb = malloc(sizeof(*gbb));
gbb->header_size = sizeof(*gbb);
gbb->rootkey_offset = gbb_used;
gbb->rootkey_size = 64;
@@ -264,8 +264,5 @@ int main(void)
DisplayKeyTest();
FontTest();
- if (vboot_api_stub_check_memory())
- return 255;
-
return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c
index dfb66195..057e2dd3 100644
--- a/tests/vboot_kernel_tests.c
+++ b/tests/vboot_kernel_tests.c
@@ -834,8 +834,5 @@ int main(void)
InvalidParamsTest();
LoadKernelTest();
- if (vboot_api_stub_check_memory())
- return 255;
-
return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_nvstorage_test.c b/tests/vboot_nvstorage_test.c
index ecfe1714..687048e1 100644
--- a/tests/vboot_nvstorage_test.c
+++ b/tests/vboot_nvstorage_test.c
@@ -198,15 +198,9 @@ static void VbNvStorageTest(void) {
}
-int main(int argc, char* argv[]) {
- int error_code = 0;
-
+int main(int argc, char* argv[])
+{
VbNvStorageTest();
- if (vboot_api_stub_check_memory())
- error_code = 255;
- if (!gTestSuccess)
- error_code = 255;
-
- return error_code;
+ return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_region_tests.c b/tests/vboot_region_tests.c
index d087f0ad..464461c7 100644
--- a/tests/vboot_region_tests.c
+++ b/tests/vboot_region_tests.c
@@ -194,15 +194,9 @@ static void VbRegionReadTest(void) {
VBERROR_NO_DISK_FOUND, "Kernel");
}
-int main(int argc, char* argv[]) {
- int error_code = 0;
-
+int main(int argc, char* argv[])
+{
VbRegionReadTest();
- if (vboot_api_stub_check_memory())
- error_code = 255;
- if (!gTestSuccess)
- error_code = 255;
-
- return error_code;
+ return gTestSuccess ? 0 : 255;
}
diff --git a/utility/verify_data.c b/utility/verify_data.c
index 74a11fc4..a3ab277a 100644
--- a/utility/verify_data.c
+++ b/utility/verify_data.c
@@ -15,8 +15,6 @@
#include <sys/types.h>
#include <unistd.h>
-#define _STUB_IMPLEMENTATION_ /* For malloc()/free() */
-
#include "2sysincludes.h"
#include "2common.h"