From 8e604574fb362754ec1361b47a89adaba7aca7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vivek=20Das=C2=A0Mohapatra?= <vivek@collabora.co.uk> Date: Tue, 16 May 2017 18:21:30 +0100 Subject: [PATCH] Start implementing the debug-flag-from-env infrastructure --- Makefile.am | 1 + capsule/capsule-init.c | 10 ++++++++++ capsule/capsule.h | 2 ++ generate-stublib.sh | 2 ++ utils/debug.h | 26 ++++++++++++++++++++++++++ utils/utils.c | 7 +++++-- utils/utils.h | 25 +------------------------ 7 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 capsule/capsule-init.c create mode 100644 utils/debug.h diff --git a/Makefile.am b/Makefile.am index 1e5688c1b..85202e543 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,6 +33,7 @@ print_libstubs_LDFLAGS = -ldl libcapsule_la_SOURCES = capsule/capsule-dlmopen.c \ capsule/capsule-relocate.c \ + capsule/capsule-init.c \ utils/utils.c utils/dump.c \ utils/process-pt-dynamic.c \ utils/mmap-info.c diff --git a/capsule/capsule-init.c b/capsule/capsule-init.c new file mode 100644 index 000000000..d66593792 --- /dev/null +++ b/capsule/capsule-init.c @@ -0,0 +1,10 @@ +#include "capsule.h" +#include "utils/utils.h" +#include <stdlib.h> + +void +capsule_init () +{ + set_debug_flags( secure_getenv("CAPSULE_DEBUG") ); +} + diff --git a/capsule/capsule.h b/capsule/capsule.h index 129de50a8..fd2071f46 100644 --- a/capsule/capsule.h +++ b/capsule/capsule.h @@ -26,6 +26,8 @@ typedef struct ElfW(Addr) real; } capsule_item_t; +void capsule_init (void); + int capsule_relocate (const char *target, void *source, int debug, diff --git a/generate-stublib.sh b/generate-stublib.sh index f86da7823..538cde1cd 100755 --- a/generate-stublib.sh +++ b/generate-stublib.sh @@ -139,6 +139,8 @@ cat - <<EOF symbol_ns = LM_ID_NEWLM; prefix = "/host"; + capsule_init(); + dso = capsule_dlmopen( "$proxied_dso", prefix, &symbol_ns, wrappers, 0, exclude, &capsule_errno, &capsule_error ); diff --git a/utils/debug.h b/utils/debug.h new file mode 100644 index 000000000..188a82a0d --- /dev/null +++ b/utils/debug.h @@ -0,0 +1,26 @@ +#pragma once + +enum +{ + DEBUG_NONE = 0, + DEBUG_PATH = 0x1, + DEBUG_SEARCH = 0x1 << 1, + DEBUG_LDCACHE = 0x1 << 2, + DEBUG_CAPSULE = 0x1 << 3, + DEBUG_MPROTECT = 0x1 << 4, + DEBUG_WRAPPERS = 0x1 << 5, + DEBUG_RELOCS = 0x1 << 6, + DEBUG_ALL = 0xffff, +}; + +#ifdef DEBUG +#define debug(fmt, args...) \ + fprintf( stderr, "%s:" fmt "\n", __PRETTY_FUNCTION__, ##args ) +#else +#define debug(fmt, args...) \ + +#endif + +extern unsigned long debug_context; +extern unsigned long debug_flags; +void set_debug_flags (const char *control); diff --git a/utils/utils.c b/utils/utils.c index 25910dbf5..9a7e3a54d 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -20,6 +20,10 @@ #include <fcntl.h> #include <string.h> #include <stdio.h> +#include "debug.h" + +unsigned long debug_flags; +unsigned long debug_context; char *safe_strncpy (char *dest, const char *src, size_t n) { @@ -108,6 +112,5 @@ void set_debug_flags (const char *control) (debug_flags & DEBUG_CAPSULE ) ? 'Y' : 'n' , (debug_flags & DEBUG_MPROTECT) ? 'Y' : 'n' , (debug_flags & DEBUG_WRAPPERS) ? 'Y' : 'n' , - (debug_flags & DEBUG_RELOCS ) ? 'Y' : 'n' , - (debug_flags & DEBUG_ALL ) ? 'Y' : 'n' ) + (debug_flags & DEBUG_RELOCS ) ? 'Y' : 'n' ); } diff --git a/utils/utils.h b/utils/utils.h index 77d6f2855..068e8dd4a 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -17,30 +17,7 @@ #pragma once -enum -{ - DEBUG_NONE = 0, - DEBUG_PATH = 0x1, - DEBUG_SEARCH = 0x1 << 1, - DEBUG_LDCACHE = 0x1 << 2, - DEBUG_CAPSULE = 0x1 << 3, - DEBUG_MPROTECT = 0x1 << 4, - DEBUG_WRAPPERS = 0x1 << 5, - DEBUG_RELOCS = 0x1 << 6, - DEBUG_ALL = 0xffff, -}; - -#ifdef DEBUG -#define debug(fmt, args...) \ - fprintf( stderr, "%s:" fmt "\n", __PRETTY_FUNCTION__, ##args ) -#else -#define debug(fmt, args...) \ - -#endif - -extern unsigned long debug_context; -extern unsigned long debug_flags; +#include "debug.h" char *safe_strncpy (char *dest, const char *src, size_t n); int resolve_link (const char *prefix, char *path, char *dir); -void set_debug_flags (const char *control); -- GitLab