29 |
#endif |
#endif |
30 |
|
|
31 |
#include "pnetvm.h" |
#include "pnetvm.h" |
32 |
|
#include "clrCache.h" |
33 |
#include "dgreadenv.h" |
#include "dgreadenv.h" |
34 |
|
|
35 |
#include <gwtypes.h> |
#include <gwtypes.h> |
40 |
static ILObject *resultString = NULL; |
static ILObject *resultString = NULL; |
41 |
|
|
42 |
#ifdef __cplusplus |
#ifdef __cplusplus |
43 |
extern "C" { |
extern "C" |
44 |
|
{ |
45 |
#endif |
#endif |
46 |
|
|
47 |
/* #define DBG gw_logf */ |
/* #define DBG gw_logf */ |
48 |
#define DBG if(0) gw_logf |
#define DBG if(0) gw_logf |
49 |
|
|
50 |
|
/* Include internal call stuff |
51 |
|
*/ |
52 |
|
#include "int_dgee.c" |
53 |
|
|
54 |
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
55 |
|
|
56 |
static int CallStaticConstructor(ILExecThread *thread, ILMethod * method) |
static int |
57 |
|
CallStaticConstructor(ILExecThread *thread, ILMethod * method) |
58 |
{ |
{ |
59 |
ILClass *classInfo = ILMethod_Owner(method); |
ILClass *classInfo = ILMethod_Owner(method); |
60 |
ILMethod *cctor = 0; |
ILMethod *cctor = 0; |
61 |
|
|
62 |
while((cctor = (ILMethod *)ILClassNextMemberByKind |
while((cctor = (ILMethod *)ILClassNextMemberByKind |
63 |
(classInfo, (ILMember *)cctor, IL_META_MEMBERKIND_METHOD)) != 0) |
(classInfo, (ILMember *)cctor, IL_META_MEMBERKIND_METHOD)) != 0) |
64 |
{ |
{ |
65 |
if(ILMethod_IsStaticConstructor(cctor)) |
if(ILMethod_IsStaticConstructor(cctor)) |
66 |
{ |
{ |
67 |
if(ILExecThreadCall(thread, cctor, NULL)) |
if(ILExecThreadCall(thread, cctor, NULL)) |
68 |
{ |
{ |
69 |
/* An exception was thrown while executing the program */ |
/* An exception was thrown while executing the program */ |
70 |
return 1; |
return 1; |
71 |
} |
} |
72 |
} |
} |
73 |
} |
} |
74 |
return 0; |
return 0; |
75 |
} |
} |
76 |
|
|
77 |
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
78 |
|
|
79 |
int |
int |
80 |
pnetvm_entry(int argc, char *argv[]) |
pnetvm_entry(char *invoke) |
81 |
{ |
{ |
82 |
char *progname = argv[0]; |
char *progname = invoke; |
83 |
unsigned long heapSize = IL_CONFIG_GC_HEAP_SIZE; |
unsigned long heapSize = IL_CONFIG_GC_HEAP_SIZE; |
84 |
unsigned long stackSize = IL_CONFIG_STACK_SIZE; |
unsigned long stackSize = IL_CONFIG_STACK_SIZE; |
85 |
unsigned long methodCachePageSize = IL_CONFIG_CACHE_PAGE_SIZE; |
unsigned long methodCachePageSize = IL_CONFIG_CACHE_PAGE_SIZE; |
86 |
char **libraryDirs; |
char **libraryDirs; |
87 |
int numLibraryDirs; |
int numLibraryDirs; |
|
char *param; |
|
|
ILMethod *method; |
|
88 |
int error; |
int error; |
|
ILInt32 retval; |
|
|
ILObject *args; |
|
|
ILString *argString; |
|
|
ILObject *exception; |
|
|
ILExecValue execValue; |
|
|
int sawException; |
|
|
int flags = 2; |
|
89 |
|
|
90 |
char dgeeWSdir[128] = {0}; |
char dgeeWSdir[128] = {0}; |
91 |
|
|
92 |
DBG( LOG_DEBUG, "cleanup" ); |
DBG( LOG_DEBUG, "cleanup" ); |
93 |
if( process ) pnetvm_cleanup(); |
/* if( process ) pnetvm_cleanup(); */ |
94 |
|
/* TODO : cycle after it reaches critical */ |
95 |
|
if( process ) return 0; |
96 |
|
|
97 |
thread = NULL; |
thread = NULL; |
98 |
process = NULL; |
process = NULL; |
107 |
|
|
108 |
DBG( LOG_DEBUG, "ILMalloc" ); |
DBG( LOG_DEBUG, "ILMalloc" ); |
109 |
/* Allocate space for the library list */ |
/* Allocate space for the library list */ |
110 |
libraryDirs = (char **)ILMalloc(sizeof(char *) * argc); |
libraryDirs = (char **)ILMalloc(sizeof(char *) * 2); |
111 |
numLibraryDirs = 0; |
numLibraryDirs = 0; |
112 |
|
|
113 |
DBG( LOG_DEBUG, "ILExecProcessCreate" ); |
DBG( LOG_DEBUG, "ILExecProcessCreate" ); |
114 |
/* Create a process to load the program into */ |
/* Create a process to load the program into */ |
115 |
process = ILExecProcessCreate(stackSize, methodCachePageSize); |
process = ILExecProcessCreate(stackSize, methodCachePageSize); |
116 |
|
|
117 |
if(!process) |
if(!process) { |
118 |
{ |
printf( "%s: could not create process\n", progname); |
119 |
printf( "%s: could not create process\n", progname); |
return 1; |
120 |
return 1; |
} |
|
} |
|
|
|
|
|
ILExecProcessSetCoderFlags(process,flags); |
|
|
|
|
121 |
sprintf( dgeeWSdir, "%s/data", dgee_repository ); |
sprintf( dgeeWSdir, "%s/data", dgee_repository ); |
122 |
|
|
123 |
DBG( LOG_DEBUG, "dgee_repository: %s", dgeeWSdir ); |
DBG( LOG_DEBUG, "dgee_repository: %s", dgeeWSdir ); |
127 |
|
|
128 |
DBG( LOG_DEBUG, "Building PNETVM...." ); |
DBG( LOG_DEBUG, "Building PNETVM...." ); |
129 |
/* Set the list of directories to use for path searching */ |
/* Set the list of directories to use for path searching */ |
130 |
if(numLibraryDirs > 0) |
|
131 |
{ |
if(numLibraryDirs > 0) { |
132 |
ILExecProcessSetLibraryDirs(process, libraryDirs, numLibraryDirs); |
ILExecProcessSetLibraryDirs(process, libraryDirs, numLibraryDirs); |
133 |
} |
} |
134 |
|
|
135 |
DBG( LOG_DEBUG, "ILExecProcessLoadFile" ); |
DBG( LOG_DEBUG, "ILExecProcessLoadFile" ); |
136 |
/* Attempt to load the program into the process */ |
/* Attempt to load the program into the process */ |
137 |
error = ILExecProcessLoadFile(process, argv[1]); |
error = ILExecProcessLoadFile(process, invoke); |
|
if(error != 0) |
|
|
{ |
|
|
gw_logf(LOG_ERROR, "%s: %s\n", argv[1], ILImageLoadError(error)); |
|
|
return 1; |
|
|
} |
|
138 |
|
|
139 |
|
if(error != 0) { |
140 |
|
gw_logf(LOG_ERROR, "%s: %s\n", invoke, ILImageLoadError(error)); |
141 |
|
return 1; |
142 |
|
} |
143 |
|
|
144 |
|
/* Import internalCalls from int_dgee.c |
145 |
|
*/ |
146 |
|
ILExecProcessAddInternalCallTable( process, |
147 |
|
(ILEngineInternalClassInfo*)internalClassTable, |
148 |
|
numInternalClasses ); |
149 |
|
|
150 |
|
|
151 |
|
return 0; |
152 |
|
|
153 |
|
} |
154 |
|
|
155 |
|
/* ------------------------------------------------------------------------- */ |
156 |
|
|
157 |
|
char * |
158 |
|
pnetvm_get_reply_xml(int argc, char* argv[]) |
159 |
|
{ |
160 |
|
static char *xml = NULL; |
161 |
|
ILString *argString = NULL; |
162 |
|
ILMethod *method = NULL; |
163 |
|
ILObject *args = NULL; |
164 |
|
ILObject *exception = NULL; |
165 |
|
char *param = NULL; |
166 |
|
ILInt32 retval; |
167 |
|
ILExecValue execValue; |
168 |
|
|
169 |
|
int sawException; |
170 |
|
|
171 |
|
if(!process) return NULL; |
172 |
|
|
173 |
DBG( LOG_DEBUG, "ILExecProcessGetMain" ); |
DBG( LOG_DEBUG, "ILExecProcessGetMain" ); |
174 |
thread = ILExecProcessGetMain(process); |
thread = ILExecProcessGetMain(process); |
175 |
|
|
176 |
DBG( LOG_DEBUG, "ILExecThreadLookupMethod" ); |
DBG( LOG_DEBUG, "ILExecThreadLookupMethod" ); |
177 |
/* Locate Entry Point for DotGNU WebService */ |
/* Locate Entry Point for DotGNU WebService */ |
178 |
/* ILExecThreadLookupMethod(Type name, Method name, Signature) */ |
/* ILExecThreadLookupMethod(Type name, Method name, Signature) */ |
179 |
method = ILExecThreadLookupMethod(thread, PROTOCOL_TYPE_NAME, "DGEE_run", |
method = ILExecThreadLookupMethod(thread, |
180 |
"([oSystem.String;)oSystem.String;" ); |
PROTOCOL_TYPE_NAME, |
181 |
|
"DGEE_run", |
182 |
if(!method) |
"([oSystem.String;)oSystem.String;" ); |
183 |
{ |
|
184 |
gw_logf(LOG_ERROR, "%s: no DGEE Webservice entry point [%s]\n", argv[1], PROTOCOL_TYPE_NAME); |
if(!method) { |
185 |
/* ILExecProcessDestroy(process); */ |
gw_logf(LOG_ERROR, "%s: no DGEE Webservice entry point\n", argv[1]); |
186 |
return 1; |
/* ILExecProcessDestroy(process); */ |
187 |
} |
return NULL; |
188 |
|
} |
189 |
|
|
190 |
DBG( LOG_DEBUG, "ILExecProcessSetCommandLine" ); |
DBG( LOG_DEBUG, "ILExecProcessSetCommandLine" ); |
191 |
/* Convert the arguments into an array of strings */ |
/* Convert the arguments into an array of strings */ |
193 |
|
|
194 |
/* Call the entry point */ |
/* Call the entry point */ |
195 |
sawException = 0; |
sawException = 0; |
196 |
if(args != 0 && !ILExecThreadHasException(thread)) |
if(args != 0 && !ILExecThreadHasException(thread)) { |
197 |
{ |
retval = CallStaticConstructor(thread, method); |
198 |
retval = 0; |
sawException = retval; |
199 |
DBG( LOG_DEBUG, "ILExecThreadCallV" ); |
execValue.ptrValue = args; |
200 |
|
|
201 |
retval = CallStaticConstructor(thread, method); |
if( !sawException && |
202 |
sawException = retval; |
ILExecThreadCallV(thread, method, (ILExecValue*)&resultString, &execValue)) { |
203 |
execValue.ptrValue = args; |
gw_logf(LOG_ERROR, "%s: no DGEE Webservice entry point\n", argv[1]); |
204 |
|
/* ILExecProcessDestroy(process); */ |
205 |
if( !sawException && |
return NULL; |
|
ILExecThreadCallV(thread, method, (ILExecValue*)&resultString, &execValue)) |
|
|
{ |
|
|
/* An exception was thrown while executing the program */ |
|
|
sawException = 1; |
|
|
retval = 1; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
/* An exception was thrown while building the argument array */ |
|
|
retval = 1; |
|
206 |
} |
} |
207 |
|
} else { |
208 |
|
/* An exception was thrown while building the argument array */ |
209 |
|
retval = 1; |
210 |
|
} |
211 |
|
|
212 |
/* Print the top-level exception that occurred */ |
/* Print the top-level exception that occurred */ |
213 |
if(sawException) |
if(sawException) { |
214 |
{ |
DBG( LOG_DEBUG, "sawException" ); |
|
DBG( LOG_DEBUG, "sawException" ); |
|
|
|
|
|
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" ); |
|
|
} |
|
|
} |
|
215 |
|
|
216 |
|
exception = ILExecThreadGetException(thread); |
217 |
|
ILExecThreadClearException(thread); |
218 |
|
argString = ILObjectToString(thread, exception); |
219 |
|
if(argString != 0 && (param = ILStringToAnsi(thread, argString)) != 0) |
220 |
|
{ |
221 |
|
gw_logf( LOG_ERROR, "Uncaught exception: %s\n", param); |
222 |
|
} |
223 |
|
else if(exception) |
224 |
|
{ |
225 |
|
gw_logf(LOG_ERROR, "An exception occurred which could not be converted into a string\n" ); |
226 |
|
} |
227 |
|
else |
228 |
|
{ |
229 |
|
gw_logf( LOG_ERROR, "virtual memory exhausted\n" ); |
230 |
|
} |
231 |
|
} |
232 |
|
|
|
/* Clean up the process and exit */ |
|
|
error = ILExecProcessGetStatus(process); |
|
|
|
|
|
return (int)retval; |
|
|
} |
|
|
|
|
|
/* ------------------------------------------------------------------------- */ |
|
|
|
|
|
char * |
|
|
pnetvm_get_reply_xml() |
|
|
{ |
|
|
static char *xml = NULL; |
|
|
ILString *argString; |
|
233 |
|
|
234 |
if( process ) { |
if(sawException == 0 && retval == 0) |
235 |
argString = ILObjectToString(thread, resultString); |
{ |
236 |
if( argString && (xml = ILStringToAnsi(thread, argString)) ) return xml; |
argString = ILObjectToString(thread, resultString); |
237 |
} |
if( argString && (xml = ILStringToAnsi(thread, argString)) ) return xml; |
238 |
|
} |
239 |
|
|
240 |
|
if(sawException == 1 || retval == 1) |
241 |
|
{ |
242 |
|
pnetvm_cleanup(); |
243 |
|
} |
244 |
return NULL; |
return NULL; |
245 |
} |
} |
246 |
|
|
250 |
pnetvm_cleanup() |
pnetvm_cleanup() |
251 |
{ |
{ |
252 |
if( process ) { |
if( process ) { |
253 |
/* - This was PRE Threading |
/* ILGCCollect(); |
254 |
ILGCCollect(); |
ILGCInvokeFinalizers();*/ |
|
ILGCInvokeFinalizers(); |
|
|
*/ |
|
255 |
|
|
256 |
ILExecProcessDestroy(process); |
ILExecProcessDestroy(process); |
|
ILExecDeinit(); |
|
257 |
} |
} |
258 |
process = NULL; |
process = NULL; |
259 |
} |
} |