Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmake/linux/FindOracle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ if(DEFINED ENV{ORACLE_HOME})
${ORACLE_HOME}/OCI/include) # Oracle XE on Windows

set(ORACLE_OCI_NAMES clntsh libclntsh oci)
set(ORACLE_NNZ_NAMES libnnz18 nnz18 libnnz21 nnz21 ociw32)
set(ORACLE_NNZ_NAMES libnnz18 nnz18 libnnz19 nnz19 libnnz21 nnz21 ociw32)
set(ORACLE_OCCI_NAMES libocci occi oraocci10 oraocci11)

set(ORACLE_LIB_DIR
${ORACLE_HOME}
${ORACLE_HOME}/lib
${ORACLE_HOME}/sdk/lib # Oracle SDK
${ORACLE_HOME}/sdk/lib/msvc
Expand Down Expand Up @@ -76,4 +77,4 @@ endif(DEFINED ENV{ORACLE_HOME})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Oracle DEFAULT_MSG ORACLE_LIBRARY ORACLE_INCLUDE_DIR)

mark_as_advanced(ORACLE_INCLUDE_DIR ORACLE_LIBRARY)
mark_as_advanced(ORACLE_INCLUDE_DIR ORACLE_LIBRARY)
26 changes: 18 additions & 8 deletions engine/server/library/serverScript/src/shared/JavaLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,16 +781,26 @@ void JavaLibrary::fatalHandler(int signum)
{
// try to see if our call stack came from C or Java
void *frameAddress = __builtin_frame_address(0);
// the address that generated the segfault is stored at an offset of 0x44 from
// the frame address
// @todo: find documentation on the offset to verify it is stable
void *crashAddress1 = *((void**)((static_cast<char *>(frameAddress)) + 0x44));

// pass the crash address to addr2line to get the file name where the crash occurred
// These are zero initialized because the strstr() checks below read them
// whenever a lookup fails.
static const int BUFLEN = 2048;
char lib1[BUFLEN], lib2[BUFLEN];
char file1[BUFLEN], file2[BUFLEN];
int line1, line2;
bool result1 = DebugHelp::lookupAddress(reinterpret_cast<uint64>(crashAddress1), lib1, file1, BUFLEN, line1);
char lib1[BUFLEN] = { '\0' }, lib2[BUFLEN] = { '\0' };
char file1[BUFLEN] = { '\0' }, file2[BUFLEN] = { '\0' };
int line1 = 0, line2 = 0;
bool result1 = false;

// The faulting address used to be read from a fixed 0x44 byte offset into
// this frame. That constant describes the 32-bit x86 frame layout only; on
// x86-64 it is both misaligned and meaningless, and dereferencing it from
// inside a SIGSEGV handler risks a recursive fault that loses the crash
// report entirely. The __builtin_return_address() probe below is portable
// and already covers this case.
#if defined(__i386__)
void *crashAddress1 = *((void**)((static_cast<char *>(frameAddress)) + 0x44));
result1 = DebugHelp::lookupAddress(reinterpret_cast<uint64>(crashAddress1), lib1, file1, BUFLEN, line1);
#endif

// do a second test based on the return address
// it turns out that in some java crashes we don't even have 2 return
Expand Down
23 changes: 21 additions & 2 deletions engine/shared/library/sharedDebug/src/linux/DebugHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,30 @@ bool DebugHelp::lookupAddress(uint64 address, char *libName, char *fileName, int

// ----------------------------------------------------------------------

void DebugHelp::getCallStack(uint32 *callStack, int sizeOfCallStack)
void DebugHelp::getCallStack(uint64 *callStack, int sizeOfCallStack)
{
//-- backtrace() writes sizeOfCallStack void* entries. Handing it the
// caller's buffer directly only works when sizeof(void*) happens to
// equal the element size; under LP64 it wrote 8 bytes per entry into a
// 4-byte-per-entry array and overran the buffer by 2x. Capture into a
// native pointer array and widen instead, which is correct for both
// ILP32 and LP64.
enum { cs_maximumFrameCount = 256 };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is functioning as a magic number, so could instead be at top of file, even though it is scoped and only relevant to the single function so it's 50/50 (I also don't love use of an untyped enum here since the compiler then has to make an inference and god knows what it may do in the future); alternatively, e.g., at top of file:

namespace
{
	constexpr int cs_maximumFrameCount = 256;
}


if (sizeOfCallStack <= 0)
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source generally (but admittedly inconsistently) uses allman style bracing and doesn't tend to use indentation block syntax/off-side rule, so code like this would properly be (but again doesn't technically matter and would surely start a not so fun debate)

if (sizeOfCallStack <= 0)
{
    return;
}


for (int i = 0; i < sizeOfCallStack; ++i)
callStack[i] = 0;
IGNORE_RETURN(backtrace(reinterpret_cast<void **>(callStack), sizeOfCallStack));

if (sizeOfCallStack > static_cast<int>(cs_maximumFrameCount))
sizeOfCallStack = static_cast<int>(cs_maximumFrameCount);

void *frames[cs_maximumFrameCount];
int const frameCount = backtrace(frames, sizeOfCallStack);

for (int i = 0; i < frameCount; ++i)
callStack[i] = reinterpret_cast<uint64>(frames[i]);
}

