45 |
/* #define DBG gw_logf */ |
/* #define DBG gw_logf */ |
46 |
#define DBG if(0) gw_logf |
#define DBG if(0) gw_logf |
47 |
|
|
48 |
|
|
49 |
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
50 |
|
|
51 |
static int CallStaticConstructor(ILExecThread *thread, ILMethod * method) |
static int CallStaticConstructor(ILExecThread *thread, ILMethod * method) |
73 |
int |
int |
74 |
pnetvm_entry(int argc, char *argv[]) |
pnetvm_entry(int argc, char *argv[]) |
75 |
{ |
{ |
76 |
char *progname = argv[0]; |
char *progname = argv[0]; |
77 |
unsigned long heapSize = IL_CONFIG_GC_HEAP_SIZE; |
unsigned long heapSize = IL_CONFIG_GC_HEAP_SIZE; |
78 |
unsigned long stackSize = IL_CONFIG_STACK_SIZE; |
unsigned long stackSize = IL_CONFIG_STACK_SIZE; |
79 |
unsigned long methodCachePageSize = IL_CONFIG_CACHE_PAGE_SIZE; |
unsigned long methodCachePageSize = IL_CONFIG_CACHE_PAGE_SIZE; |
80 |
char **libraryDirs; |
char **libraryDirs; |
81 |
int numLibraryDirs; |
int numLibraryDirs; |
82 |
char *param; |
char *param; |
83 |
ILMethod *method; |
ILMethod *method; |
84 |
int error; |
int error; |
85 |
ILInt32 retval; |
ILInt32 retval; |
86 |
ILObject *args; |
ILObject *args; |
87 |
ILString *argString; |
ILString *argString; |
88 |
ILObject *exception; |
ILObject *exception; |
89 |
ILExecValue execValue; |
ILExecValue execValue; |
90 |
int sawException; |
int sawException; |
91 |
int flags = 2; |
int flags = 2; |
92 |
|
|
93 |
char dgeeWSdir[128] = {0}; |
char dgeeWSdir[128] = {0}; |
94 |
|
|
95 |
DBG( LOG_DEBUG, "cleanup" ); |
DBG( LOG_DEBUG, "cleanup" ); |
96 |
if( process ) pnetvm_cleanup(); |
if( process ) pnetvm_cleanup(); |
97 |
|
|
98 |
thread = NULL; |
thread = NULL; |
99 |
process = NULL; |
process = NULL; |
100 |
|
|
101 |
DBG( LOG_DEBUG, "locale" ); |
DBG( LOG_DEBUG, "locale" ); |
102 |
/* Initialize the locale routines */ |
/* Initialize the locale routines */ |
103 |
ILInitLocale(); |
ILInitLocale(); |
104 |
|
|
105 |
DBG( LOG_DEBUG, "ILExecInit" ); |
DBG( LOG_DEBUG, "ILExecInit" ); |
106 |
/* Initialize the engine and set the maximum heap size */ |
/* Initialize the engine and set the maximum heap size */ |
107 |
ILExecInit(heapSize); |
ILExecInit(heapSize); |
108 |
|
|
109 |
DBG( LOG_DEBUG, "ILMalloc" ); |
DBG( LOG_DEBUG, "ILMalloc" ); |
110 |
/* Allocate space for the library list */ |
/* Allocate space for the library list */ |
111 |
libraryDirs = (char **)ILMalloc(sizeof(char *) * argc); |
libraryDirs = (char **)ILMalloc(sizeof(char *) * argc); |
112 |
numLibraryDirs = 0; |
numLibraryDirs = 0; |
113 |
|
|
114 |
DBG( LOG_DEBUG, "ILExecProcessCreate" ); |
DBG( LOG_DEBUG, "ILExecProcessCreate" ); |
115 |
/* Create a process to load the program into */ |
/* Create a process to load the program into */ |
116 |
process = ILExecProcessCreate(stackSize, methodCachePageSize); |
process = ILExecProcessCreate(stackSize, methodCachePageSize); |
117 |
|
|
118 |
if(!process) |
if(!process) |
119 |
{ |
{ |
120 |
printf( "%s: could not create process\n", progname); |
printf( "%s: could not create process\n", progname); |
121 |
return 1; |
return 1; |
122 |
} |
} |
123 |
|
|
124 |
ILExecProcessSetCoderFlags(process,flags); |
ILExecProcessSetCoderFlags(process,flags); |
125 |
|
|
126 |
sprintf( dgeeWSdir, "%s/data", dgee_repository ); |
sprintf( dgeeWSdir, "%s/data", dgee_repository ); |
127 |
|
|
128 |
DBG( LOG_DEBUG, "dgee_repository: %s", dgeeWSdir ); |
DBG( LOG_DEBUG, "dgee_repository: %s", dgeeWSdir ); |
129 |
|
|
130 |
libraryDirs[numLibraryDirs++] = dgee_libdir; |
libraryDirs[numLibraryDirs++] = dgee_libdir; |
131 |
libraryDirs[numLibraryDirs++] = dgeeWSdir; |
libraryDirs[numLibraryDirs++] = dgeeWSdir; |
132 |
|
|
133 |
DBG( LOG_DEBUG, "Building PNETVM...." ); |
DBG( LOG_DEBUG, "Building PNETVM...." ); |
134 |
/* Set the list of directories to use for path searching */ |
/* Set the list of directories to use for path searching */ |
135 |
if(numLibraryDirs > 0) |
if(numLibraryDirs > 0) |
136 |
{ |
{ |
137 |
ILExecProcessSetLibraryDirs(process, libraryDirs, numLibraryDirs); |
ILExecProcessSetLibraryDirs(process, libraryDirs, numLibraryDirs); |
138 |
} |
} |
139 |
|
|
140 |
DBG( LOG_DEBUG, "ILExecProcessLoadFile" ); |
DBG( LOG_DEBUG, "ILExecProcessLoadFile" ); |
141 |
/* Attempt to load the program into the process */ |
/* Attempt to load the program into the process */ |
142 |
error = ILExecProcessLoadFile(process, argv[1]); |
error = ILExecProcessLoadFile(process, argv[1]); |
143 |
if(error != 0) |
if(error != 0) |
144 |
{ |
{ |
145 |
gw_logf(LOG_ERROR, "%s: %s\n", argv[1], ILImageLoadError(error)); |
gw_logf(LOG_ERROR, "%s: %s\n", argv[1], ILImageLoadError(error)); |
146 |
return 1; |
return 1; |
147 |
} |
} |
148 |
|
|
149 |
|
DBG( LOG_DEBUG, "ILExecProcessGetMain" ); |
150 |
|
thread = ILExecProcessGetMain(process); |
151 |
|
|
152 |
|
DBG( LOG_DEBUG, "ILExecThreadLookupMethod" ); |
153 |
|
/* Locate Entry Point for DotGNU WebService */ |
154 |
|
/* ILExecThreadLookupMethod(Type name, Method name, Signature) */ |
155 |
|
method = ILExecThreadLookupMethod(thread, PROTOCOL_TYPE_NAME, "DGEE_run", |
156 |
|
"([oSystem.String;)oSystem.String;" ); |
157 |
|
|
158 |
DBG( LOG_DEBUG, "ILExecProcessGetMain" ); |
if(!method) |
159 |
thread = ILExecProcessGetMain(process); |
{ |
160 |
|
gw_logf(LOG_ERROR, "%s: no DGEE Webservice entry point [%s]\n", argv[1], PROTOCOL_TYPE_NAME); |
161 |
|
/* ILExecProcessDestroy(process); */ |
162 |
|
return 1; |
163 |
|
} |
164 |
|
|
165 |
DBG( LOG_DEBUG, "ILExecThreadLookupMethod" ); |
DBG( LOG_DEBUG, "ILExecProcessSetCommandLine" ); |
166 |
/* Locate Entry Point for DotGNU WebService */ |
/* Convert the arguments into an array of strings */ |
167 |
/* ILExecThreadLookupMethod(Type name, Method name, Signature) */ |
args = ILExecProcessSetCommandLine(process, argv[1], argv + 2); |
|
method = ILExecThreadLookupMethod(thread, |
|
|
"DotGNU.DGEE.DGEEWSInvoke", |
|
|
"DGEE_run", |
|
|
"([oSystem.String;)oSystem.String;" ); |
|
168 |
|
|
169 |
if(!method) |
/* Call the entry point */ |
170 |
|
sawException = 0; |
171 |
|
if(args != 0 && !ILExecThreadHasException(thread)) |
172 |
|
{ |
173 |
|
retval = 0; |
174 |
|
DBG( LOG_DEBUG, "ILExecThreadCallV" ); |
175 |
|
|
176 |
|
retval = CallStaticConstructor(thread, method); |
177 |
|
sawException = retval; |
178 |
|
execValue.ptrValue = args; |
179 |
|
|
180 |
|
if( !sawException && |
181 |
|
ILExecThreadCallV(thread, method, (ILExecValue*)&resultString, &execValue)) |
182 |
{ |
{ |
183 |
gw_logf(LOG_ERROR, "%s: no DGEE Webservice entry point\n", argv[1]); |
/* An exception was thrown while executing the program */ |
184 |
/* ILExecProcessDestroy(process); */ |
sawException = 1; |
185 |
return 1; |
retval = 1; |
186 |
} |
} |
187 |
|
} |
188 |
|
else |
189 |
|
{ |
190 |
|
/* An exception was thrown while building the argument array */ |
191 |
|
retval = 1; |
192 |
|
} |
193 |
|
|
|
DBG( LOG_DEBUG, "ILExecProcessSetCommandLine" ); |
|
|
/* Convert the arguments into an array of strings */ |
|
|
args = ILExecProcessSetCommandLine(process, argv[1], argv + 2); |
|
|
|
|
|
/* Call the entry point */ |
|
|
sawException = 0; |
|
|
if(args != 0 && !ILExecThreadHasException(thread)) |
|
|
{ |
|
|
retval = 0; |
|
|
DBG( LOG_DEBUG, "ILExecThreadCallV" ); |
|
194 |
|
|
195 |
retval = CallStaticConstructor(thread, method); |
/* Print the top-level exception that occurred */ |
196 |
sawException = retval; |
if(sawException) |
197 |
execValue.ptrValue = args; |
{ |
198 |
|
DBG( LOG_DEBUG, "sawException" ); |
199 |
|
|
200 |
if( !sawException && |
exception = ILExecThreadGetException(thread); |
201 |
ILExecThreadCallV(thread, method, (ILExecValue*)&resultString, &execValue)) |
ILExecThreadClearException(thread); |
202 |
{ |
argString = ILObjectToString(thread, exception); |
203 |
/* An exception was thrown while executing the program */ |
if(argString != 0 && (param = ILStringToAnsi(thread, argString)) != 0) |
204 |
sawException = 1; |
{ |
205 |
retval = 1; |
gw_logf( LOG_ERROR, "Uncaught exception: %s\n", param); |
|
} |
|
206 |
} |
} |
207 |
else |
else if(exception) |
208 |
{ |
{ |
209 |
/* An exception was thrown while building the argument array */ |
gw_logf(LOG_ERROR, "An exception occurred which could not be converted into a string\n" ); |
|
retval = 1; |
|
210 |
} |
} |
211 |
|
else |
|
|
|
|
/* Print the top-level exception that occurred */ |
|
|
if(sawException) |
|
212 |
{ |
{ |
213 |
DBG( LOG_DEBUG, "sawException" ); |
gw_logf( LOG_ERROR, "virtual memory exhausted\n" ); |
|
|
|
|
exception = ILExecThreadGetException(thread); |
|
|
ILExecThreadClearException(thread); |
|
|
argString = ILObjectToString(thread, exception); |
|
|
if(argString != 0 && (param = ILStringToAnsi(thread, argString)) != 0) |
|
|
{ |
|
|
gw_logf( LOG_ERROR, "Uncaught exception: %s\n", param); |
|
|
} |
|
|
else if(exception) |
|
|
{ |
|
|
gw_logf(LOG_ERROR, "An exception occurred which could not be converted into a string\n" ); |
|
|
} |
|
|
else |
|
|
{ |
|
|
gw_logf( LOG_ERROR, "virtual memory exhausted\n" ); |
|
|
} |
|
214 |
} |
} |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
/* Clean up the process and exit */ |
/* Clean up the process and exit */ |
219 |
error = ILExecProcessGetStatus(process); |
error = ILExecProcessGetStatus(process); |
220 |
|
|
221 |
return (int)retval; |
return (int)retval; |
222 |
} |
} |
223 |
|
|
224 |
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |