Code Monkey home page Code Monkey logo

Comments (8)

bb107 avatar bb107 commented on July 30, 2024

Sorry I can't reproduce this problem. The thread_local variable works correctly on my simple test program. Can you provide a code snippet that causes this problem?

from memorymodulepp.

BadaPZ avatar BadaPZ commented on July 30, 2024

I integrated MMPP into a larger build, cannot provide a small repro now.
There is a.EXE it uses import lib to a b.DLL what links MMPP as a static lib. MMPP lib built crt Debug DLL, /EHa x64.
b.DLL (crt debug dll, /EHa, x64) has a thread_local struct WorkData. In the init section inside b.DLL there is a new std::stread(threadWork,...)
At the very beginning of the threadWork(), the thread wants to access WorkData but crashes with access violation at 0x0000000000000330
There are 2 treads created before MMPP registers itself, that threads can access WorkData without crashing. After the registration, the first new std::thread has this issue.
VS2019

from memorymodulepp.

bb107 avatar bb107 commented on July 30, 2024

Please answer these questions to help me build the test program:

  1. Is MMPP linked to a.EXE or b.DLL?
  2. When is WorkData initialized?
  3. Is WorkData a structure or a pointer to a structure?
  4. Is threadWork created by a.EXE or b.DLL?

from memorymodulepp.

BadaPZ avatar BadaPZ commented on July 30, 2024
  1. MMPP linked to the b.DLL.
    2.-3. WorkData is a thread_local struct:
    thread_local RMTLSDATA g_WorkData;
    It is automatically initialized in every thread at the 1st reference to it by the CRT (I guess)

b.dll!RMTLSDATA::RMTLSDATA() Line 84 C++
b.dll!`dynamic initializer for 'g_WorkData''() Line 188 C++
[External Code]

  1. threadWork created by b.DLL

from memorymodulepp.

bb107 avatar bb107 commented on July 30, 2024

If MMPP is statically linked, how did you create the threadWork thread before initializing MMPP and make it run?

from memorymodulepp.

BadaPZ avatar BadaPZ commented on July 30, 2024

in the b.DLL:

initbDll()
{
pThreadData = new THREAD_DATA;
.
.
hthreadWork = new std::thread(threadWork, pThreadData);
.
}

static unsigned __stdcall threadWork(void *lpParam)
{
// read access violation 0x0000000000000215 <-- always a small number
int a = g_WorkData.a;
}

// if I do not link MMPP.lib to the b.DLL everything works.
// the program calls MMPP api first time later

from memorymodulepp.

BadaPZ avatar BadaPZ commented on July 30, 2024

When MMPP is not initialized, in the 1st worker thread:
00007FF91708A510 push rdi
00007FF91708A512 sub rsp,40h
if (g_pWorkData == NULL)
00007FF91708A516 mov eax,110h
00007FF91708A51B mov eax,eax
00007FF91708A51D mov ecx,dword ptr [_tls_index (07FF9173357C0h)] <--- tls index looks good
00007FF91708A523 mov rdx,qword ptr gs:[58h] <---- rdx looks real address
00007FF91708A52C mov rcx,qword ptr [rdx+rcx*8]
00007FF91708A530 cmp qword ptr [rax+rcx],0
00007FF91708A535 jne GetRmTLSData+85h (07FF91708A595h)

later, MMPP initialized next new thread(worker 2nd thread) --> and at same code, rdx 0

from memorymodulepp.

BadaPZ avatar BadaPZ commented on July 30, 2024

Hi! Could you reproduce the issue?

from memorymodulepp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.