Changeset 2bb8648 in mainline for generic/src


Ignore:
Timestamp:
2006-05-07T15:21:11Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
31282f9
Parents:
ecf3722
Message:

Add SYS_CAP_GRANT and SYS_CAP_REVOKE syscalls.
Move SYS_PREEMPT_CONTROL to ddi.c.
Add some comments and fix some small issues.

Location:
generic/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • generic/src/ddi/ddi.c

    recf3722 r2bb8648  
    212212        return (__native) ddi_iospace_enable((task_id_t) arg.task_id, (__address) arg.ioaddr, (size_t) arg.size);
    213213}
     214
     215/** Disable or enable preemption.
     216 *
     217 * @param enable If non-zero, the preemption counter will be decremented, leading to potential
     218 *               enabling of preemption. Otherwise the preemption counter will be incremented,
     219 *               preventing preemption from occurring.
     220 *
     221 * @return Zero on success or EPERM if callers capabilities are not sufficient.
     222 */
     223__native sys_preempt_control(int enable)
     224{
     225        if (! cap_get(TASK) & CAP_PREEMPT_CONTROL)
     226                return EPERM;
     227        if (enable)
     228                preemption_enable();
     229        else
     230                preemption_disable();
     231        return 0;
     232}
  • generic/src/ipc/sysipc.c

    recf3722 r2bb8648  
    4040#include <print.h>
    4141#include <syscall/copy.h>
     42#include <security/cap.h>
    4243
    4344#define GET_CHECK_PHONE(phone,phoneid,err) { \
     
    491492__native sys_ipc_register_irq(__native irq, irq_code_t *ucode)
    492493{
     494        if (!(cap_get(TASK) & CAP_IRQ_REG))
     495                return EPERM;
     496
    493497        if (irq >= IRQ_COUNT)
    494                 return -ELIMIT;
     498                return (__native) ELIMIT;
    495499
    496500        irq_ipc_bind_arch(irq);
     
    502506__native sys_ipc_unregister_irq(__native irq)
    503507{
     508        if (!(cap_get(TASK) & CAP_IRQ_REG))
     509                return EPERM;
     510
    504511        if (irq >= IRQ_COUNT)
    505                 return -ELIMIT;
     512                return (__native) ELIMIT;
    506513
    507514        ipc_irq_unregister(&TASK->answerbox, irq);
  • generic/src/main/kinit.c

    recf3722 r2bb8648  
    160160                         * Set capabilities to init userspace tasks.
    161161                         */
    162                         cap_set(utask, CAP_CAP | CAP_MEM_MANAGER | CAP_IO_MANAGER);
     162                        cap_set(utask, CAP_CAP | CAP_MEM_MANAGER | CAP_IO_MANAGER | CAP_PREEMPT_CONTROL);
    163163                       
    164164                        if (!ipc_phone_0)
  • generic/src/mm/tlb.c

    recf3722 r2bb8648  
    3030 * @file        tlb.c
    3131 * @brief       Generic TLB shootdown algorithm.
     32 *
     33 * The algorithm implemented here is based on the CMU TLB shootdown
     34 * algorithm and is further simplified (e.g. all CPUs receive all TLB
     35 * shootdown messages).
    3236 */
    3337
  • generic/src/security/cap.c

    recf3722 r2bb8648  
    3737#include <proc/task.h>
    3838#include <synch/spinlock.h>
     39#include <syscall/sysarg64.h>
     40#include <syscall/copy.h>
    3941#include <arch.h>
    4042#include <typedefs.h>
     43#include <errno.h>
    4144
    4245/** Set capabilities.
     
    7881        return caps;
    7982}
     83
     84/** Grant capabilities to a task.
     85 *
     86 * The calling task must have the CAP_CAP capability.
     87 *
     88 * @param uspace_taskid_arg Userspace structure holding destination task ID.
     89 * @param caps Capabilities to grant.
     90 *
     91 * @return Zero on success or an error code from @ref errno.h.
     92 */
     93__native sys_cap_grant(sysarg64_t *uspace_taskid_arg, cap_t caps)
     94{
     95        sysarg64_t taskid_arg;
     96        task_t *t;
     97        ipl_t ipl;
     98        int rc;
     99       
     100        if (!(cap_get(TASK) & CAP_CAP))
     101                return (__native) EPERM;
     102       
     103        rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
     104        if (rc != 0)
     105                return (__native) rc;
     106               
     107        ipl = interrupts_disable();
     108        spinlock_lock(&tasks_lock);
     109        t = task_find_by_id((task_id_t) taskid_arg.value);
     110        if (!t) {
     111                spinlock_unlock(&tasks_lock);
     112                interrupts_restore(ipl);
     113                return (__native) ENOENT;
     114        }
     115        spinlock_unlock(&tasks_lock);
     116       
     117        cap_set(t, cap_get(t) | caps);
     118       
     119        interrupts_restore(ipl);       
     120        return 0;
     121}
     122
     123/** Revoke capabilities from a task.
     124 *
     125 * The calling task must have the CAP_CAP capability or the caller must
     126 * attempt to revoke capabilities from itself.
     127 *
     128 * @param uspace_taskid_arg Userspace structure holding destination task ID.
     129 * @param caps Capabilities to revoke.
     130 *
     131 * @return Zero on success or an error code from @ref errno.h.
     132 */
     133__native sys_cap_revoke(sysarg64_t *uspace_taskid_arg, cap_t caps)
     134{
     135        sysarg64_t taskid_arg;
     136        task_t *t;
     137        ipl_t ipl;
     138        int rc;
     139       
     140        rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
     141        if (rc != 0)
     142                return (__native) rc;
     143
     144        ipl = interrupts_disable();
     145        spinlock_lock(&tasks_lock);     
     146        t = task_find_by_id((task_id_t) taskid_arg.value);
     147        if (!t) {
     148                spinlock_unlock(&tasks_lock);
     149                interrupts_restore(ipl);
     150                return (__native) ENOENT;
     151        }
     152        spinlock_unlock(&tasks_lock);
     153
     154        /*
     155         * Revoking capabilities is different from granting them in that
     156         * a task can revoke capabilities from itself even if it
     157         * doesn't have CAP_CAP.
     158         */
     159        if (!(cap_get(TASK) & CAP_CAP) || !(t == TASK)) {
     160                interrupts_restore(ipl);
     161                return (__native) EPERM;
     162        }
     163
     164        cap_set(t, cap_get(t) & ~caps);
     165       
     166        interrupts_restore(ipl);
     167        return 0;
     168}
  • generic/src/syscall/syscall.c

    recf3722 r2bb8648  
    4444#include <synch/futex.h>
    4545#include <ddi/ddi.h>
     46#include <security/cap.h>
    4647#include <syscall/copy.h>
    4748
     
    5657       
    5758        return count;
    58 }
    59 
    60 static __native sys_preempt_control(int enable)
    61 {
    62         if (! cap_get(TASK) & CAP_PREEMPT_CONTROL)
    63                 return EPERM;
    64         if (enable)
    65                 preemption_enable();
    66         else
    67                 preemption_disable();
    68         return 0;
    6959}
    7060
     
    8272        sys_io,
    8373        sys_tls_set,
    84         sys_preempt_control,
    85 
     74       
    8675        /* Thread and task related syscalls. */
    8776        sys_thread_create,
     
    112101        sys_ipc_unregister_irq,
    113102
     103        /* Capabilities related syscalls. */
     104        sys_cap_grant,
     105        sys_cap_revoke,
     106
    114107        /* DDI related syscalls. */
    115108        sys_physmem_map,
    116         sys_iospace_enable
     109        sys_iospace_enable,
     110        sys_preempt_control
    117111};
Note: See TracChangeset for help on using the changeset viewer.