Matlab crashes when the external function in DLL is called (x64 code)
Show older comments
Hello,
I have a code in assembly language that includes few functions. The code was translated into .DLL (x64). Now I want to call the function in x64 Matlab, but when I do so, Matlab crashes.
I use fastcall (as it's the only calling convention for x64), header file is adjusted to fastcall also.
No call function or load library errors, it just crashes.
Any help appreciated. Thanks!
Accepted Answer
More Answers (6)
Jan
on 22 Mar 2017
0 votes
Well, it sounds like the code of the DLL is buggy. Do you have any evidence that this assembler code works?
Samuel SLenker
on 22 Mar 2017
Edited: Samuel SLenker
on 22 Mar 2017
0 votes
Philip Borghesani
on 22 Mar 2017
0 votes
Sounds like a job for the debugger. Without specifics we can't be of much help. The 64bit abi is sometimes called fastcall and sometimes not. LOADLIBRARY does not need or desire the function to be decorated with the microsoft extension "fastcall" decoration. I assume you are doing this on Windows?
Matlab makes some assumptions about processor state that can be violated by assembly code, my first thought is why are you using assembly? If you change any processor settings make sure you put them back before returning to MATLAB...
The more of the flowing information you supply the more likely we are to be helpful:
- Matlab version and OS.
- Function source or shortened example source if possible.
- Header file contents.
- Matlab example code used to call function.
- Information on how library was built and example c test code you used to test the library function.
- If you cant supply enough code to allow reproduction at least give us the stack trace so we can reason about why things are crashing.
Samuel SLenker
on 22 Mar 2017
Edited: Samuel SLenker
on 22 Mar 2017
void vxm_sse(float *a,float *b,float *c,int d);
calllib('kody', 'vxm_sse', pM, px, py0, length(x)/4);
While pM, px and py0 are float *, length(x)/4 replies a double, not an int. Let's assume that the int has 64 bits, then please try:
calllib('kody', 'vxm_sse', pM, px, py0, int64(length(x)/4));
or
calllib('kody', 'vxm_sse', pM, px, py0, int32(length(x)/4));
I assume that this should be changed also:
% y0=zeros(1,N); py0 = libpointer('singlePtr', y0);
y0 = zeros(1, N, 'single'); py0 = libpointer('singlePtr', y0);
Otherwise you provide a single pointer to double data. This should not crash, but reply messed up data.
Samuel SLenker
on 22 Mar 2017
0 votes
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!