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