Rev 3597 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3597 | Rev 4377 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <ipc/ipc.h> |
35 | #include <ipc/ipc.h> |
36 | #include <ipc/loader.h> |
36 | #include <ipc/loader.h> |
- | 37 | #include <ipc/services.h> |
|
37 | #include <libc.h> |
38 | #include <libc.h> |
38 | #include <task.h> |
39 | #include <task.h> |
39 | #include <string.h> |
40 | #include <string.h> |
40 | #include <stdlib.h> |
41 | #include <stdlib.h> |
41 | #include <async.h> |
42 | #include <async.h> |
Line 48... | Line 49... | ||
48 | * Spawns a new program loader task and returns the connection structure. |
49 | * Spawns a new program loader task and returns the connection structure. |
49 | * @param name Symbolic name to set on the newly created task. |
50 | * @param name Symbolic name to set on the newly created task. |
50 | * @return Pointer to the loader connection structure (should be |
51 | * @return Pointer to the loader connection structure (should be |
51 | * de-allocated using free() after use). |
52 | * de-allocated using free() after use). |
52 | */ |
53 | */ |
53 | loader_t *loader_spawn(char *name) |
54 | int loader_spawn(const char *name) |
54 | { |
55 | { |
55 | int phone_id, rc; |
56 | return __SYSCALL2(SYS_PROGRAM_SPAWN_LOADER, |
56 | loader_t *ldr; |
57 | (sysarg_t) name, str_size(name)); |
- | 58 | } |
|
57 | 59 | ||
58 | /* |
- | |
59 | * Ask kernel to spawn a new loader task. |
60 | loader_t *loader_connect(void) |
60 | */ |
61 | { |
61 | rc = __SYSCALL3(SYS_PROGRAM_SPAWN_LOADER, (sysarg_t) &phone_id, |
- | |
62 | (sysarg_t) name, strlen(name)); |
- | |
63 | if (rc != 0) |
62 | loader_t *ldr; |
64 | return NULL; |
63 | int phone_id; |
65 | 64 | ||
66 | /* |
- | |
67 | * Say hello so that the loader knows the incoming connection's |
- | |
68 | * phone hash. |
- | |
69 | */ |
- | |
70 | rc = async_req_0_0(phone_id, LOADER_HELLO); |
65 | phone_id = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_LOAD, 0, 0); |
71 | if (rc != EOK) |
66 | if (phone_id < 0) |
72 | return NULL; |
67 | return NULL; |
73 | 68 | ||
74 | ldr = malloc(sizeof(loader_t)); |
69 | ldr = malloc(sizeof(loader_t)); |
75 | if (ldr == NULL) |
70 | if (ldr == NULL) |
76 | return NULL; |
71 | return NULL; |
77 | 72 | ||
78 | ldr->phone_id = phone_id; |
73 | ldr->phone_id = phone_id; |
79 | return ldr; |
74 | return ldr; |
80 | } |
75 | } |
81 | 76 | ||
82 | /** Get ID of the new task. |
77 | /** Get ID of the new task. |
83 | * |
78 | * |
84 | * Retrieves the ID of the new task from the loader. |
79 | * Retrieves the ID of the new task from the loader. |
Line 171... | Line 166... | ||
171 | * compute size of the buffer needed. |
166 | * compute size of the buffer needed. |
172 | */ |
167 | */ |
173 | ap = argv; |
168 | ap = argv; |
174 | buffer_size = 0; |
169 | buffer_size = 0; |
175 | while (*ap != NULL) { |
170 | while (*ap != NULL) { |
176 | buffer_size += strlen(*ap) + 1; |
171 | buffer_size += str_size(*ap) + 1; |
177 | ++ap; |
172 | ++ap; |
178 | } |
173 | } |
179 | 174 | ||
180 | arg_buf = malloc(buffer_size); |
175 | arg_buf = malloc(buffer_size); |
181 | if (arg_buf == NULL) return ENOMEM; |
176 | if (arg_buf == NULL) return ENOMEM; |
182 | 177 | ||
183 | /* Now fill the buffer with null-terminated argument strings */ |
178 | /* Now fill the buffer with null-terminated argument strings */ |
184 | ap = argv; |
179 | ap = argv; |
185 | dp = arg_buf; |
180 | dp = arg_buf; |
- | 181 | ||
186 | while (*ap != NULL) { |
182 | while (*ap != NULL) { |
187 | strcpy(dp, *ap); |
183 | str_cpy(dp, buffer_size - (dp - arg_buf), *ap); |
188 | dp += strlen(*ap) + 1; |
184 | dp += str_size(*ap) + 1; |
189 | 185 | ||
190 | ++ap; |
186 | ++ap; |
191 | } |
187 | } |
192 | 188 | ||
193 | /* Send serialized arguments to the loader */ |
189 | /* Send serialized arguments to the loader */ |
Line 245... | Line 241... | ||
245 | 241 | ||
246 | rc = async_req_0_0(ldr->phone_id, LOADER_RUN); |
242 | rc = async_req_0_0(ldr->phone_id, LOADER_RUN); |
247 | if (rc != EOK) |
243 | if (rc != EOK) |
248 | return rc; |
244 | return rc; |
249 | 245 | ||
- | 246 | ipc_hangup(ldr->phone_id); |
|
- | 247 | ldr->phone_id = 0; |
|
250 | return EOK; |
248 | return EOK; |
251 | } |
249 | } |
252 | 250 | ||
253 | /** Cancel the loader session. |
251 | /** Cancel the loader session. |
254 | * |
252 | * |