Index: Makefile
===================================================================
--- Makefile	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ Makefile	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -136,5 +136,5 @@
 $(ERRNO_HEADER): $(ERRNO_INPUT)
 	echo '/* Generated file. Edit errno.in instead. */' > $@.new
-	sed 's/__errno_entry(\([^,]*\),\([^,]*\),.*/#define \1 \2/' < $< >> $@.new
+	sed 's/__errno_entry(\([^,]*\),\([^,]*\),.*/#define \1 __errno_t(\2)/' < $< >> $@.new
 	mv $@.new $@
 
Index: abi/include/_bits/errno.h
===================================================================
--- abi/include/_bits/errno.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
+++ abi/include/_bits/errno.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+
+/* Authors:
+ *	Jiří Zárevúcky (jzr) <zarevucky.jiri@gmail.com>
+ */
+
+/** @addtogroup bits
+ * @{
+ */
+/** @file
+ */
+
+#ifndef _BITS_ERRNO_H_
+#define _BITS_ERRNO_H_
+
+#ifdef __OPAQUE_ERRNO__
+#include <_bits/opaque_handle.h>
+
+opaque_handle(errno_t);
+typedef errno_t sys_errno_t;
+#define __errno_t(val) ((errno_t) val)
+
+#else
+
+#include <_bits/native.h>
+
+/**
+ * The type of <errno.h> constants. Normally, this is an alias for `int`,
+ * but we support an alternative definition that allows us to verify
+ * integrity of error handling without using external tools.
+ */
+typedef int errno_t;
+
+/**
+ * Same as `errno_t`, except represented as `sysarg_t`. Used in kernel in
+ * places where error number is always passed, but the type must be `sysarg_t`.
+ */
+typedef sysarg_t sys_errno_t;
+
+/**
+ * A C++-style "cast" to `errno_t`.
+ * Used in <abi/errno.h> to define error constants. Normally, it doesn't do
+ * anything at all.
+ */
+#define __errno_t(val) val
+
+#endif
+
+#endif
Index: abi/include/_bits/opaque_handle.h
===================================================================
--- abi/include/_bits/opaque_handle.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
+++ abi/include/_bits/opaque_handle.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+
+/* Authors:
+ *	Jiří Zárevúcky (jzr) <zarevucky.jiri@gmail.com>
+ */
+
+/** @addtogroup bits
+ * @{
+ */
+
+#ifndef _BITS_OPAQUE_HANDLE_H_
+#define _BITS_OPAQUE_HANDLE_H_
+
+#define opaque_handle(__name) typedef struct __opaque_##__name *__name
+
+#endif
+
+/** @}
+ */
Index: abi/include/abi/errno.h
===================================================================
--- abi/include/abi/errno.h	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ abi/include/abi/errno.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -1,38 +1,44 @@
 /* Generated file. Edit errno.in instead. */
