[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/4] Add module infrastructure to QEMU
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 1/4] Add module infrastructure to QEMU |
Date: |
Mon, 11 May 2009 09:26:46 -0500 |
Signed-off-by: Anthony Liguori <address@hidden>
diff --git a/Makefile b/Makefile
index 8649938..5c53801 100644
--- a/Makefile
+++ b/Makefile
@@ -63,7 +63,7 @@ recurse-all: $(SUBDIR_RULES)
#######################################################################
# BLOCK_OBJS is code used by both qemu system emulation and qemu-img
-BLOCK_OBJS=cutils.o cache-utils.o qemu-malloc.o
+BLOCK_OBJS=cutils.o cache-utils.o qemu-malloc.o module.o
BLOCK_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o
BLOCK_OBJS+=block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
BLOCK_OBJS+=block-qcow2.o block-parallels.o block-nbd.o
diff --git a/Makefile.target b/Makefile.target
index fe83837..c08c6fd 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -340,14 +340,13 @@ ifeq ($(TARGET_ARCH), m68k)
OBJS+= m68k-sim.o m68k-semi.o
endif
-OBJS+= libqemu.a
-
# Note: this is a workaround. The real fix is to avoid compiling
# cpu_signal_handler() in cpu-exec.c.
signal.o: CFLAGS += $(HELPER_CFLAGS)
-$(QEMU_PROG): $(OBJS) ../libqemu_user.a
- $(LINK)
+$(QEMU_PROG): ARLIBS=../libqemu_user.a libqemu.a
+$(QEMU_PROG): $(OBJS) ../libqemu_user.a libqemu.a
+ $(call LINK,$(OBJS))
ifeq ($(ARCH),alpha)
# Mark as 32 bit binary, i. e. it will be mapped into the low 31 bit of
# the address space (31 bit so sign extending doesn't matter)
@@ -372,14 +371,13 @@ LIBS+=-lmx
OBJS= main.o commpage.o machload.o mmap.o signal.o syscall.o thunk.o \
gdbstub.o gdbstub-xml.o
-OBJS+= libqemu.a
-
# Note: this is a workaround. The real fix is to avoid compiling
# cpu_signal_handler() in cpu-exec.c.
signal.o: CFLAGS += $(HELPER_CFLAGS)
-$(QEMU_PROG): $(OBJS)
- $(LINK)
+$(QEMU_PROG): ARLIBS=libqemu.a
+$(QEMU_PROG): $(OBJS) libqemu.a
+ $(call LINK,$(OBJS))
endif #CONFIG_DARWIN_USER
@@ -473,14 +471,13 @@ OBJS= main.o bsdload.o elfload.o mmap.o path.o signal.o
strace.o syscall.o \
gdbstub.o gdbstub-xml.o
OBJS+= uaccess.o
-OBJS+= libqemu.a
-
# Note: this is a workaround. The real fix is to avoid compiling
# cpu_signal_handler() in cpu-exec.c.
signal.o: CFLAGS += $(HELPER_CFLAGS)
-$(QEMU_PROG): $(OBJS) ../libqemu_user.a
- $(LINK)
+$(QEMU_PROG): ARLIBS=libqemu.a ../libqemu_user.a
+$(QEMU_PROG): $(OBJS) libqemu.a ../libqemu_user.a
+ $(call LINK,$(OBJS))
endif #CONFIG_BSD_USER
@@ -497,14 +494,6 @@ OBJS+=fw_cfg.o
ifdef CONFIG_KVM
OBJS+=kvm.o kvm-all.o
endif
-ifdef CONFIG_WIN32
-OBJS+=block-raw-win32.o
-else
-ifdef CONFIG_AIO
-OBJS+=posix-aio-compat.o
-endif
-OBJS+=block-raw-posix.o
-endif
LIBS+=-lz
ifdef CONFIG_ALSA
@@ -724,9 +713,9 @@ endif
vl.o: qemu-options.h
$(QEMU_PROG): LIBS += $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(BRLAPI_LIBS)
$(VDE_LIBS)
-
+$(QEMU_PROG): ARLIBS=../libqemu_common.a libqemu.a
$(QEMU_PROG): $(OBJS) ../libqemu_common.a libqemu.a
- $(LINK)
+ $(call LINK,$(OBJS))
endif # !CONFIG_USER_ONLY
diff --git a/module.c b/module.c
new file mode 100644
index 0000000..2db2dad
--- /dev/null
+++ b/module.c
@@ -0,0 +1,137 @@
+/*
+ * QEMU Module Infrastructure
+ *
+ * Copyright IBM, Corp. 2009
+ *
+ * Authors:
+ * Anthony Liguori <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "sys-queue.h"
+#include "module.h"
+
+typedef struct ModuleEntry
+{
+ int priority;
+ int is_init;
+ union {
+ int (*init)(void);
+ void (*exit)(void);
+ };
+ TAILQ_ENTRY(ModuleEntry) node;
+} ModuleEntry;
+
+typedef struct ModulePriorityList
+{
+ int priority;
+ TAILQ_HEAD(, ModuleEntry) entry_list;
+ TAILQ_ENTRY(ModulePriorityList) node;
+} ModulePriorityList;
+
+static TAILQ_HEAD(, ModulePriorityList) priority_list;
+
+static ModulePriorityList *find_priority_or_alloc(int priority, int alloc)
+{
+ ModulePriorityList *n;
+
+ TAILQ_FOREACH(n, &priority_list, node) {
+ if (priority >= n->priority)
+ break;
+ }
+
+ if (!n || n->priority != priority) {
+ ModulePriorityList *o;
+
+ if (!alloc)
+ return NULL;
+
+ o = qemu_mallocz(sizeof(*o));
+ o->priority = priority;
+ TAILQ_INIT(&o->entry_list);
+
+ if (n) {
+ TAILQ_INSERT_AFTER(&priority_list, n, o, node);
+ } else {
+ TAILQ_INSERT_HEAD(&priority_list, o, node);
+ }
+
+ n = o;
+ }
+
+ return n;
+}
+
+void register_module_init(int (*fn)(void), int priority)
+{
+ ModuleEntry *e;
+ ModulePriorityList *l;
+
+ e = qemu_mallocz(sizeof(*e));
+ e->is_init = 1;
+ e->init = fn;
+
+ l = find_priority_or_alloc(priority, 1);
+
+ TAILQ_INSERT_TAIL(&l->entry_list, e, node);
+}
+
+void register_module_exit(void (*fn)(void), int priority)
+{
+ ModuleEntry *e;
+ ModulePriorityList *l;
+
+ e = qemu_mallocz(sizeof(*e));
+ e->is_init = 0;
+ e->exit = fn;
+
+ l = find_priority_or_alloc(priority, 1);
+
+ TAILQ_INSERT_TAIL(&l->entry_list, e, node);
+}
+
+int module_call_init(int priority)
+{
+ ModulePriorityList *l;
+ ModuleEntry *e;
+
+ l = find_priority_or_alloc(priority, 0);
+ if (!l) {
+ return 0;
+ }
+
+ TAILQ_FOREACH(e, &l->entry_list, node) {
+ int ret;
+
+ if (!e->is_init) {
+ continue;
+ }
+
+ ret = e->init();
+ if (ret != 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+void module_call_exit(int priority)
+{
+ ModulePriorityList *l;
+ ModuleEntry *e;
+
+ l = find_priority_or_alloc(priority, 0);
+ if (!l) {
+ return;
+ }
+
+ TAILQ_FOREACH(e, &l->entry_list, node) {
+ if (!e->is_init) {
+ e->exit();
+ }
+ }
+}
diff --git a/module.h b/module.h
new file mode 100644
index 0000000..5aa3eaa
--- /dev/null
+++ b/module.h
@@ -0,0 +1,41 @@
+/*
+ * QEMU Module Infrastructure
+ *
+ * Copyright IBM, Corp. 2009
+ *
+ * Authors:
+ * Anthony Liguori <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_MODULE_H
+#define QEMU_MODULE_H
+
+#define module_init(function, priority) \
+static void __attribute__((constructor)) qemu_init_ ## function(void) { \
+ register_module_init(function, priority); \
+}
+
+#define module_exit(function, priority) \
+static void __attribute__((constructor)) qemu_exit_ ## function(void) { \
+ register_module_exit(function, priority); \
+}
+
+#define MOD_PRI_HIGHEST 0
+#define MOD_PRI_BLOCK (MOD_PRI_HIGHEST + 1)
+
+#define block_init(function) module_init(function, MOD_PRI_BLOCK)
+#define block_exit(function) module_exit(function, MOD_PRI_BLOCK)
+
+void register_module_init(int (*fn)(void), int priority);
+
+void register_module_exit(void (*fn)(void), int priority);
+
+int module_call_init(int priority);
+
+void module_call_exit(int priority);
+
+#endif
diff --git a/rules.mak b/rules.mak
index a75a93b..8471d40 100644
--- a/rules.mak
+++ b/rules.mak
@@ -8,10 +8,13 @@
%.o: %.m
$(call quiet-command,$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<," OBJC
$(TARGET_DIR)$@")
-LINK = $(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)," LINK
$(TARGET_DIR)$@")
+WAS=-Wl,--whole-archive
+WAE=-Wl,--no-whole-archive
+
+LINK = $(call quiet-command,$(CC) $(LDFLAGS) -o $@ $(1) $(LIBS) $(WAS)
$(ARLIBS) $(WAE)," LINK $(TARGET_DIR)$@")
%$(EXESUF): %.o
- $(LINK)
+ $(call LINK,$^)
%.a:
$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR
$(TARGET_DIR)$@")
--
1.6.0.6
[Qemu-devel] [PATCH 2/4] Convert block infrastructure to use new module init functionality, Anthony Liguori, 2009/05/11
[Qemu-devel] [PATCH 4/4] Introduce global .config to selectively enable compile features, Anthony Liguori, 2009/05/11