BlindMindStudios / AngelScript-JIT-Compiler

A Just-In-Time compiler for the AngelScript language on x86 processors.

Home Page:www.blind-mind.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

valgrind detects invalid write in virtual_asm.h

ScottDillman opened this issue · comments

I building on Ubuntu 14.04 LTS 64 bit with gcc 4.8.2 using the latest JIT compiler code and AngelScript 2.29, but I have tried 2.28 and 2.27 and have gotten the same results. I am still narrowing down the problem. But running valgrind with --tool=memcheck detects an invalid write with a script containing an empty main function, here is part of the output:

==10471== Invalid write of size 1
==10471== at 0x5BA821: assembler::Processor& assembler::Processor::operator<< (unsigned char) (virtual_asm.h:216)
==10471== by 0x5B2E66: assembler::Processor& assembler::Processor::operator<< assembler::RegPrefix(assembler::RegPrefix) (virtual_asm_x64.cpp:471)
==10471== by 0x5B2EE4: assembler::Processor::push(assembler::Register&) (virtual_asm_x64.cpp:476)
==10471== by 0x583185: asCJITCompiler::CompileFunction(asIScriptFunction_, void (__)(asSVMRegisters_, unsigned long)) (as_jit.cpp:421)
==10471== by 0x6841BD: asCScriptFunction::JITCompile() (as_scriptfunction.cpp:1422)
==10471== by 0x6F16C0: asCModule::JITCompile() (as_module.cpp:241)
==10471== by 0x6F183B: asCModule::Build() (as_module.cpp:288)

I wanted to post this here while I look into it further just in case anyone on the team sees anything in the output. Just for completeness the line referenced above is:

(T)op = b; op += sizeof(T);

So it at first glance it seems like op is going out of bounds, and I'm not sure why or if I have done anything to cause it to happen. I'm still debugging it a bit.

I'll update here when I have something more concrete to show, or close it if I find I did something in my code to cause it.. thanks..

It looks like no executable page was allocated. There is no error thrown if that happens, which is an oversight. Check what the return of mmap is in virtual_asm_linux.cpp:98.

Thanks for the info.. I added a throw in virtual_asm_linux.cpp right after the page allocation if the pointer returned was MAP_FAILED, and it threw in Valgrind but didn't under normal conditions or while debugging, so I might be seeing some wonkyness with Valgrind's memcheck tool and mmap and not a real error. I'm going to dig a bit further to make sure that is what is going on and if I don't find anything I'll close this issue over the next day or so.. thanks..

While debugging an issue in our main project, we discovered that the mmap call was passing technically incorrect addresses to mmap, which our C++ library accepted without error. We'll fix it shortly.

Great, let me know if there is anything I can test. I was also having problems in Windows in the same area but have not had time to dig into it yet.. Thanks for the update..