mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 02:05:01 +00:00
Port to musl: musl doesn't have execinfo.h.
Change-Id: Idc2f18880581d3a2e67185becee8b77cfa5cdf04 Reviewed-on: https://chromium-review.googlesource.com/313388 Commit-Ready: Doug Evans <dje@google.com> Tested-by: Doug Evans <dje@google.com> Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
5
Makefile
5
Makefile
@@ -205,6 +205,11 @@ ifdef HAVE_MACOS
|
|||||||
CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
|
CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Musl doesn't have execinfo.h.
|
||||||
|
ifndef HAVE_MUSL
|
||||||
|
CFLAGS += -DHAVE_EXECINFO_H
|
||||||
|
endif
|
||||||
|
|
||||||
# And a few more default utilities
|
# And a few more default utilities
|
||||||
LD = ${CC}
|
LD = ${CC}
|
||||||
CXX ?= g++
|
CXX ?= g++
|
||||||
|
|||||||
@@ -5,7 +5,12 @@
|
|||||||
* Stub implementations of firmware-provided API functions.
|
* 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>
|
#include <execinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define _STUB_IMPLEMENTATION_
|
#define _STUB_IMPLEMENTATION_
|
||||||
@@ -26,12 +31,15 @@ struct alloc_node {
|
|||||||
struct alloc_node *next;
|
struct alloc_node *next;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
void *bt_buffer[MAX_STACK_LEVELS];
|
void *bt_buffer[MAX_STACK_LEVELS];
|
||||||
int bt_levels;
|
int bt_levels;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct alloc_node *alloc_head;
|
static struct alloc_node *alloc_head;
|
||||||
|
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
static void print_stacktrace(void)
|
static void print_stacktrace(void)
|
||||||
{
|
{
|
||||||
void *buffer[MAX_STACK_LEVELS];
|
void *buffer[MAX_STACK_LEVELS];
|
||||||
@@ -40,6 +48,7 @@ static void print_stacktrace(void)
|
|||||||
// print to stderr (fd = 2), and remove this function from the trace
|
// print to stderr (fd = 2), and remove this function from the trace
|
||||||
backtrace_symbols_fd(buffer + 1, levels - 1, 2);
|
backtrace_symbols_fd(buffer + 1, levels - 1, 2);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void *VbExMalloc(size_t size)
|
void *VbExMalloc(size_t size)
|
||||||
{
|
{
|
||||||
@@ -57,7 +66,9 @@ void *VbExMalloc(size_t size)
|
|||||||
node->next = alloc_head;
|
node->next = alloc_head;
|
||||||
node->ptr = p;
|
node->ptr = p;
|
||||||
node->size = size;
|
node->size = size;
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
node->bt_levels = backtrace(node->bt_buffer, MAX_STACK_LEVELS);
|
node->bt_levels = backtrace(node->bt_buffer, MAX_STACK_LEVELS);
|
||||||
|
#endif
|
||||||
alloc_head = node;
|
alloc_head = node;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
@@ -86,7 +97,9 @@ void VbExFree(void *ptr)
|
|||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "\n>>>>>> Invalid VbExFree() %p\n", ptr);
|
fprintf(stderr, "\n>>>>>> Invalid VbExFree() %p\n", ptr);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
print_stacktrace();
|
print_stacktrace();
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Fall through and do the free() so we get normal error
|
* Fall through and do the free() so we get normal error
|
||||||
* handling.
|
* handling.
|
||||||
@@ -118,8 +131,10 @@ int vboot_api_stub_check_memory(void)
|
|||||||
next = node->next;
|
next = node->next;
|
||||||
fprintf(stderr, "\nptr=%p, size=%zd\n", node->ptr, node->size);
|
fprintf(stderr, "\nptr=%p, size=%zd\n", node->ptr, node->size);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
#ifdef HAVE_EXECINFO_H
|
||||||
backtrace_symbols_fd(node->bt_buffer + 1, node->bt_levels - 1,
|
backtrace_symbols_fd(node->bt_buffer + 1, node->bt_levels - 1,
|
||||||
2);
|
2);
|
||||||
|
#endif
|
||||||
free(node);
|
free(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user