Rev 3677 | Rev 3690 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3677 | Rev 3681 | ||
---|---|---|---|
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 | void program_run(void *entry, pcb_t *pcb); |
|
- | 63 | ||
62 | /** Pathname of the file that will be loaded */ |
64 | /** Pathname of the file that will be loaded */ |
63 | static char *pathname = NULL; |
65 | static char *pathname = NULL; |
64 | 66 | ||
65 | /** The Program control block */ |
67 | /** The Program control block */ |
66 | static pcb_t pcb; |
68 | static pcb_t pcb; |
67 | 69 | ||
68 | /** Number of arguments */ |
70 | /** Number of arguments */ |
69 | static int argc = 0; |
71 | static int argc = 0; |
70 | /** Argument vector */ |
72 | /** Argument vector */ |
71 | static char **argv = NULL; |
73 | static char **argv = NULL; |
72 | /** Buffer holding all arguments */ |
74 | /** Buffer holding all arguments */ |
73 | static char *arg_buf = NULL; |
75 | static char *arg_buf = NULL; |
74 | 76 | ||
75 | static elf_info_t prog_info; |
77 | static elf_info_t prog_info; |
76 | static elf_info_t interp_info; |
78 | static elf_info_t interp_info; |
77 | 79 | ||
78 | static bool is_dyn_linked; |
80 | static bool is_dyn_linked; |
79 | 81 | ||
80 | 82 | ||
81 | static void loader_get_taskid(ipc_callid_t rid, ipc_call_t *request) |
83 | static void loader_get_taskid(ipc_callid_t rid, ipc_call_t *request) |
82 | { |
84 | { |
83 | ipc_callid_t callid; |
85 | ipc_callid_t callid; |
84 | task_id_t task_id; |
86 | task_id_t task_id; |
85 | size_t len; |
87 | size_t len; |
86 | 88 | ||
87 | task_id = task_get_id(); |
89 | task_id = task_get_id(); |
88 | 90 | ||
89 | if (!ipc_data_read_receive(&callid, &len)) { |
91 | if (!ipc_data_read_receive(&callid, &len)) { |
90 | ipc_answer_0(callid, EINVAL); |
92 | ipc_answer_0(callid, EINVAL); |
91 | ipc_answer_0(rid, EINVAL); |
93 | ipc_answer_0(rid, EINVAL); |
92 | return; |
94 | return; |
93 | } |
95 | } |
94 | 96 | ||
95 | if (len > sizeof(task_id)) len = sizeof(task_id); |
97 | if (len > sizeof(task_id)) len = sizeof(task_id); |
96 | 98 | ||
97 | ipc_data_read_finalize(callid, &task_id, len); |
99 | ipc_data_read_finalize(callid, &task_id, len); |
98 | ipc_answer_0(rid, EOK); |
100 | ipc_answer_0(rid, EOK); |
99 | } |
101 | } |
100 | 102 | ||
101 | 103 | ||
102 | /** Receive a call setting pathname of the program to execute. |
104 | /** Receive a call setting pathname of the program to execute. |
103 | * |
105 | * |
104 | * @param rid |
106 | * @param rid |
105 | * @param request |
107 | * @param request |
106 | */ |
108 | */ |
107 | static void loader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
109 | static void loader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
108 | { |
110 | { |
109 | ipc_callid_t callid; |
111 | ipc_callid_t callid; |
110 | size_t len; |
112 | size_t len; |
111 | char *name_buf; |
113 | char *name_buf; |
112 | 114 | ||
113 | if (!ipc_data_write_receive(&callid, &len)) { |
115 | if (!ipc_data_write_receive(&callid, &len)) { |
114 | ipc_answer_0(callid, EINVAL); |
116 | ipc_answer_0(callid, EINVAL); |
115 | ipc_answer_0(rid, EINVAL); |
117 | ipc_answer_0(rid, EINVAL); |
116 | return; |
118 | return; |
117 | } |
119 | } |
118 | 120 | ||
119 | name_buf = malloc(len + 1); |
121 | name_buf = malloc(len + 1); |
120 | if (!name_buf) { |
122 | if (!name_buf) { |
121 | ipc_answer_0(callid, ENOMEM); |
123 | ipc_answer_0(callid, ENOMEM); |
122 | ipc_answer_0(rid, ENOMEM); |
124 | ipc_answer_0(rid, ENOMEM); |
123 | return; |
125 | return; |
124 | } |
126 | } |
125 | 127 | ||
126 | ipc_data_write_finalize(callid, name_buf, len); |
128 | ipc_data_write_finalize(callid, name_buf, len); |
127 | ipc_answer_0(rid, EOK); |
129 | ipc_answer_0(rid, EOK); |
128 | 130 | ||
129 | if (pathname != NULL) { |
131 | if (pathname != NULL) { |
130 | free(pathname); |
132 | free(pathname); |
131 | pathname = NULL; |
133 | pathname = NULL; |
132 | } |
134 | } |
133 | 135 | ||
134 | name_buf[len] = '\0'; |
136 | name_buf[len] = '\0'; |
135 | pathname = name_buf; |
137 | pathname = name_buf; |
136 | } |
138 | } |
137 | 139 | ||
138 | /** Receive a call setting arguments of the program to execute. |
140 | /** Receive a call setting arguments of the program to execute. |
139 | * |
141 | * |
140 | * @param rid |
142 | * @param rid |
141 | * @param request |
143 | * @param request |
142 | */ |
144 | */ |
143 | static void loader_set_args(ipc_callid_t rid, ipc_call_t *request) |
145 | static void loader_set_args(ipc_callid_t rid, ipc_call_t *request) |
144 | { |
146 | { |
145 | ipc_callid_t callid; |
147 | ipc_callid_t callid; |
146 | size_t buf_len, arg_len; |
148 | size_t buf_len, arg_len; |
147 | char *p; |
149 | char *p; |
148 | int n; |
150 | int n; |
149 | 151 | ||
150 | if (!ipc_data_write_receive(&callid, &buf_len)) { |
152 | if (!ipc_data_write_receive(&callid, &buf_len)) { |
151 | ipc_answer_0(callid, EINVAL); |
153 | ipc_answer_0(callid, EINVAL); |
152 | ipc_answer_0(rid, EINVAL); |
154 | ipc_answer_0(rid, EINVAL); |
153 | return; |
155 | return; |
154 | } |
156 | } |
155 | 157 | ||
156 | if (arg_buf != NULL) { |
158 | if (arg_buf != NULL) { |
157 | free(arg_buf); |
159 | free(arg_buf); |
158 | arg_buf = NULL; |
160 | arg_buf = NULL; |
159 | } |
161 | } |
160 | 162 | ||
161 | if (argv != NULL) { |
163 | if (argv != NULL) { |
162 | free(argv); |
164 | free(argv); |
163 | argv = NULL; |
165 | argv = NULL; |
164 | } |
166 | } |
165 | 167 | ||
166 | arg_buf = malloc(buf_len + 1); |
168 | arg_buf = malloc(buf_len + 1); |
167 | if (!arg_buf) { |
169 | if (!arg_buf) { |
168 | ipc_answer_0(callid, ENOMEM); |
170 | ipc_answer_0(callid, ENOMEM); |
169 | ipc_answer_0(rid, ENOMEM); |
171 | ipc_answer_0(rid, ENOMEM); |
170 | return; |
172 | return; |
171 | } |
173 | } |
172 | 174 | ||
173 | ipc_data_write_finalize(callid, arg_buf, buf_len); |
175 | ipc_data_write_finalize(callid, arg_buf, buf_len); |
174 | ipc_answer_0(rid, EOK); |
176 | ipc_answer_0(rid, EOK); |
175 | 177 | ||
176 | arg_buf[buf_len] = '\0'; |
178 | arg_buf[buf_len] = '\0'; |
177 | 179 | ||
178 | /* |
180 | /* |
179 | * Count number of arguments |
181 | * Count number of arguments |
180 | */ |
182 | */ |
181 | p = arg_buf; |
183 | p = arg_buf; |
182 | n = 0; |
184 | n = 0; |
183 | while (p < arg_buf + buf_len) { |
185 | while (p < arg_buf + buf_len) { |
184 | arg_len = strlen(p); |
186 | arg_len = strlen(p); |
185 | p = p + arg_len + 1; |
187 | p = p + arg_len + 1; |
186 | ++n; |
188 | ++n; |
187 | } |
189 | } |
188 | 190 | ||
189 | /* Allocate argv */ |
191 | /* Allocate argv */ |
190 | argv = malloc((n + 1) * sizeof(char *)); |
192 | argv = malloc((n + 1) * sizeof(char *)); |
191 | 193 | ||
192 | if (argv == NULL) { |
194 | if (argv == NULL) { |
193 | free(arg_buf); |
195 | free(arg_buf); |
194 | ipc_answer_0(callid, ENOMEM); |
196 | ipc_answer_0(callid, ENOMEM); |
195 | ipc_answer_0(rid, ENOMEM); |
197 | ipc_answer_0(rid, ENOMEM); |
196 | return; |
198 | return; |
197 | } |
199 | } |
198 | 200 | ||
199 | /* |
201 | /* |
200 | * Fill argv with argument pointers |
202 | * Fill argv with argument pointers |
201 | */ |
203 | */ |
202 | p = arg_buf; |
204 | p = arg_buf; |
203 | n = 0; |
205 | n = 0; |
204 | while (p < arg_buf + buf_len) { |
206 | while (p < arg_buf + buf_len) { |
205 | argv[n] = p; |
207 | argv[n] = p; |
206 | 208 | ||
207 | arg_len = strlen(p); |
209 | arg_len = strlen(p); |
208 | p = p + arg_len + 1; |
210 | p = p + arg_len + 1; |
209 | ++n; |
211 | ++n; |
210 | } |
212 | } |
211 | 213 | ||
212 | argc = n; |
214 | argc = n; |
213 | argv[n] = NULL; |
215 | argv[n] = NULL; |
214 | } |
216 | } |
215 | 217 | ||
216 | /** Load the previously selected program. |
218 | /** Load the previously selected program. |
217 | * |
219 | * |
218 | * @param rid |
220 | * @param rid |
219 | * @param request |
221 | * @param request |
220 | * @return 0 on success, !0 on error. |
222 | * @return 0 on success, !0 on error. |
221 | */ |
223 | */ |
222 | static int loader_load(ipc_callid_t rid, ipc_call_t *request) |
224 | static int loader_load(ipc_callid_t rid, ipc_call_t *request) |
223 | { |
225 | { |
224 | int rc; |
226 | int rc; |
225 | 227 | ||
226 | rc = elf_load_file(pathname, 0, 0, &prog_info); |
228 | rc = elf_load_file(pathname, 0, 0, &prog_info); |
227 | if (rc < 0) { |
229 | if (rc < 0) { |
228 | printf("Failed to load executable '%s'.\n", pathname); |
230 | printf("Failed to load executable '%s'.\n", pathname); |
229 | ipc_answer_0(rid, EINVAL); |
231 | ipc_answer_0(rid, EINVAL); |
230 | return 1; |
232 | return 1; |
231 | } |
233 | } |
232 | 234 | ||
233 | elf_create_pcb(&prog_info, &pcb); |
235 | elf_create_pcb(&prog_info, &pcb); |
234 | 236 | ||
235 | pcb.argc = argc; |
237 | pcb.argc = argc; |
236 | pcb.argv = argv; |
238 | pcb.argv = argv; |
237 | 239 | ||
238 | if (prog_info.interp == NULL) { |
240 | if (prog_info.interp == NULL) { |
239 | /* Statically linked program */ |
241 | /* Statically linked program */ |
240 | is_dyn_linked = false; |
242 | is_dyn_linked = false; |
241 | ipc_answer_0(rid, EOK); |
243 | ipc_answer_0(rid, EOK); |
242 | return 0; |
244 | return 0; |
243 | } |
245 | } |
244 | 246 | ||
245 | printf("Load ELF interpreter '%s'\n", prog_info.interp); |
247 | printf("Load ELF interpreter '%s'\n", prog_info.interp); |
246 | rc = elf_load_file(prog_info.interp, 0, 0, &interp_info); |
248 | rc = elf_load_file(prog_info.interp, 0, 0, &interp_info); |
247 | if (rc < 0) { |
249 | if (rc < 0) { |
248 | printf("Failed to load interpreter '%s.'\n", prog_info.interp); |
250 | printf("Failed to load interpreter '%s.'\n", prog_info.interp); |
249 | ipc_answer_0(rid, EINVAL); |
251 | ipc_answer_0(rid, EINVAL); |
250 | return 1; |
252 | return 1; |
251 | } |
253 | } |
252 | 254 | ||
253 | printf("Run interpreter.\n"); |
255 | printf("Run interpreter.\n"); |
254 | printf("entry point: 0x%lx\n", interp_info.entry); |
256 | printf("entry point: 0x%lx\n", interp_info.entry); |
255 | printf("pcb address: 0x%lx\n", &pcb); |
257 | printf("pcb address: 0x%lx\n", &pcb); |
256 | 258 | ||
257 | is_dyn_linked = true; |
259 | is_dyn_linked = true; |
258 | ipc_answer_0(rid, EOK); |
260 | ipc_answer_0(rid, EOK); |
259 | 261 | ||
260 | return 0; |
262 | return 0; |
261 | } |
263 | } |
262 | 264 | ||
263 | 265 | ||
264 | /** Run the previously loaded program. |
266 | /** Run the previously loaded program. |
265 | * |
267 | * |
266 | * @param rid |
268 | * @param rid |
267 | * @param request |
269 | * @param request |
268 | * @return 0 on success, !0 on error. |
270 | * @return 0 on success, !0 on error. |
269 | */ |
271 | */ |
270 | static void loader_run(ipc_callid_t rid, ipc_call_t *request) |
272 | static void loader_run(ipc_callid_t rid, ipc_call_t *request) |
271 | { |
273 | { |
272 | if (is_dyn_linked == true) { |
274 | if (is_dyn_linked == true) { |
273 | /* Dynamically linked program */ |
275 | /* Dynamically linked program */ |
274 | printf("run dynamic linker\n"); |
276 | printf("run dynamic linker\n"); |
275 | printf("entry point: 0x%lx\n", interp_info.entry); |
277 | printf("entry point: 0x%lx\n", interp_info.entry); |
276 | close_console(); |
278 | close_console(); |
277 | 279 | ||
278 | ipc_answer_0(rid, EOK); |
280 | ipc_answer_0(rid, EOK); |
279 | elf_run(&interp_info, &pcb); |
281 | program_run(interp_info.entry, &pcb); |
280 | 282 | ||
281 | } else { |
283 | } else { |
282 | /* Statically linked program */ |
284 | /* Statically linked program */ |
283 | close_console(); |
285 | close_console(); |
284 | ipc_answer_0(rid, EOK); |
286 | ipc_answer_0(rid, EOK); |
285 | elf_run(&prog_info, &pcb); |
287 | program_run(prog_info.entry, &pcb); |
286 | } |
288 | } |
287 | 289 | ||
288 | /* Not reached */ |
290 | /* Not reached */ |
289 | } |
291 | } |
290 | 292 | ||
291 | /** Handle loader connection. |
293 | /** Handle loader connection. |
292 | * |
294 | * |
293 | * Receive and carry out commands (of which the last one should be |
295 | * Receive and carry out commands (of which the last one should be |
294 | * to execute the loaded program). |
296 | * to execute the loaded program). |
295 | */ |
297 | */ |
296 | static void loader_connection(ipc_callid_t iid, ipc_call_t *icall) |
298 | static void loader_connection(ipc_callid_t iid, ipc_call_t *icall) |
297 | { |
299 | { |
298 | ipc_callid_t callid; |
300 | ipc_callid_t callid; |
299 | ipc_call_t call; |
301 | ipc_call_t call; |
300 | int retval; |
302 | int retval; |
301 | 303 | ||
302 | /* Ignore parameters, the connection is already open */ |
304 | /* Ignore parameters, the connection is already open */ |
303 | (void)iid; (void)icall; |
305 | (void)iid; (void)icall; |
304 | 306 | ||
305 | while (1) { |
307 | while (1) { |
306 | callid = async_get_call(&call); |
308 | callid = async_get_call(&call); |
307 | 309 | ||
308 | switch (IPC_GET_METHOD(call)) { |
310 | switch (IPC_GET_METHOD(call)) { |
309 | case IPC_M_PHONE_HUNGUP: |
311 | case IPC_M_PHONE_HUNGUP: |
310 | exit(0); |
312 | exit(0); |
311 | case LOADER_GET_TASKID: |
313 | case LOADER_GET_TASKID: |
312 | loader_get_taskid(callid, &call); |
314 | loader_get_taskid(callid, &call); |
313 | continue; |
315 | continue; |
314 | case LOADER_SET_PATHNAME: |
316 | case LOADER_SET_PATHNAME: |
315 | loader_set_pathname(callid, &call); |
317 | loader_set_pathname(callid, &call); |
316 | continue; |
318 | continue; |
317 | case LOADER_SET_ARGS: |
319 | case LOADER_SET_ARGS: |
318 | loader_set_args(callid, &call); |
320 | loader_set_args(callid, &call); |
319 | continue; |
321 | continue; |
320 | case LOADER_LOAD: |
322 | case LOADER_LOAD: |
321 | loader_load(callid, &call); |
323 | loader_load(callid, &call); |
322 | continue; |
324 | continue; |
323 | case LOADER_RUN: |
325 | case LOADER_RUN: |
324 | loader_run(callid, &call); |
326 | loader_run(callid, &call); |
325 | /* Not reached */ |
327 | /* Not reached */ |
326 | default: |
328 | default: |
327 | retval = ENOENT; |
329 | retval = ENOENT; |
328 | break; |
330 | break; |
329 | } |
331 | } |
330 | if ((callid & IPC_CALLID_NOTIFICATION) == 0 && |
332 | if ((callid & IPC_CALLID_NOTIFICATION) == 0 && |
331 | IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) { |
333 | IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) { |
332 | printf("responding EINVAL to method %d\n", |
334 | printf("responding EINVAL to method %d\n", |
333 | IPC_GET_METHOD(call)); |
335 | IPC_GET_METHOD(call)); |
334 | ipc_answer_0(callid, EINVAL); |
336 | ipc_answer_0(callid, EINVAL); |
335 | } |
337 | } |
336 | } |
338 | } |
337 | } |
339 | } |
338 | 340 | ||
339 | /** Program loader main function. |
341 | /** Program loader main function. |
340 | */ |
342 | */ |
341 | int main(int argc, char *argv[]) |
343 | int main(int argc, char *argv[]) |
342 | { |
344 | { |
343 | ipc_callid_t callid; |
345 | ipc_callid_t callid; |
344 | ipc_call_t call; |
346 | ipc_call_t call; |
345 | ipcarg_t phone_hash; |
347 | ipcarg_t phone_hash; |
346 | 348 | ||
347 | /* The first call only communicates the incoming phone hash */ |
349 | /* The first call only communicates the incoming phone hash */ |
348 | callid = ipc_wait_for_call(&call); |
350 | callid = ipc_wait_for_call(&call); |
349 | 351 | ||
350 | if (IPC_GET_METHOD(call) != LOADER_HELLO) { |
352 | if (IPC_GET_METHOD(call) != LOADER_HELLO) { |
351 | if (IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) |
353 | if (IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) |
352 | ipc_answer_0(callid, EINVAL); |
354 | ipc_answer_0(callid, EINVAL); |
353 | return 1; |
355 | return 1; |
354 | } |
356 | } |
355 | 357 | ||
356 | ipc_answer_0(callid, EOK); |
358 | ipc_answer_0(callid, EOK); |
357 | phone_hash = call.in_phone_hash; |
359 | phone_hash = call.in_phone_hash; |
358 | 360 | ||
359 | /* |
361 | /* |
360 | * Up until now async must not be used as it couldn't |
362 | * Up until now async must not be used as it couldn't |
361 | * handle incoming requests. (Which means e.g. printf() |
363 | * handle incoming requests. (Which means e.g. printf() |
362 | * cannot be used) |
364 | * cannot be used) |
363 | */ |
365 | */ |
364 | async_new_connection(phone_hash, 0, NULL, loader_connection); |
366 | async_new_connection(phone_hash, 0, NULL, loader_connection); |
365 | async_manager(); |
367 | async_manager(); |
366 | 368 | ||
367 | /* not reached */ |
369 | /* not reached */ |
368 | return 0; |
370 | return 0; |
369 | } |
371 | } |
370 | 372 | ||
371 | /** @} |
373 | /** @} |
372 | */ |
374 | */ |
373 | 375 |