Rev 3101 | Rev 3155 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3101 | Rev 3148 | ||
---|---|---|---|
Line 47... | Line 47... | ||
47 | #include <stdlib.h> |
47 | #include <stdlib.h> |
48 | #include <unistd.h> |
48 | #include <unistd.h> |
49 | #include <fcntl.h> |
49 | #include <fcntl.h> |
50 | #include <sys/types.h> |
50 | #include <sys/types.h> |
51 | #include <ipc/ipc.h> |
51 | #include <ipc/ipc.h> |
- | 52 | #include <ipc/loader.h> |
|
52 | #include <errno.h> |
53 | #include <errno.h> |
- | 54 | #include <async.h> |
|
53 | #include <as.h> |
55 | #include <as.h> |
54 | 56 | ||
55 | #include <elf.h> |
57 | #include <elf.h> |
56 | #include <elf_load.h> |
58 | #include <elf_load.h> |
57 | #include <pcb.h> |
59 | #include <pcb.h> |
Line 68... | Line 70... | ||
68 | /** Receive a call setting pathname of the program to execute. |
70 | /** Receive a call setting pathname of the program to execute. |
69 | * |
71 | * |
70 | * @param rid |
72 | * @param rid |
71 | * @param request |
73 | * @param request |
72 | */ |
74 | */ |
73 | void iloader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
75 | static void iloader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
74 | { |
76 | { |
75 | // ipc_callid_t callid; |
77 | ipc_callid_t callid; |
76 | size_t len; |
78 | size_t len; |
77 | char *name_buf; |
79 | char *name_buf; |
78 | 80 | ||
79 | /* printf("iloader_set_pathname\n"); |
81 | printf("iloader_set_pathname\n"); |
80 | if (!ipc_data_write_receive(&callid, &len)) { |
82 | if (!ipc_data_write_receive(&callid, &len)) { |
81 | ipc_answer_0(callid, EINVAL); |
83 | ipc_answer_0(callid, EINVAL); |
82 | ipc_answer_0(rid, EINVAL); |
84 | ipc_answer_0(rid, EINVAL); |
83 | return; |
85 | return; |
84 | } |
86 | } |
85 | */ |
87 | |
86 | len = IPC_GET_ARG2(*request); |
- | |
87 | printf("alloc %d bytes\n", len+1); |
88 | printf("alloc %d bytes\n", len+1); |
88 | 89 | ||
89 | name_buf = malloc(len + 1); |
90 | name_buf = malloc(len + 1); |
90 | if (!name_buf) { |
91 | if (!name_buf) { |
91 | // ipc_answer_0(callid, ENOMEM); |
92 | ipc_answer_0(callid, ENOMEM); |
92 | ipc_answer_0(rid, ENOMEM); |
93 | ipc_answer_0(rid, ENOMEM); |
93 | return; |
94 | return; |
94 | } |
95 | } |
95 | 96 | ||
96 | printf("write_finalize\n"); |
97 | printf("write_finalize\n"); |
97 | ipc_data_write_finalize(rid, name_buf, len); |
98 | ipc_data_write_finalize(callid, name_buf, len); |
- | 99 | printf("answer\n"); |
|
98 | // ipc_answer_0(rid, EOK); |
100 | ipc_answer_0(rid, EOK); |
99 | 101 | ||
100 | if (pathname != NULL) { |
102 | if (pathname != NULL) { |
101 | free(pathname); |
103 | free(pathname); |
102 | pathname = NULL; |
104 | pathname = NULL; |
103 | } |
105 | } |
104 | 106 | ||
- | 107 | name_buf[len] = '\0'; |
|
105 | pathname = name_buf; |
108 | pathname = name_buf; |
106 | } |
109 | } |
107 | 110 | ||
108 | /** Load and run the previously selected program. |
111 | /** Load and run the previously selected program. |
109 | * |
112 | * |
110 | * @param rid |
113 | * @param rid |
111 | * @param request |
114 | * @param request |
112 | * @return 0 on success, !0 on error. |
115 | * @return 0 on success, !0 on error. |
113 | */ |
116 | */ |
114 | int iloader_run(ipc_callid_t rid, ipc_call_t *request) |
117 | static int iloader_run(ipc_callid_t rid, ipc_call_t *request) |
115 | { |
118 | { |
116 | int rc; |
119 | int rc; |
117 | pcb_t *pcb; |
120 | pcb_t *pcb; |
118 | 121 | ||
119 | elf_info_t prog_info; |
122 | elf_info_t prog_info; |
Line 155... | Line 158... | ||
155 | elf_run(&interp_info); |
158 | elf_run(&interp_info); |
156 | 159 | ||
157 | return 0; |
160 | return 0; |
158 | } |
161 | } |
159 | 162 | ||
160 | /** Program loader main function. |
163 | /** Handle loader connection. |
161 | * |
164 | * |
162 | * Receive and carry out commands (of which the last one should be |
165 | * Receive and carry out commands (of which the last one should be |
163 | * to execute the loaded program). |
166 | * to execute the loaded program). |
164 | */ |
167 | */ |
165 | int main(int argc, char *argv[]) |
168 | static void loader_connection(ipc_callid_t iid, ipc_call_t *icall) |
166 | { |
169 | { |
167 | ipc_callid_t callid; |
170 | ipc_callid_t callid; |
168 | ipc_call_t call; |
171 | ipc_call_t call; |
169 | int retval; |
172 | int retval; |
- | 173 | ||
- | 174 | /* Ignore parameters, the connection is already open */ |
|
170 | int len; |
175 | (void)iid; (void)icall; |
171 | 176 | ||
172 | while (1) { |
177 | while (1) { |
173 | callid = ipc_wait_for_call(&call); |
178 | callid = async_get_call(&call); |
- | 179 | printf("received call from phone %d, method=%d\n", |
|
174 | printf("received call, method=%d\n", IPC_GET_METHOD(call)); |
180 | call.in_phone_hash, IPC_GET_METHOD(call)); |
175 | switch (IPC_GET_METHOD(call)) { |
181 | switch (IPC_GET_METHOD(call)) { |
176 | case IPC_M_DATA_WRITE: |
182 | case LOADER_SET_PATHNAME: |
177 | iloader_set_pathname(callid, &call); |
183 | iloader_set_pathname(callid, &call); |
- | 184 | continue; |
|
- | 185 | case LOADER_RUN: |
|
178 | iloader_run(callid, &call); |
186 | iloader_run(callid, &call); |
179 | exit(0); |
187 | exit(0); |
180 | continue; |
188 | continue; |
181 | default: |
189 | default: |
182 | retval = ENOENT; |
190 | retval = ENOENT; |
Line 185... | Line 193... | ||
185 | if ((callid & IPC_CALLID_NOTIFICATION) == 0) { |
193 | if ((callid & IPC_CALLID_NOTIFICATION) == 0) { |
186 | printf("responding EINVAL to method %d\n", IPC_GET_METHOD(call)); |
194 | printf("responding EINVAL to method %d\n", IPC_GET_METHOD(call)); |
187 | ipc_answer_0(callid, EINVAL); |
195 | ipc_answer_0(callid, EINVAL); |
188 | } |
196 | } |
189 | } |
197 | } |
- | 198 | } |
|
- | 199 | ||
- | 200 | /** Program loader main function. |
|
- | 201 | */ |
|
- | 202 | int main(int argc, char *argv[]) |
|
- | 203 | { |
|
- | 204 | ipc_callid_t callid; |
|
- | 205 | ipc_call_t call; |
|
- | 206 | ipcarg_t phone_hash; |
|
- | 207 | ||
- | 208 | /* The first call only communicates the incoming phone hash */ |
|
- | 209 | callid = ipc_wait_for_call(&call); |
|
- | 210 | ||
- | 211 | if (IPC_GET_METHOD(call) != LOADER_HELLO) { |
|
- | 212 | if (IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) |
|
- | 213 | ipc_answer_0(callid, EINVAL); |
|
- | 214 | return 1; |
|
- | 215 | } |
|
- | 216 | ||
- | 217 | ipc_answer_0(callid, EOK); |
|
- | 218 | phone_hash = call.in_phone_hash; |
|
- | 219 | ||
- | 220 | /* |
|
- | 221 | * FIXME: up until now no async calls can be used!!! |
|
- | 222 | * (Which means e.g. printf() cannot be used) |
|
- | 223 | */ |
|
- | 224 | async_new_connection(phone_hash, 0, NULL, loader_connection); |
|
- | 225 | async_manager(); |
|
190 | 226 | ||
191 | /* not reached */ |
227 | /* not reached */ |
192 | return 0; |
228 | return 0; |
193 | } |
229 | } |
194 | 230 |