<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello,<br>
I will put it in the 'master-pu' branch for building and testing!<br>
<br>
BR Fredrik Gustafsson (Terran player)<br>
Erlang OTP Team<br>
On 02/06/2013 04:27 AM, Blaine Whittle wrote:
<blockquote
cite="mid:CA6DD6A22A5FD840943A5F165006F42689D79B39@IRVEX006.corp.blizzard.net"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">git fetch git://github.com/bwhittle/otp.git
win-64-pointer-fix<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><a moz-do-not-send="true"
href="https://github.com/bwhittle/otp/commit/1d21ce8d0287a0a50b2e42631d361f43ce14e23e">https://github.com/bwhittle/otp/commit/1d21ce8d0287a0a50b2e42631d361f43ce14e23e</a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This patch should fix a number of memory
corruption issues and / or crashes on Win64 that can potential
occur when the Erlang VM exceeds 4 GB of ram. The problem
stems from casting pointers to unsigned long and assuming long
is type that is always large enough to hold a pointer. This
assumption holds up for all platforms except windows.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Nix 32 (unsigned long) -> 32 bit
(pointer size = unsigned long)<o:p></o:p></p>
<p class="MsoNormal">Nix 64 (unsigned long) -> 64 bit
(pointer size = unsigned long)<o:p></o:p></p>
<p class="MsoNormal">Win 32 (unsigned long) -> 32
bit (pointer size = unsigned long)<o:p></o:p></p>
<p class="MsoNormal">Win 64 (unsigned long) -> 32
bit (pointer size != unsigned long)
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">To compound the problem these casts can
appear to be fine on Win64 as only those pointers that
reference memory above the 32 bit address space will lead to
issues. Which means you need Erlang to allocate ~ 4 GB of
memory before you even have a chance or running into
problems. The issue is if you have a pointer that
reference memory above the 32 bit address space on Win64 and
then type cast it to a long (i.e. 32 bits) and then turn
around and use that type cast value as a pointer then you’ll
be referencing a different memory location. Most of the time
the incorrect pointer will still reference a valid location as
memory is allocated bottom up which can lead to memory
corruption.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This patch has been tested heavily and has
been used on production systems. I made the changes a year
ago when the Win64 Erlang VM was released (just didn’t mean to
wait so long to submit it.)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The patch submission page recommends that I
create new test cases which I have not done. However I have
a small registry change that should be applied on any systems
that execute Erlang Win64 smoke and / or unit tests.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The registry change instructs Windows to
allocate memory from top down, meaning that any valid memory
pointers will require a 64 bit value and any attempt to cast
them to a 32 bit value followed by a dereference will produce
an access violation.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><a class="moz-txt-link-freetext" href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb613473(v=vs.85).aspx">http://msdn.microsoft.com/en-us/library/windows/desktop/bb613473(v=vs.85).aspx</a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">To apply the registry setting just copy and
paste the following section and place it into a <some
name>.reg file and import it on each test machines followed
by a reboot.
<o:p></o:p></p>
<p class="MsoNormal">=============================================================<o:p></o:p></p>
<p class="MsoNormal">Windows Registry Editor Version 5.00<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Memory Management]<o:p></o:p></p>
<p class="MsoNormal">"AllocationPreference"=dword:00100000. <o:p></o:p></p>
<p class="MsoNormal">=============================================================<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">With this registry change Erlang’s existing
unit tests should be able to catch any incorrect pointer casts
by causing the VM to crash. Every pointer will reference
memory above the 32 value so type casting it to a 32 bit value
and then dereferencing causes an access violation. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">One potential issue with using this
registry setting is that if your test machines rely on 3rd
party Win64 apps it’s possible they may crash on startup (that
is if they contain similar type casting bugs.)<o:p></o:p></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
erlang-patches mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-patches@erlang.org">erlang-patches@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-patches">http://erlang.org/mailman/listinfo/erlang-patches</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
BR Fredrik Gustafsson
Erlang OTP Team</pre>
</body>
</html>