Skip to content

Commit 2c54256

Browse files
committed
Merge remote-tracking branch 'upstream/main' into tests-bass-experimental
2 parents b4908db + a5c19ef commit 2c54256

120 files changed

Lines changed: 4018 additions & 8531 deletions

File tree

Some content is hidden

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

.github/workflows/compile.yml

Lines changed: 76 additions & 63 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ source/_versioninfo.h
2626
source/_prebuildtools/http/*.txt
2727
source/_prebuildtools/generated_summary.md
2828
source/modules/_modules.cpp
29+
30+
projects/windows/vs2022/

README.md

Lines changed: 215 additions & 104 deletions
Large diffs are not rendered by default.

development/module/premake5

2.49 MB
Binary file not shown.

example-module-dll/source/example.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ namespace Util
6464
class CExampleModule : public IModule
6565
{
6666
public:
67-
virtual void LuaInit(GarrysMod::Lua::ILuaInterface* pLua, bool bServerInit) override;
68-
virtual void LuaShutdown(GarrysMod::Lua::ILuaInterface* pLua) override;
69-
virtual const char* Name() { return "example"; };
70-
virtual int Compatibility() { return LINUX32 | LINUX64 | WINDOWS32 | WINDOWS64; };
71-
virtual bool SupportsMultipleLuaStates() { return true; }; // This currently is unused
67+
void LuaInit(GarrysMod::Lua::ILuaInterface* pLua, bool bServerInit) override;
68+
void LuaShutdown(GarrysMod::Lua::ILuaInterface* pLua) override;
69+
const char* Name() override { return "example"; };
70+
int Compatibility() override { return LINUX32 | LINUX64 | WINDOWS32 | WINDOWS64; };
71+
bool SupportsMultipleLuaStates() override { return true; }; // This currently is unused
7272
};
7373

7474
LUA_FUNCTION_STATIC(example_hello)

example-module-dll/source/public/iconfigsystem.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#include "interface.h"
44
#include "Bootil/Bootil.h"
55

6+
#ifdef PLATFORM_64BITS
7+
#define HOLYLIB_CONFIG_PATH "garrysmod/holylib/cfg/x64/"
8+
#else
9+
#define HOLYLIB_CONFIG_PATH "garrysmod/holylib/cfg/x86/"
10+
#endif
11+
612
/*
713
This is the exposed config system used by holylib for it's config files.
814
*/
@@ -18,6 +24,8 @@ enum ConfigState
1824
abstract_class IConfig
1925
{
2026
public:
27+
virtual ~IConfig() {};
28+
2129
// Returns true if the config was just created. Add your default values and then save it!
2230
virtual ConfigState GetState() = 0;
2331

example-module-dll/source/public/iholyutil.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ class IHolyUtil
6868
// A bind to CM_Vis allowing you to load the PVS/PAS into the given cluster.
6969
// type = DVIS_PAS(1) or DVIS_PVS(0)
7070
virtual bool CM_Vis(byte* cluster, int clusterSize, int cluserID, int type) = 0;
71+
72+
// Blocks the creation of the given gameevent.
73+
// Does nothing if the the gameevent is already blocked.
74+
virtual void BlockGameEvent(const char* pName) = 0;
75+
76+
// Unblocks the creation of the given gameevent.
77+
// Does nothing if the the gameevent is not blocked.
78+
virtual void UnblockGameEvent(const char* pName) = 0;
79+
80+
// tries to find a SendProp with the given name
81+
// and if found it will return the offset stored in the sendprop.
82+
// Returns -1 on failure
83+
virtual int FindOffsetForNetworkVar(const char* pDTName, const char* pVarName) = 0;
84+
85+
// Returns a pointer to the given offset for the base, do the casting yourself.
86+
virtual void* GoToNetworkVarOffset(void* pBase, int nOffset) = 0;
7187
};
7288

7389
// Should we make this also a interface? :^ (Ye :3)

example-module-dll/source/public/imodule.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ class IModuleManager
246246
// This usually means we were loaded by require("holylib")
247247
virtual bool IsMarkedAsBinaryModule() = 0;
248248

