Rev 3150 | Rev 3190 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3150 | Rev 3174 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | #include <task.h> |
36 | #include <task.h> |
37 | #include <ipc/ipc.h> |
37 | #include <ipc/ipc.h> |
38 | #include <ipc/loader.h> |
38 | #include <ipc/loader.h> |
39 | #include <libc.h> |
39 | #include <libc.h> |
40 | #include <string.h> |
40 | #include <string.h> |
- | 41 | #include <stdlib.h> |
|
41 | #include <async.h> |
42 | #include <async.h> |
42 | #include <errno.h> |
43 | #include <errno.h> |
43 | 44 | ||
44 | task_id_t task_get_id(void) |
45 | task_id_t task_get_id(void) |
45 | { |
46 | { |
Line 59... | Line 60... | ||
59 | return rc; |
60 | return rc; |
60 | 61 | ||
61 | return phone_id; |
62 | return phone_id; |
62 | } |
63 | } |
63 | 64 | ||
- | 65 | static int loader_set_args(int phone_id, const char *argv[]) |
|
- | 66 | { |
|
- | 67 | aid_t req; |
|
- | 68 | ipc_call_t answer; |
|
- | 69 | int rc; |
|
- | 70 | ||
- | 71 | const char **ap; |
|
- | 72 | char *dp; |
|
- | 73 | char *arg_buf; |
|
- | 74 | size_t buffer_size; |
|
- | 75 | size_t len; |
|
- | 76 | ||
- | 77 | /* |
|
- | 78 | * Serialize the arguments into a single array. First |
|
- | 79 | * compute size of the buffer needed. |
|
- | 80 | */ |
|
- | 81 | ap = argv; |
|
- | 82 | buffer_size = 0; |
|
- | 83 | while (*ap != NULL) { |
|
- | 84 | buffer_size += strlen(*ap) + 1; |
|
- | 85 | ++ap; |
|
- | 86 | } |
|
- | 87 | ||
- | 88 | arg_buf = malloc(buffer_size); |
|
- | 89 | if (arg_buf == NULL) return ENOMEM; |
|
- | 90 | ||
- | 91 | /* Now fill the buffer with null-terminated argument strings */ |
|
- | 92 | ap = argv; |
|
- | 93 | dp = arg_buf; |
|
- | 94 | while (*ap != NULL) { |
|
- | 95 | strcpy(dp, *ap); |
|
- | 96 | dp += strlen(*ap) + 1; |
|
- | 97 | ||
- | 98 | ++ap; |
|
- | 99 | } |
|
- | 100 | ||
- | 101 | /* Send serialized arguments to the loader */ |
|
- | 102 | ||
- | 103 | req = async_send_0(phone_id, LOADER_SET_ARGS, &answer); |
|
- | 104 | rc = ipc_data_write_start(phone_id, (void *)arg_buf, buffer_size); |
|
- | 105 | if (rc != EOK) { |
|
- | 106 | async_wait_for(req, NULL); |
|
- | 107 | return rc; |
|
- | 108 | } |
|
- | 109 | ||
- | 110 | async_wait_for(req, &rc); |
|
- | 111 | if (rc != EOK) return rc; |
|
- | 112 | ||
- | 113 | /* Free temporary buffer */ |
|
- | 114 | free(arg_buf); |
|
- | 115 | ||
- | 116 | return EOK; |
|
- | 117 | } |
|
- | 118 | ||
64 | /** Create a new task by running an executable from VFS. |
119 | /** Create a new task by running an executable from VFS. |
65 | * |
120 | * |
66 | * @param path pathname of the binary to execute |
121 | * @param path pathname of the binary to execute |
67 | * @param argv command-line arguments |
122 | * @param argv command-line arguments |
68 | * @return ID of the newly created task or zero on error. |
123 | * @return ID of the newly created task or zero on error. |
Line 92... | Line 147... | ||
92 | async_wait_for(req, NULL); |
147 | async_wait_for(req, NULL); |
93 | return 1; |
148 | return 1; |
94 | } |
149 | } |
95 | 150 | ||
96 | async_wait_for(req, &rc); |
151 | async_wait_for(req, &rc); |
97 | if (rc != EOK) return 0; |
152 | if (rc != EOK) goto error; |
- | 153 | ||
- | 154 | /* Send arguments */ |
|
- | 155 | rc = loader_set_args(phone_id, argv); |
|
- | 156 | if (rc != EOK) goto error; |
|
98 | 157 | ||
99 | /* Request loader to start the program */ |
158 | /* Request loader to start the program */ |
100 | rc = async_req_0_0(phone_id, LOADER_RUN); |
159 | rc = async_req_0_0(phone_id, LOADER_RUN); |
101 | if (rc != EOK) return 0; |
160 | if (rc != EOK) goto error; |
102 | 161 | ||
- | 162 | /* Success */ |
|
103 | ipc_hangup(phone_id); |
163 | ipc_hangup(phone_id); |
104 | - | ||
105 | return 1; |
164 | return 1; |
- | 165 | ||
- | 166 | /* Error exit */ |
|
- | 167 | error: |
|
- | 168 | ipc_hangup(phone_id); |
|
- | 169 | return 0; |
|
106 | } |
170 | } |
107 | 171 | ||
108 | int task_spawn(void *image, size_t size) |
172 | int task_spawn(void *image, size_t size) |
109 | { |
173 | { |
110 | return __SYSCALL2(SYS_TASK_SPAWN, (sysarg_t) image, (sysarg_t) size); |
174 | return __SYSCALL2(SYS_TASK_SPAWN, (sysarg_t) image, (sysarg_t) size); |