+ exec* functions
[meinos.git] / apps / lib / crt0 / crt0.c
blobca56ef9f4523357ecd0a5c6d3e750c4d291b5750
1 /*
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>
20 #include <sys/shm.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <syscall.h>
25 #include <misc.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
31 /*static int var;
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*));
36 size_t i = 0;
37 size_t j;
39 for (j=0;j<argc;j++) {
40 argv[j] = data->cmdline+i;
41 i += strlen(data->cmdline+i)+1;
43 argv[j] = NULL;
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;
63 *_argv = argv;
64 *_argc = argc;
67 static void crt0_quit() {
68 if (_process_data!=NULL) {
69 // remove process data
70 shmdt(_process_data);
71 shmctl(var,IPC_RMID,NULL);
73 }*/
75 void _start() {
76 char *backup_argv[] = { NULL };
77 char **argv = backup_argv;
78 int argc = 0;
80 // initialize libs
81 _stdlib_init();
82 _libmeinos_init();
84 // get process data
85 int var = syscall_call(SYSCALL_PROC_GETVAR,1,getpid());
86 if (var!=-1) proc_unpack_procdata(var,&argc,&argv);
88 /*if (var!=-1) {
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);
96 atexit(crt0_quit);*/
98 // call main function and exit
99 exit(main(argc,argv));
101 while (1);