Index: abi/include/abi/cap.h
===================================================================
--- abi/include/abi/cap.h	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ abi/include/abi/cap.h	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -36,8 +36,8 @@
 #define ABI_CAP_H_
 
+#include <stdbool.h>
+#include <stdint.h>
+
 #define CAP_NIL  0
-
-#define CAP_HANDLE_VALID(handle)  ((handle) != CAP_NIL)
-#define CAP_HANDLE_RAW(handle)    ((intptr_t) (handle))
 
 typedef void *cap_handle_t;
@@ -55,4 +55,14 @@
 } *cap_waitq_handle_t;
 
+static inline bool cap_handle_valid(cap_handle_t handle)
+{
+	return handle != CAP_NIL;
+}
+
+static inline intptr_t cap_handle_raw(cap_handle_t handle)
+{
+	return (intptr_t) handle;
+}
+
 #endif
 
Index: kernel/generic/src/cap/cap.c
===================================================================
--- kernel/generic/src/cap/cap.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ kernel/generic/src/cap/cap.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -98,5 +98,5 @@
 {
 	cap_t *cap = hash_table_get_inst(item, cap_t, caps_link);
-	return hash_mix(CAP_HANDLE_RAW(cap->handle));
+	return hash_mix(cap_handle_raw(cap->handle));
 }
 
@@ -104,5 +104,5 @@
 {
 	cap_handle_t *handle = (cap_handle_t *) key;
-	return hash_mix(CAP_HANDLE_RAW(*handle));
+	return hash_mix(cap_handle_raw(*handle));
 }
 
@@ -232,6 +232,6 @@
 	assert(mutex_locked(&task->cap_info->lock));
 
-	if ((CAP_HANDLE_RAW(handle) < CAPS_START) ||
-	    (CAP_HANDLE_RAW(handle) > CAPS_LAST))
+	if ((cap_handle_raw(handle) < CAPS_START) ||
+	    (cap_handle_raw(handle) > CAPS_LAST))
 		return NULL;
 	ht_link_t *link = hash_table_find(&task->cap_info->caps, &handle);
