diff options
Diffstat (limited to 'libcacard')
-rw-r--r-- | libcacard/Makefile | 10 | ||||
-rw-r--r-- | libcacard/event.c | 23 | ||||
-rw-r--r-- | libcacard/vreader.c | 18 | ||||
-rw-r--r-- | libcacard/vscclient.c | 70 |
4 files changed, 57 insertions, 64 deletions
diff --git a/libcacard/Makefile b/libcacard/Makefile index 881b222f93..0e7903fcfb 100644 --- a/libcacard/Makefile +++ b/libcacard/Makefile @@ -3,13 +3,7 @@ libcacard_includedir=$(includedir)/cacard TOOLS += vscclient$(EXESUF) # objects linked into a shared library, built with libtool with -fPIC if required -libcacard-obj-y = $(stub-obj-y) $(libcacard-y) -libcacard-obj-y += util/osdep.o util/cutils.o util/qemu-timer-common.o -libcacard-obj-y += util/error.o util/qemu-error.o -libcacard-obj-$(CONFIG_WIN32) += util/oslib-win32.o util/qemu-thread-win32.o -libcacard-obj-$(CONFIG_POSIX) += util/oslib-posix.o util/qemu-thread-posix.o -libcacard-obj-y += $(filter trace/%, $(util-obj-y)) - +libcacard-obj-y = $(libcacard-y) libcacard-lobj-y=$(patsubst %.o,%.lo,$(libcacard-obj-y)) # libtool will build the .o files, too @@ -24,7 +18,7 @@ vscclient$(EXESUF): libcacard/vscclient.o libcacard.la # Rules for building libcacard standalone library libcacard.la: LDFLAGS += -rpath $(libdir) -no-undefined \ - -export-syms $(SRC_PATH)/libcacard/libcacard.syms + -export-symbols $(SRC_PATH)/libcacard/libcacard.syms libcacard.la: $(libcacard-lobj-y) $(call LINK,$^) diff --git a/libcacard/event.c b/libcacard/event.c index a2e6c7dcd0..4c551e4e38 100644 --- a/libcacard/event.c +++ b/libcacard/event.c @@ -6,7 +6,6 @@ */ #include "qemu-common.h" -#include "qemu/thread.h" #include "vcard.h" #include "vreader.h" @@ -43,13 +42,11 @@ vevent_delete(VEvent *vevent) static VEvent *vevent_queue_head; static VEvent *vevent_queue_tail; -static QemuMutex vevent_queue_lock; -static QemuCond vevent_queue_condition; +static CompatGMutex vevent_queue_lock; +static CompatGCond vevent_queue_condition; void vevent_queue_init(void) { - qemu_mutex_init(&vevent_queue_lock); - qemu_cond_init(&vevent_queue_condition); vevent_queue_head = vevent_queue_tail = NULL; } @@ -57,7 +54,7 @@ void vevent_queue_vevent(VEvent *vevent) { vevent->next = NULL; - qemu_mutex_lock(&vevent_queue_lock); + g_mutex_lock(&vevent_queue_lock); if (vevent_queue_head) { assert(vevent_queue_tail); vevent_queue_tail->next = vevent; @@ -65,8 +62,8 @@ vevent_queue_vevent(VEvent *vevent) vevent_queue_head = vevent; } vevent_queue_tail = vevent; - qemu_cond_signal(&vevent_queue_condition); - qemu_mutex_unlock(&vevent_queue_lock); + g_cond_signal(&vevent_queue_condition); + g_mutex_unlock(&vevent_queue_lock); } /* must have lock */ @@ -86,11 +83,11 @@ VEvent *vevent_wait_next_vevent(void) { VEvent *vevent; - qemu_mutex_lock(&vevent_queue_lock); + g_mutex_lock(&vevent_queue_lock); while ((vevent = vevent_dequeue_vevent()) == NULL) { - qemu_cond_wait(&vevent_queue_condition, &vevent_queue_lock); + g_cond_wait(&vevent_queue_condition, &vevent_queue_lock); } - qemu_mutex_unlock(&vevent_queue_lock); + g_mutex_unlock(&vevent_queue_lock); return vevent; } @@ -98,9 +95,9 @@ VEvent *vevent_get_next_vevent(void) { VEvent *vevent; - qemu_mutex_lock(&vevent_queue_lock); + g_mutex_lock(&vevent_queue_lock); vevent = vevent_dequeue_vevent(); - qemu_mutex_unlock(&vevent_queue_lock); + g_mutex_unlock(&vevent_queue_lock); return vevent; } diff --git a/libcacard/vreader.c b/libcacard/vreader.c index 9f42f0fe21..0315dd8920 100644 --- a/libcacard/vreader.c +++ b/libcacard/vreader.c @@ -9,10 +9,8 @@ #undef G_LOG_DOMAIN #endif #define G_LOG_DOMAIN "libcacard" -#include <glib.h> #include "qemu-common.h" -#include "qemu/thread.h" #include "vcard.h" #include "vcard_emul.h" @@ -28,7 +26,7 @@ struct VReaderStruct { VCard *card; char *name; vreader_id_t id; - QemuMutex lock; + CompatGMutex lock; VReaderEmul *reader_private; VReaderEmulFree reader_private_free; }; @@ -97,13 +95,13 @@ apdu_ins_to_string(int ins) static inline void vreader_lock(VReader *reader) { - qemu_mutex_lock(&reader->lock); + g_mutex_lock(&reader->lock); } static inline void vreader_unlock(VReader *reader) { - qemu_mutex_unlock(&reader->lock); + g_mutex_unlock(&reader->lock); } /* @@ -116,7 +114,7 @@ vreader_new(const char *name, VReaderEmul *private, VReader *reader; reader = g_new(VReader, 1); - qemu_mutex_init(&reader->lock); + g_mutex_init(&reader->lock); reader->reference_count = 1; reader->name = g_strdup(name); reader->card = NULL; @@ -152,6 +150,7 @@ vreader_free(VReader *reader) return; } vreader_unlock(reader); + g_mutex_clear(&reader->lock); if (reader->card) { vcard_free(reader->card); } @@ -402,25 +401,24 @@ vreader_dequeue(VReaderList *list, VReaderListEntry *entry) } static VReaderList *vreader_list; -static QemuMutex vreader_list_mutex; +static CompatGMutex vreader_list_mutex; static void vreader_list_init(void) { vreader_list = vreader_list_new(); - qemu_mutex_init(&vreader_list_mutex); } static void vreader_list_lock(void) { - qemu_mutex_lock(&vreader_list_mutex); + g_mutex_lock(&vreader_list_mutex); } static void vreader_list_unlock(void) { - qemu_mutex_unlock(&vreader_list_mutex); + g_mutex_unlock(&vreader_list_mutex); } static VReaderList * diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c index 6693900201..ab9b2b82d6 100644 --- a/libcacard/vscclient.c +++ b/libcacard/vscclient.c @@ -12,12 +12,10 @@ #ifndef _WIN32 #include <netdb.h> +#define closesocket(x) close(x) #endif -#include <glib.h> #include "qemu-common.h" -#include "qemu/thread.h" -#include "qemu/sockets.h" #include "vscard_common.h" @@ -54,7 +52,7 @@ print_usage(void) { static GIOChannel *channel_socket; static GByteArray *socket_to_send; -static QemuMutex socket_to_send_lock; +static CompatGMutex socket_to_send_lock; static guint socket_tag; static void @@ -103,7 +101,7 @@ send_msg( ) { VSCMsgHeader mhHeader; - qemu_mutex_lock(&socket_to_send_lock); + g_mutex_lock(&socket_to_send_lock); if (verbose > 10) { printf("sending type=%d id=%u, len =%u (0x%x)\n", @@ -117,18 +115,18 @@ send_msg( g_byte_array_append(socket_to_send, (guint8 *)msg, length); g_idle_add(socket_prepare_sending, NULL); - qemu_mutex_unlock(&socket_to_send_lock); + g_mutex_unlock(&socket_to_send_lock); return 0; } static VReader *pending_reader; -static QemuMutex pending_reader_lock; -static QemuCond pending_reader_condition; +static CompatGMutex pending_reader_lock; +static CompatGCond pending_reader_condition; #define MAX_ATR_LEN 40 -static void * -event_thread(void *arg) +static gpointer +event_thread(gpointer arg) { unsigned char atr[MAX_ATR_LEN]; int atr_len; @@ -149,20 +147,20 @@ event_thread(void *arg) /* ignore events from readers qemu has rejected */ /* if qemu is still deciding on this reader, wait to see if need to * forward this event */ - qemu_mutex_lock(&pending_reader_lock); + g_mutex_lock(&pending_reader_lock); if (!pending_reader || (pending_reader != event->reader)) { /* wasn't for a pending reader, this reader has already been * rejected by qemu */ - qemu_mutex_unlock(&pending_reader_lock); + g_mutex_unlock(&pending_reader_lock); vevent_delete(event); continue; } /* this reader hasn't been told its status from qemu yet, wait for * that status */ while (pending_reader != NULL) { - qemu_cond_wait(&pending_reader_condition, &pending_reader_lock); + g_cond_wait(&pending_reader_condition, &pending_reader_lock); } - qemu_mutex_unlock(&pending_reader_lock); + g_mutex_unlock(&pending_reader_lock); /* now recheck the id */ reader_id = vreader_get_id(event->reader); if (reader_id == VSCARD_UNDEFINED_READER_ID) { @@ -178,12 +176,12 @@ event_thread(void *arg) /* wait until qemu has responded to our first reader insert * before we send a second. That way we won't confuse the responses * */ - qemu_mutex_lock(&pending_reader_lock); + g_mutex_lock(&pending_reader_lock); while (pending_reader != NULL) { - qemu_cond_wait(&pending_reader_condition, &pending_reader_lock); + g_cond_wait(&pending_reader_condition, &pending_reader_lock); } pending_reader = vreader_reference(event->reader); - qemu_mutex_unlock(&pending_reader_lock); + g_mutex_unlock(&pending_reader_lock); reader_name = vreader_get_name(event->reader); if (verbose > 10) { printf(" READER INSERT: %s\n", reader_name); @@ -246,7 +244,6 @@ on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming) int num_capabilities = 1 + ((mhHeader->length - sizeof(VSCMsgInit)) / sizeof(uint32_t)); int i; - QemuThread thread_id; incoming->version = ntohl(incoming->version); if (incoming->version != VSCARD_VERSION) { @@ -269,7 +266,7 @@ on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming) send_msg(VSC_ReaderRemove, VSCARD_MINIMAL_READER_ID, NULL, 0); /* launch the event_thread. This will trigger reader adds for all the * existing readers */ - qemu_thread_create(&thread_id, "vsc/event", event_thread, NULL, 0); + g_thread_new("vsc/event", event_thread, NULL); return 0; } @@ -379,26 +376,26 @@ do_socket_read(GIOChannel *source, case VSC_Error: error_msg = (VSCMsgError *) pbSendBuffer; if (error_msg->code == VSC_SUCCESS) { - qemu_mutex_lock(&pending_reader_lock); + g_mutex_lock(&pending_reader_lock); if (pending_reader) { vreader_set_id(pending_reader, mhHeader.reader_id); vreader_free(pending_reader); pending_reader = NULL; - qemu_cond_signal(&pending_reader_condition); + g_cond_signal(&pending_reader_condition); } - qemu_mutex_unlock(&pending_reader_lock); + g_mutex_unlock(&pending_reader_lock); break; } printf("warning: qemu refused to add reader\n"); if (error_msg->code == VSC_CANNOT_ADD_MORE_READERS) { /* clear pending reader, qemu can't handle any more */ - qemu_mutex_lock(&pending_reader_lock); + g_mutex_lock(&pending_reader_lock); if (pending_reader) { pending_reader = NULL; /* make sure the event loop doesn't hang */ - qemu_cond_signal(&pending_reader_condition); + g_cond_signal(&pending_reader_condition); } - qemu_mutex_unlock(&pending_reader_lock); + g_mutex_unlock(&pending_reader_lock); } break; case VSC_Init: @@ -601,7 +598,7 @@ connect_to_qemu( struct addrinfo *server; int ret, sock; - sock = qemu_socket(AF_INET, SOCK_STREAM, 0); + sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { /* Error */ fprintf(stderr, "Error opening socket!\n"); @@ -654,8 +651,20 @@ main( int cert_count = 0; int c, sock; - if (socket_init() != 0) +#ifdef _WIN32 + WSADATA Data; + + if (WSAStartup(MAKEWORD(2, 2), &Data) != 0) { + c = WSAGetLastError(); + fprintf(stderr, "WSAStartup: %d\n", c); return 1; + } +#endif +#if !GLIB_CHECK_VERSION(2, 31, 0) + if (!g_thread_supported()) { + g_thread_init(NULL); + } +#endif while ((c = getopt(argc, argv, "c:e:pd:")) != -1) { switch (c) { @@ -722,13 +731,8 @@ main( } socket_to_send = g_byte_array_new(); - qemu_mutex_init(&socket_to_send_lock); - qemu_mutex_init(&pending_reader_lock); - qemu_cond_init(&pending_reader_condition); - vcard_emul_init(command_line_options); - - loop = g_main_loop_new(NULL, true); + loop = g_main_loop_new(NULL, TRUE); printf("> "); fflush(stdout); |