Index: uspace/lib/block/libblock.c
===================================================================
--- uspace/lib/block/libblock.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/block/libblock.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -51,4 +51,6 @@
 #include <macros.h>
 #include <mem.h>
+#include <malloc.h>
+#include <stdio.h>
 #include <sys/typefmt.h>
 #include <stacktrace.h>
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/Makefile	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -41,12 +41,23 @@
 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
 
+LINKER_SCRIPTS = \
+	$(LIBC_PREFIX)/arch/$(UARCH)/_link.ld \
+	$(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld \
+	$(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld \
+	$(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
+
 PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH)
-EXTRA_OUTPUT = $(LINKER_SCRIPT)
-EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPT)
+EXTRA_OUTPUT = $(LINKER_SCRIPTS)
+EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPTS)
 LIBRARY = libc
+SLIBRARY = libc.so.0.0
+LSONAME = libc.so0
+
 
 -include $(COMMON_MAKEFILE)
 -include $(CONFIG_MAKEFILE)
 -include arch/$(UARCH)/Makefile.inc
+
+EXTRA_CFLAGS += -I../../srv/loader/include
 
 GENERIC_SOURCES = \
@@ -98,4 +109,5 @@
 	generic/adt/measured_strings.c \
 	generic/adt/char_map.c \
+	generic/adt/prodcons.c \
 	generic/time.c \
 	generic/stdlib.c \
@@ -114,5 +126,16 @@
 	generic/arg_parse.c \
 	generic/sort.c \
-	generic/stats.c
+	generic/stats.c \
+	generic/assert.c
+
+ifeq ($(CONFIG_RTLD), y)
+	GENERIC_SOURCES += \
+		generic/dlfcn.c \
+		generic/rtld/rtld.c \
+		generic/rtld/elf_load.c \
+		generic/rtld/dynamic.c \
+		generic/rtld/module.c \
+		generic/rtld/symbol.c
+endif
 
 SOURCES = \
@@ -133,6 +156,15 @@
 	ln -sfn ../$< $@
 
-$(LINKER_SCRIPT): $(LINKER_SCRIPT).in
+$(LIBC_PREFIX)/arch/$(UARCH)/_link.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
 	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -E -x c $< | grep -v "^\#" > $@
+
+$(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
+	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DLOADER -E -x c $< | grep -v "^\#" > $@
+
+$(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
+	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DSHLIB -E -x c $< | grep -v "^\#" > $@
+
+$(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
+	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DDLEXE -E -x c $< | grep -v "^\#" > $@
 
 $(COMMON_HEADER_ARCH): $(COMMON_HEADER)
Index: uspace/lib/c/arch/abs32le/Makefile.inc
===================================================================
--- uspace/lib/c/arch/abs32le/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/abs32le/Makefile.inc	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.c \
+	arch/$(UARCH)/src/entryjmp.c \
 	arch/$(UARCH)/src/thread_entry.c \
 	arch/$(UARCH)/src/fibril.c \
Index: uspace/lib/c/arch/abs32le/_link.ld.in
===================================================================
--- uspace/lib/c/arch/abs32le/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/abs32le/_link.ld.in	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.text : {
 		*(.text .text.*);
Index: uspace/lib/c/arch/abs32le/src/entryjmp.c
===================================================================
--- uspace/lib/c/arch/abs32le/src/entryjmp.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/abs32le/src/entryjmp.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#include <bool.h>
+#include <entry_point.h>
+
+/** Jump to program entry point. */
+void entry_point_jmp(void *entry_point, void *pcb)
+{
+	while (true);
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/c/arch/amd64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/amd64/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/amd64/Makefile.inc	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.S \
Index: uspace/lib/c/arch/amd64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/amd64/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/amd64/_link.ld.in	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -3,5 +3,10 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 	debug PT_NOTE;
@@ -9,6 +14,13 @@
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/amd64/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/amd64/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/amd64/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# %rdi	contains entry_point
+# %rsi	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	# pcb must be passed in %rdi, use %rdx as a scratch register
+	mov %rdi, %rdx
+	mov %rsi, %rdi
+
+	# jump to entry point
+	jmp %rdx
Index: uspace/lib/c/arch/arm32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/arm32/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/arm32/Makefile.inc	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -30,4 +30,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.c \
Index: uspace/lib/c/arch/arm32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/arm32/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/arm32/_link.ld.in	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/arm32/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/arm32/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/arm32/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# r0	contains entry_point
+# r1	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	# load ras_page address to r2
+	ldr r2, =ras_page
+	ldr r2, [r2]
+	# pcb is passed to the entry point in r1 (where it already is)
+	mov r15, r0
Index: uspace/lib/c/arch/ia32/Makefile.common
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.common	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/Makefile.common	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -28,5 +28,5 @@
 
 CLANG_ARCH = i386
-GCC_CFLAGS += -march=pentium
+GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer
 
 ENDIANESS = LE
Index: uspace/lib/c/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/Makefile.inc	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.S \
@@ -35,5 +36,7 @@
 	arch/$(UARCH)/src/setjmp.S \
 	arch/$(UARCH)/src/stacktrace.c \
-	arch/$(UARCH)/src/stacktrace_asm.S
+	arch/$(UARCH)/src/stacktrace_asm.S \
+	arch/$(UARCH)/src/rtld/dynamic.c \
+	arch/$(UARCH)/src/rtld/reloc.c
 
 .PRECIOUS: arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/ia32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ia32/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/_link.ld.in	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -1,14 +1,32 @@
+#ifndef SHLIB
 STARTUP(LIBC_PATH/arch/UARCH/src/entry.o)
 ENTRY(__entry)
+#endif
 
 PHDRS {
+#if defined(LOADER) || defined(DLEXE)
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
+#if defined(SHLIB) || defined(DLEXE)
+	dynamic PT_DYNAMIC;
+#endif
 	debug PT_NOTE;
 }
 
 SECTIONS {
+#if defined(LOADER) || defined(DLEXE)
+	.interp : {
+		*(.interp);
+	} :interp
+#endif
+#ifdef LOADER
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
@@ -19,6 +37,40 @@
 		*(.rodata .rodata.*);
 	} :text
+
+#if defined(SHLIB) || defined(DLEXE)
+	.rel.plt : {
+		*(.rel.plt);
+	}
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
 	
+	.plt : {
+		*(.plt);
+	} :text
+	
+	.dynsym : {
+		*(.dynsym);
+	} :text
+	
+	.dynstr : {
+		*(.dynstr);
+	} :text
+	
+	.hash : {
+		*(.hash);
+	} :text
+#endif
 	. = . + 0x1000;
+	
+#if defined(SHLIB) || defined(DLEXE)
+	.dynamic : {
+		*(.dynamic);
+	} :data :dynamic
+#endif
 	
 	.data : {
@@ -26,4 +78,18 @@
 	} :data
 	
+#if defined(SHLIB) || defined(DLEXE)
+	.data.rel : {
+                *(.data.rel .data.rel.*);
+	} :data
+
+	.got : {
+                *(.got);
+	} :data
+	.got.plt : {
+                *(.got.plt);
+	} :data
+#endif
+	
+#ifndef DLEXE
 	.tdata : {
 		_tdata_start = .;
@@ -37,6 +103,8 @@
 	
 	_tls_alignment = ALIGNOF(.tdata);
+#endif
 	
 	.bss : {
+		*(.dynbss);
 		*(COMMON);
 		*(.bss);
Index: uspace/lib/c/arch/ia32/include/config.h
===================================================================
--- uspace/lib/c/arch/ia32/include/config.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/include/config.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -36,6 +36,9 @@
 #define LIBC_ia32_CONFIG_H_
 
-#define PAGE_WIDTH	12
-#define PAGE_SIZE	(1 << PAGE_WIDTH)
+#define PAGE_WIDTH  12
+#define PAGE_SIZE   (1 << PAGE_WIDTH)
+
+#define USER_ADDRESS_SPACE_START_ARCH  UINT32_C(0x00000000)
+#define USER_ADDRESS_SPACE_END_ARCH    UINT32_C(0x7fffffff)
 
 #endif
Index: uspace/lib/c/arch/ia32/include/ddi.h
===================================================================
--- uspace/lib/c/arch/ia32/include/ddi.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/include/ddi.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -37,5 +37,5 @@
 #include <libarch/types.h>
 
-#define IO_SPACE_BOUNDARY	((void *) (64 * 1024))
+#define IO_SPACE_BOUNDARY  ((void *) (64 * 1024))
 
 static inline uint8_t pio_read_8(ioport8_t *port)
Index: uspace/lib/c/arch/ia32/include/faddr.h
===================================================================
--- uspace/lib/c/arch/ia32/include/faddr.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/include/faddr.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -38,5 +38,5 @@
 #include <libarch/types.h>
 
-#define FADDR(fptr)		((uintptr_t) (fptr))
+#define FADDR(fptr)  ((uintptr_t) (fptr))
 
 #endif
Index: uspace/lib/c/arch/ia32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/ia32/include/fibril.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/include/fibril.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -42,5 +42,5 @@
  * panic sooner or later
  */
-#define SP_DELTA     (12)
+#define SP_DELTA  12
 
 #define context_set(c, _pc, stack, size, ptls) \
@@ -51,6 +51,7 @@
 		(c)->ebp = 0; \
 	} while (0)
-	
-/* We include only registers that must be preserved
+
+/*
+ * We include only registers that must be preserved
  * during function call
  */
Index: uspace/lib/c/arch/ia32/include/rtld/dynamic.h
===================================================================
--- uspace/lib/c/arch/ia32/include/rtld/dynamic.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/ia32/include/rtld/dynamic.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ia32_RTLD_DYNAMIC_H_
+#define LIBC_ia32_RTLD_DYNAMIC_H_
+
+#include <sys/types.h>
+
+typedef struct {
+	/* Empty. */
+} dyn_info_arch_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h
===================================================================
--- uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ia32_RTLD_ELF_DYN_H_
+#define LIBC_ia32_RTLD_ELF_DYN_H_
+
+/* 
+ * ia32 dynamic relocation types
+ */
+
+#define R_386_32	1
+#define R_386_PC32	2
+#define R_386_COPY	5
+#define R_386_GLOB_DAT	6
+#define R_386_JUMP_SLOT	7
+#define R_386_RELATIVE	8
+
+#define R_386_TLS_DTPMOD32 35
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/ia32/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/ia32/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# Jump to program entry point
+entry_point_jmp:
+	# Use standard ia32 prologue not to confuse anybody
+	push %ebp
+	movl %esp, %ebp
+
+	# %eax := entry_point
+	movl 0x8(%ebp), %eax
+
+	# %edi := pcb
+	# pcb is passed to the entry point in %edi
+	mov 0xc(%ebp), %edi
+
+	# Save a tiny bit of stack space
+	pop %ebp
+
+	jmp *%eax
Index: uspace/lib/c/arch/ia32/src/rtld/dynamic.c
===================================================================
--- uspace/lib/c/arch/ia32/src/rtld/dynamic.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/ia32/src/rtld/dynamic.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcia32
+ * @brief
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <rtld/elf_dyn.h>
+#include <rtld/dynamic.h>
+
+void dyn_parse_arch(elf_dyn_t *dp, size_t bias, dyn_info_t *info)
+{
+	(void) dp;
+	(void) bias;
+	(void) info;
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/src/rtld/reloc.c
===================================================================
--- uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcia32
+ * @brief
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libarch/rtld/elf_dyn.h>
+#include <rtld/symbol.h>
+#include <rtld/rtld.h>
+#include <rtld/rtld_debug.h>
+#include <rtld/rtld_arch.h>
+
+void module_process_pre_arch(module_t *m)
+{
+	/* Unused */
+}
+
+
+/**
+ * Process (fixup) all relocations in a relocation table.
+ */
+void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size)
+{
+	unsigned i;
+
+	size_t rt_entries;
+	size_t r_offset;
+	elf_word r_info;
+	unsigned rel_type;
+	elf_word sym_idx;
+	uint32_t sym_addr;
+	
+	elf_symbol_t *sym_table;
+	elf_symbol_t *sym;
+	uint32_t *r_ptr;
+	uint32_t sym_size;
+	char *str_tab;
+	
+	elf_symbol_t *sym_def;
+	module_t *dest;
+
+	DPRINTF("parse relocation table\n");
+
+	sym_table = m->dyn.sym_tab;
+	rt_entries = rt_size / sizeof(elf_rel_t);
+	str_tab = m->dyn.str_tab;
+
+	DPRINTF("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries);
+	
+	for (i = 0; i < rt_entries; ++i) {
+//		DPRINTF("symbol %d: ", i);
+		r_offset = rt[i].r_offset;
+		r_info = rt[i].r_info;
+
+		sym_idx = ELF32_R_SYM(r_info);
+		sym = &sym_table[sym_idx];
+
+/*		DPRINTF("name '%s', value 0x%x, size 0x%x\n",
+		    str_tab + sym->st_name,
+		    sym->st_value,
+		    sym->st_size);
+*/
+		rel_type = ELF32_R_TYPE(r_info);
+		r_ptr = (uint32_t *)(r_offset + m->bias);
+
+		if (sym->st_name != 0) {
+//			DPRINTF("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
+			sym_def = symbol_def_find(str_tab + sym->st_name,
+			    m, &dest);
+//			DPRINTF("dest name: '%s'\n", dest->dyn.soname);
+//			DPRINTF("dest bias: 0x%x\n", dest->bias);
+			if (sym_def) {
+				sym_addr = (uint32_t)
+				    symbol_get_addr(sym_def, dest);
+//				DPRINTF("symbol definition found, addr=0x%x\n", sym_addr);
+			} else {
+				printf("Definition of '%s' not found.\n",
+				    str_tab + sym->st_name);
+				continue;
+			}
+		} else {
+			sym_addr = 0;
+			sym_def = NULL;
+		}
+
+		switch (rel_type) {
+		case R_386_GLOB_DAT:
+		case R_386_JUMP_SLOT:
+			DPRINTF("fixup R_386_GLOB_DAT/JUMP_SLOT (b+v)\n");
+			*r_ptr = sym_addr;
+			break;
+
+		case R_386_32:
+			DPRINTF("fixup R_386_32 (b+v+a)\n");
+			*r_ptr += sym_addr;
+			break;
+
+		case R_386_PC32:
+			DPRINTF("fixup R_386_PC32 (b+v+a-p)\n");
+			*r_ptr += sym_addr - (uint32_t) r_ptr;
+			break;
+
+		case R_386_COPY:
+			/*
+			 * Copy symbol data from shared object to specified
+			 * location.
+			 */
+			DPRINTF("fixup R_386_COPY (s)\n");
+			sym_size = sym->st_size;
+			if (sym_size != sym_def->st_size) {
+				printf("Warning: Mismatched symbol sizes.\n");
+				/* Take the lower value. */
+				if (sym_size > sym_def->st_size)
+					sym_size = sym_def->st_size;
+			}
+			memcpy(r_ptr, (const void *)sym_addr, sym_size);
+			break;
+			
+		case R_386_RELATIVE:
+			DPRINTF("fixup R_386_RELATIVE (b+a)\n");
+			*r_ptr += m->bias;
+			break;
+
+		case R_386_TLS_DTPMOD32:
+			/*
+			 * We can ignore this as long as the only module
+			 * with TLS variables is libc.so.
+			 */
+			DPRINTF("Ignoring R_386_TLS_DTPMOD32\n");
+			break;
+
+		default:
+			printf("Error: Unknown relocation type %d\n",
+			    rel_type);
+			exit(1);
+		}
+
+	}
+
+}
+
+void rela_table_process(module_t *m, elf_rela_t *rt, size_t rt_size)
+{
+	/* Unused */
+	(void)m; (void)rt; (void)rt_size;
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/src/stacktrace.c
===================================================================
--- uspace/lib/c/arch/ia32/src/stacktrace.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/src/stacktrace.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -35,16 +35,16 @@
  */
 
+#include <libarch/config.h>
 #include <sys/types.h>
 #include <bool.h>
-
 #include <stacktrace.h>
 
-#define FRAME_OFFSET_FP_PREV	0
-#define FRAME_OFFSET_RA		4
+#define FRAME_OFFSET_FP_PREV  0
+#define FRAME_OFFSET_RA       4
 
 bool stacktrace_fp_valid(stacktrace_t *st, uintptr_t fp)
 {
 	(void) st;
-	return fp != 0;
+	return (fp != 0) && (fp <= USER_ADDRESS_SPACE_END_ARCH);
 }
 
Index: uspace/lib/c/arch/ia32/src/syscall.S
===================================================================
--- uspace/lib/c/arch/ia32/src/syscall.S	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/src/syscall.S	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -32,4 +32,5 @@
 __syscall_fast_func:
 	.long __syscall_slow
+	.size __syscall_fast_func, . - __syscall_fast_func
 
 .text
@@ -71,4 +72,6 @@
  */
 .global __syscall_fast
+	.type __syscall_fast, @function
+
 __syscall_fast:
 	pushl %ebx
@@ -95,2 +98,4 @@
 	popl %ebx
 	ret
+
+	.size __syscall_fast, . - __syscall_fast
Index: uspace/lib/c/arch/ia32/src/tls.c
===================================================================
--- uspace/lib/c/arch/ia32/src/tls.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/src/tls.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -37,4 +37,5 @@
 #include <tls.h>
 #include <sys/types.h>
+#include <align.h>
 
 tcb_t * __alloc_tls(void **data, size_t size)
@@ -48,4 +49,31 @@
 }
 
+/*
+ * Rtld TLS support
+ */
+
+typedef struct {
+	unsigned long int ti_module;
+	unsigned long int ti_offset;
+} tls_index;
+
+void __attribute__ ((__regparm__ (1)))
+    *___tls_get_addr(tls_index *ti);
+
+void __attribute__ ((__regparm__ (1)))
+    *___tls_get_addr(tls_index *ti)
+{
+	size_t tls_size;
+	uint8_t *tls;
+
+	/* Calculate size of TLS block */
+	tls_size = ALIGN_UP(&_tbss_end - &_tdata_start, &_tls_alignment);
+
+	/* The TLS block is just before TCB */
+	tls = (uint8_t *)__tcb_get() - tls_size;
+
+	return tls + ti->ti_offset;
+}
+
 /** @}
  */
Index: uspace/lib/c/arch/ia64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia64/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia64/Makefile.inc	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.S \
Index: uspace/lib/c/arch/ia64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ia64/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia64/_link.ld.in	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -3,11 +3,29 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
 	text PT_LOAD FLAGS(5);
+#else
+	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x800000000 + SIZEOF_HEADERS;
+#else
 	. = 0x4000 + SIZEOF_HEADERS;
-	
+#endif
+	/*
+	 * XXX This is just a work around. Problem: .init section does not
+	 * have the proper alignment.
+	 */
+	. = ALIGN(., 16);
+
 	.init : {
 		*(.init);
@@ -22,5 +40,6 @@
 	
 	.got : {
-		_gp = .;
+		/* Tell the linker where we expect GP to point. */
+		__gp = .;
 		*(.got .got.*);
 	} :data
Index: uspace/lib/c/arch/ia64/src/entry.s
===================================================================
--- uspace/lib/c/arch/ia64/src/entry.s	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia64/src/entry.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -39,5 +39,5 @@
 __entry:
 	alloc loc0 = ar.pfs, 0, 1, 2, 0
-	movl gp = _gp
+	movl gp = __gp
 	
 	# Pass PCB pointer as the first argument to __main
Index: uspace/lib/c/arch/ia64/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/ia64/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/ia64/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# in0 (r32)	contains entry_point
+# in1 (r33)	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	# Pass pcb to the entry point in r2
+
+	mov b6 = r32
+	mov r2 = r33 ;;
+	br b6 ;;
Index: uspace/lib/c/arch/ia64/src/thread_entry.s
===================================================================
--- uspace/lib/c/arch/ia64/src/thread_entry.s	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia64/src/thread_entry.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -37,5 +37,5 @@
 	alloc loc0 = ar.pfs, 0, 1, 1, 0
 
-	movl gp = _gp
+	movl gp = __gp
 	
 	#
Index: uspace/lib/c/arch/mips32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/mips32/Makefile.inc	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.c \
Index: uspace/lib/c/arch/mips32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/mips32/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/mips32/_link.ld.in	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70004000 + SIZEOF_HEADERS;
+#else
 	. = 0x4000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/mips32/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/mips32/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/mips32/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+.section .text
+.global entry_point_jmp
+.set noreorder
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# $a0 (=$4)	contains entry_point
+# $a1 (=$5)	contains pcb
+#
+# Jump to program entry point
+.ent entry_point_jmp
+entry_point_jmp:
+	# tmp := entry_point
+	move $25, $a0
+
+	# Pass pcb to the entry point in $a0
+	move $a0, $a1
+	jr $25
+	nop
+.end
Index: uspace/lib/c/arch/mips32eb/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32eb/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/mips32eb/Makefile.inc	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.c \
Index: uspace/lib/c/arch/ppc32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ppc32/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ppc32/Makefile.inc	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.c \
Index: uspace/lib/c/arch/ppc32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ppc32/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ppc32/_link.ld.in	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/ppc32/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/ppc32/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/ppc32/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# %r3	contains entry_point
+# %r4	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	mtctr %r3
+	mr %r6, %r4	# Pass pcb to the entry point in %r6
+	bctr
Index: uspace/lib/c/arch/sparc64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/sparc64/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/sparc64/Makefile.inc	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/fibril.S \
Index: uspace/lib/c/arch/sparc64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/sparc64/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/sparc64/_link.ld.in	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70004000 + SIZEOF_HEADERS;
+#else
 	. = 0x4000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/sparc64/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/sparc64/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/arch/sparc64/src/entryjmp.s	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# %o0	contains entry_point
+# %o1	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	# Pass pcb pointer to entry point in %o1. As it is already
+	# there, no action is needed.
+	call %o0
+	nop
+	# fixme: use branch instead of call
Index: uspace/lib/c/generic/adt/prodcons.c
===================================================================
--- uspace/lib/c/generic/adt/prodcons.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/generic/adt/prodcons.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#include <adt/prodcons.h>
+#include <adt/list.h>
+#include <fibril_synch.h>
+
+void prodcons_initialize(prodcons_t *pc)
+{
+	list_initialize(&pc->list);
+	fibril_mutex_initialize(&pc->mtx);
+	fibril_condvar_initialize(&pc->cv);
+}
+
+void prodcons_produce(prodcons_t *pc, link_t *item)
+{
+	fibril_mutex_lock(&pc->mtx);
+	
+	list_append(item, &pc->list);
+	fibril_condvar_signal(&pc->cv);
+	
+	fibril_mutex_unlock(&pc->mtx);
+}
+
+link_t *prodcons_consume(prodcons_t *pc)
+{
+	fibril_mutex_lock(&pc->mtx);
+	
+	while (list_empty(&pc->list))
+		fibril_condvar_wait(&pc->cv, &pc->mtx);
+	
+	link_t *head = pc->list.next;
+	list_remove(head);
+	
+	fibril_mutex_unlock(&pc->mtx);
+	
+	return head;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/as.c
===================================================================
--- uspace/lib/c/generic/as.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/as.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -52,5 +52,5 @@
  *
  */
-void *as_area_create(void *address, size_t size, int flags)
+void *as_area_create(void *address, size_t size, unsigned int flags)
 {
 	return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address,
@@ -68,5 +68,5 @@
  *
  */
-int as_area_resize(void *address, size_t size, int flags)
+int as_area_resize(void *address, size_t size, unsigned int flags)
 {
 	return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address,
@@ -96,5 +96,5 @@
  *
  */
-int as_area_change_flags(void *address, int flags)
+int as_area_change_flags(void *address, unsigned int flags)
 {
 	return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address,
Index: uspace/lib/c/generic/assert.c
===================================================================
--- uspace/lib/c/generic/assert.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/generic/assert.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stacktrace.h>
+
+void assert_abort(const char *cond, const char *file, unsigned int line)
+{
+	printf("Assertion failed (%s) in file \"%s\", line %u.\n",
+	    cond, file, line);
+	stacktrace_print();
+	abort();
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/async.c
===================================================================
--- uspace/lib/c/generic/async.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/async.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -102,4 +102,6 @@
 #include <arch/barrier.h>
 #include <bool.h>
+#include <stdlib.h>
+#include <malloc.h>
 #include "private/async.h"
 
Index: uspace/lib/c/generic/async_sess.c
===================================================================
--- uspace/lib/c/generic/async_sess.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/async_sess.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -105,4 +105,5 @@
 #include <errno.h>
 #include <assert.h>
+#include <async.h>
 #include "private/async_sess.h"
 
Index: uspace/lib/c/generic/dlfcn.c
===================================================================
--- uspace/lib/c/generic/dlfcn.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/generic/dlfcn.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+#include <rtld/module.h>
+#include <rtld/symbol.h>
+
+void *dlopen(const char *path, int flag)
+{
+	module_t *m;
+
+	if (runtime_env == NULL) {
+		printf("Dynamic linker not set up -- initializing.\n");
+		rtld_init_static();
+	}
+
+	printf("dlopen(\"%s\", %d)\n", path, flag);
+
+	printf("module_find('%s')\n", path);
+	m = module_find(path);
+	if (m == NULL) {
+		printf("NULL. module_load('%s')\n", path);
+		m = module_load(path);
+		printf("module_load_deps(m)\n");
+		module_load_deps(m);
+		/* Now relocate. */
+		printf("module_process_relocs(m)\n");
+		module_process_relocs(m);
+	} else {
+		printf("not NULL\n");
+	}
+
+	return (void *) m;
+}
+
+/*
+ * @note Symbols with NULL values are not accounted for.
+ */
+void *dlsym(void *mod, const char *sym_name)
+{
+	elf_symbol_t *sd;
+	module_t *sm;
+
+	printf("dlsym(0x%lx, \"%s\")\n", (long)mod, sym_name);
+	sd = symbol_bfs_find(sym_name, (module_t *) mod, &sm);
+	if (sd != NULL) {
+		return symbol_get_addr(sd, sm);
+	}
+
+	return NULL;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/errno.c
===================================================================
--- uspace/lib/c/generic/errno.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/errno.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -36,5 +36,10 @@
 #include <fibril.h>
 
-int _errno;
+static fibril_local int fibril_errno;
+
+int *__errno(void)
+{
+	return &fibril_errno;
+}
 
 /** @}
Index: uspace/lib/c/generic/event.c
===================================================================
--- uspace/lib/c/generic/event.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/event.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -41,14 +41,28 @@
 #include <kernel/ipc/event_types.h>
 
-/** Subscribe for event notifications.
+/** Subscribe event notifications.
  *
- * @param evno   Event number.
- * @param method Use this method for notifying me.
+ * @param evno    Event type to subscribe.
+ * @param imethod Use this interface and method for notifying me.
  *
  * @return Value returned by the kernel.
+ *
  */
-int event_subscribe(event_type_t e, sysarg_t method)
+int event_subscribe(event_type_t evno, sysarg_t imethod)
 {
-	return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) e, (sysarg_t) method);
+	return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno,
+	    (sysarg_t) imethod);
+}
+
+/** Unmask event notifications.
+ *
+ * @param evno Event type to unmask.
+ *
+ * @return Value returned by the kernel.
+ *
+ */
+int event_unmask(event_type_t evno)
+{
+	return __SYSCALL1(SYS_EVENT_UNMASK, (sysarg_t) evno);
 }
 
Index: uspace/lib/c/generic/fibril_synch.c
===================================================================
--- uspace/lib/c/generic/fibril_synch.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/fibril_synch.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -43,4 +43,5 @@
 #include <stacktrace.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include "private/async.h"
 
Index: uspace/lib/c/generic/io/io.c
===================================================================
--- uspace/lib/c/generic/io/io.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/io/io.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -173,4 +173,5 @@
 		}
 		*flags = (O_APPEND | O_CREAT) | (plus ? O_RDWR : O_WRONLY);
+		break;
 	default:
 		errno = EINVAL;
Index: uspace/lib/c/generic/libc.c
===================================================================
--- uspace/lib/c/generic/libc.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/libc.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -53,4 +53,8 @@
 #include "private/io.h"
 
+#ifdef CONFIG_RTLD
+#include <rtld/rtld.h>
+#endif
+
 static bool env_setup = false;
 
@@ -77,4 +81,9 @@
 	char **argv;
 	
+#ifdef __IN_SHARED_LIBC__
+	if (__pcb != NULL && __pcb->rtld_runtime != NULL) {
+		runtime_env = (runtime_env_t *) __pcb->rtld_runtime;
+	}
+#endif
 	/*
 	 * Get command line arguments and initialize
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/malloc.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -44,4 +44,5 @@
 #include <mem.h>
 #include <futex.h>
+#include <stdlib.h>
 #include <adt/gcdlcm.h>
 #include "private/malloc.h"
Index: uspace/lib/c/generic/rtld/dynamic.c
===================================================================
--- uspace/lib/c/generic/rtld/dynamic.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/generic/rtld/dynamic.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+
+#include <rtld/elf_dyn.h>
+#include <rtld/dynamic.h>
+#include <rtld/rtld.h>
+#include <rtld/rtld_debug.h>
+
+void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info)
+{
+	elf_dyn_t *dp = dyn_ptr;
+
+	void *d_ptr;
+	elf_word d_val;
+
+	elf_word soname_idx;
+	elf_word rpath_idx;
+
+	DPRINTF("memset\n");
+	memset(info, 0, sizeof(dyn_info_t));
+
+	soname_idx = 0;
+	rpath_idx = 0;
+
+	DPRINTF("pass 1\n");
+	while (dp->d_tag != DT_NULL) {
+		d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias);
+		d_val = dp->d_un.d_val;
+		DPRINTF("tag=%u ptr=0x%x val=%u\n", (unsigned)dp->d_tag,
+			(unsigned)d_ptr, (unsigned)d_val);
+
+		switch (dp->d_tag) {
+
+		case DT_PLTRELSZ:	info->plt_rel_sz = d_val; break;
+		case DT_PLTGOT:		info->plt_got = d_ptr; break;
+		case DT_HASH:		info->hash = d_ptr; break;
+		case DT_STRTAB:		info->str_tab = d_ptr; break;
+		case DT_SYMTAB:		info->sym_tab = d_ptr; break;
+		case DT_RELA:		info->rela = d_ptr; break;
+		case DT_RELASZ:		info->rela_sz = d_val; break;
+		case DT_RELAENT:	info->rela_ent = d_val; break;
+		case DT_STRSZ:		info->str_sz = d_val; break;
+		case DT_SYMENT:		info->sym_ent = d_val; break;
+		case DT_INIT:		info->init = d_ptr; break;
+		case DT_FINI:		info->fini = d_ptr; break;
+		case DT_SONAME:		soname_idx = d_val; break;
+		case DT_RPATH:		rpath_idx = d_val; break;
+		case DT_SYMBOLIC:	info->symbolic = true; break;
+		case DT_REL:		info->rel = d_ptr; break;
+		case DT_RELSZ:		info->rel_sz = d_val; break;
+		case DT_RELENT:		info->rel_ent = d_val; break;
+		case DT_PLTREL:		info->plt_rel = d_val; break;
+		case DT_TEXTREL:	info->text_rel = true; break;
+		case DT_JMPREL:		info->jmp_rel = d_ptr; break;
+		case DT_BIND_NOW:	info->bind_now = true; break;
+
+		default:
+			if (dp->d_tag >= DT_LOPROC && dp->d_tag <= DT_HIPROC)
+				dyn_parse_arch(dp, bias, info);
+			break;
+		}
+
+		++dp;
+	}
+
+	info->soname = info->str_tab + soname_idx;
+	info->rpath = info->str_tab + rpath_idx;
+
+	/* This will be useful for parsing dependencies later */
+	info->dynamic = dyn_ptr;
+
+	DPRINTF("str_tab=0x%x, soname_idx=0x%x, soname=0x%x\n",
+		(uintptr_t)info->soname, soname_idx, (uintptr_t)info->soname);
+	DPRINTF("soname='%s'\n", info->soname);
+	DPRINTF("rpath='%s'\n", info->rpath);
+	DPRINTF("hash=0x%x\n", (uintptr_t)info->hash);
+	DPRINTF("dt_rela=0x%x\n", (uintptr_t)info->rela);
+	DPRINTF("dt_rela_sz=0x%x\n", (uintptr_t)info->rela_sz);
+	DPRINTF("dt_rel=0x%x\n", (uintptr_t)info->rel);
+	DPRINTF("dt_rel_sz=0x%x\n", (uintptr_t)info->rel_sz);
+
+	/*
+	 * Now that we have a pointer to the string table,
+	 * we can parse DT_NEEDED fields (which contain offsets into it).
+	 */
+
+	DPRINTF("pass 2\n");
+	dp = dyn_ptr;
+	while (dp->d_tag != DT_NULL) {
+		d_val = dp->d_un.d_val;
+
+		switch (dp->d_tag) {
+		case DT_NEEDED:
+			/* Assume just for now there's only one dependency */
+			info->needed = info->str_tab + d_val;
+			DPRINTF("needed:'%s'\n", info->needed);
+			break;
+
+		default: break;
+		}
+
+		++dp;
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/rtld/elf_load.c
===================================================================
--- uspace/lib/c/generic/rtld/elf_load.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/generic/rtld/elf_load.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,1 @@
+../../../../srv/loader/elf_load.c
Index: uspace/lib/c/generic/rtld/module.c
===================================================================
--- uspace/lib/c/generic/rtld/module.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/generic/rtld/module.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <adt/list.h>
+#include <loader/pcb.h>
+
+#include <rtld/rtld.h>
+#include <rtld/rtld_debug.h>
+#include <rtld/dynamic.h>
+#include <rtld/rtld_arch.h>
+#include <rtld/module.h>
+#include <elf_load.h>
+
+/** (Eagerly) process all relocation tables in a module.
+ *
+ * Currently works as if LD_BIND_NOW was specified.
+ */
+void module_process_relocs(module_t *m)
+{
+	DPRINTF("module_process_relocs('%s')\n", m->dyn.soname);
+
+	/* Do not relocate twice. */
+	if (m->relocated) return;
+
+	module_process_pre_arch(m);
+
+	if (m->dyn.plt_rel == DT_REL) {
+		DPRINTF("table type DT_REL\n");
+		if (m->dyn.rel != NULL) {
+			DPRINTF("non-empty\n");
+			rel_table_process(m, m->dyn.rel, m->dyn.rel_sz);
+		}
+		/* FIXME: this seems wrong */
+		if (m->dyn.jmp_rel != NULL) {
+		DPRINTF("table type jmp-rel\n");
+			DPRINTF("non-empty\n");
+			rel_table_process(m, m->dyn.jmp_rel, m->dyn.plt_rel_sz);
+		}
+	} else { /* (m->dyn.plt_rel == DT_RELA) */
+		DPRINTF("table type DT_RELA\n");
+		if (m->dyn.rela != NULL) {
+			DPRINTF("non-empty\n");
+			rela_table_process(m, m->dyn.rela, m->dyn.rela_sz);
+		}
+	}
+
+	m->relocated = true;
+}
+
+/** Find module structure by soname/pathname.
+ *
+ * Used primarily to see if a module has already been loaded.
+ * Modules are compared according to their soname, i.e. possible
+ * path components are ignored.
+ */
+module_t *module_find(const char *name)
+{
+	link_t *head = &runtime_env->modules_head;
+
+	link_t *cur;
+	module_t *m;
+	const char *p, *soname;
+
+	DPRINTF("module_find('%s')\n", name);
+
+	/*
+	 * If name contains slashes, treat it as a pathname and
+	 * construct soname by chopping off the path. Otherwise
+	 * treat it as soname.
+	 */
+	p = str_rchr(name, '/');
+	soname = p ? (p + 1) : name;
+
+	/* Traverse list of all modules. Not extremely fast, but simple */
+	DPRINTF("head = %p\n", head);
+	for (cur = head->next; cur != head; cur = cur->next) {
+		DPRINTF("cur = %p\n", cur);
+		m = list_get_instance(cur, module_t, modules_link);
+		if (str_cmp(m->dyn.soname, soname) == 0) {
+			return m; /* Found */
+		}
+	}
+	
+	return NULL; /* Not found */
+}
+
+#define NAME_BUF_SIZE 64
+
+/** Load a module.
+ *
+ * Currently this trivially tries to load '/<name>'.
+ */
+module_t *module_load(const char *name)
+{
+	elf_info_t info;
+	char name_buf[NAME_BUF_SIZE];
+	module_t *m;
+	int rc;
+	
+	m = malloc(sizeof(module_t));
+	if (!m) {
+		printf("malloc failed\n");
+		exit(1);
+	}
+
+	if (str_size(name) > NAME_BUF_SIZE - 2) {
+		printf("soname too long. increase NAME_BUF_SIZE\n");
+		exit(1);
+	}
+
+	/* Prepend soname with '/lib/' */
+	str_cpy(name_buf, NAME_BUF_SIZE, "/lib/");
+	str_cpy(name_buf + 5, NAME_BUF_SIZE - 5, name);
+
+	/* FIXME: need to real allocation of address space */
+	m->bias = runtime_env->next_bias;
+	runtime_env->next_bias += 0x100000;
+
+	DPRINTF("filename:'%s'\n", name_buf);
+	DPRINTF("load '%s' at 0x%x\n", name_buf, m->bias);
+
+	rc = elf_load_file(name_buf, m->bias, ELDF_RW, &info);
+	if (rc != EE_OK) {
+		printf("Failed to load '%s'\n", name_buf);
+		exit(1);
+	}
+
+	if (info.dynamic == NULL) {
+		printf("Error: '%s' is not a dynamically-linked object.\n",
+		    name_buf);
+		exit(1);
+	}
+
+	/* Pending relocation. */
+	m->relocated = false;
+
+	DPRINTF("parse dynamic section\n");
+	/* Parse ELF .dynamic section. Store info to m->dyn. */
+	dynamic_parse(info.dynamic, m->bias, &m->dyn);
+
+	/* Insert into the list of loaded modules */
+	list_append(&m->modules_link, &runtime_env->modules_head);
+
+	return m;
+}
+
+/** Load all modules on which m (transitively) depends.
+ */
+void module_load_deps(module_t *m)
+{
+	elf_dyn_t *dp;
+	char *dep_name;
+	module_t *dm;
+	size_t n, i;
+
+	DPRINTF("module_load_deps('%s')\n", m->dyn.soname);
+
+	/* Count direct dependencies */
+	
+	dp = m->dyn.dynamic;
+	n = 0;
+
+	while (dp->d_tag != DT_NULL) {
+		if (dp->d_tag == DT_NEEDED) ++n;
+		++dp;
+	}
+
+	/* Create an array of pointers to direct dependencies */
+
+	m->n_deps = n;
+
+	if (n == 0) {
+		/* There are no dependencies, so we are done. */
+		m->deps = NULL;
+		return;
+	}
+
+	m->deps = malloc(n * sizeof(module_t *));
+	if (!m->deps) {
+		printf("malloc failed\n");
+		exit(1);
+	}
+
+	i = 0; /* Current dependency index */
+	dp = m->dyn.dynamic;
+
+	while (dp->d_tag != DT_NULL) {
+		if (dp->d_tag == DT_NEEDED) {
+			dep_name = m->dyn.str_tab + dp->d_un.d_val;
+
+			DPRINTF("%s needs %s\n", m->dyn.soname, dep_name);
+			dm = module_find(dep_name);
+			if (!dm) {
+				dm = module_load(dep_name);
+				module_load_deps(dm);
+			}
+
+			/* Save into deps table */
+			m->deps[i++] = dm;
+		}
+		++dp;
+	}
+}
+
+/** Process relocations in modules.
+ *
+ * Processes relocations in @a start and all its dependencies.
+ * Modules that have already been relocated are unaffected.
+ *
+ * @param	start	The module where to start from.
+ */
+void modules_process_relocs(module_t *start)
+{
+	link_t *head = &runtime_env->modules_head;
+
+	link_t *cur;
+	module_t *m;
+
+	for (cur = head->next; cur != head; cur = cur->next) {
+		m = list_get_instance(cur, module_t, modules_link);
+
+		/* Skip rtld, since it has already been processed */
+		if (m != &runtime_env->rtld) {
+			module_process_relocs(m);
+		}
+	}
+}
+
+/** Clear BFS tags of all modules.
+ */
+void modules_untag(void)
+{
+	link_t *head = &runtime_env->modules_head;
+
+	link_t *cur;
+	module_t *m;
+
+	for (cur = head->next; cur != head; cur = cur->next) {
+		m = list_get_instance(cur, module_t, modules_link);
+		m->bfs_tag = false;
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/rtld/rtld.c
===================================================================
--- uspace/lib/c/generic/rtld/rtld.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/generic/rtld/rtld.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <rtld/rtld.h>
+
+runtime_env_t *runtime_env;
+static runtime_env_t rt_env_static;
+
+/** Initialize the loder for use in a statically-linked binary. */
+void rtld_init_static(void)
+{
+	runtime_env = &rt_env_static;
+	list_initialize(&runtime_env->modules_head);
+	runtime_env->next_bias = 0x2000000;
+	runtime_env->program = NULL;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/rtld/symbol.c
===================================================================
--- uspace/lib/c/generic/rtld/symbol.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/generic/rtld/symbol.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <rtld/rtld.h>
+#include <rtld/rtld_debug.h>
+#include <rtld/symbol.h>
+#include <elf.h>
+
+/*
+ * Hash tables are 32-bit (elf_word) even for 64-bit ELF files.
+ */
+static elf_word elf_hash(const unsigned char *name)
+{
+	elf_word h = 0, g;
+
+	while (*name) {
+		h = (h << 4) + *name++;
+		g = h & 0xf0000000;
+		if (g != 0) h ^= g >> 24;
+		h &= ~g;
+	}
+
+	return h;
+}
+
+static elf_symbol_t *def_find_in_module(const char *name, module_t *m)
+{
+	elf_symbol_t *sym_table;
+	elf_symbol_t *s, *sym;
+	elf_word nbucket;
+	/*elf_word nchain;*/
+	elf_word i;
+	char *s_name;
+	elf_word bucket;
+
+	DPRINTF("def_find_in_module('%s', %s)\n", name, m->dyn.soname);
+
+	sym_table = m->dyn.sym_tab;
+	nbucket = m->dyn.hash[0];
+	/*nchain = m->dyn.hash[1]; XXX Use to check HT range*/
+
+	bucket = elf_hash((unsigned char *)name) % nbucket;
+	i = m->dyn.hash[2 + bucket];
+
+	sym = NULL;
+	while (i != STN_UNDEF) {
+		s = &sym_table[i];
+		s_name = m->dyn.str_tab + s->st_name;
+
+		if (str_cmp(name, s_name) == 0) {
+			sym = s;
+			break;
+		}
+
+		i = m->dyn.hash[2 + nbucket + i];
+	}
+
+	if (!sym)
+		return NULL;	/* Not found */
+
+	if (sym->st_shndx == SHN_UNDEF) {
+		/* Not a definition */
+		return NULL;
+	}
+
+	return sym; /* Found */
+}
+
+/** Find the definition of a symbol in a module and its deps.
+ *
+ * Search the module dependency graph is breadth-first, beginning
+ * from the module @a start. Thus, @start and all its dependencies
+ * get searched.
+ *
+ * @param name		Name of the symbol to search for.
+ * @param start		Module in which to start the search..
+ * @param mod		(output) Will be filled with a pointer to the module 
+ *			that contains the symbol.
+ */
+elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod)
+{
+	module_t *m, *dm;
+	elf_symbol_t *sym, *s;
+	link_t queue_head;
+	size_t i;
+
+	/*
+	 * Do a BFS using the queue_link and bfs_tag fields.
+	 * Vertices (modules) are tagged the moment they are inserted
+	 * into the queue. This prevents from visiting the same vertex
+	 * more times in case of circular dependencies.
+	 */
+
+	/* Mark all vertices (modules) as unvisited */	
+	modules_untag();
+
+	/* Insert root (the program) into the queue and tag it */
+	list_initialize(&queue_head);
+	start->bfs_tag = true;
+	list_append(&start->queue_link, &queue_head);
+
+	/* If the symbol is found, it will be stored in 'sym' */
+	sym = NULL;
+
+	/* While queue is not empty */
+	while (!list_empty(&queue_head)) {
+		/* Pop first element from the queue */
+		m = list_get_instance(queue_head.next, module_t, queue_link);
+		list_remove(&m->queue_link);
+
+		s = def_find_in_module(name, m);
+		if (s != NULL) {
+			/* Symbol found */
+			sym = s;
+			*mod = m;
+			break;
+		}
+
+		/*
+		 * Insert m's untagged dependencies into the queue
+		 * and tag them.
+		 */
+		for (i = 0; i < m->n_deps; ++i) {
+			dm = m->deps[i];
+
+			if (dm->bfs_tag == false) {
+				dm->bfs_tag = true;
+				list_append(&dm->queue_link, &queue_head);
+			}
+		}
+	}
+
+	/* Empty the queue so that we leave it in a clean state */
+	while (!list_empty(&queue_head))
+		list_remove(queue_head.next);
+
+	if (!sym) {
+		return NULL; /* Not found */
+	}
+
+	return sym; /* Symbol found */
+}
+
+
+/** Find the definition of a symbol..
+ *
+ * By definition in System V ABI, if module origin has the flag DT_SYMBOLIC,
+ * origin is searched first. Otherwise, or if the symbol hasn't been found,
+ * the module dependency graph is searched breadth-first, beginning
+ * from the executable program.
+ *
+ * @param name		Name of the symbol to search for.
+ * @param origin	Module in which the dependency originates.
+ * @param mod		(output) Will be filled with a pointer to the module 
+ *			that contains the symbol.
+ */
+elf_symbol_t *symbol_def_find(const char *name, module_t *origin, module_t **mod)
+{
+	elf_symbol_t *s;
+
+	if (origin->dyn.symbolic) {
+		/* 
+		 * Origin module has a DT_SYMBOLIC flag.
+		 * Try this module first
+		 */
+		 s = def_find_in_module(name, origin);
+		 if (s != NULL) {
+			/* Found */
+			*mod = origin;
+			return s;
+		 }
+	}
+
+	/* Not DT_SYMBOLIC or no match. Now try other locations. */
+
+	if (runtime_env->program) {
+		/* Program is dynamic -- start with program as root. */
+		return symbol_bfs_find(name, runtime_env->program, mod);
+	} else {
+		/* Program is static -- start with @a origin as root. */
+		return symbol_bfs_find(name, origin, mod);
+	}
+}
+
+void *symbol_get_addr(elf_symbol_t *sym, module_t *m)
+{
+	if (sym->st_shndx == SHN_ABS) {
+		/* Do not add bias to absolute symbols */
+		return (void *) sym->st_value;
+	} else {
+		return (void *) (sym->st_value + m->bias);
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/stacktrace.c
===================================================================
--- uspace/lib/c/generic/stacktrace.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/stacktrace.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -61,9 +61,11 @@
 	stacktrace_prepare();
 	stacktrace_print_fp_pc(stacktrace_fp_get(), stacktrace_pc_get());
+	
 	/*
 	 * Prevent the tail call optimization of the previous call by
 	 * making it a non-tail call.
 	 */
-	(void) stacktrace_fp_get();
+	
+	printf("-- end of stack trace --\n");
 }
 
Index: uspace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/str.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -1215,21 +1215,21 @@
 void order_suffix(const uint64_t val, uint64_t *rv, char *suffix)
 {
-	if (val > 10000000000000000000ULL) {
-		*rv = val / 1000000000000000000ULL;
+	if (val > UINT64_C(10000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000000);
 		*suffix = 'Z';
-	} else if (val > 1000000000000000000ULL) {
-		*rv = val / 1000000000000000ULL;
+	} else if (val > UINT64_C(1000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000);
 		*suffix = 'E';
-	} else if (val > 1000000000000000ULL) {
-		*rv = val / 1000000000000ULL;
+	} else if (val > UINT64_C(1000000000000000)) {
+		*rv = val / UINT64_C(1000000000000);
 		*suffix = 'T';
-	} else if (val > 1000000000000ULL) {
-		*rv = val / 1000000000ULL;
+	} else if (val > UINT64_C(1000000000000)) {
+		*rv = val / UINT64_C(1000000000);
 		*suffix = 'G';
-	} else if (val > 1000000000ULL) {
-		*rv = val / 1000000ULL;
+	} else if (val > UINT64_C(1000000000)) {
+		*rv = val / UINT64_C(1000000);
 		*suffix = 'M';
-	} else if (val > 1000000ULL) {
-		*rv = val / 1000ULL;
+	} else if (val > UINT64_C(1000000)) {
+		*rv = val / UINT64_C(1000);
 		*suffix = 'k';
 	} else {
@@ -1239,4 +1239,31 @@
 }
 
+void bin_order_suffix(const uint64_t val, uint64_t *rv, const char **suffix,
+    bool fixed)
+{
+	if (val > UINT64_C(1152921504606846976)) {
+		*rv = val / UINT64_C(1125899906842624);
+		*suffix = "EiB";
+	} else if (val > UINT64_C(1125899906842624)) {
+		*rv = val / UINT64_C(1099511627776);
+		*suffix = "TiB";
+	} else if (val > UINT64_C(1099511627776)) {
+		*rv = val / UINT64_C(1073741824);
+		*suffix = "GiB";
+	} else if (val > UINT64_C(1073741824)) {
+		*rv = val / UINT64_C(1048576);
+		*suffix = "MiB";
+	} else if (val > UINT64_C(1048576)) {
+		*rv = val / UINT64_C(1024);
+		*suffix = "KiB";
+	} else {
+		*rv = val;
+		if (fixed)
+			*suffix = "B  ";
+		else
+			*suffix = "B";
+	}
+}
+
 /** @}
  */
Index: uspace/lib/c/include/adt/fifo.h
===================================================================
--- uspace/lib/c/include/adt/fifo.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/adt/fifo.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -51,10 +51,10 @@
 typedef unsigned long fifo_index_t;
 
-#define FIFO_CREATE_STATIC(name, t, itms)		\
-	struct {					\
-		t fifo[(itms)];				\
-		fifo_count_t items;			\
-		fifo_index_t head;			\
-		fifo_index_t tail;			\
+#define FIFO_CREATE_STATIC(name, t, itms) \
+	struct { \
+		t fifo[(itms)]; \
+		fifo_count_t items; \
+		fifo_index_t head; \
+		fifo_index_t tail; \
 	} name
 
Index: uspace/lib/c/include/adt/list.h
===================================================================
--- uspace/lib/c/include/adt/list.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/adt/list.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -47,4 +47,5 @@
  *
  * @param name Name of the new statically allocated list.
+ *
  */
 #define LIST_INITIALIZE(name)  link_t name = { \
@@ -58,4 +59,5 @@
  *
  * @param link Pointer to link_t structure to be initialized.
+ *
  */
 static inline void link_initialize(link_t *link)
@@ -70,4 +72,5 @@
  *
  * @param head Pointer to link_t structure representing head of the list.
+ *
  */
 static inline void list_initialize(link_t *head)
@@ -83,4 +86,5 @@
  * @param link Pointer to link_t structure to be added.
  * @param head Pointer to link_t structure representing head of the list.
+ *
  */
 static inline void list_prepend(link_t *link, link_t *head)
@@ -98,4 +102,5 @@
  * @param link Pointer to link_t structure to be added.
  * @param head Pointer to link_t structure representing head of the list.
+ *
  */
 static inline void list_append(link_t *link, link_t *head)
@@ -123,5 +128,7 @@
  * Remove item from doubly-linked circular list.
  *
- * @param link Pointer to link_t structure to be removed from the list it is contained in.
+ * @param link Pointer to link_t structure to be removed from the list
+ *             it is contained in.
+ *
  */
 static inline void list_remove(link_t *link)
@@ -137,4 +144,5 @@
  *
  * @param head Pointer to link_t structure representing head of the list.
+ *
  */
 static inline int list_empty(link_t *head)
@@ -142,5 +150,4 @@
 	return ((head->next == head) ? 1 : 0);
 }
-
 
 /** Split or concatenate headless doubly-linked circular list
@@ -151,6 +158,9 @@
  * concatenates splitted lists and splits concatenated lists.
  *
- * @param part1 Pointer to link_t structure leading the first (half of the headless) list.
- * @param part2 Pointer to link_t structure leading the second (half of the headless) list. 
+ * @param part1 Pointer to link_t structure leading the first
+ *              (half of the headless) list.
+ * @param part2 Pointer to link_t structure leading the second
+ *              (half of the headless) list.
+ *
  */
 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
@@ -165,11 +175,13 @@
 }
 
-
 /** Split headless doubly-linked circular list
  *
  * Split headless doubly-linked circular list.
  *
- * @param part1 Pointer to link_t structure leading the first half of the headless list.
- * @param part2 Pointer to link_t structure leading the second half of the headless list. 
+ * @param part1 Pointer to link_t structure leading
+ *              the first half of the headless list.
+ * @param part2 Pointer to link_t structure leading
+ *              the second half of the headless list.
+ *
  */
 static inline void headless_list_split(link_t *part1, link_t *part2)
@@ -182,6 +194,9 @@
  * Concatenate two headless doubly-linked circular lists.
  *
- * @param part1 Pointer to link_t structure leading the first headless list.
- * @param part2 Pointer to link_t structure leading the second headless list. 
+ * @param part1 Pointer to link_t structure leading
+ *              the first headless list.
+ * @param part2 Pointer to link_t structure leading
+ *              the second headless list.
+ *
  */
 static inline void headless_list_concat(link_t *part1, link_t *part2)
@@ -190,9 +205,14 @@
 }
 
-#define list_get_instance(link, type, member)  ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member))))
-
-extern int list_member(const link_t *link, const link_t *head);
-extern void list_concat(link_t *head1, link_t *head2);
-extern unsigned int list_count(const link_t *link);
+#define list_get_instance(link, type, member) \
+	((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member))))
+
+#define list_foreach(list, iterator) \
+	for (link_t *iterator = (list).next; \
+	    iterator != &(list); iterator = iterator->next)
+
+extern int list_member(const link_t *, const link_t *);
+extern void list_concat(link_t *, link_t *);
+extern unsigned int list_count(const link_t *);
 
 #endif
Index: uspace/lib/c/include/adt/measured_strings.h
===================================================================
--- uspace/lib/c/include/adt/measured_strings.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/adt/measured_strings.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -61,4 +61,5 @@
 extern measured_string_t *measured_string_create_bulk(const uint8_t *, size_t);
 extern measured_string_t *measured_string_copy(measured_string_t *);
+
 extern int measured_strings_receive(measured_string_t **, uint8_t **, size_t);
 extern int measured_strings_reply(const measured_string_t *, size_t);
Index: uspace/lib/c/include/adt/prodcons.h
===================================================================
--- uspace/lib/c/include/adt/prodcons.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/adt/prodcons.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_PRODCONS_H_
+#define LIBC_PRODCONS_H_
+
+#include <adt/list.h>
+#include <fibril_synch.h>
+
+typedef struct {
+	fibril_mutex_t mtx;
+	fibril_condvar_t cv;
+	link_t list;
+} prodcons_t;
+
+extern void prodcons_initialize(prodcons_t *);
+extern void prodcons_produce(prodcons_t *, link_t *);
+extern link_t *prodcons_consume(prodcons_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/as.h
===================================================================
--- uspace/lib/c/include/as.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/as.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -54,11 +54,11 @@
 }
 
-extern void *as_area_create(void *address, size_t size, int flags);
-extern int as_area_resize(void *address, size_t size, int flags);
-extern int as_area_change_flags(void *address, int flags);
-extern int as_area_destroy(void *address);
-extern void *set_maxheapsize(size_t mhs);
-extern void * as_get_mappable_page(size_t sz);
-extern int as_get_physical_mapping(void *address, uintptr_t *frame);
+extern void *as_area_create(void *, size_t, unsigned int);
+extern int as_area_resize(void *, size_t, unsigned int);
+extern int as_area_change_flags(void *, unsigned int);
+extern int as_area_destroy(void *);
+extern void *set_maxheapsize(size_t);
+extern void * as_get_mappable_page(size_t);
+extern int as_get_physical_mapping(void *, uintptr_t *);
 
 #endif
Index: uspace/lib/c/include/assert.h
===================================================================
--- uspace/lib/c/include/assert.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/assert.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -40,5 +40,5 @@
  *
  * If NDEBUG is not set, the assert() macro
- * evaluates expr and if it is false prints 
+ * evaluates expr and if it is false prints
  * error message and terminate program.
  *
@@ -47,16 +47,10 @@
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-
 #ifndef NDEBUG
 
 #define assert(expr) \
 	do { \
-		if (!(expr)) { \
-			printf("Assertion failed (%s) at file '%s', " \
-			    "line %d.\n", #expr, __FILE__, __LINE__); \
-			abort(); \
-		} \
+		if (!(expr)) \
+			assert_abort(#expr, __FILE__, __LINE__); \
 	} while (0)
 
@@ -67,4 +61,7 @@
 #endif /* NDEBUG */
 
+extern void assert_abort(const char *, const char *, unsigned int)
+    __attribute__((noreturn));
+
 #endif
 
Index: uspace/lib/c/include/dlfcn.h
===================================================================
--- uspace/lib/c/include/dlfcn.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/dlfcn.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld
+ * @{
+ */
+/** @file
+ * @brief UNIX-like dynamic linker interface.
+ */
+
+#ifndef LIBC_DLFCN_H_
+#define LIBC_DLFCN_H_
+
+void *dlopen(const char *, int);
+void *dlsym(void *, const char *);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/c/include/entry_point.h
===================================================================
--- uspace/lib/c/include/entry_point.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/entry_point.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ENTRY_POINT_H_
+#define LIBC_ENTRY_POINT_H_
+
+/* Defined in arch/ARCH/src/entryjmp.[c|s] */
+void entry_point_jmp(void *, void *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/errno.h
===================================================================
--- uspace/lib/c/include/errno.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/errno.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -39,7 +39,7 @@
 #include <fibril.h>
 
-#define errno _errno
+#define errno  (*(__errno()))
 
-extern int _errno;
+extern int *__errno(void) __attribute__((const));
 
 #define EMFILE        (-18)
Index: uspace/lib/c/include/event.h
===================================================================
--- uspace/lib/c/include/event.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/event.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -39,4 +39,5 @@
 
 extern int event_subscribe(event_type_t, sysarg_t);
+extern int event_unmask(event_type_t);
 
 #endif
Index: uspace/lib/c/include/fibril.h
===================================================================
--- uspace/lib/c/include/fibril.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/fibril.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -70,9 +70,9 @@
 	int (*func)(void *);
 	tcb_t *tcb;
-
+	
 	struct fibril *clean_after_me;
 	int retval;
 	int flags;
-
+	
 	fibril_owner_info_t *waits_for;
 } fibril_t;
Index: uspace/lib/c/include/fibril_synch.h
===================================================================
--- uspace/lib/c/include/fibril_synch.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/fibril_synch.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -36,12 +36,12 @@
 #define LIBC_FIBRIL_SYNCH_H_
 
-#include <async.h>
 #include <fibril.h>
 #include <adt/list.h>
 #include <libarch/tls.h>
 #include <sys/time.h>
+#include <bool.h>
 
 typedef struct {
-	fibril_owner_info_t oi;		/* Keep this the first thing. */
+	fibril_owner_info_t oi;  /**< Keep this the first thing. */
 	int counter;
 	link_t waiters;
@@ -64,5 +64,5 @@
 
 typedef struct {
-	fibril_owner_info_t oi;	/* Keep this the first thing. */
+	fibril_owner_info_t oi;  /**< Keep this the first thing. */
 	unsigned writers;
 	unsigned readers;
Index: uspace/lib/c/include/loader/pcb.h
===================================================================
--- uspace/lib/c/include/loader/pcb.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/loader/pcb.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -72,4 +72,6 @@
 	/** Pointer to ELF dynamic section of the program. */
 	void *dynamic;
+	/** Pointer to dynamic linker state structure (runtime_env_t). */
+	void *rtld_runtime;
 } pcb_t;
 
Index: uspace/lib/c/include/macros.h
===================================================================
--- uspace/lib/c/include/macros.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/macros.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -39,9 +39,6 @@
 #define max(a, b)  ((a) > (b) ? (a) : (b))
 
-#define SIZE2KB(size)  ((size) >> 10)
-#define SIZE2MB(size)  ((size) >> 20)
-
-#define KB2SIZE(kb)  ((kb) << 10)
-#define MB2SIZE(mb)  ((mb) << 20)
+#define KiB2SIZE(kb)  ((kb) << 10)
+#define MiB2SIZE(mb)  ((mb) << 20)
 
 #define STRING(arg)      STRING_ARG(arg)
Index: uspace/lib/c/include/rtld/dynamic.h
===================================================================
--- uspace/lib/c/include/rtld/dynamic.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/rtld/dynamic.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_DYNAMIC_H_
+#define LIBC_RTLD_DYNAMIC_H_
+
+#include <bool.h>
+#include <rtld/elf_dyn.h>
+#include <libarch/rtld/dynamic.h>
+
+/**
+ * Holds the data extracted from an ELF Dynamic section.
+ *
+ * The data is already pre-processed: Pointers are adjusted
+ * to their final run-time values by adding the load bias
+ * and indices into the symbol table are converted to pointers.
+ */
+typedef struct dyn_info {
+	/** Type of relocations used for the PLT, either DT_REL or DT_RELA */
+	int plt_rel;
+
+	/** Relocation table without explicit addends */
+	void *rel;
+	size_t rel_sz;
+	size_t rel_ent;
+
+	/** Relocation table with explicit addends */
+	void *rela;
+	size_t rela_sz;
+	size_t rela_ent;
+
+	/** PLT relocation table */
+	void *jmp_rel;
+	size_t plt_rel_sz;
+
+	/** Pointer to PLT/GOT (processor-specific) */
+	void *plt_got;
+
+	/** Hash table */
+	elf_word *hash;
+
+	/** String table */
+	char *str_tab;
+	size_t str_sz;
+
+	/** Symbol table */
+	void *sym_tab;
+	size_t sym_ent;
+
+	void *init;		/**< Module initialization code */
+	void *fini;		/**< Module cleanup code */
+
+	const char *soname;	/**< Library identifier */
+	char *rpath;		/**< Library search path list */
+
+	bool symbolic;
+	bool text_rel;
+	bool bind_now;
+
+	/* Assume for now that there's at most one needed library */
+	char *needed;
+
+	/** Pointer to the module's dynamic section */
+	elf_dyn_t *dynamic;
+
+	/** Architecture-specific info. */
+	dyn_info_arch_t arch;
+} dyn_info_t;
+
+void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info);
+void dyn_parse_arch(elf_dyn_t *dp, size_t bias, dyn_info_t *info);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/elf_dyn.h
===================================================================
--- uspace/lib/c/include/rtld/elf_dyn.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/rtld/elf_dyn.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_ELF_DYN_H_
+#define LIBC_RTLD_ELF_DYN_H_
+
+#include <arch/elf.h>
+#include <sys/types.h>
+
+#include <elf.h>
+#include <libarch/rtld/elf_dyn.h>
+
+#define ELF32_R_SYM(i) ((i)>>8)
+#define ELF32_R_TYPE(i) ((unsigned char)(i))
+
+struct elf32_dyn {
+	elf_sword d_tag;
+	union {
+		elf_word d_val;
+		elf32_addr d_ptr;
+	} d_un;
+};
+
+struct elf32_rel {
+	elf32_addr r_offset;
+	elf_word r_info;
+};
+
+struct elf32_rela {
+	elf32_addr r_offset;
+	elf_word r_info;
+	elf_sword r_addend;
+};
+
+#ifdef __32_BITS__
+typedef struct elf32_dyn elf_dyn_t;
+typedef struct elf32_rel elf_rel_t;
+typedef struct elf32_rela elf_rela_t;
+#endif
+
+/*
+ * Dynamic array tags
+ */
+#define DT_NULL		0
+#define DT_NEEDED	1
+#define DT_PLTRELSZ	2
+#define DT_PLTGOT	3
+#define DT_HASH		4
+#define DT_STRTAB	5
+#define DT_SYMTAB	6
+#define DT_RELA		7
+#define DT_RELASZ	8
+#define DT_RELAENT	9
+#define DT_STRSZ	10
+#define DT_SYMENT	11
+#define DT_INIT		12
+#define DT_FINI		13
+#define DT_SONAME	14
+#define DT_RPATH	15
+#define DT_SYMBOLIC	16
+#define DT_REL		17
+#define DT_RELSZ	18
+#define DT_RELENT	19
+#define DT_PLTREL	20
+#define DT_DEBUG	21
+#define DT_TEXTREL	22
+#define DT_JMPREL	23
+#define DT_BIND_NOW	24
+#define DT_LOPROC	0x70000000
+#define DT_HIPROC	0x7fffffff
+
+/*
+ * Special section indexes
+ */
+#define SHN_UNDEF	0
+#define SHN_LORESERVE	0xff00
+#define SHN_LOPROC	0xff00
+#define SHN_HIPROC	0xff1f
+#define SHN_ABS		0xfff1
+#define SHN_COMMON	0xfff2
+#define SHN_HIRESERVE	0xffff
+
+/*
+ * Special symbol table index
+ */
+#define STN_UNDEF	0
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/module.h
===================================================================
--- uspace/lib/c/include/rtld/module.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/rtld/module.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_MODULE_H_
+#define LIBC_RTLD_MODULE_H_
+
+#include <sys/types.h>
+#include <rtld/dynamic.h>
+#include <adt/list.h>
+
+typedef struct module {
+	dyn_info_t dyn;
+	size_t bias;
+
+	/** Array of pointers to directly dependent modules */
+	struct module **deps;
+	/** Number of fields in deps */
+	size_t n_deps;
+
+	/** True iff relocations have already been processed in this module. */
+	bool relocated;
+
+	/** Link to list of all modules in runtime environment */
+	link_t modules_link;
+
+	/** Link to BFS queue. Only used when doing a BFS of the module graph */
+	link_t queue_link;
+	/** Tag for modules already processed during a BFS */
+	bool bfs_tag;
+} module_t;
+
+void module_process_relocs(module_t *m);
+module_t *module_find(const char *name);
+module_t *module_load(const char *name);
+void module_load_deps(module_t *m);
+
+void modules_process_relocs(module_t *start);
+void modules_untag(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/rtld.h
===================================================================
--- uspace/lib/c/include/rtld/rtld.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/rtld/rtld.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_H_
+#define LIBC_RTLD_H_
+
+#include <sys/types.h>
+#include <adt/list.h>
+
+#include <rtld/dynamic.h>
+#include <rtld/module.h>
+
+typedef struct {
+	elf_dyn_t *rtld_dynamic;
+	module_t rtld;
+
+	module_t *program;
+
+	/** List of all loaded modules including rtld and the program */
+	link_t modules_head;
+
+	/** Temporary hack to place each module at different address. */
+	uintptr_t next_bias;
+} runtime_env_t;
+
+extern runtime_env_t *runtime_env;
+
+extern void rtld_init_static(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/rtld_arch.h
===================================================================
--- uspace/lib/c/include/rtld/rtld_arch.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/rtld/rtld_arch.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_RTLD_ARCH_H_
+#define LIBC_RTLD_RTLD_ARCH_H_
+
+#include <rtld/rtld.h>
+#include <loader/pcb.h>
+
+void module_process_pre_arch(module_t *m);
+
+void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size);
+void rela_table_process(module_t *m, elf_rela_t *rt, size_t rt_size);
+
+void program_run(void *entry, pcb_t *pcb);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/rtld_debug.h
===================================================================
--- uspace/lib/c/include/rtld/rtld_debug.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/rtld/rtld_debug.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_RTLD_DEBUG_H_
+#define LIBC_RTLD_RTLD_DEBUG_H_
+
+/* Define to enable debugging mode. */
+#undef RTLD_DEBUG
+
+#ifdef RTLD_DEBUG
+	#define DPRINTF(format, ...) printf(format, ##__VA_ARGS__)
+#else
+	#define DPRINTF(format, ...) if (0) printf(format, ##__VA_ARGS__)
+#endif
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/symbol.h
===================================================================
--- uspace/lib/c/include/rtld/symbol.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
+++ uspace/lib/c/include/rtld/symbol.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_SYMBOL_H_
+#define LIBC_RTLD_SYMBOL_H_
+
+#include <rtld/rtld.h>
+#include <elf.h>
+
+elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod);
+elf_symbol_t *symbol_def_find(const char *name, module_t *origin, module_t **mod);
+void *symbol_get_addr(elf_symbol_t *sym, module_t *m);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/str.h
===================================================================
--- uspace/lib/c/include/str.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/str.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -89,5 +89,6 @@
 extern int str_size_t(const char *, char **, unsigned int, bool, size_t *);
 
-extern void order_suffix(const uint64_t val, uint64_t *rv, char *suffix);
+extern void order_suffix(const uint64_t, uint64_t *, char *);
+extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
 
 /*
Index: uspace/lib/softfloat/generic/add.c
===================================================================
--- uspace/lib/softfloat/generic/add.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/generic/add.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -33,7 +33,7 @@
  */
 
-#include<sftypes.h>
-#include<add.h>
-#include<comparison.h>
+#include <sftypes.h>
+#include <add.h>
+#include <comparison.h>
 
 /** Add two Float32 numbers with same signs
@@ -139,9 +139,8 @@
 	a.parts.exp = exp1;
 	
-	/*Clear hidden bit and shift */
+	/* Clear hidden bit and shift */
 	a.parts.fraction = ((frac1 >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)) ; 
 	return a;
 }
-
 
 /** Add two Float64 numbers with same signs
@@ -250,5 +249,5 @@
 	
 	a.parts.exp = exp1;
-	/*Clear hidden bit and shift */
+	/* Clear hidden bit and shift */
 	a.parts.fraction = ( (frac1 >> 6 ) & (~FLOAT64_HIDDEN_BIT_MASK));
 	
Index: uspace/lib/softfloat/generic/common.c
===================================================================
--- uspace/lib/softfloat/generic/common.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/generic/common.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -33,6 +33,6 @@
  */
 
-#include<sftypes.h>
-#include<common.h>
+#include <sftypes.h>
+#include <common.h>
 
 /* Table for fast leading zeroes counting */
@@ -213,3 +213,2 @@
 /** @}
  */
-
Index: uspace/lib/softfloat/generic/comparison.c
===================================================================
--- uspace/lib/softfloat/generic/comparison.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/generic/comparison.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -33,43 +33,47 @@
  */
 
-#include<sftypes.h>
-#include<comparison.h>
+#include <sftypes.h>
+#include <comparison.h>
 
-inline int isFloat32NaN(float32 f)
-{	/* NaN : exp = 0xff and nonzero fraction */
-	return ((f.parts.exp==0xFF)&&(f.parts.fraction));
+/* NaN : exp = 0xff and nonzero fraction */
+int isFloat32NaN(float32 f)
+{
+	return ((f.parts.exp == 0xFF) && (f.parts.fraction));
 }
 
-inline int isFloat64NaN(float64 d)
-{	/* NaN : exp = 0x7ff and nonzero fraction */
-	return ((d.parts.exp==0x7FF)&&(d.parts.fraction));
+/* NaN : exp = 0x7ff and nonzero fraction */
+int isFloat64NaN(float64 d)
+{
+	return ((d.parts.exp == 0x7FF) && (d.parts.fraction));
 }
 
-inline int isFloat32SigNaN(float32 f)
-{	/* SigNaN : exp = 0xff fraction = 0xxxxx..x (binary), where at least one x is nonzero */
-	return ((f.parts.exp==0xFF)&&(f.parts.fraction<0x400000)&&(f.parts.fraction));
+/* SigNaN : exp = 0xff fraction = 0xxxxx..x (binary), where at least one x is nonzero */
+int isFloat32SigNaN(float32 f)
+{
+	return ((f.parts.exp == 0xFF) && (f.parts.fraction < 0x400000) && (f.parts.fraction));
 }
 
-inline int isFloat64SigNaN(float64 d)
-{	/* SigNaN : exp = 0x7ff fraction = 0xxxxx..x (binary), where at least one x is nonzero */
-	return ((d.parts.exp==0x7FF)&&(d.parts.fraction)&&(d.parts.fraction<0x8000000000000ll));
+/* SigNaN : exp = 0x7ff fraction = 0xxxxx..x (binary), where at least one x is nonzero */
+int isFloat64SigNaN(float64 d)
+{
+	return ((d.parts.exp == 0x7FF) && (d.parts.fraction) && (d.parts.fraction < 0x8000000000000ll));
 }
 
-inline int isFloat32Infinity(float32 f) 
+int isFloat32Infinity(float32 f)
 {
-	return ((f.parts.exp==0xFF)&&(f.parts.fraction==0x0));
+	return ((f.parts.exp == 0xFF) && (f.parts.fraction == 0x0));
 }
 
-inline int isFloat64Infinity(float64 d) 
+int isFloat64Infinity(float64 d) 
 {
-	return ((d.parts.exp==0x7FF)&&(d.parts.fraction==0x0));
+	return ((d.parts.exp == 0x7FF) && (d.parts.fraction == 0x0));
 }
 
-inline int isFloat32Zero(float32 f)
+int isFloat32Zero(float32 f)
 {
 	return (((f.binary) & 0x7FFFFFFF) == 0);
 }
 
-inline int isFloat64Zero(float64 d)
+int isFloat64Zero(float64 d)
 {
 	return (((d.binary) & 0x7FFFFFFFFFFFFFFFll) == 0);
@@ -77,51 +81,46 @@
 
 /**
- * @return 1, if both floats are equal - but NaNs are not recognized 
+ * @return 1 if both floats are equal - but NaNs are not recognized
  */
-inline int isFloat32eq(float32 a, float32 b)
+int isFloat32eq(float32 a, float32 b)
 {
-	return ((a.binary==b.binary)||(((a.binary| b.binary)&0x7FFFFFFF)==0)); /* a equals to b or both are zeros (with any sign) */
+	/* a equals to b or both are zeros (with any sign) */
+	return ((a.binary==b.binary) || (((a.binary | b.binary) & 0x7FFFFFFF) == 0));
 }
 
 /**
- * @return 1, if a<b - but NaNs are not recognized 
+ * @return 1 if a < b - but NaNs are not recognized 
  */
-inline int isFloat32lt(float32 a, float32 b) 
+int isFloat32lt(float32 a, float32 b) 
 {
-	if (((a.binary| b.binary)&0x7FFFFFFF)==0) {
+	if (((a.binary | b.binary) & 0x7FFFFFFF) == 0)
 		return 0; /* +- zeroes */
-	};
 	
-	if ((a.parts.sign)&&(b.parts.sign)) {
-		/*if both are negative, smaller is that with greater binary value*/
-		return (a.binary>b.binary);
-		};
+	if ((a.parts.sign) && (b.parts.sign))
+		/* if both are negative, smaller is that with greater binary value */
+		return (a.binary > b.binary);
 	
-	/* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison)*/
-	a.parts.sign=!a.parts.sign;
-	b.parts.sign=!b.parts.sign;
-	return (a.binary<b.binary);
-			
+	/* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison) */
+	a.parts.sign = !a.parts.sign;
+	b.parts.sign = !b.parts.sign;
+	return (a.binary < b.binary);
 }
 
 /**
- * @return 1, if a>b - but NaNs are not recognized 
+ * @return 1 if a > b - but NaNs are not recognized 
  */
-inline int isFloat32gt(float32 a, float32 b) 
+int isFloat32gt(float32 a, float32 b) 
 {
-	if (((a.binary| b.binary)&0x7FFFFFFF)==0) {
+	if (((a.binary | b.binary) & 0x7FFFFFFF) == 0)
 		return 0; /* zeroes are equal with any sign */
-	};
 	
-	if ((a.parts.sign)&&(b.parts.sign)) {
-		/*if both are negative, greater is that with smaller binary value*/
-		return (a.binary<b.binary);
-		};
+	if ((a.parts.sign) && (b.parts.sign))
+		/* if both are negative, greater is that with smaller binary value */
+		return (a.binary < b.binary);
 	
-	/* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison)*/
-	a.parts.sign=!a.parts.sign;
-	b.parts.sign=!b.parts.sign;
-	return (a.binary>b.binary);
-			
+	/* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison) */
+	a.parts.sign = !a.parts.sign;
+	b.parts.sign = !b.parts.sign;
+	return (a.binary > b.binary);
 }
 
Index: uspace/lib/softfloat/generic/div.c
===================================================================
--- uspace/lib/softfloat/generic/div.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/generic/div.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -33,11 +33,10 @@
  */
 
-#include<sftypes.h>
-#include<add.h>
-#include<div.h>
-#include<comparison.h>
-#include<mul.h>
-#include<common.h>
-
+#include <sftypes.h>
+#include <add.h>
+#include <div.h>
+#include <comparison.h>
+#include <mul.h>
+#include <common.h>
 
 float32 divFloat32(float32 a, float32 b) 
Index: uspace/lib/softfloat/generic/mul.c
===================================================================
--- uspace/lib/softfloat/generic/mul.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/generic/mul.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -33,8 +33,8 @@
  */
 
-#include<sftypes.h>
-#include<mul.h>
-#include<comparison.h>
-#include<common.h>
+#include <sftypes.h>
+#include <mul.h>
+#include <comparison.h>
+#include <common.h>
 
 /** Multiply two 32 bit float numbers
Index: uspace/lib/softfloat/generic/other.c
===================================================================
--- uspace/lib/softfloat/generic/other.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/generic/other.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
Index: uspace/lib/softfloat/generic/softfloat.c
===================================================================
--- uspace/lib/softfloat/generic/softfloat.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/generic/softfloat.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -35,17 +35,17 @@
  */
 
-#include<softfloat.h>
-#include<sftypes.h>
-
-#include<add.h>
-#include<sub.h>
-#include<mul.h>
-#include<div.h>
-
-#include<conversion.h>
-#include<comparison.h>
-#include<other.h>
-
-#include<functions.h>
+#include <softfloat.h>
+#include <sftypes.h>
+
+#include <add.h>
+#include <sub.h>
+#include <mul.h>
+#include <div.h>
+
+#include <conversion.h>
+#include <comparison.h>
+#include <other.h>
+
+#include <functions.h>
 
 /* Arithmetic functions */
@@ -494,6 +494,4 @@
 }
 
-
 /** @}
  */
-
Index: uspace/lib/softfloat/generic/sub.c
===================================================================
--- uspace/lib/softfloat/generic/sub.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/generic/sub.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -33,7 +33,7 @@
  */
 
-#include<sftypes.h>
-#include<sub.h>
-#include<comparison.h>
+#include <sftypes.h>
+#include <sub.h>
+#include <comparison.h>
 
 /** Subtract two float32 numbers with same signs
@@ -260,6 +260,4 @@
 }
 
-
- /** @}
- */
-
+/** @}
+ */
Index: uspace/lib/softfloat/include/add.h
===================================================================
--- uspace/lib/softfloat/include/add.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/add.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -36,12 +36,9 @@
 #define __ADD_H__
 
-float32 addFloat32(float32 a, float32 b);
-
-float64 addFloat64(float64 a, float64 b);
+extern float32 addFloat32(float32, float32);
+extern float64 addFloat64(float64, float64);
 
 #endif
 
-
- /** @}
+/** @}
  */
-
Index: uspace/lib/softfloat/include/common.h
===================================================================
--- uspace/lib/softfloat/include/common.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/common.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -36,18 +36,17 @@
 #define __COMMON_H__
 
-#include<sftypes.h>
+#include <sftypes.h>
 
-float64 finishFloat64(int32_t cexp, uint64_t cfrac, char sign);
+extern float64 finishFloat64(int32_t, uint64_t, char);
 
-int countZeroes64(uint64_t i);
-int countZeroes32(uint32_t i);
-int countZeroes8(uint8_t i);
+extern int countZeroes64(uint64_t);
+extern int countZeroes32(uint32_t);
+extern int countZeroes8(uint8_t);
 
-void roundFloat32(int32_t *exp, uint32_t *fraction);
-void roundFloat64(int32_t *exp, uint64_t *fraction);
+extern void roundFloat32(int32_t *, uint32_t *);
+extern void roundFloat64(int32_t *, uint64_t *);
 
 #endif
 
- /** @}
+/** @}
  */
-
Index: uspace/lib/softfloat/include/comparison.h
===================================================================
--- uspace/lib/softfloat/include/comparison.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/comparison.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -36,24 +36,22 @@
 #define __COMPARISON_H__
 
-inline int isFloat32NaN(float32 f);
-inline int isFloat32SigNaN(float32 f);
+extern int isFloat32NaN(float32);
+extern int isFloat32SigNaN(float32);
 
-inline int isFloat32Infinity(float32 f);
-inline int isFloat32Zero(float32 f);
+extern int isFloat32Infinity(float32);
+extern int isFloat32Zero(float32);
 
-inline int isFloat64NaN(float64 d);
-inline int isFloat64SigNaN(float64 d);
+extern int isFloat64NaN(float64);
+extern int isFloat64SigNaN(float64);
 
-inline int isFloat64Infinity(float64 d);
-inline int isFloat64Zero(float64 d);
+extern int isFloat64Infinity(float64);
+extern int isFloat64Zero(float64);
 
-inline int isFloat32eq(float32 a, float32 b);
-inline int isFloat32lt(float32 a, float32 b);
-inline int isFloat32gt(float32 a, float32 b);
+extern int isFloat32eq(float32, float32);
+extern int isFloat32lt(float32, float32);
+extern int isFloat32gt(float32, float32);
 
 #endif
 
-
- /** @}
+/** @}
  */
-
Index: uspace/lib/softfloat/include/conversion.h
===================================================================
--- uspace/lib/softfloat/include/conversion.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/conversion.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+ /** @addtogroup softfloat
  * @{
  */
@@ -36,36 +36,33 @@
 #define __CONVERSION_H__
 
-float64 convertFloat32ToFloat64(float32 a);
+extern float64 convertFloat32ToFloat64(float32);
+extern float32 convertFloat64ToFloat32(float64);
 
-float32 convertFloat64ToFloat32(float64 a);
+extern uint32_t float32_to_uint32(float32);
+extern int32_t float32_to_int32(float32);
 
-uint32_t float32_to_uint32(float32 a);
-int32_t float32_to_int32(float32 a);
+extern uint64_t float32_to_uint64(float32);
+extern int64_t float32_to_int64(float32);
 
-uint64_t float32_to_uint64(float32 a);
-int64_t float32_to_int64(float32 a);
+extern uint64_t float64_to_uint64(float64);
+extern int64_t float64_to_int64(float64);
 
-uint64_t float64_to_uint64(float64 a);
-int64_t float64_to_int64(float64 a);
+extern uint32_t float64_to_uint32(float64);
+extern int32_t float64_to_int32(float64);
 
-uint32_t float64_to_uint32(float64 a);
-int32_t float64_to_int32(float64 a);
+extern float32 uint32_to_float32(uint32_t);
+extern float32 int32_to_float32(int32_t);
 
-float32 uint32_to_float32(uint32_t i);
-float32 int32_to_float32(int32_t i);
+extern float32 uint64_to_float32(uint64_t);
+extern float32 int64_to_float32(int64_t);
 
-float32 uint64_to_float32(uint64_t i);
-float32 int64_to_float32(int64_t i);
+extern float64 uint32_to_float64(uint32_t);
+extern float64 int32_to_float64(int32_t);
 
-float64 uint32_to_float64(uint32_t i);
-float64 int32_to_float64(int32_t i);
-
-float64 uint64_to_float64(uint64_t i);
-float64 int64_to_float64(int64_t i);
+extern float64 uint64_to_float64(uint64_t);
+extern float64 int64_to_float64(int64_t);
 
 #endif
 
-
- /** @}
+/** @}
  */
-
Index: uspace/lib/softfloat/include/div.h
===================================================================
--- uspace/lib/softfloat/include/div.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/div.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -36,13 +36,11 @@
 #define __DIV_H__
 
-float32 divFloat32(float32 a, float32 b);
-float64 divFloat64(float64 a, float64 b);
+extern float32 divFloat32(float32, float32);
+extern float64 divFloat64(float64, float64);
 
-uint64_t divFloat64estim(uint64_t a, uint64_t b);
+extern uint64_t divFloat64estim(uint64_t, uint64_t);
 
 #endif
 
-
- /** @}
+/** @}
  */
-
Index: uspace/lib/softfloat/include/mul.h
===================================================================
--- uspace/lib/softfloat/include/mul.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/mul.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -36,14 +36,11 @@
 #define __MUL_H__
 
-float32 mulFloat32(float32 a, float32 b);
+extern float32 mulFloat32(float32, float32);
+extern float64 mulFloat64(float64, float64);
 
-float64 mulFloat64(float64 a, float64 b);
-
-void mul64integers(uint64_t a,uint64_t b, uint64_t *lo, uint64_t *hi);
+extern void mul64integers(uint64_t, uint64_t, uint64_t *, uint64_t *);
 
 #endif
 
-
- /** @}
+/** @}
  */
-
Index: uspace/lib/softfloat/include/other.h
===================================================================
--- uspace/lib/softfloat/include/other.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/other.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -38,6 +38,4 @@
 #endif
 
-
- /** @}
+/** @}
  */
-
Index: uspace/lib/softfloat/include/sftypes.h
===================================================================
--- uspace/lib/softfloat/include/sftypes.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/sftypes.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -55,5 +55,5 @@
 	#error Unknown endianess
 #endif
-		} parts __attribute__ ((packed));
+	} parts __attribute__ ((packed));
 } float32;
 
@@ -77,6 +77,6 @@
 } float64;
 
-#define FLOAT32_MAX 0x7f800000
-#define FLOAT32_MIN 0xff800000
+#define FLOAT32_MAX  0x7f800000
+#define FLOAT32_MIN  0xff800000
 #define FLOAT64_MAX
 #define FLOAT64_MIN
@@ -86,25 +86,25 @@
  * comparing with these constants is not sufficient.
  */
-#define FLOAT32_NAN 0x7FC00001
-#define FLOAT32_SIGNAN 0x7F800001
-#define FLOAT32_INF 0x7F800000
 
-#define FLOAT64_NAN 0x7FF8000000000001ll
-#define FLOAT64_SIGNAN 0x7FF0000000000001ll
-#define FLOAT64_INF 0x7FF0000000000000ll
+#define FLOAT32_NAN     0x7FC00001
+#define FLOAT32_SIGNAN  0x7F800001
+#define FLOAT32_INF     0x7F800000
 
-#define FLOAT32_FRACTION_SIZE 23
-#define FLOAT64_FRACTION_SIZE 52
+#define FLOAT64_NAN     0x7FF8000000000001ll
+#define FLOAT64_SIGNAN  0x7FF0000000000001ll
+#define FLOAT64_INF     0x7FF0000000000000ll
 
-#define FLOAT32_HIDDEN_BIT_MASK 0x800000
-#define FLOAT64_HIDDEN_BIT_MASK 0x10000000000000ll
+#define FLOAT32_FRACTION_SIZE  23
+#define FLOAT64_FRACTION_SIZE  52
 
-#define FLOAT32_MAX_EXPONENT 0xFF
-#define FLOAT64_MAX_EXPONENT 0x7FF
+#define FLOAT32_HIDDEN_BIT_MASK  0x800000
+#define FLOAT64_HIDDEN_BIT_MASK  0x10000000000000ll
 
-#define FLOAT32_BIAS 0x7F
-#define FLOAT64_BIAS 0x3FF
-#define FLOAT80_BIAS 0x3FFF
+#define FLOAT32_MAX_EXPONENT  0xFF
+#define FLOAT64_MAX_EXPONENT  0x7FF
 
+#define FLOAT32_BIAS  0x7F
+#define FLOAT64_BIAS  0x3FF
+#define FLOAT80_BIAS  0x3FFF
 
 #endif
Index: uspace/lib/softfloat/include/softfloat.h
===================================================================
--- uspace/lib/softfloat/include/softfloat.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/softfloat.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -36,139 +36,137 @@
 #define __SOFTFLOAT_H__
 
-float __addsf3(float a, float b);
-double __adddf3(double a, double b);
-long double __addtf3(long double a, long double b);
-long double __addxf3(long double a, long double b);
- 
-float __subsf3(float a, float b);
-double __subdf3(double a, double b);
-long double __subtf3(long double a, long double b);
-long double __subxf3(long double a, long double b);
- 
-float __mulsf3(float a, float b);
-double __muldf3(double a, double b);
-long double __multf3(long double a, long double b);
-long double __mulxf3(long double a, long double b);
- 
-float __divsf3(float a, float b);
-double __divdf3(double a, double b);
-long double __divtf3(long double a, long double b);
-long double __divxf3(long double a, long double b);
- 
-float __negsf2(float a);
-double __negdf2(double a);
-long double __negtf2(long double a);
-long double __negxf2(long double a);
- 
-double __extendsfdf2(float a);
-long double __extendsftf2(float a);
-long double __extendsfxf2(float a);
-long double __extenddftf2(double a);
-long double __extenddfxf2(double a);
- 
-double __truncxfdf2(long double a);
-double __trunctfdf2(long double a);
-float __truncxfsf2(long double a);
-float __trunctfsf2(long double a);
-float __truncdfsf2(double a);
- 
-int __fixsfsi(float a);
-int __fixdfsi(double a);
-int __fixtfsi(long double a);
-int __fixxfsi(long double a);
- 
-long __fixsfdi(float a);
-long __fixdfdi(double a);
-long __fixtfdi(long double a);
-long __fixxfdi(long double a);
- 
-long long __fixsfti(float a);
-long long __fixdfti(double a);
-long long __fixtfti(long double a);
-long long __fixxfti(long double a);
- 
-unsigned int __fixunssfsi(float a);
-unsigned int __fixunsdfsi(double a);
-unsigned int __fixunstfsi(long double a);
-unsigned int __fixunsxfsi(long double a);
- 
-unsigned long __fixunssfdi(float a);
-unsigned long __fixunsdfdi(double a);
-unsigned long __fixunstfdi(long double a);
-unsigned long __fixunsxfdi(long double a);
- 
-unsigned long long __fixunssfti(float a);
-unsigned long long __fixunsdfti(double a);
-unsigned long long __fixunstfti(long double a);
-unsigned long long __fixunsxfti(long double a);
- 
-float __floatsisf(int i);
-double __floatsidf(int i);
-long double __floatsitf(int i);
-long double __floatsixf(int i);
- 
-float __floatdisf(long i);
-double __floatdidf(long i);
-long double __floatditf(long i);
-long double __floatdixf(long i);
- 
-float __floattisf(long long i);
-double __floattidf(long long i);
-long double __floattitf(long long i);
-long double __floattixf(long long i);
- 
-float __floatunsisf(unsigned int i);
-double __floatunsidf(unsigned int i);
-long double __floatunsitf(unsigned int i);
-long double __floatunsixf(unsigned int i);
- 
-float __floatundisf(unsigned long i);
-double __floatundidf(unsigned long i);
-long double __floatunditf(unsigned long i);
-long double __floatundixf(unsigned long i);
- 
-float __floatuntisf(unsigned long long i);
-double __floatuntidf(unsigned long long i);
-long double __floatuntitf(unsigned long long i);
-long double __floatuntixf(unsigned long long i);
- 
-int __cmpsf2(float a, float b);
-int __cmpdf2(double a, double b);
-int __cmptf2(long double a, long double b);
- 
-int __unordsf2(float a, float b);
-int __unorddf2(double a, double b);
-int __unordtf2(long double a, long double b);
- 
-int __eqsf2(float a, float b);
-int __eqdf2(double a, double b);
-int __eqtf2(long double a, long double b);
- 
-int __nesf2(float a, float b);
-int __nedf2(double a, double b);
-int __netf2(long double a, long double b);
- 
-int __gesf2(float a, float b);
-int __gedf2(double a, double b);
-int __getf2(long double a, long double b);
- 
-int __ltsf2(float a, float b);
-int __ltdf2(double a, double b);
-int __lttf2(long double a, long double b);
-int __lesf2(float a, float b);
-int __ledf2(double a, double b);
-int __letf2(long double a, long double b);
- 
-int __gtsf2(float a, float b);
-int __gtdf2(double a, double b);
-int __gttf2(long double a, long double b);
- 
-/* Not implemented yet*/ 
-float __powisf2(float a, int b);
+extern float __addsf3(float, float);
+extern double __adddf3(double, double);
+extern long double __addtf3(long double, long double);
+extern long double __addxf3(long double, long double);
+
+extern float __subsf3(float, float);
+extern double __subdf3(double, double);
+extern long double __subtf3(long double, long double);
+extern long double __subxf3(long double, long double);
+
+extern float __mulsf3(float, float);
+extern double __muldf3(double, double);
+extern long double __multf3(long double, long double);
+extern long double __mulxf3(long double, long double);
+
+extern float __divsf3(float, float);
+extern double __divdf3(double, double);
+extern long double __divtf3(long double, long double);
+extern long double __divxf3(long double, long double);
+
+extern float __negsf2(float);
+extern double __negdf2(double);
+extern long double __negtf2(long double);
+extern long double __negxf2(long double);
+
+extern double __extendsfdf2(float);
+extern long double __extendsftf2(float);
+extern long double __extendsfxf2(float);
+extern long double __extenddftf2(double);
+extern long double __extenddfxf2(double);
+
+extern double __truncxfdf2(long double);
+extern double __trunctfdf2(long double);
+extern float __truncxfsf2(long double);
+extern float __trunctfsf2(long double);
+extern float __truncdfsf2(double);
+
+extern int __fixsfsi(float);
+extern int __fixdfsi(double);
+extern int __fixtfsi(long double);
+extern int __fixxfsi(long double);
+
+extern long __fixsfdi(float);
+extern long __fixdfdi(double);
+extern long __fixtfdi(long double);
+extern long __fixxfdi(long double);
+
+extern long long __fixsfti(float);
+extern long long __fixdfti(double);
+extern long long __fixtfti(long double);
+extern long long __fixxfti(long double);
+
+extern unsigned int __fixunssfsi(float);
+extern unsigned int __fixunsdfsi(double);
+extern unsigned int __fixunstfsi(long double);
+extern unsigned int __fixunsxfsi(long double);
+
+extern unsigned long __fixunssfdi(float);
+extern unsigned long __fixunsdfdi(double);
+extern unsigned long __fixunstfdi(long double);
+extern unsigned long __fixunsxfdi(long double);
+
+extern unsigned long long __fixunssfti(float);
+extern unsigned long long __fixunsdfti(double);
+extern unsigned long long __fixunstfti(long double);
+extern unsigned long long __fixunsxfti(long double);
+
+extern float __floatsisf(int);
+extern double __floatsidf(int);
+extern long double __floatsitf(int);
+extern long double __floatsixf(int);
+
+extern float __floatdisf(long);
+extern double __floatdidf(long);
+extern long double __floatditf(long);
+extern long double __floatdixf(long);
+
+extern float __floattisf(long long);
+extern double __floattidf(long long);
+extern long double __floattitf(long long);
+extern long double __floattixf(long long);
+
+extern float __floatunsisf(unsigned int);
+extern double __floatunsidf(unsigned int);
+extern long double __floatunsitf(unsigned int);
+extern long double __floatunsixf(unsigned int);
+
+extern float __floatundisf(unsigned long);
+extern double __floatundidf(unsigned long);
+extern long double __floatunditf(unsigned long);
+extern long double __floatundixf(unsigned long);
+
+extern float __floatuntisf(unsigned long long);
+extern double __floatuntidf(unsigned long long);
+extern long double __floatuntitf(unsigned long long);
+extern long double __floatuntixf(unsigned long long);
+
+extern int __cmpsf2(float, float);
+extern int __cmpdf2(double, double);
+extern int __cmptf2(long double, long double);
+
+extern int __unordsf2(float, float);
+extern int __unorddf2(double, double);
+extern int __unordtf2(long double, long double);
+
+extern int __eqsf2(float, float);
+extern int __eqdf2(double, double);
+extern int __eqtf2(long double, long double);
+
+extern int __nesf2(float, float);
+extern int __nedf2(double, double);
+extern int __netf2(long double, long double);
+
+extern int __gesf2(float, float);
+extern int __gedf2(double, double);
+extern int __getf2(long double, long double);
+
+extern int __ltsf2(float, float);
+extern int __ltdf2(double, double);
+extern int __lttf2(long double, long double);
+extern int __lesf2(float, float);
+extern int __ledf2(double, double);
+extern int __letf2(long double, long double);
+
+extern int __gtsf2(float, float);
+extern int __gtdf2(double, double);
+extern int __gttf2(long double, long double);
+
+/* Not implemented yet */
+extern float __powisf2(float, int);
 
 #endif
 
-
- /** @}
+/** @}
  */
-
Index: uspace/lib/softfloat/include/sub.h
===================================================================
--- uspace/lib/softfloat/include/sub.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softfloat/include/sub.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup softfloat	
+/** @addtogroup softfloat
  * @{
  */
@@ -36,12 +36,9 @@
 #define __SUB_H__
 
-float32 subFloat32(float32 a, float32 b);
-
-float64 subFloat64(float64 a, float64 b);
+extern float32 subFloat32(float32, float32);
+extern float64 subFloat64(float64, float64);
 
 #endif
 
-
- /** @}
+/** @}
  */
-
Index: uspace/lib/softint/Makefile
===================================================================
--- uspace/lib/softint/Makefile	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/softint/Makefile	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -31,7 +31,9 @@
 EXTRA_CFLAGS = -Iinclude
 LIBRARY = libsoftint
+SLIBRARY = libsoftint.so.0.0
+LSONAME = libsofti.so0
 
 SOURCES = \
-	generic/division.c\
+	generic/division.c \
 	generic/multiplication.c
 
Index: uspace/lib/usbhid/src/hidparser.c
===================================================================
--- uspace/lib/usbhid/src/hidparser.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/usbhid/src/hidparser.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -46,5 +46,5 @@
  */
 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size);
-inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
+//inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
 int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data);
 uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int32_t value);
Index: uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -40,4 +40,5 @@
 #define LIBUSB_HOST_YSB_ENDPOINT_MANAGER_H
 
+#include <stdlib.h>
 #include <adt/hash_table.h>
 #include <fibril_synch.h>
Index: uspace/lib/usbhost/src/endpoint.c
===================================================================
--- uspace/lib/usbhost/src/endpoint.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/usbhost/src/endpoint.c	(revision 3375bd4db69b0aa8eb7d3766620c112904c2dab3)
@@ -35,4 +35,5 @@
 
 #include <assert.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <usb/host/endpoint.h>