// ======================================================================
Expand Down
5 changes: 4 additions & 1 deletion engine/shared/library/sharedDebug/src/linux/DebugHelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class DebugHelp
static void install();
static void remove();

static void getCallStack(uint32 *callStack, int sizeOfCallStack);
//-- Entries are instruction addresses, so the buffer must be pointer-width
// capable. uint64 matches lookupAddress() below and is wide enough on
// both ILP32 and LP64.
static void getCallStack(uint64 *callStack, int sizeOfCallStack);
static bool lookupAddress(uint64 address, char *libName, char *fileName, int fileNameLength, int &line);
};

Expand Down
8 changes: 4 additions & 4 deletions engine/shared/library/sharedDebug/src/shared/CallStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ void CallStack::debugPrint() const
for (size_t i = 2; i < CALLSTACK_DEPTH; ++i)
{
if (DebugHelp::lookupAddress(m_callStack[i], libName, fileName, sizeof(fileName), line))
DEBUG_REPORT_PRINT(true, (" (0x%08X) %s(%d) : caller %d\n", static_cast<int>(m_callStack[i]), fileName, line, i - 1));
DEBUG_REPORT_PRINT(true, (" (0x%016llX) %s(%d) : caller %d\n", static_cast<unsigned long long>(m_callStack[i]), fileName, line, i - 1));
else
DEBUG_REPORT_PRINT(true, (" unknown(0x%08X) : caller %d\n", static_cast<int>(m_callStack[i]), i - 1));
DEBUG_REPORT_PRINT(true, (" unknown(0x%016llX) : caller %d\n", static_cast<unsigned long long>(m_callStack[i]), i - 1));
}
}

Expand All @@ -76,9 +76,9 @@ void CallStack::debugLog() const
for (size_t i = 2; i < CALLSTACK_DEPTH && m_callStack[i]!=0; ++i)
{
if (DebugHelp::lookupAddress(m_callStack[i], libName, fileName, sizeof(fileName), line))
DEBUG_REPORT_LOG(true, (" (0x%08X) %s(%d) : caller %d\n", static_cast<int>(m_callStack[i]), fileName, line, i - 1));
DEBUG_REPORT_LOG(true, (" (0x%016llX) %s(%d) : caller %d\n", static_cast<unsigned long long>(m_callStack[i]), fileName, line, i - 1));
else
DEBUG_REPORT_LOG(true, (" unknown(0x%08X) : caller %d\n", static_cast<int>(m_callStack[i]), i - 1));
DEBUG_REPORT_LOG(true, (" unknown(0x%016llX) : caller %d\n", static_cast<unsigned long long>(m_callStack[i]), i - 1));
}
}

Expand Down
3 changes: 2 additions & 1 deletion engine/shared/library/sharedDebug/src/shared/CallStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class CallStack

private:

