Index: abi/include/abi/syscall.h
===================================================================
--- abi/include/abi/syscall.h	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ abi/include/abi/syscall.h	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -78,6 +78,6 @@
 	SYS_IPC_EVENT_UNMASK,
 	
-	SYS_CAP_GRANT,
-	SYS_CAP_REVOKE,
+	SYS_PERM_GRANT,
+	SYS_PERM_REVOKE,
 	
 	SYS_DEVICE_ASSIGN_DEVNO,
Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ kernel/Makefile	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -286,5 +286,5 @@
 	generic/src/ipc/irq.c \
 	generic/src/ipc/event.c \
-	generic/src/security/cap.c \
+	generic/src/security/perm.c \
 	generic/src/sysinfo/sysinfo.c \
 	generic/src/sysinfo/stats.c
Index: kernel/generic/include/proc/task.h
===================================================================
--- kernel/generic/include/proc/task.h	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ kernel/generic/include/proc/task.h	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -48,5 +48,5 @@
 #include <adt/cht.h>
 #include <adt/list.h>
-#include <security/cap.h>
+#include <security/perm.h>
 #include <arch/proc/task.h>
 #include <arch/proc/thread.h>
@@ -93,6 +93,6 @@
 	atomic_t lifecount;
 	
-	/** Task capabilities. */
-	cap_t capabilities;
+	/** Task permissions. */
+	perm_t perms;
 	
 	/* IPC stuff */
@@ -159,6 +159,6 @@
 extern void task_print_list(bool);
 
-extern void cap_set(task_t *, cap_t);
-extern cap_t cap_get(task_t *);
+extern void perm_set(task_t *, perm_t);
+extern perm_t perm_get(task_t *);
 
 #ifndef task_create_arch
Index: rnel/generic/include/security/cap.h
===================================================================
--- kernel/generic/include/security/cap.h	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ 	(revision )
@@ -1,94 +1,0 @@
-/*
- * Copyright (c) 2006 Jakub Jermar
- * 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
- */
-
-/**
- * @file
- * @brief Capabilities definitions.
- *
- * Capabilities represent virtual rights that entitle their
- * holder to perform certain security sensitive tasks.
- *
- * Each task can have arbitrary combination of the capabilities
- * defined in this file. Therefore, they are required to be powers
- * of two.
- */
-
-#ifndef __CAP_H__
-#define __CAP_H__
-
-#include <typedefs.h>
-
-/**
- * CAP_CAP allows its holder to grant/revoke arbitrary
- * privilege to/from other tasks.
- */
-#define CAP_CAP  (1 << 0)
-
-/**
- * CAP_MEM_MANAGER allows its holder to map physical memory
- * to other tasks.
- */
-#define CAP_MEM_MANAGER  (1 << 1)
-
-/**
- * CAP_IO_MANAGER allows its holder to access I/O space
- * to other tasks.
- */
-#define CAP_IO_MANAGER  (1 << 2)
-
-/**
- * CAP_IRQ_REG entitles its holder to register IRQ handlers.
- */
-#define CAP_IRQ_REG  (1 << 3)
-
-typedef uint32_t cap_t;
-
-#ifdef __32_BITS__
-
-extern sysarg_t sys_cap_grant(sysarg64_t *, cap_t);
-extern sysarg_t sys_cap_revoke(sysarg64_t *, cap_t);
-
-#endif  /* __32_BITS__ */
-
-#ifdef __64_BITS__
-
-extern sysarg_t sys_cap_grant(sysarg_t, cap_t);
-extern sysarg_t sys_cap_revoke(sysarg_t, cap_t);
-
-#endif  /* __64_BITS__ */
-
-#endif
-
-/** @}
- */
Index: kernel/generic/include/security/perm.h
===================================================================
--- kernel/generic/include/security/perm.h	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
+++ kernel/generic/include/security/perm.h	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2006 Jakub Jermar
+ * 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
+ */
+
+/**
+ * @file
+ * @brief Task permissions definitions.
+ *
+ * Permissions represent virtual rights that entitle their
+ * holder to perform certain security sensitive tasks.
+ *
+ * Each task can have arbitrary combination of the permissions 
+ * defined in this file. Therefore, they are required to be powers
+ * of two.
+ */
+
+#ifndef __PERM_H__
+#define __PERM_H__
+
+#include <typedefs.h>
+
+/**
+ * PERM_PERM allows its holder to grant/revoke arbitrary permission to/from
+ * other tasks.
+ */
+#define PERM_PERM        (1 << 0)
+
+/**
+ * PERM_MEM_MANAGER allows its holder to map physical memory to other tasks.
+ */
+#define PERM_MEM_MANAGER (1 << 1)
+
+/**
+ * PERM_IO_MANAGER allows its holder to access I/O space to other tasks.
+ */
+#define PERM_IO_MANAGER  (1 << 2)
+
+/**
+ * PERM_IRQ_REG entitles its holder to register IRQ handlers.
+ */
+#define PERM_IRQ_REG     (1 << 3)
+
+typedef uint32_t perm_t;
+
+#ifdef __32_BITS__
+
+extern sysarg_t sys_perm_grant(sysarg64_t *, perm_t);
+extern sysarg_t sys_perm_revoke(sysarg64_t *, perm_t);
+
+#endif  /* __32_BITS__ */
+
+#ifdef __64_BITS__
+
+extern sysarg_t sys_perm_grant(sysarg_t, perm_t);
+extern sysarg_t sys_perm_revoke(sysarg_t, perm_t);
+
+#endif  /* __64_BITS__ */
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/src/ddi/ddi.c
===================================================================
--- kernel/generic/src/ddi/ddi.c	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ kernel/generic/src/ddi/ddi.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -42,5 +42,5 @@
 #include <ddi/ddi.h>
 #include <proc/task.h>
-#include <security/cap.h>
+#include <security/perm.h>
 #include <mm/frame.h>
 #include <mm/as.h>
@@ -96,5 +96,5 @@
  *
  * @return EOK on success.
- * @return EPERM if the caller lacks capabilities to use this syscall.
+ * @return EPERM if the caller lacks permissions to use this syscall.
  * @return EBADMEM if phys is not page aligned.
  * @return ENOENT if there is no task matching the specified ID or
@@ -116,5 +116,5 @@
 	 */
 	bool priv =
-	    ((cap_get(TASK) & CAP_MEM_MANAGER) == CAP_MEM_MANAGER);
+	    ((perm_get(TASK) & PERM_MEM_MANAGER) == PERM_MEM_MANAGER);
 	
 	mem_backend_data_t backend_data;
@@ -260,5 +260,5 @@
  * @param size   Size of the enabled I/O space.
  *
- * @return 0 on success, EPERM if the caller lacks capabilities to use this
+ * @return 0 on success, EPERM if the caller lacks permissions to use this
  *           syscall, ENOENT if there is no task matching the specified ID.
  *
@@ -269,6 +269,6 @@
 	 * Make sure the caller is authorised to make this syscall.
 	 */
-	cap_t caps = cap_get(TASK);
-	if (!(caps & CAP_IO_MANAGER))
+	perm_t perms = perm_get(TASK);
+	if (!(perms & PERM_IO_MANAGER))
 		return EPERM;
 	
@@ -301,5 +301,5 @@
  * @param size   Size of the enabled I/O space.
  *
- * @return 0 on success, EPERM if the caller lacks capabilities to use this
+ * @return 0 on success, EPERM if the caller lacks permissions to use this
  *           syscall, ENOENT if there is no task matching the specified ID.
  *
@@ -310,6 +310,6 @@
 	 * Make sure the caller is authorised to make this syscall.
 	 */
-	cap_t caps = cap_get(TASK);
-	if (!(caps & CAP_IO_MANAGER))
+	perm_t perms = perm_get(TASK);
+	if (!(perms & PERM_IO_MANAGER))
 		return EPERM;
 	
Index: kernel/generic/src/ipc/sysipc.c
===================================================================
--- kernel/generic/src/ipc/sysipc.c	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ kernel/generic/src/ipc/sysipc.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -48,5 +48,5 @@
 #include <arch/interrupt.h>
 #include <syscall/copy.h>
-#include <security/cap.h>
+#include <security/perm.h>
 #include <console/console.h>
 #include <print.h>