-#define EOK                   0
-#define ENOENT               -1
-#define ENOMEM               -2
-#define ELIMIT               -3
-#define EREFUSED             -4
-#define EFORWARD             -5
-#define EPERM                -6
-#define EHANGUP              -7
-#define EPARTY               -8
-#define EEXIST               -9
-#define EBADMEM             -10
-#define ENOTSUP             -11
-#define EADDRNOTAVAIL       -12
-#define ETIMEOUT            -13
-#define EINVAL              -14
-#define EBUSY               -15
-#define EOVERFLOW           -16
-#define EINTR               -17
-#define EMFILE              -18
-#define ENAMETOOLONG       -256
-#define EISDIR             -257
-#define ENOTDIR            -258
-#define ENOSPC             -259
-#define ENOTEMPTY          -261
-#define EBADF              -262
-#define EDOM               -263
-#define ERANGE             -264
-#define EXDEV              -265
-#define EIO                -266
-#define EMLINK             -267
-#define ENXIO              -268
-#define ENOFS              -269
-#define EBADCHECKSUM       -300
-#define ESTALL             -301
-#define EEMPTY             -302
-#define ENAK               -303
-#define EAGAIN           -11002
+#define EOK             __errno_t(      0)
+#define ENOENT          __errno_t(     -1)
+#define ENOMEM          __errno_t(     -2)
+#define ELIMIT          __errno_t(     -3)
+#define EREFUSED        __errno_t(     -4)
+#define EFORWARD        __errno_t(     -5)
+#define EPERM           __errno_t(     -6)
+#define EHANGUP         __errno_t(     -7)
+#define EPARTY          __errno_t(     -8)
+#define EEXIST          __errno_t(     -9)
+#define EBADMEM         __errno_t(    -10)
+#define ENOTSUP         __errno_t(    -11)
+#define EADDRNOTAVAIL   __errno_t(    -12)
+#define ETIMEOUT        __errno_t(    -13)
+#define EINVAL          __errno_t(    -14)
+#define EBUSY           __errno_t(    -15)
+#define EOVERFLOW       __errno_t(    -16)
+#define EINTR           __errno_t(    -17)
+#define EMFILE          __errno_t(    -18)
+#define ENAMETOOLONG    __errno_t(   -256)
+#define EISDIR          __errno_t(   -257)
+#define ENOTDIR         __errno_t(   -258)
+#define ENOSPC          __errno_t(   -259)
+#define ENOTEMPTY       __errno_t(   -261)
+#define EBADF           __errno_t(   -262)
+#define EDOM            __errno_t(   -263)
+#define ERANGE          __errno_t(   -264)
+#define EXDEV           __errno_t(   -265)
+#define EIO             __errno_t(   -266)
+#define EMLINK          __errno_t(   -267)
+#define ENXIO           __errno_t(   -268)
+#define ENOFS           __errno_t(   -269)
+#define EBADCHECKSUM    __errno_t(   -300)
+#define ESTALL          __errno_t(   -301)
+#define EEMPTY          __errno_t(   -302)
+#define ENAK            __errno_t(   -303)
+#define EAGAIN          __errno_t( -11002)
+
+#define HTTP_EMULTIPLE_HEADERS  __errno_t( -20001)
+#define HTTP_EMISSING_HEADER    __errno_t( -20002)
+#define HTTP_EPARSE             __errno_t( -20003)
+
+#define EXT4_ERR_BAD_DX_DIR     __errno_t( -75000)
Index: abi/include/abi/errno.in
===================================================================
--- abi/include/abi/errno.in	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ abi/include/abi/errno.in	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -35,3 +35,9 @@
 __errno_entry(EEMPTY         ,   -302, "Resource is empty")
 __errno_entry(ENAK           ,   -303, "Negative acknowledgement")
-__errno_entry(EAGAIN         , -11002, "Operation could not proceed. Try again.")
+__errno_entry(EAGAIN         , -11002, "Operation could not proceed, try again")
+
+__errno_entry(HTTP_EMULTIPLE_HEADERS , -20001, "HTTP: Multiple headers")  // libhttp error codes. Defining them here is a temporary hack.
+__errno_entry(HTTP_EMISSING_HEADER   , -20002, "HTTP: Missing header")
+__errno_entry(HTTP_EPARSE            , -20003, "HTTP: Parse error")
+
+__errno_entry(EXT4_ERR_BAD_DX_DIR    , -75000, "EXT4: Filesystem corrupted")  // libext4
Index: abi/include/abi/ipc/ipc.h
===================================================================
--- abi/include/abi/ipc/ipc.h	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ abi/include/abi/ipc/ipc.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -70,5 +70,5 @@
 
 /* Macros for manipulating calling data */
-#define IPC_SET_RETVAL(data, retval)  ((data).args[0] = (retval))
+#define IPC_SET_RETVAL(data, retval)  ((data).args[0] = (sysarg_t) (retval))
 #define IPC_SET_IMETHOD(data, val)    ((data).args[0] = (val))
 #define IPC_SET_ARG1(data, val)       ((data).args[1] = (val))
