mirror of
https://github.com/ElliotKillick/operating-system-design-review
synced 2026-06-06 15:34:33 +00:00
8f9257c1da
From June to now, most of my time on this project was spent writing "The Rise of Microsoft". Researching and writing that thing took an inordinate amount of time. Also, I took a break to work primarily on another unreleased project I have before switching back to this one. I am proud of what I got here though and I feel like it is all coming together. My plans for the whitepapers are already well drafted and I know they will make an impact. I have learned a ton from working on this project and it has definitely given me something to idly think about and work on in my spare time. Finishing "The Problem with How Windows Uses Threads" was something I thought I wanted done before this release, but oh well. The main README is at about 50K words now, plus all the other smaller documents and you are looking at about a small novel's worth of technical writing. And technical writing takes multiple times longer than typical story writing. Anyway, this project is exciting for me - people who I show it to also really like it - and I am even more excited about what is to come!
49 lines
2.2 KiB
C++
49 lines
2.2 KiB
C++
#include <windows.h>
|
|
#include <stdio.h>
|
|
#include <iostream>
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
|
|
switch (fdwReason) {
|
|
case DLL_PROCESS_ATTACH:
|
|
puts("DllMain: DLL_PROCESS_ATTACH");
|
|
|
|
// Similate C++ constructor failing (specifically, the "new" keyword fails to allocate memory)
|
|
// On Windows, C++ exceptions are implemented using SEH
|
|
throw std::bad_alloc();
|
|
|
|
/*
|
|
// Ensure catch handler runs within the same module
|
|
try {
|
|
throw std::bad_alloc();
|
|
}
|
|
catch (const std::bad_alloc& e) {
|
|
std::cerr << "Memory allocation failed: " << e.what() << '\n';
|
|
}
|
|
*/
|
|
|
|
return TRUE;
|
|
break;
|
|
case DLL_PROCESS_DETACH:
|
|
puts("DllMain: DLL_PROCESS_DETACH");
|
|
//__debugbreak();
|
|
break;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
// NOTE:
|
|
// WinDbg appears to be weird with exceptions that have a catcher in another module (or maybe just at process startup between modules?).
|
|
// WinDbg will break then print the following when continuing from an exceptionsssss: "WARNING: Continuing a non-continuable exception"
|
|
// Then, WinDbg will continue code execution as if the exeception had never been raised - without running the code that is supposed to catch the exception. Thus, the loader will not be aware that the module failed initialization.
|
|
// This issue does not occur outside of WinDbg. The loader will catch the exception during module initialization, fail the module's initialization, then exit the process early because the module initialization failure occurred during process startup. This is the correct behavior.
|
|
// This issue does not occur when the exception is caught within the module scope of the module that raised the exception. The catch handler will run as it should in that case before code execution continues (although the aforementioned WinDbg message will still print).
|
|
// I played around with various "sxe" and other WinDbg commands but to no avail.
|
|
// Seems like a WinDbg bug to me.
|
|
// So, run this test outside of WinDbg to get the correct result.
|
|
|
|
EXTERN_C __declspec(dllexport) void DummyExport() {
|
|
// Exported function that does nothing so we can dynamically link
|
|
puts("Test export");
|
|
}
|