Minheadless trial

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Minheadless trial

Ben Coman
 
wow time flies, its been 18 months since Ronie announced his
Minheadless VM branch...
[1] http://forum.world.st/Minheadless-VM-flavour-status-update-td4928091.html

I've been meaning this whole time to try it out.  Recently in my
meandering thoughts on FreeRTOS port, I guessed Minheadless might make
a good starting basis to experiment with.

So a quick test on Ubuntu16.04.3(Windows10-WSL)...

Long ago I'd already done...
   git clone [hidden email]:OpenSmalltalk/opensmalltalk-vm.git
so I now did...
  cd opensmalltalk-vm
  git remote add ronie [hidden email]:ronsaldo/opensmalltalk-vm.git
  git fetch ronie
  git checkout MinimalisticHeadless
  ./scripts/updateSCCSVersions
  cd build.minheadless.cmake/x64/pharo.stack.spur/
  ./mvm
  VM=`pwd`/release/dist/pharo
  ls $VM
==> confirmed it exists

  cd ~/pharo
  wget http://files.pharo.org/image/70/latest-minimal-64.zip
  unzip latest-minimal-64.zip
  sudo $VM Pharo7.0-metacello-64bit-65cff7b.image eval "19 + 23"
==> 42 yay


Particularly interesting from [1] is "using the same CMake scripts for
building on the three platforms: Windows, Linux and OS X."
So I thought I'd also give it a try under Windows10-VisualStudio2017.
I hardly used VS before, so I'll detail what I did as a reminder for
myself (and also in case someone might be able to help if I get
stuck).

Under a windows cmd.exe prompt (having installed git and cloned
opensmalltalk-vm a long time ago)
  cd opensmalltalk-vm
  git remote add ronie [hidden email]:ronsaldo/opensmalltalk-vm.git
  git fetch ronie
  git checkout -b MinimalisticHeadless ronie/MinimalisticHeadless

I watched video [2] about CMake integration with Visual Studio 10.
and checked the VS workloads configuration specified [2@1:13]
using [3].

There is a CMakeLists.txt file in the git root folder, so..
started VS > File > Open > Folder...
C:\Repos\OpenSmalltalk\opensmalltalk-vm

The CMake command run ([2]@2:13) was...
  C:\...\cmake.exe  -G "Ninja"
     -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\Ben\CMakeBuilds\...\x86-Debug"
     -DCMAKE_CXX_COMPILER="C:/.../MSVC/14.14.26428/bin/HostX86/x86/cl.exe"
     -DCMAKE_C_COMPILER="C:/.../MSVC/14.14.26428/bin/HostX86/x86/cl.exe"
     -DCMAKE_BUILD_TYPE="Debug"
     -DCMAKE_MAKE_PROGRAM="C:\...\CMAKE\Ninja\ninja.exe"
     "C:\Repos\OpenSmalltalk\opensmalltalk-vm"

I changed the cmake configuration [2@2:27] to "x64-Debug".
For debug target [2@3:00]  I chose "pharo.exe"

Hey, thats pretty cool [2@4:05] that switching between targets changes
the highlighting of #ifdef code.

I had a moment when I was missing the "Debug and Launch Settings" menu
item [2@4:40-4:55] and mentioned at [4], but maybe there was some
clash with previously experimenting with git cloning opensmalltalk-vm
from inside VS.
After closing VS and reopening my cmd.exe git'd opensmalltalk-vm it
showed up, but I didn't change any settings there.

Then (with x64-Debug & pharo.exe selected)
I went Cmake > Build All
==> 10 Errors, 9 Warnings, which I'll discuss in a followup post.

cheers -ben

[2] https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/
[3] https://docs.microsoft.com/en-us/visualstudio/install/modify-visual-studio
[4] https://blogs.msdn.microsoft.com/vcblog/2016/12/20/cmake-support-in-visual-studio-2017-whats-new-in-the-rc-update/
[5] https://developercommunity.visualstudio.com/content/problem/234808/cmake-debug-and-launch-settings-not-shown-while-bu.html
Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Ben Coman
 
On 6 August 2018 at 11:50, Ben Coman <[hidden email]> wrote:
> wow time flies, its been 18 months since Ronie announced his
> Minheadless VM branch...
> [1] http://forum.world.st/Minheadless-VM-flavour-status-update-td4928091.html

In Visual Studio...
> (with x64-Debug & pharo.exe selected)
> I went Cmake > Build All
> ==> 10 Errors, 9 Warnings, which I'll discuss in a followup post.
and btw, the build finishes too quick

Here are the errors...
------------------------
https://github.com/ronsaldo/opensmalltalk-vm/blob/be7b1c03/platforms/minheadless/windows/sqPlatformSpecific-Win32.c#L80
 typedef HRESULT WINAPI (*SetProcessDpiAwarenessFunctionPointer) (int
awareness);
    C2059 sqPlatformSpecific-Win32.c:80 syntax error: '('
    E0651 a calling convention may not be followed by a nested declarator.

The following change reduces build errors to 1...
  typedef HRESULT (*SetProcessDpiAwarenessFunctionPointer) (int awareness);

but I'm not sure of the implications.

Could be "the parenthesis around the function name" [2]
Or "there's already a C standard function [of that name]" [3]
The Microsoft definition returns a BOOL [4].

[2] https://software.intel.com/en-us/forums/intel-c-compiler/topic/385282
[3] https://social.msdn.microsoft.com/Forums/vstudio/en-US/2c57ada8-e1c9-4030-a058-6a7afd2fd29f/a-calling-convention-may-not-be-followed-by-a-nested-declarator?forum=vcgeneral
[4] https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setprocessdpiawarenesscontext


------------------------
https://github.com/ronsaldo/opensmalltalk-vm/blob/be7b1c03/platforms/minheadless/common/sqWindow-Dispatch.c#L68
  sqInt ioSetCursorARGB(sqInt cursorBitsIndex, sqInt extentX, sqInt
extentY, sqInt offsetX, sqInt offsetY)
    C2371 'ioSetCursorARGB': redefinition; different basic types

where sqInt is "long long".
but the function declaration is
https://github.com/ronsaldo/opensmalltalk-vm/blob/21cc02b6bf/platforms/minheadless/windows/sqPlatformSpecific-Win32.h#L117
  int ioSetCursorARGB(sqInt bitsIndex, sqInt w, sqInt h, sqInt x, sqInt y);

After modifying that function declaration to return 'sqInt',
"Cmake > Build all" runs much longer


------------------------
and ends up with 4 link errors (and 6600 warnings)
Pharo.exe LNK1120 - 1 unresolved external
Pharow.exe LNK1120 - 1unresolved external
sqMain.c.obj LNK2019 - unresolved external symbol _imp_osvm_main
referenced in function main
sqWin32Main.c.obj LNK2019 - unresolved external symbol _imp_osvm_main
referenced in function WinMain