@@ -79,5 +79,5 @@
 
 #define IPC_GET_IMETHOD(data)  ((data).args[0])
-#define IPC_GET_RETVAL(data)   ((data).args[0])
+#define IPC_GET_RETVAL(data)   ((errno_t) (data).args[0])
 
 #define IPC_GET_ARG1(data)  ((data).args[1])
Index: kernel/generic/include/errno.h
===================================================================
--- kernel/generic/include/errno.h	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ kernel/generic/include/errno.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -36,6 +36,5 @@
 #define KERN_ERRNO_H_
 
-typedef int errno_t;
-
+#include <_bits/errno.h>
 #include <abi/errno.h>
 
Index: kernel/generic/include/typedefs.h
===================================================================
--- kernel/generic/include/typedefs.h	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ kernel/generic/include/typedefs.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -37,4 +37,5 @@
 
 #include <arch/types.h>
+#include <_bits/errno.h>
 
 typedef struct {
Index: uspace/app/sbi/src/mytypes.h
===================================================================
--- uspace/app/sbi/src/mytypes.h	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ uspace/app/sbi/src/mytypes.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -53,5 +53,8 @@
 /** We need NULL defined. */
 #include <stddef.h>
+
+#ifndef EOK
 #define EOK 0
+#endif
 
 #include "bigint_t.h"
Index: uspace/lib/c/include/errno.h
===================================================================
--- uspace/lib/c/include/errno.h	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ uspace/lib/c/include/errno.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -36,6 +36,5 @@
 #define LIBC_ERRNO_H_
 
-typedef int errno_t;
-
+#include <_bits/errno.h>
 #include <abi/errno.h>
 
Index: uspace/lib/c/include/types/common.h
===================================================================
--- uspace/lib/c/include/types/common.h	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ uspace/lib/c/include/types/common.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -45,4 +45,5 @@
 
 #include <_bits/all.h>
+#include <_bits/errno.h>
 
 #endif
Index: uspace/lib/ext4/include/ext4/types.h
===================================================================
--- uspace/lib/ext4/include/ext4/types.h	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ uspace/lib/ext4/include/ext4/types.h	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -476,5 +476,4 @@
 } ext4_directory_dx_block_t;
 
-#define EXT4_ERR_BAD_DX_DIR       (-75000)
 #define EXT4_DIRECTORY_HTREE_EOF  UINT32_C(0x7fffffff)
 
Index: pace/lib/http/include/http/errno.h
===================================================================
--- uspace/lib/http/include/http/errno.h	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/*
- * Copyright (c) 2013 Martin Sucha
- * 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 http
- * @{
- */
-/**
- * @file
- */
-
-#ifndef HTTP_ERRNO_H_
-#define HTTP_ERRNO_H_
-
-#include <errno.h>
-
-#define HTTP_EMULTIPLE_HEADERS -20001
-#define HTTP_EMISSING_HEADER -20002
-#define HTTP_EPARSE -20003
-
-#endif
-
-/** @}
- */
Index: uspace/lib/http/src/headers.c
===================================================================
--- uspace/lib/http/src/headers.c	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ uspace/lib/http/src/headers.c	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -34,4 +34,5 @@
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -41,5 +42,4 @@
 #include <http/http.h>
 #include <http/ctype.h>
-#include <http/errno.h>
 
 #define HTTP_HEADER_LINE "%s: %s\r\n"
Index: uspace/lib/http/src/response.c
===================================================================
--- uspace/lib/http/src/response.c	(revision db3089df1b73fd8c776071a2bef307f5226bdf9b)
+++ uspace/lib/http/src/response.c	(revision 10de84286f36c6e4f3f92d59c073639668ffe9a1)
@@ -34,4 +34,5 @@
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -40,5 +41,4 @@
 
 #include <http/http.h>
-#include <http/errno.h>
 
 static bool is_digit(char c)
