Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map does not support declaring as a global variable #16

Open
fgvcbv opened this issue Nov 4, 2024 · 3 comments
Open

Map does not support declaring as a global variable #16

fgvcbv opened this issue Nov 4, 2024 · 3 comments

Comments

@fgvcbv
Copy link

fgvcbv commented Nov 4, 2024

When I declare map as a global variable, it prompts that the atexit function is an unresolved external symbol

@jxy-s
Copy link
Owner

jxy-s commented Nov 4, 2024

https://github.com/jxy-s/stlkrn/blob/main/README.md#msvc-c-stl-support---jxystl

CRT initialization and atexit functionality is intentionally not supported. Order of CRT initialization is unclear and non-obvious. When a kernel driver loads global data should be clearly setup and torn down during driver load and unload. Global CRT initialization "hides" this initialization in a non-obvious way. Further, CRT atexit functionality is not supported. Emission of necessary synchronization enabling local static initialization of C++ objects is not done by the compiler. And would introduces non-obvious synchronization in the kernel. Lack of CRT initialization and atexit support is an intentional design decision. I strongly recommend avoiding it when developing kernel drivers.

@fgvcbv
Copy link
Author

fgvcbv commented Nov 4, 2024

Sorry, I am a beginner. Thank you for your patient guidance. May I ask if there is a good way to declare a global variable map for multiple threads to use

@jxy-s
Copy link
Owner

jxy-s commented Nov 4, 2024

There is a good example in the project here:

namespace jxy
{
//
// This is the global process map singleton. It is allocated/generated and torn
// down during load and unload of the driver. It should be accessed by the
// public jxy::GetProcessMap function.
//
static jxy::ProcessMap* g_ProcessMap = nullptr;
}
jxy::ProcessMap& jxy::GetProcessMap()
{
NT_ASSERT(g_ProcessMap != nullptr);
return *g_ProcessMap;
}
NTSTATUS jxy::AllocateProcessMap() try
{
NT_ASSERT(g_ProcessMap == nullptr);
auto procMap = jxy::make_unique<ProcessMap,
PagedPool,
PoolTags::ProcessMap>();
g_ProcessMap = procMap.release();
return STATUS_SUCCESS;
}
catch (const std::bad_alloc&)
{
return STATUS_INSUFFICIENT_RESOURCES;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants