Files
UnrealEngineUWP/Engine/Source/Runtime/Linux/LinuxCommonStartup/Private/LinuxCommonStartup.cpp
Andrew Grant 69f9d6f648 Copying //UE4/Orion-Staging to //UE4/Main (originated from //Orion/Dev-General @ 2831630)
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 2831624 on 2016/01/17 by Marcus.Wassmer

	Merge disable of FCachedReadPlatformData on PS4.  Reduces memory spikes. 2830986
	#rb none
	#test none
	#codereview Michael.Noland,James.Golding

Change 2831402 on 2016/01/17 by Marcus.Wassmer

	HLOD priority and streamout changes.
	Give texture pool an extra 200MB which we can afford thanks to James/Michael
	#rb Chris.Gagnon
	#test run agora, notice nice textures.
	#lockdown Andrew.Grant

Change 2831398 on 2016/01/17 by Marcus.Wassmer

	Fix 3 logic bugs with Relocate
	#rb chris.gagnon
	#test run game, look for corruption.
	#lockdown Andrew.Grant

Change 2831372 on 2016/01/16 by Marcus.Wassmer

	Update param.sfo's and lockdown version in prep for good PS4 playtest build.
	#rb none
	#test build from last night...
	#lockdown Andrew.Grant

Change 2831274 on 2016/01/16 by Graeme.Thornton

	Disable platform file cache wrapper on PS4

	#codereview James.Golding
	#rb none
	#tests ran cooked ps4 build, timed loading (no real change), measured memory used for file handles (small)

Change 2831237 on 2016/01/16 by Sammy.James

	Fix PS4 compile error

	#codereview Andrew.Grant
	#rb none
	#tests none

Change 2831219 on 2016/01/16 by Matt.Kuhlenschmidt

	Fix possible invalid access to shared  movie player resource across threads causing startup crash.

	#codereview marcus.wassmer
	#rb none, #tests initial load

Change 2831218 on 2016/01/16 by Marcus.Wassmer

	Fix bad warning case.
	#codereview Martin.Mittring
	#rb none
	#test none

Change 2831201 on 2016/01/16 by Andrew.Grant

	Added extra info about referencer to missing asset reference message
	#rb none
	#tests cooked, ran editor

Change 2831183 on 2016/01/16 by David.Nikdel

	#OSS #PS4 #Purchasing #StoreV2
	- Force failure if we have no receipts after a "successful" checkout.
	- Report consumed entitlements as well as unconsumed but leave ValidationInfo empty so we can tell the difference at the application level
	- Convert productIds to skuIds at checkout time
	- Added PS4 Implementation of IOnlineStoreV2
	- Bugfix: set bSuccessfullyStartedUp=false when InitNPGameSettings() fails
	- Adjusted FOnlineStoreOffer to use FText::AsCurrencyBase
	#RB: Paul.Moore
	#TESTS: login, purchase redemption, store MTX purchasing on PS4 & PC

Change 2831129 on 2016/01/16 by David.Nikdel

	#MCP
	- Added a ctor to make converting from FOnlineError to FMcpQueryResult easier (for stuff that was already using FMcpQueryResult).
	#RB: none
	#TESTS: frontend

Change 2830986 on 2016/01/15 by Michael.Noland

	PS4: Disabling FCachedReadPlatformFile on PS4 to significantly reduce high watermark memory consumption during blocking loads
	#rb marcus.wassmer
	#tests Ran Paragon PS4 down a bad path that currently does a blocking map and hero load
	#lockdown andrew.grant

Change 2830943 on 2016/01/15 by Max.Chen

	Sequencer: Fix bug introduced with preroll. It was also causing a crash in particle track instance.

	#tests Master sequence trailer plays without crashing
	#rb none

