1 #include <mono/jit/jit.h>
7 * The Mono and WINE header files have overlapping definitions in the
8 * header files. Since we are only using a few functions and definitions
9 * define them here to avoid conflicts.
11 #define __stdcall __attribute__((__stdcall__))
12 #define PASCAL __stdcall
15 typedef unsigned int UINT
;
18 typedef void* HINSTANCE
;
20 HINSTANCE applicationInstance
= NULL
;
23 * unresolved symbols when linking w/o pthread (testing):
31 int pthread_kill (pthread_t thread
, int signo
)
33 printf ("pthread_kill\n");
37 int sem_init (sem_t
*sem
, int pshared
, unsigned int value
)
39 printf ("sem_init\n");
43 int sem_post (sem_t
* sem
)
45 printf ("sem_post\n");
49 int sem_wait (sem_t
* sem
)
51 printf ("sem_wait\n");
55 int sem_destroy(sem_t
* sem
)
57 printf ("sem_destroy\n");
62 /* not defined in the public headers but we it to load the DLL mappings */
63 void mono_config_parse (const char *filename
);
73 static void main_thread_handler (gpointer user_data
)
75 MainThreadArgs
*main_args
=(MainThreadArgs
*)user_data
;
76 MonoAssembly
*assembly
;
79 printf ("opening assembly \"%s\", argc %d\n", main_args
->file
, main_args
->argc
);
80 for( i
= 0; i
< main_args
->argc
; i
++) {
81 printf ("param %d = \"%s\"\n", i
, main_args
->argv
[i
]);
83 assembly
= mono_domain_assembly_open (main_args
->domain
,
86 printf("error opening assembly\n");
90 * mono_jit_exec() will run the Main() method in the assembly.
91 * The return value needs to be looked up from
92 * System.Environment.ExitCode.
94 printf ("executing assembly\n");
95 mono_jit_exec (main_args
->domain
, assembly
, main_args
->argc
,
99 #define MAX_ARGV_IDX 1024
101 int PASCAL
WinMain (HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
102 LPSTR lpszCmdLine
, int nCmdShow
)
104 MonoDomain
*domain
= NULL
;
105 MainThreadArgs main_args
;
109 char *argv
[MAX_ARGV_IDX
] = { 0};
114 int isInsideQuote
= 0;
116 applicationInstance
= hInstance
;
118 printf ("parsing configuration file\n");
119 mono_config_parse (NULL
);
121 printf ("initializing JIT engine\n");
122 domain
= mono_jit_init (lpszCmdLine
);
124 printf ("parsing command line \"%s\"\n", lpszCmdLine
);
125 len
= strlen(lpszCmdLine
);
126 CommandLine
= (char*)malloc(len
+ 1);
127 memset(CommandLine
, 0,len
+ 1);
128 strncpy(CommandLine
, lpszCmdLine
, len
);
130 argv_start
= CommandLine
;
131 argv_end
= CommandLine
+ len
;
133 // FIXME: remove "" from arguments
134 for( argv_ptr
= argv_start
; argv_ptr
< argv_end
; ) {
135 if( argc
== MAX_ARGV_IDX
) {
138 if( isspace(*argv_ptr
)) {
140 // parameter completed
141 if( argv_start
!= argv_ptr
) {
142 argv
[argc
] = argv_start
;
147 while( argv_ptr
<= argv_end
&& isspace(*argv_ptr
) ) ++argv_ptr
;
148 argv_start
= argv_ptr
;
155 if(*argv_ptr
== '\"') {
156 isInsideQuote
= isInsideQuote
? 0 : 1;
161 if( argv_start
!= argv_ptr
&& argc
< MAX_ARGV_IDX
) {
162 argv
[argc
] = argv_start
;
168 main_args
.domain
=domain
;
169 if( 0 == strcmp(argv
[0],"debug")) {
170 argv
[0] = "/usr/local/bin/Interpreter.exe";
172 main_args
.file
=argv
[0];
175 printf ("runtime exec managed code\n");
177 mono_runtime_exec_managed_code (domain
, main_thread_handler
,
181 printf ("no command line parameters.\n");
185 printf ("calling JIT cleanup\n");
186 mono_jit_cleanup (domain
);