Rev 4263 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1335 | jermar | 1 | /* |
2071 | jermar | 2 | * Copyright (c) 2006 Ondrej Palkovsky |
1335 | jermar | 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 | |||
1740 | jermar | 29 | /** @addtogroup ns |
1649 | cejka | 30 | * @{ |
4153 | mejdrech | 31 | */ |
1649 | cejka | 32 | |
1335 | jermar | 33 | /** |
4153 | mejdrech | 34 | * @file ns.c |
35 | * @brief Naming service for HelenOS IPC. |
||
1335 | jermar | 36 | */ |
37 | |||
1353 | jermar | 38 | #include <ipc/ipc.h> |
4581 | mejdrech | 39 | #include <ipc/services.h> |
1353 | jermar | 40 | #include <ipc/ns.h> |
4581 | mejdrech | 41 | #include <unistd.h> |
1030 | palkovsky | 42 | #include <stdio.h> |
43 | #include <errno.h> |
||
4581 | mejdrech | 44 | #include <as.h> |
45 | #include <ddi.h> |
||
46 | #include <event.h> |
||
47 | #include <macros.h> |
||
1435 | palkovsky | 48 | #include <sysinfo.h> |
4581 | mejdrech | 49 | #include "ns.h" |
50 | #include "service.h" |
||
51 | #include "clonable.h" |
||
52 | #include "task.h" |
||
1335 | jermar | 53 | |
1596 | palkovsky | 54 | static void *clockaddr = NULL; |
55 | static void *klogaddr = NULL; |
||
56 | |||
4581 | mejdrech | 57 | static void get_as_area(ipc_callid_t callid, ipc_call_t *call, void *ph_addr, |
58 | size_t pages, void **addr) |
||
1435 | palkovsky | 59 | { |
4263 | mejdrech | 60 | if (ph_addr == NULL) { |
61 | ipc_answer_0(callid, ENOENT); |
||
62 | return; |
||
63 | } |
||
4153 | mejdrech | 64 | |
4263 | mejdrech | 65 | if (*addr == NULL) { |
66 | *addr = as_get_mappable_page(pages * PAGE_SIZE); |
||
67 | |||
68 | if (*addr == NULL) { |
||
2619 | jermar | 69 | ipc_answer_0(callid, ENOENT); |
1435 | palkovsky | 70 | return; |
71 | } |
||
4263 | mejdrech | 72 | |
73 | if (physmem_map(ph_addr, *addr, pages, |
||
4153 | mejdrech | 74 | AS_AREA_READ | AS_AREA_CACHEABLE) != 0) { |
75 | ipc_answer_0(callid, ENOENT); |
||
76 | return; |
||
77 | } |
||
1435 | palkovsky | 78 | } |
4263 | mejdrech | 79 | |
2619 | jermar | 80 | ipc_answer_2(callid, EOK, (ipcarg_t) *addr, AS_AREA_READ); |
1435 | palkovsky | 81 | } |
82 | |||
1030 | palkovsky | 83 | int main(int argc, char **argv) |
84 | { |
||
3083 | decky | 85 | printf(NAME ": HelenOS IPC Naming Service\n"); |
86 | |||
4581 | mejdrech | 87 | int rc = service_init(); |
88 | if (rc != EOK) |
||
89 | return rc; |
||
3083 | decky | 90 | |
4581 | mejdrech | 91 | rc = clonable_init(); |
92 | if (rc != EOK) |
||
93 | return rc; |
||
4153 | mejdrech | 94 | |
4581 | mejdrech | 95 | rc = task_init(); |
96 | if (rc != EOK) |
||
97 | return rc; |
||
98 | |||
3083 | decky | 99 | printf(NAME ": Accepting connections\n"); |
4581 | mejdrech | 100 | |
4153 | mejdrech | 101 | while (true) { |
4581 | mejdrech | 102 | process_pending_conn(); |
103 | process_pending_wait(); |
||
4153 | mejdrech | 104 | |
105 | ipc_call_t call; |
||
106 | ipc_callid_t callid = ipc_wait_for_call(&call); |
||
4581 | mejdrech | 107 | |
108 | task_id_t id; |
||
4153 | mejdrech | 109 | ipcarg_t retval; |
110 | |||
4581 | mejdrech | 111 | if (callid & IPC_CALLID_NOTIFICATION) { |
112 | id = (task_id_t) |
||
113 | MERGE_LOUP32(IPC_GET_ARG2(call), IPC_GET_ARG3(call)); |
||
114 | wait_notification((wait_type_t) IPC_GET_ARG1(call), id); |
||
115 | continue; |
||
116 | } |
||
117 | |||
1091 | palkovsky | 118 | switch (IPC_GET_METHOD(call)) { |
2677 | jermar | 119 | case IPC_M_SHARE_IN: |
1596 | palkovsky | 120 | switch (IPC_GET_ARG3(call)) { |
121 | case SERVICE_MEM_REALTIME: |
||
4581 | mejdrech | 122 | get_as_area(callid, &call, |
123 | (void *) sysinfo_value("clock.faddr"), |
||
124 | 1, &clockaddr); |
||
1596 | palkovsky | 125 | break; |
126 | case SERVICE_MEM_KLOG: |
||
4581 | mejdrech | 127 | get_as_area(callid, &call, |
128 | (void *) sysinfo_value("klog.faddr"), |
||
129 | sysinfo_value("klog.pages"), &klogaddr); |
||
1596 | palkovsky | 130 | break; |
131 | default: |
||
2619 | jermar | 132 | ipc_answer_0(callid, ENOENT); |
1596 | palkovsky | 133 | } |
1435 | palkovsky | 134 | continue; |
1089 | palkovsky | 135 | case IPC_M_PHONE_HUNGUP: |
2588 | jermar | 136 | retval = EOK; |
1089 | palkovsky | 137 | break; |
1336 | jermar | 138 | case IPC_M_CONNECT_TO_ME: |
1335 | jermar | 139 | /* |
1336 | jermar | 140 | * Server requests service registration. |
1335 | jermar | 141 | */ |
4153 | mejdrech | 142 | if (service_clonable(IPC_GET_ARG1(call))) { |
143 | register_clonable(IPC_GET_ARG1(call), |
||
144 | IPC_GET_ARG5(call), &call, callid); |
||
145 | continue; |
||
146 | } else { |
||
147 | retval = register_service(IPC_GET_ARG1(call), |
||
148 | IPC_GET_ARG5(call), &call); |
||
149 | } |
||
1030 | palkovsky | 150 | break; |
1089 | palkovsky | 151 | case IPC_M_CONNECT_ME_TO: |
1336 | jermar | 152 | /* |
153 | * Client requests to be connected to a service. |
||
154 | */ |
||
4153 | mejdrech | 155 | if (service_clonable(IPC_GET_ARG1(call))) { |
156 | connect_to_clonable(IPC_GET_ARG1(call), |
||
157 | &call, callid); |
||
158 | continue; |
||
159 | } else { |
||
160 | connect_to_service(IPC_GET_ARG1(call), &call, |
||
161 | callid); |
||
162 | continue; |
||
163 | } |
||
1061 | palkovsky | 164 | break; |
4581 | mejdrech | 165 | case NS_PING: |
166 | retval = EOK; |
||
167 | break; |
||
168 | case NS_TASK_WAIT: |
||
169 | id = (task_id_t) |
||
170 | MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
||
171 | wait_for_task(id, &call, callid); |
||
172 | continue; |
||
1030 | palkovsky | 173 | default: |
174 | retval = ENOENT; |
||
175 | break; |
||
176 | } |
||
4153 | mejdrech | 177 | |
178 | if (!(callid & IPC_CALLID_NOTIFICATION)) |
||
2619 | jermar | 179 | ipc_answer_0(callid, retval); |
1030 | palkovsky | 180 | } |
3083 | decky | 181 | |
182 | /* Not reached */ |
||
183 | return 0; |
||
1030 | palkovsky | 184 | } |
1335 | jermar | 185 | |
4153 | mejdrech | 186 | /** |
1649 | cejka | 187 | * @} |
188 | */ |