3 * ======================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC and authors.
7 * ======================================================
9 * This software is provided 'as-is', without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from
11 * the use of this software.
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software in a
19 * product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
28 #include "metamod_oslink.h"
35 #if defined __WIN32__ || defined _WIN32 || defined WIN32
38 static char buf[1024];
43 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
46 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
52 _snprintf(buf, sizeof(buf), "unknown error %x", num);
65 extern "C" void __cxa_guard_acquire(void)
69 extern "C" void __cxa_guard_release(void)
74 bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
76 #if defined WIN32 || defined _WIN32
77 MEMORY_BASIC_INFORMATION mem;
78 if (!VirtualQuery(pAddr, &mem, sizeof(mem)))
80 if (mem.AllocationBase == NULL)
82 HMODULE dll = (HMODULE)mem.AllocationBase;
83 GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
84 #elif defined __linux__
86 if (!dladdr(pAddr, &info))
88 if (!info.dli_fbase || !info.dli_fname)
90 const char *dllpath = info.dli_fname;
91 snprintf(buffer, maxlength, "%s", dllpath);
96 #if defined __GNUC__ && (__GNUC__ == 3 || __GNUC__ == 4)
97 void * operator new(size_t size) {
101 void * operator new[](size_t size) {
105 void operator delete(void * ptr) {
109 void operator delete[](void * ptr) {