source: mainline/uspace/lib/c/generic/libc.c@ 6d1d143

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6d1d143 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * 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 * derived from this software without specific prior written permission.
16 *
17 * 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 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * 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 * 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 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup lc Libc
30 * @brief HelenOS C library
31 * @{
32 * @}
33 */
34
35/** @addtogroup libc generic
36 * @ingroup lc
37 * @{
38 */
39
40/** @file
41 */
42
43#include <errno.h>
44#include <libc.h>
45#include <stdlib.h>
46#include <tls.h>
47#include <fibril.h>
48#include <task.h>
49#include <loader/pcb.h>
50#include <vfs/vfs.h>
51#include <vfs/inbox.h>
52#include "private/libc.h"
53#include "private/async.h"
54#include "private/malloc.h"
55#include "private/io.h"
56
57#ifdef FUTEX_UPGRADABLE
58#include <rcu.h>
59#endif
60
61#ifdef CONFIG_RTLD
62#include <rtld/rtld.h>
63#endif
64
65
66static bool env_setup = false;
67
68void __main(void *pcb_ptr)
69{
70 /* Initialize user task run-time environment */
71 __malloc_init();
72
73 /* Save the PCB pointer */
74 __pcb = (pcb_t *) pcb_ptr;
75
76#ifdef CONFIG_RTLD
77 if (__pcb != NULL && __pcb->rtld_runtime != NULL) {
78 runtime_env = (rtld_t *) __pcb->rtld_runtime;
79 } else {
80 if (rtld_init_static() != EOK)
81 abort();
82 }
83#endif
84
85 fibril_t *fibril = fibril_setup();
86 if (fibril == NULL)
87 abort();
88
89 __tcb_set(fibril->tcb);
90
91
92#ifdef FUTEX_UPGRADABLE
93 rcu_register_fibril();
94#endif
95
96 __async_init();
97
98 /* The basic run-time environment is setup */
99 env_setup = true;
100
101 int argc;
102 char **argv;
103
104 /*
105 * Get command line arguments and initialize
106 * standard input and output
107 */
108 if (__pcb == NULL) {
109 argc = 0;
110 argv = NULL;
111 __stdio_init();
112 } else {
113 argc = __pcb->argc;
114 argv = __pcb->argv;
115 __inbox_init(__pcb->inbox, __pcb->inbox_entries);
116 __stdio_init();
117 vfs_root_set(inbox_get("root"));
118 (void) vfs_cwd_set(__pcb->cwd);
119 }
120
121 /*
122 * Run main() and set task return value
123 * according the result
124 */
125 int retval = main(argc, argv);
126 exit(retval);
127}
128
129void exit(int status)
130{
131 if (env_setup) {
132 __stdio_done();
133 task_retval(status);
134 fibril_teardown(__tcb_get()->fibril_data, false);
135 }
136
137 __SYSCALL1(SYS_TASK_EXIT, false);
138
139 /* Unreachable */
140 while (1);
141}
142
143void abort(void)
144{
145 __SYSCALL1(SYS_TASK_EXIT, true);
146
147 /* Unreachable */
148 while (1);
149}
150
151/** @}
152 */
Note: See TracBrowser for help on using the repository browser.