I have a strange problem with a very basic task (I just want to print something in the console).
So I have a c++ program which runs an asm function, and this asm function should just print some text and return 3
to c++.
I tried to print the text in many different methods, one of them is the code from this link. C++ runs assembler code which correctly prints text but when it goes to ret
it crashed with the following error:
Exception 0xc0000005 encountered at address 0x7ff654f01000: User-mode data execution prevention (DEP) violation at location 0x7ff654f01000
This is my actual code (with different printing method then the one from the link):
; asmTest.asm
[bits 64] ; allow 64-bit register names
default rel
section .data
msg db "Asm started", 0xd, 0xa, 0
section .text
global _firstWatchdog
extern printf
_firstWatchdog:
lea rcx, [msg]
call printf
mov rax, 3
ret
//main.h
#include <iostream>
#include <thread>
#include <stdio.h>
namespace testCore{
extern "C"{
int _firstWatchdog();
}
}
//main.cpp
#include "main.h"
[[noreturn]] void asmTest(){
std::cout << "asm thread started" << std::endl;
while (true) {
int tmp_func_val = testCore::_firstWatchdog();
}
}
[[noreturn]]int main ()
{
std::thread asm_test;
asm_test = std::thread(asmTest);
asm_test.detach();
while (true){
std::cout << "Do some stuff here" << std::endl;
}
}