void-packages/srcpkgs/vboot-utils/patches/fix-musl.patch
2015-07-21 20:00:57 +02:00

49 lines
1.2 KiB
Diff

--- firmware/stub/vboot_api_stub_sf.c.orig
+++ firmware/stub/vboot_api_stub_sf.c
@@ -5,7 +5,9 @@
* Stub implementations of firmware-provided API functions.
*/
+#if defined(__GLIBC__)
#include <execinfo.h>
+#endif
#include <stdint.h>
#define _STUB_IMPLEMENTATION_
@@ -34,11 +36,13 @@ static struct alloc_node *alloc_head;
static void print_stacktrace(void)
{
+#if defined(__GLIBC__)
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)
@@ -57,7 +61,11 @@ void *VbExMalloc(size_t size)
node->next = alloc_head;
node->ptr = p;
node->size = size;
+#if defined(__GLIBC__)
node->bt_levels = backtrace(node->bt_buffer, MAX_STACK_LEVELS);
+#else
+ node->bt_levels = 0;
+#endif
alloc_head = node;
return p;
@@ -118,8 +126,10 @@ int vboot_api_stub_check_memory(void)
next = node->next;
fprintf(stderr, "\nptr=%p, size=%zd\n", node->ptr, node->size);
fflush(stderr);
+#if defined(__GLIBC__)
backtrace_symbols_fd(node->bt_buffer + 1, node->bt_levels - 1,
2);
+#endif
free(node);
}