[MPlayer-dev-eng] win32 loader exception handler

Gianluigi Tiesi mplayer at netfarm.it
Tue Feb 1 05:18:52 CET 2005


I'm working on avisynth on linux, but I have two problems,
corrupted stack when I call some functions and win32 misses exception
handler. It can be merged from wine but it's not so easy, I'm attaching
a preliminar patch to win32, also my avs patch is needed, if someone
would to be involved I can work on this, but I'm not very familiar with
exceptions, also I known it's a bit difficult but if someone can help
me to setup the exception handler I can offer my time to make it works.

Regards

-- 
Gianluigi Tiesi <sherpya at netfarm.it>
EDP Project Leader
Netfarm S.r.l. - http://www.netfarm.it/
Free Software: http://oss.netfarm.it/
-------------- next part --------------
Index: loader/Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/loader/Makefile,v
retrieving revision 1.16
diff -u -r1.16 Makefile
--- loader/Makefile	26 Jun 2004 10:40:23 -0000	1.16
+++ loader/Makefile	1 Feb 2005 04:12:23 -0000
@@ -1,9 +1,12 @@
 include ../config.mak
 
 # Generated automatically from Makefile.in by configure.
-DEFINES=-DMPLAYER -D__WINE__ #-Ddbg_printf=__vprintf \
+#DEFINES=-DMPLAYER -D__WINE__ #-Ddbg_printf=__vprintf \
 	#-DTRACE=__vprintf # -DDETAILED_OUT
 
+DEFINES=-DMPLAYER -D__WINE__ -Ddbg_printf=__vprintf \
+	-DTRACE=__vprintf -DDETAILED_OUT
+
 ifeq ($(TARGET_WIN32),yes)
 LIB_OBJECTS= driver.o afl.o vfl.o
 else
Index: loader/win32.c
===================================================================
RCS file: /cvsroot/mplayer/main/loader/win32.c,v
retrieving revision 1.97
diff -u -r1.97 win32.c
--- loader/win32.c	21 Dec 2004 23:26:45 -0000	1.97
+++ loader/win32.c	1 Feb 2005 04:12:25 -0000
@@ -56,6 +56,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <dirent.h>
 #include <sys/time.h>
 #include <sys/timeb.h>
@@ -1870,7 +1871,22 @@
 }
 static long WINAPI expRegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count)
 {
-    long result=RegQueryValueExA(key, value, reserved, type, data, count);
+    /* Sherpya Avisynth plugindir */
+    long result = -1;
+    if (!strcasecmp(value, "PluginDir2_5"))
+    {
+      if (data)
+      {
+         data[0] = 0;
+	 strcat(data, ".");
+	 *count = 1;
+      }
+      else
+         *count = 1;
+      result = ERROR_SUCCESS;
+    }
+    else
+      result=RegQueryValueExA(key, value, reserved, type, data, count);
     dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)"
 	      " => 0x%x\n", key, value, reserved, data, count, result);
     if(data && count)dbgprintf("  read %d bytes: '%s'\n", *count, data);
@@ -3591,7 +3607,7 @@
 	return r;
     }
 
-#if 0
+#if 1
     /* we need this for some virtualdub filters */
     {
 	int r;
@@ -3604,6 +3620,7 @@
 	    printf("Warning: openning filename %s  %d (flags; 0x%x) for write\n", cs1, r, flg);
 	}
 	r=open(cs1, flg);
+	dbgprintf("CreateFileA: %s -> %d\n", cs1, r);
 	return r;
     }
 #endif
@@ -3665,6 +3682,16 @@
     return strlen(shortpath);
 }
 