@@ -383,6 +383,6 @@
 void cap_free(task_t *task, cap_handle_t handle)
 {
-	assert(CAP_HANDLE_RAW(handle) >= CAPS_START);
-	assert(CAP_HANDLE_RAW(handle) <= CAPS_LAST);
+	assert(cap_handle_raw(handle) >= CAPS_START);
+	assert(cap_handle_raw(handle) <= CAPS_LAST);
 
 	mutex_lock(&task->cap_info->lock);
@@ -392,5 +392,5 @@
 
 	hash_table_remove_item(&task->cap_info->caps, &cap->caps_link);
-	ra_free(task->cap_info->handles, CAP_HANDLE_RAW(handle), 1);
+	ra_free(task->cap_info->handles, cap_handle_raw(handle), 1);
 	slab_free(cap_cache, cap);
 	mutex_unlock(&task->cap_info->lock);
Index: kernel/generic/src/ipc/ipc.c
===================================================================
--- kernel/generic/src/ipc/ipc.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ kernel/generic/src/ipc/ipc.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -931,5 +931,5 @@
 	mutex_lock(&phone->lock);
 	if (phone->state != IPC_PHONE_FREE) {
-		printf("%-11d %7" PRIun " ", (int) CAP_HANDLE_RAW(cap->handle),
+		printf("%-11d %7" PRIun " ", (int) cap_handle_raw(cap->handle),
 		    atomic_load(&phone->active_calls));
 
Index: kernel/generic/src/ipc/ops/conctmeto.c
===================================================================
--- kernel/generic/src/ipc/ops/conctmeto.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ kernel/generic/src/ipc/ops/conctmeto.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -68,5 +68,5 @@
 	cap_phone_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(call->data);
 
-	if (CAP_HANDLE_RAW(phandle) < 0)
+	if (cap_handle_raw(phandle) < 0)
 		return EOK;
 
@@ -113,5 +113,5 @@
 
 	if (IPC_GET_RETVAL(answer->data)) {
-		if (CAP_HANDLE_RAW(phandle) >= 0) {
+		if (cap_handle_raw(phandle) >= 0) {
 			/*
 			 * Cleanup the unpublished capability and drop
Index: kernel/generic/src/ipc/ops/concttome.c
===================================================================
--- kernel/generic/src/ipc/ops/concttome.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ kernel/generic/src/ipc/ops/concttome.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -52,5 +52,5 @@
 	}
 	call->priv = (sysarg_t) pobj;
-	IPC_SET_ARG5(call->data, CAP_HANDLE_RAW(phandle));
+	IPC_SET_ARG5(call->data, cap_handle_raw(phandle));
 	return 0;
 }
@@ -61,5 +61,5 @@
 	kobject_t *pobj = (kobject_t *) answer->priv;
 
-	if (CAP_HANDLE_VALID(phandle)) {
+	if (cap_handle_valid(phandle)) {
 		kobject_put(pobj);
 		cap_free(TASK, phandle);
@@ -77,5 +77,5 @@
 		/* The connection was not accepted */
 		answer_cleanup(answer, olddata);
-	} else if (CAP_HANDLE_VALID(phandle)) {
+	} else if (cap_handle_valid(phandle)) {
 		/*
 		 * The connection was accepted
Index: kernel/generic/src/ipc/sysipc.c
===================================================================
--- kernel/generic/src/ipc/sysipc.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ kernel/generic/src/ipc/sysipc.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -841,5 +841,5 @@
 
 error:
-	if (CAP_HANDLE_VALID(handle))
+	if (cap_handle_valid(handle))
 		cap_free(TASK, handle);
 
Index: uspace/app/trace/ipcp.c
===================================================================
--- uspace/app/trace/ipcp.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/app/trace/ipcp.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -75,5 +75,5 @@
 {
 	cap_call_handle_t *chandle = (cap_call_handle_t *) key;
-	return CAP_HANDLE_RAW(*chandle);
+	return cap_handle_raw(*chandle);
 }
 
@@ -81,5 +81,5 @@
 {
 	pending_call_t *hs = hash_table_get_inst(item, pending_call_t, link);
-	return CAP_HANDLE_RAW(hs->call_handle);
+	return cap_handle_raw(hs->call_handle);
 }
 
@@ -104,16 +104,16 @@
 	// XXX: there is no longer a limit on the number of phones as phones are
 	// now handled using capabilities
-	if (CAP_HANDLE_RAW(phone) < 0 || CAP_HANDLE_RAW(phone) >= MAX_PHONE)
+	if (cap_handle_raw(phone) < 0 || cap_handle_raw(phone) >= MAX_PHONE)
 		return;
-	connections[CAP_HANDLE_RAW(phone)].server = server;
-	connections[CAP_HANDLE_RAW(phone)].proto = proto;
-	have_conn[CAP_HANDLE_RAW(phone)] = 1;
+	connections[cap_handle_raw(phone)].server = server;
+	connections[cap_handle_raw(phone)].proto = proto;
+	have_conn[cap_handle_raw(phone)] = 1;
 }
 
 void ipcp_connection_clear(cap_phone_handle_t phone)
 {
-	have_conn[CAP_HANDLE_RAW(phone)] = 0;
-	connections[CAP_HANDLE_RAW(phone)].server = 0;
-	connections[CAP_HANDLE_RAW(phone)].proto = NULL;
+	have_conn[cap_handle_raw(phone)] = 0;
+	connections[cap_handle_raw(phone)].server = 0;
+	connections[cap_handle_raw(phone)].proto = NULL;
 }
 
@@ -184,6 +184,6 @@
 	int i;
 
-	if (have_conn[CAP_HANDLE_RAW(phandle)])
-		proto = connections[CAP_HANDLE_RAW(phandle)].proto;
+	if (have_conn[cap_handle_raw(phandle)])
+		proto = connections[cap_handle_raw(phandle)].proto;
 	else
 		proto = NULL;
Index: uspace/drv/bus/usb/ohci/hc.c
===================================================================
--- uspace/drv/bus/usb/ohci/hc.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/drv/bus/usb/ohci/hc.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -514,5 +514,5 @@
 
 	/* Enable interrupts */
-	if (CAP_HANDLE_VALID(instance->base.irq_handle)) {
+	if (cap_handle_valid(instance->base.irq_handle)) {
 		OHCI_WR(instance->registers->interrupt_enable,
 		    OHCI_USED_INTERRUPTS);
Index: uspace/drv/bus/usb/uhci/hc.c
===================================================================
--- uspace/drv/bus/usb/uhci/hc.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/drv/bus/usb/uhci/hc.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -295,5 +295,5 @@
 	pio_write_32(&registers->flbaseadd, pa);
 
-	if (CAP_HANDLE_VALID(instance->base.irq_handle)) {
+	if (cap_handle_valid(instance->base.irq_handle)) {
 		/* Enable all interrupts, but resume interrupt */
 		pio_write_16(&instance->registers->usbintr,
Index: uspace/drv/bus/usb/xhci/hc.c
===================================================================
--- uspace/drv/bus/usb/xhci/hc.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/drv/bus/usb/xhci/hc.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -494,5 +494,5 @@
 	XHCI_REG_WR(intr0, XHCI_INTR_ERSTBA, erstba_phys);
 
-	if (CAP_HANDLE_VALID(hc->base.irq_handle)) {
+	if (cap_handle_valid(hc->base.irq_handle)) {
 		XHCI_REG_SET(intr0, XHCI_INTR_IE, 1);
 		XHCI_REG_SET(hc->op_regs, XHCI_OP_INTE, 1);
Index: uspace/drv/char/msim-con/msim-con.c
===================================================================
--- uspace/drv/char/msim-con/msim-con.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/drv/char/msim-con/msim-con.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -156,5 +156,5 @@
 	return EOK;
 error:
-	if (CAP_HANDLE_VALID(con->irq_handle))
+	if (cap_handle_valid(con->irq_handle))
 		async_irq_unsubscribe(con->irq_handle);
 	if (bound)
Index: uspace/drv/char/pc-lpt/pc-lpt.c
===================================================================
--- uspace/drv/char/pc-lpt/pc-lpt.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/drv/char/pc-lpt/pc-lpt.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -173,5 +173,5 @@
 	return EOK;
 error:
-	if (CAP_HANDLE_VALID(lpt->irq_handle))
+	if (cap_handle_valid(lpt->irq_handle))
 		async_irq_unsubscribe(lpt->irq_handle);
 	if (bound)
Index: uspace/lib/c/generic/async/client.c
===================================================================
--- uspace/lib/c/generic/async/client.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/lib/c/generic/async/client.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -1260,5 +1260,5 @@
 {
 	return async_req_5_0(exch, IPC_M_STATE_CHANGE_AUTHORIZE,
-	    arg1, arg2, arg3, 0, CAP_HANDLE_RAW(other_exch->phone));
+	    arg1, arg2, arg3, 0, cap_handle_raw(other_exch->phone));
 }
 
Index: uspace/lib/c/generic/async/server.c
===================================================================
--- uspace/lib/c/generic/async/server.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/lib/c/generic/async/server.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -1735,5 +1735,5 @@
 
 	if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) ||
-	    !CAP_HANDLE_VALID((phandle))) {
+	    !cap_handle_valid((phandle))) {
 		async_answer_0(&call, EINVAL);
 		return NULL;
@@ -1779,5 +1779,5 @@
 
 	if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) ||
-	    !CAP_HANDLE_VALID((phandle)))
+	    !cap_handle_valid((phandle)))
 		return NULL;
 
@@ -1813,5 +1813,5 @@
 	assert(call);
 
-	return async_answer_1(call, EOK, CAP_HANDLE_RAW(other_exch->phone));
+	return async_answer_1(call, EOK, cap_handle_raw(other_exch->phone));
 }
 
Index: uspace/lib/c/generic/ipc.c
===================================================================
--- uspace/lib/c/generic/ipc.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/lib/c/generic/ipc.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -71,5 +71,5 @@
 {
 	return __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST,
-	    CAP_HANDLE_RAW(phandle), imethod, arg1, arg2, arg3,
+	    cap_handle_raw(phandle), imethod, arg1, arg2, arg3,
 	    (sysarg_t) label);
 }
@@ -106,5 +106,5 @@
 
 	return __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW,
-	    CAP_HANDLE_RAW(phandle), (sysarg_t) &data,
+	    cap_handle_raw(phandle), (sysarg_t) &data,
 	    (sysarg_t) label);
 }
@@ -130,5 +130,5 @@
 {
 	return (errno_t) __SYSCALL6(SYS_IPC_ANSWER_FAST,
-	    CAP_HANDLE_RAW(chandle), (sysarg_t) retval, arg1, arg2, arg3, arg4);
+	    cap_handle_raw(chandle), (sysarg_t) retval, arg1, arg2, arg3, arg4);
 }
 
@@ -160,5 +160,5 @@
 
 	return (errno_t) __SYSCALL2(SYS_IPC_ANSWER_SLOW,
-	    CAP_HANDLE_RAW(chandle), (sysarg_t) &data);
+	    cap_handle_raw(chandle), (sysarg_t) &data);
 }
 
@@ -186,5 +186,5 @@
 errno_t ipc_hangup(cap_phone_handle_t phandle)
 {
-	return (errno_t) __SYSCALL1(SYS_IPC_HANGUP, CAP_HANDLE_RAW(phandle));
+	return (errno_t) __SYSCALL1(SYS_IPC_HANGUP, cap_handle_raw(phandle));
 }
 
@@ -210,5 +210,5 @@
 {
 	return (errno_t) __SYSCALL6(SYS_IPC_FORWARD_FAST,
-	    CAP_HANDLE_RAW(chandle), CAP_HANDLE_RAW(phandle), imethod, arg1,
+	    cap_handle_raw(chandle), cap_handle_raw(phandle), imethod, arg1,
 	    arg2, mode);
 }
@@ -228,5 +228,5 @@
 
 	return (errno_t) __SYSCALL4(SYS_IPC_FORWARD_SLOW,
-	    CAP_HANDLE_RAW(chandle), CAP_HANDLE_RAW(phandle), (sysarg_t) &data,
+	    cap_handle_raw(chandle), cap_handle_raw(phandle), (sysarg_t) &data,
 	    mode);
 }