uint32 m_callStack[S_callStack];
//-- Instruction addresses; must be pointer-width capable (see DebugHelp::getCallStack).
uint64 m_callStack[S_callStack];
};

// ======================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace CallStackCollectorNamespace
~Node();

CrcString const & getName() const;
void addCallStack(uint32 * callStack);
void addCallStack(uint64 * callStack);

void debugReport() const;

Expand All @@ -63,7 +63,7 @@ namespace CallStackCollectorNamespace

public:

uint32 * m_callStack;
uint64 * m_callStack;
int m_calls;
};

Expand Down Expand Up @@ -125,10 +125,10 @@ CrcString const & CallStackCollectorNamespace::Node::getName() const

// ----------------------------------------------------------------------

void CallStackCollectorNamespace::Node::addCallStack(uint32 * const callStack)
void CallStackCollectorNamespace::Node::addCallStack(uint64 * const callStack)
{
//-- Compute crc of memory
uint32 const crc = Crc::calculate(callStack, (sizeof(uint32) * CALLSTACK_DEPTH));
uint32 const crc = Crc::calculate(callStack, (sizeof(*callStack) * CALLSTACK_DEPTH));

//-- Find callstack in list
CallStackEntryMap::iterator iter = m_callStackEntryMap.find(crc);
Expand All @@ -140,8 +140,8 @@ void CallStackCollectorNamespace::Node::addCallStack(uint32 * const callStack)
else
{
//-- Create new callstack
uint32 * const newCallStack = new uint32[CALLSTACK_DEPTH];
memcpy(newCallStack, callStack, sizeof(*newCallStack));
uint64 * const newCallStack = new uint64[CALLSTACK_DEPTH];
memcpy(newCallStack, callStack, sizeof(*newCallStack) * CALLSTACK_DEPTH);

CallStackEntry callStackEntry;
callStackEntry.m_callStack = newCallStack;
Expand Down Expand Up @@ -180,7 +180,7 @@ void CallStackCollectorNamespace::Node::debugReport() const
if (DebugHelp::lookupAddress(callStackEntry->m_callStack[j], libName, fileName, sizeof(fileName), line))
REPORT_LOG(true, (" %s(%d) : caller %d\n", fileName, line, j - 1));
else
REPORT_LOG(true, (" unknown(0x%08X) : caller %d\n", static_cast<int>(callStackEntry->m_callStack[j]), j - 1));
REPORT_LOG(true, (" unknown(0x%016llX) : caller %d\n", static_cast<unsigned long long>(callStackEntry->m_callStack[j]), j - 1));
}
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ void CallStackCollector::sample(char const * const name)
}

//-- Sample the callstack
uint32 callStack[CALLSTACK_DEPTH];
uint64 callStack[CALLSTACK_DEPTH];
DebugHelp::getCallStack(&callStack[0], CALLSTACK_DEPTH);

//-- Add to the node
Expand Down
10 changes: 5 additions & 5 deletions engine/shared/library/sharedDebug/src/win32/DebugHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ bool DebugHelp::loadSymbolsForDll(const char *name)

// ----------------------------------------------------------------------
#pragma warning (disable: 4740 4748)
void DebugHelp::getCallStack(uint32 *callStack, int sizeOfCallStack)
void DebugHelp::getCallStack(uint64 *callStack, int sizeOfCallStack)
{
{
for (int i = 0; i < sizeOfCallStack; ++i)
Expand Down Expand Up @@ -525,7 +525,7 @@ void DebugHelp::getCallStack(uint32 *callStack, int sizeOfCallStack)
if (stackWalk64(IMAGE_FILE_MACHINE_I386, process, process, &stackFrame, &context, NULL, functionTableAccess, getModuleBase, NULL))
{
const DWORD64 Offset = stackFrame.AddrPC.Offset;
*callStack = DWORD(Offset);
*callStack = static_cast<uint64>(Offset);
}
}
}
Expand All @@ -537,7 +537,7 @@ void DebugHelp::reportCallStack(int const maxStackDepth)
// look up the call stack information
int const callStackOffset = 2;
int const callStackSize = callStackOffset + maxStackDepth;
uint32 * callStack = static_cast<uint32 *>(_alloca((callStackOffset + maxStackDepth) * sizeof(uint32)));
uint64 * callStack = static_cast<uint64 *>(_alloca((callStackOffset + maxStackDepth) * sizeof(uint64)));
getCallStack(callStack, callStackOffset + maxStackDepth);

