1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-11 13:06:59 +03:00
mold/common/signal-win32.cc
2024-03-21 11:00:13 +09:00

47 lines
1.1 KiB
C++

#include "common.h"
#include <windows.h>
namespace mold {
std::string errno_string() {
LPVOID buf;
DWORD dw = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buf, 0, nullptr);
std::string ret = (char *)buf;
LocalFree(buf);
return ret;
}
static LONG WINAPI vectored_handler(_EXCEPTION_POINTERS *exception_info) {
static std::mutex mu;
std::scoped_lock lock{mu};
PEXCEPTION_RECORD rec = exception_info->ExceptionRecord;
ULONG_PTR *p = rec->ExceptionInformation;
if (rec->ExceptionCode == EXCEPTION_IN_PAGE_ERROR &&
(ULONG_PTR)output_buffer_start <= p[1] &&
p[1] < (ULONG_PTR)output_buffer_end) {
static const char msg[] =
"mold: failed to write to an output file. Disk full?\n";
(void)!_write(_fileno(stderr), msg, sizeof(msg) - 1);
}
cleanup();
_exit(1);
}
void install_signal_handler() {
AddVectoredExceptionHandler(0, vectored_handler);
}
} // namespace mold