Changeset 84876aa4 in mainline for uspace/lib/c/generic/task.c


Ignore:
Timestamp:
2019-11-15T13:46:34Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ecb7828
Parents:
b093a62 (diff), d548fc0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge master into gfx

Mainly to get XCW fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/task.c

    rb093a62 r84876aa4  
    3535 */
    3636
     37#include <async.h>
    3738#include <task.h>
    3839#include <loader/loader.h>
     
    4647#include <ns.h>
    4748#include <stdlib.h>
     49#include <udebug.h>
    4850#include <libc.h>
    4951#include "private/ns.h"
     
    9496 * This is really just a convenience wrapper over the more complicated
    9597 * loader API. Arguments are passed as a null-terminated array of strings.
     98 * A debug session is created optionally.
    9699 *
    97100 * @param id   If not NULL, the ID of the task is stored here on success.
     
    100103 * @param path Pathname of the binary to execute.
    101104 * @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 */
     111errno_t task_spawnv_debug(task_id_t *id, task_wait_t *wait, const char *path,
     112    const char *const args[], async_sess_t **rsess)
    108113{
    109114        /* Send default files */
     
    125130        }
    126131
    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);
    129134}
    130135
    131136/** 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 */
     150errno_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.
    132157 *
    133158 * This is really just a convenience wrapper over the more complicated
    134159 * loader API. Arguments are passed as a null-terminated array of strings.
    135160 * Files are passed as null-terminated array of pointers to fdi_node_t.
     161 * A debug session is created optionally.
    136162 *
    137163 * @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.
    139165 * @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 */
     176errno_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
    151182        /* Connect to a program loader. */
    152183        loader_t *ldr = loader_connect();
     
    217248        }
    218249
    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        }
    223274
    224275        /* Success */
    225276        if (id != NULL)
    226277                *id = task_id;
    227 
     278        if (rsess != NULL)
     279                *rsess = ksess;
    228280        return EOK;
    229281
    230282error:
     283        if (ksess != NULL)
     284                async_hangup(ksess);
    231285        if (wait_initialized)
    232286                task_cancel_wait(wait);
     
    235289        loader_abort(ldr);
    236290        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 */
     309errno_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);
    237314}
    238315
Note: See TracChangeset for help on using the changeset viewer.