Rev 4348 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4348 | Rev 4691 | ||
|---|---|---|---|
| Line 25... | Line 25... | ||
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
27 | */ |
| 28 | 28 | ||
| 29 | /** @addtogroup lc Libc |
29 | /** @addtogroup lc Libc |
| 30 | * @brief HelenOS C library |
30 | * @brief HelenOS C library |
| 31 | * @{ |
31 | * @{ |
| 32 | * @} |
32 | * @} |
| 33 | */ |
33 | */ |
| - | 34 | ||
| 34 | /** @addtogroup libc generic |
35 | /** @addtogroup libc generic |
| 35 | * @ingroup lc |
36 | * @ingroup lc |
| 36 | * @{ |
37 | * @{ |
| 37 | */ |
38 | */ |
| - | 39 | ||
| 38 | /** @file |
40 | /** @file |
| 39 | */ |
41 | */ |
| 40 | 42 | ||
| 41 | #include <libc.h> |
43 | #include <libc.h> |
| - | 44 | #include <stdio.h> |
|
| 42 | #include <unistd.h> |
45 | #include <unistd.h> |
| 43 | #include <malloc.h> |
46 | #include <malloc.h> |
| 44 | #include <tls.h> |
47 | #include <tls.h> |
| 45 | #include <thread.h> |
48 | #include <thread.h> |
| 46 | #include <fibril.h> |
49 | #include <fibril.h> |
| 47 | #include <io/stream.h> |
- | |
| 48 | #include <ipc/ipc.h> |
50 | #include <ipc/ipc.h> |
| 49 | #include <async.h> |
51 | #include <async.h> |
| 50 | #include <as.h> |
52 | #include <as.h> |
| 51 | #include <console.h> |
- | |
| 52 | #include <loader/pcb.h> |
53 | #include <loader/pcb.h> |
| 53 | 54 | ||
| 54 | /* From librtld. */ |
55 | /* From librtld. */ |
| 55 | #include <rtld.h> |
56 | #include <rtld.h> |
| 56 | #include <string.h> |
57 | #include <string.h> |
| 57 | 58 | ||
| 58 | extern char _heap; |
- | |
| 59 | extern int main(int argc, char *argv[]); |
59 | extern int main(int argc, char *argv[]); |
| 60 | 60 | ||
| 61 | int _errno; |
- | |
| 62 | - | ||
| 63 | void _exit(int status) |
61 | void _exit(int status) |
| 64 | { |
62 | { |
| 65 | thread_exit(status); |
63 | thread_exit(status); |
| 66 | } |
64 | } |
| 67 | 65 | ||
| 68 | void __main(void *pcb_ptr) |
66 | void __main(void *pcb_ptr) |
| 69 | { |
67 | { |
| 70 | fibril_t *f; |
- | |
| 71 | int argc; |
68 | int retval; |
| 72 | char **argv; |
- | |
| 73 | 69 | ||
| 74 | (void) as_area_create(&_heap, 1, AS_AREA_WRITE | AS_AREA_READ); |
70 | __heap_init(); |
| 75 | _async_init(); |
71 | __async_init(); |
| 76 | f = fibril_setup(); |
72 | fibril_t *fibril = fibril_setup(); |
| 77 | __tcb_set(f->tcb); |
73 | __tcb_set(fibril->tcb); |
| 78 | 74 | ||
| 79 | /* Save the PCB pointer */ |
75 | /* Save the PCB pointer */ |
| 80 | __pcb = (pcb_t *)pcb_ptr; |
76 | __pcb = (pcb_t *) pcb_ptr; |
| - | 77 | ||
| - | 78 | int argc; |
|
| - | 79 | char **argv; |
|
| 81 | 80 | ||
| 82 | #ifdef __IN_SHARED_LIBC__ |
81 | #ifdef __IN_SHARED_LIBC__ |
| 83 | if (__pcb != NULL && __pcb->rtld_runtime != NULL) { |
82 | if (__pcb != NULL && __pcb->rtld_runtime != NULL) { |
| 84 | runtime_env = (runtime_env_t *) __pcb->rtld_runtime; |
83 | runtime_env = (runtime_env_t *) __pcb->rtld_runtime; |
| 85 | } |
84 | } |
| 86 | #endif |
85 | #endif |
| 87 | 86 | ||
| 88 | if (__pcb == NULL) { |
87 | if (__pcb == NULL) { |
| 89 | argc = 0; |
88 | argc = 0; |
| 90 | argv = NULL; |
89 | argv = NULL; |
| - | 90 | __stdio_init(0, NULL); |
|
| 91 | } else { |
91 | } else { |
| 92 | argc = __pcb->argc; |
92 | argc = __pcb->argc; |
| 93 | argv = __pcb->argv; |
93 | argv = __pcb->argv; |
| - | 94 | __stdio_init(__pcb->filc, __pcb->filv); |
|
| 94 | } |
95 | } |
| - | 96 | ||
| - | 97 | retval = main(argc, argv); |
|
| 95 | 98 | ||
| 96 | main(argc, argv); |
99 | __stdio_done(); |
| 97 | console_flush(); |
100 | (void) task_retval(retval); |
| 98 | } |
101 | } |
| 99 | 102 | ||
| 100 | void __exit(void) |
103 | void __exit(void) |
| 101 | { |
104 | { |
| 102 | fibril_teardown(__tcb_get()->fibril_data); |
105 | fibril_teardown(__tcb_get()->fibril_data); |