Changeset 2443ad8 in mainline for uspace/lib/c
- Timestamp:
- 2019-10-02T09:27:57Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9dcf472
- Parents:
- 6fa3a03
- git-author:
- Jiri Svoboda <jiri@…> (2019-10-01 17:23:52)
- git-committer:
- Jiri Svoboda <jiri@…> (2019-10-02 09:27:57)
- Location:
- uspace/lib/c
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/loader.c
r6fa3a03 r2443ad8 345 345 } 346 346 347 /** Instruct loader to execute the program and do not wait for reply. 348 * 349 * This function does not block even if the loaded task is stopped 350 * for debugging. 351 * 352 * After using this function, no further operations can be performed 353 * on the loader structure and it is deallocated. 354 * 355 * @param ldr Loader connection structure. 356 * 357 * @return Zero on success or an error code. 358 * 359 */ 360 void loader_run_nowait(loader_t *ldr) 361 { 362 async_exch_t *exch = async_exchange_begin(ldr->sess); 363 async_msg_0(exch, LOADER_RUN); 364 async_exchange_end(exch); 365 366 async_hangup(ldr->sess); 367 free(ldr); 368 } 369 347 370 /** Cancel the loader session. 348 371 * -
uspace/lib/c/generic/task.c
r6fa3a03 r2443ad8 35 35 */ 36 36 37 #include <async.h> 37 38 #include <task.h> 38 39 #include <loader/loader.h> … … 46 47 #include <ns.h> 47 48 #include <stdlib.h> 49 #include <udebug.h> 48 50 #include <libc.h> 49 51 #include "private/ns.h" … … 94 96 * This is really just a convenience wrapper over the more complicated 95 97 * loader API. Arguments are passed as a null-terminated array of strings. 98 * A debug session is created optionally. 96 99 * 97 100 * @param id If not NULL, the ID of the task is stored here on success. … … 100 103 * @param path Pathname of the binary to execute. 101 104 * @param argv Command-line arguments. 102 * 103 * @return Zero on success or an error code. 104 * 105 */ 106 errno_t task_spawnv(task_id_t *id, task_wait_t *wait, const char *path, 107 const char *const args[]) 105 * @param rsess Place to store pointer to debug session or @c NULL 106 * not to start a debug session 107 * 108 * @return Zero on success or an error code. 109 * 110 */ 111 errno_t task_spawnv_debug(task_id_t *id, task_wait_t *wait, const char *path, 112 const char *const args[], async_sess_t **rsess) 108 113 { 109 114 /* Send default files */ … … 125 130 } 126 131 127 return task_spawnvf (id, wait, path, args, fd_stdin, fd_stdout,128 fd_stderr );132 return task_spawnvf_debug(id, wait, path, args, fd_stdin, fd_stdout, 133 fd_stderr, rsess); 129 134 } 130 135 131 136 /** Create a new task by running an executable from the filesystem. 137 * 138 * This is really just a convenience wrapper over the more complicated 139 * loader API. Arguments are passed as a null-terminated array of strings. 140 * 141 * @param id If not NULL, the ID of the task is stored here on success. 142 * @param wait If not NULL, setup waiting for task's return value and store 143 * the information necessary for waiting here on success. 144 * @param path Pathname of the binary to execute. 145 * @param argv Command-line arguments. 146 * 147 * @return Zero on success or an error code. 148 * 149 */ 150 errno_t task_spawnv(task_id_t *id, task_wait_t *wait, const char *path, 151 const char *const args[]) 152 { 153 return task_spawnv_debug(id, wait, path, args, NULL); 154 } 155 156 /** Create a new task by loading an executable from the filesystem. 132 157 * 133 158 * This is really just a convenience wrapper over the more complicated 134 159 * loader API. Arguments are passed as a null-terminated array of strings. 135 160 * Files are passed as null-terminated array of pointers to fdi_node_t. 161 * A debug session is created optionally. 136 162 * 137 163 * @param id If not NULL, the ID of the task is stored here on success. 138 * @param wait If not NULL, setup waiting for task's return value and store 164 * @param wait If not NULL, setup waiting for task's return value and store. 139 165 * @param path Pathname of the binary to execute. 140 * @param argv Command-line arguments. 141 * @param std_in File to use as stdin. 142 * @param std_out File to use as stdout. 143 * @param std_err File to use as stderr. 144 * 145 * @return Zero on success or an error code. 146 * 147 */ 148 errno_t task_spawnvf(task_id_t *id, task_wait_t *wait, const char *path, 149 const char *const args[], int fd_stdin, int fd_stdout, int fd_stderr) 150 { 166 * @param argv Command-line arguments 167 * @param std_in File to use as stdin 168 * @param std_out File to use as stdout 169 * @param std_err File to use as stderr 170 * @param rsess Place to store pointer to debug session or @c NULL 171 * not to start a debug session 172 * 173 * @return Zero on success or an error code 174 * 175 */ 176 errno_t task_spawnvf_debug(task_id_t *id, task_wait_t *wait, 177 const char *path, const char *const args[], int fd_stdin, int fd_stdout, 178 int fd_stderr, async_sess_t **rsess) 179 { 180 async_sess_t *ksess = NULL; 181 151 182 /* Connect to a program loader. */ 152 183 loader_t *ldr = loader_connect(); … … 217 248 } 218 249 219 /* Run it. */ 220 rc = loader_run(ldr); 221 if (rc != EOK) 222 goto error; 250 /* Start a debug session if requested */ 251 if (rsess != NULL) { 252 ksess = async_connect_kbox(task_id); 253 if (ksess == NULL) { 254 /* Most likely debugging support is not compiled in */ 255 rc = ENOTSUP; 256 goto error; 257 } 258 259 rc = udebug_begin(ksess); 260 if (rc != EOK) 261 goto error; 262 263 /* 264 * Run it, not waiting for response. It would never come 265 * as the loader is stopped. 266 */ 267 loader_run_nowait(ldr); 268 } else { 269 /* Run it. */ 270 rc = loader_run(ldr); 271 if (rc != EOK) 272 goto error; 273 } 223 274 224 275 /* Success */ 225 276 if (id != NULL) 226 277 *id = task_id; 227 278 if (rsess != NULL) 279 *rsess = ksess; 228 280 return EOK; 229 281 230 282 error: 283 if (ksess != NULL) 284 async_hangup(ksess); 231 285 if (wait_initialized) 232 286 task_cancel_wait(wait); … … 235 289 loader_abort(ldr); 236 290 return rc; 291 } 292 293 /** Create a new task by running an executable from the filesystem. 294 * 295 * Arguments are passed as a null-terminated array of strings. 296 * Files are passed as null-terminated array of pointers to fdi_node_t. 297 * 298 * @param id If not NULL, the ID of the task is stored here on success. 299 * @param wait If not NULL, setup waiting for task's return value and store. 300 * @param path Pathname of the binary to execute 301 * @param argv Command-line arguments 302 * @param std_in File to use as stdin 303 * @param std_out File to use as stdout 304 * @param std_err File to use as stderr 305 * 306 * @return Zero on success or an error code. 307 * 308 */ 309 errno_t task_spawnvf(task_id_t *id, task_wait_t *wait, const char *path, 310 const char *const args[], int fd_stdin, int fd_stdout, int fd_stderr) 311 { 312 return task_spawnvf_debug(id, wait, path, args, fd_stdin, fd_stdout, 313 fd_stderr, NULL); 237 314 } 238 315 -
uspace/lib/c/include/loader/loader.h
r6fa3a03 r2443ad8 53 53 extern errno_t loader_load_program(loader_t *); 54 54 extern errno_t loader_run(loader_t *); 55 extern void loader_run_nowait(loader_t *); 55 56 extern void loader_abort(loader_t *); 56 57 -
uspace/lib/c/include/task.h
r6fa3a03 r2443ad8 36 36 #define _LIBC_TASK_H_ 37 37 38 #include <async.h> 38 39 #include <stdint.h> 39 40 #include <stdarg.h> … … 56 57 extern errno_t task_spawnv(task_id_t *, task_wait_t *, const char *path, 57 58 const char *const []); 59 extern errno_t task_spawnv_debug(task_id_t *, task_wait_t *, const char *path, 60 const char *const [], async_sess_t **); 58 61 extern errno_t task_spawnvf(task_id_t *, task_wait_t *, const char *path, 59 62 const char *const [], int, int, int); 63 extern errno_t task_spawnvf_debug(task_id_t *, task_wait_t *, const char *path, 64 const char *const [], int, int, int, async_sess_t **); 60 65 extern errno_t task_spawn(task_id_t *, task_wait_t *, const char *path, int, 61 66 va_list ap);
Note:
See TracChangeset
for help on using the changeset viewer.