Subversion Repositories HelenOS-historic

Rev

Rev 1702 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1702 Rev 1780
Line 92... Line 92...
92
 * @param uspace_taskid_arg Userspace structure holding destination task ID.
92
 * @param uspace_taskid_arg Userspace structure holding destination task ID.
93
 * @param caps Capabilities to grant.
93
 * @param caps Capabilities to grant.
94
 *
94
 *
95
 * @return Zero on success or an error code from @ref errno.h.
95
 * @return Zero on success or an error code from @ref errno.h.
96
 */
96
 */
97
__native sys_cap_grant(sysarg64_t *uspace_taskid_arg, cap_t caps)
97
unative_t sys_cap_grant(sysarg64_t *uspace_taskid_arg, cap_t caps)
98
{
98
{
99
    sysarg64_t taskid_arg;
99
    sysarg64_t taskid_arg;
100
    task_t *t;
100
    task_t *t;
101
    ipl_t ipl;
101
    ipl_t ipl;
102
    int rc;
102
    int rc;
103
   
103
   
104
    if (!(cap_get(TASK) & CAP_CAP))
104
    if (!(cap_get(TASK) & CAP_CAP))
105
        return (__native) EPERM;
105
        return (unative_t) EPERM;
106
   
106
   
107
    rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
107
    rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
108
    if (rc != 0)
108
    if (rc != 0)
109
        return (__native) rc;
109
        return (unative_t) rc;
110
       
110
       
111
    ipl = interrupts_disable();
111
    ipl = interrupts_disable();
112
    spinlock_lock(&tasks_lock);
112
    spinlock_lock(&tasks_lock);
113
    t = task_find_by_id((task_id_t) taskid_arg.value);
113
    t = task_find_by_id((task_id_t) taskid_arg.value);
114
    if (!t) {
114
    if (!t) {
115
        spinlock_unlock(&tasks_lock);
115
        spinlock_unlock(&tasks_lock);
116
        interrupts_restore(ipl);
116
        interrupts_restore(ipl);
117
        return (__native) ENOENT;
117
        return (unative_t) ENOENT;
118
    }
118
    }
119
   
119
   
120
    spinlock_lock(&t->lock);
120
    spinlock_lock(&t->lock);
121
    cap_set(t, cap_get(t) | caps);
121
    cap_set(t, cap_get(t) | caps);
122
    spinlock_unlock(&t->lock);
122
    spinlock_unlock(&t->lock);
Line 137... Line 137...
137
 * @param uspace_taskid_arg Userspace structure holding destination task ID.
137
 * @param uspace_taskid_arg Userspace structure holding destination task ID.
138
 * @param caps Capabilities to revoke.
138
 * @param caps Capabilities to revoke.
139
 *
139
 *
140
 * @return Zero on success or an error code from @ref errno.h.
140
 * @return Zero on success or an error code from @ref errno.h.
141
 */
141
 */
142
__native sys_cap_revoke(sysarg64_t *uspace_taskid_arg, cap_t caps)
142
unative_t sys_cap_revoke(sysarg64_t *uspace_taskid_arg, cap_t caps)
143
{
143
{
144
    sysarg64_t taskid_arg;
144
    sysarg64_t taskid_arg;
145
    task_t *t;
145
    task_t *t;
146
    ipl_t ipl;
146
    ipl_t ipl;
147
    int rc;
147
    int rc;
148
   
148
   
149
    rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
149
    rc = copy_from_uspace(&taskid_arg, uspace_taskid_arg, sizeof(sysarg64_t));
150
    if (rc != 0)
150
    if (rc != 0)
151
        return (__native) rc;
151
        return (unative_t) rc;
152
 
152
 
153
    ipl = interrupts_disable();
153
    ipl = interrupts_disable();
154
    spinlock_lock(&tasks_lock);
154
    spinlock_lock(&tasks_lock);
155
    t = task_find_by_id((task_id_t) taskid_arg.value);
155
    t = task_find_by_id((task_id_t) taskid_arg.value);
156
    if (!t) {
156
    if (!t) {
157
        spinlock_unlock(&tasks_lock);
157
        spinlock_unlock(&tasks_lock);
158
        interrupts_restore(ipl);
158
        interrupts_restore(ipl);
159
        return (__native) ENOENT;
159
        return (unative_t) ENOENT;
160
    }
160
    }
161
 
161
 
162
    /*
162
    /*
163
     * Revoking capabilities is different from granting them in that
163
     * Revoking capabilities is different from granting them in that
164
     * a task can revoke capabilities from itself even if it
164
     * a task can revoke capabilities from itself even if it
165
     * doesn't have CAP_CAP.
165
     * doesn't have CAP_CAP.
166
     */
166
     */
167
    if (!(cap_get(TASK) & CAP_CAP) || !(t == TASK)) {
167
    if (!(cap_get(TASK) & CAP_CAP) || !(t == TASK)) {
168
        spinlock_unlock(&tasks_lock);
168
        spinlock_unlock(&tasks_lock);
169
        interrupts_restore(ipl);
169
        interrupts_restore(ipl);
170
        return (__native) EPERM;
170
        return (unative_t) EPERM;
171
    }
171
    }
172
   
172
   
173
    spinlock_lock(&t->lock);
173
    spinlock_lock(&t->lock);
174
    cap_set(t, cap_get(t) & ~caps);
174
    cap_set(t, cap_get(t) & ~caps);
175
    spinlock_unlock(&t->lock);
175
    spinlock_unlock(&t->lock);