source: mainline/kernel/generic/src/ipc/ops/conctmeto.c

Last change on this file was fafb8e5, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Mechanically lowercase IPC_SET_*/IPC_GET_*

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
3 * Copyright (c) 2012 Jakub Jermar
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup kernel_generic_ipc
31 * @{
32 */
33/** @file
34 */
35
36#include <ipc/sysipc_ops.h>
37#include <ipc/ipc.h>
38#include <ipc/ipcrsc.h>
39#include <abi/errno.h>
40#include <arch.h>
41
42static errno_t request_preprocess(call_t *call, phone_t *phone)
43{
44 /*
45 * Create the new phone and capability, but don't publish them yet.
46 * That will be done once the phone is connected.
47 */
48 cap_phone_handle_t phandle;
49 kobject_t *pobj;
50 errno_t rc = phone_alloc(TASK, false, &phandle, &pobj);
51 if (rc != EOK) {
52 call->priv = 0;
53 return rc;
54 }
55
56 /* Move pobj's reference to call->priv */
57 call->priv = (sysarg_t) pobj;
58 pobj = NULL;
59
60 /* Remember the handle */
61 ipc_set_arg5(&call->data, (sysarg_t) phandle);
62
63 return EOK;
64}
65
66static errno_t request_forget(call_t *call)
67{
68 cap_phone_handle_t phandle = (cap_handle_t) ipc_get_arg5(&call->data);
69
70 if (cap_handle_raw(phandle) < 0)
71 return EOK;
72
73 /* Move reference from call->priv to pobj */
74 kobject_t *pobj = (kobject_t *) call->priv;
75 call->priv = 0;
76 /* Drop pobj's reference */
77 kobject_put(pobj);
78 cap_free(TASK, phandle);
79
80 return EOK;
81}
82
83static errno_t answer_preprocess(call_t *answer, ipc_data_t *olddata)
84{
85 /* Get an extra reference for phone */
86 kobject_t *pobj = (kobject_t *) answer->priv;
87 kobject_add_ref(pobj);
88
89 /* Set the recipient-assigned label */
90 pobj->phone->label = ipc_get_arg5(&answer->data);
91
92 /* Restore phone handle in answer's ARG5 */
93 ipc_set_arg5(&answer->data, ipc_get_arg5(olddata));
94
95 /* If the user accepted the call, connect */
96 if (ipc_get_retval(&answer->data) == EOK) {
97 /* Hand over reference from pobj to the answerbox */
98 (void) ipc_phone_connect(pobj->phone, &TASK->answerbox);
99 } else {
100 /* Drop the extra reference */
101 kobject_put(pobj);
102 }
103
104 return EOK;
105}
106
107static errno_t answer_process(call_t *answer)
108{
109 cap_phone_handle_t phandle = (cap_handle_t) ipc_get_arg5(&answer->data);
110 /* Move the reference from answer->priv to pobj */
111 kobject_t *pobj = (kobject_t *) answer->priv;
112 answer->priv = 0;
113
114 if (ipc_get_retval(&answer->data)) {
115 if (cap_handle_raw(phandle) >= 0) {
116 /*
117 * Cleanup the unpublished capability and drop
118 * phone->kobject's reference.
119 */
120 kobject_put(pobj);
121 cap_free(TASK, phandle);
122 }
123 } else {
124 /*
125 * Publish the capability. Publishing the capability this late
126 * is important for ipc_cleanup() where we want to have a
127 * capability for each phone that wasn't hung up by the user.
128 */
129 cap_publish(TASK, phandle, pobj);
130 }
131
132 return EOK;
133}
134
135sysipc_ops_t ipc_m_connect_me_to_ops = {
136 .request_preprocess = request_preprocess,
137 .request_forget = request_forget,
138 .request_process = null_request_process,
139 .answer_cleanup = null_answer_cleanup,
140 .answer_preprocess = answer_preprocess,
141 .answer_process = answer_process,
142};
143
144/** @}
145 */
Note: See TracBrowser for help on using the repository browser.