source: mainline/uspace/srv/ns/clonable.c@ ccf7a7e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ccf7a7e was 984a9ba, checked in by Martin Decky <martin@…>, 7 years ago

do not expose the call capability handler from the async framework

Keep the call capability handler encapsulated within the async framework
and do not expose it explicitly via its API. Use the pointer to
ipc_call_t as the sole object identifying an IPC call in the code that
uses the async framework.

This plugs a major leak in the abstraction and also simplifies both the
async framework (slightly) and all IPC servers.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2009 Martin Decky
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
29/** @addtogroup ns
30 * @{
31 */
32
33#include <async.h>
34#include <ipc/services.h>
35#include <adt/list.h>
36#include <stdbool.h>
37#include <errno.h>
38#include <assert.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <loader/loader.h>
42#include "clonable.h"
43#include "ns.h"
44
45/** Request for connection to a clonable service. */
46typedef struct {
47 link_t link;
48 service_t service;
49 iface_t iface;
50 ipc_call_t call;
51} cs_req_t;
52
53/** List of clonable-service connection requests. */
54static list_t cs_req;
55
56errno_t clonable_init(void)
57{
58 list_initialize(&cs_req);
59 return EOK;
60}
61
62/** Return true if @a service is clonable. */
63bool service_clonable(service_t service)
64{
65 return (service == SERVICE_LOADER);
66}
67
68/** Register clonable service.
69 *
70 * @param service Service to be registered.
71 * @param phone Phone to be used for connections to the service.
72 * @param call Pointer to call structure.
73 *
74 */
75void register_clonable(service_t service, sysarg_t phone, ipc_call_t *call)
76{
77 link_t *req_link = list_first(&cs_req);
78 if (req_link == NULL) {
79 /* There was no pending connection request. */
80 printf("%s: Unexpected clonable server.\n", NAME);
81 async_answer_0(call, EBUSY);
82 return;
83 }
84
85 cs_req_t *csr = list_get_instance(req_link, cs_req_t, link);
86 list_remove(req_link);
87
88 /* Currently we can only handle a single type of clonable service. */
89 assert(csr->service == SERVICE_LOADER);
90
91 async_answer_0(call, EOK);
92
93 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
94 if (sess == NULL)
95 async_answer_0(call, EIO);
96
97 async_exch_t *exch = async_exchange_begin(sess);
98 async_forward_fast(&csr->call, exch, csr->iface,
99 IPC_GET_ARG3(csr->call), 0, IPC_FF_NONE);
100 async_exchange_end(exch);
101
102 free(csr);
103 async_hangup(sess);
104}
105
106/** Connect client to clonable service.
107 *
108 * @param service Service to be connected to.
109 * @param iface Interface to be connected to.
110 * @param call Pointer to call structure.
111 *
112 * @return Zero on success or a value from @ref errno.h.
113 *
114 */
115void connect_to_clonable(service_t service, iface_t iface, ipc_call_t *call)
116{
117 assert(service == SERVICE_LOADER);
118
119 cs_req_t *csr = malloc(sizeof(cs_req_t));
120 if (csr == NULL) {
121 async_answer_0(call, ENOMEM);
122 return;
123 }
124
125 /* Spawn a loader. */
126 errno_t rc = loader_spawn("loader");
127
128 if (rc != EOK) {
129 free(csr);
130 async_answer_0(call, rc);
131 return;
132 }
133
134 link_initialize(&csr->link);
135 csr->service = service;
136 csr->iface = iface;
137 csr->call = *call;
138
139 /*
140 * We can forward the call only after the server we spawned connects
141 * to us. Meanwhile we might need to service more connection requests.
142 * Thus we store the call in a queue.
143 */
144 list_append(&csr->link, &cs_req);
145}
146
147/**
148 * @}
149 */
Note: See TracBrowser for help on using the repository browser.