[babe786] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[babe786] | 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 |
|
---|
[231a60a] | 29 | /** @addtogroup ns
|
---|
[ce5bcb4] | 30 | * @{
|
---|
[1fcfc94] | 31 | */
|
---|
[ce5bcb4] | 32 |
|
---|
[babe786] | 33 | /**
|
---|
[1fcfc94] | 34 | * @file ns.c
|
---|
| 35 | * @brief Naming service for HelenOS IPC.
|
---|
[babe786] | 36 | */
|
---|
| 37 |
|
---|
[38edb96] | 38 | #include <ipc/ipc.h>
|
---|
[51dbadf3] | 39 | #include <ipc/services.h>
|
---|
[40313e4] | 40 | #include <ipc/ns.h>
|
---|
[69cdeec] | 41 | #include <unistd.h>
|
---|
[40313e4] | 42 | #include <stdio.h>
|
---|
[69cdeec] | 43 | #include <errno.h>
|
---|
[0b99e40] | 44 | #include <as.h>
|
---|
[40313e4] | 45 | #include <ddi.h>
|
---|
| 46 | #include <event.h>
|
---|
| 47 | #include <macros.h>
|
---|
[3bf907a] | 48 | #include <sysinfo.h>
|
---|
[40313e4] | 49 | #include "ns.h"
|
---|
| 50 | #include "service.h"
|
---|
| 51 | #include "clonable.h"
|
---|
| 52 | #include "task.h"
|
---|
[bfd1546] | 53 |
|
---|
[1fcfc94] | 54 | static void *clockaddr = NULL;
|
---|
| 55 | static void *klogaddr = NULL;
|
---|
| 56 |
|
---|
[40313e4] | 57 | static void get_as_area(ipc_callid_t callid, ipc_call_t *call, void *ph_addr,
|
---|
| 58 | size_t pages, void **addr)
|
---|
[0b99e40] | 59 | {
|
---|
[3636964] | 60 | if (ph_addr == NULL) {
|
---|
| 61 | ipc_answer_0(callid, ENOENT);
|
---|
| 62 | return;
|
---|
| 63 | }
|
---|
[ae318d3] | 64 |
|
---|
[3636964] | 65 | if (*addr == NULL) {
|
---|
| 66 | *addr = as_get_mappable_page(pages * PAGE_SIZE);
|
---|
| 67 |
|
---|
| 68 | if (*addr == NULL) {
|
---|
[b74959bd] | 69 | ipc_answer_0(callid, ENOENT);
|
---|
[0b99e40] | 70 | return;
|
---|
| 71 | }
|
---|
[3636964] | 72 |
|
---|
| 73 | if (physmem_map(ph_addr, *addr, pages,
|
---|
[ae318d3] | 74 | AS_AREA_READ | AS_AREA_CACHEABLE) != 0) {
|
---|
| 75 | ipc_answer_0(callid, ENOENT);
|
---|
| 76 | return;
|
---|
| 77 | }
|
---|
[0b99e40] | 78 | }
|
---|
[3636964] | 79 |
|
---|
[b74959bd] | 80 | ipc_answer_2(callid, EOK, (ipcarg_t) *addr, AS_AREA_READ);
|
---|
[0b99e40] | 81 | }
|
---|
| 82 |
|
---|
[69cdeec] | 83 | int main(int argc, char **argv)
|
---|
| 84 | {
|
---|
[e623197] | 85 | printf(NAME ": HelenOS IPC Naming Service\n");
|
---|
| 86 |
|
---|
[40313e4] | 87 | int rc = service_init();
|
---|
| 88 | if (rc != EOK)
|
---|
| 89 | return rc;
|
---|
[1fcfc94] | 90 |
|
---|
[40313e4] | 91 | rc = clonable_init();
|
---|
| 92 | if (rc != EOK)
|
---|
| 93 | return rc;
|
---|
| 94 |
|
---|
| 95 | rc = task_init();
|
---|
| 96 | if (rc != EOK)
|
---|
| 97 | return rc;
|
---|
[e623197] | 98 |
|
---|
| 99 | printf(NAME ": Accepting connections\n");
|
---|
[40313e4] | 100 |
|
---|
[1fcfc94] | 101 | while (true) {
|
---|
[40313e4] | 102 | process_pending_conn();
|
---|
| 103 | process_pending_wait();
|
---|
[1fcfc94] | 104 |
|
---|
| 105 | ipc_call_t call;
|
---|
| 106 | ipc_callid_t callid = ipc_wait_for_call(&call);
|
---|
[40313e4] | 107 |
|
---|
| 108 | task_id_t id;
|
---|
[1fcfc94] | 109 | ipcarg_t retval;
|
---|
| 110 |
|
---|
[4c61e60] | 111 | switch (IPC_GET_METHOD(call)) {
|
---|
[27d293a] | 112 | case IPC_M_SHARE_IN:
|
---|
[51dbadf3] | 113 | switch (IPC_GET_ARG3(call)) {
|
---|
| 114 | case SERVICE_MEM_REALTIME:
|
---|
[40313e4] | 115 | get_as_area(callid, &call,
|
---|
| 116 | (void *) sysinfo_value("clock.faddr"),
|
---|
| 117 | 1, &clockaddr);
|
---|
[51dbadf3] | 118 | break;
|
---|
| 119 | case SERVICE_MEM_KLOG:
|
---|
[40313e4] | 120 | get_as_area(callid, &call,
|
---|
| 121 | (void *) sysinfo_value("klog.faddr"),
|
---|
| 122 | sysinfo_value("klog.pages"), &klogaddr);
|
---|
[51dbadf3] | 123 | break;
|
---|
| 124 | default:
|
---|
[b74959bd] | 125 | ipc_answer_0(callid, ENOENT);
|
---|
[51dbadf3] | 126 | }
|
---|
[0b99e40] | 127 | continue;
|
---|
[7048773] | 128 | case IPC_M_PHONE_HUNGUP:
|
---|
[5d96851b] | 129 | retval = ns_task_disconnect(&call);
|
---|
[7048773] | 130 | break;
|
---|
[043dcc27] | 131 | case IPC_M_CONNECT_TO_ME:
|
---|
[babe786] | 132 | /*
|
---|
[043dcc27] | 133 | * Server requests service registration.
|
---|
[babe786] | 134 | */
|
---|
[bfd1546] | 135 | if (service_clonable(IPC_GET_ARG1(call))) {
|
---|
| 136 | register_clonable(IPC_GET_ARG1(call),
|
---|
| 137 | IPC_GET_ARG5(call), &call, callid);
|
---|
| 138 | continue;
|
---|
| 139 | } else {
|
---|
| 140 | retval = register_service(IPC_GET_ARG1(call),
|
---|
| 141 | IPC_GET_ARG5(call), &call);
|
---|
| 142 | }
|
---|
[69cdeec] | 143 | break;
|
---|
[7048773] | 144 | case IPC_M_CONNECT_ME_TO:
|
---|
[043dcc27] | 145 | /*
|
---|
| 146 | * Client requests to be connected to a service.
|
---|
| 147 | */
|
---|
[bfd1546] | 148 | if (service_clonable(IPC_GET_ARG1(call))) {
|
---|
| 149 | connect_to_clonable(IPC_GET_ARG1(call),
|
---|
| 150 | &call, callid);
|
---|
| 151 | continue;
|
---|
| 152 | } else {
|
---|
[1fcfc94] | 153 | connect_to_service(IPC_GET_ARG1(call), &call,
|
---|
| 154 | callid);
|
---|
| 155 | continue;
|
---|
[bfd1546] | 156 | }
|
---|
[11eae82] | 157 | break;
|
---|
[40313e4] | 158 | case NS_PING:
|
---|
| 159 | retval = EOK;
|
---|
| 160 | break;
|
---|
| 161 | case NS_TASK_WAIT:
|
---|
| 162 | id = (task_id_t)
|
---|
| 163 | MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
---|
| 164 | wait_for_task(id, &call, callid);
|
---|
| 165 | continue;
|
---|
[5d96851b] | 166 | case NS_ID_INTRO:
|
---|
| 167 | retval = ns_task_id_intro(&call);
|
---|
| 168 | break;
|
---|
[7114d83] | 169 | case NS_RETVAL:
|
---|
| 170 | retval = ns_task_retval(&call);
|
---|
| 171 | break;
|
---|
[69cdeec] | 172 | default:
|
---|
| 173 | retval = ENOENT;
|
---|
| 174 | break;
|
---|
| 175 | }
|
---|
[1fcfc94] | 176 |
|
---|
| 177 | if (!(callid & IPC_CALLID_NOTIFICATION))
|
---|
[b74959bd] | 178 | ipc_answer_0(callid, retval);
|
---|
[69cdeec] | 179 | }
|
---|
[e623197] | 180 |
|
---|
| 181 | /* Not reached */
|
---|
| 182 | return 0;
|
---|
[69cdeec] | 183 | }
|
---|
[babe786] | 184 |
|
---|
[1fcfc94] | 185 | /**
|
---|
[ce5bcb4] | 186 | * @}
|
---|
| 187 | */
|
---|