Rev 3171 | Rev 3400 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3171 | Rev 3174 | ||
---|---|---|---|
Line 68... | Line 68... | ||
68 | static char *pathname = NULL; |
68 | static char *pathname = NULL; |
69 | 69 | ||
70 | /** The Program control block */ |
70 | /** The Program control block */ |
71 | static pcb_t pcb; |
71 | static pcb_t pcb; |
72 | 72 | ||
- | 73 | /** Number of arguments */ |
|
- | 74 | static int argc = 0; |
|
- | 75 | /** Argument vector */ |
|
- | 76 | static char **argv = NULL; |
|
- | 77 | /** Buffer holding all arguments */ |
|
- | 78 | static char *arg_buf = NULL; |
|
- | 79 | ||
73 | /** Receive a call setting pathname of the program to execute. |
80 | /** Receive a call setting pathname of the program to execute. |
74 | * |
81 | * |
75 | * @param rid |
82 | * @param rid |
76 | * @param request |
83 | * @param request |
77 | */ |
84 | */ |
78 | static void iloader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
85 | static void loader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
79 | { |
86 | { |
80 | ipc_callid_t callid; |
87 | ipc_callid_t callid; |
81 | size_t len; |
88 | size_t len; |
82 | char *name_buf; |
89 | char *name_buf; |
83 | 90 | ||
Line 104... | Line 111... | ||
104 | 111 | ||
105 | name_buf[len] = '\0'; |
112 | name_buf[len] = '\0'; |
106 | pathname = name_buf; |
113 | pathname = name_buf; |
107 | } |
114 | } |
108 | 115 | ||
- | 116 | /** Receive a call setting arguments of the program to execute. |
|
- | 117 | * |
|
- | 118 | * @param rid |
|
- | 119 | * @param request |
|
- | 120 | */ |
|
- | 121 | static void loader_set_args(ipc_callid_t rid, ipc_call_t *request) |
|
- | 122 | { |
|
- | 123 | ipc_callid_t callid; |
|
- | 124 | size_t buf_len, arg_len; |
|
- | 125 | char *p; |
|
- | 126 | int n; |
|
- | 127 | ||
- | 128 | if (!ipc_data_write_receive(&callid, &buf_len)) { |
|
- | 129 | ipc_answer_0(callid, EINVAL); |
|
- | 130 | ipc_answer_0(rid, EINVAL); |
|
- | 131 | return; |
|
- | 132 | } |
|
- | 133 | ||
- | 134 | if (arg_buf != NULL) { |
|
- | 135 | free(arg_buf); |
|
- | 136 | arg_buf = NULL; |
|
- | 137 | } |
|
- | 138 | ||
- | 139 | if (argv != NULL) { |
|
- | 140 | free(argv); |
|
- | 141 | argv = NULL; |
|
- | 142 | } |
|
- | 143 | ||
- | 144 | arg_buf = malloc(buf_len + 1); |
|
- | 145 | if (!arg_buf) { |
|
- | 146 | ipc_answer_0(callid, ENOMEM); |
|
- | 147 | ipc_answer_0(rid, ENOMEM); |
|
- | 148 | return; |
|
- | 149 | } |
|
- | 150 | ||
- | 151 | ipc_data_write_finalize(callid, arg_buf, buf_len); |
|
- | 152 | ipc_answer_0(rid, EOK); |
|
- | 153 | ||
- | 154 | arg_buf[buf_len] = '\0'; |
|
- | 155 | ||
- | 156 | /* |
|
- | 157 | * Count number of arguments |
|
- | 158 | */ |
|
- | 159 | p = arg_buf; |
|
- | 160 | n = 0; |
|
- | 161 | while (p < arg_buf + buf_len) { |
|
- | 162 | arg_len = strlen(p); |
|
- | 163 | p = p + arg_len + 1; |
|
- | 164 | ++n; |
|
- | 165 | } |
|
- | 166 | ||
- | 167 | /* Allocate argv */ |
|
- | 168 | argv = malloc((n + 1) * sizeof(char *)); |
|
- | 169 | ||
- | 170 | if (argv == NULL) { |
|
- | 171 | free(arg_buf); |
|
- | 172 | ipc_answer_0(callid, ENOMEM); |
|
- | 173 | ipc_answer_0(rid, ENOMEM); |
|
- | 174 | return; |
|
- | 175 | } |
|
- | 176 | ||
- | 177 | /* |
|
- | 178 | * Fill argv with argument pointers |
|
- | 179 | */ |
|
- | 180 | p = arg_buf; |
|
- | 181 | n = 0; |
|
- | 182 | while (p < arg_buf + buf_len) { |
|
- | 183 | argv[n] = p; |
|
- | 184 | ||
- | 185 | arg_len = strlen(p); |
|
- | 186 | p = p + arg_len + 1; |
|
- | 187 | ++n; |
|
- | 188 | } |
|
- | 189 | ||
- | 190 | argc = n; |
|
- | 191 | argv[n] = NULL; |
|
- | 192 | } |
|
- | 193 | ||
- | 194 | ||
109 | /** Load and run the previously selected program. |
195 | /** Load and run the previously selected program. |
110 | * |
196 | * |
111 | * @param rid |
197 | * @param rid |
112 | * @param request |
198 | * @param request |
113 | * @return 0 on success, !0 on error. |
199 | * @return 0 on success, !0 on error. |
114 | */ |
200 | */ |
115 | static int iloader_run(ipc_callid_t rid, ipc_call_t *request) |
201 | static int loader_run(ipc_callid_t rid, ipc_call_t *request) |
116 | { |
202 | { |
117 | int rc; |
203 | int rc; |
118 | 204 | ||
119 | elf_info_t prog_info; |
205 | elf_info_t prog_info; |
120 | elf_info_t interp_info; |
206 | elf_info_t interp_info; |
Line 129... | Line 215... | ||
129 | } |
215 | } |
130 | 216 | ||
131 | // printf("Create PCB\n"); |
217 | // printf("Create PCB\n"); |
132 | elf_create_pcb(&prog_info, &pcb); |
218 | elf_create_pcb(&prog_info, &pcb); |
133 | 219 | ||
134 | pcb.argc = 0; |
220 | pcb.argc = argc; |
135 | pcb.argv = NULL; |
221 | pcb.argv = argv; |
136 | 222 | ||
137 | if (prog_info.interp == NULL) { |
223 | if (prog_info.interp == NULL) { |
138 | /* Statically linked program */ |
224 | /* Statically linked program */ |
139 | // printf("Run statically linked program\n"); |
225 | // printf("Run statically linked program\n"); |
140 | // printf("entry point: 0x%llx\n", prog_info.entry); |
226 | // printf("entry point: 0x%llx\n", prog_info.entry); |
Line 187... | Line 273... | ||
187 | callid = async_get_call(&call); |
273 | callid = async_get_call(&call); |
188 | // printf("received call from phone %d, method=%d\n", |
274 | // printf("received call from phone %d, method=%d\n", |
189 | // call.in_phone_hash, IPC_GET_METHOD(call)); |
275 | // call.in_phone_hash, IPC_GET_METHOD(call)); |
190 | switch (IPC_GET_METHOD(call)) { |
276 | switch (IPC_GET_METHOD(call)) { |
191 | case LOADER_SET_PATHNAME: |
277 | case LOADER_SET_PATHNAME: |
192 | iloader_set_pathname(callid, &call); |
278 | loader_set_pathname(callid, &call); |
193 | continue; |
279 | continue; |
- | 280 | case LOADER_SET_ARGS: |
|
- | 281 | loader_set_args(callid, &call); |
|
194 | case LOADER_RUN: |
282 | case LOADER_RUN: |
195 | iloader_run(callid, &call); |
283 | loader_run(callid, &call); |
196 | exit(0); |
284 | exit(0); |
197 | continue; |
285 | continue; |
198 | default: |
286 | default: |
199 | retval = ENOENT; |
287 | retval = ENOENT; |
200 | break; |
288 | break; |
201 | } |
289 | } |
202 | if ((callid & IPC_CALLID_NOTIFICATION) == 0) { |
290 | if ((callid & IPC_CALLID_NOTIFICATION) == 0 && |
- | 291 | IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) { |
|
203 | printf("responding EINVAL to method %d\n", IPC_GET_METHOD(call)); |
292 | printf("responding EINVAL to method %d\n", |
- | 293 | IPC_GET_METHOD(call)); |
|
204 | ipc_answer_0(callid, EINVAL); |
294 | ipc_answer_0(callid, EINVAL); |
205 | } |
295 | } |
206 | } |
296 | } |
207 | } |
297 | } |
208 | 298 |