Rev 3102 | Rev 3150 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3102 | Rev 3148 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Jakub Jermar |
2 | * Copyright (c) 2006 Jakub Jermar |
- | 3 | * Copyright (c) 2008 Jiri Svoboda |
|
3 | * All rights reserved. |
4 | * All rights reserved. |
4 | * |
5 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * are met: |
8 | * |
9 | * |
9 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
14 | * - 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 |
15 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
16 | * |
17 | * |
17 | * 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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * 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, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * 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, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (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 |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | */ |
28 | 29 | ||
29 | /** @addtogroup libc |
30 | /** @addtogroup libc |
30 | * @{ |
31 | * @{ |
31 | */ |
32 | */ |
32 | /** @file |
33 | /** @file |
33 | */ |
34 | */ |
34 | 35 | ||
35 | #include <task.h> |
36 | #include <task.h> |
36 | #include <ipc/ipc.h> |
37 | #include <ipc/ipc.h> |
- | 38 | #include <ipc/loader.h> |
|
37 | #include <libc.h> |
39 | #include <libc.h> |
- | 40 | #include <string.h> |
|
38 | #include <async.h> |
41 | #include <async.h> |
39 | #include <errno.h> |
42 | #include <errno.h> |
40 | 43 | ||
41 | task_id_t task_get_id(void) |
44 | task_id_t task_get_id(void) |
42 | { |
45 | { |
43 | task_id_t task_id; |
46 | task_id_t task_id; |
44 | 47 | ||
45 | (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id); |
48 | (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id); |
46 | 49 | ||
47 | return task_id; |
50 | return task_id; |
48 | } |
51 | } |
49 | 52 | ||
50 | static int task_spawn_loader(void) |
53 | static int task_spawn_loader(void) |
51 | { |
54 | { |
52 | int phone_id, rc; |
55 | int phone_id, rc; |
53 | 56 | ||
54 | rc = __SYSCALL1(SYS_TASK_SPAWN, (sysarg_t) &phone_id); |
57 | rc = __SYSCALL1(SYS_TASK_SPAWN, (sysarg_t) &phone_id); |
55 | if (rc != 0) |
58 | if (rc != 0) |
56 | return rc; |
59 | return rc; |
57 | 60 | ||
58 | return phone_id; |
61 | return phone_id; |
59 | } |
62 | } |
- | 63 | ||
- | 64 | /** Create a new task by running an executable from VFS. |
|
- | 65 | * |
|
60 | #include <stdio.h> |
66 | * @param path pathname of the binary to execute |
61 | #include <unistd.h> |
67 | * @param argv command-line arguments |
- | 68 | * @return ID of the newly created task or zero on error. |
|
- | 69 | */ |
|
62 | task_id_t task_spawn(const char *path, const char *argv[]) |
70 | task_id_t task_spawn(const char *path, const char *argv[]) |
63 | { |
71 | { |
64 | int phone_id; |
72 | int phone_id; |
65 | ipc_call_t answer; |
73 | ipc_call_t answer; |
66 | aid_t req; |
74 | aid_t req; |
67 | int rc; |
75 | int rc; |
68 | 76 | ||
- | 77 | /* Spawn a program loader */ |
|
69 | phone_id = task_spawn_loader(); |
78 | phone_id = task_spawn_loader(); |
70 | if (phone_id < 0) return 0; |
79 | if (phone_id < 0) return 0; |
71 | printf("phone_id:%d\n", phone_id); |
- | |
72 | 80 | ||
- | 81 | /* |
|
- | 82 | * Say hello so that the loader knows the incoming connection's |
|
73 | // getchar(); |
83 | * phone hash. |
- | 84 | */ |
|
- | 85 | rc = async_req_0_0(phone_id, LOADER_HELLO); |
|
- | 86 | if (rc != EOK) return 0; |
|
74 | 87 | ||
- | 88 | /* Send program pathname */ |
|
75 | // req = async_send_0(phone_id, 1024, &answer); |
89 | req = async_send_0(phone_id, LOADER_SET_PATHNAME, &answer); |
76 | rc = ipc_data_write_start(phone_id, (void *)path, strlen(path)); |
90 | rc = ipc_data_write_start(phone_id, (void *)path, strlen(path)); |
77 | printf("->%d\n", rc); |
- | |
78 | if (rc != EOK) { |
91 | if (rc != EOK) { |
79 | // async_wait_for(req, NULL); |
92 | async_wait_for(req, NULL); |
80 | return 1; |
93 | return 1; |
81 | } |
94 | } |
82 | // async_wait_for(req, &rc); |
- | |
83 | 95 | ||
- | 96 | async_wait_for(req, &rc); |
|
- | 97 | if (rc != EOK) return 0; |
|
- | 98 | ||
- | 99 | /* Request loader to start the program */ |
|
- | 100 | rc = async_req_0_0(phone_id, LOADER_RUN); |
|
84 | if (rc != EOK) return 0; |
101 | if (rc != EOK) return 0; |
85 | - | ||
86 | // rc = async_req_0_0(phone_id, 1025); |
- | |
87 | // printf("->%d\n", rc); |
- | |
88 | // if (rc != EOK) return 0; |
- | |
89 | 102 | ||
90 | // ipc_hangup(phone_id); |
103 | ipc_hangup(phone_id); |
91 | 104 | ||
92 | return 1; |
105 | return 1; |
93 | } |
106 | } |
94 | 107 | ||
95 | /** @} |
108 | /** @} |
96 | */ |
109 | */ |
97 | 110 |