[2d5a54f3] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[2d5a54f3] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 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
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 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
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 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
|
---|
| 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
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[cc73a8a1] | 29 | /** @addtogroup genericipc
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[2d5a54f3] | 35 | #include <arch.h>
|
---|
| 36 | #include <errno.h>
|
---|
| 37 | #include <memstr.h>
|
---|
| 38 | #include <ipc/ipc.h>
|
---|
[c0699467] | 39 | #include <abi/ipc/methods.h>
|
---|
[2d5a54f3] | 40 | #include <ipc/sysipc.h>
|
---|
[e8039a86] | 41 | #include <ipc/sysipc_ops.h>
|
---|
[5d3ed34] | 42 | #include <ipc/sysipc_priv.h>
|
---|
[162f919] | 43 | #include <ipc/irq.h>
|
---|
[4e49572] | 44 | #include <ipc/ipcrsc.h>
|
---|
[fdd4898] | 45 | #include <ipc/event.h>
|
---|
[e028660] | 46 | #include <ipc/kbox.h>
|
---|
[057d21a] | 47 | #include <synch/waitq.h>
|
---|
[5626277] | 48 | #include <arch/interrupt.h>
|
---|
[e3c762cd] | 49 | #include <syscall/copy.h>
|
---|
[2bb8648] | 50 | #include <security/cap.h>
|
---|
[6b10dab] | 51 | #include <console/console.h>
|
---|
[253f35a1] | 52 | #include <print.h>
|
---|
[e2ab36f1] | 53 | #include <macros.h>
|
---|
[2d5a54f3] | 54 |
|
---|
[da1bafb] | 55 | #define STRUCT_TO_USPACE(dst, src) copy_to_uspace((dst), (src), sizeof(*(src)))
|
---|
[7918fce] | 56 |
|
---|
[228e490] | 57 | /** Decide if the interface and method is a system method.
|
---|
[8b243f2] | 58 | *
|
---|
[228e490] | 59 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 60 | *
|
---|
[228e490] | 61 | * @return True if the interface and method is a system
|
---|
| 62 | * interface and method.
|
---|
[8b243f2] | 63 | *
|
---|
| 64 | */
|
---|
[228e490] | 65 | static inline bool method_is_system(sysarg_t imethod)
|
---|
[2ba7810] | 66 | {
|
---|
[228e490] | 67 | if (imethod <= IPC_M_LAST_SYSTEM)
|
---|
[da1bafb] | 68 | return true;
|
---|
| 69 |
|
---|
| 70 | return false;
|
---|
[2ba7810] | 71 | }
|
---|
| 72 |
|
---|
[228e490] | 73 | /** Decide if the message with this interface and method is forwardable.
|
---|
[2ba7810] | 74 | *
|
---|
[228e490] | 75 | * Some system messages may be forwarded, for some of them
|
---|
| 76 | * it is useless.
|
---|
[8b243f2] | 77 | *
|
---|
[228e490] | 78 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 79 | *
|
---|
[228e490] | 80 | * @return True if the interface and method is forwardable.
|
---|
[8b243f2] | 81 | *
|
---|
[2ba7810] | 82 | */
|
---|
[228e490] | 83 | static inline bool method_is_forwardable(sysarg_t imethod)
|
---|
[2ba7810] | 84 | {
|
---|
[228e490] | 85 | switch (imethod) {
|
---|
[2c0e5d2] | 86 | case IPC_M_CONNECTION_CLONE:
|
---|
[6aae539d] | 87 | case IPC_M_CLONE_ESTABLISH:
|
---|
[7918fce] | 88 | case IPC_M_PHONE_HUNGUP:
|
---|
| 89 | /* This message is meant only for the original recipient. */
|
---|
[da1bafb] | 90 | return false;
|
---|
[7918fce] | 91 | default:
|
---|
[da1bafb] | 92 | return true;
|
---|
[7918fce] | 93 | }
|
---|
[2ba7810] | 94 | }
|
---|
| 95 |
|
---|
[228e490] | 96 | /** Decide if the message with this interface and method is immutable on forward.
|
---|
[0dc4258] | 97 | *
|
---|
[228e490] | 98 | * Some system messages may be forwarded but their content cannot be altered.
|
---|
[0dc4258] | 99 | *
|
---|
[228e490] | 100 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 101 | *
|
---|
[228e490] | 102 | * @return True if the interface and method is immutable on forward.
|
---|
[0dc4258] | 103 | *
|
---|
| 104 | */
|
---|
[228e490] | 105 | static inline bool method_is_immutable(sysarg_t imethod)
|
---|
[0dc4258] | 106 | {
|
---|
[228e490] | 107 | switch (imethod) {
|
---|
[27d293a] | 108 | case IPC_M_SHARE_OUT:
|
---|
| 109 | case IPC_M_SHARE_IN:
|
---|
[36d852c] | 110 | case IPC_M_DATA_WRITE:
|
---|
| 111 | case IPC_M_DATA_READ:
|
---|
[fdd4898] | 112 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
---|
[da1bafb] | 113 | return true;
|
---|
[0dc4258] | 114 | default:
|
---|
[da1bafb] | 115 | return false;
|
---|
[0dc4258] | 116 | }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[2d5a54f3] | 119 |
|
---|
[8b243f2] | 120 | /***********************************************************************
|
---|
| 121 | * Functions that preprocess answer before sending it to the recepient.
|
---|
| 122 | ***********************************************************************/
|
---|
| 123 |
|
---|
| 124 | /** Decide if the caller (e.g. ipc_answer()) should save the old call contents
|
---|
| 125 | * for answer_preprocess().
|
---|
| 126 | *
|
---|
[da1bafb] | 127 | * @param call Call structure to be decided.
|
---|
| 128 | *
|
---|
| 129 | * @return true if the old call contents should be saved.
|
---|
[8b243f2] | 130 | *
|
---|
[2d5a54f3] | 131 | */
|
---|
[da1bafb] | 132 | static inline bool answer_need_old(call_t *call)
|
---|
[2d5a54f3] | 133 | {
|
---|
[228e490] | 134 | switch (IPC_GET_IMETHOD(call->data)) {
|
---|
[2c0e5d2] | 135 | case IPC_M_CONNECTION_CLONE:
|
---|
[6aae539d] | 136 | case IPC_M_CLONE_ESTABLISH:
|
---|
[7918fce] | 137 | case IPC_M_CONNECT_TO_ME:
|
---|
| 138 | case IPC_M_CONNECT_ME_TO:
|
---|
[27d293a] | 139 | case IPC_M_SHARE_OUT:
|
---|
| 140 | case IPC_M_SHARE_IN:
|
---|
[36d852c] | 141 | case IPC_M_DATA_WRITE:
|
---|
| 142 | case IPC_M_DATA_READ:
|
---|
[fdd4898] | 143 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
---|
[da1bafb] | 144 | return true;
|
---|
[7918fce] | 145 | default:
|
---|
[da1bafb] | 146 | return false;
|
---|
[7918fce] | 147 | }
|
---|
[2d5a54f3] | 148 | }
|
---|
| 149 |
|
---|
[8b243f2] | 150 | /** Interpret process answer as control information.
|
---|
| 151 | *
|
---|
| 152 | * This function is called directly after sys_ipc_answer().
|
---|
[46fc2f9] | 153 | *
|
---|
[da1bafb] | 154 | * @param answer Call structure with the answer.
|
---|
| 155 | * @param olddata Saved data of the request.
|
---|
| 156 | *
|
---|
[9956fad9] | 157 | * @return Return EOK on success or a negative error code.
|
---|
[8b243f2] | 158 | *
|
---|
[46fc2f9] | 159 | */
|
---|
[5d3ed34] | 160 | int answer_preprocess(call_t *answer, ipc_data_t *olddata)
|
---|
[2d5a54f3] | 161 | {
|
---|
[9956fad9] | 162 | int rc = EOK;
|
---|
[b1e6269] | 163 | sysipc_ops_t *ops;
|
---|
[9956fad9] | 164 |
|
---|
[2405bb5] | 165 | spinlock_lock(&answer->forget_lock);
|
---|
| 166 | if (answer->forget) {
|
---|
| 167 | /*
|
---|
| 168 | * This is a forgotten call and answer->sender is not valid.
|
---|
| 169 | */
|
---|
| 170 | spinlock_unlock(&answer->forget_lock);
|
---|
[b1e6269] | 171 |
|
---|
| 172 | ops = sysipc_ops_get(answer->request_method);
|
---|
| 173 | if (ops->answer_cleanup)
|
---|
| 174 | ops->answer_cleanup(answer, olddata);
|
---|
| 175 |
|
---|
[2405bb5] | 176 | return rc;
|
---|
| 177 | } else {
|
---|
[20282ef3] | 178 | ASSERT(answer->active);
|
---|
| 179 |
|
---|
| 180 | /*
|
---|
| 181 | * Mark the call as inactive to prevent _ipc_answer_free_call()
|
---|
| 182 | * from attempting to remove the call from the active list
|
---|
| 183 | * itself.
|
---|
| 184 | */
|
---|
| 185 | answer->active = false;
|
---|
| 186 |
|
---|
| 187 | /*
|
---|
| 188 | * Remove the call from the sender's active call list.
|
---|
| 189 | * We enforce this locking order so that any potential
|
---|
| 190 | * concurrently executing forget operation is forced to
|
---|
| 191 | * release its active_calls_lock and lose the race to
|
---|
| 192 | * forget this soon to be answered call.
|
---|
| 193 | */
|
---|
| 194 | spinlock_lock(&answer->sender->active_calls_lock);
|
---|
| 195 | list_remove(&answer->ta_link);
|
---|
| 196 | spinlock_unlock(&answer->sender->active_calls_lock);
|
---|
[2405bb5] | 197 | }
|
---|
| 198 | spinlock_unlock(&answer->forget_lock);
|
---|
| 199 |
|
---|
[6c441cf8] | 200 | if ((native_t) IPC_GET_RETVAL(answer->data) == EHANGUP) {
|
---|
[2541646] | 201 | phone_t *phone = answer->caller_phone;
|
---|
| 202 | mutex_lock(&phone->lock);
|
---|
| 203 | if (phone->state == IPC_PHONE_CONNECTED) {
|
---|
| 204 | irq_spinlock_lock(&phone->callee->lock, true);
|
---|
| 205 | list_remove(&phone->link);
|
---|
| 206 | phone->state = IPC_PHONE_SLAMMED;
|
---|
| 207 | irq_spinlock_unlock(&phone->callee->lock, true);
|
---|
[ca687ad] | 208 | }
|
---|
[2541646] | 209 | mutex_unlock(&phone->lock);
|
---|
[9f22213] | 210 | }
|
---|
[da1bafb] | 211 |
|
---|
[53af6e8c] | 212 | if (!olddata)
|
---|
[9956fad9] | 213 | return rc;
|
---|
[e8039a86] | 214 |
|
---|
[b1e6269] | 215 | ops = sysipc_ops_get(answer->request_method);
|
---|
[e8039a86] | 216 | if (ops->answer_preprocess)
|
---|
| 217 | rc = ops->answer_preprocess(answer, olddata);
|
---|
[da1bafb] | 218 |
|
---|
[9956fad9] | 219 | return rc;
|
---|
[2d5a54f3] | 220 | }
|
---|
| 221 |
|
---|
[8b243f2] | 222 | /** Called before the request is sent.
|
---|
| 223 | *
|
---|
[da1bafb] | 224 | * @param call Call structure with the request.
|
---|
| 225 | * @param phone Phone that the call will be sent through.
|
---|
| 226 | *
|
---|
| 227 | * @return Return 0 on success, ELIMIT or EPERM on error.
|
---|
[7c7aae16] | 228 | *
|
---|
| 229 | */
|
---|
[9a1b20c] | 230 | static int request_preprocess(call_t *call, phone_t *phone)
|
---|
[7c7aae16] | 231 | {
|
---|
[924c2530] | 232 | int rc = EOK;
|
---|
| 233 |
|
---|
[32e4643] | 234 | call->request_method = IPC_GET_IMETHOD(call->data);
|
---|
| 235 |
|
---|
| 236 | sysipc_ops_t *ops = sysipc_ops_get(call->request_method);
|
---|
[e8039a86] | 237 | if (ops->request_preprocess)
|
---|
| 238 | rc = ops->request_preprocess(call, phone);
|
---|
[da1bafb] | 239 |
|
---|
[924c2530] | 240 | return rc;
|
---|
[7c7aae16] | 241 | }
|
---|
| 242 |
|
---|
[8b243f2] | 243 | /*******************************************************************************
|
---|
| 244 | * Functions called to process received call/answer before passing it to uspace.
|
---|
| 245 | *******************************************************************************/
|
---|
[2d5a54f3] | 246 |
|
---|
[8b243f2] | 247 | /** Do basic kernel processing of received call answer.
|
---|
| 248 | *
|
---|
[da1bafb] | 249 | * @param call Call structure with the answer.
|
---|
| 250 | *
|
---|
[8b243f2] | 251 | */
|
---|
[7c7aae16] | 252 | static void process_answer(call_t *call)
|
---|
[2d5a54f3] | 253 | {
|
---|
[6c441cf8] | 254 | if (((native_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
|
---|
[51ec40f] | 255 | (call->flags & IPC_CALL_FORWARDED))
|
---|
[9f22213] | 256 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
[da1bafb] | 257 |
|
---|
[32e4643] | 258 | sysipc_ops_t *ops = sysipc_ops_get(call->request_method);
|
---|
| 259 | if (ops->answer_process)
|
---|
| 260 | (void) ops->answer_process(call);
|
---|
[2d5a54f3] | 261 | }
|
---|
| 262 |
|
---|
[691d8d8] | 263 |
|
---|
[8b243f2] | 264 | /** Do basic kernel processing of received call request.
|
---|
| 265 | *
|
---|
[da1bafb] | 266 | * @param box Destination answerbox structure.
|
---|
| 267 | * @param call Call structure with the request.
|
---|
| 268 | *
|
---|
| 269 | * @return 0 if the call should be passed to userspace.
|
---|
| 270 | * @return -1 if the call should be ignored.
|
---|
[2d5a54f3] | 271 | *
|
---|
| 272 | */
|
---|
[51ec40f] | 273 | static int process_request(answerbox_t *box, call_t *call)
|
---|
[2d5a54f3] | 274 | {
|
---|
[691d8d8] | 275 | int rc = EOK;
|
---|
| 276 |
|
---|
[32e4643] | 277 | sysipc_ops_t *ops = sysipc_ops_get(call->request_method);
|
---|
[e8039a86] | 278 | if (ops->request_process)
|
---|
| 279 | rc = ops->request_process(call, box);
|
---|
[da1bafb] | 280 |
|
---|
[691d8d8] | 281 | return rc;
|
---|
[2d5a54f3] | 282 | }
|
---|
| 283 |
|
---|
[97d17fe] | 284 | /** Check that the task did not exceed the allowed limit of asynchronous calls
|
---|
| 285 | * made over a phone.
|
---|
[2d5a54f3] | 286 | *
|
---|
[228e490] | 287 | * @param phone Phone to check the limit against.
|
---|
| 288 | *
|
---|
[da1bafb] | 289 | * @return 0 if limit not reached or -1 if limit exceeded.
|
---|
| 290 | *
|
---|
[2d5a54f3] | 291 | */
|
---|
[97d17fe] | 292 | static int check_call_limit(phone_t *phone)
|
---|
[2d5a54f3] | 293 | {
|
---|
[97d17fe] | 294 | if (atomic_get(&phone->active_calls) >= IPC_MAX_ASYNC_CALLS)
|
---|
[2d5a54f3] | 295 | return -1;
|
---|
[da1bafb] | 296 |
|
---|
[2d5a54f3] | 297 | return 0;
|
---|
| 298 | }
|
---|
| 299 |
|
---|
[8b243f2] | 300 | /** Make a fast asynchronous call over IPC.
|
---|
[2d5a54f3] | 301 | *
|
---|
[3209923] | 302 | * This function can only handle four arguments of payload, but is faster than
|
---|
| 303 | * the generic function sys_ipc_call_async_slow().
|
---|
[8b243f2] | 304 | *
|
---|
[da1bafb] | 305 | * @param phoneid Phone handle for the call.
|
---|
[228e490] | 306 | * @param imethod Interface and method of the call.
|
---|
[da1bafb] | 307 | * @param arg1 Service-defined payload argument.
|
---|
| 308 | * @param arg2 Service-defined payload argument.
|
---|
| 309 | * @param arg3 Service-defined payload argument.
|
---|
| 310 | * @param arg4 Service-defined payload argument.
|
---|
| 311 | *
|
---|
| 312 | * @return Call hash on success.
|
---|
| 313 | * @return IPC_CALLRET_FATAL in case of a fatal error.
|
---|
| 314 | * @return IPC_CALLRET_TEMPORARY if there are too many pending
|
---|
| 315 | * asynchronous requests; answers should be handled first.
|
---|
| 316 | *
|
---|
[2d5a54f3] | 317 | */
|
---|
[228e490] | 318 | sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t imethod,
|
---|
[96b02eb9] | 319 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[2d5a54f3] | 320 | {
|
---|
[da1bafb] | 321 | phone_t *phone;
|
---|
[c9fff17] | 322 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 323 | return IPC_CALLRET_FATAL;
|
---|
[228e490] | 324 |
|
---|
[97d17fe] | 325 | if (check_call_limit(phone))
|
---|
| 326 | return IPC_CALLRET_TEMPORARY;
|
---|
[da1bafb] | 327 |
|
---|
| 328 | call_t *call = ipc_call_alloc(0);
|
---|
[228e490] | 329 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[2d5a54f3] | 330 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 331 | IPC_SET_ARG2(call->data, arg2);
|
---|
[3209923] | 332 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 333 | IPC_SET_ARG4(call->data, arg4);
|
---|
[da1bafb] | 334 |
|
---|
[8498915] | 335 | /*
|
---|
| 336 | * To achieve deterministic behavior, zero out arguments that are beyond
|
---|
| 337 | * the limits of the fast version.
|
---|
| 338 | */
|
---|
| 339 | IPC_SET_ARG5(call->data, 0);
|
---|
[da1bafb] | 340 |
|
---|
| 341 | int res = request_preprocess(call, phone);
|
---|
| 342 |
|
---|
| 343 | if (!res)
|
---|
[7c7aae16] | 344 | ipc_call(phone, call);
|
---|
| 345 | else
|
---|
| 346 | ipc_backsend_err(phone, call, res);
|
---|
[da1bafb] | 347 |
|
---|
[96b02eb9] | 348 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 349 | }
|
---|
| 350 |
|
---|
[8b243f2] | 351 | /** Make an asynchronous IPC call allowing to transmit the entire payload.
|
---|
| 352 | *
|
---|
[da1bafb] | 353 | * @param phoneid Phone handle for the call.
|
---|
| 354 | * @param data Userspace address of call data with the request.
|
---|
| 355 | *
|
---|
| 356 | * @return See sys_ipc_call_async_fast().
|
---|
[2d5a54f3] | 357 | *
|
---|
| 358 | */
|
---|
[96b02eb9] | 359 | sysarg_t sys_ipc_call_async_slow(sysarg_t phoneid, ipc_data_t *data)
|
---|
[2d5a54f3] | 360 | {
|
---|
[da1bafb] | 361 | phone_t *phone;
|
---|
[c9fff17] | 362 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 363 | return IPC_CALLRET_FATAL;
|
---|
[4e49572] | 364 |
|
---|
[97d17fe] | 365 | if (check_call_limit(phone))
|
---|
| 366 | return IPC_CALLRET_TEMPORARY;
|
---|
| 367 |
|
---|
[da1bafb] | 368 | call_t *call = ipc_call_alloc(0);
|
---|
| 369 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 370 | sizeof(call->data.args));
|
---|
[f58af46] | 371 | if (rc != 0) {
|
---|
| 372 | ipc_call_free(call);
|
---|
[96b02eb9] | 373 | return (sysarg_t) rc;
|
---|
[f58af46] | 374 | }
|
---|
[da1bafb] | 375 |
|
---|
| 376 | int res = request_preprocess(call, phone);
|
---|
| 377 |
|
---|
| 378 | if (!res)
|
---|
[7c7aae16] | 379 | ipc_call(phone, call);
|
---|
| 380 | else
|
---|
| 381 | ipc_backsend_err(phone, call, res);
|
---|
[da1bafb] | 382 |
|
---|
[96b02eb9] | 383 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 384 | }
|
---|
| 385 |
|
---|
[da1bafb] | 386 | /** Forward a received call to another destination
|
---|
| 387 | *
|
---|
| 388 | * Common code for both the fast and the slow version.
|
---|
| 389 | *
|
---|
| 390 | * @param callid Hash of the call to forward.
|
---|
| 391 | * @param phoneid Phone handle to use for forwarding.
|
---|
[228e490] | 392 | * @param imethod New interface and method to use for the forwarded call.
|
---|
[da1bafb] | 393 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 394 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 395 | * @param arg3 New value of the third argument for the forwarded call.
|
---|
| 396 | * @param arg4 New value of the fourth argument for the forwarded call.
|
---|
| 397 | * @param arg5 New value of the fifth argument for the forwarded call.
|
---|
| 398 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 399 | * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise
|
---|
| 400 | * the function considers only the fast version arguments:
|
---|
| 401 | * i.e. arg1 and arg2.
|
---|
| 402 | *
|
---|
| 403 | * @return 0 on succes, otherwise an error code.
|
---|
| 404 | *
|
---|
| 405 | * Warning: Make sure that ARG5 is not rewritten for certain system IPC
|
---|
| 406 | *
|
---|
[2ba7810] | 407 | */
|
---|
[96b02eb9] | 408 | static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phoneid,
|
---|
[228e490] | 409 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
|
---|
[96b02eb9] | 410 | sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
|
---|
[2ba7810] | 411 | {
|
---|
[da1bafb] | 412 | call_t *call = get_call(callid);
|
---|
[f9841e69] | 413 | phone_t *phone;
|
---|
| 414 | bool need_old = answer_need_old(call);
|
---|
| 415 | bool after_forward = false;
|
---|
| 416 | ipc_data_t old;
|
---|
[95a3082] | 417 | int rc;
|
---|
| 418 |
|
---|
[2ba7810] | 419 | if (!call)
|
---|
| 420 | return ENOENT;
|
---|
[f9841e69] | 421 |
|
---|
| 422 | if (need_old)
|
---|
| 423 | old = call->data;
|
---|
[48daf64] | 424 |
|
---|
[c9fff17] | 425 | if (phone_get(phoneid, &phone) != EOK) {
|
---|
[95a3082] | 426 | rc = ENOENT;
|
---|
| 427 | goto error;
|
---|
[c9fff17] | 428 | }
|
---|
[da1bafb] | 429 |
|
---|
[228e490] | 430 | if (!method_is_forwardable(IPC_GET_IMETHOD(call->data))) {
|
---|
[95a3082] | 431 | rc = EPERM;
|
---|
| 432 | goto error;
|
---|
[2ba7810] | 433 | }
|
---|
[95a3082] | 434 |
|
---|
| 435 | call->flags |= IPC_CALL_FORWARDED;
|
---|
[da1bafb] | 436 |
|
---|
[0dc4258] | 437 | /*
|
---|
[4e5dabf] | 438 | * User space is not allowed to change interface and method of system
|
---|
[228e490] | 439 | * methods on forward, allow changing ARG1, ARG2, ARG3 and ARG4 by
|
---|
[4e5dabf] | 440 | * means of imethod, arg1, arg2 and arg3.
|
---|
[228e490] | 441 | * If the interface and method is immutable, don't change anything.
|
---|
[2ba7810] | 442 | */
|
---|
[228e490] | 443 | if (!method_is_immutable(IPC_GET_IMETHOD(call->data))) {
|
---|
| 444 | if (method_is_system(IPC_GET_IMETHOD(call->data))) {
|
---|
| 445 | if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME)
|
---|
[b61d47d] | 446 | phone_dealloc(IPC_GET_ARG5(call->data));
|
---|
[da1bafb] | 447 |
|
---|
[228e490] | 448 | IPC_SET_ARG1(call->data, imethod);
|
---|
[0dc4258] | 449 | IPC_SET_ARG2(call->data, arg1);
|
---|
[b61d47d] | 450 | IPC_SET_ARG3(call->data, arg2);
|
---|
[da1bafb] | 451 |
|
---|
[4e5dabf] | 452 | if (slow)
|
---|
[48daf64] | 453 | IPC_SET_ARG4(call->data, arg3);
|
---|
[4e5dabf] | 454 |
|
---|
| 455 | /*
|
---|
| 456 | * For system methods we deliberately don't
|
---|
| 457 | * overwrite ARG5.
|
---|
| 458 | */
|
---|
[0dc4258] | 459 | } else {
|
---|
[228e490] | 460 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[0dc4258] | 461 | IPC_SET_ARG1(call->data, arg1);
|
---|
[b61d47d] | 462 | IPC_SET_ARG2(call->data, arg2);
|
---|
[48daf64] | 463 | if (slow) {
|
---|
| 464 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 465 | IPC_SET_ARG4(call->data, arg4);
|
---|
| 466 | IPC_SET_ARG5(call->data, arg5);
|
---|
| 467 | }
|
---|
[0dc4258] | 468 | }
|
---|
[2ba7810] | 469 | }
|
---|
[da1bafb] | 470 |
|
---|
[f9841e69] | 471 | rc = ipc_forward(call, phone, &TASK->answerbox, mode);
|
---|
| 472 | if (rc != EOK) {
|
---|
| 473 | after_forward = true;
|
---|
| 474 | goto error;
|
---|
| 475 | }
|
---|
[95a3082] | 476 |
|
---|
[f9841e69] | 477 | return EOK;
|
---|
[95a3082] | 478 |
|
---|
[f9841e69] | 479 | error:
|
---|
[fcfa926b] | 480 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
[9ef1b79b] | 481 | (void) answer_preprocess(call, need_old ? &old : NULL);
|
---|
[f9841e69] | 482 | if (after_forward)
|
---|
| 483 | _ipc_answer_free_call(call, false);
|
---|
| 484 | else
|
---|
| 485 | ipc_answer(&TASK->answerbox, call);
|
---|
| 486 |
|
---|
[95a3082] | 487 | return rc;
|
---|
[2ba7810] | 488 | }
|
---|
| 489 |
|
---|
[48daf64] | 490 | /** Forward a received call to another destination - fast version.
|
---|
| 491 | *
|
---|
[228e490] | 492 | * In case the original interface and method is a system method, ARG1, ARG2
|
---|
| 493 | * and ARG3 are overwritten in the forwarded message with the new method and
|
---|
| 494 | * the new arg1 and arg2, respectively. Otherwise the IMETHOD, ARG1 and ARG2
|
---|
| 495 | * are rewritten with the new interface and method, arg1 and arg2, respectively.
|
---|
| 496 | * Also note there is a set of immutable methods, for which the new method and
|
---|
| 497 | * arguments are not set and these values are ignored.
|
---|
[da1bafb] | 498 | *
|
---|
| 499 | * @param callid Hash of the call to forward.
|
---|
| 500 | * @param phoneid Phone handle to use for forwarding.
|
---|
[228e490] | 501 | * @param imethod New interface and method to use for the forwarded call.
|
---|
[da1bafb] | 502 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 503 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 504 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 505 | *
|
---|
| 506 | * @return 0 on succes, otherwise an error code.
|
---|
| 507 | *
|
---|
[48daf64] | 508 | */
|
---|
[96b02eb9] | 509 | sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
|
---|
[228e490] | 510 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
|
---|
[48daf64] | 511 | {
|
---|
[228e490] | 512 | return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
|
---|
[48daf64] | 513 | 0, mode, false);
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 | /** Forward a received call to another destination - slow version.
|
---|
| 517 | *
|
---|
| 518 | * This function is the slow verision of the sys_ipc_forward_fast interface.
|
---|
[228e490] | 519 | * It can copy all five new arguments and the new interface and method from
|
---|
| 520 | * the userspace. It naturally extends the functionality of the fast version.
|
---|
| 521 | * For system methods, it additionally stores the new value of arg3 to ARG4.
|
---|
| 522 | * For non-system methods, it additionally stores the new value of arg3, arg4
|
---|
| 523 | * and arg5, respectively, to ARG3, ARG4 and ARG5, respectively.
|
---|
[da1bafb] | 524 | *
|
---|
| 525 | * @param callid Hash of the call to forward.
|
---|
| 526 | * @param phoneid Phone handle to use for forwarding.
|
---|
| 527 | * @param data Userspace address of the new IPC data.
|
---|
| 528 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 529 | *
|
---|
| 530 | * @return 0 on succes, otherwise an error code.
|
---|
| 531 | *
|
---|
[48daf64] | 532 | */
|
---|
[96b02eb9] | 533 | sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
|
---|
[da1bafb] | 534 | ipc_data_t *data, unsigned int mode)
|
---|
[48daf64] | 535 | {
|
---|
| 536 | ipc_data_t newdata;
|
---|
[da1bafb] | 537 | int rc = copy_from_uspace(&newdata.args, &data->args,
|
---|
[48daf64] | 538 | sizeof(newdata.args));
|
---|
[da1bafb] | 539 | if (rc != 0)
|
---|
[96b02eb9] | 540 | return (sysarg_t) rc;
|
---|
[da1bafb] | 541 |
|
---|
[48daf64] | 542 | return sys_ipc_forward_common(callid, phoneid,
|
---|
[228e490] | 543 | IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
|
---|
[48daf64] | 544 | IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
|
---|
| 545 | IPC_GET_ARG4(newdata), IPC_GET_ARG5(newdata), mode, true);
|
---|
| 546 | }
|
---|
| 547 |
|
---|
[8b243f2] | 548 | /** Answer an IPC call - fast version.
|
---|
| 549 | *
|
---|
| 550 | * This function can handle only two return arguments of payload, but is faster
|
---|
| 551 | * than the generic sys_ipc_answer().
|
---|
| 552 | *
|
---|
[da1bafb] | 553 | * @param callid Hash of the call to be answered.
|
---|
| 554 | * @param retval Return value of the answer.
|
---|
| 555 | * @param arg1 Service-defined return value.
|
---|
| 556 | * @param arg2 Service-defined return value.
|
---|
| 557 | * @param arg3 Service-defined return value.
|
---|
| 558 | * @param arg4 Service-defined return value.
|
---|
| 559 | *
|
---|
| 560 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 561 | *
|
---|
| 562 | */
|
---|
[96b02eb9] | 563 | sysarg_t sys_ipc_answer_fast(sysarg_t callid, sysarg_t retval,
|
---|
| 564 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[2d5a54f3] | 565 | {
|
---|
[897f2e76] | 566 | /* Do not answer notification callids */
|
---|
| 567 | if (callid & IPC_CALLID_NOTIFICATION)
|
---|
| 568 | return 0;
|
---|
[da1bafb] | 569 |
|
---|
| 570 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 571 | if (!call)
|
---|
| 572 | return ENOENT;
|
---|
[da1bafb] | 573 |
|
---|
| 574 | ipc_data_t saved_data;
|
---|
| 575 | bool saved;
|
---|
| 576 |
|
---|
[9f22213] | 577 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 578 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 579 | saved = true;
|
---|
| 580 | } else
|
---|
| 581 | saved = false;
|
---|
| 582 |
|
---|
[2d5a54f3] | 583 | IPC_SET_RETVAL(call->data, retval);
|
---|
| 584 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 585 | IPC_SET_ARG2(call->data, arg2);
|
---|
[b74959bd] | 586 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 587 | IPC_SET_ARG4(call->data, arg4);
|
---|
[da1bafb] | 588 |
|
---|
[8498915] | 589 | /*
|
---|
| 590 | * To achieve deterministic behavior, zero out arguments that are beyond
|
---|
| 591 | * the limits of the fast version.
|
---|
| 592 | */
|
---|
| 593 | IPC_SET_ARG5(call->data, 0);
|
---|
[da1bafb] | 594 | int rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
| 595 |
|
---|
[2d5a54f3] | 596 | ipc_answer(&TASK->answerbox, call);
|
---|
[7c23af9] | 597 | return rc;
|
---|
[2d5a54f3] | 598 | }
|
---|
| 599 |
|
---|
[8b243f2] | 600 | /** Answer an IPC call.
|
---|
| 601 | *
|
---|
[da1bafb] | 602 | * @param callid Hash of the call to be answered.
|
---|
| 603 | * @param data Userspace address of call data with the answer.
|
---|
| 604 | *
|
---|
| 605 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 606 | *
|
---|
| 607 | */
|
---|
[96b02eb9] | 608 | sysarg_t sys_ipc_answer_slow(sysarg_t callid, ipc_data_t *data)
|
---|
[2d5a54f3] | 609 | {
|
---|
[897f2e76] | 610 | /* Do not answer notification callids */
|
---|
| 611 | if (callid & IPC_CALLID_NOTIFICATION)
|
---|
| 612 | return 0;
|
---|
[da1bafb] | 613 |
|
---|
| 614 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 615 | if (!call)
|
---|
| 616 | return ENOENT;
|
---|
[da1bafb] | 617 |
|
---|
| 618 | ipc_data_t saved_data;
|
---|
| 619 | bool saved;
|
---|
| 620 |
|
---|
[9f22213] | 621 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 622 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 623 | saved = true;
|
---|
| 624 | } else
|
---|
| 625 | saved = false;
|
---|
| 626 |
|
---|
| 627 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 628 | sizeof(call->data.args));
|
---|
[e3c762cd] | 629 | if (rc != 0)
|
---|
| 630 | return rc;
|
---|
[da1bafb] | 631 |
|
---|
| 632 | rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[2d5a54f3] | 633 |
|
---|
| 634 | ipc_answer(&TASK->answerbox, call);
|
---|
[7c23af9] | 635 | return rc;
|
---|
[2d5a54f3] | 636 | }
|
---|
| 637 |
|
---|
[8b243f2] | 638 | /** Hang up a phone.
|
---|
[2d5a54f3] | 639 | *
|
---|
[da1bafb] | 640 | * @param Phone handle of the phone to be hung up.
|
---|
| 641 | *
|
---|
| 642 | * @return 0 on success or an error code.
|
---|
[8b243f2] | 643 | *
|
---|
[fbcfd458] | 644 | */
|
---|
[96b02eb9] | 645 | sysarg_t sys_ipc_hangup(sysarg_t phoneid)
|
---|
[fbcfd458] | 646 | {
|
---|
| 647 | phone_t *phone;
|
---|
[da1bafb] | 648 |
|
---|
[c9fff17] | 649 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 650 | return ENOENT;
|
---|
[da1bafb] | 651 |
|
---|
[d8f7362] | 652 | if (ipc_phone_hangup(phone))
|
---|
[fbcfd458] | 653 | return -1;
|
---|
[da1bafb] | 654 |
|
---|
[fbcfd458] | 655 | return 0;
|
---|
| 656 | }
|
---|
| 657 |
|
---|
[8b243f2] | 658 | /** Wait for an incoming IPC call or an answer.
|
---|
[fbcfd458] | 659 | *
|
---|
[da1bafb] | 660 | * @param calldata Pointer to buffer where the call/answer data is stored.
|
---|
| 661 | * @param usec Timeout. See waitq_sleep_timeout() for explanation.
|
---|
| 662 | * @param flags Select mode of sleep operation. See waitq_sleep_timeout()
|
---|
| 663 | * for explanation.
|
---|
| 664 | *
|
---|
| 665 | * @return Hash of the call.
|
---|
| 666 | * If IPC_CALLID_NOTIFICATION bit is set in the hash, the
|
---|
| 667 | * call is a notification. IPC_CALLID_ANSWERED denotes an
|
---|
| 668 | * answer.
|
---|
[bd5a663] | 669 | *
|
---|
[2d5a54f3] | 670 | */
|
---|
[96b02eb9] | 671 | sysarg_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
|
---|
[da1bafb] | 672 | unsigned int flags)
|
---|
[2d5a54f3] | 673 | {
|
---|
| 674 | call_t *call;
|
---|
[da1bafb] | 675 |
|
---|
[741fd16] | 676 | restart:
|
---|
[da1bafb] | 677 |
|
---|
[741fd16] | 678 | #ifdef CONFIG_UDEBUG
|
---|
| 679 | udebug_stoppable_begin();
|
---|
[da1bafb] | 680 | #endif
|
---|
| 681 |
|
---|
[51ec40f] | 682 | call = ipc_wait_for_call(&TASK->answerbox, usec,
|
---|
| 683 | flags | SYNCH_FLAGS_INTERRUPTIBLE);
|
---|
[da1bafb] | 684 |
|
---|
[741fd16] | 685 | #ifdef CONFIG_UDEBUG
|
---|
| 686 | udebug_stoppable_end();
|
---|
| 687 | #endif
|
---|
[da1bafb] | 688 |
|
---|
[9f22213] | 689 | if (!call)
|
---|
| 690 | return 0;
|
---|
[da1bafb] | 691 |
|
---|
[5626277] | 692 | if (call->flags & IPC_CALL_NOTIF) {
|
---|
[43752b6] | 693 | /* Set in_phone_hash to the interrupt counter */
|
---|
[0c1a5d8a] | 694 | call->data.phone = (void *) call->priv;
|
---|
[43752b6] | 695 |
|
---|
| 696 | STRUCT_TO_USPACE(calldata, &call->data);
|
---|
[da1bafb] | 697 |
|
---|
[5626277] | 698 | ipc_call_free(call);
|
---|
| 699 |
|
---|
[96b02eb9] | 700 | return ((sysarg_t) call) | IPC_CALLID_NOTIFICATION;
|
---|
[5626277] | 701 | }
|
---|
[da1bafb] | 702 |
|
---|
[2d5a54f3] | 703 | if (call->flags & IPC_CALL_ANSWERED) {
|
---|
[7c7aae16] | 704 | process_answer(call);
|
---|
[da1bafb] | 705 |
|
---|
[fbcfd458] | 706 | if (call->flags & IPC_CALL_DISCARD_ANSWER) {
|
---|
| 707 | ipc_call_free(call);
|
---|
| 708 | goto restart;
|
---|
| 709 | }
|
---|
[da1bafb] | 710 |
|
---|
[fbcfd458] | 711 | STRUCT_TO_USPACE(&calldata->args, &call->data.args);
|
---|
[2d5a54f3] | 712 | ipc_call_free(call);
|
---|
[da1bafb] | 713 |
|
---|
[96b02eb9] | 714 | return ((sysarg_t) call) | IPC_CALLID_ANSWERED;
|
---|
[2d5a54f3] | 715 | }
|
---|
[da1bafb] | 716 |
|
---|
[2d5a54f3] | 717 | if (process_request(&TASK->answerbox, call))
|
---|
| 718 | goto restart;
|
---|
[da1bafb] | 719 |
|
---|
[7c7aae16] | 720 | /* Include phone address('id') of the caller in the request,
|
---|
| 721 | * copy whole call->data, not only call->data.args */
|
---|
[bd55bbb] | 722 | if (STRUCT_TO_USPACE(calldata, &call->data)) {
|
---|
[e06da7e] | 723 | /*
|
---|
| 724 | * The callee will not receive this call and no one else has
|
---|
| 725 | * a chance to answer it. Reply with the EPARTY error code.
|
---|
[b11ee88] | 726 | */
|
---|
[e06da7e] | 727 | ipc_data_t saved_data;
|
---|
[da1bafb] | 728 | bool saved;
|
---|
| 729 |
|
---|
[e06da7e] | 730 | if (answer_need_old(call)) {
|
---|
| 731 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 732 | saved = true;
|
---|
| 733 | } else
|
---|
| 734 | saved = false;
|
---|
[e06da7e] | 735 |
|
---|
| 736 | IPC_SET_RETVAL(call->data, EPARTY);
|
---|
[da1bafb] | 737 | (void) answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[e06da7e] | 738 | ipc_answer(&TASK->answerbox, call);
|
---|
[bd55bbb] | 739 | return 0;
|
---|
| 740 | }
|
---|
[da1bafb] | 741 |
|
---|
[96b02eb9] | 742 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 743 | }
|
---|
[5626277] | 744 |
|
---|
[da1bafb] | 745 | /** Interrupt one thread from sys_ipc_wait_for_call().
|
---|
| 746 | *
|
---|
| 747 | */
|
---|
[96b02eb9] | 748 | sysarg_t sys_ipc_poke(void)
|
---|
[057d21a] | 749 | {
|
---|
[da1bafb] | 750 | waitq_unsleep(&TASK->answerbox.wq);
|
---|
[057d21a] | 751 | return EOK;
|
---|
| 752 | }
|
---|
| 753 |
|
---|
[8b243f2] | 754 | /** Connect an IRQ handler to a task.
|
---|
[2b017ba] | 755 | *
|
---|
[228e490] | 756 | * @param inr IRQ number.
|
---|
| 757 | * @param devno Device number.
|
---|
| 758 | * @param imethod Interface and method to be associated with the notification.
|
---|
| 759 | * @param ucode Uspace pointer to the top-half pseudocode.
|
---|
[da1bafb] | 760 | *
|
---|
| 761 | * @return EPERM or a return code returned by ipc_irq_register().
|
---|
[2b017ba] | 762 | *
|
---|
| 763 | */
|
---|
[f044e96] | 764 | sysarg_t sys_irq_register(inr_t inr, devno_t devno, sysarg_t imethod,
|
---|
[51ec40f] | 765 | irq_code_t *ucode)
|
---|
[5626277] | 766 | {
|
---|
[2bb8648] | 767 | if (!(cap_get(TASK) & CAP_IRQ_REG))
|
---|
| 768 | return EPERM;
|
---|
[da1bafb] | 769 |
|
---|
[228e490] | 770 | return ipc_irq_register(&TASK->answerbox, inr, devno, imethod, ucode);
|
---|
[5626277] | 771 | }
|
---|
| 772 |
|
---|
[8b243f2] | 773 | /** Disconnect an IRQ handler from a task.
|
---|
| 774 | *
|
---|
[da1bafb] | 775 | * @param inr IRQ number.
|
---|
| 776 | * @param devno Device number.
|
---|
| 777 | *
|
---|
| 778 | * @return Zero on success or EPERM on error.
|
---|
[2b017ba] | 779 | *
|
---|
| 780 | */
|
---|
[f044e96] | 781 | sysarg_t sys_irq_unregister(inr_t inr, devno_t devno)
|
---|
[5626277] | 782 | {
|
---|
[2bb8648] | 783 | if (!(cap_get(TASK) & CAP_IRQ_REG))
|
---|
| 784 | return EPERM;
|
---|
[da1bafb] | 785 |
|
---|
[2b017ba] | 786 | ipc_irq_unregister(&TASK->answerbox, inr, devno);
|
---|
[da1bafb] | 787 |
|
---|
[5626277] | 788 | return 0;
|
---|
| 789 | }
|
---|
[b45c443] | 790 |
|
---|
[6b10dab] | 791 | #ifdef __32_BITS__
|
---|
[9a1b20c] | 792 |
|
---|
[6b10dab] | 793 | /** Syscall connect to a task by ID (32 bits)
|
---|
[da1bafb] | 794 | *
|
---|
| 795 | * @return Phone id on success, or negative error code.
|
---|
[9a1b20c] | 796 | *
|
---|
| 797 | */
|
---|
[6b10dab] | 798 | sysarg_t sys_ipc_connect_kbox(sysarg64_t *uspace_taskid)
|
---|
[9a1b20c] | 799 | {
|
---|
| 800 | #ifdef CONFIG_UDEBUG
|
---|
[6b10dab] | 801 | sysarg64_t taskid;
|
---|
| 802 | int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
|
---|
[9a1b20c] | 803 | if (rc != 0)
|
---|
[96b02eb9] | 804 | return (sysarg_t) rc;
|
---|
[da1bafb] | 805 |
|
---|
[6b10dab] | 806 | return ipc_connect_kbox((task_id_t) taskid);
|
---|
[9a1b20c] | 807 | #else
|
---|
[96b02eb9] | 808 | return (sysarg_t) ENOTSUP;
|
---|
[9a1b20c] | 809 | #endif
|
---|
| 810 | }
|
---|
| 811 |
|
---|
[6b10dab] | 812 | #endif /* __32_BITS__ */
|
---|
| 813 |
|
---|
| 814 | #ifdef __64_BITS__
|
---|
| 815 |
|
---|
| 816 | /** Syscall connect to a task by ID (64 bits)
|
---|
| 817 | *
|
---|
| 818 | * @return Phone id on success, or negative error code.
|
---|
| 819 | *
|
---|
| 820 | */
|
---|
| 821 | sysarg_t sys_ipc_connect_kbox(sysarg_t taskid)
|
---|
| 822 | {
|
---|
| 823 | #ifdef CONFIG_UDEBUG
|
---|
| 824 | return ipc_connect_kbox((task_id_t) taskid);
|
---|
| 825 | #else
|
---|
| 826 | return (sysarg_t) ENOTSUP;
|
---|
| 827 | #endif
|
---|
| 828 | }
|
---|
| 829 |
|
---|
| 830 | #endif /* __64_BITS__ */
|
---|
| 831 |
|
---|
[cc73a8a1] | 832 | /** @}
|
---|
[b45c443] | 833 | */
|
---|