Changeset 95c675b in mainline for uspace/lib/c/generic/perm.c


Ignore:
Timestamp:
2017-10-17T13:11:35Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
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.
Message:

Merge mainline

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/perm.c

    rdbf32b1 r95c675b  
    11/*
    2  * Copyright (c) 2008 Jakub Jermar
     2 * Copyright (c) 2006 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/**
    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.
    3635 */
    3736
    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>
    4041
    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 */
     50int 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}
    4361
    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 */
     70int 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);
    5575#endif
     76       
     77#ifdef __64_BITS__
     78        return __SYSCALL2(SYS_PERM_REVOKE, (sysarg_t) id, (sysarg_t) perms);
     79#endif
     80}
    5681
    5782/** @}
Note: See TracChangeset for help on using the changeset viewer.