*/
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <inttypes.h>
#include "xg_private.h"
/* ------------------------------------------------------------------------ */
+static void log_callback(struct elf_binary *elf, void *caller_data,
+ int iserr, const char *fmt, va_list al) {
+ vfprintf(caller_data,fmt,al);
+}
+
+void xc_elf_set_logfile(struct elf_binary *elf, FILE *f, int verbose) {
+ elf_set_log(elf, log_callback, f, verbose);
+}
+
+/* ------------------------------------------------------------------------ */
+
static char *xc_dom_guest_type(struct xc_dom_image *dom,
struct elf_binary *elf)
{
}
if ( elf_init(&syms, hdr + sizeof(int), size - sizeof(int)) )
return -1;
+
if ( xc_dom_logfile )
- elf_set_logfile(&syms, xc_dom_logfile, 1);
+ xc_elf_set_logfile(&syms, xc_dom_logfile, 1);
symtab = dom->bsd_symtab_start + sizeof(int);
maxaddr = elf_round_up(&syms, symtab + elf_size(&syms, syms.ehdr) +
dom->private_loader = elf;
rc = elf_init(elf, dom->kernel_blob, dom->kernel_size);
if ( xc_dom_logfile )
- elf_set_logfile(elf, xc_dom_logfile, 1);
+ xc_elf_set_logfile(elf, xc_dom_logfile, 1);
if ( rc != 0 )
{
xc_dom_panic(XC_INVALID_KERNEL, "%s: corrupted ELF image\n",
#include <stddef.h>
#include <stdint.h>
+#include <stdio.h>
#include <xen/xen.h>
#include <xen/domctl.h>
#include <xen/physdev.h>
uint32_t domid,
grant_ref_t gref);
+struct elf_binary;
+void xc_elf_set_logfile(struct elf_binary *elf, FILE *f, int verbose);
+/* Useful for callers who also use libelf. */
+
#endif /* XENCTRL_H */
fprintf(stderr, "File %s is not an ELF image\n", f);
return 1;
}
- elf_set_logfile(&elf, stderr, 0);
+ xc_elf_set_logfile(&elf, stderr, 0);
count = elf_phdr_count(&elf);
for ( h=0; h < count; h++)
* parse and load elf binaries
*/
+#include <stdarg.h>
+
#include "libelf-private.h"
/* ------------------------------------------------------------------------ */
}
#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
#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 ... ) \
#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); \
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*";
#else
#include <xen/elfnote.h>
#include <xen/features.h>
+
+#include <stdarg.h>
+
+struct elf_binary;
+typedef void elf_log_callback(struct elf_binary*, void *caller_data,
+ int iserr, const char *fmt, va_list al);
+
#endif
/* ------------------------------------------------------------------------ */
#ifndef __XEN__
/* misc */
- FILE *log;
+ elf_log_callback *log_callback;
+ void *log_caller_data;
#endif
int verbose;
};
#ifdef __XEN__
void elf_set_verbose(struct elf_binary *elf);
#else
-void elf_set_logfile(struct elf_binary *elf, FILE * log, int verbose);
+void elf_set_log(struct elf_binary *elf, elf_log_callback*,
+ void *log_caller_pointer, int verbose);
#endif
void elf_parse_binary(struct elf_binary *elf);