Rev 3773 | Rev 4344 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3773 | Rev 4338 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Jiri Svoboda |
2 | * Copyright (c) 2008 Jiri Svoboda |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup loader |
29 | /** @addtogroup loader |
30 | * @brief Loads and runs programs from VFS. |
30 | * @brief Loads and runs programs from VFS. |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** |
33 | /** |
34 | * @file |
34 | * @file |
35 | * @brief Loads and runs programs from VFS. |
35 | * @brief Loads and runs programs from VFS. |
36 | * |
36 | * |
37 | * The program loader is a special init binary. Its image is used |
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 |
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. |
39 | * returns the id of a phone connected to the newly created task. |
40 | * |
40 | * |
41 | * The caller uses this phone to send the pathname and various other |
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 |
42 | * information to the loader. This is normally done by the C library |
43 | * and completely hidden from applications. |
43 | * and completely hidden from applications. |
44 | */ |
44 | */ |
45 | 45 | ||
46 | #include <stdio.h> |
46 | #include <stdio.h> |
47 | #include <stdlib.h> |
47 | #include <stdlib.h> |
48 | #include <unistd.h> |
48 | #include <unistd.h> |
49 | #include <bool.h> |
49 | #include <bool.h> |
50 | #include <fcntl.h> |
50 | #include <fcntl.h> |
51 | #include <sys/types.h> |
51 | #include <sys/types.h> |
52 | #include <ipc/ipc.h> |
52 | #include <ipc/ipc.h> |
53 | #include <ipc/loader.h> |
53 | #include <ipc/loader.h> |
54 | #include <loader/pcb.h> |
54 | #include <loader/pcb.h> |
55 | #include <errno.h> |
55 | #include <errno.h> |
56 | #include <async.h> |
56 | #include <async.h> |
57 | #include <as.h> |
57 | #include <as.h> |
58 | 58 | ||
59 | #include <elf.h> |
59 | #include <elf.h> |
60 | #include <elf_load.h> |
60 | #include <elf_load.h> |
61 | 61 | ||
- | 62 | #define DPRINTF(...) |
|
- | 63 | ||
62 | void program_run(void *entry, pcb_t *pcb); |
64 | void program_run(void *entry, pcb_t *pcb); |
63 | 65 | ||
64 | /** Pathname of the file that will be loaded */ |
66 | /** Pathname of the file that will be loaded */ |
65 | static char *pathname = NULL; |
67 | static char *pathname = NULL; |
66 | 68 | ||
67 | /** The Program control block */ |
69 | /** The Program control block */ |
68 | static pcb_t pcb; |
70 | static pcb_t pcb; |
69 | 71 | ||
70 | /** Number of arguments */ |
72 | /** Number of arguments */ |
71 | static int argc = 0; |
73 | static int argc = 0; |
72 | /** Argument vector */ |
74 | /** Argument vector */ |
73 | static char **argv = NULL; |
75 | static char **argv = NULL; |
74 | /** Buffer holding all arguments */ |
76 | /** Buffer holding all arguments */ |
75 | static char *arg_buf = NULL; |
77 | static char *arg_buf = NULL; |
76 | 78 | ||
77 | static elf_info_t prog_info; |
79 | static elf_info_t prog_info; |
78 | static elf_info_t interp_info; |
80 | static elf_info_t interp_info; |
79 | 81 | ||
80 | static bool is_dyn_linked; |
82 | static bool is_dyn_linked; |
81 | 83 | ||
82 | 84 | ||
83 | static void loader_get_taskid(ipc_callid_t rid, ipc_call_t *request) |
85 | static void loader_get_taskid(ipc_callid_t rid, ipc_call_t *request) |
84 | { |
86 | { |
85 | ipc_callid_t callid; |
87 | ipc_callid_t callid; |
86 | task_id_t task_id; |
88 | task_id_t task_id; |
87 | size_t len; |
89 | size_t len; |
88 | 90 | ||
89 | task_id = task_get_id(); |
91 | task_id = task_get_id(); |
90 | 92 | ||
91 | if (!ipc_data_read_receive(&callid, &len)) { |
93 | if (!ipc_data_read_receive(&callid, &len)) { |
92 | ipc_answer_0(callid, EINVAL); |
94 | ipc_answer_0(callid, EINVAL); |
93 | ipc_answer_0(rid, EINVAL); |
95 | ipc_answer_0(rid, EINVAL); |
94 | return; |
96 | return; |
95 | } |
97 | } |
96 | 98 | ||
97 | if (len > sizeof(task_id)) len = sizeof(task_id); |
99 | if (len > sizeof(task_id)) len = sizeof(task_id); |
98 | 100 | ||
99 | ipc_data_read_finalize(callid, &task_id, len); |
101 | ipc_data_read_finalize(callid, &task_id, len); |
100 | ipc_answer_0(rid, EOK); |
102 | ipc_answer_0(rid, EOK); |
101 | } |
103 | } |
102 | 104 | ||
103 | 105 | ||
104 | /** Receive a call setting pathname of the program to execute. |
106 | /** Receive a call setting pathname of the program to execute. |
105 | * |
107 | * |
106 | * @param rid |
108 | * @param rid |
107 | * @param request |
109 | * @param request |
108 | */ |
110 | */ |
109 | static void loader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
111 | static void loader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
110 | { |
112 | { |
111 | ipc_callid_t callid; |
113 | ipc_callid_t callid; |
112 | size_t len; |
114 | size_t len; |
113 | char *name_buf; |
115 | char *name_buf; |
114 | 116 | ||
115 | if (!ipc_data_write_receive(&callid, &len)) { |
117 | if (!ipc_data_write_receive(&callid, &len)) { |
116 | ipc_answer_0(callid, EINVAL); |
118 | ipc_answer_0(callid, EINVAL); |
117 | ipc_answer_0(rid, EINVAL); |
119 | ipc_answer_0(rid, EINVAL); |
118 | return; |
120 | return; |
119 | } |
121 | } |
120 | 122 | ||
121 | name_buf = malloc(len + 1); |
123 | name_buf = malloc(len + 1); |
122 | if (!name_buf) { |
124 | if (!name_buf) { |
123 | ipc_answer_0(callid, ENOMEM); |
125 | ipc_answer_0(callid, ENOMEM); |
124 | ipc_answer_0(rid, ENOMEM); |
126 | ipc_answer_0(rid, ENOMEM); |
125 | return; |
127 | return; |
126 | } |
128 | } |
127 | 129 | ||
128 | ipc_data_write_finalize(callid, name_buf, len); |
130 | ipc_data_write_finalize(callid, name_buf, len); |
129 | ipc_answer_0(rid, EOK); |
131 | ipc_answer_0(rid, EOK); |
130 | 132 | ||
131 | if (pathname != NULL) { |
133 | if (pathname != NULL) { |
132 | free(pathname); |
134 | free(pathname); |
133 | pathname = NULL; |
135 | pathname = NULL; |
134 | } |
136 | } |
135 | 137 | ||
136 | name_buf[len] = '\0'; |
138 | name_buf[len] = '\0'; |
137 | pathname = name_buf; |
139 | pathname = name_buf; |
138 | } |
140 | } |
139 | 141 | ||
140 | /** Receive a call setting arguments of the program to execute. |
142 | /** Receive a call setting arguments of the program to execute. |
141 | * |
143 | * |
142 | * @param rid |
144 | * @param rid |
143 | * @param request |
145 | * @param request |
144 | */ |
146 | */ |
145 | static void loader_set_args(ipc_callid_t rid, ipc_call_t *request) |
147 | static void loader_set_args(ipc_callid_t rid, ipc_call_t *request) |
146 | { |
148 | { |
147 | ipc_callid_t callid; |
149 | ipc_callid_t callid; |
148 | size_t buf_len, arg_len; |
150 | size_t buf_len, arg_len; |
149 | char *p; |
151 | char *p; |
150 | int n; |
152 | int n; |
151 | 153 | ||
152 | if (!ipc_data_write_receive(&callid, &buf_len)) { |
154 | if (!ipc_data_write_receive(&callid, &buf_len)) { |
153 | ipc_answer_0(callid, EINVAL); |
155 | ipc_answer_0(callid, EINVAL); |
154 | ipc_answer_0(rid, EINVAL); |
156 | ipc_answer_0(rid, EINVAL); |
155 | return; |
157 | return; |
156 | } |
158 | } |
157 | 159 | ||
158 | if (arg_buf != NULL) { |
160 | if (arg_buf != NULL) { |
159 | free(arg_buf); |
161 | free(arg_buf); |
160 | arg_buf = NULL; |
162 | arg_buf = NULL; |
161 | } |
163 | } |
162 | 164 | ||
163 | if (argv != NULL) { |
165 | if (argv != NULL) { |
164 | free(argv); |
166 | free(argv); |
165 | argv = NULL; |
167 | argv = NULL; |
166 | } |
168 | } |
167 | 169 | ||
168 | arg_buf = malloc(buf_len + 1); |
170 | arg_buf = malloc(buf_len + 1); |
169 | if (!arg_buf) { |
171 | if (!arg_buf) { |
170 | ipc_answer_0(callid, ENOMEM); |
172 | ipc_answer_0(callid, ENOMEM); |
171 | ipc_answer_0(rid, ENOMEM); |
173 | ipc_answer_0(rid, ENOMEM); |
172 | return; |
174 | return; |
173 | } |
175 | } |
174 | 176 | ||
175 | ipc_data_write_finalize(callid, arg_buf, buf_len); |
177 | ipc_data_write_finalize(callid, arg_buf, buf_len); |
176 | ipc_answer_0(rid, EOK); |
178 | ipc_answer_0(rid, EOK); |
177 | 179 | ||
178 | arg_buf[buf_len] = '\0'; |
180 | arg_buf[buf_len] = '\0'; |
179 | 181 | ||
180 | /* |
182 | /* |
181 | * Count number of arguments |
183 | * Count number of arguments |
182 | */ |
184 | */ |
183 | p = arg_buf; |
185 | p = arg_buf; |
184 | n = 0; |
186 | n = 0; |
185 | while (p < arg_buf + buf_len) { |
187 | while (p < arg_buf + buf_len) { |
186 | arg_len = strlen(p); |
188 | arg_len = strlen(p); |
187 | p = p + arg_len + 1; |
189 | p = p + arg_len + 1; |
188 | ++n; |
190 | ++n; |
189 | } |
191 | } |
190 | 192 | ||
191 | /* Allocate argv */ |
193 | /* Allocate argv */ |
192 | argv = malloc((n + 1) * sizeof(char *)); |
194 | argv = malloc((n + 1) * sizeof(char *)); |
193 | 195 | ||
194 | if (argv == NULL) { |
196 | if (argv == NULL) { |
195 | free(arg_buf); |
197 | free(arg_buf); |
196 | ipc_answer_0(callid, ENOMEM); |
198 | ipc_answer_0(callid, ENOMEM); |
197 | ipc_answer_0(rid, ENOMEM); |
199 | ipc_answer_0(rid, ENOMEM); |
198 | return; |
200 | return; |
199 | } |
201 | } |
200 | 202 | ||
201 | /* |
203 | /* |
202 | * Fill argv with argument pointers |
204 | * Fill argv with argument pointers |
203 | */ |
205 | */ |
204 | p = arg_buf; |
206 | p = arg_buf; |
205 | n = 0; |
207 | n = 0; |
206 | while (p < arg_buf + buf_len) { |
208 | while (p < arg_buf + buf_len) { |
207 | argv[n] = p; |
209 | argv[n] = p; |
208 | 210 | ||
209 | arg_len = strlen(p); |
211 | arg_len = strlen(p); |
210 | p = p + arg_len + 1; |
212 | p = p + arg_len + 1; |
211 | ++n; |
213 | ++n; |
212 | } |
214 | } |
213 | 215 | ||
214 | argc = n; |
216 | argc = n; |
215 | argv[n] = NULL; |
217 | argv[n] = NULL; |
216 | } |
218 | } |
217 | 219 | ||
218 | /** Load the previously selected program. |
220 | /** Load the previously selected program. |
219 | * |
221 | * |
220 | * @param rid |
222 | * @param rid |
221 | * @param request |
223 | * @param request |
222 | * @return 0 on success, !0 on error. |
224 | * @return 0 on success, !0 on error. |
223 | */ |
225 | */ |
224 | static int loader_load(ipc_callid_t rid, ipc_call_t *request) |
226 | static int loader_load(ipc_callid_t rid, ipc_call_t *request) |
225 | { |
227 | { |
226 | int rc; |
228 | int rc; |
227 | 229 | ||
228 | rc = elf_load_file(pathname, 0, 0, &prog_info); |
230 | rc = elf_load_file(pathname, 0, 0, &prog_info); |
229 | if (rc < 0) { |
231 | if (rc < 0) { |
230 | printf("Failed to load executable '%s'.\n", pathname); |
232 | DPRINTF("Failed to load executable '%s'.\n", pathname); |
231 | ipc_answer_0(rid, EINVAL); |
233 | ipc_answer_0(rid, EINVAL); |
232 | return 1; |
234 | return 1; |
233 | } |
235 | } |
234 | 236 | ||
235 | elf_create_pcb(&prog_info, &pcb); |
237 | elf_create_pcb(&prog_info, &pcb); |
236 | 238 | ||
237 | pcb.argc = argc; |
239 | pcb.argc = argc; |
238 | pcb.argv = argv; |
240 | pcb.argv = argv; |
239 | 241 | ||
240 | if (prog_info.interp == NULL) { |
242 | if (prog_info.interp == NULL) { |
241 | /* Statically linked program */ |
243 | /* Statically linked program */ |
242 | is_dyn_linked = false; |
244 | is_dyn_linked = false; |
243 | ipc_answer_0(rid, EOK); |
245 | ipc_answer_0(rid, EOK); |
244 | return 0; |
246 | return 0; |
245 | } |
247 | } |
246 | 248 | ||
247 | printf("Load ELF interpreter '%s'\n", prog_info.interp); |
249 | printf("Load ELF interpreter '%s'\n", prog_info.interp); |
248 | rc = elf_load_file(prog_info.interp, 0, 0, &interp_info); |
250 | rc = elf_load_file(prog_info.interp, 0, 0, &interp_info); |
249 | if (rc < 0) { |
251 | if (rc < 0) { |
250 | printf("Failed to load interpreter '%s.'\n", prog_info.interp); |
252 | DPRINTF("Failed to load interpreter '%s.'\n", |
- | 253 | prog_info.interp); |
|
251 | ipc_answer_0(rid, EINVAL); |
254 | ipc_answer_0(rid, EINVAL); |
252 | return 1; |
255 | return 1; |
253 | } |
256 | } |
254 | 257 | ||
255 | printf("Run interpreter.\n"); |
258 | printf("Run interpreter.\n"); |
256 | printf("entry point: 0x%lx\n", interp_info.entry); |
259 | printf("entry point: 0x%lx\n", interp_info.entry); |
257 | printf("pcb address: 0x%lx\n", &pcb); |
260 | printf("pcb address: 0x%lx\n", &pcb); |
258 | printf("prog dynamic: 0x%lx\n", prog_info.dynamic); |
261 | printf("prog dynamic: 0x%lx\n", prog_info.dynamic); |
259 | 262 | ||
260 | is_dyn_linked = true; |
263 | is_dyn_linked = true; |
261 | ipc_answer_0(rid, EOK); |
264 | ipc_answer_0(rid, EOK); |
262 | 265 | ||
263 | return 0; |
266 | return 0; |
264 | } |
267 | } |
265 | 268 | ||
266 | 269 | ||
267 | /** Run the previously loaded program. |
270 | /** Run the previously loaded program. |
268 | * |
271 | * |
269 | * @param rid |
272 | * @param rid |
270 | * @param request |
273 | * @param request |
271 | * @return 0 on success, !0 on error. |
274 | * @return 0 on success, !0 on error. |
272 | */ |
275 | */ |
273 | static void loader_run(ipc_callid_t rid, ipc_call_t *request) |
276 | static void loader_run(ipc_callid_t rid, ipc_call_t *request) |
274 | { |
277 | { |
275 | if (is_dyn_linked == true) { |
278 | if (is_dyn_linked == true) { |
276 | /* Dynamically linked program */ |
279 | /* Dynamically linked program */ |
277 | printf("run dynamic linker\n"); |
280 | DPRINTF("Run ELF interpreter.\n"); |
278 | printf("entry point: 0x%lx\n", interp_info.entry); |
281 | DPRINTF("Entry point: 0x%lx\n", interp_info.entry); |
279 | close_console(); |
282 | close_console(); |
280 | 283 | ||
281 | ipc_answer_0(rid, EOK); |
284 | ipc_answer_0(rid, EOK); |
282 | program_run(interp_info.entry, &pcb); |
285 | program_run(interp_info.entry, &pcb); |
283 | 286 | ||
284 | } else { |
287 | } else { |
285 | /* Statically linked program */ |
288 | /* Statically linked program */ |
286 | close_console(); |
289 | close_console(); |
287 | ipc_answer_0(rid, EOK); |
290 | ipc_answer_0(rid, EOK); |
288 | program_run(prog_info.entry, &pcb); |
291 | program_run(prog_info.entry, &pcb); |
289 | } |
292 | } |
290 | 293 | ||
291 | /* Not reached */ |
294 | /* Not reached */ |
292 | } |
295 | } |
293 | 296 | ||
294 | /** Handle loader connection. |
297 | /** Handle loader connection. |
295 | * |
298 | * |
296 | * Receive and carry out commands (of which the last one should be |
299 | * Receive and carry out commands (of which the last one should be |
297 | * to execute the loaded program). |
300 | * to execute the loaded program). |
298 | */ |
301 | */ |
299 | static void loader_connection(ipc_callid_t iid, ipc_call_t *icall) |
302 | static void loader_connection(ipc_callid_t iid, ipc_call_t *icall) |
300 | { |
303 | { |
301 | ipc_callid_t callid; |
304 | ipc_callid_t callid; |
302 | ipc_call_t call; |
305 | ipc_call_t call; |
303 | int retval; |
306 | int retval; |
304 | 307 | ||
305 | /* Ignore parameters, the connection is already open */ |
308 | /* Ignore parameters, the connection is already open */ |
306 | (void)iid; (void)icall; |
309 | (void)iid; (void)icall; |
307 | 310 | ||
308 | while (1) { |
311 | while (1) { |
309 | callid = async_get_call(&call); |
312 | callid = async_get_call(&call); |
310 | 313 | ||
311 | switch (IPC_GET_METHOD(call)) { |
314 | switch (IPC_GET_METHOD(call)) { |
312 | case IPC_M_PHONE_HUNGUP: |
315 | case IPC_M_PHONE_HUNGUP: |
313 | exit(0); |
316 | exit(0); |
314 | case LOADER_GET_TASKID: |
317 | case LOADER_GET_TASKID: |
315 | loader_get_taskid(callid, &call); |
318 | loader_get_taskid(callid, &call); |
316 | continue; |
319 | continue; |
317 | case LOADER_SET_PATHNAME: |
320 | case LOADER_SET_PATHNAME: |
318 | loader_set_pathname(callid, &call); |
321 | loader_set_pathname(callid, &call); |
319 | continue; |
322 | continue; |
320 | case LOADER_SET_ARGS: |
323 | case LOADER_SET_ARGS: |
321 | loader_set_args(callid, &call); |
324 | loader_set_args(callid, &call); |
322 | continue; |
325 | continue; |
323 | case LOADER_LOAD: |
326 | case LOADER_LOAD: |
324 | loader_load(callid, &call); |
327 | loader_load(callid, &call); |
325 | continue; |
328 | continue; |
326 | case LOADER_RUN: |
329 | case LOADER_RUN: |
327 | loader_run(callid, &call); |
330 | loader_run(callid, &call); |
328 | /* Not reached */ |
331 | /* Not reached */ |
329 | default: |
332 | default: |
330 | retval = ENOENT; |
333 | retval = ENOENT; |
331 | break; |
334 | break; |
332 | } |
335 | } |
333 | if ((callid & IPC_CALLID_NOTIFICATION) == 0 && |
336 | if ((callid & IPC_CALLID_NOTIFICATION) == 0 && |
334 | IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) { |
337 | IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) { |
335 | printf("responding EINVAL to method %d\n", |
338 | DPRINTF("Responding EINVAL to method %d.\n", |
336 | IPC_GET_METHOD(call)); |
339 | IPC_GET_METHOD(call)); |
337 | ipc_answer_0(callid, EINVAL); |
340 | ipc_answer_0(callid, EINVAL); |
338 | } |
341 | } |
339 | } |
342 | } |
340 | } |
343 | } |
341 | 344 | ||
342 | /** Program loader main function. |
345 | /** Program loader main function. |
343 | */ |
346 | */ |
344 | int main(int argc, char *argv[]) |
347 | int main(int argc, char *argv[]) |
345 | { |
348 | { |
346 | ipc_callid_t callid; |
349 | ipc_callid_t callid; |
347 | ipc_call_t call; |
350 | ipc_call_t call; |
348 | ipcarg_t phone_hash; |
351 | ipcarg_t phone_hash; |
349 | 352 | ||
350 | /* The first call only communicates the incoming phone hash */ |
353 | /* The first call only communicates the incoming phone hash */ |
351 | callid = ipc_wait_for_call(&call); |
354 | callid = ipc_wait_for_call(&call); |
352 | 355 | ||
353 | if (IPC_GET_METHOD(call) != LOADER_HELLO) { |
356 | if (IPC_GET_METHOD(call) != LOADER_HELLO) { |
354 | if (IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) |
357 | if (IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) |
355 | ipc_answer_0(callid, EINVAL); |
358 | ipc_answer_0(callid, EINVAL); |
356 | return 1; |
359 | return 1; |
357 | } |
360 | } |
358 | 361 | ||
359 | ipc_answer_0(callid, EOK); |
362 | ipc_answer_0(callid, EOK); |
360 | phone_hash = call.in_phone_hash; |
363 | phone_hash = call.in_phone_hash; |
361 | 364 | ||
362 | /* |
365 | /* |
363 | * Up until now async must not be used as it couldn't |
366 | * Up until now async must not be used as it couldn't |
364 | * handle incoming requests. (Which means e.g. printf() |
367 | * handle incoming requests. (Which means e.g. printf() |
365 | * cannot be used) |
368 | * cannot be used) |
366 | */ |
369 | */ |
367 | async_new_connection(phone_hash, 0, NULL, loader_connection); |
370 | async_new_connection(phone_hash, 0, NULL, loader_connection); |
368 | async_manager(); |
371 | async_manager(); |
369 | 372 | ||
370 | /* not reached */ |
373 | /* not reached */ |
371 | return 0; |
374 | return 0; |
372 | } |
375 | } |
373 | 376 | ||
374 | /** @} |
377 | /** @} |
375 | */ |
378 | */ |
376 | 379 |