Subversion Repositories Kolibri OS

Rev

Rev 4921 | Rev 5198 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4921 Rev 5190
Line 23... Line 23...
23
    void  *__idata_end;
23
    void  *__idata_end;
24
    int  (*main)(int argc, char **argv, char **envp);
24
    int  (*main)(int argc, char **argv, char **envp);
25
};
25
};
26
 
26
 
Line -... Line 27...
-
 
27
void _pei386_runtime_relocator (void);
27
int    _argc;
28
void init_loader(void *libc_image);
28
char **_argv;
29
void init_reent();
29
 
-
 
Line -... Line 30...
-
 
30
 
30
 
31
int link_app();
31
void* get_entry_point(void *raw);
32
void* get_entry_point(void *raw);
Line -... Line 33...
-
 
33
int (*entry)(int, char **, char **);
32
int (*entry)(int, char **, char **);
34
 
33
 
-
 
34
void init_loader(void *libc_image);
35
char  __appcwd[1024];
35
 
36
int   __appcwdlen;
Line 36... Line 37...
36
 
37
char* __appenv;
Line 37... Line 38...
37
void init_reent();
38
int   __appenv_size;
38
 
39
 
39
jmp_buf loader_env;
40
extern char _tls_map[128];
40
 
41
 
41
void  __attribute__((noreturn))
42
void  __attribute__((noreturn))
Line 42... Line 43...
42
__thread_startup (int (*entry)(void*), void *param,
43
__thread_startup (int (*entry)(void*), void *param,
Line 43... Line 44...
43
                  void *stacklow, void *stackhigh)
44
                  void *stacklow, void *stackhigh)
