/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include <../Common/UnixLike/Launcher_UnixLike.h> #include #include #include // for AZ_MAX_PATH_LEN #include #include #include #include #include #include #include namespace { void SignalHandler(int sig, siginfo_t* info, void* secret) { FILE* ftrace = fopen("backtrace.log", "w"); if (!ftrace) { ftrace = stderr; } AZ::Debug::StackFrame frames[25]; unsigned int frameCount = AZ_ARRAY_SIZE(frames); frameCount = AZ::Debug::StackRecorder::Record(frames, frameCount); AZ::Debug::SymbolStorage::StackLine lines[25]; AZ::Debug::SymbolStorage::DecodeFrames(frames, frameCount, lines); for (unsigned int frame = 0; frame < frameCount; ++frame) { fprintf(ftrace, "%s", lines[frame]); } if (ftrace != stderr) { fclose(ftrace); } abort(); } void InitStackTracer() { struct sigaction sa; sa.sa_sigaction = SignalHandler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction(SIGSEGV, &sa, 0); sigaction(SIGBUS, &sa, 0); sigaction(SIGILL, &sa, 0); prctl(PR_SET_DUMPABLE, 1, 0, 0, 0); } } #if AZ_TESTS_ENABLED int main(int argc, char** argv) { char exePath[AZ_MAX_PATH_LEN] = { 0 }; if (readlink("/proc/self/exe", exePath, AZ_MAX_PATH_LEN) == -1) { return static_cast(LumberyardLauncher::ReturnCode::ErrExePath); } char* runDir = dirname(exePath); LumberyardLauncher::ReturnCode status = LumberyardLauncher::RunUnitTests(runDir, argc, argv); return static_cast(status); } #else int main(int argc, char** argv) { bool waitForDebugger = false; for (int i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-wait")) { waitForDebugger = true; break; } } if (waitForDebugger) { while(!AZ::Debug::Trace::IsDebuggerPresent()) { AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(50)); } } InitStackTracer(); using namespace LumberyardLauncher; #if !defined(AZ_MONOLITHIC_BUILD) char exePath[AZ_MAX_PATH_LEN] = { 0 }; if (readlink("/proc/self/exe", exePath, AZ_MAX_PATH_LEN) == -1) { return static_cast(ReturnCode::ErrExePath); } char* runDir = dirname(exePath); SetModulePath(runDir); #endif // !defined(AZ_MONOLITHIC_BUILD) PlatformMainInfo mainInfo; char appResourcesPath[AZ_MAX_PATH_LEN] = { 0 }; mainInfo.m_appResourcesPath = GetAbsolutePath(appResourcesPath,AZ_ARRAY_SIZE(appResourcesPath),GetAppResourcePathForHostPlatforms()); if (mainInfo.m_appResourcesPath[0] == '\0') { // Unable to resolve the application resource path because we cannot find the application descriptor (game.xml) return static_cast(ReturnCode::ErrAppDescriptor); } mainInfo.m_updateResourceLimits = IncreaseResourceLimits; bool ret = mainInfo.CopyCommandLine(argc, argv); // run the Lumberyard application ReturnCode status = ret ? Run(mainInfo) : ReturnCode::ErrCommandLine; return static_cast(status); } #endif // AZ_TESTS_ENABLED