From: "Dominik Żeromski" <dzeromsk@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Dominik Żeromski" <dzeromsk@gmail.com>
Subject: [Qemu-devel] [PATCH] Support for loading devices as dynamic libraries
Date: Sat, 25 Aug 2012 13:10:20 +0200 [thread overview]
Message-ID: <1345893020-4894-1-git-send-email-dzeromsk@gmail.com> (raw)
Adding support for loading DSO with -device option.
Example Makefile for out of tree modules:
#v+
DEVICENAME=pcnet2
hw-obj-y=pcnet-pci.o
hw-obj-y+=pcnet.o
include rules.mak
.PHONY: all
QEMU_CFLAGS=-I../qemu-kvm -I../qemu-kvm/hw
QEMU_CFLAGS+=-I../qemu-kvm/fpu -I../qemu-kvm/include
QEMU_CFLAGS+=-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
QEMU_CFLAGS+=-DTARGET_PHYS_ADDR_BITS=64 -fPIC
LDFLAGS+=-shared
LIBNAME=libqemu_$(DEVICENAME).so
all: $(LIBNAME)
$(LIBNAME): $(hw-obj-y)
$(call LINK,$^)
clean:
rm -f *.o
rm -f *.d
rm -f $(LIBNAME)
# Include automatically generated dependency files
-include $(patsubst %.o, %.d, $(hw-obj-y))
#v-
Signed-off-by: Dominik Żeromski <dzeromsk@gmail.com>
---
Makefile.target | 4 +++-
hw/qdev-monitor.c | 11 +++++++++++
2 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/Makefile.target b/Makefile.target
index 74f7a4a..7fd9245 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -130,7 +130,9 @@ obj-$(CONFIG_HAVE_GET_MEMORY_MAPPING) += memory_mapping.o
obj-$(CONFIG_HAVE_CORE_DUMP) += dump.o
obj-$(CONFIG_NO_GET_MEMORY_MAPPING) += memory_mapping-stub.o
obj-$(CONFIG_NO_CORE_DUMP) += dump-stub.o
-LIBS+=-lz
+LIBS+=-lz -ldl
+
+LDFLAGS+=-rdynamic
QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 7915b45..3b5b0b0 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -17,6 +17,8 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
+#include <dlfcn.h>
+
#include "qdev.h"
#include "monitor.h"
#include "qmp-commands.h"
@@ -402,6 +404,8 @@ DeviceState *qdev_device_add(QemuOpts *opts)
const char *driver, *path, *id;
DeviceState *qdev;
BusState *bus;
+ void *libhandle;
+ char libname[NAME_MAX];
driver = qemu_opt_get(opts, "driver");
if (!driver) {
@@ -419,7 +423,14 @@ DeviceState *qdev_device_add(QemuOpts *opts)
obj = object_class_by_name(driver);
}
}
+ if (!obj) {
+ snprintf(libname, sizeof(libname), "libqemu_%s.so", driver);
+ libhandle = dlopen(libname, RTLD_NOW);
+ if (libhandle != NULL) {
+ obj = object_class_by_name(driver);
+ }
+ }
if (!obj) {
qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
return NULL;
--
1.7.0.4
next reply other threads:[~2012-08-25 11:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-25 11:10 Dominik Żeromski [this message]
2012-08-25 13:53 ` [Qemu-devel] [PATCH] Support for loading devices as dynamic libraries Stefan Hajnoczi
2012-08-25 17:06 ` Dominik Żeromski
2012-08-25 18:18 ` Stefan Hajnoczi
2012-08-25 20:50 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1345893020-4894-1-git-send-email-dzeromsk@gmail.com \
--to=dzeromsk@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).