249+
// Tells modules that they can expose / use unsafe code
250+
// This allows them to provide an unrestricted API
251+
// Though of course people should only use it if they know their code isn't potentially malicious.
252+
// (or they may have outside addons/sources that could become malicious)
253+
virtual void EnableUnsafeCode() = 0;
254+
255+
// Returns true if unsafe code is allowed
256+
virtual bool IsUnsafeCodeEnabled() = 0;
257+
249258
// This function is sets the internal variables.
250259
virtual void Setup(CreateInterfaceFn appfn, CreateInterfaceFn gamefn) = 0;
251260

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
return {
2+
groupName = "HolyLib manages to properly Get HolyLib Referenced UserData to Lua",
3+
cases = {
4+
{
5+
name = "Is _HOLYLIB_CORE.GetReferencedTestUserData function existent",
6+
func = function()
7+
expect( _HOLYLIB_CORE.GetReferencedTestUserData ).to.beA( "function" )
8+
end
9+
},
10+
{
11+
name = "Properly got the valid pointer to our userdata",
12+
func = function()
13+
local userdata = _HOLYLIB_CORE.PushReferencedTestUserData()
14+
expect( userdata ).to.beA( "_HOLYLIB_CORE_TEST_REFERENCED" )
15+
16+
-- If we got a garbage pointer, this will return false or crash.
17+
expect( _HOLYLIB_CORE.GetReferencedTestUserData(userdata) ).to.beTrue()
18+
end
19+
},
20+
{
21+
name = "__newindex and __index functions properly work on userdata",
22+
func = function()
23+
local userdata = _HOLYLIB_CORE.PushReferencedTestUserData()
24+
expect( userdata ).to.beA( "_HOLYLIB_CORE_TEST_REFERENCED" )
25+
26+
userdata.example = "Hello World"
27+
28+
expect( userdata.example ).to.equal( "Hello World" )
29+
end
30+
},
31+
{
32+
name = "Performance",
33+
func = function()
34+
local userdata = _HOLYLIB_CORE.PushReferencedTestUserData()
35+
HolyLib_RunPerformanceTest("_HOLYLIB_CORE.GetReferencedTestUserData", _HOLYLIB_CORE.RawReferencedGetTestUserData, userdata)
36+
37+
HolyLib_RunPerformanceTest("_HOLYLIB_CORE.__newindex", function(userdata) userdata.example = "Hello World" end, userdata)
38+
HolyLib_RunPerformanceTest("_HOLYLIB_CORE.__index", function(userdata) return userdata.example end, userdata)
39+
end
40+
},
41+
{
42+
name = "LuaJIT traces do not create a crash",
43+
async = true,
44+
timeout = 5,
45+
func = function()
46+
--[[
47+
Very specific crash caused by LuaJIT generating a GCtrace which then for very magical reasons can lead to memory corruption of userdata
48+
]]
49+
50+
function generate_trace()
51+
jit.opt.start("hotloop=1", "hotexit=1")
52+
jit.flush()
53+
54+
--[[jit.attach(function(what, traceno, func, pc, exitno)
55+
if exitno ~= nil then what = "abort" end
56+
57+
local src = "<unknown>"
58+
if type(func) == "function" or type(func) == "proto" then
59+
local info = jit.util.funcinfo(func)
60+
if info then
61+
src = string.format("%s:%d", info.source or "C", info.linedefined or 0)
62+
end
63+
elseif func ~= nil then
64+
src = tostring(func)
65+
end
66+
67+
print(string.format("[TRACE] %-6s %s %-35s pc=%s exit=%s",
68+
tostring(what),
69+
tostring(traceno or "?"),
70+
tostring(src),
71+
tostring(pc or "-"),
72+
tostring(exitno or "-")
73+
))
74+
end, "trace")]]
75+
76+
local function trace_userdata(u)
77+
return u.test
78+
end
79+
80+
local userData = _HOLYLIB_CORE.PushReferencedTestUserData()
81+
for n = 1, 1e4 do -- Generate those sweet GCtrace
82+
trace_userdata(userData)
83+
end
84+
end
85+
86+
generate_trace()
87+
88+
timer.Simple(1, function()
89+
collectgarbage("collect")
90+
91+
timer.Simple(1, function()
92+
generate_trace() -- If this crashes, we got a problem...
93+
94+
done()
95+
end)
96+
end)
97+
end
98+
},
99+
}
100+
}

gluatests/lua/tests/modules/util/FancyJSONToTable.lua

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,55 @@ return {
3232
expect( actualTable ).to.deepEqual( expectedTable )
3333
end
3434
},
35+
{ -- This the second reported crash from: https://github.com/RaphaelIT7/gmod-holylib/issues/101
36+
name = "Returns a proper result",
37+
when = HolyLib_IsModuleEnabled("util"),
38+
func = function()
39+
local expectedTable = {
40+
{
41+
a = 1,
42+
b = 2,
43+
}
44+
}
45+
46+
-- Input forces it to enter IsArray, which then recursively calls to IsObject internally as this focus on testing if the stack is properly taken account of
47+
-- Formerly, this was screwed up as it handled pushing values wrong pushing more than one value onto the stack resulting in a stack leak and other weird behavior.
48+
local actualTable = util.FancyJSONToTable( '[{"a":1,"b":2}]' )
49+
50+
expect( actualTable ).to.deepEqual( expectedTable )
51+
end
52+
},
53+
{ -- This the third reported issue from (it just never stops :sob:): https://github.com/RaphaelIT7/gmod-holylib/issues/101
54+
name = "Returns a proper result",
55+
when = HolyLib_IsModuleEnabled("util"),
56+
func = function()
57+
local expectedTable = {
58+
name = "[Important: HolyLibIsGoated]",
59+
pos = Vector(4, 2, 0)
60+
}
61+
62+
-- Input uses [ ] though does not focus on being a vector, instead its just a normal string using it
63+
-- This focuses on the internal validation ensuring no garbage vectors are returned (which they previously were)
64+
local actualTable = util.FancyJSONToTable( '{"pos": "[4 2 0]", "name": "[Important: HolyLibIsGoated]"}' )
65+
66+
expect( actualTable ).to.deepEqual( expectedTable )
67+
end
68+
},
69+
{
70+
name = "Returns a proper result",
71+
when = HolyLib_IsModuleEnabled("util"),
72+
func = function()
73+
local expectedTable = {
74+
[1] = "a",
75+
[2] = "b",
76+
["0YHolyLibIsS0C00L"] = "c",
77+
}
78+
79+
local actualTable = util.FancyJSONToTable( '{"1":"a","2":"b","0YHolyLibIsS0C00L":"c"}' )
80+
81+
expect( actualTable ).to.deepEqual( expectedTable )
82+
end
83+
},
3584
{
3685
name = "Performance",
3786
when = HolyLib_IsModuleEnabled("util"),

0 commit comments

Comments
 (0)