Skip to content

Commit ffef640

Browse files
authored
Merge branch 'master' into attach
2 parents f166f04 + a79a764 commit ffef640

File tree

90 files changed

+925
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+925
-403
lines changed

.github/workflows/codeql.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: [ "master" ]
17+
pull_request:
18+
branches: [ "master" ]
19+
schedule:
20+
- cron: '19 17 * * 3'
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners (GitHub.com only)
29+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
30+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31+
permissions:
32+
# required for all workflows
33+
security-events: write
34+
35+
# required to fetch internal or private CodeQL packs
36+
packages: read
37+
38+
# only required for workflows in private repositories
39+
actions: read
40+
contents: read
41+
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
include:
46+
- language: actions
47+
build-mode: none
48+
- language: c-cpp
49+
build-mode: autobuild
50+
- language: javascript-typescript
51+
build-mode: none
52+
- language: python
53+
build-mode: none
54+
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
55+
# Use `c-cpp` to analyze code written in C, C++ or both
56+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
57+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
58+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
59+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
60+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
61+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v4
65+
66+
# Add any setup steps before running the `github/codeql-action/init` action.
67+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
68+
# or others). This is typically only required for manual builds.
69+
# - name: Setup runtime (example)
70+
# uses: actions/setup-example@v1
71+
72+
# Initializes the CodeQL tools for scanning.
73+
- name: Initialize CodeQL
74+
uses: github/codeql-action/init@v3
75+
with:
76+
languages: ${{ matrix.language }}
77+
build-mode: ${{ matrix.build-mode }}
78+
# If you wish to specify custom queries, you can do so here or in a config file.
79+
# By default, queries listed here will override any specified in a config file.
80+
# Prefix the list here with "+" to use these queries and those in the config file.
81+
82+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
83+
# queries: security-extended,security-and-quality
84+
85+
# If the analyze step fails for one of the languages you are analyzing with
86+
# "We were unable to automatically build your code", modify the matrix above
87+
# to set the build mode to "manual" for that language. Then modify this step
88+
# to build your code.
89+
# ℹ️ Command-line programs to run using the OS shell.
90+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
91+
- if: matrix.build-mode == 'manual'
92+
shell: bash
93+
run: |
94+
echo 'If you are using a "manual" build mode for one or more of the' \
95+
'languages you are analyzing, replace this with the commands to build' \
96+
'your code, for example:'
97+
echo ' make bootstrap'
98+
echo ' make release'
99+
exit 1
100+
101+
- name: Perform CodeQL Analysis
102+
uses: github/codeql-action/analyze@v3
103+
with:
104+
category: "/language:${{matrix.language}}"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:v3="urn:schemas-microsoft-com:asm.v3">
3+
<assemblyIdentity type="win32" version="1.0.0.0" processorArchitecture="*" name="CEFLauncher" />
4+
5+
<v3:application>
6+
<windowsSettings>
7+
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
8+
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
9+
</windowsSettings>
10+
</v3:application>
11+
12+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
13+
<application>
14+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> <!-- Windows 10 and Windows 11 -->
15+
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" /> <!-- Windows 8.1 -->
16+
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" /> <!-- Windows 8 -->
17+
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" /> <!-- Windows 7 -->
18+
</application>
19+
</compatibility>
20+
21+
<dependency optional="yes">
22+
<dependentAssembly>
23+
<!-- Automatically use ComCtl32.dll version 6 or later. -->
24+
<assemblyIdentity
25+
type="win32"
26+
name="Microsoft.Windows.Common-Controls"
27+
version="6.0.0.0"
28+
processorArchitecture="*"
29+
publicKeyToken="6595b64144ccf1df"
30+
language="*" />
31+
</dependentAssembly>
32+
</dependency>
33+
</assembly>

Client/ceflauncher/premake5.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ project "CEFLauncher"
99
vpaths {
1010
["Headers/*"] = "**.h",
1111
["Sources/*"] = "**.cpp",
12+
["Resources/*"] = {"*.rc", "**.ico", "**.xml", "**.manifest"},
1213
["*"] = "premake5.lua"
1314
}
1415

1516
files {
1617
"premake5.lua",
1718
"*.h",
18-
"*.cpp"
19+
"*.cpp",
20+
"*.manifest",
1921
}
2022

2123
filter "architecture:not x86"

Client/ceflauncher_DLL/Main.cpp

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
*
1010
*****************************************************************************/
1111

12+
#define WIN32_NO_STATUS
1213
#define WIN32_LEAN_AND_MEAN
1314
#include <Windows.h>
15+
#undef WIN32_NO_STATUS
16+
#include <ntstatus.h>
17+
#include <winnt.h>
18+
#include <winternl.h>
1419
#include <delayimp.h>
1520
#include "CCefApp.h"
1621
#include <string>
@@ -21,6 +26,8 @@
2126
#pragma comment(lib, "cef_sandbox.lib")
2227
#endif
2328

