Rev 2359 | Rev 2494 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2359 | Rev 2471 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup genericipc |
29 | /** @addtogroup genericipc |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch.h> |
35 | #include <arch.h> |
36 | #include <proc/task.h> |
36 | #include <proc/task.h> |
37 | #include <proc/thread.h> |
37 | #include <proc/thread.h> |
38 | #include <errno.h> |
38 | #include <errno.h> |
39 | #include <memstr.h> |
39 | #include <memstr.h> |
40 | #include <debug.h> |
40 | #include <debug.h> |
41 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
42 | #include <ipc/sysipc.h> |
42 | #include <ipc/sysipc.h> |
43 | #include <ipc/irq.h> |
43 | #include <ipc/irq.h> |
44 | #include <ipc/ipcrsc.h> |
44 | #include <ipc/ipcrsc.h> |
45 | #include <arch/interrupt.h> |
45 | #include <arch/interrupt.h> |
46 | #include <print.h> |
46 | #include <print.h> |
47 | #include <syscall/copy.h> |
47 | #include <syscall/copy.h> |
48 | #include <security/cap.h> |
48 | #include <security/cap.h> |
49 | #include <mm/as.h> |
49 | #include <mm/as.h> |
50 | #include <print.h> |
50 | #include <print.h> |
51 | 51 | ||
52 | #define GET_CHECK_PHONE(phone, phoneid, err) { \ |
52 | #define GET_CHECK_PHONE(phone, phoneid, err) \ |
- | 53 | { \ |
|
53 | if (phoneid > IPC_MAX_PHONES) { err; } \ |
54 | if (phoneid > IPC_MAX_PHONES) { \ |
- | 55 | err; \ |
|
- | 56 | } \ |
|
54 | phone = &TASK->phones[phoneid]; \ |
57 | phone = &TASK->phones[phoneid]; \ |
55 | } |
58 | } |
56 | 59 | ||
57 | #define STRUCT_TO_USPACE(dst, src) copy_to_uspace(dst, src, sizeof(*(src))) |
60 | #define STRUCT_TO_USPACE(dst, src) copy_to_uspace(dst, src, sizeof(*(src))) |
58 | 61 | ||
59 | /** Return true if the method is a system method */ |
62 | /** Decide if the method is a system method. |
- | 63 | * |
|
- | 64 | * @param method Method to be decided. |
|
- | 65 | * |
|
- | 66 | * @return Return 1 if the method is a system method. |
|
- | 67 | * Otherwise return 0. |
|
- | 68 | */ |
|
60 | static inline int is_system_method(unative_t method) |
69 | static inline int is_system_method(unative_t method) |
61 | { |
70 | { |
62 | if (method <= IPC_M_LAST_SYSTEM) |
71 | if (method <= IPC_M_LAST_SYSTEM) |
63 | return 1; |
72 | return 1; |
64 | return 0; |
73 | return 0; |
65 | } |
74 | } |
66 | 75 | ||
67 | /** Return true if the message with this method is forwardable |
76 | /** Decide if the message with this method is forwardable. |
68 | * |
77 | * |
69 | * - some system messages may be forwarded, for some of them |
78 | * - some system messages may be forwarded, for some of them |
70 | * it is useless |
79 | * it is useless |
- | 80 | * |
|
- | 81 | * @param method Method to be decided. |
|
- | 82 | * |
|
- | 83 | * @return Return 1 if the method is forwardable. |
|
- | 84 | * Otherwise return 0. |
|
71 | */ |
85 | */ |
72 | static inline int is_forwardable(unative_t method) |
86 | static inline int is_forwardable(unative_t method) |
73 | { |
87 | { |
74 | if (method == IPC_M_PHONE_HUNGUP || method == IPC_M_AS_AREA_SEND || |
88 | if (method == IPC_M_PHONE_HUNGUP || method == IPC_M_AS_AREA_SEND || |
75 | method == IPC_M_AS_AREA_RECV) |
89 | method == IPC_M_AS_AREA_RECV) |
76 | return 0; /* This message is meant only for the receiver */ |
90 | return 0; /* This message is meant only for the receiver */ |
77 | return 1; |
91 | return 1; |
78 | } |
92 | } |
79 | 93 | ||
80 | /****************************************************/ |
- | |
81 | /* Functions that preprocess answer before sending |
- | |
82 | * it to the recepient |
- | |
83 | */ |
- | |
84 | 94 | ||
- | 95 | /*********************************************************************** |
|
- | 96 | * Functions that preprocess answer before sending it to the recepient. |
|
- | 97 | ***********************************************************************/ |
|
- | 98 | ||
85 | /** Return true if the caller (ipc_answer) should save |
99 | /** Decide if the caller (e.g. ipc_answer()) should save the old call contents |
86 | * the old call contents for answer_preprocess |
100 | * for answer_preprocess(). |
- | 101 | * |
|
- | 102 | * @param call Call structure to be decided. |
|
- | 103 | * |
|
- | 104 | * @return Return 1 if the old call contents should be saved. |
|
- | 105 | * Return 0 otherwise. |
|
87 | */ |
106 | */ |
88 | static inline int answer_need_old(call_t *call) |
107 | static inline int answer_need_old(call_t *call) |
89 | { |
108 | { |
90 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) |
109 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) |
91 | return 1; |
110 | return 1; |
92 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_ME_TO) |
111 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_ME_TO) |
93 | return 1; |
112 | return 1; |
94 | if (IPC_GET_METHOD(call->data) == IPC_M_AS_AREA_SEND) |
113 | if (IPC_GET_METHOD(call->data) == IPC_M_AS_AREA_SEND) |
95 | return 1; |
114 | return 1; |
96 | if (IPC_GET_METHOD(call->data) == IPC_M_AS_AREA_RECV) |
115 | if (IPC_GET_METHOD(call->data) == IPC_M_AS_AREA_RECV) |
97 | return 1; |
116 | return 1; |
98 | return 0; |
117 | return 0; |
99 | } |
118 | } |
100 | 119 | ||
101 | /** Interpret process answer as control information |
120 | /** Interpret process answer as control information. |
102 | * |
121 | * |
103 | * This function is called directly after sys_ipc_answer |
122 | * This function is called directly after sys_ipc_answer(). |
- | 123 | * |
|
- | 124 | * @param answer Call structure with the answer. |
|
- | 125 | * @param olddata Saved data of the request. |
|
- | 126 | * |
|
- | 127 | * @return Return 0 on success or an error code. |
|
104 | */ |
128 | */ |
105 | static inline int answer_preprocess(call_t *answer, ipc_data_t *olddata) |
129 | static inline int answer_preprocess(call_t *answer, ipc_data_t *olddata) |
106 | { |
130 | { |
107 | int phoneid; |
131 | int phoneid; |
108 | 132 | ||
109 | if (IPC_GET_RETVAL(answer->data) == EHANGUP) { |
133 | if (IPC_GET_RETVAL(answer->data) == EHANGUP) { |
110 | /* In case of forward, hangup the forwared phone, |
134 | /* In case of forward, hangup the forwared phone, |
111 | * not the originator |
135 | * not the originator |
112 | */ |
136 | */ |
113 | spinlock_lock(&answer->data.phone->lock); |
137 | spinlock_lock(&answer->data.phone->lock); |
114 | spinlock_lock(&TASK->answerbox.lock); |
138 | spinlock_lock(&TASK->answerbox.lock); |
115 | if (answer->data.phone->state == IPC_PHONE_CONNECTED) { |
139 | if (answer->data.phone->state == IPC_PHONE_CONNECTED) { |
116 | list_remove(&answer->data.phone->link); |
140 | list_remove(&answer->data.phone->link); |
117 | answer->data.phone->state = IPC_PHONE_SLAMMED; |
141 | answer->data.phone->state = IPC_PHONE_SLAMMED; |
118 | } |
142 | } |
119 | spinlock_unlock(&TASK->answerbox.lock); |
143 | spinlock_unlock(&TASK->answerbox.lock); |
120 | spinlock_unlock(&answer->data.phone->lock); |
144 | spinlock_unlock(&answer->data.phone->lock); |
121 | } |
145 | } |
122 | 146 | ||
123 | if (!olddata) |
147 | if (!olddata) |
124 | return 0; |
148 | return 0; |
125 | 149 | ||
126 | if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_TO_ME) { |
150 | if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_TO_ME) { |
127 | phoneid = IPC_GET_ARG3(*olddata); |
151 | phoneid = IPC_GET_ARG3(*olddata); |
128 | if (IPC_GET_RETVAL(answer->data)) { |
152 | if (IPC_GET_RETVAL(answer->data)) { |
129 | /* The connection was not accepted */ |
153 | /* The connection was not accepted */ |
130 | phone_dealloc(phoneid); |
154 | phone_dealloc(phoneid); |
131 | } else { |
155 | } else { |
132 | /* The connection was accepted */ |
156 | /* The connection was accepted */ |
133 | phone_connect(phoneid, &answer->sender->answerbox); |
157 | phone_connect(phoneid, &answer->sender->answerbox); |
134 | /* Set 'phone identification' as arg3 of response */ |
158 | /* Set 'phone hash' as arg3 of response */ |
135 | IPC_SET_ARG3(answer->data, |
159 | IPC_SET_ARG3(answer->data, |
136 | (unative_t) &TASK->phones[phoneid]); |
160 | (unative_t) &TASK->phones[phoneid]); |
137 | } |
161 | } |
138 | } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME_TO) { |
162 | } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME_TO) { |
139 | /* If the users accepted call, connect */ |
163 | /* If the users accepted call, connect */ |
140 | if (!IPC_GET_RETVAL(answer->data)) { |
164 | if (!IPC_GET_RETVAL(answer->data)) { |
141 | ipc_phone_connect((phone_t *) IPC_GET_ARG3(*olddata), |
165 | ipc_phone_connect((phone_t *) IPC_GET_ARG3(*olddata), |
142 | &TASK->answerbox); |
166 | &TASK->answerbox); |
143 | } |
167 | } |
144 | } else if (IPC_GET_METHOD(*olddata) == IPC_M_AS_AREA_SEND) { |
168 | } else if (IPC_GET_METHOD(*olddata) == IPC_M_AS_AREA_SEND) { |
145 | if (!IPC_GET_RETVAL(answer->data)) { |
169 | if (!IPC_GET_RETVAL(answer->data)) { |
146 | /* Accepted, handle as_area receipt */ |
170 | /* Accepted, handle as_area receipt */ |
147 | ipl_t ipl; |
171 | ipl_t ipl; |
148 | int rc; |
172 | int rc; |
149 | as_t *as; |
173 | as_t *as; |
150 | 174 | ||
151 | ipl = interrupts_disable(); |
175 | ipl = interrupts_disable(); |
152 | spinlock_lock(&answer->sender->lock); |
176 | spinlock_lock(&answer->sender->lock); |
153 | as = answer->sender->as; |
177 | as = answer->sender->as; |
154 | spinlock_unlock(&answer->sender->lock); |
178 | spinlock_unlock(&answer->sender->lock); |
155 | interrupts_restore(ipl); |
179 | interrupts_restore(ipl); |
156 | 180 | ||
157 | rc = as_area_share(as, IPC_GET_ARG1(*olddata), |
181 | rc = as_area_share(as, IPC_GET_ARG1(*olddata), |
158 | IPC_GET_ARG2(*olddata), AS, |
182 | IPC_GET_ARG2(*olddata), AS, |
159 | IPC_GET_ARG1(answer->data), IPC_GET_ARG3(*olddata)); |
183 | IPC_GET_ARG1(answer->data), IPC_GET_ARG3(*olddata)); |
160 | IPC_SET_RETVAL(answer->data, rc); |
184 | IPC_SET_RETVAL(answer->data, rc); |
161 | return rc; |
185 | return rc; |
162 | } |
186 | } |
163 | } else if (IPC_GET_METHOD(*olddata) == IPC_M_AS_AREA_RECV) { |
187 | } else if (IPC_GET_METHOD(*olddata) == IPC_M_AS_AREA_RECV) { |
164 | if (!IPC_GET_RETVAL(answer->data)) { |
188 | if (!IPC_GET_RETVAL(answer->data)) { |
165 | ipl_t ipl; |
189 | ipl_t ipl; |
166 | as_t *as; |
190 | as_t *as; |
167 | int rc; |
191 | int rc; |
168 | 192 | ||
169 | ipl = interrupts_disable(); |
193 | ipl = interrupts_disable(); |
170 | spinlock_lock(&answer->sender->lock); |
194 | spinlock_lock(&answer->sender->lock); |
171 | as = answer->sender->as; |
195 | as = answer->sender->as; |
172 | spinlock_unlock(&answer->sender->lock); |
196 | spinlock_unlock(&answer->sender->lock); |
173 | interrupts_restore(ipl); |
197 | interrupts_restore(ipl); |
174 | 198 | ||
175 | rc = as_area_share(AS, IPC_GET_ARG1(answer->data), |
199 | rc = as_area_share(AS, IPC_GET_ARG1(answer->data), |
176 | IPC_GET_ARG2(*olddata), as, IPC_GET_ARG1(*olddata), |
200 | IPC_GET_ARG2(*olddata), as, IPC_GET_ARG1(*olddata), |
177 | IPC_GET_ARG2(answer->data)); |
201 | IPC_GET_ARG2(answer->data)); |
178 | IPC_SET_RETVAL(answer->data, rc); |
202 | IPC_SET_RETVAL(answer->data, rc); |
179 | } |
203 | } |
180 | } |
204 | } |
181 | return 0; |
205 | return 0; |
182 | } |
206 | } |
183 | 207 | ||
184 | /** Called before the request is sent |
208 | /** Called before the request is sent. |
- | 209 | * |
|
- | 210 | * @param call Call structure with the request. |
|
185 | * |
211 | * |
186 | * @return 0 - no error, -1 - report error to user |
212 | * @return Return 0 on success, ELIMIT or EPERM on error. |
187 | */ |
213 | */ |
188 | static int request_preprocess(call_t *call) |
214 | static int request_preprocess(call_t *call) |
189 | { |
215 | { |
190 | int newphid; |
216 | int newphid; |
191 | size_t size; |
217 | size_t size; |
192 | 218 | ||
193 | switch (IPC_GET_METHOD(call->data)) { |
219 | switch (IPC_GET_METHOD(call->data)) { |
194 | case IPC_M_CONNECT_ME_TO: |
220 | case IPC_M_CONNECT_ME_TO: |
195 | newphid = phone_alloc(); |
221 | newphid = phone_alloc(); |
196 | if (newphid < 0) |
222 | if (newphid < 0) |
197 | return ELIMIT; |
223 | return ELIMIT; |
198 | /* Set arg3 for server */ |
224 | /* Set arg3 for server */ |
199 | IPC_SET_ARG3(call->data, (unative_t) &TASK->phones[newphid]); |
225 | IPC_SET_ARG3(call->data, (unative_t) &TASK->phones[newphid]); |
200 | call->flags |= IPC_CALL_CONN_ME_TO; |
226 | call->flags |= IPC_CALL_CONN_ME_TO; |
201 | call->priv = newphid; |
227 | call->priv = newphid; |
202 | break; |
228 | break; |
203 | case IPC_M_AS_AREA_SEND: |
229 | case IPC_M_AS_AREA_SEND: |
204 | size = as_get_size(IPC_GET_ARG1(call->data)); |
230 | size = as_get_size(IPC_GET_ARG1(call->data)); |
205 | if (!size) { |
231 | if (!size) |
206 | return EPERM; |
232 | return EPERM; |
207 | } |
- | |
208 | IPC_SET_ARG2(call->data, size); |
233 | IPC_SET_ARG2(call->data, size); |
209 | break; |
234 | break; |
210 | default: |
235 | default: |
211 | break; |
236 | break; |
212 | } |
237 | } |
213 | return 0; |
238 | return 0; |
214 | } |
239 | } |
215 | 240 | ||
216 | /****************************************************/ |
241 | /******************************************************************************* |
217 | /* Functions called to process received call/answer |
242 | * Functions called to process received call/answer before passing it to uspace. |
218 | * before passing to uspace |
243 | *******************************************************************************/ |
219 | */ |
- | |
220 | 244 | ||
221 | /** Do basic kernel processing of received call answer */ |
245 | /** Do basic kernel processing of received call answer. |
- | 246 | * |
|
- | 247 | * @param call Call structure with the answer. |
|
- | 248 | */ |
|
222 | static void process_answer(call_t *call) |
249 | static void process_answer(call_t *call) |
223 | { |
250 | { |
224 | if (IPC_GET_RETVAL(call->data) == EHANGUP && |
251 | if (IPC_GET_RETVAL(call->data) == EHANGUP && |
225 | (call->flags & IPC_CALL_FORWARDED)) |
252 | (call->flags & IPC_CALL_FORWARDED)) |
226 | IPC_SET_RETVAL(call->data, EFORWARD); |
253 | IPC_SET_RETVAL(call->data, EFORWARD); |
227 | 254 | ||
228 | if (call->flags & IPC_CALL_CONN_ME_TO) { |
255 | if (call->flags & IPC_CALL_CONN_ME_TO) { |
229 | if (IPC_GET_RETVAL(call->data)) |
256 | if (IPC_GET_RETVAL(call->data)) |
230 | phone_dealloc(call->priv); |
257 | phone_dealloc(call->priv); |
231 | else |
258 | else |
232 | IPC_SET_ARG3(call->data, call->priv); |
259 | IPC_SET_ARG3(call->data, call->priv); |
233 | } |
260 | } |
234 | } |
261 | } |
235 | 262 | ||
236 | /** Do basic kernel processing of received call request |
263 | /** Do basic kernel processing of received call request. |
237 | * |
264 | * |
- | 265 | * @param box Destination answerbox structure. |
|
- | 266 | * @param call Call structure with the request. |
|
- | 267 | * |
|
238 | * @return 0 - the call should be passed to userspace, 1 - ignore call |
268 | * @return Return 0 if the call should be passed to userspace. |
- | 269 | * Return -1 if the call should be ignored. |
|
239 | */ |
270 | */ |
240 | static int process_request(answerbox_t *box, call_t *call) |
271 | static int process_request(answerbox_t *box, call_t *call) |
241 | { |
272 | { |
242 | int phoneid; |
273 | int phoneid; |
243 | 274 | ||
244 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) { |
275 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) { |
245 | phoneid = phone_alloc(); |
276 | phoneid = phone_alloc(); |
246 | if (phoneid < 0) { /* Failed to allocate phone */ |
277 | if (phoneid < 0) { /* Failed to allocate phone */ |
247 | IPC_SET_RETVAL(call->data, ELIMIT); |
278 | IPC_SET_RETVAL(call->data, ELIMIT); |
248 | ipc_answer(box,call); |
279 | ipc_answer(box, call); |
249 | return -1; |
280 | return -1; |
250 | } |
281 | } |
251 | IPC_SET_ARG3(call->data, phoneid); |
282 | IPC_SET_ARG3(call->data, phoneid); |
252 | } |
283 | } |
253 | return 0; |
284 | return 0; |
254 | } |
285 | } |
255 | 286 | ||
256 | /** Send a call over IPC, wait for reply, return to user |
287 | /** Make a fast call over IPC, wait for reply and return to user. |
- | 288 | * |
|
- | 289 | * This function can handle only one argument of payload, but is faster than |
|
- | 290 | * the generic function (i.e. sys_ipc_call_sync()). |
|
257 | * |
291 | * |
- | 292 | * @param phoneid Phone handle for the call. |
|
- | 293 | * @param method Method of the call. |
|
- | 294 | * @param arg1 Service-defined payload argument. |
|
- | 295 | * @param data Address of userspace structure where the reply call will |
|
- | 296 | * be stored. |
|
- | 297 | * |
|
258 | * @return Call identification, returns -1 on fatal error, |
298 | * @return Returns 0 on success. |
259 | -2 on 'Too many async request, handle answers first |
299 | * Return ENOENT if there is no such phone handle. |
260 | */ |
300 | */ |
261 | unative_t sys_ipc_call_sync_fast(unative_t phoneid, unative_t method, |
301 | unative_t sys_ipc_call_sync_fast(unative_t phoneid, unative_t method, |
262 | unative_t arg1, ipc_data_t *data) |
302 | unative_t arg1, ipc_data_t *data) |
263 | { |
303 | { |
264 | call_t call; |
304 | call_t call; |
265 | phone_t *phone; |
305 | phone_t *phone; |
266 | int res; |
306 | int res; |
267 | 307 | ||
268 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
308 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
269 | 309 | ||
270 | ipc_call_static_init(&call); |
310 | ipc_call_static_init(&call); |
271 | IPC_SET_METHOD(call.data, method); |
311 | IPC_SET_METHOD(call.data, method); |
272 | IPC_SET_ARG1(call.data, arg1); |
312 | IPC_SET_ARG1(call.data, arg1); |
273 | 313 | ||
274 | if (!(res=request_preprocess(&call))) { |
314 | if (!(res = request_preprocess(&call))) { |
275 | ipc_call_sync(phone, &call); |
315 | ipc_call_sync(phone, &call); |
276 | process_answer(&call); |
316 | process_answer(&call); |
277 | } else |
317 | } else { |
278 | IPC_SET_RETVAL(call.data, res); |
318 | IPC_SET_RETVAL(call.data, res); |
- | 319 | } |
|
279 | STRUCT_TO_USPACE(&data->args, &call.data.args); |
320 | STRUCT_TO_USPACE(&data->args, &call.data.args); |
280 | 321 | ||
281 | return 0; |
322 | return 0; |
282 | } |
323 | } |
283 | 324 | ||
284 | /** Synchronous IPC call allowing to send whole message */ |
325 | /** Make a synchronous IPC call allowing to transmit the entire payload. |
- | 326 | * |
|
- | 327 | * @param phoneid Phone handle for the call. |
|
- | 328 | * @param question Userspace address of call data with the request. |
|
- | 329 | * @param reply Userspace address of call data where to store the answer. |
|
- | 330 | * |
|
- | 331 | * @return Zero on success or an error code. |
|
- | 332 | */ |
|
285 | unative_t sys_ipc_call_sync(unative_t phoneid, ipc_data_t *question, |
333 | unative_t sys_ipc_call_sync(unative_t phoneid, ipc_data_t *question, |
286 | ipc_data_t *reply) |
334 | ipc_data_t *reply) |
287 | { |
335 | { |
288 | call_t call; |
336 | call_t call; |
289 | phone_t *phone; |
337 | phone_t *phone; |
290 | int res; |
338 | int res; |
291 | int rc; |
339 | int rc; |
292 | 340 | ||
293 | ipc_call_static_init(&call); |
341 | ipc_call_static_init(&call); |
294 | rc = copy_from_uspace(&call.data.args, &question->args, |
342 | rc = copy_from_uspace(&call.data.args, &question->args, |
295 | sizeof(call.data.args)); |
343 | sizeof(call.data.args)); |
296 | if (rc != 0) |
344 | if (rc != 0) |
297 | return (unative_t) rc; |
345 | return (unative_t) rc; |
298 | 346 | ||
299 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
347 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
300 | 348 | ||
301 | if (!(res=request_preprocess(&call))) { |
349 | if (!(res = request_preprocess(&call))) { |
302 | ipc_call_sync(phone, &call); |
350 | ipc_call_sync(phone, &call); |
303 | process_answer(&call); |
351 | process_answer(&call); |
304 | } else |
352 | } else |
305 | IPC_SET_RETVAL(call.data, res); |
353 | IPC_SET_RETVAL(call.data, res); |
306 | 354 | ||
307 | rc = STRUCT_TO_USPACE(&reply->args, &call.data.args); |
355 | rc = STRUCT_TO_USPACE(&reply->args, &call.data.args); |
308 | if (rc != 0) |
356 | if (rc != 0) |
309 | return rc; |
357 | return rc; |
310 | 358 | ||
311 | return 0; |
359 | return 0; |
312 | } |
360 | } |
313 | 361 | ||
314 | /** Check that the task did not exceed allowed limit |
362 | /** Check that the task did not exceed the allowed limit of asynchronous calls. |
315 | * |
363 | * |
316 | * @return 0 - Limit OK, -1 - limit exceeded |
364 | * @return Return 0 if limit not reached or -1 if limit exceeded. |
317 | */ |
365 | */ |
318 | static int check_call_limit(void) |
366 | static int check_call_limit(void) |
319 | { |
367 | { |
320 | if (atomic_preinc(&TASK->active_calls) > IPC_MAX_ASYNC_CALLS) { |
368 | if (atomic_preinc(&TASK->active_calls) > IPC_MAX_ASYNC_CALLS) { |
321 | atomic_dec(&TASK->active_calls); |
369 | atomic_dec(&TASK->active_calls); |
322 | return -1; |
370 | return -1; |
323 | } |
371 | } |
324 | return 0; |
372 | return 0; |
325 | } |
373 | } |
326 | 374 | ||
327 | /** Send an asynchronous call over ipc |
375 | /** Make a fast asynchronous call over IPC. |
328 | * |
376 | * |
- | 377 | * This function can only handle two arguments of payload, but is faster than |
|
- | 378 | * the generic function sys_ipc_call_async(). |
|
- | 379 | * |
|
- | 380 | * @param phoneid Phone handle for the call. |
|
- | 381 | * @param method Method of the call. |
|
- | 382 | * @param arg1 Service-defined payload argument. |
|
- | 383 | * @param arg2 Service-defined payload argument. |
|
- | 384 | * |
|
- | 385 | * @return Return call hash on success. |
|
329 | * @return Call identification, returns -1 on fatal error, |
386 | * Return IPC_CALLRET_FATAL in case of a fatal error and |
- | 387 | * IPC_CALLRET_TEMPORARY if there are too many pending |
|
330 | -2 on 'Too many async request, handle answers first |
388 | * asynchronous requests; answers should be handled first. |
331 | */ |
389 | */ |
332 | unative_t sys_ipc_call_async_fast(unative_t phoneid, unative_t method, |
390 | unative_t sys_ipc_call_async_fast(unative_t phoneid, unative_t method, |
333 | unative_t arg1, unative_t arg2) |
391 | unative_t arg1, unative_t arg2) |
334 | { |
392 | { |
335 | call_t *call; |
393 | call_t *call; |
336 | phone_t *phone; |
394 | phone_t *phone; |
337 | int res; |
395 | int res; |
338 | 396 | ||
339 | if (check_call_limit()) |
397 | if (check_call_limit()) |
340 | return IPC_CALLRET_TEMPORARY; |
398 | return IPC_CALLRET_TEMPORARY; |
341 | 399 | ||
342 | GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL); |
400 | GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL); |
343 | 401 | ||
344 | call = ipc_call_alloc(0); |
402 | call = ipc_call_alloc(0); |
345 | IPC_SET_METHOD(call->data, method); |
403 | IPC_SET_METHOD(call->data, method); |
346 | IPC_SET_ARG1(call->data, arg1); |
404 | IPC_SET_ARG1(call->data, arg1); |
347 | IPC_SET_ARG2(call->data, arg2); |
405 | IPC_SET_ARG2(call->data, arg2); |
348 | IPC_SET_ARG3(call->data, 0); |
406 | IPC_SET_ARG3(call->data, 0); |
349 | 407 | ||
350 | if (!(res = request_preprocess(call))) |
408 | if (!(res = request_preprocess(call))) |
351 | ipc_call(phone, call); |
409 | ipc_call(phone, call); |
352 | else |
410 | else |
353 | ipc_backsend_err(phone, call, res); |
411 | ipc_backsend_err(phone, call, res); |
354 | 412 | ||
355 | return (unative_t) call; |
413 | return (unative_t) call; |
356 | } |
414 | } |
357 | 415 | ||
358 | /** Synchronous IPC call allowing to send whole message |
416 | /** Make an asynchronous IPC call allowing to transmit the entire payload. |
- | 417 | * |
|
- | 418 | * @param phoneid Phone handle for the call. |
|
- | 419 | * @param data Userspace address of call data with the request. |
|
359 | * |
420 | * |
360 | * @return The same as sys_ipc_call_async |
421 | * @return See sys_ipc_call_async_fast(). |
361 | */ |
422 | */ |
362 | unative_t sys_ipc_call_async(unative_t phoneid, ipc_data_t *data) |
423 | unative_t sys_ipc_call_async(unative_t phoneid, ipc_data_t *data) |
363 | { |
424 | { |
364 | call_t *call; |
425 | call_t *call; |
365 | phone_t *phone; |
426 | phone_t *phone; |
366 | int res; |
427 | int res; |
367 | int rc; |
428 | int rc; |
368 | 429 | ||
369 | if (check_call_limit()) |
430 | if (check_call_limit()) |
370 | return IPC_CALLRET_TEMPORARY; |
431 | return IPC_CALLRET_TEMPORARY; |
371 | 432 | ||
372 | GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL); |
433 | GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL); |
373 | 434 | ||
374 | call = ipc_call_alloc(0); |
435 | call = ipc_call_alloc(0); |
375 | rc = copy_from_uspace(&call->data.args, &data->args, |
436 | rc = copy_from_uspace(&call->data.args, &data->args, |
376 | sizeof(call->data.args)); |
437 | sizeof(call->data.args)); |
377 | if (rc != 0) { |
438 | if (rc != 0) { |
378 | ipc_call_free(call); |
439 | ipc_call_free(call); |
379 | return (unative_t) rc; |
440 | return (unative_t) rc; |
380 | } |
441 | } |
381 | if (!(res = request_preprocess(call))) |
442 | if (!(res = request_preprocess(call))) |
382 | ipc_call(phone, call); |
443 | ipc_call(phone, call); |
383 | else |
444 | else |
384 | ipc_backsend_err(phone, call, res); |
445 | ipc_backsend_err(phone, call, res); |
385 | 446 | ||
386 | return (unative_t) call; |
447 | return (unative_t) call; |
387 | } |
448 | } |
388 | 449 | ||
389 | /** Forward received call to another destination |
450 | /** Forward a received call to another destination. |
390 | * |
451 | * |
- | 452 | * @param callid Hash of the call to forward. |
|
- | 453 | * @param phoneid Phone handle to use for forwarding. |
|
- | 454 | * @param method New method to use for the forwarded call. |
|
391 | * The arg1 and arg2 are changed in the forwarded message |
455 | * @param arg1 New value of the first argument for the forwarded call. |
- | 456 | * |
|
- | 457 | * @return Return 0 on succes, otherwise return an error code. |
|
- | 458 | * |
|
- | 459 | * In case the original method is a system method, ARG1 and ARG2 are overwritten |
|
- | 460 | * in the forwarded message with the new method and the new arg1, respectively. |
|
- | 461 | * Otherwise the METHOD and ARG1 are rewritten with the new method and arg1, |
|
- | 462 | * respectively. |
|
392 | * |
463 | * |
393 | * Warning: If implementing non-fast version, make sure that |
464 | * Warning: If implementing non-fast version, make sure that |
394 | * arg3 is not rewritten for certain system IPC |
465 | * ARG3 is not rewritten for certain system IPC |
395 | */ |
466 | */ |
396 | unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid, |
467 | unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid, |
397 | unative_t method, unative_t arg1) |
468 | unative_t method, unative_t arg1) |
398 | { |
469 | { |
399 | call_t *call; |
470 | call_t *call; |
400 | phone_t *phone; |
471 | phone_t *phone; |
401 | 472 | ||
402 | call = get_call(callid); |
473 | call = get_call(callid); |
403 | if (!call) |
474 | if (!call) |
404 | return ENOENT; |
475 | return ENOENT; |
405 | 476 | ||
406 | call->flags |= IPC_CALL_FORWARDED; |
477 | call->flags |= IPC_CALL_FORWARDED; |
407 | 478 | ||
408 | GET_CHECK_PHONE(phone, phoneid, { |
479 | GET_CHECK_PHONE(phone, phoneid, { |
409 | IPC_SET_RETVAL(call->data, EFORWARD); |
480 | IPC_SET_RETVAL(call->data, EFORWARD); |
410 | ipc_answer(&TASK->answerbox, call); |
481 | ipc_answer(&TASK->answerbox, call); |
411 | return ENOENT; |
482 | return ENOENT; |
412 | }); |
483 | }); |
413 | 484 | ||
414 | if (!is_forwardable(IPC_GET_METHOD(call->data))) { |
485 | if (!is_forwardable(IPC_GET_METHOD(call->data))) { |
415 | IPC_SET_RETVAL(call->data, EFORWARD); |
486 | IPC_SET_RETVAL(call->data, EFORWARD); |
416 | ipc_answer(&TASK->answerbox, call); |
487 | ipc_answer(&TASK->answerbox, call); |
417 | return EPERM; |
488 | return EPERM; |
418 | } |
489 | } |
419 | 490 | ||
420 | /* Userspace is not allowed to change method of system methods |
491 | /* Userspace is not allowed to change method of system methods |
421 | * on forward, allow changing ARG1 and ARG2 by means of method and arg1 |
492 | * on forward, allow changing ARG1 and ARG2 by means of method and arg1 |
422 | */ |
493 | */ |
423 | if (is_system_method(IPC_GET_METHOD(call->data))) { |
494 | if (is_system_method(IPC_GET_METHOD(call->data))) { |
424 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) |
495 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) |
425 | phone_dealloc(IPC_GET_ARG3(call->data)); |
496 | phone_dealloc(IPC_GET_ARG3(call->data)); |
426 | 497 | ||
427 | IPC_SET_ARG1(call->data, method); |
498 | IPC_SET_ARG1(call->data, method); |
428 | IPC_SET_ARG2(call->data, arg1); |
499 | IPC_SET_ARG2(call->data, arg1); |
429 | } else { |
500 | } else { |
430 | IPC_SET_METHOD(call->data, method); |
501 | IPC_SET_METHOD(call->data, method); |
431 | IPC_SET_ARG1(call->data, arg1); |
502 | IPC_SET_ARG1(call->data, arg1); |
432 | } |
503 | } |
433 | 504 | ||
434 | return ipc_forward(call, phone, &TASK->answerbox); |
505 | return ipc_forward(call, phone, &TASK->answerbox); |
435 | } |
506 | } |
436 | 507 | ||
437 | /** Send IPC answer */ |
508 | /** Answer an IPC call - fast version. |
- | 509 | * |
|
- | 510 | * This function can handle only two return arguments of payload, but is faster |
|
- | 511 | * than the generic sys_ipc_answer(). |
|
- | 512 | * |
|
- | 513 | * @param callid Hash of the call to be answered. |
|
- | 514 | * @param retval Return value of the answer. |
|
- | 515 | * @param arg1 Service-defined return value. |
|
- | 516 | * @param arg2 Service-defined return value. |
|
- | 517 | * |
|
- | 518 | * @return Return 0 on success, otherwise return an error code. |
|
- | 519 | */ |
|
438 | unative_t sys_ipc_answer_fast(unative_t callid, unative_t retval, |
520 | unative_t sys_ipc_answer_fast(unative_t callid, unative_t retval, |
439 | unative_t arg1, unative_t arg2) |
521 | unative_t arg1, unative_t arg2) |
440 | { |
522 | { |
441 | call_t *call; |
523 | call_t *call; |
442 | ipc_data_t saved_data; |
524 | ipc_data_t saved_data; |
443 | int saveddata = 0; |
525 | int saveddata = 0; |
444 | int rc; |
526 | int rc; |
445 | 527 | ||
446 | /* Do not answer notification callids */ |
528 | /* Do not answer notification callids */ |
447 | if (callid & IPC_CALLID_NOTIFICATION) |
529 | if (callid & IPC_CALLID_NOTIFICATION) |
448 | return 0; |
530 | return 0; |
449 | 531 | ||
450 | call = get_call(callid); |
532 | call = get_call(callid); |
451 | if (!call) |
533 | if (!call) |
452 | return ENOENT; |
534 | return ENOENT; |
453 | 535 | ||
454 | if (answer_need_old(call)) { |
536 | if (answer_need_old(call)) { |
455 | memcpy(&saved_data, &call->data, sizeof(call->data)); |
537 | memcpy(&saved_data, &call->data, sizeof(call->data)); |
456 | saveddata = 1; |
538 | saveddata = 1; |
457 | } |
539 | } |
458 | 540 | ||
459 | IPC_SET_RETVAL(call->data, retval); |
541 | IPC_SET_RETVAL(call->data, retval); |
460 | IPC_SET_ARG1(call->data, arg1); |
542 | IPC_SET_ARG1(call->data, arg1); |
461 | IPC_SET_ARG2(call->data, arg2); |
543 | IPC_SET_ARG2(call->data, arg2); |
462 | rc = answer_preprocess(call, saveddata ? &saved_data : NULL); |
544 | rc = answer_preprocess(call, saveddata ? &saved_data : NULL); |
463 | 545 | ||
464 | ipc_answer(&TASK->answerbox, call); |
546 | ipc_answer(&TASK->answerbox, call); |
465 | return rc; |
547 | return rc; |
466 | } |
548 | } |
467 | 549 | ||
468 | /** Send IPC answer */ |
550 | /** Answer an IPC call. |
- | 551 | * |
|
- | 552 | * @param callid Hash of the call to be answered. |
|
- | 553 | * @param data Userspace address of call data with the answer. |
|
- | 554 | * |
|
- | 555 | * @return Return 0 on success, otherwise return an error code. |
|
- | 556 | */ |
|
469 | unative_t sys_ipc_answer(unative_t callid, ipc_data_t *data) |
557 | unative_t sys_ipc_answer(unative_t callid, ipc_data_t *data) |
470 | { |
558 | { |
471 | call_t *call; |
559 | call_t *call; |
472 | ipc_data_t saved_data; |
560 | ipc_data_t saved_data; |
473 | int saveddata = 0; |
561 | int saveddata = 0; |
474 | int rc; |
562 | int rc; |
475 | 563 | ||
476 | /* Do not answer notification callids */ |
564 | /* Do not answer notification callids */ |
477 | if (callid & IPC_CALLID_NOTIFICATION) |
565 | if (callid & IPC_CALLID_NOTIFICATION) |
478 | return 0; |
566 | return 0; |
479 | 567 | ||
480 | call = get_call(callid); |
568 | call = get_call(callid); |
481 | if (!call) |
569 | if (!call) |
482 | return ENOENT; |
570 | return ENOENT; |
483 | 571 | ||
484 | if (answer_need_old(call)) { |
572 | if (answer_need_old(call)) { |
485 | memcpy(&saved_data, &call->data, sizeof(call->data)); |
573 | memcpy(&saved_data, &call->data, sizeof(call->data)); |
486 | saveddata = 1; |
574 | saveddata = 1; |
487 | } |
575 | } |
488 | rc = copy_from_uspace(&call->data.args, &data->args, |
576 | rc = copy_from_uspace(&call->data.args, &data->args, |
489 | sizeof(call->data.args)); |
577 | sizeof(call->data.args)); |
490 | if (rc != 0) |
578 | if (rc != 0) |
491 | return rc; |
579 | return rc; |
492 | 580 | ||
493 | rc = answer_preprocess(call, saveddata ? &saved_data : NULL); |
581 | rc = answer_preprocess(call, saveddata ? &saved_data : NULL); |
494 | 582 | ||
495 | ipc_answer(&TASK->answerbox, call); |
583 | ipc_answer(&TASK->answerbox, call); |
496 | 584 | ||
497 | return rc; |
585 | return rc; |
498 | } |
586 | } |
499 | 587 | ||
500 | /** Hang up the phone |
588 | /** Hang up a phone. |
501 | * |
589 | * |
- | 590 | * @param Phone handle of the phone to be hung up. |
|
- | 591 | * |
|
- | 592 | * @return Return 0 on success or an error code. |
|
502 | */ |
593 | */ |
503 | unative_t sys_ipc_hangup(int phoneid) |
594 | unative_t sys_ipc_hangup(int phoneid) |
504 | { |
595 | { |
505 | phone_t *phone; |
596 | phone_t *phone; |
506 | 597 | ||
507 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
598 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
508 | 599 | ||
509 | if (ipc_phone_hangup(phone)) |
600 | if (ipc_phone_hangup(phone)) |
510 | return -1; |
601 | return -1; |
511 | 602 | ||
512 | return 0; |
603 | return 0; |
513 | } |
604 | } |
514 | 605 | ||
515 | /** Wait for incoming ipc call or answer |
606 | /** Wait for an incoming IPC call or an answer. |
516 | * |
607 | * |
517 | * @param calldata Pointer to buffer where the call/answer data is stored. |
608 | * @param calldata Pointer to buffer where the call/answer data is stored. |
518 | * @param usec Timeout. See waitq_sleep_timeout() for explanation. |
609 | * @param usec Timeout. See waitq_sleep_timeout() for explanation. |
519 | * @param flags Select mode of sleep operation. See waitq_sleep_timeout() |
610 | * @param flags Select mode of sleep operation. See waitq_sleep_timeout() |
520 | * for explanation. |
611 | * for explanation. |
521 | * |
612 | * |
522 | * @return Callid, if callid & 1, then the call is answer |
613 | * @return Hash of the call. |
- | 614 | * If IPC_CALLID_NOTIFICATION bit is set in the hash, the |
|
- | 615 | * call is a notification. IPC_CALLID_ANSWERED denotes an |
|
- | 616 | * answer. |
|
523 | */ |
617 | */ |
524 | unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec, int flags) |
618 | unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec, int flags) |
525 | { |
619 | { |
526 | call_t *call; |
620 | call_t *call; |
527 | 621 | ||
528 | restart: |
622 | restart: |
529 | call = ipc_wait_for_call(&TASK->answerbox, usec, |
623 | call = ipc_wait_for_call(&TASK->answerbox, usec, |
530 | flags | SYNCH_FLAGS_INTERRUPTIBLE); |
624 | flags | SYNCH_FLAGS_INTERRUPTIBLE); |
531 | if (!call) |
625 | if (!call) |
532 | return 0; |
626 | return 0; |
533 | 627 | ||
534 | if (call->flags & IPC_CALL_NOTIF) { |
628 | if (call->flags & IPC_CALL_NOTIF) { |
535 | ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC)); |
629 | ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC)); |
536 | 630 | ||
537 | /* Set in_phone_hash to the interrupt counter */ |
631 | /* Set in_phone_hash to the interrupt counter */ |
538 | call->data.phone = (void *) call->priv; |
632 | call->data.phone = (void *) call->priv; |
539 | 633 | ||
540 | STRUCT_TO_USPACE(calldata, &call->data); |
634 | STRUCT_TO_USPACE(calldata, &call->data); |
541 | 635 | ||
542 | ipc_call_free(call); |
636 | ipc_call_free(call); |
543 | 637 | ||
544 | return ((unative_t)call) | IPC_CALLID_NOTIFICATION; |
638 | return ((unative_t) call) | IPC_CALLID_NOTIFICATION; |
545 | } |
639 | } |
546 | 640 | ||
547 | if (call->flags & IPC_CALL_ANSWERED) { |
641 | if (call->flags & IPC_CALL_ANSWERED) { |
548 | process_answer(call); |
642 | process_answer(call); |
549 | 643 | ||
550 | ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC)); |
644 | ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC)); |
551 | 645 | ||
552 | atomic_dec(&TASK->active_calls); |
646 | atomic_dec(&TASK->active_calls); |
553 | 647 | ||
554 | if (call->flags & IPC_CALL_DISCARD_ANSWER) { |
648 | if (call->flags & IPC_CALL_DISCARD_ANSWER) { |
555 | ipc_call_free(call); |
649 | ipc_call_free(call); |
556 | goto restart; |
650 | goto restart; |
557 | } |
651 | } |
558 | 652 | ||
559 | STRUCT_TO_USPACE(&calldata->args, &call->data.args); |
653 | STRUCT_TO_USPACE(&calldata->args, &call->data.args); |
560 | ipc_call_free(call); |
654 | ipc_call_free(call); |
561 | 655 | ||
562 | return ((unative_t)call) | IPC_CALLID_ANSWERED; |
656 | return ((unative_t) call) | IPC_CALLID_ANSWERED; |
563 | } |
657 | } |
564 | 658 | ||
565 | if (process_request(&TASK->answerbox, call)) |
659 | if (process_request(&TASK->answerbox, call)) |
566 | goto restart; |
660 | goto restart; |
567 | 661 | ||
568 | /* Include phone address('id') of the caller in the request, |
662 | /* Include phone address('id') of the caller in the request, |
569 | * copy whole call->data, not only call->data.args */ |
663 | * copy whole call->data, not only call->data.args */ |
570 | if (STRUCT_TO_USPACE(calldata, &call->data)) { |
664 | if (STRUCT_TO_USPACE(calldata, &call->data)) { |
571 | return 0; |
665 | return 0; |
572 | } |
666 | } |
573 | return (unative_t)call; |
667 | return (unative_t)call; |
574 | } |
668 | } |
575 | 669 | ||
576 | /** Connect irq handler to task. |
670 | /** Connect an IRQ handler to a task. |
577 | * |
671 | * |
578 | * @param inr IRQ number. |
672 | * @param inr IRQ number. |
579 | * @param devno Device number. |
673 | * @param devno Device number. |
580 | * @param method Method to be associated with the notification. |
674 | * @param method Method to be associated with the notification. |
581 | * @param ucode Uspace pointer to the top-half pseudocode. |
675 | * @param ucode Uspace pointer to the top-half pseudocode. |
582 | * |
676 | * |
583 | * @return EPERM or a return code returned by ipc_irq_register(). |
677 | * @return EPERM or a return code returned by ipc_irq_register(). |
584 | */ |
678 | */ |
585 | unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method, |
679 | unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method, |
586 | irq_code_t *ucode) |
680 | irq_code_t *ucode) |
587 | { |
681 | { |
588 | if (!(cap_get(TASK) & CAP_IRQ_REG)) |
682 | if (!(cap_get(TASK) & CAP_IRQ_REG)) |
589 | return EPERM; |
683 | return EPERM; |
590 | 684 | ||
591 | return ipc_irq_register(&TASK->answerbox, inr, devno, method, ucode); |
685 | return ipc_irq_register(&TASK->answerbox, inr, devno, method, ucode); |
592 | } |
686 | } |
593 | 687 | ||
594 | /** Disconnect irq handler from task. |
688 | /** Disconnect an IRQ handler from a task. |
- | 689 | * |
|
- | 690 | * @param inr IRQ number. |
|
- | 691 | * @param devno Device number. |
|
595 | * |
692 | * |
596 | * @param inr IRQ number. |
- | |
597 | * @param devno Device number. |
693 | * @return Zero on success or EPERM on error.. |
598 | */ |
694 | */ |
599 | unative_t sys_ipc_unregister_irq(inr_t inr, devno_t devno) |
695 | unative_t sys_ipc_unregister_irq(inr_t inr, devno_t devno) |
600 | { |
696 | { |
601 | if (!(cap_get(TASK) & CAP_IRQ_REG)) |
697 | if (!(cap_get(TASK) & CAP_IRQ_REG)) |
602 | return EPERM; |
698 | return EPERM; |
603 | 699 | ||
604 | ipc_irq_unregister(&TASK->answerbox, inr, devno); |
700 | ipc_irq_unregister(&TASK->answerbox, inr, devno); |
605 | 701 | ||
606 | return 0; |
702 | return 0; |
607 | } |
703 | } |
608 | 704 | ||
609 | /** @} |
705 | /** @} |
610 | */ |
706 | */ |
611 | 707 |