[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pnet-developers] Embedding pnet
From: |
BRUNET Pierre-Marie - stagiaire |
Subject: |
[Pnet-developers] Embedding pnet |
Date: |
Tue, 26 Apr 2005 11:54:31 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; fr-FR; rv:1.6) Gecko/20040113 |
Hi, I'm a french student working on pnet. I try to embed pnet into my
application.
My goal is to launch pnet into a pthread and run an assembly over it :
( ) ( ) ( ) <- toto.exe
| | |
| | | <- pthread running pnet
| | |
| | |
___________
| |
| Process |
|____________|
I copied ilrun.c but "SegFault" appeared when mixed with pthreads...
Is it possible to do this, and how ????
Thanks a lot !
my prog :
#include <il_engine.h>
#include <gc.h>
#include <pthread.h>
typedef struct{
char *program;
char** argv;
ILObject *arg_prog;
ILExecProcess *process;
ILMethod *method;
ILExecThread *thread;
ILObject *args;
}pthread_arg;
static int CallStaticConstructor(ILExecThread *thread, ILMethod * method){
ILClass *classInfo=ILMethod_Owner(method);
ILMethod *cctor = 0;
while( (cctor = (ILMethod *)ILClassNextMemberByKind(classInfo,
(ILMember *)cctor,IL_META_MEMBERKIND_METHOD)) != 0 ) {
if(ILMethod_IsStaticConstructor(cctor)){
if(ILExecThreadCall(thread, cctor, NULL)){
return 1;
}
}
}
return 0;
}
void *main_thread_handler (void *argument){
int sawException;
ILInt32 retval;
ILExecValue execValue;
ILExecValue retValue;
unsigned long stackSize = IL_CONFIG_STACK_SIZE;
unsigned long heapSize = IL_CONFIG_GC_HEAP_SIZE;
unsigned long methodCachePageSize = IL_CONFIG_CACHE_PAGE_SIZE;
ILExecProcess *process;
ILMethod *method;
ILExecThread *thread;
ILObject *args;
char *program;
int error;
pthread_arg structArg = *(pthread_arg *)argument;
program = structArg.argv[1];
if (ILExecInit(heapSize) != IL_EXEC_INIT_OK){
fprintf(stderr,"Erreur lors de l initialisation\n");
exit(1);
}
process = ILExecProcessCreate(stackSize, methodCachePageSize);
if(!process){
fprintf(stderr,"Erreur lors de la creation de process\n");
ILExecProcessDestroy(process);
exit(1);
}
error = ILExecProcessLoadFile(process, program);
if (error < 0){
fprintf(stderr,"Erreur lors du chargement de fichier.\n");
ILExecProcessDestroy(process);
exit(1);
}
method = ILExecProcessGetEntry(process);
if(!method){
fprintf(stderr,"Erreur : no program entry point\n");
ILExecProcessDestroy(process);
exit(1);
}
if(ILExecProcessEntryType(method) == IL_ENTRY_INVALID){
fprintf(stderr,"Erreur : invalid entry point\n");
ILExecProcessDestroy(process);
exit(1);
}
thread = ILExecProcessGetMain(process);
args = ILExecProcessSetCommandLine( process, program, structArg.argv + 2);
sawException = 0;
if(args != 0 && !ILExecThreadHasException(thread)){
retval = CallStaticConstructor(thread, method);
sawException = retval;
execValue.ptrValue = args;
ILMemZero(&retValue, sizeof(retValue));
if(!sawException && ILExecThreadCallV
(thread, method, &retValue, &execValue)){
sawException = 1;
retval = 1;
} else if(!sawException){
retval = retValue.int32Value;
}
} else {
retval = 1;
}
if(sawException &&
!ILExecThreadIsThreadAbortException(thread,
ILExecThreadGetException(thread))){
ILExecThreadPrintException(thread);
}
ILThreadWaitForForegroundThreads(-1);
ILExecProcessDestroy(process);
pthread_exit(0);
}
int main (int argc, char **argv){
pthread_t *pthread_tab;
pthread_arg *structArg;
int i;
if (argc < 2 ){
fprintf(stderr,"Usage : %s [assembly to load]\n",argv[0]);
exit(1);
}
pthread_tab = (pthread_t *)calloc(1,sizeof(pthread_t));
structArg = (pthread_arg *)calloc(1,sizeof(pthread_arg));
for (i=0 ; i<1 ; i++){
structArg[i].argv = argv;
pthread_create(&pthread_tab[i],NULL,main_thread_handler,&structArg[i]);
}
for (i=0 ; i<1 ; i++){
pthread_join(pthread_tab[i],NULL);
}
free (pthread_tab);
free (structArg);
exit(0);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pnet-developers] Embedding pnet,
BRUNET Pierre-Marie - stagiaire <=