29+
DWORD WINAPI CheckParentProcessAliveness(LPVOID);
30+
2431
int _declspec(dllexport) InitCEF()
2532
{
2633
// Get absolute CEFLauncher.exe path
@@ -46,20 +53,62 @@ int _declspec(dllexport) InitCEF()
4653
sandboxInfo = scopedSandbox.sandbox_info();
4754
#endif
4855

49-
if (HANDLE job = CreateJobObjectW(nullptr, nullptr); job != nullptr)
56+
const HANDLE parentCheckThread = CreateThread(nullptr, 0, CheckParentProcessAliveness, nullptr, 0, nullptr);
57+
58+
const int exitCode = CefExecuteProcess(mainArgs, app, sandboxInfo);
59+
60+
if (parentCheckThread != nullptr)
5061
{
51-
JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits{};
52-
limits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
62+
TerminateThread(parentCheckThread, 0);
63+
CloseHandle(parentCheckThread);
64+
}
5365

54-
if (SetInformationJobObject(job, JobObjectExtendedLimitInformation, &limits, sizeof(limits)))
55-
{
56-
AssignProcessToJobObject(job, GetCurrentProcess());
57-
}
58-
else
66+
return exitCode;
67+
}
68+
69+
static DWORD WINAPI CheckParentProcessAliveness(LPVOID)
70+
{
71+
NTSTATUS(NTAPI * queryInformation)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG) = nullptr;
72+
73+
if (HMODULE const ntdll = GetModuleHandleW(L"ntdll.dll"); ntdll != nullptr)
74+
{
75+
queryInformation = reinterpret_cast<decltype(queryInformation)>(GetProcAddress(ntdll, "NtQueryInformationProcess"));
76+
}
77+
78+
if (queryInformation == nullptr)
79+
return 1;
80+
81+
PROCESS_BASIC_INFORMATION info{};
82+
83+
ULONG returnLength = 0;
84+
NTSTATUS status = queryInformation(GetCurrentProcess(), ProcessBasicInformation, &info, sizeof(info), &returnLength);
85+
86+
if (!NT_SUCCESS(status) || returnLength < sizeof(PROCESS_BASIC_INFORMATION))
87+
return 2;
88+
89+
const auto parentProcessId = static_cast<DWORD>(reinterpret_cast<ULONG_PTR>(info.Reserved3));
90+
const HANDLE parentProcess = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, parentProcessId);
91+
92+
if (parentProcess == nullptr)
93+
{
94+
if (GetLastError() == ERROR_INVALID_PARAMETER)
95+
ExitProcess(0);
96+
97+
return 3;
98+
}
99+
100+
while (true)
101+
{
102+
DWORD exitCode{};
103+
104+
if (!GetExitCodeProcess(parentProcess, &exitCode) || exitCode != STILL_ACTIVE)
59105
{
60-
CloseHandle(job);
106+
CloseHandle(parentProcess);
107+
ExitProcess(exitCode);
61108
}
109+
110+
Sleep(1000);
62111
}
63112

64-
return CefExecuteProcess(mainArgs, app, sandboxInfo);
113+
return 0;
65114
}

Client/cefweb/CefWeb.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ extern "C" _declspec(dllexport) CWebCoreInterface* InitWebCoreInterface(CCoreInt
2222
// Ensure main thread identification is consistent
2323
IsMainThread();
2424

25+
SetMemoryAllocationFailureHandler();
26+
2527
CWebCore* pWebCore = new CWebCore;
2628
return pWebCore;
2729
}

Client/core/CCommandFuncs.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,19 @@ void CCommandFuncs::Test(const char* szParameters)
427427
}
428428
}
429429
}
430+
#if defined(MTA_DEBUG) || MTASA_VERSION_TYPE == VERSION_TYPE_CUSTOM
431+
else if (SStringX(szParameters) == "bad_alloc")
432+
{
433+
if (FileExists(CalcMTASAPath("debug.txt")))
434+
{
435+
while (true)
436+
{
437+
new int[100 * 1024 * 1024]();
438+
g_pCore->GetConsole()->Print("Allocated 100 MiB");
439+
}
440+
}
441+
}
442+
#endif
430443
}
431444

432445
void CCommandFuncs::Serial(const char* szParameters)

Client/core/CCore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,7 @@ void CCore::Quit(bool bInstantly)
14641464
WatchDogBeginSection("Q0"); // Allow loader to detect freeze on exit
14651465

14661466
// Hide game window to make quit look instant
1467+
PostQuitMessage(0);
14671468
ShowWindow(GetHookedWindow(), SW_HIDE);
14681469

14691470
// Destroy the client
@@ -1476,7 +1477,6 @@ void CCore::Quit(bool bInstantly)
14761477

14771478
// Use TerminateProcess for now as exiting the normal way crashes
14781479
TerminateProcess(GetCurrentProcess(), 0);
1479-
// PostQuitMessage ( 0 );
14801480
}
14811481
else
14821482
{

Client/core/CCrashDumpWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ void CCrashDumpWriter::DumpCoreLog(CExceptionInformation* pExceptionInformation)
291291

292292
// For the crash dialog
293293
SetApplicationSetting("diagnostics", "last-crash-info", strInfo);
294+
SetApplicationSetting("diagnostics", "last-crash-module", pExceptionInformation->GetModulePathName());
295+
SetApplicationSettingInt("diagnostics", "last-crash-code", pExceptionInformation->GetCode());
294296
WriteDebugEvent(strInfo.Replace("\n", " "));
295297
}
296298
}

Client/core/Core.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "profiler/SharedUtil.Profiler.h"
1616
#define UTF8_FILE_HOOKS_PERSONALITY_Core
1717
#include "SharedUtil.Win32Utf8FileHooks.hpp"
18+
#include "SharedUtil.Memory.h"
1819

1920
#define CORE_API extern "C" __declspec(dllexport)
2021

@@ -94,6 +95,8 @@ CORE_API int InitializeCore()
9495

9596
WriteDebugEvent(SString("ModuleFileName: %s", *GetLaunchPathFilename()));
9697

98+
SetMemoryAllocationFailureHandler();
99+
97100
g_pCore = new CCore();
98101
return 0;
99102
}

0 commit comments

Comments
 (0)