// look up the caller's file and line
Expand All @@ -553,15 +553,15 @@ void DebugHelp::reportCallStack(int const maxStackDepth)
if (lookupAddress(callStack[i], lib, file, sizeof(file), line))
REPORT_LOG(true, ("\t%s(%d) : caller %d\n", file, line, i-callStackOffset));
else
REPORT_LOG(true, ("\tunknown(0x%08X) : caller %d\n", static_cast<int>(callStack[i]), i-callStackOffset));
REPORT_LOG(true, ("\tunknown(0x%016llX) : caller %d\n", static_cast<unsigned long long>(callStack[i]), i-callStackOffset));
}
}
}
}

// ----------------------------------------------------------------------

bool DebugHelp::lookupAddress(uint32 address, char *libName, char *fileName, int fileNameLength, int &line)
bool DebugHelp::lookupAddress(uint64 address, char *libName, char *fileName, int fileNameLength, int &line)
{
UNREF(libName);

Expand Down
4 changes: 2 additions & 2 deletions engine/shared/library/sharedDebug/src/win32/DebugHelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class DebugHelp

static bool loadSymbolsForDll(const char *name);

static void getCallStack(uint32 *callStack, int sizeOfCallStack);
static void getCallStack(uint64 *callStack, int sizeOfCallStack);
static void reportCallStack(int const maxStackDepth = 4);
static bool lookupAddress(uint32 address, char *libName, char *fileName, int fileNameLength, int &line);
static bool lookupAddress(uint64 address, char *libName, char *fileName, int fileNameLength, int &line);

static bool writeMiniDump(char const *miniDumpFileName=0, PEXCEPTION_POINTERS exceptionPointers=0);
};
Expand Down
21 changes: 17 additions & 4 deletions engine/shared/library/sharedFoundation/src/linux/PlatformGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,23 @@ char* _itoa(int value, char* stringOut, int radix)