@@ -811,5 +811,5 @@
     irq_code_t *ucode)
 {
-	if (!(cap_get(TASK) & CAP_IRQ_REG))
+	if (!(perm_get(TASK) & PERM_IRQ_REG))
 		return EPERM;
 	
@@ -827,5 +827,5 @@
 sysarg_t sys_ipc_irq_unsubscribe(inr_t inr, devno_t devno)
 {
-	if (!(cap_get(TASK) & CAP_IRQ_REG))
+	if (!(perm_get(TASK) & PERM_IRQ_REG))
 		return EPERM;
 	
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ kernel/generic/src/main/kinit.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -64,5 +64,5 @@
 #include <interrupt.h>
 #include <console/kconsole.h>
-#include <security/cap.h>
+#include <security/perm.h>
 #include <lib/rd.h>
 #include <ipc/ipc.h>
@@ -259,8 +259,9 @@
 			if (programs[i].task != NULL) {
 				/*
-				 * Set capabilities to init userspace tasks.
+				 * Set permissions to init userspace tasks.
 				 */
-				cap_set(programs[i].task, CAP_CAP | CAP_MEM_MANAGER |
-				    CAP_IO_MANAGER | CAP_IRQ_REG);
+				perm_set(programs[i].task,
+				    PERM_PERM | PERM_MEM_MANAGER |
+				    PERM_IO_MANAGER | PERM_IRQ_REG);
 				
 				if (!ipc_phone_0) {
Index: kernel/generic/src/proc/program.c
===================================================================
--- kernel/generic/src/proc/program.c	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ kernel/generic/src/proc/program.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -46,5 +46,5 @@
 #include <ipc/ipc.h>
 #include <ipc/ipcrsc.h>
-#include <security/cap.h>
+#include <security/perm.h>
 #include <lib/elf_load.h>
 #include <errno.h>
@@ -244,6 +244,6 @@
 		return rc;
 	
-	// FIXME: control the capabilities
-	cap_set(prg.task, cap_get(TASK));
+	// FIXME: control the permissions 
+	perm_set(prg.task, perm_get(TASK));
 	program_ready(&prg);
 	
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ kernel/generic/src/proc/task.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -203,5 +203,5 @@
 	
 	task->container = CONTAINER;
-	task->capabilities = 0;
+	task->perms = 0;
 	task->ucycles = 0;
 	task->kcycles = 0;
Index: rnel/generic/src/security/cap.c
===================================================================
--- kernel/generic/src/security/cap.c	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ 	(revision )
@@ -1,229 +1,0 @@
-/*
- * Copyright (c) 2006 Jakub Jermar
- * 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 cap.c
- * @brief Capabilities control.
- *
- * @see cap.h
- */
-
-#include <security/cap.h>
-#include <proc/task.h>
-#include <synch/spinlock.h>
-#include <syscall/copy.h>
-#include <arch.h>
-#include <errno.h>
-
-/** Set capabilities.
- *
- * @param task Task whose capabilities are to be changed.
- * @param caps New set of capabilities.
- *
- */
-void cap_set(task_t *task, cap_t caps)
-{
-	irq_spinlock_lock(&task->lock, true);
-	task->capabilities = caps;
-	irq_spinlock_unlock(&task->lock, true);
-}
-
-/** Get capabilities.
- *
- * @param task Task whose capabilities are to be returned.
- *
- * @return Task's capabilities.
- *
- */
-cap_t cap_get(task_t *task)
-{
-	irq_spinlock_lock(&task->lock, true);
-	cap_t caps = task->capabilities;
-	irq_spinlock_unlock(&task->lock, true);
-	
-	return caps;
-}
-
-/** Grant capabilities to a task.
- *
- * The calling task must have the CAP_CAP capability.
- *
- * @param taskid Destination task ID.
- * @param caps   Capabilities to grant.
- *
- * @return Zero on success or an error code from @ref errno.h.
- *
- */
-static sysarg_t cap_grant(task_id_t taskid, cap_t caps)
-{
-	if (!(cap_get(TASK) & CAP_CAP))
-		return (sysarg_t) EPERM;
-	
-	irq_spinlock_lock(&tasks_lock, true);
-	task_t *task = task_find_by_id(taskid);
-	
-	if ((!task) || (!container_check(CONTAINER, task->container))) {
-		irq_spinlock_unlock(&tasks_lock, true);
-		return (sysarg_t) ENOENT;
-	}
-	
-	irq_spinlock_lock(&task->lock, false);
-	task->capabilities |= caps;
-	irq_spinlock_unlock(&task->lock, false);
-	
-	irq_spinlock_unlock(&tasks_lock, true);
-	return 0;
-}
-
-/** Revoke capabilities from a task.
- *
- * The calling task must have the CAP_CAP capability or the caller must
- * attempt to revoke capabilities from itself.
- *
- * @param taskid Destination task ID.
- * @param caps   Capabilities to revoke.
- *
- * @return Zero on success or an error code from @ref errno.h.
- *
- */
-static sysarg_t cap_revoke(task_id_t taskid, cap_t caps)
-{
-	irq_spinlock_lock(&tasks_lock, true);
-	
-	task_t *task = task_find_by_id(taskid);
-	if ((!task) || (!container_check(CONTAINER, task->container))) {
-		irq_spinlock_unlock(&tasks_lock, true);
-		return (sysarg_t) ENOENT;
-	}
-	
-	/*
-	 * Revoking capabilities is different from granting them in that
-	 * a task can revoke capabilities from itself even if it
-	 * doesn't have CAP_CAP.
-	 */
-	irq_spinlock_unlock(&TASK->lock, false);
-	
-	if ((!(TASK->capabilities & CAP_CAP)) || (task != TASK)) {
-		irq_spinlock_unlock(&TASK->lock, false);
-		irq_spinlock_unlock(&tasks_lock, true);
-		return (sysarg_t) EPERM;
-	}
-	
-	task->capabilities &= ~caps;
-	irq_spinlock_unlock(&TASK->lock, false);
-	
-	irq_spinlock_unlock(&tasks_lock, true);
-	return 0;
-}
-
-#ifdef __32_BITS__
-
-/** Grant capabilities to a task (32 bits)
- *
- * The calling task must have the CAP_CAP capability.
- *
- * @param uspace_taskid User-space pointer to destination task ID.
- * @param caps          Capabilities to grant.
- *
- * @return Zero on success or an error code from @ref errno.h.
- *
- */
-sysarg_t sys_cap_grant(sysarg64_t *uspace_taskid, cap_t caps)
-{
-	sysarg64_t taskid;
-	int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
-	if (rc != 0)
-		return (sysarg_t) rc;
-	
-	return cap_grant((task_id_t) taskid, caps);
-}
-
-/** Revoke capabilities from a task (32 bits)
- *
- * The calling task must have the CAP_CAP capability or the caller must
- * attempt to revoke capabilities from itself.
- *
- * @param uspace_taskid User-space pointer to destination task ID.
- * @param caps          Capabilities to revoke.
- *
- * @return Zero on success or an error code from @ref errno.h.
- *
- */
-sysarg_t sys_cap_revoke(sysarg64_t *uspace_taskid, cap_t caps)
-{
-	sysarg64_t taskid;
-	int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
-	if (rc != 0)
-		return (sysarg_t) rc;
-	
-	return cap_revoke((task_id_t) taskid, caps);
-}
-
-#endif  /* __32_BITS__ */
-
-#ifdef __64_BITS__
-
-/** Grant capabilities to a task (64 bits)
- *
- * The calling task must have the CAP_CAP capability.
- *
- * @param taskid Destination task ID.
- * @param caps   Capabilities to grant.
- *
- * @return Zero on success or an error code from @ref errno.h.
- *
- */
-sysarg_t sys_cap_grant(sysarg_t taskid, cap_t caps)
-{
-	return cap_grant((task_id_t) taskid, caps);
-}
-
-/** Revoke capabilities from a task (64 bits)
- *
- * The calling task must have the CAP_CAP capability or the caller must
- * attempt to revoke capabilities from itself.
- *
- * @param taskid Destination task ID.
- * @param caps   Capabilities to revoke.
- *
- * @return Zero on success or an error code from @ref errno.h.
- *
- */
-sysarg_t sys_cap_revoke(sysarg_t taskid, cap_t caps)
-{
-	return cap_revoke((task_id_t) taskid, caps);
-}
-
-#endif  /* __64_BITS__ */
-
-/** @}
- */
Index: kernel/generic/src/security/perm.c
===================================================================
--- kernel/generic/src/security/perm.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
+++ kernel/generic/src/security/perm.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -0,0 +1,229 @@
+/*
+ * Copyright (c) 2006 Jakub Jermar
+ * 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 perm.c
+ * @brief Task permissions control.
+ *
+ * @see perm.h
+ */
+
+#include <security/perm.h>
+#include <proc/task.h>
+#include <synch/spinlock.h>
+#include <syscall/copy.h>
+#include <arch.h>
+#include <errno.h>
+
+/** Set permissions.
+ *
+ * @param task  Task whose permissions are to be changed.
+ * @param perms New set of permissions.
+ *
+ */
+void perm_set(task_t *task, perm_t perms)
+{
+	irq_spinlock_lock(&task->lock, true);
+	task->perms = perms;
+	irq_spinlock_unlock(&task->lock, true);
+}
+
+/** Get permissions.
+ *
+ * @param task Task whose permissions are to be returned.
+ *
+ * @return Task's permissions.
+ *
+ */
+perm_t perm_get(task_t *task)
+{
+	irq_spinlock_lock(&task->lock, true);
+	perm_t perms = task->perms;
+	irq_spinlock_unlock(&task->lock, true);
+	
+	return perms;
+}
+
+/** Grant permissions to a task.
+ *
+ * The calling task must have the PERM_PERM permission.
+ *
+ * @param taskid Destination task ID.
+ * @param perms   Permissions to grant.
+ *
+ * @return Zero on success or an error code from @ref errno.h.
+ *
+ */
+static sysarg_t perm_grant(task_id_t taskid, perm_t perms)
+{
+	if (!(perm_get(TASK) & PERM_PERM))
+		return (sysarg_t) EPERM;
+	
+	irq_spinlock_lock(&tasks_lock, true);
+	task_t *task = task_find_by_id(taskid);
+	
+	if ((!task) || (!container_check(CONTAINER, task->container))) {
+		irq_spinlock_unlock(&tasks_lock, true);
+		return (sysarg_t) ENOENT;
+	}
+	
+	irq_spinlock_lock(&task->lock, false);
+	task->perms |= perms;
+	irq_spinlock_unlock(&task->lock, false);
+	
+	irq_spinlock_unlock(&tasks_lock, true);
+	return 0;
+}
+
+/** Revoke permissions from a task.
+ *
+ * The calling task must have the PERM_PERM permission or the caller must
+ * attempt to revoke permissions from itself.
+ *
+ * @param taskid Destination task ID.
+ * @param perms   Permissions to revoke.
+ *
+ * @return Zero on success or an error code from @ref errno.h.
+ *
+ */
+static sysarg_t perm_revoke(task_id_t taskid, perm_t perms)
+{
+	irq_spinlock_lock(&tasks_lock, true);
+	
+	task_t *task = task_find_by_id(taskid);
+	if ((!task) || (!container_check(CONTAINER, task->container))) {
+		irq_spinlock_unlock(&tasks_lock, true);
+		return (sysarg_t) ENOENT;
+	}
+	
+	/*
+	 * Revoking permissions is different from granting them in that
+	 * a task can revoke permissions from itself even if it
+	 * doesn't have PERM_PERM.
+	 */
+	irq_spinlock_unlock(&TASK->lock, false);
+	
+	if ((!(TASK->perms & PERM_PERM)) || (task != TASK)) {
+		irq_spinlock_unlock(&TASK->lock, false);
+		irq_spinlock_unlock(&tasks_lock, true);
+		return (sysarg_t) EPERM;
+	}
+	
+	task->perms &= ~perms;
+	irq_spinlock_unlock(&TASK->lock, false);
+	
+	irq_spinlock_unlock(&tasks_lock, true);
+	return 0;
+}
+
+#ifdef __32_BITS__
+
+/** Grant permissions to a task (32 bits)
+ *
+ * The calling task must have the PERM_PERM permission.
+ *
+ * @param uspace_taskid User-space pointer to destination task ID.
+ * @param perms         Permissions to grant.
+ *
+ * @return Zero on success or an error code from @ref errno.h.
+ *
+ */
+sysarg_t sys_perm_grant(sysarg64_t *uspace_taskid, perm_t perms)
+{
+	sysarg64_t taskid;
+	int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
+	if (rc != 0)
+		return (sysarg_t) rc;
+	
+	return perm_grant((task_id_t) taskid, perms);
+}
+
+/** Revoke permissions from a task (32 bits)
+ *
+ * The calling task must have the PERM_PERM permission or the caller must
+ * attempt to revoke permissions from itself.
+ *
+ * @param uspace_taskid User-space pointer to destination task ID.
+ * @param perms         Perms to revoke.
+ *
+ * @return Zero on success or an error code from @ref errno.h.
+ *
+ */
+sysarg_t sys_perm_revoke(sysarg64_t *uspace_taskid, perm_t perms)
+{
+	sysarg64_t taskid;
+	int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
+	if (rc != 0)
+		return (sysarg_t) rc;
+	
+	return perm_revoke((task_id_t) taskid, perms);
+}
+
+#endif  /* __32_BITS__ */
+
+#ifdef __64_BITS__
+
+/** Grant permissions to a task (64 bits)
+ *
+ * The calling task must have the PERM_PERM permission.
+ *
+ * @param taskid Destination task ID.
+ * @param perms  Permissions to grant.
+ *
+ * @return Zero on success or an error code from @ref errno.h.
+ *
+ */
+sysarg_t sys_perm_grant(sysarg_t taskid, perm_t perms)
+{
+	return perm_grant((task_id_t) taskid, perms);
+}
+
+/** Revoke permissions from a task (64 bits)
+ *
+ * The calling task must have the PERM_PERM permission or the caller must
+ * attempt to revoke permissions from itself.
+ *
+ * @param taskid Destination task ID.
+ * @param perms  Permissions to revoke.
+ *
+ * @return Zero on success or an error code from @ref errno.h.
+ *
+ */
+sysarg_t sys_perm_revoke(sysarg_t taskid, perm_t perms)
+{
+	return perm_revoke((task_id_t) taskid, perms);
+}
+
+#endif  /* __64_BITS__ */
+
+/** @}
+ */
Index: kernel/generic/src/syscall/syscall.c
===================================================================
--- kernel/generic/src/syscall/syscall.c	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ kernel/generic/src/syscall/syscall.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -53,5 +53,5 @@
 #include <ddi/ddi.h>
 #include <ipc/event.h>
-#include <security/cap.h>
+#include <security/perm.h>
 #include <sysinfo/sysinfo.h>
 #include <console/console.h>
@@ -171,7 +171,7 @@
 	(syshandler_t) sys_ipc_event_unmask,
 	
-	/* Capabilities related syscalls. */
-	(syshandler_t) sys_cap_grant,
-	(syshandler_t) sys_cap_revoke,
+	/* Permission related syscalls. */
+	(syshandler_t) sys_perm_grant,
+	(syshandler_t) sys_perm_revoke,
 	
 	/* DDI related syscalls. */
Index: uspace/app/trace/syscalls.c
===================================================================
--- uspace/app/trace/syscalls.c	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ uspace/app/trace/syscalls.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -68,6 +68,6 @@
     [SYS_IPC_EVENT_UNMASK] = { "ipc_event_unmask",	1,	V_ERRNO },
 
-    [SYS_CAP_GRANT] = { "cap_grant",			2,	V_ERRNO },
-    [SYS_CAP_REVOKE] = { "cap_revoke",			2,	V_ERRNO },
+    [SYS_PERM_GRANT] = { "perm_grant",			2,	V_ERRNO },
+    [SYS_PERM_REVOKE] = { "perm_revoke",		2,	V_ERRNO },
     [SYS_PHYSMEM_MAP] = { "physmem_map",		4,	V_ERRNO },
     [SYS_IOSPACE_ENABLE] = { "iospace_enable",		1,	V_ERRNO },
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ uspace/lib/c/Makefile	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -63,5 +63,5 @@
 	generic/bd.c \
 	generic/bd_srv.c \
-	generic/cap.c \
+	generic/perm.c \
 	generic/clipboard.c \
 	generic/config.c \
Index: pace/lib/c/generic/cap.c
===================================================================
--- uspace/lib/c/generic/cap.c	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ 	(revision )
@@ -1,83 +1,0 @@
-/*
- * Copyright (c) 2006 Jakub Jermar
- * 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  cap.c
- * @brief Functions to grant/revoke capabilities to/from a task.
- */
-
-#include <cap.h>
-#include <task.h>
-#include <libc.h>
-#include <libarch/types.h>
-
-/** Grant capabilities to a task.
- *
- * @param id   Destination task ID.
- * @param caps Capabilities to grant.
- *
- * @return Zero on success or a value from @ref errno.h on failure.
- *
- */
-int cap_grant(task_id_t id, unsigned int caps)
-{
-#ifdef __32_BITS__
-	sysarg64_t arg = (sysarg64_t) id;
-	return __SYSCALL2(SYS_CAP_GRANT, (sysarg_t) &arg, (sysarg_t) caps);
-#endif
-	
-#ifdef __64_BITS__
-	return __SYSCALL2(SYS_CAP_GRANT, (sysarg_t) id, (sysarg_t) caps);
-#endif
-}
-
-/** Revoke capabilities from a task.
- *
- * @param id   Destination task ID.
- * @param caps Capabilities to revoke.
- *
- * @return Zero on success or a value from @ref errno.h on failure.
- *
- */
-int cap_revoke(task_id_t id, unsigned int caps)
-{
-#ifdef __32_BITS__
-	sysarg64_t arg = (sysarg64_t) id;
-	return __SYSCALL2(SYS_CAP_REVOKE, (sysarg_t) &arg, (sysarg_t) caps);
-#endif
-	
-#ifdef __64_BITS__
-	return __SYSCALL2(SYS_CAP_REVOKE, (sysarg_t) id, (sysarg_t) caps);
-#endif
-}
-
-/** @}
- */
Index: uspace/lib/c/generic/perm.c
===================================================================
--- uspace/lib/c/generic/perm.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
+++ uspace/lib/c/generic/perm.c	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2006 Jakub Jermar
+ * 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  perm.c
+ * @brief Functions to grant/revoke permissions to/from a task.
+ */
+
+#include <perm.h>
+#include <task.h>
+#include <libc.h>
+#include <libarch/types.h>
+
+/** Grant permissions to a task.
+ *
+ * @param id    Destination task ID.
+ * @param perms Permissions to grant.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure.
+ *
+ */
+int perm_grant(task_id_t id, unsigned int perms)
+{
+#ifdef __32_BITS__
+	sysarg64_t arg = (sysarg64_t) id;
+	return __SYSCALL2(SYS_PERM_GRANT, (sysarg_t) &arg, (sysarg_t) perms);
+#endif
+	
+#ifdef __64_BITS__
+	return __SYSCALL2(SYS_PERM_GRANT, (sysarg_t) id, (sysarg_t) perms);
+#endif
+}
+
+/** Revoke permissions from a task.
+ *
+ * @param id    Destination task ID.
+ * @param perms Permissions to revoke.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure.
+ *
+ */
+int perm_revoke(task_id_t id, unsigned int perms)
+{
+#ifdef __32_BITS__
+	sysarg64_t arg = (sysarg64_t) id;
+	return __SYSCALL2(SYS_PERM_REVOKE, (sysarg_t) &arg, (sysarg_t) perms);
+#endif
+	
+#ifdef __64_BITS__
+	return __SYSCALL2(SYS_PERM_REVOKE, (sysarg_t) id, (sysarg_t) perms);
+#endif
+}
+
+/** @}
+ */
Index: pace/lib/c/include/cap.h
===================================================================
--- uspace/lib/c/include/cap.h	(revision 456c086ff4eec09f0e755f56cd28921657993534)
+++ 	(revision )
@@ -1,46 +1,0 @@
-/*
- * Copyright (c) 2006 Jakub Jermar
- * 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 LIB_CAP_H_
-#define LIB_CAP_H_
-
-#include <task.h>
-
-extern int cap_grant(task_id_t id, unsigned int caps);
-extern int cap_revoke(task_id_t id, unsigned int caps);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/c/include/perm.h
===================================================================
--- uspace/lib/c/include/perm.h	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
+++ uspace/lib/c/include/perm.h	(revision 719a208dbe29f92f5690472a3500c890db8f3f1f)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2006 Jakub Jermar
+ * 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 LIB_PERM_H_
+#define LIB_PERM_H_
+
+#include <task.h>
+
+extern int perm_grant(task_id_t, unsigned int);
+extern int perm_revoke(task_id_t, unsigned int);
+
+#endif
+
+/** @}
+ */
