Changeset 2bb8648 in mainline


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.

Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • doc/mm

    recf3722 r2bb8648  
    5858tables.
    5959
    60 
    61 
    62601.2 Single global page hash table
    6361
     
    6664There is only one global page hash table in the system shared by all address
    6765spaces.
     66
     67
     682. Memory allocators
    6869
    69702.1 General allocator
  • generic/include/ddi/ddi.h

    recf3722 r2bb8648  
    3636extern __native sys_physmem_map(ddi_memarg_t *uspace_mem_arg);
    3737extern __native sys_iospace_enable(ddi_ioarg_t *uspace_io_arg);
     38extern __native sys_preempt_control(int enable);
    3839
    3940/*
  • generic/include/security/cap.h

    recf3722 r2bb8648  
    4242#define __CAP_H__
    4343
     44#include <syscall/sysarg64.h>
    4445#include <arch/types.h>
    4546#include <typedefs.h>
     
    6465
    6566/**
    66  * CAP_PREEMPT_CONTROL allows its holder to disable interrupts
     67 * CAP_PREEMPT_CONTROL allows its holder to disable/enable preemption.
    6768 */
    68 #define CAP_PREEMPT_CONTROL         (1<<3)
     69#define CAP_PREEMPT_CONTROL     (1<<3)
     70
     71/**
     72 * CAP_IRQ_REG entitles its holder to register IRQ handlers.
     73 */
     74#define CAP_IRQ_REG             (1<<4)
    6975
    7076typedef __u32 cap_t;
     
    7379extern cap_t cap_get(task_t *t);
    7480
     81extern __native sys_cap_grant(sysarg64_t *uspace_taskid_arg, cap_t caps);
     82extern __native sys_cap_revoke(sysarg64_t *uspace_taskid_arg, cap_t caps);
     83
    7584#endif
  • generic/include/syscall/syscall.h

    recf3722 r2bb8648  
    3333        SYS_IO = 0,
    3434        SYS_TLS_SET = 1, /* Hardcoded in AMD64,IA32 uspace - psthread.S */
    35         SYS_PREEMPT_CONTROL,
    3635        SYS_THREAD_CREATE,
    3736        SYS_THREAD_EXIT,
     
    5453        SYS_IPC_REGISTER_IRQ,
    5554        SYS_IPC_UNREGISTER_IRQ,
     55        SYS_CAP_GRANT,
     56        SYS_CAP_REVOKE,
    5657        SYS_MAP_PHYSMEM,
    5758        SYS_IOSPACE_ENABLE,
     59        SYS_PREEMPT_CONTROL,
    5860        SYSCALL_END
    5961} syscall_t;
  • 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.