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
RevLine 
[007e6efa]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
[79ae36dd]35#include <ns.h>
[007e6efa]36#include <ipc/ns.h>
[79ae36dd]37#include <async.h>
38#include <macros.h>
[b1bd89ea]39#include <errno.h>
[012dd8e]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}
[007e6efa]60
[7b616e2]61/*
[0a8f070]62 * XXX ns does not know about session_primary, so we create an extra session for
[7b616e2]63 * actual communicaton
64 */
[0a8f070]65static async_sess_t *sess_primary = NULL;
[7b616e2]66
[9b1baac]67errno_t service_register(service_t service, iface_t iface,
68 async_port_handler_t handler, void *data)
[007e6efa]69{
[9b1baac]70 port_id_t port;
71 errno_t rc = async_create_port(iface, handler, data, &port);
72 if (rc != EOK)
73 return rc;
74
[012dd8e]75 async_exch_t *exch = ns_exchange_begin();
[9b1baac]76
[7b616e2]77 ipc_call_t answer;
[9b1baac]78 aid_t req = async_send_2(exch, NS_REGISTER, service, iface, &answer);
79 rc = async_connect_to_me(exch, iface, service, 0);
80
[012dd8e]81 ns_exchange_end(exch);
[9b1baac]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);
[a35b458]97
[0a8f070]98 async_sess_t *sess = get_session_primary();
[7b616e2]99 if (sess == NULL)
100 return EIO;
[a35b458]101
[7b616e2]102 async_exch_t *exch = async_exchange_begin(sess);
[9b1baac]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);
[a35b458]107
[79ae36dd]108 async_exchange_end(exch);
[a35b458]109
[7b616e2]110 if (rc != EOK) {
111 async_forget(req);
112 return rc;
113 }
[a35b458]114
[9b1baac]115 errno_t retval;
[7b616e2]116 async_wait_for(req, &retval);
[79ae36dd]117 return rc;
118}
119
[f9b2cb4c]120async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
[0dd16778]121{
[012dd8e]122 async_exch_t *exch = ns_exchange_begin();
[7b616e2]123 if (exch == NULL)
[0dd16778]124 return NULL;
[a35b458]125
[012dd8e]126 async_sess_t *sess =
[914c693]127 async_connect_me_to(exch, iface, service, arg3);
[012dd8e]128 ns_exchange_end(exch);
[a35b458]129
[012dd8e]130 if (sess == NULL)
[0dd16778]131 return NULL;
[a35b458]132
[0dd16778]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 */
[012dd8e]138 async_sess_args_set(sess, iface, arg3, 0);
[a35b458]139
[7b616e2]140 return csess;
[0dd16778]141}
142
[f9b2cb4c]143async_sess_t *service_connect_blocking(service_t service, iface_t iface,
144 sysarg_t arg3)
[566992e1]145{
[012dd8e]146 async_exch_t *exch = ns_exchange_begin();
147 async_sess_t *sess =
[914c693]148 async_connect_me_to_blocking(exch, iface, service, arg3);
[012dd8e]149 ns_exchange_end(exch);
[a35b458]150
[012dd8e]151 if (sess == NULL)
[566992e1]152 return NULL;
[a35b458]153
[566992e1]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 */
[012dd8e]159 async_sess_args_set(sess, iface, arg3, 0);
[a35b458]160
[012dd8e]161 return sess;
[566992e1]162}
163
[b7fd2a0]164errno_t ns_ping(void)
[007e6efa]165{
[012dd8e]166 async_exch_t *exch = ns_exchange_begin(sess);
[b7fd2a0]167 errno_t rc = async_req_0_0(exch, NS_PING);
[012dd8e]168 ns_exchange_end(exch);
[a35b458]169
[79ae36dd]170 return rc;
[007e6efa]171}
172
173/** @}
174 */
Note: See TracBrowser for help on using the repository browser.