source: mainline/uspace/lib/c/generic/ns.c@ 012dd8e

Last change on this file since 012dd8e was 012dd8e, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

taskman: Handle INIT_TASKS as tasks spawned by loader

  • everyone is connected to its spawner, except for INIT_TASKS, they are connected to taskman (first binary)
  • taskman is now aware even of INIT_TASKS and taskman itself
  • refactored taskman handshake — NS session is created lazily
  • refactored async.c with usage of create_session
  • changed EINVAL to EINTR on lost waits
  • removed TODOs from taskman and related libc TODOs

Conflicts:

abi/include/abi/ipc/methods.h
boot/Makefile.common
uspace/lib/c/generic/async.c
uspace/lib/c/generic/libc.c
uspace/lib/c/generic/loader.c
uspace/lib/c/generic/ns.c
uspace/lib/c/generic/private/async.h
uspace/lib/c/generic/private/taskman.h
uspace/lib/c/generic/task.c
uspace/lib/c/include/async.h
uspace/lib/c/include/task.h
uspace/srv/loader/main.c
uspace/srv/ns/ns.c

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 2011 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 libc
30 * @{
31 */
32/** @file
33 */
34
35#include <ns.h>
36#include <ipc/ns.h>
37#include <async.h>
38#include <macros.h>
39#include <errno.h>
40
41#include "private/taskman.h"
42
43static async_sess_t *session_ns = NULL;
44
45static async_exch_t *ns_exchange_begin(void)
46{
47 /* Lazily connect to our NS */
48 if (session_ns == NULL) {
49 session_ns = taskman_session_ns();
50 }
51
52 async_exch_t *exch = async_exchange_begin(session_ns);
53 return exch;
54}
55
56static void ns_exchange_end(async_exch_t *exch)
57{
58 async_exchange_end(exch);
59}
60
61/*
62 * XXX ns does not know about session_primary, so we create an extra session for
63 * actual communicaton
64 */
65static async_sess_t *sess_primary = NULL;
66
67errno_t service_register(service_t service, iface_t iface,
68 async_port_handler_t handler, void *data)
69{
70 port_id_t port;
71 errno_t rc = async_create_port(iface, handler, data, &port);
72 if (rc != EOK)
73 return rc;
74
75 async_exch_t *exch = ns_exchange_begin();
76
77 ipc_call_t answer;
78 aid_t req = async_send_2(exch, NS_REGISTER, service, iface, &answer);
79 rc = async_connect_to_me(exch, iface, service, 0);
80
81 ns_exchange_end(exch);
82
83 if (rc != EOK) {
84 async_forget(req);
85 return rc;
86 }
87
88 errno_t retval;
89 async_wait_for(req, &retval);
90 return rc;
91}
92
93errno_t service_register_broker(service_t service, async_port_handler_t handler,
94 void *data)
95{
96 async_set_fallback_port_handler(handler, data);
97
98 async_sess_t *sess = get_session_primary();
99 if (sess == NULL)
100 return EIO;
101
102 async_exch_t *exch = async_exchange_begin(sess);
103
104 ipc_call_t answer;
105 aid_t req = async_send_1(exch, NS_REGISTER_BROKER, service, &answer);
106 errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, service, 0);
107
108 async_exchange_end(exch);
109
110 if (rc != EOK) {
111 async_forget(req);
112 return rc;
113 }
114
115 errno_t retval;
116 async_wait_for(req, &retval);
117 return rc;
118}
119
120async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
121{
122 async_exch_t *exch = ns_exchange_begin();
123 if (exch == NULL)
124 return NULL;
125
126 async_sess_t *sess =
127 async_connect_me_to(exch, iface, service, arg3);
128 ns_exchange_end(exch);
129
130 if (sess == NULL)
131 return NULL;
132
133 /*
134 * FIXME Ugly hack to work around limitation of implementing
135 * parallel exchanges using multiple connections. Shift out
136 * first argument for non-initial connections.
137 */
138 async_sess_args_set(sess, iface, arg3, 0);
139
140 return csess;
141}
142
143async_sess_t *service_connect_blocking(service_t service, iface_t iface,
144 sysarg_t arg3)
145{
146 async_exch_t *exch = ns_exchange_begin();
147 async_sess_t *sess =
148 async_connect_me_to_blocking(exch, iface, service, arg3);
149 ns_exchange_end(exch);
150
151 if (sess == NULL)
152 return NULL;
153
154 /*
155 * FIXME Ugly hack to work around limitation of implementing
156 * parallel exchanges using multiple connections. Shift out
157 * first argument for non-initial connections.
158 */
159 async_sess_args_set(sess, iface, arg3, 0);
160
161 return sess;
162}
163
164errno_t ns_ping(void)
165{
166 async_exch_t *exch = ns_exchange_begin(sess);
167 errno_t rc = async_req_0_0(exch, NS_PING);
168 ns_exchange_end(exch);
169
170 return rc;
171}
172
173/** @}
174 */
Note: See TracBrowser for help on using the repository browser.