[c98e6ee] | 1 | /*
|
---|
| 2 | * Copyright (c) 2008 Jiri Svoboda
|
---|
| 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 loader
|
---|
[2f57690] | 30 | * @brief Loads and runs programs from VFS.
|
---|
[c98e6ee] | 31 | * @{
|
---|
[2f57690] | 32 | */
|
---|
[c98e6ee] | 33 | /**
|
---|
| 34 | * @file
|
---|
[2f57690] | 35 | * @brief Loads and runs programs from VFS.
|
---|
[c98e6ee] | 36 | *
|
---|
| 37 | * The program loader is a special init binary. Its image is used
|
---|
| 38 | * to create a new task upon a @c task_spawn syscall. The syscall
|
---|
| 39 | * returns the id of a phone connected to the newly created task.
|
---|
| 40 | *
|
---|
| 41 | * The caller uses this phone to send the pathname and various other
|
---|
| 42 | * information to the loader. This is normally done by the C library
|
---|
| 43 | * and completely hidden from applications.
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | #include <stdio.h>
|
---|
| 47 | #include <stdlib.h>
|
---|
| 48 | #include <unistd.h>
|
---|
[4470e26] | 49 | #include <bool.h>
|
---|
[c98e6ee] | 50 | #include <fcntl.h>
|
---|
| 51 | #include <sys/types.h>
|
---|
| 52 | #include <ipc/ipc.h>
|
---|
[bfd1546] | 53 | #include <ipc/services.h>
|
---|
[c98e6ee] | 54 | #include <ipc/loader.h>
|
---|
[5d96851b] | 55 | #include <ipc/ns.h>
|
---|
| 56 | #include <macros.h>
|
---|
[c98e6ee] | 57 | #include <loader/pcb.h>
|
---|
| 58 | #include <errno.h>
|
---|
| 59 | #include <async.h>
|
---|
[bbdbf86] | 60 | #include <string.h>
|
---|
[c98e6ee] | 61 | #include <as.h>
|
---|
| 62 |
|
---|
| 63 | #include <elf.h>
|
---|
| 64 | #include <elf_load.h>
|
---|
| 65 |
|
---|
[06b2b7f] | 66 | #define DPRINTF(...)
|
---|
| 67 |
|
---|
[1ea99cc] | 68 | void program_run(void *entry, pcb_t *pcb);
|
---|
| 69 |
|
---|
[c98e6ee] | 70 | /** Pathname of the file that will be loaded */
|
---|
| 71 | static char *pathname = NULL;
|
---|
| 72 |
|
---|
| 73 | /** The Program control block */
|
---|
| 74 | static pcb_t pcb;
|
---|
| 75 |
|
---|
| 76 | /** Number of arguments */
|
---|
| 77 | static int argc = 0;
|
---|
| 78 | /** Argument vector */
|
---|
| 79 | static char **argv = NULL;
|
---|
| 80 | /** Buffer holding all arguments */
|
---|
| 81 | static char *arg_buf = NULL;
|
---|
| 82 |
|
---|
[bbdbf86] | 83 | /** Number of preset files */
|
---|
| 84 | static int filc = 0;
|
---|
| 85 | /** Preset files vector */
|
---|
[08c9f7d5] | 86 | static fdi_node_t **filv = NULL;
|
---|
[bbdbf86] | 87 | /** Buffer holding all preset files */
|
---|
[99272a3] | 88 | static fdi_node_t *fil_buf = NULL;
|
---|
[bbdbf86] | 89 |
|
---|
[4470e26] | 90 | static elf_info_t prog_info;
|
---|
| 91 | static elf_info_t interp_info;
|
---|
| 92 |
|
---|
| 93 | static bool is_dyn_linked;
|
---|
| 94 |
|
---|
[bfd1546] | 95 | /** Used to limit number of connections to one. */
|
---|
| 96 | static bool connected;
|
---|
[4470e26] | 97 |
|
---|
[bbdbf86] | 98 | static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
|
---|
[47e0a05b] | 99 | {
|
---|
| 100 | ipc_callid_t callid;
|
---|
| 101 | task_id_t task_id;
|
---|
| 102 | size_t len;
|
---|
[2f57690] | 103 |
|
---|
[47e0a05b] | 104 | task_id = task_get_id();
|
---|
[2f57690] | 105 |
|
---|
[47e0a05b] | 106 | if (!ipc_data_read_receive(&callid, &len)) {
|
---|
| 107 | ipc_answer_0(callid, EINVAL);
|
---|
| 108 | ipc_answer_0(rid, EINVAL);
|
---|
| 109 | return;
|
---|
| 110 | }
|
---|
[2f57690] | 111 |
|
---|
| 112 | if (len > sizeof(task_id))
|
---|
| 113 | len = sizeof(task_id);
|
---|
| 114 |
|
---|
[0993087] | 115 | ipc_data_read_finalize(callid, &task_id, len);
|
---|
[47e0a05b] | 116 | ipc_answer_0(rid, EOK);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 |
|
---|
[c98e6ee] | 120 | /** Receive a call setting pathname of the program to execute.
|
---|
| 121 | *
|
---|
| 122 | * @param rid
|
---|
| 123 | * @param request
|
---|
| 124 | */
|
---|
[bbdbf86] | 125 | static void ldr_set_pathname(ipc_callid_t rid, ipc_call_t *request)
|
---|
[c98e6ee] | 126 | {
|
---|
| 127 | ipc_callid_t callid;
|
---|
| 128 | size_t len;
|
---|
| 129 | char *name_buf;
|
---|
[2f57690] | 130 |
|
---|
[c98e6ee] | 131 | if (!ipc_data_write_receive(&callid, &len)) {
|
---|
| 132 | ipc_answer_0(callid, EINVAL);
|
---|
| 133 | ipc_answer_0(rid, EINVAL);
|
---|
| 134 | return;
|
---|
| 135 | }
|
---|
[2f57690] | 136 |
|
---|
[c98e6ee] | 137 | name_buf = malloc(len + 1);
|
---|
| 138 | if (!name_buf) {
|
---|
| 139 | ipc_answer_0(callid, ENOMEM);
|
---|
| 140 | ipc_answer_0(rid, ENOMEM);
|
---|
| 141 | return;
|
---|
| 142 | }
|
---|
[2f57690] | 143 |
|
---|
[c98e6ee] | 144 | ipc_data_write_finalize(callid, name_buf, len);
|
---|
| 145 | ipc_answer_0(rid, EOK);
|
---|
[2f57690] | 146 |
|
---|
[c98e6ee] | 147 | if (pathname != NULL) {
|
---|
| 148 | free(pathname);
|
---|
| 149 | pathname = NULL;
|
---|
| 150 | }
|
---|
[2f57690] | 151 |
|
---|
[c98e6ee] | 152 | name_buf[len] = '\0';
|
---|
| 153 | pathname = name_buf;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | /** Receive a call setting arguments of the program to execute.
|
---|
| 157 | *
|
---|
| 158 | * @param rid
|
---|
| 159 | * @param request
|
---|
| 160 | */
|
---|
[bbdbf86] | 161 | static void ldr_set_args(ipc_callid_t rid, ipc_call_t *request)
|
---|
[c98e6ee] | 162 | {
|
---|
| 163 | ipc_callid_t callid;
|
---|
[92fd52d7] | 164 | size_t buf_size, arg_size;
|
---|
[c98e6ee] | 165 | char *p;
|
---|
| 166 | int n;
|
---|
[2f57690] | 167 |
|
---|
[92fd52d7] | 168 | if (!ipc_data_write_receive(&callid, &buf_size)) {
|
---|
[c98e6ee] | 169 | ipc_answer_0(callid, EINVAL);
|
---|
| 170 | ipc_answer_0(rid, EINVAL);
|
---|
| 171 | return;
|
---|
| 172 | }
|
---|
[2f57690] | 173 |
|
---|
[c98e6ee] | 174 | if (arg_buf != NULL) {
|
---|
| 175 | free(arg_buf);
|
---|
| 176 | arg_buf = NULL;
|
---|
| 177 | }
|
---|
[2f57690] | 178 |
|
---|
[c98e6ee] | 179 | if (argv != NULL) {
|
---|
| 180 | free(argv);
|
---|
| 181 | argv = NULL;
|
---|
| 182 | }
|
---|
[2f57690] | 183 |
|
---|
[92fd52d7] | 184 | arg_buf = malloc(buf_size + 1);
|
---|
[c98e6ee] | 185 | if (!arg_buf) {
|
---|
| 186 | ipc_answer_0(callid, ENOMEM);
|
---|
| 187 | ipc_answer_0(rid, ENOMEM);
|
---|
| 188 | return;
|
---|
| 189 | }
|
---|
[2f57690] | 190 |
|
---|
[92fd52d7] | 191 | ipc_data_write_finalize(callid, arg_buf, buf_size);
|
---|
[2f57690] | 192 |
|
---|
[92fd52d7] | 193 | arg_buf[buf_size] = '\0';
|
---|
[2f57690] | 194 |
|
---|
[c98e6ee] | 195 | /*
|
---|
| 196 | * Count number of arguments
|
---|
| 197 | */
|
---|
| 198 | p = arg_buf;
|
---|
| 199 | n = 0;
|
---|
[92fd52d7] | 200 | while (p < arg_buf + buf_size) {
|
---|
| 201 | arg_size = str_size(p);
|
---|
| 202 | p = p + arg_size + 1;
|
---|
[c98e6ee] | 203 | ++n;
|
---|
| 204 | }
|
---|
[2f57690] | 205 |
|
---|
[c98e6ee] | 206 | /* Allocate argv */
|
---|
| 207 | argv = malloc((n + 1) * sizeof(char *));
|
---|
[2f57690] | 208 |
|
---|
[c98e6ee] | 209 | if (argv == NULL) {
|
---|
| 210 | free(arg_buf);
|
---|
| 211 | ipc_answer_0(rid, ENOMEM);
|
---|
| 212 | return;
|
---|
| 213 | }
|
---|
[482c86f] | 214 |
|
---|
[c98e6ee] | 215 | /*
|
---|
| 216 | * Fill argv with argument pointers
|
---|
| 217 | */
|
---|
| 218 | p = arg_buf;
|
---|
| 219 | n = 0;
|
---|
[92fd52d7] | 220 | while (p < arg_buf + buf_size) {
|
---|
[c98e6ee] | 221 | argv[n] = p;
|
---|
[2f57690] | 222 |
|
---|
[92fd52d7] | 223 | arg_size = str_size(p);
|
---|
| 224 | p = p + arg_size + 1;
|
---|
[c98e6ee] | 225 | ++n;
|
---|
| 226 | }
|
---|
[2f57690] | 227 |
|
---|
[c98e6ee] | 228 | argc = n;
|
---|
| 229 | argv[n] = NULL;
|
---|
[482c86f] | 230 |
|
---|
| 231 | ipc_answer_0(rid, EOK);
|
---|
[c98e6ee] | 232 | }
|
---|
| 233 |
|
---|
[bbdbf86] | 234 | /** Receive a call setting preset files of the program to execute.
|
---|
| 235 | *
|
---|
| 236 | * @param rid
|
---|
| 237 | * @param request
|
---|
| 238 | */
|
---|
| 239 | static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request)
|
---|
| 240 | {
|
---|
| 241 | ipc_callid_t callid;
|
---|
| 242 | size_t buf_size;
|
---|
| 243 | if (!ipc_data_write_receive(&callid, &buf_size)) {
|
---|
| 244 | ipc_answer_0(callid, EINVAL);
|
---|
| 245 | ipc_answer_0(rid, EINVAL);
|
---|
| 246 | return;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
[99272a3] | 249 | if ((buf_size % sizeof(fdi_node_t)) != 0) {
|
---|
[bbdbf86] | 250 | ipc_answer_0(callid, EINVAL);
|
---|
| 251 | ipc_answer_0(rid, EINVAL);
|
---|
| 252 | return;
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | if (fil_buf != NULL) {
|
---|
| 256 | free(fil_buf);
|
---|
| 257 | fil_buf = NULL;
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | if (filv != NULL) {
|
---|
| 261 | free(filv);
|
---|
| 262 | filv = NULL;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | fil_buf = malloc(buf_size);
|
---|
| 266 | if (!fil_buf) {
|
---|
| 267 | ipc_answer_0(callid, ENOMEM);
|
---|
| 268 | ipc_answer_0(rid, ENOMEM);
|
---|
| 269 | return;
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | ipc_data_write_finalize(callid, fil_buf, buf_size);
|
---|
| 273 |
|
---|
[99272a3] | 274 | int count = buf_size / sizeof(fdi_node_t);
|
---|
[bbdbf86] | 275 |
|
---|
| 276 | /* Allocate filvv */
|
---|
[99272a3] | 277 | filv = malloc((count + 1) * sizeof(fdi_node_t *));
|
---|
[bbdbf86] | 278 |
|
---|
| 279 | if (filv == NULL) {
|
---|
| 280 | free(fil_buf);
|
---|
| 281 | ipc_answer_0(rid, ENOMEM);
|
---|
| 282 | return;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | /*
|
---|
| 286 | * Fill filv with argument pointers
|
---|
| 287 | */
|
---|
| 288 | int i;
|
---|
| 289 | for (i = 0; i < count; i++)
|
---|
| 290 | filv[i] = &fil_buf[i];
|
---|
| 291 |
|
---|
| 292 | filc = count;
|
---|
| 293 | filv[count] = NULL;
|
---|
| 294 |
|
---|
| 295 | ipc_answer_0(rid, EOK);
|
---|
| 296 | }
|
---|
| 297 |
|
---|
[4470e26] | 298 | /** Load the previously selected program.
|
---|
[c98e6ee] | 299 | *
|
---|
| 300 | * @param rid
|
---|
| 301 | * @param request
|
---|
| 302 | * @return 0 on success, !0 on error.
|
---|
| 303 | */
|
---|
[bbdbf86] | 304 | static int ldr_load(ipc_callid_t rid, ipc_call_t *request)
|
---|
[c98e6ee] | 305 | {
|
---|
| 306 | int rc;
|
---|
[2f57690] | 307 |
|
---|
[1ea99cc] | 308 | rc = elf_load_file(pathname, 0, 0, &prog_info);
|
---|
[409b0d6] | 309 | if (rc != EE_OK) {
|
---|
[06b2b7f] | 310 | DPRINTF("Failed to load executable '%s'.\n", pathname);
|
---|
[c98e6ee] | 311 | ipc_answer_0(rid, EINVAL);
|
---|
| 312 | return 1;
|
---|
| 313 | }
|
---|
[2f57690] | 314 |
|
---|
[c98e6ee] | 315 | elf_create_pcb(&prog_info, &pcb);
|
---|
[2f57690] | 316 |
|
---|
[c98e6ee] | 317 | pcb.argc = argc;
|
---|
| 318 | pcb.argv = argv;
|
---|
[2f57690] | 319 |
|
---|
[bbdbf86] | 320 | pcb.filc = filc;
|
---|
| 321 | pcb.filv = filv;
|
---|
| 322 |
|
---|
[c98e6ee] | 323 | if (prog_info.interp == NULL) {
|
---|
| 324 | /* Statically linked program */
|
---|
[4470e26] | 325 | is_dyn_linked = false;
|
---|
[c98e6ee] | 326 | ipc_answer_0(rid, EOK);
|
---|
| 327 | return 0;
|
---|
| 328 | }
|
---|
[2f57690] | 329 |
|
---|
[1ea99cc] | 330 | printf("Load ELF interpreter '%s'\n", prog_info.interp);
|
---|
| 331 | rc = elf_load_file(prog_info.interp, 0, 0, &interp_info);
|
---|
[409b0d6] | 332 | if (rc != EE_OK) {
|
---|
[06b2b7f] | 333 | DPRINTF("Failed to load interpreter '%s.'\n",
|
---|
| 334 | prog_info.interp);
|
---|
[c98e6ee] | 335 | ipc_answer_0(rid, EINVAL);
|
---|
| 336 | return 1;
|
---|
| 337 | }
|
---|
[2f57690] | 338 |
|
---|
[1ea99cc] | 339 | printf("Run interpreter.\n");
|
---|
| 340 | printf("entry point: 0x%lx\n", interp_info.entry);
|
---|
| 341 | printf("pcb address: 0x%lx\n", &pcb);
|
---|
| 342 | printf("prog dynamic: 0x%lx\n", prog_info.dynamic);
|
---|
| 343 |
|
---|
[4470e26] | 344 | is_dyn_linked = true;
|
---|
[c98e6ee] | 345 | ipc_answer_0(rid, EOK);
|
---|
[2f57690] | 346 |
|
---|
[c98e6ee] | 347 | return 0;
|
---|
| 348 | }
|
---|
| 349 |
|
---|
[4470e26] | 350 |
|
---|
| 351 | /** Run the previously loaded program.
|
---|
| 352 | *
|
---|
| 353 | * @param rid
|
---|
| 354 | * @param request
|
---|
| 355 | * @return 0 on success, !0 on error.
|
---|
| 356 | */
|
---|
[bbdbf86] | 357 | static void ldr_run(ipc_callid_t rid, ipc_call_t *request)
|
---|
[4470e26] | 358 | {
|
---|
[20f1597] | 359 | const char *cp;
|
---|
[2f57690] | 360 |
|
---|
[bc18d63] | 361 | /* Set the task name. */
|
---|
[7afb4a5] | 362 | cp = str_rchr(pathname, '/');
|
---|
[20f1597] | 363 | cp = (cp == NULL) ? pathname : (cp + 1);
|
---|
| 364 | task_set_name(cp);
|
---|
[2f57690] | 365 |
|
---|
[4470e26] | 366 | if (is_dyn_linked == true) {
|
---|
| 367 | /* Dynamically linked program */
|
---|
[06b2b7f] | 368 | DPRINTF("Run ELF interpreter.\n");
|
---|
| 369 | DPRINTF("Entry point: 0x%lx\n", interp_info.entry);
|
---|
[2f57690] | 370 |
|
---|
[4470e26] | 371 | ipc_answer_0(rid, EOK);
|
---|
[1ea99cc] | 372 | program_run(interp_info.entry, &pcb);
|
---|
[4470e26] | 373 | } else {
|
---|
| 374 | /* Statically linked program */
|
---|
| 375 | ipc_answer_0(rid, EOK);
|
---|
[1ea99cc] | 376 | program_run(prog_info.entry, &pcb);
|
---|
[bbdbf86] | 377 | }
|
---|
| 378 |
|
---|
[4470e26] | 379 | /* Not reached */
|
---|
| 380 | }
|
---|
| 381 |
|
---|
[c98e6ee] | 382 | /** Handle loader connection.
|
---|
| 383 | *
|
---|
| 384 | * Receive and carry out commands (of which the last one should be
|
---|
| 385 | * to execute the loaded program).
|
---|
| 386 | */
|
---|
[bbdbf86] | 387 | static void ldr_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[c98e6ee] | 388 | {
|
---|
| 389 | ipc_callid_t callid;
|
---|
| 390 | ipc_call_t call;
|
---|
| 391 | int retval;
|
---|
[2f57690] | 392 |
|
---|
[bfd1546] | 393 | /* Already have a connection? */
|
---|
| 394 | if (connected) {
|
---|
| 395 | ipc_answer_0(iid, ELIMIT);
|
---|
| 396 | return;
|
---|
| 397 | }
|
---|
[2f57690] | 398 |
|
---|
[bfd1546] | 399 | connected = true;
|
---|
| 400 |
|
---|
| 401 | /* Accept the connection */
|
---|
| 402 | ipc_answer_0(iid, EOK);
|
---|
[2f57690] | 403 |
|
---|
[c98e6ee] | 404 | /* Ignore parameters, the connection is already open */
|
---|
[2f57690] | 405 | (void) iid;
|
---|
| 406 | (void) icall;
|
---|
| 407 |
|
---|
[c98e6ee] | 408 | while (1) {
|
---|
| 409 | callid = async_get_call(&call);
|
---|
[2f57690] | 410 |
|
---|
[c98e6ee] | 411 | switch (IPC_GET_METHOD(call)) {
|
---|
[86e3d62] | 412 | case IPC_M_PHONE_HUNGUP:
|
---|
| 413 | exit(0);
|
---|
[47e0a05b] | 414 | case LOADER_GET_TASKID:
|
---|
[bbdbf86] | 415 | ldr_get_taskid(callid, &call);
|
---|
[47e0a05b] | 416 | continue;
|
---|
[c98e6ee] | 417 | case LOADER_SET_PATHNAME:
|
---|
[bbdbf86] | 418 | ldr_set_pathname(callid, &call);
|
---|
[c98e6ee] | 419 | continue;
|
---|
| 420 | case LOADER_SET_ARGS:
|
---|
[bbdbf86] | 421 | ldr_set_args(callid, &call);
|
---|
| 422 | continue;
|
---|
| 423 | case LOADER_SET_FILES:
|
---|
| 424 | ldr_set_files(callid, &call);
|
---|
[4470e26] | 425 | continue;
|
---|
| 426 | case LOADER_LOAD:
|
---|
[bbdbf86] | 427 | ldr_load(callid, &call);
|
---|
[4470e26] | 428 | continue;
|
---|
[c98e6ee] | 429 | case LOADER_RUN:
|
---|
[bbdbf86] | 430 | ldr_run(callid, &call);
|
---|
[4470e26] | 431 | /* Not reached */
|
---|
[c98e6ee] | 432 | default:
|
---|
| 433 | retval = ENOENT;
|
---|
| 434 | break;
|
---|
| 435 | }
|
---|
| 436 | if ((callid & IPC_CALLID_NOTIFICATION) == 0 &&
|
---|
| 437 | IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) {
|
---|
[06b2b7f] | 438 | DPRINTF("Responding EINVAL to method %d.\n",
|
---|
[c98e6ee] | 439 | IPC_GET_METHOD(call));
|
---|
| 440 | ipc_answer_0(callid, EINVAL);
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
| 444 |
|
---|
| 445 | /** Program loader main function.
|
---|
| 446 | */
|
---|
| 447 | int main(int argc, char *argv[])
|
---|
| 448 | {
|
---|
[bfd1546] | 449 | ipcarg_t phonead;
|
---|
[5d96851b] | 450 | task_id_t id;
|
---|
| 451 | int rc;
|
---|
| 452 |
|
---|
[bfd1546] | 453 | connected = false;
|
---|
[5d96851b] | 454 |
|
---|
| 455 | /* Introduce this task to the NS (give it our task ID). */
|
---|
| 456 | id = task_get_id();
|
---|
| 457 | rc = async_req_2_0(PHONE_NS, NS_ID_INTRO, LOWER32(id), UPPER32(id));
|
---|
| 458 | if (rc != EOK)
|
---|
| 459 | return -1;
|
---|
| 460 |
|
---|
[bfd1546] | 461 | /* Set a handler of incomming connections. */
|
---|
[bbdbf86] | 462 | async_set_client_connection(ldr_connection);
|
---|
[2f57690] | 463 |
|
---|
[bfd1546] | 464 | /* Register at naming service. */
|
---|
| 465 | if (ipc_connect_to_me(PHONE_NS, SERVICE_LOAD, 0, 0, &phonead) != 0)
|
---|
[5d96851b] | 466 | return -2;
|
---|
| 467 |
|
---|
[c98e6ee] | 468 | async_manager();
|
---|
[2f57690] | 469 |
|
---|
[bfd1546] | 470 | /* Never reached */
|
---|
[c98e6ee] | 471 | return 0;
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | /** @}
|
---|
| 475 | */
|
---|