Closed zanieb closed 6 years ago
Wow, thank you for this comprehensive bug report.
To summarize: Matlab seems to load the DLL correctly (evidenced by the crash dump stack trace line 4, where it calls into libzmq), but somehow crashes in zmq_msg_recv
.
I currently don't have access to a Windows machine, so I can't reproduce this right now. My best hypothesis for now is that the msg
object in ZMQ.m is somehow broken.
Could you try replacing the line
typedef struct zmq_msg_t {unsigned char hidden [64];} zmq_msg_t;
in transplantzmq.h with the actual quote from zmq.h
typedef struct zmq_msg_t {
#if defined (__GNUC__) || defined ( __INTEL_COMPILER) || \
(defined (__SUNPRO_C) && __SUNPRO_C >= 0x590) || \
(defined (__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
unsigned char hidden [64] __attribute__ ((aligned (sizeof (void *))));
#elif defined (_MSC_VER) && (defined (_M_X64) || defined (_M_ARM64))
__declspec (align (8)) unsigned char hidden [64];
#elif defined (_MSC_VER) && (defined (_M_IX86) || defined (_M_ARM_ARMV7VE))
__declspec (align (4)) unsigned char hidden [64];
#else
unsigned char hidden [64];
#endif
and see if that fixes the issue? (I renamed _
to hidden
because Matlab can't create a struct
with a field named _
). Maybe that pointer-alignment is causing problems.
Copying the section you've provided gave the same error (note you actually excluded the final portion of the typedef, so I added it)
typedef struct zmq_msg_t {
#if defined (__GNUC__) || defined ( __INTEL_COMPILER) || \
(defined (__SUNPRO_C) && __SUNPRO_C >= 0x590) || \
(defined (__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
unsigned char hidden [64] __attribute__ ((aligned (sizeof (void *))));
#elif defined (_MSC_VER) && (defined (_M_X64) || defined (_M_ARM64))
__declspec (align (8)) unsigned char hidden [64];
#elif defined (_MSC_VER) && (defined (_M_IX86) || defined (_M_ARM_ARMV7VE))
__declspec (align (4)) unsigned char hidden [64];
#else
unsigned char hidden [64];
#endif
} zmq_msg_t;
If I copy the entire zmq.h -> transplantzmq.h and replace _ with hidden, I get the following error
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
Warning: The data type ' unsigned char hidden [ 64 ] __attribute__ (( aligned ( sizeof ( void *))))' used by structure zmq_msg_t does
not exist. The structure may not be usable.
> In loadlibrary
In ZMQ (line 25)
In transplant_remote (line 43)
Warning: The data type 'FcnPtrPtr' used by function zmq_msg_init_data does not exist.
> In loadlibrary
In ZMQ (line 25)
In transplant_remote (line 43)
Warning: The function 'zmq_msg_gets' was not found in the library
> In loadlibrary
In ZMQ (line 25)
In transplant_remote (line 43)
Warning: The function 'zmq_proxy_steerable' was not found in the library
> In loadlibrary
In ZMQ (line 25)
In transplant_remote (line 43)
Warning: The function 'zmq_has' was not found in the library
> In loadlibrary
In ZMQ (line 25)
In transplant_remote (line 43)
Warning: The data type 'FcnPtrPtr' used by function zmq_threadstart does not exist.
> In loadlibrary
In ZMQ (line 25)
In transplant_remote (line 43)
Error loading libzmq: Could not load ZMQ library
Warning: The following error was caught while executing 'ZMQ' class destructor:
Error using ZMQ/delete (line 73)
Error in zmq_close: Unknown error 128
Error in ZMQ (line 20)
function obj = ZMQ(libname, address)
Error in transplant_remote (line 43)
messenger = ZMQ(zmqname, url);
> In ZMQ (line 20)
In transplant_remote (line 43)
»
The unknown error (128) appears to be from it closing while no context exists.
When explored in the Matlab debugger, it became clear that the not_found variable was being set (library load error). I figured there may be a mismatch in versions so I tried the Anaconda 0MQ again and explored with the Matlab debugger in the ZMQ constructor. This loads the library correctly, but the zmq_msg_t warning seems critical.
>>mq = ZMQ('C:\\ProgramData\\Anaconda3\\Library\\bin\\libzmq.dll', 'tcp://127.0.0.1:65535')
Warning: The data type ' unsigned char hidden [ 64 ] __attribute__ (( aligned ( sizeof ( void *))))' used by structure zmq_msg_t does not exist. The
structure may not be usable.
> In loadlibrary
In ZMQ (line 25)
Warning: The data type 'FcnPtrPtr' used by function zmq_msg_init_data does not exist.
> In loadlibrary
In ZMQ (line 25)
Warning: The data type 'FcnPtrPtr' used by function zmq_threadstart does not exist.
> In loadlibrary
In ZMQ (line 25)
>> mq.send([1,2,3,4])
Error using ZMQ/send (line 64)
Error in zmq_send: The *zmq_send()* operation cannot be performed on this socket at the moment due to the socket not being in the appropriate state.
I thought a lack of data type definition for unsigned char
may be the problem, but
typedef unsigned char u08;
still results in process death. Perhaps aligned
is not defined? I'm not experienced with C, but the syntax appears to be correct for gcc. Additionally, it appears the socket error may be important although it passes the not null assertion.
I'm attempting to switch from MinGW to VC15 to see if that resolves anything since I haven't used MSC with the alignment code.
From a cursory internet search, it appears that the error message "Warning: The data type ... used by structure zmq_msg_t does not exist. The structure may not be usable." is generated by loadlibrary (as opposed to GCC), and seems to indicate that loadlibrary can't parse some part of the definition.
I'm assuming that the problem is the alignment. Which means we will have to cheat to enforce alignment:
Replace the zmq_msg_t
definition in transplantzmq.h:16 with
typedef struct zmq_msg_t {size_t hidden [8];} zmq_msg_t;
And the instantiation in ZMQ.h:46 with
msg = libstruct('zmq_msg_t', struct('hidden', zeros(1, 8, 'uint64')));
This will define zmq_msg_t
as a structure containing the same number of bytes as before, but since its contents are now 64-bit values, the compiler will align them to 64 bits.
This hack does not break transplant on my computer. Let's see if it fixes the issue on yours!
(Just as a sanity check: Both Matlab and libzmq are 64 bit on your computer, right?)
They're both for sure 64-bit.
With those changes (the second in ZMQ.m:46), the process still dies. The warning is gone and we're back to just a stack trace from Matlab's crash (which appears to be the same as before)
------------------------------------------------------------------------
Unknown exception 0x40000015 detected at Mon Apr 23 12:34:19 2018
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled - No sandbox or build area path
Crash Mode : continue (default)
Current Graphics Driver: Unknown hardware
Default Encoding : windows-1252
Deployed : false
Graphics card 1 : RealVNC ( 0x0 ) VNC Mirror Driver Version 1.8.0.0
Graphics card 2 : NVIDIA ( 0x10de ) NVIDIA GeForce GTX 1080 Ti Version 23.21.13.8813
Host Name : ADRLAB-32
MATLAB Architecture : win64
MATLAB Entitlement ID: 3463632
MATLAB Root : C:\Program Files\MATLAB\R2017a
MATLAB Version : 9.2.0.556344 (R2017a)
OpenGL : hardware
Operating System : Microsoft Windows 7 Enterprise
Processor ID : x86 Family 6 Model 60 Stepping 3, GenuineIntel
Virtual Machine : Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : Version 6.1 (Build 7601: Service Pack 1)
Fault Count: 1
Abnormal termination:
Unknown exception 0x40000015
Register State (from fault):
RAX = 000000006761eaee RBX = 000007fee27e3b70
RCX = 0000000004027df0 RDX = 00000000000000d8
RSP = 0000000004028400 RBP = 00000000ffffffff
RSI = 0000000004028600 RDI = 00000000339c39e0
R8 = 0000000000000000 R9 = 0000000000000000
R10 = 051e61ca59b5349f R11 = 0000000004028440
R12 = 0000000004028980 R13 = 0000000000000003
R14 = 0000000000000000 R15 = 0000000000000000
RIP = 000007fefd15a06d EFL = 00000206
CS = 0033 FS = 0053 GS = 002b
Stack Trace (from fault):
[ 0] 0x000007fefd15a06d C:\Windows\system32\KERNELBASE.dll+00106605 RaiseException+00000061
[ 1] 0x000007fee27bd6bb C:\ProgramData\Anaconda3\Library\bin\libzmq.dll+00186043
[ 2] 0x000007fee27a3ffb C:\ProgramData\Anaconda3\Library\bin\libzmq.dll+00081915
[ 3] 0x000007fee27c1b88 C:\ProgramData\Anaconda3\Library\bin\libzmq.dll+00203656
[ 4] 0x000007fee27c17c0 C:\ProgramData\Anaconda3\Library\bin\libzmq.dll+00202688
[ 5] 0x000007fee27d5c48 C:\ProgramData\Anaconda3\Library\bin\libzmq.dll+00285768 zmq_msg_recv+00000040
[ 6] 0x000000006faf14fb C:\Users\adkins\AppData\Local\Temp\tp82b477d1_6518_4e97_a196_75180b2e2adc\libzmq_thunk_pcwin64.dll+00005371 int32voidPtrvoidPtrint32Thunk+00000084
[ 7] 0x00000000e4372792 bin\win64\libmwcli.dll+00010130
[ 8] 0x00000000e437cdb4 bin\win64\libmwcli.dll+00052660
[ 9] 0x00000000e43810f5 bin\win64\libmwcli.dll+00069877
[ 10] 0x00000000e439c280 bin\win64\libmwcli.dll+00180864 PointerMapSize+00084384
[ 11] 0x00000000e439d34e bin\win64\libmwcli.dll+00185166 PointerMapSize+00088686
[ 12] 0x000000000c6eb0ee bin\win64\pgo\m_dispatcher.dll+00045294 mdLogging::~mdLogging+00000154
[ 13] 0x000000000c6e9be1 bin\win64\pgo\m_dispatcher.dll+00039905 Mfh_MATLAB_fn::dispatch_fh+00000641
[ 14] 0x000000000dc6a61c bin\win64\pgo\m_lxe.dll+00108060
[ 15] 0x000000000ddc1ffb bin\win64\pgo\m_lxe.dll+01515515 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,std::vector<MathWorks::lxe::MatlabIrTree * __ptr64,std::allocator<MathWorks::lxe::MatlabIrTree * __ptr64> > >::load_object_data+00013323
[ 16] 0x000000000ddc0aa7 bin\win64\pgo\m_lxe.dll+01510055 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,std::vector<MathWorks::lxe::MatlabIrTree * __ptr64,std::allocator<MathWorks::lxe::MatlabIrTree * __ptr64> > >::load_object_data+00007863
[ 17] 0x000000000dc6a717 bin\win64\pgo\m_lxe.dll+00108311
[ 18] 0x000000000dcf9eb5 bin\win64\pgo\m_lxe.dll+00695989
[ 19] 0x000000000dc88e6a bin\win64\pgo\m_lxe.dll+00233066
[ 20] 0x000000000ddca423 bin\win64\pgo\m_lxe.dll+01549347 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,std::vector<MathWorks::lxe::MatlabIrTree * __ptr64,std::allocator<MathWorks::lxe::MatlabIrTree * __ptr64> > >::load_object_data+00047155
[ 21] 0x000000000de31a97 bin\win64\pgo\m_lxe.dll+01972887 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,std::vector<MathWorks::lxe::MatlabIrTree * __ptr64,std::allocator<MathWorks::lxe::MatlabIrTree * __ptr64> > >::load_object_data+00470695
[ 22] 0x000000000de31a05 bin\win64\pgo\m_lxe.dll+01972741 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,std::vector<MathWorks::lxe::MatlabIrTree * __ptr64,std::allocator<MathWorks::lxe::MatlabIrTree * __ptr64> > >::load_object_data+00470549
[ 23] 0x000000000dc726c9 bin\win64\pgo\m_lxe.dll+00141001
[ 24] 0x000000000dc732f3 bin\win64\pgo\m_lxe.dll+00144115
[ 25] 0x000000000dc7474c bin\win64\pgo\m_lxe.dll+00149324
[ 26] 0x000000000dc75288 bin\win64\pgo\m_lxe.dll+00152200
[ 27] 0x000000000dc7498f bin\win64\pgo\m_lxe.dll+00149903
[ 28] 0x000000000dc68c4b bin\win64\pgo\m_lxe.dll+00101451
[ 29] 0x000000000dc7004a bin\win64\pgo\m_lxe.dll+00131146
[ 30] 0x000000000dc6f7d0 bin\win64\pgo\m_lxe.dll+00128976
[ 31] 0x000000000ddc5d0f bin\win64\pgo\m_lxe.dll+01531151 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,std::vector<MathWorks::lxe::MatlabIrTree * __ptr64,std::allocator<MathWorks::lxe::MatlabIrTree * __ptr64> > >::load_object_data+00028959
[ 32] 0x000000000ddc52d3 bin\win64\pgo\m_lxe.dll+01528531 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,std::vector<MathWorks::lxe::MatlabIrTree * __ptr64,std::allocator<MathWorks::lxe::MatlabIrTree * __ptr64> > >::load_object_data+00026339
[ 33] 0x000000000ddc51b9 bin\win64\pgo\m_lxe.dll+01528249 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,std::vector<MathWorks::lxe::MatlabIrTree * __ptr64,std::allocator<MathWorks::lxe::MatlabIrTree * __ptr64> > >::load_object_data+00026057
[ 34] 0x000000000de50ea9 bin\win64\pgo\m_lxe.dll+02100905 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,MathWorks::lxe::MatlabIrTree>::load_object_data+00015609
[ 35] 0x000000000de50e32 bin\win64\pgo\m_lxe.dll+02100786 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,MathWorks::lxe::MatlabIrTree>::load_object_data+00015490
[ 36] 0x000000000ddc3383 bin\win64\pgo\m_lxe.dll+01520515 boost::archive::detail::iserializer<boost::archive::binaryTerm_iarchive,std::vector<MathWorks::lxe::MatlabIrTree * __ptr64,std::allocator<MathWorks::lxe::MatlabIrTree * __ptr64> > >::load_object_data+00018323
[ 37] 0x000000000cd69aa9 bin\win64\pgo\m_interpreter.dll+00170665 inEvalCmdWithLocalReturnInDesiredWSAndPublishEvents+00000081
[ 38] 0x00000000fcfe4926 bin\win64\iqm.dll+00346406 iqm::InternalEvalPlugin::inEvalCmdWithLocalReturn+00000246
[ 39] 0x00000000fcfe444d bin\win64\iqm.dll+00345165 iqm::InternalEvalPlugin::execute+00000253
[ 40] 0x000000000da2d2e5 bin\win64\mcr.dll+00316133 mcrRegisterExternalFunction+00031957
[ 41] 0x00000000fcfd111a bin\win64\iqm.dll+00266522 iqm::Iqm::setupIqmFcnPtrs+00072250
[ 42] 0x00000000fcfd0ff3 bin\win64\iqm.dll+00266227 iqm::Iqm::setupIqmFcnPtrs+00071955
[ 43] 0x00000000fcfb72da bin\win64\iqm.dll+00160474 iqm::Iqm::deliver+00001114
[ 44] 0x00000000fb5fb7d5 bin\win64\libmwbridge.dll+00047061 ioReadLine+00000517
[ 45] 0x00000000fb5fb692 bin\win64\libmwbridge.dll+00046738 ioReadLine+00000194
[ 46] 0x00000000fb609dc9 bin\win64\libmwbridge.dll+00105929 mnDebugPrompt+00001545
[ 47] 0x00000000fb609903 bin\win64\libmwbridge.dll+00104707 mnDebugPrompt+00000323
[ 48] 0x00000000fb60a04a bin\win64\libmwbridge.dll+00106570 mnParser+00000426
[ 49] 0x000000000da175f1 bin\win64\mcr.dll+00226801 mcr::runtime::setInterpreterThreadSingletonToCurrent+00027889
[ 50] 0x000000000da164e7 bin\win64\mcr.dll+00222439 mcr::runtime::setInterpreterThreadSingletonToCurrent+00023527
[ 51] 0x000000000da16563 bin\win64\mcr.dll+00222563 mcr::runtime::setInterpreterThreadSingletonToCurrent+00023651
[ 52] 0x000000000da16e81 bin\win64\mcr.dll+00224897 mcr::runtime::setInterpreterThreadSingletonToCurrent+00025985
[ 53] 0x00000000fd01e647 bin\win64\iqm.dll+00583239 iqm::UserEvalPlugin::pre+00030695
[ 54] 0x00000000fd02af8c bin\win64\iqm.dll+00634764 iqm::UserEvalPlugin::pre+00082220
[ 55] 0x00000000fd018770 bin\win64\iqm.dll+00558960 iqm::UserEvalPlugin::pre+00006416
[ 56] 0x00000000fd02de9a bin\win64\iqm.dll+00646810 iqm::UserEvalPlugin::pre+00094266
[ 57] 0x00000000fcffad17 bin\win64\iqm.dll+00437527 iqm::PackagedTaskPlugin::PackagedTaskPlugin+00000727
[ 58] 0x00000000fcffb36f bin\win64\iqm.dll+00439151 iqm::PackagedTaskPlugin::execute+00000575
[ 59] 0x00000000fcffad89 bin\win64\iqm.dll+00437641 iqm::PackagedTaskPlugin::PackagedTaskPlugin+00000841
[ 60] 0x00000000fcffb1e4 bin\win64\iqm.dll+00438756 iqm::PackagedTaskPlugin::execute+00000180
[ 61] 0x00000000fcfd111a bin\win64\iqm.dll+00266522 iqm::Iqm::setupIqmFcnPtrs+00072250
[ 62] 0x00000000fcfd0ff3 bin\win64\iqm.dll+00266227 iqm::Iqm::setupIqmFcnPtrs+00071955
[ 63] 0x00000000fcfb7b95 bin\win64\iqm.dll+00162709 iqm::Iqm::deliver+00003349
[ 64] 0x00000000fcfb8815 bin\win64\iqm.dll+00165909 iqm::Iqm::deliver+00006549
[ 65] 0x0000000004776383 bin\win64\libmwservices.dll+01074051 services::system_events::PpeDispatchHook::dispatchOne+00019811
[ 66] 0x000000000477abe3 bin\win64\libmwservices.dll+01092579 sysq::addProcessPendingEventsUnitTestHook+00002099
[ 67] 0x000000000477add0 bin\win64\libmwservices.dll+01093072 sysq::addProcessPendingEventsUnitTestHook+00002592
[ 68] 0x000000000477c095 bin\win64\libmwservices.dll+01097877 sysq::getCondition+00003269
[ 69] 0x000000000477cf8f bin\win64\libmwservices.dll+01101711 svWS_ProcessPendingEvents+00000287
[ 70] 0x000000000da1795e bin\win64\mcr.dll+00227678 mcr::runtime::setInterpreterThreadSingletonToCurrent+00028766
[ 71] 0x000000000da18046 bin\win64\mcr.dll+00229446 mcr::runtime::setInterpreterThreadSingletonToCurrent+00030534
[ 72] 0x000000000da0e832 bin\win64\mcr.dll+00190514 mcr_process_events+00010210
[ 73] 0x000000000da10782 bin\win64\mcr.dll+00198530 mcr_process_events+00018226
[ 74] 0x000000000c65c21e bin\win64\MVMLocal.dll+00246302 mvm_server::inproc::LocalFactory::terminate+00073982
[ 75] 0x00000000fa95a3d9 bin\win64\mvm.dll+01221593 mvm::detail::initLocalMvmHack+00000521
[ 76] 0x00000000fa95ab25 bin\win64\mvm.dll+01223461 mvm::detail::SessionImpl::privateSession+00000533
[ 77] 0x00000000fa95ad31 bin\win64\mvm.dll+01223985 mvm::detail::SessionImpl::privateSession+00001057
[ 78] 0x0000000140006fd5 bin\win64\MATLAB.exe+00028629
[ 79] 0x0000000140007661 bin\win64\MATLAB.exe+00030305
[ 80] 0x00000000770459cd C:\Windows\system32\kernel32.dll+00088525 BaseThreadInitThunk+00000013
[ 81] 0x00000000771a383d C:\Windows\SYSTEM32\ntdll.dll+00342077 RtlUserThreadStart+00000029
I searched the internet for the error code 0x40000015, and it seems to be associated with some system files being corrupted.
That said, I tried to reproduce your error and set up a Windows virtual machine, and it crashes there, as well (though without an error message). I'll investigate further.
The error on my machine can be fixed by starting Matlab with transplant.Matlab(arguments=['-wait'])
. Does this fix your problem as well?
I just updated Transplant with this option enabled by default.
Sorry about the delay, I had moved back to exclusively Linux to get my work done. This is now tested and working on my Windows machine. Thank you so much.
Thank you for bringing it up! This is actually a regression I introduced a while ago and didn't notice (because the Matlab documentation didn't mention it anywhere).
When opening a Matlab instance on Windows, the Matlab process dies immediately. Transplant throws a runtime error. No error message is displayed in the Matlab command window, it becomes unresponsive.
Attempted solutions
Reinstall all relevant packages
No change
Running with admin permissions
No change
Install ZMQ without Anaconda
Same problem as far as I can tell
Fully removed:
Reinstalled with ZeroMQ executable:
Load the ZMQ library from Matlab
No errors e.g.
Create a ZMQ (transplant) class instance from within Matlab
Using the path given by _locate_libzmq() Can create the ZMQ object without problems
e.g.
Install on another (fresh) Windows machine
Same problem
Installation steps
(Visual C++ was already installed)
Use Visual C++ 2015 instead of MinGW/GCC
As a Matlab compiler
Reproduction and error messages
Matlab crash dump
Versions