bool QueryPerformanceCounter(__int64* time)
{
struct timeval tv;
gettimeofday(&tv, nullptr);
*time = static_cast<LARGE_INTEGER>(tv.tv_sec);
*time = (*time * 1000000) + static_cast<LARGE_INTEGER>(tv.tv_usec);
// Must be monotonic. gettimeofday() reports CLOCK_REALTIME, which NTP can
// slew or step backwards; callers subtract successive samples to derive
// frame time, so a backwards step produced negative elapsed times (see
// AlterScheduler "no forward time movement"). CLOCK_MONOTONIC never goes
// backwards. Units stay microseconds to match QueryPerformanceFrequency().
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
{
struct timeval tv;
gettimeofday(&tv, nullptr);
*time = static_cast<LARGE_INTEGER>(tv.tv_sec);
*time = (*time * 1000000) + static_cast<LARGE_INTEGER>(tv.tv_usec);
return TRUE;
}

*time = static_cast<LARGE_INTEGER>(ts.tv_sec);
*time = (*time * 1000000) + static_cast<LARGE_INTEGER>(ts.tv_nsec / 1000);

return TRUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace Archive
char temp[200];
AutoDeltaMap<NetworkId, int>::Command c;

Archive::put(target, countCharacter(buffer,':'));
Archive::put(target, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(target, static_cast<int32_t>(countCharacter(buffer,':')));
Archive::put(target, static_cast<int32_t>(0)); // baselineCommandCount

int tempPos = 0;
for (std::string::const_iterator i=buffer.begin(); i!=buffer.end(); ++i)
Expand Down Expand Up @@ -64,8 +64,8 @@ namespace Archive
char temp[200];

AutoDeltaMap<NetworkId, int>::Command c;
size_t commandCount;
size_t baselineCommandCount;
int32_t commandCount;
int32_t baselineCommandCount;

Archive::get(source, commandCount);
Archive::get(source, baselineCommandCount);
Expand All @@ -76,7 +76,7 @@ namespace Archive
}
else
{
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
Archive::get(source, c.key);
Expand Down
6 changes: 3 additions & 3 deletions engine/shared/library/sharedFoundation/src/shared/Fatal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void formatMessage(char *buffer, int bufferLength, int stackDepth, const

// look up the call stack information
const int callStackSize = callStackOffset + stackDepth;
uint32 callStack[callStackOffset + maxStackDepth];
uint64 callStack[callStackOffset + maxStackDepth];

// allow complete disable of the call stack lookup
if (stackDepth < 0)
Expand All @@ -82,7 +82,7 @@ static void formatMessage(char *buffer, int bufferLength, int stackDepth, const
if (ConfigSharedFoundation::getLookUpCallStackNames() && DebugHelp::lookupAddress(callStack[callStackOffset], lib, file, sizeof(file), line))
snprintf(buffer, bufferLength, "%s(%d) : %s %08x: \n", file, line, type, static_cast<int>(Crc::calculate(format)));
else
snprintf(buffer, bufferLength, "(0x%08X) : %s %08x: \n", static_cast<int>(callStack[callStackOffset]), type, static_cast<int>(Crc::calculate(format)));
snprintf(buffer, bufferLength, "(0x%016llX) : %s %08x: \n", static_cast<unsigned long long>(callStack[callStackOffset]), type, static_cast<int>(Crc::calculate(format)));
}
else
{
Expand Down Expand Up @@ -126,7 +126,7 @@ static void formatMessage(char *buffer, int bufferLength, int stackDepth, const
if (ConfigSharedFoundation::getLookUpCallStackNames() && DebugHelp::lookupAddress(callStack[i], lib, file, sizeof(file), line))
snprintf(buffer, bufferLength, " %s(%d) : caller %d\n", file, line, i-callStackOffset);
else
snprintf(buffer, bufferLength, " (0x%08X) : caller %d\n", static_cast<int>(callStack[i]), i-callStackOffset);
snprintf(buffer, bufferLength, " (0x%016llX) : caller %d\n", static_cast<unsigned long long>(callStack[i]), i-callStackOffset);

const int length = strlen(buffer);
buffer += length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace Archive
char value[200];
Command c;

Archive::put(target, countCharacter(buffer,':'));
Archive::put(target, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(target, static_cast<int32_t>(countCharacter(buffer,':')));
Archive::put(target, static_cast<int32_t>(0)); // baselineCommandCount

int tempPos = 0;
for (std::string::const_iterator i=buffer.begin(); i!=buffer.end(); ++i)
Expand Down Expand Up @@ -52,8 +52,8 @@ namespace Archive
char temp[200];

Command c;
size_t commandCount;
size_t baselineCommandCount;
int32_t commandCount;
int32_t baselineCommandCount;

Archive::get(source, commandCount);
Archive::get(source, baselineCommandCount);
Expand All @@ -64,7 +64,7 @@ namespace Archive
}
else
{
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
Archive::get(source, c.key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace Archive
char temp[200];
Command c;

Archive::put(target, countCharacter(buffer,':'));
Archive::put(target, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(target, static_cast<int32_t>(countCharacter(buffer,':')));
Archive::put(target, static_cast<int32_t>(0)); // baselineCommandCount

int tempPos = 0;
for (std::string::const_iterator i=buffer.begin(); i!=buffer.end(); ++i)
Expand Down Expand Up @@ -55,8 +55,8 @@ namespace Archive
char temp[200];

Command c;
size_t commandCount;
size_t baselineCommandCount;
int32_t commandCount;
int32_t baselineCommandCount;

Archive::get(source, commandCount);
Archive::get(source, baselineCommandCount);
Expand All @@ -67,7 +67,7 @@ namespace Archive
}
else
{
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
assert(c.cmd == Command::ADD); // only add is valid in unpack
Expand Down