Rev 3471 | Rev 4377 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3471 | Rev 3597 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Jakub Jermar |
2 | * Copyright (c) 2006 Jakub Jermar |
3 | * Copyright (c) 2008 Jiri Svoboda |
3 | * Copyright (c) 2008 Jiri Svoboda |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup libc |
30 | /** @addtogroup libc |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** @file |
33 | /** @file |
34 | */ |
34 | */ |
35 | 35 | ||
36 | #include <task.h> |
36 | #include <task.h> |
37 | #include <libc.h> |
37 | #include <libc.h> |
38 | #include <stdlib.h> |
38 | #include <stdlib.h> |
39 | #include <errno.h> |
39 | #include <errno.h> |
40 | #include <loader/loader.h> |
40 | #include <loader/loader.h> |
41 | 41 | ||
42 | task_id_t task_get_id(void) |
42 | task_id_t task_get_id(void) |
43 | { |
43 | { |
44 | task_id_t task_id; |
44 | task_id_t task_id; |
45 | 45 | ||
46 | (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id); |
46 | (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id); |
47 | 47 | ||
48 | return task_id; |
48 | return task_id; |
49 | } |
49 | } |
50 | 50 | ||
51 | /** Create a new task by running an executable from the filesystem. |
51 | /** Create a new task by running an executable from the filesystem. |
52 | * |
52 | * |
53 | * This is really just a convenience wrapper over the more complicated |
53 | * This is really just a convenience wrapper over the more complicated |
54 | * loader API. |
54 | * loader API. |
55 | * |
55 | * |
56 | * @param path pathname of the binary to execute |
56 | * @param path pathname of the binary to execute |
57 | * @param argv command-line arguments |
57 | * @param argv command-line arguments |
58 | * @return ID of the newly created task or zero on error. |
58 | * @return ID of the newly created task or zero on error. |
59 | */ |
59 | */ |
60 | task_id_t task_spawn(const char *path, char *const argv[]) |
60 | task_id_t task_spawn(const char *path, char *const argv[]) |
61 | { |
61 | { |
62 | loader_t *ldr; |
62 | loader_t *ldr; |
63 | task_id_t task_id; |
63 | task_id_t task_id; |
64 | int rc; |
64 | int rc; |
65 | 65 | ||
66 | /* Spawn a program loader. */ |
66 | /* Spawn a program loader. */ |
67 | ldr = loader_spawn(); |
67 | ldr = loader_spawn(path); |
68 | if (ldr == NULL) |
68 | if (ldr == NULL) |
69 | return 0; |
69 | return 0; |
70 | 70 | ||
71 | /* Get task ID. */ |
71 | /* Get task ID. */ |
72 | rc = loader_get_task_id(ldr, &task_id); |
72 | rc = loader_get_task_id(ldr, &task_id); |
73 | if (rc != EOK) |
73 | if (rc != EOK) |
74 | goto error; |
74 | goto error; |
75 | 75 | ||
76 | /* Send program pathname. */ |
76 | /* Send program pathname. */ |
77 | rc = loader_set_pathname(ldr, path); |
77 | rc = loader_set_pathname(ldr, path); |
78 | if (rc != EOK) |
78 | if (rc != EOK) |
79 | goto error; |
79 | goto error; |
80 | 80 | ||
81 | /* Send arguments. */ |
81 | /* Send arguments. */ |
82 | rc = loader_set_args(ldr, argv); |
82 | rc = loader_set_args(ldr, argv); |
83 | if (rc != EOK) |
83 | if (rc != EOK) |
84 | goto error; |
84 | goto error; |
85 | 85 | ||
86 | /* Load the program. */ |
86 | /* Load the program. */ |
87 | rc = loader_load_program(ldr); |
87 | rc = loader_load_program(ldr); |
88 | if (rc != EOK) |
88 | if (rc != EOK) |
89 | goto error; |
89 | goto error; |
90 | 90 | ||
91 | /* Run it. */ |
91 | /* Run it. */ |
92 | /* Load the program. */ |
92 | /* Load the program. */ |
93 | rc = loader_run(ldr); |
93 | rc = loader_run(ldr); |
94 | if (rc != EOK) |
94 | if (rc != EOK) |
95 | goto error; |
95 | goto error; |
96 | 96 | ||
97 | /* Success */ |
97 | /* Success */ |
98 | 98 | ||
99 | free(ldr); |
99 | free(ldr); |
100 | return task_id; |
100 | return task_id; |
101 | 101 | ||
102 | /* Error exit */ |
102 | /* Error exit */ |
103 | error: |
103 | error: |
104 | loader_abort(ldr); |
104 | loader_abort(ldr); |
105 | free(ldr); |
105 | free(ldr); |
106 | 106 | ||
107 | return 0; |
107 | return 0; |
108 | } |
108 | } |
109 | 109 | ||
110 | /** @} |
110 | /** @} |
111 | */ |
111 | */ |
112 | 112 |