44
{
45
{
45
    int retval;
46
    int retval;
46
 
47
 
Line 62... Line 63...
62
{
63
{
63
    return NULL;
64
    return NULL;
64
}
65
}
65
 
66
 
Line 66... Line 67...
66
void _pei386_runtime_relocator (void);
67
static int split_cmdline(char *cmdline, char **argv)
-
 
68
{
67
int link_app();
69
    enum quote_state
-
 
70
    {
-
 
71
        QUOTE_NONE,         /* no " active in current parm       */
-
 
72
        QUOTE_DELIMITER,    /* " was first char and must be last */
-
 
73
        QUOTE_STARTED       /* " was seen, look for a match      */
-
 
74
    };
Line 68... Line 75...
68
 
75
 
69
char  __appcwd[1024];
76
    enum quote_state state;
70
int   __appcwdlen;
77
    unsigned int argc;
71
char* __appenv;
78
    char *p = cmdline;
Line 72... Line 79...
72
int   __appenv_size;
79
    char *new_arg, *start;
Line -... Line 80...
-
 
80
 
-
 
81
    argc = 0;
-
 
82
 
-
 
83
    for(;;)
-
 
84
    {
-
 
85
        /* skip over spaces and tabs */
-
 
86
        if ( *p )
-
 
87
        {
-
 
88
            while (*p == ' ' || *p == '\t')
-
 
89
                ++p;
-
 
90
        }
-
 
91
 
-
 
92
        if (*p == '\0')
-
 
93
            break;
-
 
94
 
-
 
95
        state = QUOTE_NONE;
-
 
96
        if( *p == '\"' )
-
 
97
        {
73
 
98
            p++;
-
 
99
            state = QUOTE_DELIMITER;
-
 
100
        }
-
 
101
        new_arg = start = p;
-
 
102
        for (;;)
-
 
103
        {
-
 
104
            if( *p == '\"' )
-
 
105
            {
-
 
106
                p++;
-
 
107
                if( state == QUOTE_NONE )
-
 
108
                {
-
 
109
                    state = QUOTE_STARTED;
-
 
110
                }
-
 
111
                else
-
 
112
                {
-
 
113
                    state = QUOTE_NONE;
-
 
114
                }
-
 
115
                continue;
-
 
116
            }
-
 
117
 
-
 
118
            if( *p == ' ' || *p == '\t' )
-
 
119
            {
-
 
120
                if( state == QUOTE_NONE )
-
 
121
                {
-
 
122
                    break;
-
 
123
                }
-
 
124
            }
-
 
125
 
-
 
126
            if( *p == '\0' )
-
 
127
                break;
-
 
128
 
-
 
129
            if( *p == '\\' )
-
 
130
            {
-
 
131
                if( p[1] == '\"' )
-
 
132
                {
-
 
133
                    ++p;
-
 
134
                    if( p[-2] == '\\' )
-
 
135
                    {
-
 
136
                        continue;
-
 
137
                    }
-
 
138
                }
-
 
139
            }
-
 
140
            if( argv )
-
 
141
            {
-
 
142
                *(new_arg++) = *p;
-
 
143
            }
-
 
144
            ++p;
-
 
145
        };
-
 
146
 
-
 
147
        if( argv )
-
 
148
        {
-
 
149
            argv[ argc ] = start;
-
 
150
            ++argc;
-
 
151
 
-
 
152
            /*
-
 
153
              The *new = '\0' is req'd in case there was a \" to "
-
 
154
              translation. It must be after the *p check against
-
 
155
              '\0' because new and p could point to the same char
-
 
156
              in which case the scan would be terminated too soon.
-
 
157
            */
-
 
158
 
-
 
159
            if( *p == '\0' )
-
 
160
            {
-
 
161
                *new_arg = '\0';
-
 
162
                break;
-
 
163
            }
-
 
164
            *new_arg = '\0';
-
 
165
            ++p;
-
 
166
        }
-
 
167
        else
-
 
168
        {
-
 
169
            ++argc;
-
 
170
            if( *p == '\0' )
-
 
171
            {
-
 
172
                break;
-
 
173
            }
-
 
174
            ++p;
-
 
175
        }
-
 
176
    }
Line 74... Line 177...
74
static char *arg[2];
177
 
75
 
178
    return argc;
76
extern char _tls_map[128];
179
};
77
 
180
 
78
void  __attribute__((noreturn))
-
 
79
libc_crt_startup (void *libc_base)
-
 
80
{
-
 
81
    struct   app_hdr *header = NULL;
-
 
82
 
-
 
83
    int len;
181
void  __attribute__((noreturn))
Line -... Line 182...
-
 
182
libc_crt_startup (void *libc_base)
-
 
183
{
-
 
184
    struct   app_hdr *header = NULL;
84
    char *p;
185
    int retval = 0;
Line 85... Line 186...
85
 
186
 
86
    void *my_app;
187
    char **argv;
87
    int retval = 0;
188
    int    argc;
Line 104... Line 205...
104
    __appcwdlen = __appcwdlen > 1022 ? 1022 : __appcwdlen;
205
    __appcwdlen = __appcwdlen > 1022 ? 1022 : __appcwdlen;
105
    memcpy(__appcwd, header->path, __appcwdlen);
206
    memcpy(__appcwd, header->path, __appcwdlen);
106
    set_cwd(__appcwd);
207
    set_cwd(__appcwd);
107
 
208
 
Line 108... Line -...
108
    arg[0] = header->path;
-
 
109
 
-
 
110
    if( header->cmdline[0] != 0)
209
    if( header->cmdline[0] != 0)
111
    {
210
    {
112
        _argc = 2;
211
        argc = split_cmdline(header->cmdline, NULL) + 1;
113
        arg[1] = header->cmdline;
212
        argv = alloca((argc+1)*sizeof(char*));
114
    }
-
 
115
    else _argc = 1;
213
        argv[0] = header->path;
Line -... Line 214...
-
 
214
 
-
 
215
        split_cmdline(header->cmdline, argv + 1);
-
 
216
    }
-
 
217
    else
116
 
218
    {
-
 
219
        argc = 1;
-
 
220
        argv = alloca((argc+1)*sizeof(char*));
-
 
221
        argv[0] = header->path;
-
 
222
    }
Line 117... Line 223...
117
    _argv = arg;
223
    argv[argc] = NULL;
118
 
224
 
119
    retval = header->main(_argc, _argv, NULL);
225
    retval = header->main(argc, argv, NULL);
120
done:
226
done: