<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7652.24">
<TITLE>RE: [ofw] WDK build environment migration thoughts</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Hi all,</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">It's a good idea to clarify some points before announcing Mellanox patch for WDK porting and __ptr64 problems.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Hope, these explanations will be informative enough and not so long.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><U><B><FONT SIZE=2 FACE="Arial">1. __ptr64 problem</FONT></B></U><B></B></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Briefly speaking, this problem arises when copying 32bit len pointer into 64bit len pointer. In this case,</FONT><U> <FONT SIZE=2 FACE="Arial">signed pointer extension</FONT></U> <FONT SIZE=2 FACE="Arial">will take place.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">How it's applicable to WinOF ?  A lot of pointer were declared to be __ptr64 (i.e., to be always "long", even in 32bit kernel systems), that's to preserve on unique size of structs used in IOCTL calls.  The main problem it will cause is between 32bit user applications and 64bit kernel application.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">When user code do operation like </FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">s_ptr = &my_struct;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">my_type* __ptr64 ptr = s_ptr;</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Than kernel will receive ptr with invalid upper bits data (4 bytes FF).</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">To avoid signed pointer extension, PtrToPtr64() function should be used.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Also, I found some other places where dangerous signed pointer extension took place, even on 32bit kernel.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Yet another problem that arises with __ptr64 attribute is internal compiler error (C1001)  in WDK when using __ptr64 pointer to function (callback)</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">This problem was described in ofw discussion, you can see also :</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"></SPAN><A HREF="http://blogs.msdn.com/texblog/archive/2005/10/31/487436.aspx"><SPAN LANG="en-us"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://blogs.msdn.com/texblog/archive/2005/10/31/487436.aspx</FONT></U></SPAN></A><SPAN LANG="en-us"></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"></SPAN><A HREF="http://lists.openfabrics.org/pipermail/ofw/2007-July/001613.html"><SPAN LANG="en-us"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://lists.openfabrics.org/pipermail/ofw/2007-July/001613.html</FONT></U></SPAN></A><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"> (posted by Jan from OFW)</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Our solution:</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">1. Initially, we decided to remove all __ptr64 attributes except those ones inside IOCTL structures. After, put PtrToPtr64() conversion on every assignment to long pointer.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">(like my_type* __ptr64 ptr = PtrToPtr64(s_ptr);  )</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">During this solution, we changed a huge amount of code, so patch became unreadable. And it was difficult to validate that all long pointer (with __ptr64 attribute) were used in a proper manner</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">2. So, we decided about another solution:</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"> All __ptr64 occurrences were replaced by either:</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"> i) TO_LONG_PTR(type, field) macro, when occurred inside structure</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">ii) VOID_PTR64 macro otherwise (defined as void macro)</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#define CONCAT(str1, str2) str1##str2</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#define TO_LONG_PTR(type,member_name) \</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">    union { type member_name;  uint64_t CONCAT(member_name,_padding) ; }</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Thus, we can both preserve on a uniform shapes of structs in user and kernel and to avoid unsafe pointer arithmetic !</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">The patch now is much more readable, but it sill consist of thousands lines.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><U><B><FONT SIZE=2 FACE="Arial">2. Migration to WDK</FONT></B></U><B></B></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Main issue here was to preserve on backward compatibility with DDK</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">We were able to compile our stack with WDK, while the main problems we found were :</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">1. WDK uses newer version of SDK (SDK Vista). So, when using 2 or more versions of SDK on the same build machine, one has to update </FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">PLATFORM_SDK_PATH variable to point on the proper version of SDK (for example, PLATFORM_SDK_PATH=%sysdrive%:\PROGRA~1\MI2578~1\windows\v6.1)</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">2.verify.src script in WDK (new add-on) checks if your SOURCES file is in appropriate format.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">For example, you can't set implicitly path to system .dll in TARGETLIBS, but to use USE_<MODULE_NAME> =1 macro</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Example:</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Old code : </FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"> ....</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">TARGETLIBS= \</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">   $(CRT_LIB_PATH)\msvcprt.lib\</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">   $(SDK_LIB_PATH)\Ws2_32.lib\</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">   $(TARGETPATH)\*\mtcr.lib</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"> </FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">New code :</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">USE_MSVCRT=1</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">USE_NTDLL=1</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"> </FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">TARGETLIBS= \</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">   $(SDK_LIB_PATH)\Ws2_32.lib\</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">   $(TARGETPATH)\*\mtcr.lib</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">3. Some other problems, like mulitple includes error in .rc files, or problem with substituing more than one symbol constant into string in Makefiles (some version of WDK)</FONT></SPAN></P>
<BR>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Currently, we continue testing and will advertise these patches right after the testing will finish</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><B><FONT SIZE=2 FACE="Arial">Naslednikov Alexander (a.k.a XaleX)</FONT></B></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><B><FONT SIZE=2 FACE="Arial">Windows Team</FONT></B></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><B><FONT SIZE=2 FACE="Arial">Mellanox Technologies</FONT></B> </SPAN></P>
<BR>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">-----Original Message-----</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">From: ofw-bounces@lists.openfabrics.org [</FONT></SPAN><A HREF="mailto:ofw-bounces@lists.openfabrics.org"><SPAN LANG="en-us"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">mailto:ofw-bounces@lists.openfabrics.org</FONT></U></SPAN></A><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">] On Behalf Of Smith, Stan</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Sent: Tuesday, April 08, 2008 4:10 PM</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">To: Ishai Rabinovitz</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Cc: ofw@lists.openfabrics.org</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Subject: [ofw] WDK build environment migration thoughts</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Hello,</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">  I strongly believe it would help the WinOF community in transitioning to the WDK build environment if the connectX branch</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">(svn:gen1\branches\ConnectX) was used as a WDK build environment staging grounds prior to merging the WDK modifications into the mainline trunk.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">This has been talked about before although it still (as of last Friday) does not build using the latest WDK version.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"> </FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">One week prior to merging the WDK fixes into the mainline trunk, if you were to push all the WDK fixes into the ConnectX branch and then advertise on the ofw mailing list the availability of a WDK build branch along with</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">  1) how to build in the WDK environment,</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">     which version of the WDK is required + a URL link where to get the WDK.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">  2) An explanation of why and how the __ptr64 attributes were removed along with how</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">     others should correct their codes containing __ptr64 attributes.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">  3) updates to the WinOF wiki page describing how to build in the WDK env.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Let this branch exist for one week, receiving feedback from the list and then merge into the mainline trunk.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Using this approach is certainly community friendly and may prevent developer surprises.</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">ConnectX branch availability dates plus when the actual WDK fixes would be merged into the mainline trunk would be published beforehand.</FONT></SPAN></P>
<BR>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Thanks for your consideration,</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Stan.</FONT></SPAN></P>
<BR>
<BR>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">_______________________________________________</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">ofw mailing list</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">ofw@lists.openfabrics.org</FONT></SPAN></P>

<P DIR=LTR><SPAN LANG="en-us"></SPAN><A HREF="http://lists.openfabrics.org/cgi-bin/mailman/listinfo/ofw"><SPAN LANG="en-us"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://lists.openfabrics.org/cgi-bin/mailman/listinfo/ofw</FONT></U></SPAN></A><SPAN LANG="en-us"></SPAN></P>

</BODY>
</HTML>