aboutsummaryrefslogtreecommitdiffstats
path: root/xen/common/libelf
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-05-28 09:27:40 +0100
committerKeir Fraser <keir.fraser@citrix.com>2010-05-28 09:27:40 +0100
commit36cfb6aa84c1b5a5b5ac15883e34b10f32ab0ab8 (patch)
treef6eb1345d9d81843e0213b31d30f672895d8fdac /xen/common/libelf
parent96830282274a9f6a7aafd506976a3639b6f80836 (diff)
downloadxen-36cfb6aa84c1b5a5b5ac15883e34b10f32ab0ab8.tar.gz
xen-36cfb6aa84c1b5a5b5ac15883e34b10f32ab0ab8.tar.bz2
xen-36cfb6aa84c1b5a5b5ac15883e34b10f32ab0ab8.zip
libelf: Tidy up logging and remove dependency on stdio.
libelf now permits callers to specify logging callback functions, rather than a FILE*. libelf's non-Xen callers are all libxc users, so the stdio dependency and the default logging callback function (which calls vfprintf) is now in libxc. Xen's use of libxc is unaffected in this patch. Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'xen/common/libelf')
-rw-r--r--xen/common/libelf/libelf-loader.c22
-rw-r--r--xen/common/libelf/libelf-private.h15
-rw-r--r--xen/common/libelf/libelf-relocate.c2
3 files changed, 29 insertions, 10 deletions
diff --git a/xen/common/libelf/libelf-loader.c b/xen/common/libelf/libelf-loader.c
index 5e86555817..f50524f690 100644
--- a/xen/common/libelf/libelf-loader.c
+++ b/xen/common/libelf/libelf-loader.c
@@ -2,6 +2,8 @@
* parse and load elf binaries
*/
+#include <stdarg.h>
+
#include "libelf-private.h"
/* ------------------------------------------------------------------------ */
@@ -72,9 +74,25 @@ int elf_init(struct elf_binary *elf, const char *image, size_t size)
}
#ifndef __XEN__
-void elf_set_logfile(struct elf_binary *elf, FILE * log, int verbose)
+void elf_call_log_callback(struct elf_binary *elf, int iserr,
+ const char *fmt,...) {
+ va_list al;
+
+ if (!elf->log_callback)
+ return;
+ if (!(iserr || elf->verbose))
+ return;
+
+ va_start(al,fmt);
+ elf->log_callback(elf, elf->log_caller_data, iserr, fmt, al);
+ va_end(al);
+}
+
+void elf_set_log(struct elf_binary *elf, elf_log_callback *log_callback,
+ void *log_caller_data, int verbose)
{
- elf->log = log;
+ elf->log_callback = log_callback;
+ elf->log_caller_data = log_caller_data;
elf->verbose = verbose;
}
#else
diff --git a/xen/common/libelf/libelf-private.h b/xen/common/libelf/libelf-private.h
index e207b690c4..fcce9e331a 100644
--- a/xen/common/libelf/libelf-private.h
+++ b/xen/common/libelf/libelf-private.h
@@ -11,6 +11,8 @@
#include <asm/byteorder.h>
#include <public/elfnote.h>
+/* we would like to use elf->log_callback but we can't because
+ * there is no vprintk in Xen */
#define elf_msg(elf, fmt, args ... ) \
if (elf->verbose) printk(fmt, ## args )
#define elf_err(elf, fmt, args ... ) \
@@ -54,13 +56,12 @@
#include "xenctrl.h"
#include "xc_private.h"
-#define elf_msg(elf, fmt, args ... ) \
- if (elf->log && elf->verbose) fprintf(elf->log, fmt , ## args )
-#define elf_err(elf, fmt, args ... ) do { \
- if (elf->log) \
- fprintf(elf->log, fmt , ## args ); \
- xc_set_error(XC_INVALID_KERNEL, fmt , ## args ); \
-} while (0)
+#define elf_msg(elf, fmt, args ... ) \
+ elf_call_log_callback(elf, 0, fmt , ## args );
+#define elf_err(elf, fmt, args ... ) \
+ elf_call_log_callback(elf, 1, fmt , ## args );
+
+void elf_call_log_callback(struct elf_binary*, int iserr, const char *fmt,...);
#define safe_strcpy(d,s) \
do { strncpy((d),(s),sizeof((d))-1); \
diff --git a/xen/common/libelf/libelf-relocate.c b/xen/common/libelf/libelf-relocate.c
index 89cea4411b..fe9891da70 100644
--- a/xen/common/libelf/libelf-relocate.c
+++ b/xen/common/libelf/libelf-relocate.c
@@ -289,7 +289,7 @@ static int elf_reloc_section(struct elf_binary *elf,
value = elf_uval(elf, sym, st_value);
value += r_addend;
- if ( elf->log && (elf->verbose > 1) )
+ if ( elf->log_callback && (elf->verbose > 1) )
{
uint64_t st_name = elf_uval(elf, sym, st_name);
const char *name = st_name ? elf->sym_strtab + st_name : "*NONE*";