+static DWORD WINAPI expGetFileSize(HANDLE h, LPDWORD lpFileSizeHigh)
+{
+    /* Sherpya */
+    struct stat info;
+    info.st_size = 0;
+    fstat(h, &info);
+    dbgprintf("GetFileSize(%d, %p) = %d\n", h, lpFileSizeHigh, info.st_size);
+    return info.st_size;
+}
+
 static WIN_BOOL WINAPI expReadFile(HANDLE h,LPVOID pv,DWORD size,LPDWORD rd,LPOVERLAPPED unused)
 {
     int result;
@@ -3749,6 +3776,8 @@
 static LONG WINAPI explstrcmpiA(const char* str1, const char* str2)
 {
     LONG result=strcasecmp(str1, str2);
+    if (str1[0] == '$') return result;
+    if (!strcmp(str2, "Import")) return result;
     dbgprintf("strcmpi(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result);
     return result;
 }
@@ -3892,7 +3921,7 @@
     assert(size >= 0);
 
     result=my_mreq(size,0);
-    dbgprintf("new(%d) => %p\n", size, result);
+//    dbgprintf("new(%d) => %p\n", size, result);
     if (result==0)
 	printf("WARNING: new() failed\n");
     return result;
@@ -4206,7 +4235,7 @@
 static void* expmemmove(void* dest, void* src, int n)
 {
     void* result = memmove(dest, src, n);
-    dbgprintf("memmove(0x%x, 0x%x, %d) => %p\n", dest, src, n, result);
+//    dbgprintf("memmove(0x%x, 0x%x, %d) => %p\n", dest, src, n, result);
     return result;
 }
 static int expmemcmp(void* dest, void* src, int n)
@@ -4694,6 +4723,111 @@
 	return my_realloc(ptr, size);        
 }
 
+/* Sherpya */
+
+typedef void (*vtable_ptr)();
+
+/* exception object */
+typedef struct __exception
+{
+   const vtable_ptr *vtable;
+   char             *name;    /* Name of this exception, always a new copy for each object */
+   int               do_free; /* Whether to free 'name' in our dtor */
+} exception;
+
+/* type_info object, see cpp.c for inplementation */
+typedef struct __type_info
+{
+  const vtable_ptr *vtable;
+  char              *name;        /* Unmangled name, allocated lazily */
+  char               mangled[32]; /* Variable length, but we declare it large enough for static RTTI */
+} type_info;
+
+typedef void (*cxx_copy_ctor)(void);
+
+/* offsets for computing the this pointer */
+typedef struct
+{
+  int         this_offset;   /* offset of base class this pointer from start of object */
+  int         vbase_descr;   /* offset of virtual base class descriptor */
+  int         vbase_offset;  /* offset of this pointer offset in virtual base class descriptor */
+} this_ptr_offsets;
+
+typedef struct __cxx_type_info
+{
+  unsigned int flags;        /* flags (see CLASS_* flags below) */
+  const type_info *type_info;    /* C++ type info */
+  this_ptr_offsets offsets;      /* offsets for computing the this pointer */
+  size_t           size;         /* object size */
+  cxx_copy_ctor copy_ctor;    /* copy constructor */
+} cxx_type_info;
+
+typedef struct __cxx_type_info_table
+{
+  unsigned int count;     /* number of types */
+  const cxx_type_info *info[3];   /* variable length, we declare it large enough for static RTTI */
+} cxx_type_info_table;
+
+typedef struct __cxx_exception_type
+{
+  unsigned int flags;            /* TYPE_FLAG flags */
+  void                     (*destructor)();    /* exception object destructor */
+  /*cxx_exc_custom_handler*/ void*     custom_handler;   /* custom handler for this exception */
+  const cxx_type_info_table *type_info_table;  /* list of types for this exception object */
+} cxx_exception_type;
+
+#if 0
+int exp_except_handler3(/*PEXCEPTION_RECORD */ void * rec,
+                        /*MSVCRT_EXCEPTION_FRAME* */ void *frame,
+                        /*PCONTEXT */ void * context, void* dispatcher)
+{
+    dbgprintf("msvcrt: exp_except_handler3\n");
+    return 0;
+}
+
+int exp__CxxFrameHandler(void)
+{
+    dbgprintf("msvcrt: _CxxFrameHandler\n");
+    return 0;
+}
+#endif
+
+static void exp_CxxThrowException (exception *object, const cxx_exception_type *type)
+{
+    char buf[128];
+    char *seek = NULL;
+    char *name = type->type_info_table->info[0]->type_info->mangled;
+
+    /* Cheap undercoration */
+    name += 4;
+    seek = strstr(name, "@");
+    seek++;
+
+    buf[0]=0;
+    strcat(buf, seek);
+
+    seek = strstr(buf, "@");
+    *seek = 0;
+    strcat(buf, "::");
+    strcat(buf, name);
+    seek = strstr(buf, "@");
+    *seek = 0;
+    dbgprintf("msvcrt: ThrowException: %s\n", buf);
+
+//    __asm__ __volatile__ ("jmp 0x1000D8BF\n\t" : : );
+ //   __asm__ __volatile__ ("jmp %0\n\t" : : "r" (*object->vtable));
+//    __asm__ __volatile__ ("jmp %0\n\t" : : "r" (*type->type_info_table->info));
+
+
+    //DWORD args[3];
+    //args[0] = CXX_FRAME_MAGIC;
+    //args[1] = (DWORD)object;
+    //args[2] = (DWORD)type;
+    //RaiseException(CXX_EXCEPTION, EH_NONCONTINUABLE, 3, args);
+
+}
+
+
 /* Fake GetOpenFileNameA from comdlg32.dll for ViVD codec */
 static WIN_BOOL WINAPI expGetOpenFileNameA(/*LPOPENFILENAMEA*/ void* lpfn)
 {
@@ -4857,6 +4991,7 @@
     FF(FindClose,-1)
     FF(FileTimeToLocalFileTime,-1)
     FF(DeleteFileA,-1)
+    FF(GetFileSize, -1) // Sherpya
     FF(ReadFile,-1)
     FF(WriteFile,-1)
     FF(SetFilePointer,-1)
@@ -4945,6 +5080,10 @@
     FF(printf,-1)
     FF(getenv,-1)
     FF(floor,-1)
+    /* Sherpya */
+    FF(_CxxThrowException,-1)
+//    FF(_except_handler3,-1)
+//    FF(__CxxFrameHandler,-1)
 #ifdef MPLAYER
     FF(_EH_prolog,-1)
 #endif
@@ -5305,7 +5444,7 @@
 	printf("ERROR: name=0\n");
 	return (void*)ext_unknown;
     }
-    dbgprintf("External func %s:%s\n", library, name);
+    //dbgprintf("External func %s:%s\n", library, name);
     for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++)
     {
 	if(strcasecmp(library, libraries[i].name))


More information about the MPlayer-dev-eng mailing list