From 1a4af67d32b1c39b73e09346203f3e12c00b9e41 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 31 Jan 2012 16:06:14 +0000 Subject: mini-os: use BSD sys/queue.h instead of Linux list.h The latter is GPL which makes the whole of mini-os GPL rather than BSD as intended. In tree users are all GPL or GPL-compatible but we should fix this so that mini-os is BSD. Do so by using the same BSD sys/queue.h as we use in libxl. Tested with the builtin mini-os test app and qemu stubdomain, both of which appear to still function as expected. Move tools/libxl/external and the associated sed script to tools/include/xen-external to allow more sensible access from mini-os. Also add s/NULL/0/ in the sed script due to NULL not always being defined in stubdom code when mini-os/wait.h is included. As well as the obvious ABI changes there are a few API updates associated with the change: - struct rw_semaphore.wait_list is unused - remove_waiter needs to take the wait_queue_head The latter requires a qemu update, so there is also a QEMU_TAG update in this changeset. I sprinkled some extra-emacs local variables around the files I edited which didn't have them. I think this should be backported to the stable branches since external users of mini-os may have been mislead into thinking they could safely link mini-os against GPL-incompatible code. Signed-off-by: Ian Campbell Committed-by: Ian Jackson --- extras/mini-os/lib/sys.c | 38 +++++++++++++++++++------------------- extras/mini-os/lib/xmalloc.c | 43 ++++++++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 40 deletions(-) (limited to 'extras/mini-os/lib') diff --git a/extras/mini-os/lib/sys.c b/extras/mini-os/lib/sys.c index b7b3aff50a..2329a78c21 100644 --- a/extras/mini-os/lib/sys.c +++ b/extras/mini-os/lib/sys.c @@ -234,7 +234,7 @@ int read(int fd, void *buf, size_t nbytes) break; schedule(); } - remove_waiter(w); + remove_waiter(w, console_queue); return ret; } #ifdef HAVE_LWIP @@ -705,12 +705,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, fd_set myread, mywrite, myexcept; struct thread *thread = get_current(); s_time_t start = NOW(), stop; - DEFINE_WAIT(w1); - DEFINE_WAIT(w2); - DEFINE_WAIT(w3); - DEFINE_WAIT(w4); - DEFINE_WAIT(w5); - DEFINE_WAIT(w6); + DEFINE_WAIT(netfront_w); + DEFINE_WAIT(event_w); + DEFINE_WAIT(blkfront_w); + DEFINE_WAIT(xenbus_watch_w); + DEFINE_WAIT(kbdfront_w); + DEFINE_WAIT(console_w); assert(thread == main_thread); @@ -727,12 +727,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, /* Tell people we're going to sleep before looking at what they are * saying, hence letting them wake us if events happen between here and * schedule() */ - add_waiter(w1, netfront_queue); - add_waiter(w2, event_queue); - add_waiter(w3, blkfront_queue); - add_waiter(w4, xenbus_watch_queue); - add_waiter(w5, kbdfront_queue); - add_waiter(w6, console_queue); + add_waiter(netfront_w, netfront_queue); + add_waiter(event_w, event_queue); + add_waiter(blkfront_w, blkfront_queue); + add_waiter(xenbus_watch_w, xenbus_watch_queue); + add_waiter(kbdfront_w, kbdfront_queue); + add_waiter(console_w, console_queue); if (readfds) myread = *readfds; @@ -814,12 +814,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, ret = -1; out: - remove_waiter(w1); - remove_waiter(w2); - remove_waiter(w3); - remove_waiter(w4); - remove_waiter(w5); - remove_waiter(w6); + remove_waiter(netfront_w, netfront_queue); + remove_waiter(event_w, event_queue); + remove_waiter(blkfront_w, blkfront_queue); + remove_waiter(xenbus_watch_w, xenbus_watch_queue); + remove_waiter(kbdfront_w, kbdfront_queue); + remove_waiter(console_w, console_queue); return ret; } diff --git a/extras/mini-os/lib/xmalloc.c b/extras/mini-os/lib/xmalloc.c index c7d3fc1b30..015cd31bb9 100644 --- a/extras/mini-os/lib/xmalloc.c +++ b/extras/mini-os/lib/xmalloc.c @@ -44,16 +44,18 @@ #include #ifndef HAVE_LIBC -static MINIOS_LIST_HEAD(freelist); /* static spinlock_t freelist_lock = SPIN_LOCK_UNLOCKED; */ struct xmalloc_hdr { /* Total including this hdr, unused padding and second hdr. */ size_t size; - struct minios_list_head freelist; + MINIOS_TAILQ_ENTRY(struct xmalloc_hdr) freelist; } __cacheline_aligned; +static MINIOS_TAILQ_HEAD(,struct xmalloc_hdr) freelist = + MINIOS_TAILQ_HEAD_INITIALIZER(freelist); + /* Unused padding data between the two hdrs. */ struct xmalloc_pad @@ -82,7 +84,7 @@ static void maybe_split(struct xmalloc_hdr *hdr, size_t size, size_t block) extra = (struct xmalloc_hdr *)((unsigned long)hdr + size); extra->size = leftover; /* spin_lock_irqsave(&freelist_lock, flags); */ - minios_list_add(&extra->freelist, &freelist); + MINIOS_TAILQ_INSERT_HEAD(&freelist, extra, freelist); /* spin_unlock_irqrestore(&freelist_lock, flags); */ } else @@ -91,8 +93,6 @@ static void maybe_split(struct xmalloc_hdr *hdr, size_t size, size_t block) } hdr->size = size; - /* Debugging aid. */ - hdr->freelist.next = hdr->freelist.prev = NULL; } static struct xmalloc_hdr *xmalloc_new_page(size_t size) @@ -128,8 +128,6 @@ static void *xmalloc_whole_pages(size_t size, size_t align) return NULL; hdr->size = (1UL << (pageorder + PAGE_SHIFT)); - /* Debugging aid. */ - hdr->freelist.next = hdr->freelist.prev = NULL; ret = (char*)hdr + hdr_size; pad = (struct xmalloc_pad *) ret - 1; @@ -155,14 +153,14 @@ void *_xmalloc(size_t size, size_t align) /* Search free list. */ /* spin_lock_irqsave(&freelist_lock, flags); */ - minios_list_for_each_entry_safe( i, tmp, &freelist, freelist ) + MINIOS_TAILQ_FOREACH_SAFE(i, &freelist, freelist, tmp) { data_begin = align_up((uintptr_t)i + hdr_size, align); if ( data_begin + size > (uintptr_t)i + i->size ) continue; - minios_list_del(&i->freelist); + MINIOS_TAILQ_REMOVE(&freelist, i, freelist); /* spin_unlock_irqrestore(&freelist_lock, flags); */ uintptr_t size_before = (data_begin - hdr_size) - (uintptr_t)i; @@ -173,7 +171,7 @@ void *_xmalloc(size_t size, size_t align) new_i->size = i->size - size_before; i->size = size_before; /* spin_lock_irqsave(&freelist_lock, flags); */ - minios_list_add(&i->freelist, &freelist); + MINIOS_TAILQ_INSERT_HEAD(&freelist, i, freelist); /* spin_unlock_irqrestore(&freelist_lock, flags); */ i = new_i; } @@ -224,16 +222,9 @@ void xfree(const void *p) *(int*)0=0; } - /* Not previously freed. */ - if(hdr->freelist.next || hdr->freelist.prev) - { - printk("Should not be previously freed\n"); - *(int*)0=0; - } - /* Merge with other free block, or put in list. */ /* spin_lock_irqsave(&freelist_lock, flags); */ - minios_list_for_each_entry_safe( i, tmp, &freelist, freelist ) + MINIOS_TAILQ_FOREACH_SAFE(i, &freelist, freelist, tmp) { unsigned long _i = (unsigned long)i; unsigned long _hdr = (unsigned long)hdr; @@ -245,7 +236,7 @@ void xfree(const void *p) /* We follow this block? Swallow it. */ if ( (_i + i->size) == _hdr ) { - minios_list_del(&i->freelist); + MINIOS_TAILQ_REMOVE(&freelist, i, freelist); i->size += hdr->size; hdr = i; } @@ -253,7 +244,7 @@ void xfree(const void *p) /* We precede this block? Swallow it. */ if ( (_hdr + hdr->size) == _i ) { - minios_list_del(&i->freelist); + MINIOS_TAILQ_REMOVE(&freelist, i, freelist); hdr->size += i->size; } } @@ -270,7 +261,7 @@ void xfree(const void *p) } else { - minios_list_add(&hdr->freelist, &freelist); + MINIOS_TAILQ_INSERT_HEAD(&freelist, hdr, freelist); } /* spin_unlock_irqrestore(&freelist_lock, flags); */ @@ -306,3 +297,13 @@ void *_realloc(void *ptr, size_t size) return new; } #endif + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ -- cgit v1.2.3