Changeset 95c675b in mainline for uspace/lib/c/generic/perm.c
- Timestamp:
- 2017-10-17T13:11:35Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 60af4cdb
- Parents:
- dbf32b1 (diff), a416d070 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/perm.c
rdbf32b1 r95c675b 1 1 /* 2 * Copyright (c) 200 8Jakub Jermar2 * Copyright (c) 2006 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 31 31 */ 32 32 /** 33 * @file 34 * @brief This file contains rwlock API and provides its fake 35 * implementation based on futexes. 33 * @file perm.c 34 * @brief Functions to grant/revoke permissions to/from a task. 36 35 */ 37 36 38 #ifndef LIBC_RWLOCK_H_ 39 #define LIBC_RWLOCK_H_ 37 #include <perm.h> 38 #include <task.h> 39 #include <libc.h> 40 #include <types/common.h> 40 41 41 #include <atomic.h> 42 #include <futex.h> 42 /** Grant permissions to a task. 43 * 44 * @param id Destination task ID. 45 * @param perms Permissions to grant. 46 * 47 * @return Zero on success or a value from @ref errno.h on failure. 48 * 49 */ 50 int perm_grant(task_id_t id, unsigned int perms) 51 { 52 #ifdef __32_BITS__ 53 sysarg64_t arg = (sysarg64_t) id; 54 return __SYSCALL2(SYS_PERM_GRANT, (sysarg_t) &arg, (sysarg_t) perms); 55 #endif 56 57 #ifdef __64_BITS__ 58 return __SYSCALL2(SYS_PERM_GRANT, (sysarg_t) id, (sysarg_t) perms); 59 #endif 60 } 43 61 44 typedef atomic_t rwlock_t; 45 46 #define RWLOCK_INITIALIZE(rwlock) \ 47 rwlock_t rwlock = FUTEX_INITIALIZER 48 49 #define rwlock_initialize(rwlock) futex_initialize((rwlock), 1) 50 #define rwlock_read_lock(rwlock) futex_lock((rwlock)) 51 #define rwlock_write_lock(rwlock) futex_lock((rwlock)) 52 #define rwlock_read_unlock(rwlock) futex_unlock((rwlock)) 53 #define rwlock_write_unlock(rwlock) futex_unlock((rwlock)) 54 62 /** Revoke permissions from a task. 63 * 64 * @param id Destination task ID. 65 * @param perms Permissions to revoke. 66 * 67 * @return Zero on success or a value from @ref errno.h on failure. 68 * 69 */ 70 int perm_revoke(task_id_t id, unsigned int perms) 71 { 72 #ifdef __32_BITS__ 73 sysarg64_t arg = (sysarg64_t) id; 74 return __SYSCALL2(SYS_PERM_REVOKE, (sysarg_t) &arg, (sysarg_t) perms); 55 75 #endif 76 77 #ifdef __64_BITS__ 78 return __SYSCALL2(SYS_PERM_REVOKE, (sysarg_t) id, (sysarg_t) perms); 79 #endif 80 } 56 81 57 82 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.