Change 2830912 on 2016/01/15 by Michael.Noland

	Rendering: Exposed GRHIDeviceId (only filled in on D3D11 and D3D12 RHI's under the same circumstances as GRHIAdapterName, etc..., 0 otherwise)
	#rb mieszko.zielinski
	#tests Tested printing the value out
	#codereview martin.mittring

Change 2830910 on 2016/01/15 by Michael.Noland

	Rendering: Improved GPU driver detection logic to handle more cases
	#codereview martin.mittring
	#rb mieszko.zielinski
	#tests Tested on my machine which was previous reporting Unknown for the values as some entries contained the key in the Settings subfolder

Change 2830776 on 2016/01/15 by Martin.Mittring

	from Dev-Rendering
	added ensure to track down multiple issues like
	OR-11771 CRASH: User Crashed when pressing the Play button
	OR-12430 CRASH: OT2 user crashed with FRHIResource::AddRef()
	#rb:Gil.Gribb
	#code_review:Gil.Gribb,Mark.Satterthwaite,Marcus.Wassmer
2016-01-20 11:32:08 -05:00

249 lines
6.9 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "LinuxCommonStartup.h"
#include "ExceptionHandling.h"
#include "LinuxPlatformCrashContext.h"
#include "ModuleManager.h"
#include "EngineVersion.h"
#include <locale.h>
#include <sys/resource.h>
static FString GSavedCommandLine;
extern int32 GuardedMain( const TCHAR* CmdLine );
extern void LaunchStaticShutdownAfterError();
// FIXME: handle expose it someplace else?
extern int32 DLLIMPORT ReportCrash(const FLinuxCrashContext& Context);
extern void DLLIMPORT GenerateCrashInfoAndLaunchReporter(const FLinuxCrashContext& Context);
/**
* Game-specific crash reporter
*/
void CommonLinuxCrashHandler(const FGenericCrashContext& GenericContext)
{
// at this point we should already be using malloc crash handler (see PlatformCrashHandler)
const FLinuxCrashContext& Context = static_cast< const FLinuxCrashContext& >( GenericContext );
printf("CommonLinuxCrashHandler: Signal=%d\n", Context.Signal);
ReportCrash(Context);
if (GLog)
{
GLog->Flush();
}
if (GWarn)
{
GWarn->Flush();
}
if (GError)
{
GError->Flush();
GError->HandleError();
}
return GenerateCrashInfoAndLaunchReporter(Context);
}
/**
* Sets (soft) limit on a specific resource
*
* @param Resource - one of RLIMIT_* values
* @param DesiredLimit - desired value
* @param bIncreaseOnly - avoid changing the limit if current value is sufficient
*/
bool SetResourceLimit(int Resource, rlim_t DesiredLimit, bool bIncreaseOnly)
{
rlimit Limit;
if (getrlimit(Resource, &Limit) != 0)
{
fprintf(stderr, "getrlimit() failed with error %d (%s)\n", errno, strerror(errno));
return false;
}
if (bIncreaseOnly && (Limit.rlim_cur == RLIM_INFINITY || Limit.rlim_cur >= DesiredLimit))
{
if (!UE_BUILD_SHIPPING)
{
printf("- Existing per-process limit (soft=%lu, hard=%lu) is enough for us (need only %lu)\n", Limit.rlim_cur, Limit.rlim_max, DesiredLimit);
}
return true;
}
Limit.rlim_cur = DesiredLimit;
if (setrlimit(Resource, &Limit) != 0)
{
fprintf(stderr, "setrlimit() failed with error %d (%s)\n", errno, strerror(errno));
if (errno == EINVAL)
{
if (DesiredLimit == RLIM_INFINITY)
{
fprintf(stderr, "- Max per-process value allowed is %lu (we wanted infinity).\n", Limit.rlim_max);
}
else
{
fprintf(stderr, "- Max per-process value allowed is %lu (we wanted %lu).\n", Limit.rlim_max, DesiredLimit);
}
}
return false;
}
return true;
}
/**
* Expects GSavedCommandLine to be set up. Increases limit on
* - number of open files to be no less than desired (if specified on command line, otherwise left alone)
* - size of core file, so core gets dumped and we can debug crashed builds (unless overridden with -nocore)
*
*/
static bool IncreasePerProcessLimits()
{
// honor the parameter if given, but don't change limits if not
int32 FileHandlesToReserve = -1;
if (FParse::Value(*GSavedCommandLine, TEXT("numopenfiles="), FileHandlesToReserve) && FileHandlesToReserve > 0)
{
if (!UE_BUILD_SHIPPING)
{
printf("Increasing per-process limit of open file handles to %d\n", FileHandlesToReserve);
}
if (!SetResourceLimit(RLIMIT_NOFILE, FileHandlesToReserve, true))
{
fprintf(stderr, "Could not adjust number of file handles, consider changing \"nofile\" in /etc/security/limits.conf and relogin.\nerror(%d): %s\n", errno, strerror(errno));
return false;
}
}
// core dump policy:
// - Shipping and Test disable by default (unless -core is passed)
// - The rest set it to infinity unless -nocore is passed
// (in all scenarios user wish as expressed with -core or -nocore takes priority)
bool bDisableCore = (UE_BUILD_SHIPPING || UE_BUILD_TEST);
if (FParse::Param(*GSavedCommandLine, TEXT("nocore")))
{
bDisableCore = true;
}
if (FParse::Param(*GSavedCommandLine, TEXT("core")))
{
bDisableCore = false;
}
if (bDisableCore)
{
printf("Disabling core dumps.\n");
if (!SetResourceLimit(RLIMIT_CORE, 0, false))
{
fprintf(stderr, "Could not set core file size to 0, error(%d): %s\n", errno, strerror(errno));
return false;
}
}
else
{
printf("Increasing per-process limit of core file size to infinity.\n");
if (!SetResourceLimit(RLIMIT_CORE, RLIM_INFINITY, true))
{
fprintf(stderr, "Could not adjust core file size, consider changing \"core\" in /etc/security/limits.conf and relogin.\nerror(%d): %s\n", errno, strerror(errno));
fprintf(stderr, "Alternatively, pass -nocore if you are unable or unwilling to do that.\n");
return false;
}
}
return true;
}
int CommonLinuxMain(int argc, char *argv[], int (*RealMain)(const TCHAR * CommandLine))
{
FPlatformMisc::SetGracefulTerminationHandler();
if (UE_BUILD_SHIPPING)
{
// only printed in shipping
printf("%s %d %d %d %d\n", StringCast<ANSICHAR>(*FEngineVersion::Current().ToString()).Get(), GEngineMinNetVersion, GEngineNegotiationVersion, GPackageFileUE4Version, GPackageFileLicenseeUE4Version);
}
int ErrorLevel = 0;
if (setenv("LC_NUMERIC", "en_US", 1) != 0)
{
int ErrNo = errno;
fprintf(stderr, "Unable to setenv(LC_NUMERIC): errno=%d (%s)", ErrNo, strerror(ErrNo));
}
setlocale(LC_CTYPE, "");
for (int32 Option = 1; Option < argc; Option++)
{
GSavedCommandLine += TEXT(" ");
// we need to quote stuff that has spaces in it because something somewhere is removing quotation marks before they arrive here
FString Temp = UTF8_TO_TCHAR(argv[Option]);
if (Temp.Contains(TEXT(" ")))
{
if(Temp.StartsWith(TEXT("-")))
{
Temp = Temp.Replace(TEXT("="), TEXT("=\""));
}
else
{
Temp = TEXT("\"") + Temp;
}
Temp += TEXT("\"");
}
GSavedCommandLine += Temp; // note: technically it depends on locale
}
if (!UE_BUILD_SHIPPING)
{
GAlwaysReportCrash = true; // set by default and reverse the behavior
if ( FParse::Param( *GSavedCommandLine,TEXT("nocrashreports") ) || FParse::Param( *GSavedCommandLine,TEXT("no-crashreports") ) )
{
GAlwaysReportCrash = false;
}
}
if (!IncreasePerProcessLimits())
{
fprintf(stderr, "Could not set desired per-process limits, consider changing system limits.\n");
ErrorLevel = 1;
}
else
{
#if UE_BUILD_DEBUG
if( true && !GAlwaysReportCrash )
#else
if( FPlatformMisc::IsDebuggerPresent() && !GAlwaysReportCrash )
#endif
{
// Don't use exception handling when a debugger is attached to exactly trap the crash. This does NOT check
// whether we are the first instance or not!
ErrorLevel = RealMain( *GSavedCommandLine );
}
else
{
FPlatformMisc::SetCrashHandler(CommonLinuxCrashHandler);
GIsGuarded = 1;
// Run the guarded code.
ErrorLevel = RealMain( *GSavedCommandLine );
GIsGuarded = 0;
}
}
if (ErrorLevel)
{
printf("Exiting abnormally (error code: %d)\n", ErrorLevel);
}
return ErrorLevel;
}
class FLinuxCommonStartupModule : public IModuleInterface
{
/** IModuleInterface implementation */
virtual void StartupModule() override {};
virtual void ShutdownModule() override {};
};
IMPLEMENT_MODULE(FLinuxCommonStartupModule, LinuxCommonStartup);