2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <sys/types.h>
27 int main(int argc
,char *argv
[]);
28 void _stdlib_init(); ///< @see apps/lib/stdlibc/stdlib.c
29 void _libmeinos_init(); ///< @see apps/lib/libmeinos/misc.c
33 static void get_cmdline(struct process_data *data,char ***_argv,int *_argc,char **_stdin,char **_stdout,char **_stderr) {
34 int argc = data->argc;
35 char **argv = malloc((argc+1)*sizeof(char*));
39 for (j=0;j<argc;j++) {
40 argv[j] = data->cmdline+i;
41 i += strlen(data->cmdline+i)+1;
45 if (data->has_stdin) {
46 if (_stdin!=NULL) *_stdin = data->stdio+i;
47 i += strlen(data->stdio+i)+1;
49 else if (_stdin!=NULL) *_stdin = NULL;
51 if (data->has_stdout) {
52 if (_stdout!=NULL) *_stdout = data->stdio+i;
53 i += strlen(data->stdio+i)+1;
55 else if (_stdout!=NULL) *_stdout = NULL;
57 if (data->has_stderr) {
58 if (_stderr!=NULL) *_stderr = data->stdio+i;
59 i += strlen(data->stdio+i)+1;
61 else if (_stderr!=NULL) *_stderr = NULL;
67 static void crt0_quit() {
68 if (_process_data!=NULL) {
69 // remove process data
71 shmctl(var,IPC_RMID,NULL);
76 char *backup_argv
[] = { NULL
};
77 char **argv
= backup_argv
;
85 int var
= syscall_call(SYSCALL_PROC_GETVAR
,1,getpid());
86 if (var
!=-1) proc_unpack_procdata(var
,&argc
,&argv
);
89 _process_data = shmat(var,NULL,0);
90 if (_process_data!=NULL) get_cmdline(_process_data,&argv,&argc,&_stdin,&_stdout,&_stderr);
92 else _process_data = NULL;
94 // post initialize stdlibc
95 _stdlib_init_post(_stdin,_stdout,_stderr);
98 // call main function and exit
99 exit(main(argc
,argv
));