Thank you, Björn, I'll give that a try.

In the meantime, has anyone tried debugging the VM under Visual Studio 2015? 
The build tool is command-line, and I see no VS solution file.

28.05.2016, 14:14, "Björn Lindqvist" <bjou...@gmail.com>:
> Hello,
>
> Here is some sample code to run:
>
> USING: alien io kernel threads.private windows.kernel32
> windows.types ;
> IN: examples.windows.threads
>
> : eternity ( -- ) eternity ;
>
> : <ThreadProc> ( -- alien )
>     DWORD { LPVOID } stdcall [ drop eternity 0 ] alien-callback ;
>
> : start-thread ( -- handle )
>     f 0 <ThreadProc> f 0 f CreateThread ;
>
> : main ( -- )
>     start-thread drop
>     "I am here" print flush
>     20,000,000,000 (sleep) ;
>
> MAIN: main
>
> As you can see, it taxes the cpu 100% which proves that the thread is
> running. Then something triggers a gc and it crashes. It is not
> unexpected.
>
> You are kind of entering unexplored territory here. No one has ensured
> that factor works correctly when running kernel threads containing
> factor code. You aren't meant to do it.
>
> However, you can start and run a thread written in C++ in the VM using
> start_thread() as long as you are careful not to mess with the
> factor_vm object in unapproved ways. You can see how it is done in
> start_sampling_profiler_timer() in vm/os-windows.cpp.
>
> I still don't understand how you can get that thread to trap the
> ctrl+break key combo. But if you can, then great!
>
> 2016-05-27 22:16 GMT+02:00 Alexander Ilin <ajs...@yandex.ru>:
>>  Hello!
>>
>>  27.05.2016, 20:00, "Björn Lindqvist" <bjou...@gmail.com>:
>>>  Try defining <ThreadProc> like this:
>>>
>>>  : <ThreadProc> ( -- alien ) DWORD { LPVOID } stdcall [ ] alien-callback ;
>>
>>    Tried this, see below.
>>
>>    I'm now at home, trying these things on Win 8.1 64-bit, on a freshly 
>> bootstrapped Factor. (For some reason the build.cmd produced a 32-bit 
>> executable, even though I'm on a 64-bit system.) The Windows Error Reporting 
>> tool (WerFault.exe) says that an exception is happening. Sometimes I get to 
>> see some kind of dumps in the console, sometimes not.
>>
>>    Here's my code:
>>
>>  USING: kernel windows.kernel32
>>      alien alien.data alien.syntax windows.types ;
>>  IN: my-thd
>>
>>  LIBRARY: kernel32
>>
>>  FUNCTION: HANDLE CreateThread ( LPSECURITY_ATTRIBUTES lpThreadAttributes,
>>                                  SIZE_T dwStackSize,
>>                                  LPVOID lpStartAddress,
>>                                  LPVOID lpParameter,
>>                                  DWORD dwCreationFlags,
>>                                  LPDWORD lpThreadId )
>>
>>  CALLBACK: DWORD ThreadProc ( LPVOID lpParameter )
>>
>>  : <ThreadProc> ( -- alien )
>>    [ [ t ] [ ] while ] ThreadProc ;
>>
>>  : <ThreadProc-2> ( -- alien )
>>    DWORD { LPVOID } stdcall [ ] alien-callback ;
>>
>>  : <ThreadProc-3> ( -- alien )
>>    DWORD { LPVOID } stdcall [ [ t ] [ ] while ] alien-callback ;
>>
>>  : start-thd ( -- hnd )
>>      f 0 <ThreadProc> f 0 f CreateThread ;
>>
>>  : start-thd-2 ( -- hnd )
>>      f 0 <ThreadProc-2> f 0 f CreateThread ;
>>
>>  : start-thd-3 ( -- hnd )
>>      f 0 <ThreadProc-3> f 0 f CreateThread ;
>>
>>    Test runs and results:
>>    start-thd: the app sometimes dies with no output. WerFault sometimes 
>> reports Exception Code c0000409, which Googles to "Stack buffer overflow", 
>> and sometimes c0000005, which is "access violation". Sometimes I see a 
>> console dump, which starts with "fatal_error: Memory protection fault during 
>> gc: <hex-value>".
>>
>>    start-thd-2: most of the time dies with no output, but once I saw the 
>> text "Error in print-error!" on the console.
>>
>>    start-thd-3: most of the time dies with no output, but once I saw a 
>> message box with "Memory protection fault at address 0x105" in it.
>>
>>    Can you help me? I need more code to try.

---=====---
 Александр

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to