Bugzilla – Bug 320036
memory for DynamicMethods should not be malloced
Last modified: 2008-06-25 15:24:30 UTC
---- Reported by lupus@ximian.com 2006-01-13 11:06:47 MST ---- Currently we allocate the memory for the native code for DynamicMethods with malloc and mprotect it to be executable. This is the wrong thing to do, since it means we're mprotecting all over the address space, even memory that is not used for the dynamic method, since mprotect only works for page sized chunks. Also, when we'll free the memory, the page will remain executable. The Dynamic method code should use the usual method for allocating executable memory in page-sized chunks (we could have a global MonoCodeManager for dynamic methods) and allocate the needed memory from that space. Obviuosly this requires a small malloc-like implementation. Unknown operating system unknown. Setting to default OS "Other".
This also seems to cause problems under Windows with Data Execution Prevention (DEP) on.
Expanding on DEP problem on Windows: For dynamic methods, mono-codeman allocates memory using malloc (which does not set proper execute bits on Windows). Additionally, a call to mono_mprotect is never made on Windows in that case (#ifdef'd out), so trying to execute that code with DEP on results in access violation. I can't tell from the log why #ifdef was added there (it just says "don't call mono_mprotect on windows", svn rev. 71629).
This should now be fixed in SVN. Could you try this patch on windows: http://lists.ximian.com/pipermail/mono-patches/2008-April/115112.html
This patch makes it work under DEP correctly (only tested with Mono compiled with Visual Studio though).
*** Bug 403721 has been marked as a duplicate of this bug. ***