Update of /cvsroot/pywin32/pywin32/com/win32com/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9421/com/win32com/src
Modified Files:
univgw.cpp
Log Message:
prevent win32com.universal triggering DEP (yay!)
Index: univgw.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/univgw.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** univgw.cpp 19 Dec 2008 02:28:48 -0000 1.12
--- univgw.cpp 4 Feb 2009 02:34:24 -0000 1.13
***************
*** 215,220 ****
// make a copy of code and plug in the appropriate values.
! // NOTE: the call address is relative
! code = (unsigned char *)malloc(sizeof(func_template));
memcpy(code, func_template, sizeof(func_template));
*(long *)&code[19] = index;
--- 215,226 ----
// make a copy of code and plug in the appropriate values.
! // NOTE: the call address is relative, and that the memory we allocate
! // must be marked as 'executable' or DEP will kill us. To be good
! // citizens we leave the final page 'executable' but read-only.
! code = (unsigned char *)VirtualAlloc(NULL, sizeof(func_template), MEM_COMMIT, PAGE_READWRITE);
! if (code==NULL) {
! PyErr_NoMemory();
! return NULL; // caller sets memory error
! }
memcpy(code, func_template, sizeof(func_template));
*(long *)&code[19] = index;
***************
*** 222,225 ****
--- 228,238 ----
*(short *)&code[35] = argsize;
+ DWORD oldprotect;
+ if (!VirtualProtect(code, sizeof(func_template), PAGE_EXECUTE, &oldprotect)) {
+ VirtualFree(code, 0, MEM_RELEASE);
+ PyErr_SetString(PyExc_RuntimeError, "failed to set memory attributes to executable");
+ return NULL;
+ }
+
#else // _M_IX86
/* The MAINWIN toolkit allows us to build this on Linux!!! */
***************
*** 310,315 ****
for ( int i = vtbl->cMethod; i-- > (int)vtbl->cReservedMethods; )
if ( vtbl->methods[i] != NULL )
! free((void *)vtbl->methods[i]);
! free(vtbl);
}
--- 323,328 ----
for ( int i = vtbl->cMethod; i-- > (int)vtbl->cReservedMethods; )
if ( vtbl->methods[i] != NULL )
! VirtualFree((void *)vtbl->methods[i], 0, MEM_RELEASE);
! VirtualFree(vtbl, 0, MEM_RELEASE);
}
***************
*** 365,369 ****
// compute the size of the structure plus the method pointers
size_t size = sizeof(gw_vtbl) + count * sizeof(pfnGWMethod);
! gw_vtbl * vtbl = (gw_vtbl *)malloc(size);
if ( vtbl == NULL )
{
--- 378,385 ----
// compute the size of the structure plus the method pointers
size_t size = sizeof(gw_vtbl) + count * sizeof(pfnGWMethod);
! // NOTE: we are allocating a function pointer, so the memory we
! // allocate must be marked as 'executable' or DEP will kill us. To be
! // good citizens we leave the final page 'executable' but read-only.
! gw_vtbl * vtbl = (gw_vtbl *)VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
if ( vtbl == NULL )
{
***************
*** 372,376 ****
return NULL;
}
! memset(vtbl, 0, size);
vtbl->magic = GW_VTBL_MAGIC;
--- 388,392 ----
return NULL;
}
! // memset(vtbl, 0, size); - reset by VirtualAlloc
vtbl->magic = GW_VTBL_MAGIC;
***************
*** 411,422 ****
pfnGWMethod meth = make_method(i, argSize + sizeof(gw_object *));
if ( meth == NULL )
- {
- (void)PyErr_NoMemory();
goto error;
- }
vtbl->methods[i + numReservedVtables] = meth;
}
Py_DECREF(methods);
PyObject *result;
--- 427,441 ----
pfnGWMethod meth = make_method(i, argSize + sizeof(gw_object *));
if ( meth == NULL )
goto error;
vtbl->methods[i + numReservedVtables] = meth;
}
Py_DECREF(methods);
+ DWORD oldprotect;
+ if (!VirtualProtect(vtbl, size, PAGE_EXECUTE, &oldprotect)) {
+ free_vtbl(vtbl);
+ PyErr_SetString(PyExc_RuntimeError, "failed to set memory attributes to executable");
+ goto error;
+ }
PyObject *result;
|