Index: uspace/lib/c/generic/irq.c
===================================================================
--- uspace/lib/c/generic/irq.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/lib/c/generic/irq.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -83,5 +83,5 @@
 {
 	return (errno_t) __SYSCALL1(SYS_IPC_IRQ_UNSUBSCRIBE,
-	    CAP_HANDLE_RAW(cap));
+	    cap_handle_raw(cap));
 }
 
Index: uspace/lib/hound/src/protocol.c
===================================================================
--- uspace/lib/hound/src/protocol.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
+++ uspace/lib/hound/src/protocol.c	(revision bb9711836ee2378ff4d687181e9bf5bed89b1cbe)
@@ -158,5 +158,5 @@
 	async_exch_t *exch = async_exchange_begin(sess);
 	const errno_t ret = async_req_1_0(exch, IPC_M_HOUND_CONTEXT_UNREGISTER,
-	    CAP_HANDLE_RAW(id));
+	    cap_handle_raw(id));
 	async_exchange_end(exch);
 	return ret;
@@ -315,5 +315,5 @@
 	};
 
-	return async_req_4_0(exch, IPC_M_HOUND_STREAM_ENTER, CAP_HANDLE_RAW(id),
+	return async_req_4_0(exch, IPC_M_HOUND_STREAM_ENTER, cap_handle_raw(id),
 	    flags, c.arg, bsize);
 }
@@ -431,5 +431,5 @@
 				async_answer_0(&call, ret);
 			} else {
-				async_answer_1(&call, EOK, CAP_HANDLE_RAW(context));
+				async_answer_1(&call, EOK, cap_handle_raw(context));
 			}
 			break;
