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 |
57 |
|
CallStaticConstructor(ILExecThread *thread, ILMethod * method) |
58 |
|
{ |
59 |
|
ILClass *classInfo = ILMethod_Owner(method); |
60 |
|
ILMethod *cctor = 0; |
61 |
|
|
62 |
|
while((cctor = (ILMethod *)ILClassNextMemberByKind |
63 |
|
(classInfo, (ILMember *)cctor, IL_META_MEMBERKIND_METHOD)) != 0) |
64 |
|
{ |
65 |
|
if(ILMethod_IsStaticConstructor(cctor)) |
66 |
|
{ |
67 |
|
if(ILExecThreadCall(thread, cctor, NULL)) |
68 |
|
{ |
69 |
|
/* An exception was thrown while executing the program */ |
70 |
|
return 1; |
71 |
|
} |
72 |
|
} |
73 |
|
} |
74 |
|
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 |
char **libraryDirs; |
unsigned long methodCachePageSize = IL_CONFIG_CACHE_PAGE_SIZE; |
86 |
int numLibraryDirs; |
char **libraryDirs; |
87 |
char *param; |
int numLibraryDirs; |
88 |
ILMethod *method; |
int error; |
89 |
int error; |
|
90 |
ILInt32 retval; |
char dgeeWSdir[128] = {0}; |
91 |
ILObject *args; |
|
92 |
ILString *argString; |
DBG( LOG_DEBUG, "cleanup" ); |
93 |
ILObject *exception; |
/* if( process ) pnetvm_cleanup(); */ |
94 |
int sawException; |
/* TODO : cycle after it reaches critical */ |
95 |
|
if( process ) return 0; |
96 |
char dgeeWSdir[128] = {0}; |
|
97 |
|
thread = NULL; |
98 |
DBG( LOG_DEBUG, "cleanup" ); |
process = NULL; |
99 |
if( process ) pnetvm_cleanup(); |
|
100 |
|
DBG( LOG_DEBUG, "locale" ); |
101 |
thread = NULL; |
/* Initialize the locale routines */ |
102 |
process = NULL; |
ILInitLocale(); |
103 |
|
|
104 |
DBG( LOG_DEBUG, "locale" ); |
DBG( LOG_DEBUG, "ILExecInit" ); |
105 |
/* Initialize the locale routines */ |
/* Initialize the engine and set the maximum heap size */ |
106 |
ILInitLocale(); |
ILExecInit(heapSize); |
107 |
|
|
108 |
DBG( LOG_DEBUG, "ILExecInit" ); |
DBG( LOG_DEBUG, "ILMalloc" ); |
109 |
/* Initialize the engine and set the maximum heap size */ |
/* Allocate space for the library list */ |
110 |
ILExecInit(heapSize); |
libraryDirs = (char **)ILMalloc(sizeof(char *) * 2); |
111 |
|
numLibraryDirs = 0; |
|
DBG( LOG_DEBUG, "ILMalloc" ); |
|
|
/* Allocate space for the library list */ |
|
|
libraryDirs = (char **)ILMalloc(sizeof(char *) * argc); |
|
|
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); |
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; |
} |
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 ); |
124 |
|
|
125 |
libraryDirs[numLibraryDirs++] = dgee_libdir; |
libraryDirs[numLibraryDirs++] = dgee_libdir; |
126 |
libraryDirs[numLibraryDirs++] = dgeeWSdir; |
libraryDirs[numLibraryDirs++] = 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 */ |
|
if(numLibraryDirs > 0) |
|
|
{ |
|
|
ILExecProcessSetLibraryDirs(process, libraryDirs, numLibraryDirs); |
|
|
} |
|
|
|
|
|
DBG( LOG_DEBUG, "ILExecProcessLoadFile" ); |
|
|
/* Attempt to load the program into the process */ |
|
|
error = ILExecProcessLoadFile(process, argv[1]); |
|
|
if(error != 0) |
|
|
{ |
|
|
gw_logf(LOG_ERROR, "%s: %s\n", argv[1], ILImageLoadError(error)); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
DBG( LOG_DEBUG, "ILExecProcessGetMain" ); |
|
|
thread = ILExecProcessGetMain(process); |
|
|
|
|
|
DBG( LOG_DEBUG, "ILExecThreadLookupMethod" ); |
|
|
/* Locate Entry Point for DotGNU WebService */ |
|
|
/* ILExecThreadLookupMethod(Type name, Method name, Signature) */ |
|
|
method = ILExecThreadLookupMethod(thread, |
|
|
"DotGNU.DGEE.DGEEWSInvoke", |
|
|
"DGEE_run", |
|
|
"([oSystem.String;)oSystem.String;" ); |
|
|
|
|
|
if(!method) |
|
|
{ |
|
|
gw_logf(LOG_ERROR, "%s: no DGEE Webservice entry point\n", argv[1]); |
|
|
/* ILExecProcessDestroy(process); */ |
|
|
return 1; |
|
|
} |
|
|
|
|
|
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, "ILExecThreadCall" ); |
|
|
if(ILExecThreadCall(thread, method, &resultString, args)) |
|
|
{ |
|
|
/* An exception was thrown while executing the program */ |
|
|
sawException = 1; |
|
|
retval = 1; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
/* An exception was thrown while building the argument array */ |
|
|
retval = 1; |
|
|
} |
|
|
|
|
|
|
|
|
/* Print the top-level exception that occurred */ |
|
|
if(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" ); |
|
|
} |
|
|
} |
|
130 |
|
|
131 |
|
if(numLibraryDirs > 0) { |
132 |
|
ILExecProcessSetLibraryDirs(process, libraryDirs, numLibraryDirs); |
133 |
|
} |
134 |
|
|
135 |
/* Clean up the process and exit */ |
DBG( LOG_DEBUG, "ILExecProcessLoadFile" ); |
136 |
error = ILExecProcessGetStatus(process); |
/* Attempt to load the program into the process */ |
137 |
|
error = ILExecProcessLoadFile(process, invoke); |
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 |
|
|
|
return (int)retval; |
|
153 |
} |
} |
154 |
|
|
155 |
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
156 |
|
|
157 |
char * |
char * |
158 |
pnetvm_get_reply_xml() |
pnetvm_get_reply_xml(int argc, char* argv[]) |
159 |
{ |
{ |
160 |
static char *xml = NULL; |
static char *xml = NULL; |
161 |
ILString *argString; |
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" ); |
174 |
|
thread = ILExecProcessGetMain(process); |
175 |
|
|
176 |
|
DBG( LOG_DEBUG, "ILExecThreadLookupMethod" ); |
177 |
|
/* Locate Entry Point for DotGNU WebService */ |
178 |
|
/* ILExecThreadLookupMethod(Type name, Method name, Signature) */ |
179 |
|
|
180 |
|
#if 1 |
181 |
|
method = ILExecThreadLookupMethod(thread, |
182 |
|
"DotGNU.DGEE.Protocols.XmlRpcService", |
183 |
|
"DGEE_execute", |
184 |
|
"([oSystem.String;)oSystem.String;" ); |
185 |
|
#else |
186 |
|
method = ILExecProcessGetEntry(process); |
187 |
|
#endif |
188 |
|
|
189 |
if( process ) { |
if(!method) { |
190 |
argString = ILObjectToString(thread, resultString); |
gw_logf(LOG_ERROR, "%s: no DGEE Webservice entry point\n", argv[1]); |
191 |
if( argString && (xml = ILStringToAnsi(thread, argString)) ) return xml; |
/* ILExecProcessDestroy(process); */ |
192 |
|
return NULL; |
193 |
} |
} |
194 |
|
|
195 |
|
DBG( LOG_DEBUG, "ILExecProcessSetCommandLine" ); |
196 |
|
/* Convert the arguments into an array of strings */ |
197 |
|
args = ILExecProcessSetCommandLine(process, argv[1], argv + 2); |
198 |
|
|
199 |
|
/* Call the entry point */ |
200 |
|
sawException = 0; |
201 |
|
if(args != 0 && !ILExecThreadHasException(thread)) { |
202 |
|
retval = CallStaticConstructor(thread, method); |
203 |
|
sawException = retval; |
204 |
|
execValue.ptrValue = args; |
205 |
|
|
206 |
|
if( !sawException && |
207 |
|
ILExecThreadCallV(thread, method, (ILExecValue*)&resultString, &execValue)) { |
208 |
|
gw_logf(LOG_ERROR, "%s: Exception thrown executing program\n" ); |
209 |
|
sawException = 1; |
210 |
|
retval = 1; |
211 |
|
/* return NULL; */ |
212 |
|
} |
213 |
|
} else { |
214 |
|
/* An exception was thrown while building the argument array */ |
215 |
|
retval = 1; |
216 |
|
} |
217 |
|
|
218 |
|
/* Print the top-level exception that occurred */ |
219 |
|
if(sawException) { |
220 |
|
DBG( LOG_DEBUG, "sawException" ); |
221 |
|
|
222 |
|
exception = ILExecThreadGetException(thread); |
223 |
|
ILExecThreadClearException(thread); |
224 |
|
argString = ILObjectToString(thread, exception); |
225 |
|
if(argString != 0 && (param = ILStringToAnsi(thread, argString)) != 0) |
226 |
|
{ |
227 |
|
gw_logf( LOG_ERROR, "Uncaught exception: %s\n", param); |
228 |
|
} |
229 |
|
else if(exception) |
230 |
|
{ |
231 |
|
gw_logf(LOG_ERROR, "An exception occurred which could not be converted into a string\n" ); |
232 |
|
} |
233 |
|
else |
234 |
|
{ |
235 |
|
gw_logf( LOG_ERROR, "virtual memory exhausted\n" ); |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
|
if(sawException == 0 && retval == 0) |
241 |
|
{ |
242 |
|
argString = ILObjectToString(thread, resultString); |
243 |
|
if( argString && (xml = ILStringToAnsi(thread, argString)) ) return xml; |
244 |
|
} |
245 |
|
|
246 |
|
if(sawException == 1 || retval == 1) |
247 |
|
{ |
248 |
|
pnetvm_cleanup(); |
249 |
|
} |
250 |
return NULL; |
return NULL; |
251 |
} |
} |
252 |
|
|
256 |
pnetvm_cleanup() |
pnetvm_cleanup() |
257 |
{ |
{ |
258 |
if( process ) { |
if( process ) { |
259 |
ILGCCollect(); |
/* ILGCCollect(); |
260 |
ILGCInvokeFinalizers(); |
ILGCInvokeFinalizers();*/ |
261 |
|
|
262 |
ILExecProcessDestroy(process); |
ILExecProcessDestroy(process); |
263 |
} |
} |