Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 5a504309b8f5da2b18e6cc9af46dac049ced39f1)
+++ uspace/lib/c/Makefile	(revision 7137f74c74c9c2eea4980d18b86a6d9667725946)
@@ -51,4 +51,5 @@
 	generic/libc.c \
 	generic/ddi.c \
+	generic/atomic.c \
 	generic/as.c \
 	generic/bd.c \
Index: uspace/lib/c/arch/arm32/include/libarch/atomic.h
===================================================================
--- uspace/lib/c/arch/arm32/include/libarch/atomic.h	(revision 5a504309b8f5da2b18e6cc9af46dac049ced39f1)
+++ uspace/lib/c/arch/arm32/include/libarch/atomic.h	(revision 7137f74c74c9c2eea4980d18b86a6d9667725946)
@@ -52,5 +52,5 @@
 	/*
 	 * The following instructions between labels 1 and 2 constitute a
-	 * Restartable Atomic Seqeunce. Should the sequence be non-atomic,
+	 * Restartable Atomic Sequence. Should the sequence be non-atomic,
 	 * the kernel will restart it.
 	 */
Index: uspace/lib/c/generic/atomic.c
===================================================================
--- uspace/lib/c/generic/atomic.c	(revision 7137f74c74c9c2eea4980d18b86a6d9667725946)
+++ uspace/lib/c/generic/atomic.c	(revision 7137f74c74c9c2eea4980d18b86a6d9667725946)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2018 CZ.NIC, z.s.p.o.
+ * 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.
+ */
+
+#include <atomic.h>
+
+#ifdef PLATFORM_arm32
+
+/*
+ * Older ARMs don't have atomic instructions, so we need to define a bunch
+ * of symbols for GCC to use.
+ */
+
+unsigned __sync_add_and_fetch_4(volatile void *vptr, unsigned val)
+{
+	return atomic_add((atomic_t *)vptr, val);
+}
+
+unsigned __sync_sub_and_fetch_4(volatile void *vptr, unsigned val)
+{
+	return atomic_add((atomic_t *)vptr, -(atomic_signed_t)val);
+}
+
+bool __sync_bool_compare_and_swap_4(volatile void *ptr, unsigned old_val, unsigned new_val)
+{
+	return cas((atomic_t *)ptr, old_val, new_val);
+}
+
+unsigned __sync_val_compare_and_swap_4(volatile void *ptr, unsigned old_val, unsigned new_val)
+{
+	while (true) {
+		if (__sync_bool_compare_and_swap_4(ptr, old_val, new_val)) {
+			return old_val;
+		}
+
+		unsigned current = *(volatile unsigned *)ptr;
+		if (current != old_val)
+			return current;
+
+		/* If the current value is the same as old_val, retry. */
+	}
+}
+
+#endif
Index: uspace/lib/cpp/Makefile
===================================================================
--- uspace/lib/cpp/Makefile	(revision 5a504309b8f5da2b18e6cc9af46dac049ced39f1)
+++ uspace/lib/cpp/Makefile	(revision 7137f74c74c9c2eea4980d18b86a6d9667725946)
@@ -53,5 +53,4 @@
 	src/typeindex.cpp \
 	src/typeinfo.cpp \
-	src/__bits/glue.cpp \
 	src/__bits/runtime.cpp \
 	src/__bits/trycatch.cpp \
Index: pace/lib/cpp/src/__bits/glue.cpp
===================================================================
--- uspace/lib/cpp/src/__bits/glue.cpp	(revision 5a504309b8f5da2b18e6cc9af46dac049ced39f1)
+++ 	(revision )
@@ -1,65 +1,0 @@
-/*
- * Copyright (c) 2018 Jaroslav Jindrak
- * 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.
- */
-
-/**
- * This file contains glue code that makes different
- * architectures pass.
- */
-
-#ifdef PLATFORM_arm32
-
-/**
- * ARM32 does not have GCC atomic operations inlined by
- * the compiler, so we need to define stubs for our library
- * to compile on this architecture.
- * TODO: make this synchronized
- */
-extern "C"
-{
-#define LIBCPP_GLUE_OP_AND_FETCH(NAME, OP, TYPE, SIZE) \
-    TYPE __sync_##NAME##_and_fetch_##SIZE (volatile void* vptr, TYPE val) \
-    { \
-        TYPE* ptr = (TYPE*)vptr; \
-        *ptr = *ptr OP val; \
-        return *ptr; \
-    }
-
-LIBCPP_GLUE_OP_AND_FETCH(add, +, unsigned, 4)
-LIBCPP_GLUE_OP_AND_FETCH(sub, -, unsigned, 4)
-
-#define LIBCPP_GLUE_CMP_AND_SWAP(TYPE, SIZE) \
-    TYPE __sync_val_compare_and_swap_##SIZE (TYPE* ptr, TYPE old_val, TYPE new_val) \
-    { \
-        if (*ptr == old_val) \
-            *ptr = new_val; \
-        return *ptr; \
-    }
-
-LIBCPP_GLUE_CMP_AND_SWAP(unsigned, 4)
-}
-#endif