I do see osvm_main is defined here...
https://github.com/ronsaldo/opensmalltalk-vm/blob/be7b1c03/platforms/minheadless/common/sqVirtualMachineInterface.c#L618

but I'm stuck, I don't understand why its looking for "_imp_osvm_main"

I'd be glad if anyone can advise on this, and the two errors above.

cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Ben Coman
 


On 6 August 2018 at 13:22, Ben Coman <[hidden email]> wrote:

> and ends up with 4 link errors (and 6600 warnings)
> Pharo.exe LNK1120 - 1 unresolved external
> Pharow.exe LNK1120 - 1unresolved external
> sqMain.c.obj LNK2019 - unresolved external symbol _imp_osvm_main referenced in function main
> sqWin32Main.c.obj LNK2019 - unresolved external symbol _imp_osvm_main referenced in function WinMain
>
> I do see osvm_main is defined here...
> https://github.com/ronsaldo/opensmalltalk-vm/blob/be7b1c03/platforms/minheadless/common/sqVirtualMachineInterface.c#L618
>
> but I'm stuck, I don't understand why its looking for "_imp_osvm_main"

only defines a single function... 
    #include "OpenSmalltalkVM.h"
    int
    main(int argc, const char **argv)
    {
        return osvm_main(argc, argv);
    }

To check that the osvm_main function is available to be linked, at the end of CmakeLists.txt I see...
  # Build the VM executable(s)
  add_executable(${VM_EXECUTABLE_NAME} platforms/minheadless/common/sqMain.c)
  target_link_libraries(${VM_EXECUTABLE_NAME} ${VM_LIBRARY_NAME} ${VM_DEPENDENCIES_LIBRARIES})

I found...
  VM_LIBRARY_NAME=PharoVMCore 
where that library is defined
  VM_CORE_LIBRARY_TYPE=STATIC 
  add_library(${VM_LIBRARY_NAME} ${VM_CORE_LIBRARY_TYPE} ${VM_SOURCES} ${VM_INTERNAL_PLUGIN_SOURCES})

and an inspection of PharoVMCore.lib (using 7zip to expand it) 
shows it contains function osvm_main symbol, but not the "_imp_" prefixed symbol.

Regarding the "_imp_" prefix, the next to last comment in this thread
gave a hint about the __declspec() needing to be dllexport instead of dllimport.

The declaration for osvm_main() in OpenSmalltalkVM.h is effectively...
   #       define OSVM_VM_EXPORT __declspec(dllexport)
   #       define OSVM_VM_IMPORT __declspec(dllimport)
   #ifdef BUILD_VM_CORE
   #   define OSVM_VM_CORE_PUBLIC OSVM_VM_EXPORT
   #else
   #   define OSVM_VM_CORE_PUBLIC OSVM_VM_IMPORT
   #endif
    OSVM_VM_CORE_PUBLIC OSVMError osvm_main(int argc, const char **argv);


So the following change to sqMain.c fixes the link error...
    #define BUILD_VM_CORE
    #include "OpenSmalltalkVM.h"
    int
    main(int argc, const char **argv)
    {
        return osvm_main(argc, argv);
    }

and similar for sqWin32Main.c.

 
Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Ben Coman
 


On 6 August 2018 at 23:54, Ben Coman <[hidden email]> wrote:

On 6 August 2018 at 13:22, Ben Coman <[hidden email]> wrote:
> and ends up with 4 link errors (and 6600 warnings)
> Pharo.exe LNK1120 - 1 unresolved external
> Pharow.exe LNK1120 - 1unresolved external
> sqMain.c.obj LNK2019 - unresolved external symbol _imp_osvm_main referenced in function main
> sqWin32Main.c.obj LNK2019 - unresolved external symbol _imp_osvm_main referenced in function WinMain


So the following change to sqMain.c fixes the link error...
    #define BUILD_VM_CORE
    #include "OpenSmalltalkVM.h"
    int
    main(int argc, const char **argv)
    {
        return osvm_main(argc, argv);
    }

and similar for sqWin32Main.c.


The next roadbump is...
LNK2019 unresolved external symbol 'alloca' referenced in function callIA32IntegralReturn  -- File PharoVMCore.lib(xabicc.c.obj)

From the root folder, doing...
   find . -name xabicc.c 
result in...
   ./platforms/Cross/plugins/IA32ABI/xabicc.c


Googling for "alloca Visual Studio 2017" lead me to...
which indicates there is no "alloca" only "_alloca"

Now " xabicc.c" is a stub for including platform specific C code,
and the lovely defines-highlighting of Visual Studio indicates "x64win64abicc.c" is the active one right now,
so as a quick hack, jamming a define just above that include... 

  #if i386|i486|i586|i686
  #  include "ia32abicc.c"
  #elif powerpc|ppc
  #  include "ppc32abicc.c"
  #elif x86_64|x64|__x86_64|__x86_64__|_M_AMD64|_M_X64
  # if _WIN64
  #     define alloca _alloca   // <<<QUICK HACK
  #     include "x64win64abicc.c"
  #  else
  #     include "x64sysvabicc.c"
  #  endif
  #elif __ARM_ARCH__|__arm__|__arm32__|ARM32
  #  include "arm32abicc.c"
  #endif


allows CMake > Build All
==> Build succeeded.   Yay!

To determine a suitable permanent home for that define, doing...
   grep -R " _alloca"  * 
from the root folder shows...
  platforms/Cross/plugins/IA32ABI/arm32abicc.c:# define alloca _alloca
  platforms/Cross/plugins/IA32ABI/ia32abicc.c:# define alloca _alloca
  platforms/Cross/plugins/IA32ABI/ppc32abicc.c:# define alloca _alloca
  platforms/Cross/plugins/SqueakFFIPrims/sqFFIPlugin.c:# define alloca _alloca
  platforms/minheadless/windows/sqPlatformSpecific-Win32.h:#    define alloca _alloca
  platforms/unix/config/configure:#  define alloca _alloca
  platforms/win32/vm/sqPlatformSpecific.h:#    define alloca _alloca
  processors/ARM/gdb-7.10/include/alloca-conf.h:#    define alloca _alloca
  processors/IA32/bochs/bx_debug/parser.c:#    define alloca _alloca
  src/plugins/SqueakFFIPrims/ARM32FFIPlugin.c:# define alloca _alloca
  src/plugins/SqueakFFIPrims/IA32FFIPlugin.c:# define alloca _alloca
  src/plugins/SqueakFFIPrims/X64SysVFFIPlugin.c:# define alloca _alloca
  src/plugins/SqueakFFIPrims/X64Win64FFIPlugin.c:# define alloca _alloca

Interesting that there is a similar define for ia32abicc.c,
so comparing that with x64win64abicc.c (at https://www.diffchecker.com/mqCWMaTV)
looks like it should be slotted into the latter about line 41.
Doing that ==> Build successful.

cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Eliot Miranda-2
 
Hi Ben,

On Mon, Aug 6, 2018 at 12:57 PM, Ben Coman <[hidden email]> wrote:
 


On 6 August 2018 at 23:54, Ben Coman <[hidden email]> wrote:

On 6 August 2018 at 13:22, Ben Coman <[hidden email]> wrote:
> and ends up with 4 link errors (and 6600 warnings)
> Pharo.exe LNK1120 - 1 unresolved external
> Pharow.exe LNK1120 - 1unresolved external
> sqMain.c.obj LNK2019 - unresolved external symbol _imp_osvm_main referenced in function main
> sqWin32Main.c.obj LNK2019 - unresolved external symbol _imp_osvm_main referenced in function WinMain


So the following change to sqMain.c fixes the link error...
    #define BUILD_VM_CORE
    #include "OpenSmalltalkVM.h"
    int
    main(int argc, const char **argv)
    {
        return osvm_main(argc, argv);
    }

and similar for sqWin32Main.c.


The next roadbump is...
LNK2019 unresolved external symbol 'alloca' referenced in function callIA32IntegralReturn  -- File PharoVMCore.lib(xabicc.c.obj)

From the root folder, doing...
   find . -name xabicc.c 
result in...
   ./platforms/Cross/plugins/IA32ABI/xabicc.c


Googling for "alloca Visual Studio 2017" lead me to...
which indicates there is no "alloca" only "_alloca"

Now " xabicc.c" is a stub for including platform specific C code,
and the lovely defines-highlighting of Visual Studio indicates "x64win64abicc.c" is the active one right now,
so as a quick hack, jamming a define just above that include... 

  #if i386|i486|i586|i686
  #  include "ia32abicc.c"
  #elif powerpc|ppc
  #  include "ppc32abicc.c"
  #elif x86_64|x64|__x86_64|__x86_64__|_M_AMD64|_M_X64
  # if _WIN64
  #     define alloca _alloca   // <<<QUICK HACK
  #     include "x64win64abicc.c"
  #  else
  #     include "x64sysvabicc.c"
  #  endif
  #elif __ARM_ARCH__|__arm__|__arm32__|ARM32
  #  include "arm32abicc.c"
  #endif


allows CMake > Build All
==> Build succeeded.   Yay!

To determine a suitable permanent home for that define, doing...
   grep -R " _alloca"  * 
from the root folder shows...
  platforms/Cross/plugins/IA32ABI/arm32abicc.c:# define alloca _alloca
  platforms/Cross/plugins/IA32ABI/ia32abicc.c:# define alloca _alloca
  platforms/Cross/plugins/IA32ABI/ppc32abicc.c:# define alloca _alloca
  platforms/Cross/plugins/SqueakFFIPrims/sqFFIPlugin.c:# define alloca _alloca
  platforms/minheadless/windows/sqPlatformSpecific-Win32.h:#    define alloca _alloca
  platforms/unix/config/configure:#  define alloca _alloca
  platforms/win32/vm/sqPlatformSpecific.h:#    define alloca _alloca
  processors/ARM/gdb-7.10/include/alloca-conf.h:#    define alloca _alloca
  processors/IA32/bochs/bx_debug/parser.c:#    define alloca _alloca
  src/plugins/SqueakFFIPrims/ARM32FFIPlugin.c:# define alloca _alloca
  src/plugins/SqueakFFIPrims/IA32FFIPlugin.c:# define alloca _alloca
  src/plugins/SqueakFFIPrims/X64SysVFFIPlugin.c:# define alloca _alloca
  src/plugins/SqueakFFIPrims/X64Win64FFIPlugin.c:# define alloca _alloca

Interesting that there is a similar define for ia32abicc.c,
so comparing that with x64win64abicc.c (at https://www.diffchecker.com/mqCWMaTV)
looks like it should be slotted into the latter about line 41.

Feel free to make this edit and commit
 
Doing that ==> Build successful.

cheers -ben




--
_,,,^..^,,,_
best, Eliot
Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Ben Coman
In reply to this post by Ben Coman
 
On 7 August 2018 at 05:12, Eliot Miranda <[hidden email]> wrote:
 
Hi Ben, 
Feel free to make this edit and commit

I'm pushing changes here...

and the diff can be tracked here...


------------------------
On 6 August 2018 at 13:22, Ben Coman <[hidden email]> wrote:
On 6 August 2018 at 11:50, Ben Coman <[hidden email]> wrote:

https://github.com/ronsaldo/opensmalltalk-vm/blob/be7b1c03/platforms/minheadless/windows/sqPlatformSpecific-Win32.c#L80
 typedef HRESULT WINAPI (*SetProcessDpiAwarenessFunctionPointer) (int awareness);
    C2059 sqPlatformSpecific-Win32.c:80 syntax error: '('
    E0651 a calling convention may not be followed by a nested declarator.

The following change reduces build errors to 1...
  typedef HRESULT (*SetProcessDpiAwarenessFunctionPointer) (int awareness);

but I'm not sure of the implications.

I found the correct solution to this...
"The trick is placing the [call declaration] inside the parentheses"

i.e. the following compiles cleanly
typedef HRESULT (WINAPI *SetProcessDpiAwarenessFunctionPointer) (int awareness);


-----------------------------
Now running the VM (without parameters) I get...
   Debug Assertion Failed!
   Program: ...\x64-Debug\dist\pharo.exe
   File: minkernel\crts\ucrt\src\appcrt\tran\amd64\ieee.c 
   Line: 106
   Expression: (mask&~(_MCW_DN | _MCW_EM | _MCW_RC))==0

at the call to _controlfp(FPU_DEFAULT, _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC);


x64 does not support _MCW_PC or _MCW_IC
but I'm clueless about the implications of these FPU flags.
Could our math guys please advise?

Eliminating those two flags allows a VM run successfully without loading an Image.
i.e. it successfully passes...
   osvm_initialize();
   osvm_parseCommandLineArguments(argc, argv);
   osvm_initializeVM();

Next is to try loading an Image.

cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Ben Coman
 
On 7 August 2018 at 13:22, Ben Coman <[hidden email]> wrote:

Next is to try loading an Image.

+ In Visual Studio, right-clicked CMakeLists.txt > Debug and Launch Settings > pharo.exe
+ Edited the presented "launch.vs.json" as follows...
{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "pharo.exe (dist\\pharo.exe)",
      "name": "pharo.exe with image (dist\\pharo.exe)",
      "args": [
        "C:\\#Dev\\latest-minimal-64\\Pharo7.0-metacello-64bit-65cff7b.image",
        "s"
      ]
    },
  ]
}

Now running "x64-Debug" and "pharo.exe with image"
I find it gets hung up in...
    sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize)
in call...
   alloc = sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto (roundUpToPage(desiredHeapSize), address, &allocBytes);
with...
    desiredHeapSize ==> 39583744 (~39MB)
    address ==> 0x00007ff7d6e00000

where inside that call... 
  void *sqAllocateMemorySegmentOfSizeAboveAllocatedSizeInto(sqInt size, void *minAddress, sqInt *allocatedSizePointer)"
has... 
    size ==> 39583744
    minAddress ==> 0x00007ff7d6e00000
    address ==> 0x00000000d6e00000
    bytes ==> 39583744 (~39MB)
    delta ==> 1048576


    while ((usqIntptr_t)(address + bytes) > (usqIntptr_t)address)
    {    alloc = VirtualAlloc(address, bytes, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
         ...
         if (alloc >= (char *)minAddress) && (alloc <= address + delta))  return alloc;
         ...
         address += delta;
    }

where... 
    alloc ==> 0x00000000d6e00000
    (alloc >= (char *)minAddress) ==> false.

which is effectively...  (does this seem normal?)
      ((char *)minAddress-address)/delta ==> 134,180,864 loops before exit.

but... 
    (alloc >= (char *)address) ==> true.
would exit on the first pass of the loop, except... 
    /* For some reason (large page support?) we can ask for a page-aligned
     * address such as 0xNNNNf000 but VirtualAlloc will answer 0xNNNN0000.
     * So accept allocs above minAddress rather than allocs above address
     */

where back one level "minAddress" is derived like this...
    /* choose a suitable starting point. In MinGW the malloc heap is below the
     * program, so take the max of a malloc and something form uninitialized
     * data.
     */
hint = malloc(1);
free(hint);
hint = max(hint,(char *)&fIsConsole);
        address = (char *)(((usqInt)hint + alignment - 1) & ~(alignment - 1));
        address passed-by-value into minAddress 


Now I'm out of my depth trying to understand the background on that logic,
but if I blindly change the loop exit condition 
from...
     (alloc >= (char *)minAddress)
to...
     (alloc >= (char *)address)

then  osvm_loadImage(tempImageNameAttempt()
and subsequently  osvm_loadDefaultImage()  succeed.  

So some expert attention would be good here (as time permits) 
In the meantime, I'll forge ahead to play with  osvm_run();

cheers -ben


P.S. making "#define printProbes 1"  and "fIsConsole = 1;"
shows...
probing [00000000D6E00000,00000000D93C0000)
probing [00000000D6F00000,00000000D94C0000)
probing [00000000D7000000,00000000D95C0000)
probing [00000000D7100000,00000000D96C0000)
probing [00000000D7200000,00000000D97C0000)
probing [00000000D7300000,00000000D98C0000)
probing [00000000D7400000,00000000D99C0000)
probing [00000000D7500000,00000000D9AC0000)
probing [00000000D7600000,00000000D9BC0000)

Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] Minheadless trial

Ben Coman
In reply to this post by Ben Coman
 


On 7 August 2018 at 13:47, Esteban Lorenzano <[hidden email]> wrote:
Hi Ben,

Sorry for coming here so late, I didn’t see this thread before. 
I already have a working minheadless branch that was adapted to Eliot’s process. 
It was working for Pharo in Linux and Mac (Windows was ongoing but not finished, that’s why is not pushed).

You can find this branch here: 


I'll have a look at it.
 
Interesting part is that I didn’t tackled any of the issues you are working on, so the work is easily mergeable :) 

Cheers, 
Esteban

Ps: with some changes in image, I’m using exclusively this VM since a couple of months and it works fine.

That is good to know.  So just to be clear... 
even though its name indicates "headless", you are running a full graphical Image?

I got more curious about the original announcement saying... 
"minheadless is a VM variant that unifies a lot of the code for Windows, Linux and OS X."

I compare...
   find "platforms/Win32/vm" -exec wc {} \;
   find "platforms/Unix/vm" -exec wc {} \;
   find "platforms/Mac OS/vm" -exec wc {} \;
to...
   find "platforms/minheadless" -exec wc {} \; 

and if nothing important has been missed it seems about 30% of the original size. 
I'd expect Ronie's effort to produce this should have a massive impact on future maintainability.  

cheers -ben

P.S. I excluded the following presuming its common before/after.
   find "platforms/Cross/vm" -exec wc {} \;
btw, its about half the size of platforms/minheadless.
Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Ben Coman
In reply to this post by Ben Coman
 

On 7 August 2018 at 19:47, Ben Coman <[hidden email]> wrote:
>

whoops, that was meant to be the minheadless file....


In the meantime, I'll forge ahead to play with  osvm_run();

I've hardly used Visual Studio before, and never combined with CMake,
so I'll record a few things I discover in case others might find it interesting or advise a better way.


To try with the Stack Interpreter first, in CMakeLists.txt changed...
    option(COG_JIT "Cog JIT" ON)
to...
    option(COG_JIT "Cog JIT" OFF)
then cleared the cache... Right-clicked on "CMakeLists.txt > Cache(x64-Debug only) > Delete cache folder..."
otherwise it didn't seem to pick up that change.


To give the VM an image to run and something to do... 
Right-clicked on "CMakeLists.txt > Debug and Launch Settings > pharo.exe"
then edited the presented "launch.vs.json" as follows...
{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "pharo.exe (dist\\pharo.exe)",
      "name": "pharo.exe minImage+eval (dist\\pharo.exe)",
      "args": [
        "C:\\#Dev\\latest-minimal-64\\Pharo7.0-metacello-64bit-65cff7b.image eval 19 + 23",
      ]
    },
  ]
}

Then... "CMake > Build All"  
followed by starting... "x64-Debug" with "pharo.exe minImage+eval"
which opened a console window that doesn't do much besides output like this...
GIV(remapBufferCount) == 0 47923

Now I notice the file "dist\stderr" says...
    "Your VM is too old for this image. Please download the latest VM."
so probably I need to run "scripts\updateSCCSVersions"
but thats a shell script.  How to run it under Windows?

Luckily my installed Git Windows has Git Bash which opens a cygwin environment.
where I do...
   cd /c/#Repos/OpenSmalltalk/opensmalltalk-vm/
   ./scripts/ updateSCCSVersions


Now to give a bit more visibility to program execution, 
in "spurstack64src/interp.c" I inserted the following into main interpreter loop...

"+" unsigned long long debugCountBytecode = 0;
while (1) {
"+" debugCountBytecode += 1;
"+" if ((debugCountBytecode % 100000 == 0))
"+" {
"+" printf("%llu\n", debugCountBytecode);
"+" }


Then... "CMake > Build All"  
followed by starting... "x64-Debug" with "pharo.exe minImage+eval"
which opened a console window with the following output...
GIV(remapBufferCount) == 0 47923
GIV(remapBufferCount) == 0 42469
100000
200000
300000
400000
500000
600000
700000
800000
900000
1000000
1100000
1200000
1300000
1400000
1500000

and updated contents of these files... yay!
    dist\stderr ==> #'EvaluateCommandLineHandler successfully finished'
    dist\stdout ==> 42


However the VM/Image keeps running.   Adding "--quit" to the command line didn't help.
I'm not really familiar with the command line handlers. 
Doing... "Debug > Break All"
bring me up some warnings like... 
  "winmm.pdb not loaded"
  "winmm.pdb contains the debug information required to find the source for the module winmm.dll"

Never heard of a PDB, but loaded them by following these instructions...
   "Specify Symbol (.pdb) and Source Files in the Visual Studio Debugger"
and learnt a lot more about them...
  "PDB Files: What Every Developer Must Know"
Now the next few times I started...  "x64-Debug" with "pharo.exe minImage+eval"
it got hung up downloading the symbols.  I had to terminate & restart debugging it a few times
as it progressed a bit each time. 

When finally got running again and after 1500000 printed I did...  "Debug > Break All" 
and... "Debug > Windows > Threads" and now it shows the proper names rather than just addresses...


A little surprised by the number of threads.
No clue what ntdll.dll!NtWaitForWorkViaWorkerFactory 
or winmm.dll!timeThread are, but leave that for later.

Now with all thread stopped, trying... "Debug > Windows > Parallel Stacks"... 


shows the two application threads are "in external code" 
invoked from  ioRelinquishProcessorForMicroseconds()  and  beatThreadStateMachine(). 
Clicking on each of those displays their source code indicating the "external code"
for each is  MsgWaitForMultipleObjects()  and  WaitForSingleObject()  respectively  .

Its very easy to flip back and forth between the two application threads,
stepping-out of the "external code" with Shift-F11, to observe a tiny window of VM operation. 

Well thats enough for one post!  
Success running a MSVC compiled Spur Stack "minheadless" VM.

Next I'll try...    option(COG_JIT "Cog JIT" ON)

cheers -ben


P.S.  Definitions for the curious...

sqInt
ioRelinquishProcessorForMicroseconds(sqInt microSeconds)
{
    /* wake us up if something happens */
    ResetEvent(vmWakeUpEvent);
    MsgWaitForMultipleObjects(1, &vmWakeUpEvent, FALSE, microSeconds / 1000, QS_ALLINPUT);
    ioProcessEvents(); /* keep up with mouse moves etc. */
    return microSeconds;
}


static DWORD WINAPI
beatThreadStateMachine(void *careLess)
{
beatThreadState = active;
while (beatThreadState != condemned) {
DWORD res = WaitForSingleObject(beatSemaphore, beatThreadState == active ? beatMilliseconds : INFINITE);
if (res == WAIT_TIMEOUT)
heartbeat();
else if (res == WAIT_FAILED)
abortMessage(TEXT("Fatal: WaitForSingleObject(beatSemaphore) %ld"), GetLastError());
else
printLastError(TEXT("beatThreadStateMachine WaitForSingleObject"));
}
beatThreadState = dead;
return 0;
}


Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Ben Coman
 
Hi Ronie, Esteban,

Could you do a quick review of my CMakeLists.txt change for any obvious blunder.
This may be my last post on this thread for a short while.


On 8 August 2018 at 21:39, Ben Coman <[hidden email]> wrote:

Well thats enough for one post!  
Success running a MSVC compiled Spur Stack "minheadless" VM.

Next I'll try...    option(COG_JIT "Cog JIT" ON)

I did that, and then...
  "CMakeLists.txt > Cache(x64-Debug only) > Delete cache folder..."
  "CMake > Build All"
then started "x64-Debug" , "pharo.exe minImage+eval"
and a console window opens that reports...
    "linking callsite to invalid address"

Well I'm not sure how ready is the Windows 64bit JIT is, 
so lets try with 32bit JIT.
In VS selecting "x86-Debug" , "pharo.exe minImage+eval" 
and "Cmake > Build All"
reports... "Severity Code Description Project File Line Suppression State
Error C1189 #error:  As yet no Cogit implementation appears to exist for your platform.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CMakeLists.txt C:\#Repos\OpenSmalltalk\opensmalltalk-vm\spur64src\vm\cogit.c

In the CMake variables
    SourceFolderName=spur64src
because..
     VM_64BITS=TRUE
which is set here...
    if(SQUEAK_PLATFORM_X86_64)
if(BUILD_I386_VERSION)
        set(SQUEAK_PLATFORM_X86_32 True)
    set(SQUEAK_PLATFORM_X86_64 False)
else()
set(VM_64BITS TRUE)
set(SourceFolderName "${SourceFolderName}64")
if(WIN32)
set(FFI_VARIANT_X64_WIN64 True)
else()
set(FFI_VARIANT_X64_SYSV True)
endif()
        set(VM_TARGET_CPU "x86_64")
endif()
    else()
set(VM_64BITS False)
    endif()

which I'm not clear how that logic works,  
since it seems  BUILD_I386_VERSION  doesn't prevent  VM_64BITS=True

Rearranging like...

    if(BUILD_I386_VERSION)
        set(SQUEAK_PLATFORM_X86_32 True)
        set(SQUEAK_PLATFORM_X86_64 False)
        set(VM_64BITS False)
    else()
    endif()
    if(SQUEAK_PLATFORM_X86_64)
        set(VM_64BITS TRUE)
        set(SourceFolderName "${SourceFolderName}64")
        if(WIN32)
              set(FFI_VARIANT_X64_WIN64 True)
        else()
              set(FFI_VARIANT_X64_SYSV True)
        endif()
        set(VM_TARGET_CPU "x86_64")
    else()
    endif()

then adding  -DBUILD_I386_VERSION in "CmakeSettings.json" like this... 
  "CMakeLists.txt > Change Cmake Settings"
        {
            "name": "x86-Debug",
            "generator": "Ninja",
            "configurationType": "Debug",
            "inheritEnvironments": [ "msvc_x86" ],
            "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
            "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
            "cmakeCommandArgs": "-DBUILD_I386_VERSION=ON",
            "buildCommandArgs": "-v",
            "ctestCommandArgs": ""
        },
 
then refreshing...
  "CMakeLists.txt > Cache(x64-Debug only) > Delete cache folder..."
  "CMake > Build All"

leaves these values in the Cmake variables...
    VM_64BITS=False
    SourceFolderName=spursrc

and the build completes successfully.

I'm leaving it there for the moment.  
Actually the above sat in unchanged in draft for a week since I've had to shift my attention to something else.

Next would be to catch up to Esteban's branch... https://github.com/estebanlm/opensmalltalk-vm/tree/add-minheadless-vm

cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Nicolas Cellier
 
Hi Ben,
I did not follow all the thread in detail, but a lot of missing definitions like alloca  were in platform specific support headers:


The fact that minheadless seems a (better ?) re-organisation of sources (I guess with a better separation of concerns) does not mean that we have to re-invent everything.
It's just there under our hands.

Le mar. 14 août 2018 à 07:46, Ben Coman <[hidden email]> a écrit :
 
Hi Ronie, Esteban,

Could you do a quick review of my CMakeLists.txt change for any obvious blunder.
This may be my last post on this thread for a short while.


On 8 August 2018 at 21:39, Ben Coman <[hidden email]> wrote:

Well thats enough for one post!  
Success running a MSVC compiled Spur Stack "minheadless" VM.

Next I'll try...    option(COG_JIT "Cog JIT" ON)

I did that, and then...
  "CMakeLists.txt > Cache(x64-Debug only) > Delete cache folder..."
  "CMake > Build All"
then started "x64-Debug" , "pharo.exe minImage+eval"
and a console window opens that reports...
    "linking callsite to invalid address"

Well I'm not sure how ready is the Windows 64bit JIT is, 
so lets try with 32bit JIT.
In VS selecting "x86-Debug" , "pharo.exe minImage+eval" 
and "Cmake > Build All"
reports... "Severity Code Description Project File Line Suppression State
Error C1189 #error:  As yet no Cogit implementation appears to exist for your platform.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CMakeLists.txt C:\#Repos\OpenSmalltalk\opensmalltalk-vm\spur64src\vm\cogit.c

In the CMake variables
    SourceFolderName=spur64src
because..
     VM_64BITS=TRUE
which is set here...
    if(SQUEAK_PLATFORM_X86_64)
if(BUILD_I386_VERSION)
        set(SQUEAK_PLATFORM_X86_32 True)
    set(SQUEAK_PLATFORM_X86_64 False)
else()
set(VM_64BITS TRUE)
set(SourceFolderName "${SourceFolderName}64")
if(WIN32)
set(FFI_VARIANT_X64_WIN64 True)
else()
set(FFI_VARIANT_X64_SYSV True)
endif()
        set(VM_TARGET_CPU "x86_64")
endif()
    else()
set(VM_64BITS False)
    endif()

which I'm not clear how that logic works,  
since it seems  BUILD_I386_VERSION  doesn't prevent  VM_64BITS=True

Rearranging like...

    if(BUILD_I386_VERSION)
        set(SQUEAK_PLATFORM_X86_32 True)
        set(SQUEAK_PLATFORM_X86_64 False)
        set(VM_64BITS False)
    else()
    endif()
    if(SQUEAK_PLATFORM_X86_64)
        set(VM_64BITS TRUE)
        set(SourceFolderName "${SourceFolderName}64")
        if(WIN32)
              set(FFI_VARIANT_X64_WIN64 True)
        else()
              set(FFI_VARIANT_X64_SYSV True)
        endif()
        set(VM_TARGET_CPU "x86_64")
    else()
    endif()

then adding  -DBUILD_I386_VERSION in "CmakeSettings.json" like this... 
  "CMakeLists.txt > Change Cmake Settings"
        {
            "name": "x86-Debug",
            "generator": "Ninja",
            "configurationType": "Debug",
            "inheritEnvironments": [ "msvc_x86" ],
            "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
            "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
            "cmakeCommandArgs": "-DBUILD_I386_VERSION=ON",
            "buildCommandArgs": "-v",
            "ctestCommandArgs": ""
        },
 
then refreshing...
  "CMakeLists.txt > Cache(x64-Debug only) > Delete cache folder..."
  "CMake > Build All"

leaves these values in the Cmake variables...
    VM_64BITS=False
    SourceFolderName=spursrc

and the build completes successfully.

I'm leaving it there for the moment.  
Actually the above sat in unchanged in draft for a week since I've had to shift my attention to something else.

Next would be to catch up to Esteban's branch... https://github.com/estebanlm/opensmalltalk-vm/tree/add-minheadless-vm

cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: Minheadless trial

Ben Coman
 


On Wed, 5 Dec 2018 at 18:45, Nicolas Cellier <[hidden email]> wrote:
 
Hi Ben,
I did not follow all the thread in detail, but a lot of missing definitions like alloca  were in platform specific support headers:


The fact that minheadless seems a (better ?) re-organisation of sources (I guess with a better separation of concerns) does not mean that we have to re-invent everything.
It's just there under our hands.

I don't think much is being reinvented. Its just minheadless branched before much work on 64-bit Windows.  
sqPlatformSpecific.h is very much reused,  as borne out by this diff...

.../platforms/win32/vm/sqPlatformSpecific.h                     .../platforms/minheadless/windows/sqPlatformSpecific-Win32.h
/* win32 sqPlatformSpecific.h -- Platform-specific prototypes   /* win32 sqPlatformSpecific.h -- Platform-specific prototypes
/* How to use this file:                                        /* How to use this file:
   This file is for general platform-specific macros and decl      This file is for general platform-specific macros and decl
   The goal is to keep most of the other header files generic      The goal is to keep most of the other header files generic
   To override a definition or macro from sq.h, you must firs      To override a definition or macro from sq.h, you must firs
   provide the new definition.                                     provide the new definition.
*/                                                              */
#if _WIN32 || _WIN64                                          | #ifdef WIN32
/* Override necessary definitions */                            /* Override necessary definitions */
#undef putchar                                                  #undef putchar
#include "sqWin32Alloc.h"                                       #include "sqWin32Alloc.h"

#ifdef _MSC_VER                                                 #ifdef _MSC_VER
#include <windows.h>                                            #include <windows.h>
#define HAVE_BOOLEAN 1 /* for jpegReaderWriter plugin compati   #define HAVE_BOOLEAN 1 /* for jpegReaderWriter plugin compati
#endif                                                          #endif

#ifdef _MSC_VER                                                 #ifdef _MSC_VER
#define squeakFileOffsetType __int64                            #define squeakFileOffsetType __int64
#else                                                           #else
#define squeakFileOffsetType unsigned long long                 #define squeakFileOffsetType unsigned long long
#endif                                                          #endif

#ifdef WIN32_FILE_SUPPORT                                       #ifdef WIN32_FILE_SUPPORT

#undef sqImageFile                                              #undef sqImageFile
#undef sqImageFileClose                                         #undef sqImageFileClose
#undef sqImageFileOpen                                          #undef sqImageFileOpen
#undef sqImageFilePosition                                      #undef sqImageFilePosition
#undef sqImageFileRead                                          #undef sqImageFileRead
#undef sqImageFileSeek                                          #undef sqImageFileSeek
#undef sqImageFileSeekEnd                                       #undef sqImageFileSeekEnd
#undef sqImageFileWrite                                         #undef sqImageFileWrite

#define sqImageFile usqIntptr_t                                 #define sqImageFile usqIntptr_t
sqInt sqImageFileClose(sqImageFile h);                          sqInt sqImageFileClose(sqImageFile h);
sqImageFile sqImageFileOpen(const char *fileName, const char    sqImageFile sqImageFileOpen(const char *fileName, const char 
squeakFileOffsetType sqImageFilePosition(sqImageFile h);        squeakFileOffsetType sqImageFilePosition(sqImageFile h);
size_t sqImageFileRead(void *ptr, size_t sz, size_t count, sq   size_t sqImageFileRead(void *ptr, size_t sz, size_t count, sq
squeakFileOffsetType sqImageFileSeek(sqImageFile h, squeakFil   squeakFileOffsetType sqImageFileSeek(sqImageFile h, squeakFil
squeakFileOffsetType sqImageFileSeekEnd(sqImageFile h, squeak   squeakFileOffsetType sqImageFileSeekEnd(sqImageFile h, squeak
size_t sqImageFileWrite(const void *ptr, size_t sz, size_t co   size_t sqImageFileWrite(const void *ptr, size_t sz, size_t co
#else /* when no WIN32_FILE_SUPPORT, add necessary stub for u   #else /* when no WIN32_FILE_SUPPORT, add necessary stub for u
#include <stdlib.h>                                             #include <stdlib.h>
#include <io.h> /* _get_osfhandle */                            #include <io.h> /* _get_osfhandle */
                                                              > #ifndef PATH_MAX
#define PATH_MAX _MAX_PATH                                      #define PATH_MAX _MAX_PATH
                                                              > #endif

#define fsync(filenumber) FlushFileBuffers((HANDLE)_get_osfha   #define fsync(filenumber) FlushFileBuffers((HANDLE)_get_osfha
#endif /* WIN32_FILE_SUPPORT */                                 #endif /* WIN32_FILE_SUPPORT */

/* pluggable primitive support */                               /* pluggable primitive support */
#if defined(_MSC_VER) || defined(__MINGW32__)                   #if defined(_MSC_VER) || defined(__MINGW32__)
#  undef EXPORT                                                 #  undef EXPORT
#  define EXPORT(returnType) __declspec( dllexport ) returnTy   #  define EXPORT(returnType) __declspec( dllexport ) returnTy
#  undef VM_EXPORT                                              #  undef VM_EXPORT
#  define VM_EXPORT __declspec( dllexport )                     #  define VM_EXPORT __declspec( dllexport )
                                                              > #  if defined(BUILD_VM_CORE) && !defined(VM_CORE_STATIC)
                                                              > #    undef VM_FUNCTION_EXPORT
                                                              > #    define VM_FUNCTION_EXPORT(returnType) __declspec( dllexport ) returnType
                                                              > #  else
                                                              > #    undef VM_FUNCTION_EXPORT
                                                              > #    define VM_FUNCTION_EXPORT(returnType) __declspec( dllimport ) returnType
                                                              > #  endif
#endif                                                          #endif


/* missing functions */                                         /* missing functions */
#ifdef _MSC_VER                                                 #ifdef _MSC_VER
/* see on msdn the list of functions available                  /* see on msdn the list of functions available
 *  CRT Alphabetical Function Reference                          *  CRT Alphabetical Function Reference
#  include <malloc.h>                                           #  include <malloc.h>
#  include <float.h>                                            #  include <float.h>
#  ifndef alloca                                                #  ifndef alloca
#    define alloca _alloca                                      #    define alloca _alloca
#  endif                                                        #  endif
#  if _MSC_VER < 1800 /* not available before MSVC 2013 */      #  if _MSC_VER < 1800 /* not available before MSVC 2013 */
#    define atoll(x)              _atoi64(x)                    #    define atoll(x)              _atoi64(x)
#    define strtoll(beg,end,base) _strtoi64(beg,end,base)       #    define strtoll(beg,end,base) _strtoi64(beg,end,base)
     double round(double);                                           double round(double);
#  endif                                                        #  endif
#  if _MSC_VER < 1900 /* not available before MSVC 2015 */      #  if _MSC_VER < 1900 /* not available before MSVC 2015 */
#    define snprintf _snprintf                                  #    define snprintf _snprintf
#    ifndef isnan                                               #    ifndef isnan
#      define isnan _isnan                                      #      define isnan _isnan
#    endif                                                      #    endif
#  endif                                                        #  endif
#  if _MSC_VER < 1300 /* maybe not available before MSVC 7.0    #  if _MSC_VER < 1300 /* maybe not available before MSVC 7.0 
#    define fabsf(x)    ((float)fabs((double)(x)))              #    define fabsf(x)    ((float)fabs((double)(x)))
#  endif                                                        #  endif
#  define bzero(pointer,size) ZeroMemory(pointer,size)          #  define bzero(pointer,size) ZeroMemory(pointer,size)
                                                              > #else
                                                              > #  include <string.h>
                                                              > #  define bzero(pointer,size) memset(pointer, 0, size)
#endif                                                          #endif

#ifdef __GNUC__                                                 #ifdef __GNUC__
#  if __GNUC__ < 3                                              #  if __GNUC__ < 3
#    define fabsf(x)    ((float)fabs((double)(x))) /* not sur   #    define fabsf(x)    ((float)fabs((double)(x))) /* not sur
#  endif                                                        #  endif
#endif                                                          #endif

#else                                                           #else
error "Not Win32 or Win64!"                                   | error "Not Win32!"
#endif /* _WIN32 || _WIN64 */                                 | #endif /* WIN32 */

int ioSetCursorARGB(sqInt bitsIndex, sqInt w, sqInt h, sqInt    int ioSetCursorARGB(sqInt bitsIndex, sqInt w, sqInt h, sqInt 

/* poll and profile thread priorities.  The stack vm uses a t   /* poll and profile thread priorities.  The stack vm uses a t
 * VM to poll for I/O, check for delay expiry et al at regula    * VM to poll for I/O, check for delay expiry et al at regula
 * VMs use a thread to sample the pc for VM profiling.  The p    * VMs use a thread to sample the pc for VM profiling.  The p
 * to have a priority higher than the main VM thread and the     * to have a priority higher than the main VM thread and the 
 * to have a priority higher than the poll thread to be able     * to have a priority higher than the poll thread to be able 
 * We would like POLL_THREAD_PRIORITY to be THREAD_PRIORITY_T    * We would like POLL_THREAD_PRIORITY to be THREAD_PRIORITY_T
 * but SetThreadPriority fails with this value on Windows XP.    * but SetThreadPriority fails with this value on Windows XP.
 *                                                               *
 * N.B. THREAD_PRIORITY_TIME_CRITICAL a.k.a. THREAD_BASE_PRIO    * N.B. THREAD_PRIORITY_TIME_CRITICAL a.k.a. THREAD_BASE_PRIO
 *      THREAD_PRIORITY_MAX a.k.a. THREAD_BASE_PRIORITY_MAX      *      THREAD_PRIORITY_MAX a.k.a. THREAD_BASE_PRIORITY_MAX
 * See WinBase.h & WinNT.h.                                      * See WinBase.h & WinNT.h.
 */                                                              */
#if STACKVM                                                     #if STACKVM
# define POLL_THREAD_PRIORITY THREAD_PRIORITY_HIGHEST           # define POLL_THREAD_PRIORITY THREAD_PRIORITY_HIGHEST
#endif /* STACKVM */                                            #endif /* STACKVM */
#define PROF_THREAD_PRIORITY THREAD_PRIORITY_TIME_CRITICAL      #define PROF_THREAD_PRIORITY THREAD_PRIORITY_TIME_CRITICAL

#if COGVM                                                       #if COGVM
extern void sqMakeMemoryExecutableFromTo(usqIntptr_t, usqIntp   extern void sqMakeMemoryExecutableFromTo(usqIntptr_t, usqIntp
extern void sqMakeMemoryNotExecutableFromTo(usqIntptr_t, usqI   extern void sqMakeMemoryNotExecutableFromTo(usqIntptr_t, usqI

extern int isCFramePointerInUse(void);                          extern int isCFramePointerInUse(void);
extern int osCogStackPageHeadroom(void);                        extern int osCogStackPageHeadroom(void);
extern void reportMinimumUnusedHeadroom(void);                  extern void reportMinimumUnusedHeadroom(void);
#endif                                                          #endif

/* Thread support for thread-safe signalSemaphoreWithIndex an   /* Thread support for thread-safe signalSemaphoreWithIndex an
#if STACKVM || NewspeakVM                                       #if STACKVM || NewspeakVM
# define sqLowLevelYield() Sleep(0)                             # define sqLowLevelYield() Sleep(0)
/* these are used both in the STACKVM & the COGMTVM */          /* these are used both in the STACKVM & the COGMTVM */
# define sqOSThread void *                                      # define sqOSThread void *
# define ioOSThreadsEqual(a,b) ((a) == (b))                     # define ioOSThreadsEqual(a,b) ((a) == (b))
# if COGMTVM                                                    # if COGMTVM
/* Please read the comment for CogThreadManager in the VMMake   /* Please read the comment for CogThreadManager in the VMMake
 * documentation of this API.                                    * documentation of this API.
 */                                                              */
#  define sqOSSemaphore void *                                  #  define sqOSSemaphore void *
#  if !ForCOGMTVMImplementation /* this is a read-only export   #  if !ForCOGMTVMImplementation /* this is a read-only export
extern const unsigned long tltiIndex;                           extern const unsigned long tltiIndex;
#  endif                                                        #  endif
#  define ioGetThreadLocalThreadIndex() ((long)TlsGetValue(tl   #  define ioGetThreadLocalThreadIndex() ((long)TlsGetValue(tl
#  define ioSetThreadLocalThreadIndex(v) (TlsSetValue(tltiInd   #  define ioSetThreadLocalThreadIndex(v) (TlsSetValue(tltiInd
#  define ioTransferTimeslice() Sleep(0)                        #  define ioTransferTimeslice() Sleep(0)
#  define ioMilliSleep(ms) Sleep(ms)                            #  define ioMilliSleep(ms) Sleep(ms)
# endif /* COGMTVM */                                           # endif /* COGMTVM */
#endif /* STACKVM || NewspeakVM */                              #endif /* STACKVM || NewspeakVM */

#if defined(__GNUC__)                                           #if defined(__GNUC__)
# if !defined(VM_LABEL)                                         # if !defined(VM_LABEL)
#       define VM_LABEL(foo) asm("\n.globl L" #foo "\nL" #foo   #       define VM_LABEL(foo) asm("\n.globl L" #foo "\nL" #foo
# endif                                                         # endif
#endif                                                          #endif
#if !defined(VM_LABEL) || COGVM                                 #if !defined(VM_LABEL) || COGVM
# undef VM_LABEL                                                # undef VM_LABEL
# define VM_LABEL(foo) ((void)0)                              | # define VM_LABEL(foo) 0
#endif                                                          #endif

/* Define the fields in a struct _CONTEXT as returned by GetThreadContext that
 * represent the program counter and frame pointer on the current architecture.
 */
#if defined(_M_IX86) || defined(_M_I386) || defined(_X86_) || defined(i386) || defined(__i386__)
# define CONTEXT_PC Eip
# define CONTEXT_FP Ebp
# define CONTEXT_SP Esp
#elif defined(x86_64) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__amd64__) || defined(x64) || defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64)
# define CONTEXT_PC Rip
# define CONTEXT_FP Rbp
# define CONTEXT_SP Rsp
#else
# error "unknown architecture, program counter field undefined"
#endif
                                                              > #ifdef _MSC_VER
                                                              > /* disable "function XXXX: no return value" */
                                                              > #pragma warning(disable:4035)
                                                              > /* optional C SEH macros */
                                                              > #define TRY __try
                                                              > #define EXCEPT(filter) __except(filter)
                                                              > #define FINALLY __finally
                                                              > #else
                                                              > /* optional C SEH macros */
                                                              > #define TRY
                                                              > #define EXCEPT(filter) if (0)
                                                              > #define FINALLY
                                                              > #endif


But perhaps instead of my change to "platforms/Cross/plugins/IA32ABI/x64win64abicc.c" here... 
it would have been better to include "sqPlatformSpecific.h" ?  Or would that be heavy handed? I don't know.
At the time it seemed reasonable to echo the similar define here...
   platforms/Cross/plugins/IA32ABI/ia32abicc.c:   # define alloca _alloca

cheers -ben

P.S. It might be good to reconcile the two files, but I don't know enough about all the changes myself.
And to avoid divergence maybe(??) one file should #include the other instead of being a copy. 
Or would that be a bad??