diff --git a/CMakeLists.txt b/CMakeLists.txt index cb54f2e..3d0130e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ add_subdirectory(Engine/Source/FrameXML) add_subdirectory(Engine/Source/Gx) add_subdirectory(Engine/Source/Gxu) add_subdirectory(Engine/Source/Images) +add_subdirectory(Engine/Source/lua-5.1) add_subdirectory(Engine/Source/Model2) add_subdirectory(Engine/Source/Os) add_subdirectory(Engine/Source/Services) diff --git a/Engine/Source/Base/ConvertUTF.cpp b/Engine/Source/Base/ConvertUTF.cpp index 1f45b07..54ccdbf 100644 --- a/Engine/Source/Base/ConvertUTF.cpp +++ b/Engine/Source/Base/ConvertUTF.cpp @@ -222,7 +222,7 @@ int32_t ConvertUTF8toUTF16(uint16_t* dst, uint32_t dstmaxchars, const char* src, } // VERIFY: e60cd645 manual -// OFFSET: 0x0047BD40 +// OFFSET: [0x0047BD40, 0x00852210] uint32_t sgetu8(const uint8_t* strptr, int32_t* chars) { if (chars) { *chars = 0; @@ -287,7 +287,7 @@ uint32_t sgetu8(const uint8_t* strptr, int32_t* chars) { } // VERIFY: 1fa47a7d manual -// OFFSET: 0x0047BE50 +// OFFSET: [0x0047BE50, 0x00852320] char* sputu8(uint32_t c, char* strptr) { if (!strptr) { return strptr; diff --git a/Engine/Source/FrameScript/FrameScript.h b/Engine/Source/FrameScript/FrameScript.h index 62aabce..eca4c15 100644 --- a/Engine/Source/FrameScript/FrameScript.h +++ b/Engine/Source/FrameScript/FrameScript.h @@ -1,4 +1,7 @@ #ifndef ENGINE_SOURCE_FRAMESCRIPT_FRAMESCRIPT_H #define ENGINE_SOURCE_FRAMESCRIPT_FRAMESCRIPT_H +void FrameScript_FindTextSectionBounds(); +void FrameScript_InvalidPtrCheck(const void* ptr); + #endif diff --git a/Engine/Source/FrameScript/Win32/FrameScript.cpp b/Engine/Source/FrameScript/Win32/FrameScript.cpp new file mode 100644 index 0000000..c684830 --- /dev/null +++ b/Engine/Source/FrameScript/Win32/FrameScript.cpp @@ -0,0 +1,51 @@ +#if defined(WOWDECOMP_ARCH_32) + +#include +#include +#include +#include "Engine/Source/FrameScript/FrameScript.h" +#include "Engine/Source/Storm/H/storm.h" + +// STATIC: 0x00D415B8 +static uintptr_t s_textStart; + +// STATIC: 0x00D415BC +static uintptr_t s_textEnd; + +// VERIFY: 9b7c9677 manual +// OFFSET: 0x0086B510 +void FrameScript_FindTextSectionBounds() { + uint8_t* image = reinterpret_cast(StormGetInstance()); + IMAGE_NT_HEADERS* header = reinterpret_cast(image + reinterpret_cast(image)->e_lfanew); + IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(header); + uint16_t i; + + for (i = 0; i < header->FileHeader.NumberOfSections; i++) { + if (!strncmp(reinterpret_cast(sections[i].Name), ".text", 8)) { + break; + } + } + + if (i >= header->FileHeader.NumberOfSections) { + SErrDisplayAppFatal("Unable to find .text section"); + } + + s_textStart = header->OptionalHeader.ImageBase + sections[i].VirtualAddress; + s_textEnd = header->OptionalHeader.ImageBase + sections[i].VirtualAddress + sections[i].Misc.VirtualSize; +} + +// VERIFY: b7b0670a auto +// OFFSET: 0x0086B5A0 +void FrameScript_InvalidPtrCheck(const void* ptr) { + if (!s_textStart || !s_textEnd) { + FrameScript_FindTextSectionBounds(); + } + + if (reinterpret_cast(ptr) < s_textStart || reinterpret_cast(ptr) >= s_textEnd) { + char buffer[64]; + SStrPrintf(buffer, sizeof(buffer), "Invalid function pointer: %p", ptr); + SErrDisplayAppFatal(buffer); + } +} + +#endif diff --git a/Engine/Source/FrameScript/Win64/FrameScript.cpp b/Engine/Source/FrameScript/Win64/FrameScript.cpp new file mode 100644 index 0000000..f0bd057 --- /dev/null +++ b/Engine/Source/FrameScript/Win64/FrameScript.cpp @@ -0,0 +1,49 @@ +#if defined(WOWDECOMP_ARCH_64) + +#include +#include +#include +#include "Engine/Source/FrameScript/FrameScript.h" +#include "Engine/Source/Storm/H/storm.h" + +// STATIC: 0x00D415B8 +static uintptr_t s_textStart; + +// STATIC: 0x00D415BC +static uintptr_t s_textEnd; + +// OFFSET: 0x0086B510 +void FrameScript_FindTextSectionBounds() { + uint8_t* image = reinterpret_cast(StormGetInstance()); + IMAGE_NT_HEADERS* header = reinterpret_cast(image + reinterpret_cast(image)->e_lfanew); + IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(header); + uint16_t i; + + for (i = 0; i < header->FileHeader.NumberOfSections; i++) { + if (!strncmp(reinterpret_cast(sections[i].Name), ".text", 8)) { + break; + } + } + + if (i >= header->FileHeader.NumberOfSections) { + SErrDisplayAppFatal("Unable to find .text section"); + } + + s_textStart = header->OptionalHeader.ImageBase + sections[i].VirtualAddress; + s_textEnd = header->OptionalHeader.ImageBase + sections[i].VirtualAddress + sections[i].Misc.VirtualSize; +} + +// OFFSET: 0x0086B5A0 +void FrameScript_InvalidPtrCheck(const void* ptr) { + if (!s_textStart || !s_textEnd) { + FrameScript_FindTextSectionBounds(); + } + + if (reinterpret_cast(ptr) < s_textStart || reinterpret_cast(ptr) >= s_textEnd) { + char buffer[64]; + SStrPrintf(buffer, sizeof(buffer), "Invalid function pointer: %p", ptr); + SErrDisplayAppFatal(buffer); + } +} + +#endif diff --git a/Engine/Source/lua-5.1/CMakeLists.txt b/Engine/Source/lua-5.1/CMakeLists.txt new file mode 100644 index 0000000..7208d44 --- /dev/null +++ b/Engine/Source/lua-5.1/CMakeLists.txt @@ -0,0 +1,13 @@ +file(GLOB PRIVATE_SOURCES CONFIGURE_DEPENDS "src/*.c" "src/*.cpp") + +set_source_files_properties(${PRIVATE_SOURCES} PROPERTIES LANGUAGE CXX) + +add_library(lua STATIC + ${PRIVATE_SOURCES} +) + +target_include_directories(lua + PUBLIC + ${CMAKE_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/src +) diff --git a/Engine/Source/lua-5.1/src/lapi.c b/Engine/Source/lua-5.1/src/lapi.c index 4e49903..a97f5a5 100644 --- a/Engine/Source/lua-5.1/src/lapi.c +++ b/Engine/Source/lua-5.1/src/lapi.c @@ -29,6 +29,33 @@ #include "lundump.h" #include "lvm.h" +#include "Engine/Source/Os/TimeManager.h" + + + +// STATIC: 0x00D4139C +const char *lua_tainted; + +// STATIC: 0x00D413A0 +int lua_taintexpected; + +// STATIC: 0x00D413A4 +int lua_taintedclosure; + +// STATIC: 0x00D413A8 +const char *lua_closuretaint; + +// STATIC: 0x00D413AC +const char *lua_gctag; + +// STATIC: 0x00D413B0 +lua_TaintEventCallback lua_tainteventcallback; + +// STATIC: 0x00D413B8 +static int lua_decimalconvert; + +// STATIC: 0x00D413C0 +static double divisor; const char lua_ident[] = @@ -46,6 +73,7 @@ const char lua_ident[] = +// VERIFY: 1dd43771 auto // OFFSET: 0x0084D9C0 static TValue *index2adr (lua_State *L, int idx) { if (idx > 0) { @@ -87,6 +115,7 @@ static Table *getcurrenv (lua_State *L) { } +// VERIFY: d17915ee auto // OFFSET: 0x0084DA50 void luaA_pushobject (lua_State *L, const TValue *o) { setobj2s(L, L->top, o); @@ -94,6 +123,7 @@ void luaA_pushobject (lua_State *L, const TValue *o) { } +// VERIFY: bd829ab2 auto // OFFSET: 0x0084DAB0 LUA_API int lua_checkstack (lua_State *L, int size) { int res; @@ -111,6 +141,7 @@ LUA_API int lua_checkstack (lua_State *L, int size) { } +// VERIFY: a69e2f34 auto // OFFSET: 0x0084DB10 LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { int i; @@ -137,6 +168,7 @@ LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { } +// VERIFY: 8788f0a2 auto // OFFSET: 0x0084DB90 LUA_API lua_State *lua_newthread (lua_State *L) { lua_State *L1; @@ -157,12 +189,14 @@ LUA_API lua_State *lua_newthread (lua_State *L) { */ +// VERIFY: 32643dea auto // OFFSET: 0x0084DBD0 LUA_API int lua_gettop (lua_State *L) { return cast_int(L->top - L->base); } +// VERIFY: 1e7a16af manual // OFFSET: 0x0084DBF0 LUA_API void lua_settop (lua_State *L, int idx) { lua_lock(L); @@ -180,6 +214,7 @@ LUA_API void lua_settop (lua_State *L, int idx) { } +// VERIFY: 06656fc6 manual // OFFSET: 0x0084DC50 LUA_API void lua_remove (lua_State *L, int idx) { StkId p; @@ -192,6 +227,7 @@ LUA_API void lua_remove (lua_State *L, int idx) { } +// VERIFY: 2be38194 manual // OFFSET: 0x0084DCC0 LUA_API void lua_insert (lua_State *L, int idx) { StkId p; @@ -205,6 +241,7 @@ LUA_API void lua_insert (lua_State *L, int idx) { } +// VERIFY: 714e46d6 manual // OFFSET: 0x0084DD70 LUA_API void lua_replace (lua_State *L, int idx) { StkId o; @@ -231,6 +268,7 @@ LUA_API void lua_replace (lua_State *L, int idx) { } +// VERIFY: aa5e9297 auto // OFFSET: 0x0084DE50 LUA_API void lua_pushvalue (lua_State *L, int idx) { lua_lock(L); @@ -246,6 +284,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { */ +// VERIFY: 68a46d83 auto // OFFSET: 0x0084DEB0 LUA_API int lua_type (lua_State *L, int idx) { StkId o = index2adr(L, idx); @@ -253,6 +292,7 @@ LUA_API int lua_type (lua_State *L, int idx) { } +// VERIFY: 8d49994f auto // OFFSET: 0x0084DED0 LUA_API const char *lua_typename (lua_State *L, int t) { UNUSED(L); @@ -260,6 +300,7 @@ LUA_API const char *lua_typename (lua_State *L, int t) { } +// VERIFY: 286449f1 auto // OFFSET: 0x0084DEF0 LUA_API int lua_iscfunction (lua_State *L, int idx) { StkId o = index2adr(L, idx); @@ -267,6 +308,7 @@ LUA_API int lua_iscfunction (lua_State *L, int idx) { } +// VERIFY: eaa88f68 auto // OFFSET: 0x0084DF20 LUA_API int lua_isnumber (lua_State *L, int idx) { TValue n; @@ -275,6 +317,7 @@ LUA_API int lua_isnumber (lua_State *L, int idx) { } +// VERIFY: 029b8d17 auto // OFFSET: 0x0084DF60 LUA_API int lua_isstring (lua_State *L, int idx) { int t = lua_type(L, idx); @@ -288,6 +331,7 @@ LUA_API int lua_isuserdata (lua_State *L, int idx) { } +// VERIFY: 0d65ac16 auto // OFFSET: 0x0084DF90 LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { StkId o1 = index2adr(L, index1); @@ -297,7 +341,6 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { } -// OFFSET: 0x0084DFE0 LUA_API int lua_equal (lua_State *L, int index1, int index2) { StkId o1, o2; int i; @@ -310,6 +353,8 @@ LUA_API int lua_equal (lua_State *L, int index1, int index2) { } +// VERIFY: 3bbf3971 auto +// OFFSET: 0x0084DFE0 LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { StkId o1, o2; int i; @@ -324,6 +369,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { +// VERIFY: 286b3139 auto // OFFSET: 0x0084E030 LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { TValue n; @@ -335,6 +381,7 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { } +// VERIFY: db96ea7b auto // OFFSET: 0x0084E070 LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { TValue n; @@ -350,6 +397,7 @@ LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { } +// VERIFY: 3fdfc853 auto // OFFSET: 0x0084E0B0 LUA_API int lua_toboolean (lua_State *L, int idx) { const TValue *o = index2adr(L, idx); @@ -357,6 +405,7 @@ LUA_API int lua_toboolean (lua_State *L, int idx) { } +// VERIFY: b35c5c22 auto // OFFSET: 0x0084E0E0 LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { StkId o = index2adr(L, idx); @@ -376,6 +425,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { } +// VERIFY: d5420752 auto // OFFSET: 0x0084E150 LUA_API size_t lua_objlen (lua_State *L, int idx) { StkId o = index2adr(L, idx); @@ -401,6 +451,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { } +// VERIFY: a1507ea5 auto // OFFSET: 0x0084E1C0 LUA_API void *lua_touserdata (lua_State *L, int idx) { StkId o = index2adr(L, idx); @@ -412,6 +463,7 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) { } +// VERIFY: 9c47046f auto // OFFSET: 0x0084E1F0 LUA_API lua_State *lua_tothread (lua_State *L, int idx) { StkId o = index2adr(L, idx); @@ -419,6 +471,7 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) { } +// VERIFY: 01b101f3 auto // OFFSET: 0x0084E210 LUA_API const void *lua_topointer (lua_State *L, int idx) { StkId o = index2adr(L, idx); @@ -440,6 +493,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { */ +// VERIFY: 2b02b23c auto // OFFSET: 0x0084E280 LUA_API void lua_pushnil (lua_State *L) { lua_lock(L); @@ -449,6 +503,7 @@ LUA_API void lua_pushnil (lua_State *L) { } +// VERIFY: 2ed64d07 auto // OFFSET: 0x0084E2A0 LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { lua_lock(L); @@ -458,6 +513,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { } +// VERIFY: 8d42aac7 auto // OFFSET: 0x0084E2D0 LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { lua_lock(L); @@ -467,6 +523,7 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { } +// VERIFY: bc8f5431 auto // OFFSET: 0x0084E300 LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { lua_lock(L); @@ -477,6 +534,7 @@ LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { } +// VERIFY: a749f6bf manual // OFFSET: 0x0084E350 LUA_API void lua_pushstring (lua_State *L, const char *s) { if (s == NULL) @@ -486,6 +544,7 @@ LUA_API void lua_pushstring (lua_State *L, const char *s) { } +// VERIFY: b5aefec9 auto // OFFSET: 0x0084E3A0 LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp) { @@ -498,6 +557,7 @@ LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, } +// VERIFY: 93b40940 auto // OFFSET: 0x0084E3D0 LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { const char *ret; @@ -512,6 +572,7 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { } +// VERIFY: acb69a7d manual // OFFSET: 0x0084E400 LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { Closure *cl; @@ -530,6 +591,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { } +// VERIFY: 4ea5d166 auto // OFFSET: 0x0084E4D0 LUA_API void lua_pushboolean (lua_State *L, int b) { lua_lock(L); @@ -539,6 +601,7 @@ LUA_API void lua_pushboolean (lua_State *L, int b) { } +// VERIFY: 8614060b auto // OFFSET: 0x0084E500 LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { lua_lock(L); @@ -548,6 +611,7 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { } +// VERIFY: 30d1f5e9 auto // OFFSET: 0x0084E530 LUA_API int lua_pushthread (lua_State *L) { lua_lock(L); @@ -564,6 +628,7 @@ LUA_API int lua_pushthread (lua_State *L) { */ +// VERIFY: 89cab4ee auto // OFFSET: 0x0084E560 LUA_API void lua_gettable (lua_State *L, int idx) { StkId t; @@ -575,6 +640,7 @@ LUA_API void lua_gettable (lua_State *L, int idx) { } +// VERIFY: e08b04e7 auto // OFFSET: 0x0084E590 LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { StkId t; @@ -589,6 +655,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { } +// VERIFY: e439afa2 manual // OFFSET: 0x0084E600 LUA_API void lua_rawget (lua_State *L, int idx) { StkId t; @@ -600,6 +667,7 @@ LUA_API void lua_rawget (lua_State *L, int idx) { } +// VERIFY: 14f1bd9e auto // OFFSET: 0x0084E670 LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { StkId o; @@ -612,6 +680,7 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { } +// VERIFY: 05a10d3c auto // OFFSET: 0x0084E6E0 LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { lua_lock(L); @@ -622,6 +691,7 @@ LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { } +// VERIFY: 7f534bb7 auto // OFFSET: 0x0084E730 LUA_API int lua_getmetatable (lua_State *L, int objindex) { const TValue *obj; @@ -652,6 +722,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { } +// VERIFY: cf0dffc5 manual // OFFSET: 0x0084E7A0 LUA_API void lua_getfenv (lua_State *L, int idx) { StkId o; @@ -660,7 +731,17 @@ LUA_API void lua_getfenv (lua_State *L, int idx) { api_checkvalidindex(L, o); switch (ttype(o)) { case LUA_TFUNCTION: - sethvalue(L, L->top, clvalue(o)->c.env); + if (clvalue(o)->c.isC) { + sethvalue(L, L->top, clvalue(o)->c.env); + } + else { + const char *oldtaint = lua_tainted; + if (clvalue(o)->l.taint && lua_taintexpected && !lua_taintedclosure) + lua_tainted = clvalue(o)->l.taint; + sethvalue(L, L->top, clvalue(o)->l.env); + if (lua_taintexpected && !lua_taintedclosure) + lua_tainted = oldtaint; + } break; case LUA_TUSERDATA: sethvalue(L, L->top, uvalue(o)->env); @@ -682,6 +763,7 @@ LUA_API void lua_getfenv (lua_State *L, int idx) { */ +// VERIFY: 8fce564e auto // OFFSET: 0x0084E8D0 LUA_API void lua_settable (lua_State *L, int idx) { StkId t; @@ -695,6 +777,7 @@ LUA_API void lua_settable (lua_State *L, int idx) { } +// VERIFY: f9e6cb9a auto // OFFSET: 0x0084E900 LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { StkId t; @@ -710,6 +793,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { } +// VERIFY: 7caa96c6 auto // OFFSET: 0x0084E970 LUA_API void lua_rawset (lua_State *L, int idx) { StkId t; @@ -724,6 +808,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) { } +// VERIFY: f0d23e03 manual // OFFSET: 0x0084EA00 LUA_API void lua_rawseti (lua_State *L, int idx, int n) { StkId o; @@ -738,6 +823,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { } +// VERIFY: 7367d60f auto // OFFSET: 0x0084EA90 LUA_API int lua_setmetatable (lua_State *L, int objindex) { TValue *obj; @@ -776,6 +862,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { } +// VERIFY: 1fed53c2 manual // OFFSET: 0x0084EB40 LUA_API int lua_setfenv (lua_State *L, int idx) { StkId o; @@ -788,6 +875,8 @@ LUA_API int lua_setfenv (lua_State *L, int idx) { switch (ttype(o)) { case LUA_TFUNCTION: clvalue(o)->c.env = hvalue(L->top - 1); + if (ttisfunction(o) && !clvalue(o)->c.isC && !clvalue(o)->l.taint) + clvalue(o)->l.taint = lua_tainted; break; case LUA_TUSERDATA: uvalue(o)->env = hvalue(L->top - 1); @@ -819,6 +908,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) { api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) +// VERIFY: 6e4f76d9 auto // OFFSET: 0x0084EBF0 LUA_API void lua_call (lua_State *L, int nargs, int nresults) { StkId func; @@ -842,6 +932,7 @@ struct CallS { /* data to `f_call' */ }; +// VERIFY: b72ccd0c auto // OFFSET: 0x0084EC30 static void f_call (lua_State *L, void *ud) { struct CallS *c = cast(struct CallS *, ud); @@ -850,6 +941,7 @@ static void f_call (lua_State *L, void *ud) { +// VERIFY: 22bbabd1 auto // OFFSET: 0x0084EC50 LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { struct CallS c; @@ -908,6 +1000,7 @@ LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { } +// VERIFY: 7d58b942 auto // OFFSET: 0x0084ECC0 LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char *chunkname) { @@ -922,6 +1015,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, } +// VERIFY: fb196121 manual // OFFSET: 0x0084ED00 LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { int status; @@ -938,6 +1032,7 @@ LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { } +// VERIFY: 679cc239 auto // OFFSET: 0x0084ED40 LUA_API int lua_status (lua_State *L) { return L->status; @@ -948,6 +1043,7 @@ LUA_API int lua_status (lua_State *L) { ** Garbage-collection function */ +// VERIFY: 96f61d18 auto // OFFSET: 0x0084ED50 LUA_API int lua_gc (lua_State *L, int what, int data) { int res = 0; @@ -1004,6 +1100,61 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { return res; } +// VERIFY: 3455df8e auto +// OFFSET: 0x0084EE50 +LUA_API void lua_gcupdatesizes (lua_State *L) { + luaC_sizeall(L); +} + + +// VERIFY: ebf06783 auto +// OFFSET: 0x0084EE60 +LUA_API lu_mem lua_gcgetsize (lua_State *L, const char *tag) { + return luaC_getsize(L, tag); +} + + +// VERIFY: cfe5c0a3 auto +// OFFSET: 0x0084EE70 +LUA_API void lua_gcupdatetimes (lua_State *L) { + luaC_timeall(L); +} + + +// VERIFY: 539a8d2d auto +// OFFSET: 0x0084EE80 +LUA_API double lua_gcgettime (lua_State *L, const char *tag) { + return luaC_gettime(L, tag); +} + + +// VERIFY: d06fe92f manual +// OFFSET: 0x0084EE90 +LUA_API void lua_gcgetfunctiontime (lua_State *L, double *time, double *totaltime, int *calls) { + TValue *o = L->top - 1; + if (G(L)->profile && ttisfunction(o)) { + Profile *p = clvalue(o)->l.profile; + if (divisor == 0.0) + divisor = 1000.0 / OsGetAsyncClocksPerSecond(); + *time = p->time * divisor; + *totaltime = divisor * p->totaltime; + *calls = p->calls; + } + else { + *time = 0.0; + *totaltime = 0.0; + *calls = 0; + } +} + + +// VERIFY: 2cfb52a7 auto +// OFFSET: 0x0084EF20 +LUA_API void lua_gcresettimes (lua_State *L) { + luaC_timereset(L); +} + + /* @@ -1011,6 +1162,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { */ +// VERIFY: 2d6ea67c manual // OFFSET: 0x0084EF30 LUA_API int lua_error (lua_State *L) { lua_lock(L); @@ -1021,6 +1173,7 @@ LUA_API int lua_error (lua_State *L) { } +// VERIFY: 94e6d464 manual // OFFSET: 0x0084EF50 LUA_API int lua_next (lua_State *L, int idx) { StkId t; @@ -1039,6 +1192,7 @@ LUA_API int lua_next (lua_State *L, int idx) { } +// VERIFY: 2398dde4 auto // OFFSET: 0x0084EF90 LUA_API void lua_concat (lua_State *L, int n) { lua_lock(L); @@ -1056,6 +1210,45 @@ LUA_API void lua_concat (lua_State *L, int n) { lua_unlock(L); } +// VERIFY: 409b28d7 auto +// OFFSET: 0x0084F010 +LUA_API void lua_setdecimalconversion (int convert) { + lua_decimalconvert = (convert != 0); +} + + +// VERIFY: 4e57f306 manual +// OFFSET: 0x0084F030 +LUA_API void lua_convertdecimal (char *s) { + if (lua_decimalconvert) { + char *end = s + strlen(s); + while (*s && s < end) { + if (*s >= '0' && *s <= '9') { + while ((*s >= '0' && *s <= '9') || *s == '.' || *s == ',') { + if (*s == ',') { + if (s[1] >= '0' && s[1] <= '9') + *s = '.'; + } + else if (*s == '.') { + if (s[1] >= '0' && s[1] <= '9') + *s = ','; + } + s++; + } + } + s++; + } + } +} + + +// VERIFY: b97c4645 auto +// OFFSET: 0x0084F0D0 +LUA_API void lua_settaint (lua_State *L, int idx, const char *taint) { + index2adr(L, idx)->taint = taint; +} + + LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { lua_Alloc f; @@ -1075,6 +1268,7 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { } +// VERIFY: e0042c5e auto // OFFSET: 0x0084F0F0 LUA_API void *lua_newuserdata (lua_State *L, size_t size) { Udata *u; @@ -1108,6 +1302,7 @@ static const char *aux_upvalue (StkId fi, int n, TValue **val) { } +// VERIFY: 4d682a7e manual // OFFSET: 0x0084F150 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { const char *name; diff --git a/Engine/Source/lua-5.1/src/lauxlib.c b/Engine/Source/lua-5.1/src/lauxlib.c index 6ab91b1..6f10514 100644 --- a/Engine/Source/lua-5.1/src/lauxlib.c +++ b/Engine/Source/lua-5.1/src/lauxlib.c @@ -40,6 +40,7 @@ */ +// VERIFY: 735b24c7 manual // OFFSET: 0x0084F8B0 LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { lua_Debug ar; @@ -71,6 +72,7 @@ static void tag_error (lua_State *L, int narg, int tag) { } +// VERIFY: 111b2cbe auto // OFFSET: 0x0084F210 LUALIB_API void luaL_where (lua_State *L, int level) { lua_Debug ar; @@ -85,6 +87,7 @@ LUALIB_API void luaL_where (lua_State *L, int level) { } +// VERIFY: 2eca12a3 auto // OFFSET: 0x0084F280 LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { va_list argp; @@ -99,6 +102,7 @@ LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { /* }====================================================== */ +// VERIFY: 8fb56037 manual // OFFSET: 0x0084FD20 LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, const char *const lst[]) { @@ -141,6 +145,7 @@ LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { } +// VERIFY: f73be098 auto // OFFSET: 0x0084F2C0 LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { if (!lua_checkstack(L, space)) @@ -148,6 +153,7 @@ LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { } +// VERIFY: b3741d1a auto // OFFSET: 0x0084F960 LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { if (lua_type(L, narg) != t) @@ -155,6 +161,7 @@ LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { } +// VERIFY: 5c5a9206 auto // OFFSET: 0x0084F9C0 LUALIB_API void luaL_checkany (lua_State *L, int narg) { if (lua_type(L, narg) == LUA_TNONE) @@ -162,6 +169,7 @@ LUALIB_API void luaL_checkany (lua_State *L, int narg) { } +// VERIFY: 7d5de109 auto // OFFSET: 0x0084F9F0 LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { const char *s = lua_tolstring(L, narg, len); @@ -170,6 +178,7 @@ LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { } +// VERIFY: 5c35a15c auto // OFFSET: 0x0084FA50 LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, const char *def, size_t *len) { @@ -182,6 +191,7 @@ LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, } +// VERIFY: fab9f901 auto // OFFSET: 0x0084FAB0 LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { lua_Number d = lua_tonumber(L, narg); @@ -191,12 +201,14 @@ LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { } +// VERIFY: 10f4d695 auto // OFFSET: 0x0084FB30 LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { return luaL_opt(L, luaL_checknumber, narg, def); } +// VERIFY: 46e7f2fb auto // OFFSET: 0x0084FB60 LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { lua_Integer d = lua_tointeger(L, narg); @@ -206,6 +218,7 @@ LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { } +// VERIFY: f10f816d auto // OFFSET: 0x0084FBD0 LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, lua_Integer def) { @@ -213,6 +226,7 @@ LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, } +// VERIFY: 2c2b0c47 auto // OFFSET: 0x0084F2F0 LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { if (!lua_getmetatable(L, obj)) /* no metatable? */ @@ -230,6 +244,7 @@ LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { } +// VERIFY: af6254c8 auto // OFFSET: 0x0084F350 LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { obj = abs_index(L, obj); @@ -241,6 +256,7 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { } +// VERIFY: 1076a79a auto // OFFSET: 0x0084FDD0 LUALIB_API void (luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l) { @@ -255,8 +271,9 @@ static int libsize (const luaL_Reg *l) { } +// VERIFY: 80058fda auto // OFFSET: 0x0084FC00 -LUALIB_API void luaI_openlib (lua_State *L, const char *libname, +LUALIB_API void luaL_openlib (lua_State *L, const char *libname, const luaL_Reg *l, int nup) { if (libname) { int size = libsize(l); @@ -371,6 +388,7 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, } +// VERIFY: 7043ef7a auto // OFFSET: 0x0084F3B0 LUALIB_API const char *luaL_findtable (lua_State *L, int idx, const char *fname, int szhint) { @@ -425,6 +443,7 @@ static int emptybuffer (luaL_Buffer *B) { } +// VERIFY: 89e6f1ce manual // OFFSET: 0x0084F4A0 static void adjuststack (luaL_Buffer *B) { if (B->lvl > 1) { @@ -445,6 +464,7 @@ static void adjuststack (luaL_Buffer *B) { } +// VERIFY: 463957b0 auto // OFFSET: 0x0084F520 LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { if (emptybuffer(B)) @@ -453,6 +473,7 @@ LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { } +// VERIFY: 1a52e632 auto // OFFSET: 0x0084F560 LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { while (l--) @@ -465,6 +486,7 @@ LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { } +// VERIFY: b50341f2 manual // OFFSET: 0x0084F5C0 LUALIB_API void luaL_pushresult (luaL_Buffer *B) { emptybuffer(B); @@ -473,6 +495,7 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B) { } +// VERIFY: 268646f6 auto // OFFSET: 0x0084F610 LUALIB_API void luaL_addvalue (luaL_Buffer *B) { lua_State *L = B->L; @@ -492,6 +515,7 @@ LUALIB_API void luaL_addvalue (luaL_Buffer *B) { } +// VERIFY: 9476c1a1 auto // OFFSET: 0x0084F6A0 LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { B->L = L; @@ -502,14 +526,21 @@ LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { /* }====================================================== */ +// VERIFY: 10f1b6cb auto // OFFSET: 0x0084F6C0 LUALIB_API int luaL_ref (lua_State *L, int t) { int ref; + int oldexpected; + const char *oldtaint; t = abs_index(L, t); if (lua_isnil(L, -1)) { lua_pop(L, 1); /* remove from stack */ return LUA_REFNIL; /* `nil' has a unique fixed reference */ } + oldexpected = lua_taintexpected; + oldtaint = lua_tainted; + lua_taintexpected = 0; + lua_tainted = NULL; lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ lua_pop(L, 1); /* remove it from stack */ @@ -522,18 +553,27 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { ref++; /* create new reference */ } lua_rawseti(L, t, ref); + lua_tainted = oldtaint; + lua_taintexpected = oldexpected; return ref; } +// VERIFY: ec4fdb20 manual // OFFSET: 0x0084F7A0 LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { if (ref >= 0) { + int oldexpected = lua_taintexpected; + const char *oldtaint = lua_tainted; + lua_taintexpected = 0; + lua_tainted = NULL; t = abs_index(L, t); lua_rawgeti(L, t, FREELIST_REF); lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ lua_pushinteger(L, ref); lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ + lua_tainted = oldtaint; + lua_taintexpected = oldexpected; } } @@ -623,6 +663,7 @@ typedef struct LoadS { } LoadS; +// VERIFY: b7671641 auto // OFFSET: 0x0084F830 static const char *getS (lua_State *L, void *ud, size_t *size) { LoadS *ls = (LoadS *)ud; @@ -634,10 +675,15 @@ static const char *getS (lua_State *L, void *ud, size_t *size) { } +// VERIFY: 0ba06999 auto // OFFSET: 0x0084F860 LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, const char *name) { LoadS ls; + if (size >= 3 && (unsigned char)buff[0] == 0xEF && (unsigned char)buff[1] == 0xBB && (unsigned char)buff[2] == 0xBF) { + buff += 3; + size -= 3; + } ls.s = buff; ls.size = size; return lua_load(L, getS, &ls, name); @@ -674,7 +720,7 @@ static int panic (lua_State *L) { LUALIB_API lua_State *luaL_newstate (void) { - lua_State *L = lua_newstate(l_alloc, NULL); + lua_State *L = lua_newstate(l_alloc, NULL, 0); if (L) lua_atpanic(L, &panic); return L; } diff --git a/Engine/Source/lua-5.1/src/lbaselib.c b/Engine/Source/lua-5.1/src/lbaselib.c index 4d142b7..5f304d6 100644 --- a/Engine/Source/lua-5.1/src/lbaselib.c +++ b/Engine/Source/lua-5.1/src/lbaselib.c @@ -28,28 +28,7 @@ ** model but changing `fputs' to put the strings at a proper place ** (a console window or a log file, for instance). */ -static int luaB_print (lua_State *L) { - int n = lua_gettop(L); /* number of arguments */ - int i; - lua_getglobal(L, "tostring"); - for (i=1; i<=n; i++) { - const char *s; - lua_pushvalue(L, -1); /* function to be called */ - lua_pushvalue(L, i); /* value to print */ - lua_call(L, 1, 1); - s = lua_tostring(L, -1); /* get result */ - if (s == NULL) - return luaL_error(L, LUA_QL("tostring") " must return a string to " - LUA_QL("print")); - if (i>1) fputs("\t", stdout); - fputs(s, stdout); - lua_pop(L, 1); /* pop result */ - } - fputs("\n", stdout); - return 0; -} - - +// VERIFY: 3c8229bb auto // OFFSET: 0x00854100 static int luaB_tonumber (lua_State *L) { int base = luaL_optint(L, 2, 10); @@ -79,6 +58,7 @@ static int luaB_tonumber (lua_State *L) { } +// VERIFY: 54d046ae auto // OFFSET: 0x00854210 static int luaB_error (lua_State *L) { int level = luaL_optint(L, 2, 1); @@ -92,6 +72,7 @@ static int luaB_error (lua_State *L) { } +// VERIFY: b50c4dbd auto // OFFSET: 0x00854270 static int luaB_getmetatable (lua_State *L) { luaL_checkany(L, 1); @@ -104,6 +85,7 @@ static int luaB_getmetatable (lua_State *L) { } +// VERIFY: ea9aabde auto // OFFSET: 0x008542C0 static int luaB_setmetatable (lua_State *L) { int t = lua_type(L, 2); @@ -118,6 +100,7 @@ static int luaB_setmetatable (lua_State *L) { } +// VERIFY: 4e03b9ba auto // OFFSET: 0x00854340 static void getfunc (lua_State *L) { if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); @@ -135,6 +118,7 @@ static void getfunc (lua_State *L) { } +// VERIFY: 9bb620ce auto // OFFSET: 0x008543E0 static int luaB_getfenv (lua_State *L) { getfunc(L); @@ -146,6 +130,7 @@ static int luaB_getfenv (lua_State *L) { } +// VERIFY: ad37b7cf auto // OFFSET: 0x00854430 static int luaB_setfenv (lua_State *L) { luaL_checktype(L, 2, LUA_TTABLE); @@ -165,6 +150,7 @@ static int luaB_setfenv (lua_State *L) { } +// VERIFY: 644cb64e auto // OFFSET: 0x008544D0 static int luaB_rawequal (lua_State *L) { luaL_checkany(L, 1); @@ -174,6 +160,7 @@ static int luaB_rawequal (lua_State *L) { } +// VERIFY: 5803d7fd auto // OFFSET: 0x00854510 static int luaB_rawget (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); @@ -183,6 +170,7 @@ static int luaB_rawget (lua_State *L) { return 1; } +// VERIFY: 2b21d651 auto // OFFSET: 0x00854550 static int luaB_rawset (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); @@ -194,6 +182,7 @@ static int luaB_rawset (lua_State *L) { } +// VERIFY: dc14cad0 auto // OFFSET: 0x00854590 static int luaB_gcinfo (lua_State *L) { lua_pushinteger(L, lua_getgccount(L)); @@ -201,6 +190,7 @@ static int luaB_gcinfo (lua_State *L) { } +// VERIFY: 6e948561 auto // OFFSET: 0x008545C0 static int luaB_collectgarbage (lua_State *L) { static const char *const opts[] = {"stop", "restart", "collect", @@ -228,6 +218,7 @@ static int luaB_collectgarbage (lua_State *L) { } +// VERIFY: 3b5d3cc8 auto // OFFSET: 0x00854660 static int luaB_type (lua_State *L) { luaL_checkany(L, 1); @@ -236,6 +227,7 @@ static int luaB_type (lua_State *L) { } +// VERIFY: c971adad auto // OFFSET: 0x00854690 static int luaB_next (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); @@ -249,6 +241,7 @@ static int luaB_next (lua_State *L) { } +// VERIFY: e90cf26c auto // OFFSET: 0x008546E0 static int luaB_pairs (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); @@ -259,6 +252,7 @@ static int luaB_pairs (lua_State *L) { } +// VERIFY: 7fdb7dfa auto // OFFSET: 0x00854720 static int ipairsaux (lua_State *L) { int i = luaL_checkint(L, 2); @@ -270,6 +264,7 @@ static int ipairsaux (lua_State *L) { } +// VERIFY: 899a16ea auto // OFFSET: 0x00854770 static int luaB_ipairs (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); @@ -291,6 +286,7 @@ static int load_aux (lua_State *L, int status) { } +// VERIFY: 434f2d35 auto // OFFSET: 0x008547B0 static int luaB_loadstring (lua_State *L) { size_t l; @@ -300,55 +296,13 @@ static int luaB_loadstring (lua_State *L) { } -static int luaB_loadfile (lua_State *L) { - const char *fname = luaL_optstring(L, 1, NULL); - return load_aux(L, luaL_loadfile(L, fname)); -} - - /* ** Reader for generic `load' function: `lua_load' uses the ** stack for internal stuff, so the reader cannot change the ** stack top. Instead, it keeps its resulting string in a ** reserved slot inside the stack. */ -static const char *generic_reader (lua_State *L, void *ud, size_t *size) { - (void)ud; /* to avoid warnings */ - luaL_checkstack(L, 2, "too many nested functions"); - lua_pushvalue(L, 1); /* get function */ - lua_call(L, 0, 1); /* call it */ - if (lua_isnil(L, -1)) { - *size = 0; - return NULL; - } - else if (lua_isstring(L, -1)) { - lua_replace(L, 3); /* save string in a reserved stack slot */ - return lua_tolstring(L, 3, size); - } - else luaL_error(L, "reader function must return a string"); - return NULL; /* to avoid warnings */ -} - - -static int luaB_load (lua_State *L) { - int status; - const char *cname = luaL_optstring(L, 2, "=(load)"); - luaL_checktype(L, 1, LUA_TFUNCTION); - lua_settop(L, 3); /* function, eventual name, plus one reserved slot */ - status = lua_load(L, generic_reader, NULL, cname); - return load_aux(L, status); -} - - -static int luaB_dofile (lua_State *L) { - const char *fname = luaL_optstring(L, 1, NULL); - int n = lua_gettop(L); - if (luaL_loadfile(L, fname) != 0) lua_error(L); - lua_call(L, 0, LUA_MULTRET); - return lua_gettop(L) - n; -} - - +// VERIFY: ebcb532b auto // OFFSET: 0x00854810 static int luaB_assert (lua_State *L) { luaL_checkany(L, 1); @@ -358,6 +312,7 @@ static int luaB_assert (lua_State *L) { } +// VERIFY: 164ddea6 auto // OFFSET: 0x00854860 static int luaB_unpack (lua_State *L) { int i, e, n; @@ -373,6 +328,7 @@ static int luaB_unpack (lua_State *L) { } +// VERIFY: afedc8d2 manual // OFFSET: 0x008548F0 static int luaB_select (lua_State *L) { int n = lua_gettop(L); @@ -390,6 +346,7 @@ static int luaB_select (lua_State *L) { } +// VERIFY: 9ed031d0 auto // OFFSET: 0x00854980 static int luaB_pcall (lua_State *L) { int status; @@ -401,6 +358,7 @@ static int luaB_pcall (lua_State *L) { } +// VERIFY: 94aee231 auto // OFFSET: 0x008549D0 static int luaB_xpcall (lua_State *L) { int status; @@ -414,6 +372,7 @@ static int luaB_xpcall (lua_State *L) { } +// VERIFY: 5f2f55da auto // OFFSET: 0x00854A20 static int luaB_tostring (lua_State *L) { luaL_checkany(L, 1); @@ -440,6 +399,7 @@ static int luaB_tostring (lua_State *L) { } +// VERIFY: 8f89d889 auto // OFFSET: 0x00854B20 static int luaB_newproxy (lua_State *L) { lua_settop(L, 1); @@ -470,17 +430,13 @@ static int luaB_newproxy (lua_State *L) { static const luaL_Reg base_funcs[] = { {"assert", luaB_assert}, {"collectgarbage", luaB_collectgarbage}, - {"dofile", luaB_dofile}, {"error", luaB_error}, {"gcinfo", luaB_gcinfo}, {"getfenv", luaB_getfenv}, {"getmetatable", luaB_getmetatable}, - {"loadfile", luaB_loadfile}, - {"load", luaB_load}, {"loadstring", luaB_loadstring}, {"next", luaB_next}, {"pcall", luaB_pcall}, - {"print", luaB_print}, {"rawequal", luaB_rawequal}, {"rawget", luaB_rawget}, {"rawset", luaB_rawset}, @@ -502,6 +458,7 @@ static const luaL_Reg base_funcs[] = { ** ======================================================= */ +// VERIFY: 432e452a auto // OFFSET: 0x00854C00 static int auxresume (lua_State *L, lua_State *co, int narg) { int status; @@ -527,6 +484,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) { } +// VERIFY: f90b2a6d manual // OFFSET: 0x00854CB0 static int luaB_coresume (lua_State *L) { lua_State *co = lua_tothread(L, 1); @@ -546,6 +504,7 @@ static int luaB_coresume (lua_State *L) { } +// VERIFY: 4d8cf541 auto // OFFSET: 0x00854D30 static int luaB_auxwrap (lua_State *L) { lua_State *co = lua_tothread(L, lua_upvalueindex(1)); @@ -562,6 +521,7 @@ static int luaB_auxwrap (lua_State *L) { } +// VERIFY: 5058c77f auto // OFFSET: 0x00854DA0 static int luaB_cocreate (lua_State *L) { lua_State *NL = lua_newthread(L); @@ -573,6 +533,7 @@ static int luaB_cocreate (lua_State *L) { } +// VERIFY: a091d708 auto // OFFSET: 0x00854E00 static int luaB_cowrap (lua_State *L) { luaB_cocreate(L); @@ -581,12 +542,14 @@ static int luaB_cowrap (lua_State *L) { } +// VERIFY: 7765fcfb auto // OFFSET: 0x00854E30 static int luaB_yield (lua_State *L) { return lua_yield(L, lua_gettop(L)); } +// VERIFY: a53a83f9 auto // OFFSET: 0x00854E50 static int luaB_costatus (lua_State *L) { lua_State *co = lua_tothread(L, 1); @@ -616,6 +579,7 @@ static int luaB_costatus (lua_State *L) { } +// VERIFY: 07aecc61 auto // OFFSET: 0x00854F20 static int luaB_corunning (lua_State *L) { if (lua_pushthread(L)) @@ -646,6 +610,7 @@ static void auxopen (lua_State *L, const char *name, } +// VERIFY: b222b118 auto // OFFSET: 0x00854F40 static void base_open (lua_State *L) { /* set global _G */ @@ -669,6 +634,7 @@ static void base_open (lua_State *L) { } +// VERIFY: 44afe790 auto // OFFSET: 0x00855060 LUALIB_API int luaopen_base (lua_State *L) { base_open(L); diff --git a/Engine/Source/lua-5.1/src/lbitlib.c b/Engine/Source/lua-5.1/src/lbitlib.c new file mode 100644 index 0000000..dc0b263 --- /dev/null +++ b/Engine/Source/lua-5.1/src/lbitlib.c @@ -0,0 +1,112 @@ +#define lbitlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +typedef int Integer; +typedef unsigned int UInteger; + + +// VERIFY: d6a77d71 manual +// OFFSET: 0x00850CC0 +static int bit_bnot (lua_State *L) { + lua_pushnumber(L, (UInteger)~(Integer)luaL_checknumber(L, 1)); + return 1; +} + + +// VERIFY: e75ae7e6 manual +// OFFSET: 0x00850D00 +static int bit_band (lua_State *L) { + int n = lua_gettop(L), i; + UInteger w = (Integer)luaL_checknumber(L, 1); + for (i = 2; i <= n; i++) + w &= (Integer)luaL_checknumber(L, i); + lua_pushnumber(L, w); + return 1; +} + + +// VERIFY: 2eb41a74 manual +// OFFSET: 0x00850D80 +static int bit_bor (lua_State *L) { + int n = lua_gettop(L), i; + UInteger w = (Integer)luaL_checknumber(L, 1); + for (i = 2; i <= n; i++) + w |= (Integer)luaL_checknumber(L, i); + lua_pushnumber(L, w); + return 1; +} + + +// VERIFY: 6aea1192 manual +// OFFSET: 0x00850E00 +static int bit_bxor (lua_State *L) { + int n = lua_gettop(L), i; + UInteger w = (Integer)luaL_checknumber(L, 1); + for (i = 2; i <= n; i++) + w ^= (Integer)luaL_checknumber(L, i); + lua_pushnumber(L, w); + return 1; +} + + +// VERIFY: 5453693c auto +// OFFSET: 0x00850E80 +static int bit_lshift (lua_State *L) { + lua_pushnumber(L, (UInteger)((Integer)luaL_checknumber(L, 1) << (UInteger)luaL_checknumber(L, 2))); + return 1; +} + + +// VERIFY: 99a627b4 auto +// OFFSET: 0x00850EE0 +static int bit_rshift (lua_State *L) { + lua_pushnumber(L, (Integer)((UInteger)luaL_checknumber(L, 1) >> (UInteger)luaL_checknumber(L, 2))); + return 1; +} + + +// VERIFY: b56ebf4a auto +// OFFSET: 0x00850F40 +static int bit_arshift (lua_State *L) { + lua_pushnumber(L, (Integer)luaL_checknumber(L, 1) >> (UInteger)luaL_checknumber(L, 2)); + return 1; +} + + +// VERIFY: 8e98a529 auto +// OFFSET: 0x00850F90 +static int bit_mod (lua_State *L) { + if ((Integer)luaL_checknumber(L, 2) == 0) { + lua_pushnumber(L, 1 / lua_tonumber(L, 2)); + return 1; + } + lua_pushnumber(L, (Integer)luaL_checknumber(L, 1) % (Integer)luaL_checknumber(L, 2)); + return 1; +} + + +static const struct luaL_Reg bitlib[] = { + {"bnot", bit_bnot}, + {"band", bit_band}, + {"bor", bit_bor}, + {"bxor", bit_bxor}, + {"lshift", bit_lshift}, + {"rshift", bit_rshift}, + {"arshift", bit_arshift}, + {"mod", bit_mod}, + {NULL, NULL} +}; + + +// VERIFY: 23d41808 auto +// OFFSET: 0x00851010 +LUALIB_API int luaopen_bit (lua_State *L) { + luaL_openlib(L, "bit", bitlib, 0); + return 1; +} diff --git a/Engine/Source/lua-5.1/src/lcode.c b/Engine/Source/lua-5.1/src/lcode.c index 7f45fab..fe9d100 100644 --- a/Engine/Source/lua-5.1/src/lcode.c +++ b/Engine/Source/lua-5.1/src/lcode.c @@ -32,6 +32,7 @@ static int isnumeral(expdesc *e) { } +// VERIFY: 8c718947 manual // OFFSET: 0x00862560 void luaK_nil (FuncState *fs, int from, int n) { Instruction *previous; @@ -52,6 +53,7 @@ void luaK_nil (FuncState *fs, int from, int n) { } +// VERIFY: d187736c auto // OFFSET: 0x008625F0 int luaK_jump (FuncState *fs) { int jpc = fs->jpc; /* save list of jumps to here */ @@ -63,12 +65,14 @@ int luaK_jump (FuncState *fs) { } +// VERIFY: 8f9b3ba3 auto // OFFSET: 0x00862630 void luaK_ret (FuncState *fs, int first, int nret) { luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); } +// VERIFY: 4a040e1a auto // OFFSET: 0x00862660 static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { luaK_codeABC(fs, op, A, B, C); @@ -76,6 +80,7 @@ static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { } +// VERIFY: f960c59e manual // OFFSET: 0x00861BD0 static void fixjump (FuncState *fs, int pc, int dest) { Instruction *jmp = &fs->f->code[pc]; @@ -91,6 +96,7 @@ static void fixjump (FuncState *fs, int pc, int dest) { ** returns current `pc' and marks it as a jump target (to avoid wrong ** optimizations with consecutive instructions not in the same basic block). */ +// VERIFY: ee5813e1 auto // OFFSET: 0x00861C20 int luaK_getlabel (FuncState *fs) { fs->lasttarget = fs->pc; @@ -120,6 +126,7 @@ static Instruction *getjumpcontrol (FuncState *fs, int pc) { ** check whether list has any jump that do not produce a value ** (or produce an inverted value) */ +// VERIFY: 2ac2d46e manual // OFFSET: 0x00861C30 static int need_value (FuncState *fs, int list) { for (; list != NO_JUMP; list = getjump(fs, list)) { @@ -130,6 +137,7 @@ static int need_value (FuncState *fs, int list) { } +// VERIFY: aaaf7383 manual // OFFSET: 0x00861C90 static int patchtestreg (FuncState *fs, int node, int reg) { Instruction *i = getjumpcontrol(fs, node); @@ -144,6 +152,7 @@ static int patchtestreg (FuncState *fs, int node, int reg) { } +// VERIFY: f2c498fd manual // OFFSET: 0x00861D10 static void removevalues (FuncState *fs, int list) { for (; list != NO_JUMP; list = getjump(fs, list)) @@ -151,6 +160,7 @@ static void removevalues (FuncState *fs, int list) { } +// VERIFY: bbd781fb manual // OFFSET: 0x00861D90 static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, int dtarget) { @@ -171,6 +181,7 @@ static void dischargejpc (FuncState *fs) { } +// VERIFY: 35e07c09 auto // OFFSET: 0x00863580 void luaK_patchlist (FuncState *fs, int list, int target) { if (target == fs->pc) @@ -182,6 +193,7 @@ void luaK_patchlist (FuncState *fs, int list, int target) { } +// VERIFY: 04fba2ce auto // OFFSET: 0x008626C0 void luaK_patchtohere (FuncState *fs, int list) { luaK_getlabel(fs); @@ -189,6 +201,7 @@ void luaK_patchtohere (FuncState *fs, int list) { } +// VERIFY: 42c88f48 manual // OFFSET: 0x00861E80 void luaK_concat (FuncState *fs, int *l1, int l2) { if (l2 == NO_JUMP) return; @@ -204,6 +217,7 @@ void luaK_concat (FuncState *fs, int *l1, int l2) { } +// VERIFY: 41234f35 auto // OFFSET: 0x00861ED0 void luaK_checkstack (FuncState *fs, int n) { int newstack = fs->freereg + n; @@ -215,6 +229,7 @@ void luaK_checkstack (FuncState *fs, int n) { } +// VERIFY: 8c95cb3a auto // OFFSET: 0x00861F10 void luaK_reserveregs (FuncState *fs, int n) { luaK_checkstack(fs, n); @@ -230,6 +245,7 @@ static void freereg (FuncState *fs, int reg) { } +// VERIFY: de6895df manual // OFFSET: 0x00861F60 static void freeexp (FuncState *fs, expdesc *e) { if (e->k == VNONRELOC) @@ -237,6 +253,7 @@ static void freeexp (FuncState *fs, expdesc *e) { } +// VERIFY: 1044a561 manual // OFFSET: 0x00861F80 static int addk (FuncState *fs, TValue *k, TValue *v) { lua_State *L = fs->L; @@ -259,6 +276,7 @@ static int addk (FuncState *fs, TValue *k, TValue *v) { } +// VERIFY: 681dc2cd auto // OFFSET: 0x008620B0 int luaK_stringK (FuncState *fs, TString *s) { TValue o; @@ -267,6 +285,7 @@ int luaK_stringK (FuncState *fs, TString *s) { } +// VERIFY: 2b0cffc4 auto // OFFSET: 0x008620F0 int luaK_numberK (FuncState *fs, lua_Number r) { TValue o; @@ -282,6 +301,7 @@ static int boolK (FuncState *fs, int b) { } +// VERIFY: bdad03ad auto // OFFSET: 0x00862120 static int nilK (FuncState *fs) { TValue k, v; @@ -292,6 +312,7 @@ static int nilK (FuncState *fs) { } +// VERIFY: 333ac0e8 manual // OFFSET: 0x00862160 void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { if (e->k == VCALL) { /* expression is an open function call? */ @@ -305,6 +326,7 @@ void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { } +// VERIFY: 7e16673e manual // OFFSET: 0x008621F0 void luaK_setoneret (FuncState *fs, expdesc *e) { if (e->k == VCALL) { /* expression is an open function call? */ @@ -318,6 +340,7 @@ void luaK_setoneret (FuncState *fs, expdesc *e) { } +// VERIFY: b0575d43 manual // OFFSET: 0x008626E0 void luaK_dischargevars (FuncState *fs, expdesc *e) { switch (e->k) { @@ -358,6 +381,7 @@ static int code_label (FuncState *fs, int A, int b, int jump) { } +// VERIFY: b5ebdba4 auto // OFFSET: 0x008627F0 static void discharge2reg (FuncState *fs, expdesc *e, int reg) { luaK_dischargevars(fs, e); @@ -398,6 +422,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { } +// VERIFY: fa6e18a0 manual // OFFSET: 0x00862900 static void discharge2anyreg (FuncState *fs, expdesc *e) { if (e->k != VNONRELOC) { @@ -407,6 +432,7 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) { } +// VERIFY: 01b6b34c manual // OFFSET: 0x00862960 static void exp2reg (FuncState *fs, expdesc *e, int reg) { discharge2reg(fs, e, reg); @@ -432,6 +458,7 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) { } +// VERIFY: 34225265 auto // OFFSET: 0x00862A80 void luaK_exp2nextreg (FuncState *fs, expdesc *e) { luaK_dischargevars(fs, e); @@ -441,6 +468,7 @@ void luaK_exp2nextreg (FuncState *fs, expdesc *e) { } +// VERIFY: 2fecfa03 auto // OFFSET: 0x00862B00 int luaK_exp2anyreg (FuncState *fs, expdesc *e) { luaK_dischargevars(fs, e); @@ -456,6 +484,7 @@ int luaK_exp2anyreg (FuncState *fs, expdesc *e) { } +// VERIFY: 34ac168e manual // OFFSET: 0x00862B60 void luaK_exp2val (FuncState *fs, expdesc *e) { if (hasjumps(e)) @@ -465,6 +494,7 @@ void luaK_exp2val (FuncState *fs, expdesc *e) { } +// VERIFY: 9f85b055 manual // OFFSET: 0x00862B90 int luaK_exp2RK (FuncState *fs, expdesc *e) { luaK_exp2val(fs, e); @@ -494,6 +524,7 @@ int luaK_exp2RK (FuncState *fs, expdesc *e) { } +// VERIFY: 76cc100f auto // OFFSET: 0x00862C90 void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { switch (var->k) { @@ -526,6 +557,7 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { } +// VERIFY: 4de34d28 manual // OFFSET: 0x00862D80 void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { int func; @@ -540,6 +572,7 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { } +// VERIFY: c3e85005 manual // OFFSET: 0x00862250 static void invertjump (FuncState *fs, expdesc *e) { Instruction *pc = getjumpcontrol(fs, e->u.s.info); @@ -549,6 +582,7 @@ static void invertjump (FuncState *fs, expdesc *e) { } +// VERIFY: 87e22859 manual // OFFSET: 0x00862E40 static int jumponcond (FuncState *fs, expdesc *e, int cond) { if (e->k == VRELOCABLE) { @@ -565,6 +599,7 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) { } +// VERIFY: d33da7b7 auto // OFFSET: 0x00862EC0 void luaK_goiftrue (FuncState *fs, expdesc *e) { int pc; /* pc of last jump */ @@ -621,6 +656,7 @@ static void luaK_goiffalse (FuncState *fs, expdesc *e) { } +// VERIFY: bfe8eeff manual // OFFSET: 0x00863000 static void codenot (FuncState *fs, expdesc *e) { luaK_dischargevars(fs, e); @@ -657,6 +693,7 @@ static void codenot (FuncState *fs, expdesc *e) { } +// VERIFY: 6c1cba86 auto // OFFSET: 0x008630C0 void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { t->u.s.aux = luaK_exp2RK(fs, k); @@ -664,6 +701,7 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { } +// VERIFY: 52e3eaa2 manual // OFFSET: 0x008622A0 static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { lua_Number v1, v2, r; @@ -691,6 +729,7 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { } +// VERIFY: 3e9ac097 manual // OFFSET: 0x008630F0 static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { if (constfolding(op, e1, e2)) @@ -706,6 +745,7 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { } +// VERIFY: e82a615a manual // OFFSET: 0x008631B0 static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, expdesc *e2) { @@ -723,6 +763,7 @@ static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, } +// VERIFY: 9446e65a auto // OFFSET: 0x00863250 void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { expdesc e2; @@ -745,6 +786,7 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { } +// VERIFY: 9154c607 manual // OFFSET: 0x008632E0 void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { switch (op) { @@ -768,6 +810,7 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { } +// VERIFY: c96ef1d8 manual // OFFSET: 0x00863350 void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { switch (op) { @@ -816,12 +859,14 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { } +// VERIFY: 2fc89dfa auto // OFFSET: 0x00862390 void luaK_fixline (FuncState *fs, int line) { fs->f->lineinfo[fs->pc - 1] = line; } +// VERIFY: 4518ae3a manual // OFFSET: 0x008623B0 static int luaK_code (FuncState *fs, Instruction i, int line) { Proto *f = fs->f; @@ -838,6 +883,7 @@ static int luaK_code (FuncState *fs, Instruction i, int line) { } +// VERIFY: 421f8541 auto // OFFSET: 0x00862460 int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { lua_assert(getOpMode(o) == iABC); @@ -847,6 +893,7 @@ int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { } +// VERIFY: bc316280 auto // OFFSET: 0x00862490 int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); @@ -855,6 +902,7 @@ int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { } +// VERIFY: d614b3eb manual // OFFSET: 0x008624C0 void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; diff --git a/Engine/Source/lua-5.1/src/ldebug.c b/Engine/Source/lua-5.1/src/ldebug.c index 73f5701..a7eede4 100644 --- a/Engine/Source/lua-5.1/src/ldebug.c +++ b/Engine/Source/lua-5.1/src/ldebug.c @@ -41,6 +41,7 @@ static int currentpc (lua_State *L, CallInfo *ci) { } +// VERIFY: 798feef7 auto // OFFSET: 0x0084FDF0 static int currentline (lua_State *L, CallInfo *ci) { int pc = currentpc(L, ci); @@ -82,6 +83,7 @@ LUA_API int lua_gethookcount (lua_State *L) { } +// VERIFY: 04595f21 auto // OFFSET: 0x0084FE40 LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { int status; @@ -111,6 +113,7 @@ static Proto *getluaproto (CallInfo *ci) { } +// VERIFY: 28a2e081 auto // OFFSET: 0x0084FEC0 static const char *findlocal (lua_State *L, CallInfo *ci, int n) { const char *name; @@ -127,6 +130,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n) { } +// VERIFY: f61d8da8 auto // OFFSET: 0x0084FF30 LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { CallInfo *ci = L->base_ci + ar->i_ci; @@ -151,6 +155,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { } +// VERIFY: 436034fc manual // OFFSET: 0x0084FF80 static void funcinfo (lua_Debug *ar, Closure *cl) { if (cl->c.isC) { @@ -179,6 +184,7 @@ static void info_tailcall (lua_Debug *ar) { } +// VERIFY: 67c79abf auto // OFFSET: 0x00850000 static void collectvalidlines (lua_State *L, Closure *f) { if (f == NULL || f->c.isC) { @@ -196,6 +202,7 @@ static void collectvalidlines (lua_State *L, Closure *f) { } +// VERIFY: ade29135 manual // OFFSET: 0x00850950 static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, Closure *f, CallInfo *ci) { @@ -236,6 +243,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, } +// VERIFY: ab0f6a89 manual // OFFSET: 0x00850A90 LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { int status; @@ -256,7 +264,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { } status = auxgetinfo(L, what, ar, f, ci); if (strchr(what, 'f')) { - if (f == NULL) setnilvalue(L->top); + if (f == NULL) { setnilvalue(L->top); } else setclvalue(L, L->top, f); incr_top(L); } @@ -295,6 +303,7 @@ static int precheck (const Proto *pt) { #define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) +// VERIFY: 0f00de52 manual // OFFSET: 0x008500B0 int luaG_checkopenop (Instruction i) { switch (GET_OPCODE(i)) { @@ -310,6 +319,7 @@ int luaG_checkopenop (Instruction i) { } +// VERIFY: 0c4dc1b7 auto // OFFSET: 0x008500E0 static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { switch (mode) { @@ -324,6 +334,7 @@ static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { } +// VERIFY: f11df706 manual // OFFSET: 0x00850130 static Instruction symbexec (const Proto *pt, int lastpc, int reg) { int pc; @@ -479,6 +490,7 @@ int luaG_checkcode (const Proto *pt) { } +// VERIFY: 7672832d auto // OFFSET: 0x00850570 static const char *kname (Proto *p, int c) { if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) @@ -488,6 +500,7 @@ static const char *kname (Proto *p, int c) { } +// VERIFY: e0094cee manual // OFFSET: 0x008505A0 static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, const char **name) { @@ -536,6 +549,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, } +// VERIFY: 213bbc04 manual // OFFSET: 0x00850720 static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { Instruction i; @@ -560,6 +574,7 @@ static int isinstack (CallInfo *ci, const TValue *o) { } +// VERIFY: 86d0d989 auto // OFFSET: 0x00850B60 void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { const char *name = NULL; @@ -575,6 +590,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { } +// VERIFY: 9514a4be auto // OFFSET: 0x00850BF0 void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { if (ttisstring(p1)) p1 = p2; @@ -583,6 +599,7 @@ void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { } +// VERIFY: bef69465 auto // OFFSET: 0x00850C20 void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { TValue temp; @@ -592,6 +609,7 @@ void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { } +// VERIFY: 36b4bf1c auto // OFFSET: 0x00850C60 int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { const char *t1 = luaT_typenames[ttype(p1)]; @@ -604,6 +622,7 @@ int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { } +// VERIFY: 8ec78b46 manual // OFFSET: 0x008507C0 static void addinfo (lua_State *L, const char *msg) { CallInfo *ci = L->ci; @@ -616,6 +635,7 @@ static void addinfo (lua_State *L, const char *msg) { } +// VERIFY: f631dd92 manual // OFFSET: 0x00850830 void luaG_errormsg (lua_State *L) { if (L->errfunc != 0) { /* is there an error handling function? */ @@ -630,6 +650,7 @@ void luaG_errormsg (lua_State *L) { } +// VERIFY: 67b86ee1 auto // OFFSET: 0x00850920 void luaG_runerror (lua_State *L, const char *fmt, ...) { va_list argp; diff --git a/Engine/Source/lua-5.1/src/ldo.c b/Engine/Source/lua-5.1/src/ldo.c index b4d62fd..89e059b 100644 --- a/Engine/Source/lua-5.1/src/ldo.c +++ b/Engine/Source/lua-5.1/src/ldo.c @@ -30,6 +30,9 @@ #include "lvm.h" #include "lzio.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include "Engine/Source/Os/TimeManager.h" + @@ -48,6 +51,7 @@ struct lua_longjmp { }; +// VERIFY: 0e03a5bb manual // OFFSET: 0x00855A20 void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { switch (errcode) { @@ -79,6 +83,7 @@ static void restore_stack_limit (lua_State *L) { } +// VERIFY: e408654f auto // OFFSET: 0x00856260 static void resetstack (lua_State *L, int status) { L->ci = L->base_ci; @@ -93,6 +98,7 @@ static void resetstack (lua_State *L, int status) { } +// VERIFY: 8957ae9c auto // OFFSET: 0x008562E0 void luaD_throw (lua_State *L, int errcode) { if (L->errorJmp) { @@ -111,12 +117,14 @@ void luaD_throw (lua_State *L, int errcode) { } +// VERIFY: c7d35834 auto // OFFSET: 0x00855AF0 int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { struct lua_longjmp lj; lj.status = 0; lj.previous = L->errorJmp; /* chain new error handler */ L->errorJmp = &lj; + FrameScript_InvalidPtrCheck((const void *)f); LUAI_TRY(L, &lj, (*f)(L, ud); ); @@ -142,6 +150,7 @@ static void correctstack (lua_State *L, TValue *oldstack) { } +// VERIFY: 37ce7719 manual // OFFSET: 0x00855BF0 void luaD_reallocstack (lua_State *L, int newsize) { TValue *oldstack = L->stack; @@ -154,6 +163,7 @@ void luaD_reallocstack (lua_State *L, int newsize) { } +// VERIFY: e5041c0f manual // OFFSET: 0x00855C50 void luaD_reallocCI (lua_State *L, int newsize) { CallInfo *oldci = L->base_ci; @@ -164,6 +174,7 @@ void luaD_reallocCI (lua_State *L, int newsize) { } +// VERIFY: 4edceb53 manual // OFFSET: 0x00855CD0 void luaD_growstack (lua_State *L, int n) { if (n <= L->stacksize) /* double size is enough? */ @@ -173,6 +184,7 @@ void luaD_growstack (lua_State *L, int n) { } +// VERIFY: afeb0acc manual // OFFSET: 0x00856330 static CallInfo *growCI (lua_State *L) { if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ @@ -186,6 +198,7 @@ static CallInfo *growCI (lua_State *L) { } +// VERIFY: 0ee10297 auto // OFFSET: 0x00855D00 void luaD_callhook (lua_State *L, int event, int line) { lua_Hook hook = L->hook; @@ -204,6 +217,7 @@ void luaD_callhook (lua_State *L, int event, int line) { lua_assert(L->ci->top <= L->stack_last); L->allowhook = 0; /* cannot call hooks inside a hook */ lua_unlock(L); + FrameScript_InvalidPtrCheck((const void *)hook); (*hook)(L, &ar); lua_lock(L); lua_assert(!L->allowhook); @@ -214,6 +228,7 @@ void luaD_callhook (lua_State *L, int event, int line) { } +// VERIFY: 73cffd33 manual // OFFSET: 0x00855DE0 static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { int i; @@ -250,6 +265,7 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { } +// VERIFY: d1e9a88d manual // OFFSET: 0x00855EA0 static StkId tryfuncTM (lua_State *L, StkId func) { const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); @@ -272,6 +288,7 @@ static StkId tryfuncTM (lua_State *L, StkId func) { (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) +// VERIFY: b51b12b5 auto // OFFSET: 0x00856370 int luaD_precall (lua_State *L, StkId func, int nresults) { LClosure *cl; @@ -318,6 +335,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { else { /* if is a C function, call it */ CallInfo *ci; int n; + lua_CFunction f; luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ ci = inc_ci(L); /* now `enter' new function */ ci->func = restorestack(L, funcr); @@ -328,7 +346,9 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { if (L->hookmask & LUA_MASKCALL) luaD_callhook(L, LUA_HOOKCALL, -1); lua_unlock(L); - n = (*curr_func(L)->c.f)(L); /* do the actual call */ + f = curr_func(L)->c.f; + FrameScript_InvalidPtrCheck((const void *)f); + n = (*f)(L); /* do the actual call */ lua_lock(L); if (n < 0) /* yielding? */ return PCRYIELD; @@ -340,6 +360,83 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { } +// VERIFY: beb28cc5 auto +// OFFSET: 0x00856550 +int luaD_precall_profile (lua_State *L, StkId func, int nresults, __int64 start, __int64 *stop) { + LClosure *cl; + ptrdiff_t funcr; + if (!ttisfunction(func)) /* `func' is not a function? */ + func = tryfuncTM(L, func); /* check the `function' tag method */ + funcr = savestack(L, func); + cl = &clvalue(func)->l; + cl->profile->calls++; + L->ci->savedpc = L->savedpc; + if (!cl->isC) { /* Lua function? prepare its call */ + CallInfo *ci; + StkId st, base; + Proto *p = cl->p; + luaD_checkstack(L, p->maxstacksize); + func = restorestack(L, funcr); + if (!p->is_vararg) { /* no varargs? */ + base = func + 1; + if (L->top > base + p->numparams) + L->top = base + p->numparams; + } + else { /* vararg function */ + int nargs = cast_int(L->top - func) - 1; + base = adjust_varargs(L, p, nargs); + func = restorestack(L, funcr); /* previous call may change the stack */ + } + ci = inc_ci(L); /* now `enter' new function */ + ci->func = func; + L->base = ci->base = base; + ci->top = L->base + p->maxstacksize; + lua_assert(ci->top <= L->stack_last); + L->savedpc = p->code; /* starting point */ + ci->tailcalls = 0; + ci->nresults = nresults; + for (st = L->top; st < ci->top; st++) + setnilvalue(st); + L->top = ci->top; + if (L->hookmask & LUA_MASKCALL) { + L->savedpc++; /* hooks assume 'pc' is already incremented */ + luaD_callhook(L, LUA_HOOKCALL, -1); + L->savedpc--; /* correct 'pc' */ + } + return PCRLUA; + } + else { /* if is a C function, call it */ + CallInfo *ci; + int n; + lua_CFunction f; + luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ + ci = inc_ci(L); /* now `enter' new function */ + ci->func = restorestack(L, funcr); + L->base = ci->base = ci->func + 1; + ci->top = L->top + LUA_MINSTACK; + lua_assert(ci->top <= L->stack_last); + ci->nresults = nresults; + if (L->hookmask & LUA_MASKCALL) + luaD_callhook(L, LUA_HOOKCALL, -1); + lua_unlock(L); + f = curr_func(L)->c.f; + FrameScript_InvalidPtrCheck((const void *)f); + n = (*f)(L); /* do the actual call */ + *stop = OsGetAsyncTimeClocks(); + cl->profile->time += *stop - start; + cl->profile->totaltime += *stop - start; + lua_lock(L); + if (n < 0) /* yielding? */ + return PCRYIELD; + else { + luaD_poscall(L, L->top - n); + return PCRC; + } + } +} + + +// VERIFY: 97564eed auto // OFFSET: 0x00855FB0 static StkId callrethooks (lua_State *L, StkId firstResult) { ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ @@ -352,6 +449,7 @@ static StkId callrethooks (lua_State *L, StkId firstResult) { } +// VERIFY: 87765791 auto // OFFSET: 0x00856010 int luaD_poscall (lua_State *L, StkId firstResult) { StkId res; @@ -380,6 +478,7 @@ int luaD_poscall (lua_State *L, StkId firstResult) { ** When returns, all the results are on the stack, starting at the original ** function position. */ +// VERIFY: 627d4e86 manual // OFFSET: 0x00856760 void luaD_call (lua_State *L, StkId func, int nResults) { if (++L->nCcalls >= LUAI_MAXCCALLS) { @@ -388,20 +487,31 @@ void luaD_call (lua_State *L, StkId func, int nResults) { else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ } - if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ + if (G(L)->profile) { + __int64 stop; + if (luaD_precall_profile(L, func, nResults, OsGetAsyncTimeClocks(), &stop) == PCRLUA) + luaV_execute_profile(L, 1); + } + else if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ luaV_execute(L, 1); /* call it */ L->nCcalls--; luaC_checkGC(L); } +// VERIFY: 03ff921d auto // OFFSET: 0x00856810 static void resume (lua_State *L, void *ud) { StkId firstArg = cast(StkId, ud); CallInfo *ci = L->ci; if (L->status == 0) { /* start coroutine? */ lua_assert(ci == L->base_ci && firstArg > L->base); - if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) + if (G(L)->profile) { + __int64 stop; + if (luaD_precall_profile(L, firstArg - 1, LUA_MULTRET, OsGetAsyncTimeClocks(), &stop) != PCRLUA) + return; + } + else if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) return; } else { /* resuming from previous yield */ @@ -417,10 +527,14 @@ static void resume (lua_State *L, void *ud) { else /* yielded inside a hook: just continue its execution */ L->base = L->ci->base; } - luaV_execute(L, cast_int(L->ci - L->base_ci)); + if (G(L)->profile) + luaV_execute_profile(L, cast_int(L->ci - L->base_ci)); + else + luaV_execute(L, cast_int(L->ci - L->base_ci)); } +// VERIFY: bdb23f63 auto // OFFSET: 0x008560E0 static int resume_error (lua_State *L, const char *msg) { L->top = L->ci->base; @@ -431,6 +545,7 @@ static int resume_error (lua_State *L, const char *msg) { } +// VERIFY: a1bbc7c1 auto // OFFSET: 0x008568F0 LUA_API int lua_resume (lua_State *L, int nargs) { int status; @@ -456,6 +571,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { } +// VERIFY: e347b86d auto // OFFSET: 0x00856150 LUA_API int lua_yield (lua_State *L, int nresults) { luai_userstateyield(L, nresults); @@ -469,6 +585,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) { } +// VERIFY: 52adf63b auto // OFFSET: 0x00856970 int luaD_pcall (lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, ptrdiff_t ef) { @@ -481,6 +598,14 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, status = luaD_rawrunprotected(L, func, u); if (status != 0) { /* an error occurred? */ StkId oldtop = restorestack(L, old_top); + if (G(L)->profile) { + CallInfo *ci = L->ci; + while (ci > restoreci(L, old_ci) + 1) { + ci--; + if (isLua(ci)) + clvalue(ci->func)->l.profile->depth--; + } + } luaF_close(L, oldtop); /* close eventual pending closures */ luaD_seterrorobj(L, status, oldtop); L->nCcalls = oldnCcalls; @@ -489,6 +614,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, L->savedpc = L->ci->savedpc; L->allowhook = old_allowhooks; restore_stack_limit(L); + lua_taintedclosure = 0; } L->errfunc = old_errfunc; return status; @@ -505,16 +631,15 @@ struct SParser { /* data to `f_parser' */ const char *name; }; +// VERIFY: 038b3c71 manual // OFFSET: 0x00856190 static void f_parser (lua_State *L, void *ud) { int i; Proto *tf; Closure *cl; struct SParser *p = cast(struct SParser *, ud); - int c = luaZ_lookahead(p->z); luaC_checkGC(L); - tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, - &p->buff, p->name); + tf = luaY_parser(L, p->z, &p->buff, p->name); cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); cl->l.p = tf; for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ @@ -524,6 +649,7 @@ static void f_parser (lua_State *L, void *ud) { } +// VERIFY: 6d29f951 auto // OFFSET: 0x00856A90 int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { struct SParser p; diff --git a/Engine/Source/lua-5.1/src/ldo.h b/Engine/Source/lua-5.1/src/ldo.h index b2de92b..c663658 100644 --- a/Engine/Source/lua-5.1/src/ldo.h +++ b/Engine/Source/lua-5.1/src/ldo.h @@ -40,6 +40,7 @@ typedef void (*Pfunc) (lua_State *L, void *ud); LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); +LUAI_FUNC int luaD_precall_profile (lua_State *L, StkId func, int nresults, __int64 start, __int64 *stop); LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, ptrdiff_t oldtop, ptrdiff_t ef); diff --git a/Engine/Source/lua-5.1/src/ldump.c b/Engine/Source/lua-5.1/src/ldump.c index 8d391c1..9b81934 100644 --- a/Engine/Source/lua-5.1/src/ldump.c +++ b/Engine/Source/lua-5.1/src/ldump.c @@ -58,6 +58,7 @@ static void DumpVector(const void* b, int n, size_t size, DumpState* D) DumpMem(b,n,size,D); } +// VERIFY: 50bd014a manual // OFFSET: 0x0085D1D0 static void DumpString(const TString* s, DumpState* D) { @@ -78,6 +79,7 @@ static void DumpString(const TString* s, DumpState* D) static void DumpFunction(const Proto* f, const TString* p, DumpState* D); +// VERIFY: d8142fa1 manual // OFFSET: 0x0085D260 static void DumpConstants(const Proto* f, DumpState* D) { @@ -110,6 +112,7 @@ static void DumpConstants(const Proto* f, DumpState* D) for (i=0; ip[i],f->source,D); } +// VERIFY: b9f4489c manual // OFFSET: 0x0085D390 static void DumpDebug(const Proto* f, DumpState* D) { @@ -129,6 +132,7 @@ static void DumpDebug(const Proto* f, DumpState* D) for (i=0; iupvalues[i],D); } +// VERIFY: dac789ab manual // OFFSET: 0x0085D500 static void DumpFunction(const Proto* f, const TString* p, DumpState* D) { @@ -154,6 +158,7 @@ static void DumpHeader(DumpState* D) /* ** dump Lua function as precompiled chunk */ +// VERIFY: ccdf9cd8 auto // OFFSET: 0x0085D660 int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) { diff --git a/Engine/Source/lua-5.1/src/lfunc.c b/Engine/Source/lua-5.1/src/lfunc.c index 6159a07..28114c4 100644 --- a/Engine/Source/lua-5.1/src/lfunc.c +++ b/Engine/Source/lua-5.1/src/lfunc.c @@ -6,6 +6,7 @@ #include +#include #define lfunc_c #define LUA_CORE @@ -20,10 +21,17 @@ +// VERIFY: 1ee59e51 auto // OFFSET: 0x0085CC10 Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); luaC_link(L, obj2gco(c), LUA_TFUNCTION); + if (G(L)->profile) { + c->c.profile = luaM_new(L, Profile); + memset(c->c.profile, 0, sizeof(Profile)); + } + else + c->c.profile = NULL; c->c.isC = 1; c->c.env = e; c->c.nupvalues = cast_byte(nelems); @@ -31,18 +39,28 @@ Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { } +// VERIFY: 4eecb7b8 manual // OFFSET: 0x0085CC90 Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); luaC_link(L, obj2gco(c), LUA_TFUNCTION); + if (G(L)->profile) { + c->l.profile = luaM_new(L, Profile); + memset(c->l.profile, 0, sizeof(Profile)); + } + else + c->l.profile = NULL; c->l.isC = 0; c->l.env = e; c->l.nupvalues = cast_byte(nelems); + if (!c->l.taint) + c->l.taint = lua_closuretaint; while (nelems--) c->l.upvals[nelems] = NULL; return c; } +// VERIFY: f15c35bb manual // OFFSET: 0x0085CD40 UpVal *luaF_newupval (lua_State *L) { UpVal *uv = luaM_new(L, UpVal); @@ -53,6 +71,7 @@ UpVal *luaF_newupval (lua_State *L) { } +// VERIFY: d386263e auto // OFFSET: 0x0085CD80 UpVal *luaF_findupval (lua_State *L, StkId level) { global_State *g = G(L); @@ -70,6 +89,7 @@ UpVal *luaF_findupval (lua_State *L, StkId level) { } uv = luaM_new(L, UpVal); /* not found: create a new one */ uv->tt = LUA_TUPVAL; + uv->taint = (lua_tainted && lua_gctag) ? lua_gctag : lua_tainted; uv->marked = luaC_white(g); uv->v = level; /* current value lives in the stack */ uv->next = *pp; /* chain it in the proper position */ @@ -90,6 +110,7 @@ static void unlinkupval (UpVal *uv) { } +// VERIFY: 86834f1b auto // OFFSET: 0x0085CE30 void luaF_freeupval (lua_State *L, UpVal *uv) { if (uv->v != &uv->u.value) /* is it open? */ @@ -98,6 +119,7 @@ void luaF_freeupval (lua_State *L, UpVal *uv) { } +// VERIFY: d8bbf93f auto // OFFSET: 0x0085CE70 void luaF_close (lua_State *L, StkId level) { UpVal *uv; @@ -118,6 +140,7 @@ void luaF_close (lua_State *L, StkId level) { } +// VERIFY: 7ea424c2 manual // OFFSET: 0x0085CF40 Proto *luaF_newproto (lua_State *L) { Proto *f = luaM_new(L, Proto); @@ -145,6 +168,7 @@ Proto *luaF_newproto (lua_State *L) { } +// VERIFY: 2374cc79 manual // OFFSET: 0x0085CFB0 void luaF_freeproto (lua_State *L, Proto *f) { luaM_freearray(L, f->code, f->sizecode, Instruction); @@ -157,10 +181,13 @@ void luaF_freeproto (lua_State *L, Proto *f) { } +// VERIFY: dbbdd064 manual // OFFSET: 0x0085D050 void luaF_freeclosure (lua_State *L, Closure *c) { int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : sizeLclosure(c->l.nupvalues); + if (c->c.profile) + luaM_free(L, c->c.profile); luaM_freemem(L, c, size); } @@ -169,6 +196,7 @@ void luaF_freeclosure (lua_State *L, Closure *c) { ** Look for n-th local variable at line `line' in function `func'. ** Returns NULL if not found. */ +// VERIFY: 1b95f164 auto // OFFSET: 0x0085D0A0 const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { int i; diff --git a/Engine/Source/lua-5.1/src/lgc.c b/Engine/Source/lua-5.1/src/lgc.c index f8231f2..8597d95 100644 --- a/Engine/Source/lua-5.1/src/lgc.c +++ b/Engine/Source/lua-5.1/src/lgc.c @@ -22,6 +22,11 @@ #include "ltable.h" #include "ltm.h" +#include "Engine/Source/Os/TimeManager.h" + + +// STATIC: 0x00D413C8 +static double divisor; #define GCSTEPSIZE 1024u #define GCSWEEPMAX 40 @@ -66,6 +71,7 @@ static void removeentry (Node *n) { } +// VERIFY: c0a6f86e auto // OFFSET: 0x0085A7D0 static void reallymarkobject (global_State *g, GCObject *o) { lua_assert(iswhite(o) && !isdead(g, o)); @@ -126,6 +132,7 @@ static void marktmu (global_State *g) { /* move `dead' udata that need finalization to list `tmudata' */ +// VERIFY: fb07e94a manual // OFFSET: 0x0085A8B0 size_t luaC_separateudata (lua_State *L, int all) { global_State *g = G(L); @@ -157,6 +164,7 @@ size_t luaC_separateudata (lua_State *L, int all) { } +// VERIFY: 8a283b13 manual // OFFSET: 0x0085A960 static int traversetable (global_State *g, Table *h) { int i; @@ -203,6 +211,7 @@ static int traversetable (global_State *g, Table *h) { ** All marks are conditional because a GC may happen while the ** prototype is still being created */ +// VERIFY: 46fdbba6 auto // OFFSET: 0x0085AB10 static void traverseproto (global_State *g, Proto *f) { int i; @@ -225,6 +234,7 @@ static void traverseproto (global_State *g, Proto *f) { +// VERIFY: e41c76a9 auto // OFFSET: 0x0085ABE0 static void traverseclosure (global_State *g, Closure *cl) { markobject(g, cl->c.env); @@ -258,6 +268,7 @@ static void checkstacksizes (lua_State *L, StkId max) { } +// VERIFY: 830a44d4 manual // OFFSET: 0x0085AC90 static void traversestack (global_State *g, lua_State *l) { StkId o, lim; @@ -280,6 +291,7 @@ static void traversestack (global_State *g, lua_State *l) { ** traverse one gray object, turning it to black. ** Returns `quantity' traversed. */ +// VERIFY: 575860f1 manual // OFFSET: 0x0085AD80 static l_mem propagatemark (global_State *g) { GCObject *o = g->gray; @@ -355,6 +367,7 @@ static int iscleared (const TValue *o, int iskey) { /* ** clear collected entries from weaktables */ +// VERIFY: 8a6f1806 manual // OFFSET: 0x0085AE80 static void cleartable (GCObject *l) { while (l) { @@ -383,6 +396,7 @@ static void cleartable (GCObject *l) { } +// VERIFY: 287dad0c manual // OFFSET: 0x0085AF90 static void freeobj (lua_State *L, GCObject *o) { switch (o->gch.tt) { @@ -408,11 +422,104 @@ static void freeobj (lua_State *L, GCObject *o) { } } +// VERIFY: ca60516c auto +// OFFSET: 0x0085B030 +static lu_mem sizeobj (GCObject *o) { + switch (o->gch.tt) { + case LUA_TSTRING: + return sizestring(gco2ts(o)); + case LUA_TTABLE: { + Table *h = gco2h(o); + return sizeof(Table) + sizeof(TValue) * h->sizearray + sizeof(Node) * sizenode(h); + } + case LUA_TFUNCTION: { + Closure *cl = gco2cl(o); + if (cl->c.isC) + return sizeCclosure(cl->c.nupvalues); + return sizeLclosure(cl->l.nupvalues) + (cl->l.profile ? sizeof(Profile) : 0); + } + case LUA_TUSERDATA: + return sizeudata(gco2u(o)); + case LUA_TTHREAD: { + lua_State *th = gco2th(o); + return sizeof(lua_State) + sizeof(TValue) * th->stacksize + sizeof(CallInfo) * th->size_ci; + } + case LUA_TPROTO: { + Proto *p = gco2p(o); + return sizeof(Proto) + sizeof(Instruction) * p->sizecode + sizeof(Proto *) * p->sizep + + sizeof(TValue) * p->sizek + sizeof(int) * p->sizelineinfo + + sizeof(LocVar) * p->sizelocvars + sizeof(TString *) * p->sizeupvalues; + } + case LUA_TUPVAL: + return sizeof(UpVal); + default: + return 0; + } +} + + +// VERIFY: dd628a7b auto +// OFFSET: 0x0085B0F0 +static void updatesizes (lua_State *L, GCObject *o) { + for (; o; o = o->gch.next) { + const char *tag = o->gch.taint; + if (tag) { + lu_mem size = sizeobj(o); + global_State *g = G(L); + GCUsage *u; + for (u = g->gcusage; u; u = u->next) { + if (u->tag == tag) + break; + } + if (u) + u->usage += size; + else { + u = luaM_new(L, GCUsage); + u->next = g->gcusage; + u->tag = tag; + u->usage = size; + g->gcusage = u; + } + } + } +} + + +// VERIFY: 7bbb4677 auto +// OFFSET: 0x0085B160 +static void addtimetotag (lua_State *L, const char *tag, __int64 time) { + global_State *g = G(L); + GCTime *t; + for (t = g->gctime; t; t = t->next) { + if (t->tag == tag) { + t->time += time; + return; + } + } + t = luaM_new(L, GCTime); + t->next = g->gctime; + t->tag = tag; + t->time = time; + g->gctime = t; +} + + +// VERIFY: 9bce24e3 auto +// OFFSET: 0x0085B1C0 +static void updatetimes (lua_State *L, GCObject *o) { + for (; o; o = o->gch.next) { + if (o->gch.taint && o->gch.tt == LUA_TFUNCTION) + addtimetotag(L, o->gch.taint, gco2cl(o)->l.profile->time); + } +} + + #define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) +// VERIFY: 5e5e0256 manual // OFFSET: 0x0085B200 static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { GCObject *curr; @@ -438,6 +545,7 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { } +// VERIFY: 153439af auto // OFFSET: 0x0085B290 static void checkSizes (lua_State *L) { global_State *g = G(L); @@ -453,6 +561,7 @@ static void checkSizes (lua_State *L) { } +// VERIFY: 3785e316 manual // OFFSET: 0x0085B300 static void GCTM (lua_State *L) { global_State *g = G(L); @@ -486,6 +595,7 @@ static void GCTM (lua_State *L) { /* ** Call all GC tag methods */ +// VERIFY: 226cae54 auto // OFFSET: 0x0085B410 void luaC_callGCTM (lua_State *L) { while (G(L)->tmudata) @@ -493,6 +603,7 @@ void luaC_callGCTM (lua_State *L) { } +// VERIFY: 0fdcdcbf auto // OFFSET: 0x0085B440 void luaC_freeall (lua_State *L) { global_State *g = G(L); @@ -501,9 +612,95 @@ void luaC_freeall (lua_State *L) { sweepwholelist(L, &g->rootgc); for (i = 0; i < g->strt.size; i++) /* free all string lists */ sweepwholelist(L, &g->strt.hash[i]); + while (G(L)->gcusage) { + GCUsage *u = G(L)->gcusage; + G(L)->gcusage = u->next; + luaM_free(L, u); + } + while (G(L)->gctime) { + GCTime *t = G(L)->gctime; + G(L)->gctime = t->next; + luaM_free(L, t); + } +} + +// VERIFY: 8f3c5ead auto +// OFFSET: 0x0085B4E0 +void luaC_sizeall (lua_State *L) { + global_State *g = G(L); + GCUsage *u; + int i; + for (u = g->gcusage; u; u = u->next) + u->usage = 0; + updatesizes(L, g->rootgc); + for (i = 0; i < g->strt.size; i++) + updatesizes(L, g->strt.hash[i]); } +// VERIFY: 36d76bcf auto +// OFFSET: 0x0085B530 +lu_mem luaC_getsize (lua_State *L, const char *tag) { + GCUsage *u; + for (u = G(L)->gcusage; u; u = u->next) { + if (u->tag == tag) + return u->usage; + } + return 0; +} + + +// VERIFY: 9fa4fdca manual +// OFFSET: 0x0085B560 +void luaC_timeall (lua_State *L) { + global_State *g = G(L); + if (g->profile) { + GCTime *t; + for (t = g->gctime; t; t = t->next) + t->time = 0; + updatetimes(L, g->rootgc); + } +} + + +// VERIFY: fb2b57ed auto +// OFFSET: 0x0085B5A0 +double luaC_gettime (lua_State *L, const char *tag) { + GCTime *t; + for (t = G(L)->gctime; t; t = t->next) { + if (t->tag == tag) { + if (divisor == 0.0) + divisor = 1000.0 / OsGetAsyncClocksPerSecond(); + return divisor * t->time; + } + } + return 0.0; +} + + +// VERIFY: aa59cfad manual +// OFFSET: 0x0085B610 +void luaC_timereset (lua_State *L) { + global_State *g = G(L); + if (g->profile) { + GCTime *t; + GCObject *o; + for (t = g->gctime; t; t = t->next) + t->time = 0; + for (o = g->rootgc; o; o = o->gch.next) { + if (o->gch.tt == LUA_TFUNCTION) { + Profile *p = gco2cl(o)->l.profile; + p->time = 0; + p->totaltime = 0; + p->calls = 0; + } + } + } +} + + + +// VERIFY: cdf2fa44 auto // OFFSET: 0x0085B660 static void markmt (global_State *g) { int i; @@ -513,6 +710,7 @@ static void markmt (global_State *g) { /* mark root set */ +// VERIFY: 74d5129b auto // OFFSET: 0x0085B6A0 static void markroot (lua_State *L) { global_State *g = G(L); @@ -528,6 +726,7 @@ static void markroot (lua_State *L) { } +// VERIFY: c21055d8 auto // OFFSET: 0x0085B710 static void remarkupvals (global_State *g) { UpVal *uv; @@ -539,6 +738,7 @@ static void remarkupvals (global_State *g) { } +// VERIFY: f77f8002 manual // OFFSET: 0x0085B750 static void atomic (lua_State *L) { global_State *g = G(L); @@ -571,6 +771,7 @@ static void atomic (lua_State *L) { } +// VERIFY: 93839d13 auto // OFFSET: 0x0085B850 static l_mem singlestep (lua_State *L) { global_State *g = G(L); @@ -626,6 +827,7 @@ static l_mem singlestep (lua_State *L) { } +// VERIFY: b74879d2 auto // OFFSET: 0x0085B950 void luaC_step (lua_State *L) { global_State *g = G(L); @@ -653,6 +855,7 @@ void luaC_step (lua_State *L) { } +// VERIFY: c33bfb16 auto // OFFSET: 0x0085B9E0 void luaC_fullgc (lua_State *L) { global_State *g = G(L); @@ -680,6 +883,7 @@ void luaC_fullgc (lua_State *L) { } +// VERIFY: e4249e4b auto // OFFSET: 0x0085BA50 void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { global_State *g = G(L); @@ -694,6 +898,7 @@ void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { } +// VERIFY: 52adbc03 auto // OFFSET: 0x0085BA90 void luaC_barrierback (lua_State *L, Table *t) { global_State *g = G(L); @@ -706,6 +911,7 @@ void luaC_barrierback (lua_State *L, Table *t) { } +// VERIFY: 9b0e295d auto // OFFSET: 0x0085BAB0 void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { global_State *g = G(L); @@ -713,9 +919,11 @@ void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { g->rootgc = o; o->gch.marked = luaC_white(g); o->gch.tt = tt; + o->gch.taint = (lua_tainted && lua_gctag) ? lua_gctag : lua_tainted; } +// VERIFY: 6cf5c95e auto // OFFSET: 0x0085BB00 void luaC_linkupval (lua_State *L, UpVal *uv) { global_State *g = G(L); diff --git a/Engine/Source/lua-5.1/src/lgc.h b/Engine/Source/lua-5.1/src/lgc.h index 5f69acb..a3dab6d 100644 --- a/Engine/Source/lua-5.1/src/lgc.h +++ b/Engine/Source/lua-5.1/src/lgc.h @@ -99,6 +99,11 @@ LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); LUAI_FUNC void luaC_callGCTM (lua_State *L); LUAI_FUNC void luaC_freeall (lua_State *L); +LUAI_FUNC void luaC_sizeall (lua_State *L); +LUAI_FUNC lu_mem luaC_getsize (lua_State *L, const char *tag); +LUAI_FUNC void luaC_timeall (lua_State *L); +LUAI_FUNC double luaC_gettime (lua_State *L, const char *tag); +LUAI_FUNC void luaC_timereset (lua_State *L); LUAI_FUNC void luaC_step (lua_State *L); LUAI_FUNC void luaC_fullgc (lua_State *L); LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); diff --git a/Engine/Source/lua-5.1/src/llex.c b/Engine/Source/lua-5.1/src/llex.c index 1fd8b60..f8b7ba0 100644 --- a/Engine/Source/lua-5.1/src/llex.c +++ b/Engine/Source/lua-5.1/src/llex.c @@ -48,6 +48,7 @@ const char *const luaX_tokens [] = { #define save_and_next(ls) (save(ls, ls->current), next(ls)) +// VERIFY: c4af139a auto // OFFSET: 0x0085D810 static void save (LexState *ls, int c) { Mbuffer *b = ls->buff; @@ -62,6 +63,7 @@ static void save (LexState *ls, int c) { } +// VERIFY: 700928bc auto // OFFSET: 0x0085D890 void luaX_init (lua_State *L) { int i; @@ -77,6 +79,7 @@ void luaX_init (lua_State *L) { #define MAXSRC 80 +// VERIFY: 058ab5d7 manual // OFFSET: 0x0085D8E0 const char *luaX_token2str (LexState *ls, int token) { if (token < FIRST_RESERVED) { @@ -102,6 +105,7 @@ static const char *txtToken (LexState *ls, int token) { } +// VERIFY: a59650ac manual // OFFSET: 0x0085D940 void luaX_lexerror (LexState *ls, const char *msg, int token) { char buff[MAXSRC]; @@ -113,12 +117,14 @@ void luaX_lexerror (LexState *ls, const char *msg, int token) { } +// VERIFY: 9ebfe1bd manual // OFFSET: 0x0085D9E0 void luaX_syntaxerror (LexState *ls, const char *msg) { luaX_lexerror(ls, msg, ls->t.token); } +// VERIFY: 63483ec2 auto // OFFSET: 0x0085DA00 TString *luaX_newstring (LexState *ls, const char *str, size_t l) { lua_State *L = ls->L; @@ -130,6 +136,7 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) { } +// VERIFY: a29e5f40 manual // OFFSET: 0x0085DA50 static void inclinenumber (LexState *ls) { int old = ls->current; @@ -142,6 +149,7 @@ static void inclinenumber (LexState *ls) { } +// VERIFY: 452efdd8 auto // OFFSET: 0x0085DAE0 void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { ls->decpoint = '.'; @@ -166,6 +174,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { +// VERIFY: 6f23716e auto // OFFSET: 0x0085DB70 static int check_next (LexState *ls, const char *set) { if (!strchr(set, ls->current)) @@ -183,6 +192,7 @@ static void buffreplace (LexState *ls, char from, char to) { } +// VERIFY: f725711d manual // OFFSET: 0x0085DBD0 static void trydecpoint (LexState *ls, SemInfo *seminfo) { /* format error: try to update decimal point separator */ @@ -199,6 +209,7 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) { /* LUA_NUMBER */ +// VERIFY: 5d4f3275 auto // OFFSET: 0x0085DCB0 static void read_numeral (LexState *ls, SemInfo *seminfo) { lua_assert(isdigit(ls->current)); @@ -216,6 +227,7 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { } +// VERIFY: 8b89b1a9 manual // OFFSET: 0x0085DDD0 static int skip_sep (LexState *ls) { int count = 0; @@ -230,6 +242,7 @@ static int skip_sep (LexState *ls) { } +// VERIFY: 0237b3f0 manual // OFFSET: 0x0085DE70 static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { int cont = 0; @@ -286,6 +299,7 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { } +// VERIFY: 0644c91f manual // OFFSET: 0x0085E160 static void read_string (LexState *ls, int del, SemInfo *seminfo) { save_and_next(ls); @@ -343,6 +357,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { } +// VERIFY: aabde59a manual // OFFSET: 0x0085E600 static int llex (LexState *ls, SemInfo *seminfo) { luaZ_resetbuffer(ls->buff); @@ -458,6 +473,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { } +// VERIFY: 728810c2 auto // OFFSET: 0x0085ECB0 void luaX_next (LexState *ls) { ls->lastline = ls->linenumber; @@ -470,6 +486,7 @@ void luaX_next (LexState *ls) { } +// VERIFY: b7f80828 auto // OFFSET: 0x0085ED00 void luaX_lookahead (LexState *ls) { lua_assert(ls->lookahead.token == TK_EOS); diff --git a/Engine/Source/lua-5.1/src/llimits.h b/Engine/Source/lua-5.1/src/llimits.h index b03221a..150d13f 100644 --- a/Engine/Source/lua-5.1/src/llimits.h +++ b/Engine/Source/lua-5.1/src/llimits.h @@ -27,7 +27,7 @@ typedef LUAI_MEM l_mem; typedef unsigned char lu_byte; -#define MAX_SIZET ((size_t)(~(size_t)0)-2) +#define MAX_SIZET 0x1000000 #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) diff --git a/Engine/Source/lua-5.1/src/lmathlib.c b/Engine/Source/lua-5.1/src/lmathlib.c index ad00fea..396aa83 100644 --- a/Engine/Source/lua-5.1/src/lmathlib.c +++ b/Engine/Source/lua-5.1/src/lmathlib.c @@ -23,90 +23,105 @@ +// VERIFY: 06c8d9c2 auto // OFFSET: 0x00851040 static int math_abs (lua_State *L) { lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); return 1; } +// VERIFY: 38236aba auto // OFFSET: 0x00851070 static int math_sin (lua_State *L) { lua_pushnumber(L, sin(luaL_checknumber(L, 1))); return 1; } +// VERIFY: dd25a649 auto // OFFSET: 0x008510A0 static int math_sinh (lua_State *L) { lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); return 1; } +// VERIFY: f37f3546 auto // OFFSET: 0x008510D0 static int math_cos (lua_State *L) { lua_pushnumber(L, cos(luaL_checknumber(L, 1))); return 1; } +// VERIFY: a30485a7 auto // OFFSET: 0x00851100 static int math_cosh (lua_State *L) { lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); return 1; } +// VERIFY: 97760d7d auto // OFFSET: 0x00851130 static int math_tan (lua_State *L) { lua_pushnumber(L, tan(luaL_checknumber(L, 1))); return 1; } +// VERIFY: 9d0915ef auto // OFFSET: 0x00851160 static int math_tanh (lua_State *L) { lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); return 1; } +// VERIFY: f061939b auto // OFFSET: 0x00851190 static int math_asin (lua_State *L) { lua_pushnumber(L, asin(luaL_checknumber(L, 1))); return 1; } +// VERIFY: 09e32b8e auto // OFFSET: 0x008511C0 static int math_acos (lua_State *L) { lua_pushnumber(L, acos(luaL_checknumber(L, 1))); return 1; } +// VERIFY: 6175a388 auto // OFFSET: 0x008511F0 static int math_atan (lua_State *L) { lua_pushnumber(L, atan(luaL_checknumber(L, 1))); return 1; } +// VERIFY: d67237a6 auto // OFFSET: 0x00851220 static int math_atan2 (lua_State *L) { lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); return 1; } +// VERIFY: 25bb528f auto // OFFSET: 0x00851260 static int math_ceil (lua_State *L) { lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); return 1; } +// VERIFY: 7869f986 auto // OFFSET: 0x00851290 static int math_floor (lua_State *L) { lua_pushnumber(L, floor(luaL_checknumber(L, 1))); return 1; } +// VERIFY: 1ad77106 auto // OFFSET: 0x008512C0 static int math_fmod (lua_State *L) { lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); return 1; } +// VERIFY: a8f23514 auto // OFFSET: 0x00851310 static int math_modf (lua_State *L) { double ip; @@ -116,48 +131,56 @@ static int math_modf (lua_State *L) { return 2; } +// VERIFY: d382c6b8 auto // OFFSET: 0x00851360 static int math_sqrt (lua_State *L) { lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); return 1; } +// VERIFY: 10d84021 auto // OFFSET: 0x00851390 static int math_pow (lua_State *L) { lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); return 1; } +// VERIFY: fd6221b8 auto // OFFSET: 0x008513E0 static int math_log (lua_State *L) { lua_pushnumber(L, log(luaL_checknumber(L, 1))); return 1; } +// VERIFY: b8699921 auto // OFFSET: 0x00851410 static int math_log10 (lua_State *L) { lua_pushnumber(L, log10(luaL_checknumber(L, 1))); return 1; } +// VERIFY: 5a4e28ee auto // OFFSET: 0x00851440 static int math_exp (lua_State *L) { lua_pushnumber(L, exp(luaL_checknumber(L, 1))); return 1; } +// VERIFY: d3b84732 auto // OFFSET: 0x00851480 static int math_deg (lua_State *L) { lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); return 1; } +// VERIFY: 760a29cd auto // OFFSET: 0x008514B0 static int math_rad (lua_State *L) { lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); return 1; } +// VERIFY: d612d86a auto // OFFSET: 0x008514E0 static int math_frexp (lua_State *L) { int e; @@ -166,6 +189,7 @@ static int math_frexp (lua_State *L) { return 2; } +// VERIFY: da0e10dd auto // OFFSET: 0x00851520 static int math_ldexp (lua_State *L) { lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); @@ -174,6 +198,7 @@ static int math_ldexp (lua_State *L) { +// VERIFY: 481dcfb2 auto // OFFSET: 0x00851560 static int math_min (lua_State *L) { int n = lua_gettop(L); /* number of arguments */ @@ -189,6 +214,7 @@ static int math_min (lua_State *L) { } +// VERIFY: 106147a2 auto // OFFSET: 0x008515D0 static int math_max (lua_State *L) { int n = lua_gettop(L); /* number of arguments */ @@ -204,6 +230,7 @@ static int math_max (lua_State *L) { } +// VERIFY: a0c78bf3 auto // OFFSET: 0x00851640 static int math_random (lua_State *L) { /* the `%' avoids the (rare) case of r==1, and is needed also because on @@ -233,12 +260,6 @@ static int math_random (lua_State *L) { } -static int math_randomseed (lua_State *L) { - srand(luaL_checkint(L, 1)); - return 0; -} - - static const luaL_Reg mathlib[] = { {"abs", math_abs}, {"acos", math_acos}, @@ -262,7 +283,6 @@ static const luaL_Reg mathlib[] = { {"pow", math_pow}, {"rad", math_rad}, {"random", math_random}, - {"randomseed", math_randomseed}, {"sinh", math_sinh}, {"sin", math_sin}, {"sqrt", math_sqrt}, @@ -275,6 +295,7 @@ static const luaL_Reg mathlib[] = { /* ** Open math library */ +// VERIFY: ffc54c50 auto // OFFSET: 0x00851760 LUALIB_API int luaopen_math (lua_State *L) { luaL_register(L, LUA_MATHLIBNAME, mathlib); diff --git a/Engine/Source/lua-5.1/src/lmem.c b/Engine/Source/lua-5.1/src/lmem.c index af84448..adbebe2 100644 --- a/Engine/Source/lua-5.1/src/lmem.c +++ b/Engine/Source/lua-5.1/src/lmem.c @@ -43,6 +43,7 @@ #define MINSIZEARRAY 4 +// VERIFY: 3bc1b402 manual // OFFSET: 0x0085D740 void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, int limit, const char *errormsg) { @@ -64,6 +65,8 @@ void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, } +// VERIFY: fcfa9ba9 manual +// OFFSET: 0x0085D6D0 void *luaM_toobig (lua_State *L) { luaG_runerror(L, "memory allocation error: block too big"); return NULL; /* to avoid warnings */ @@ -74,6 +77,7 @@ void *luaM_toobig (lua_State *L) { /* ** generic allocation routine. */ +// VERIFY: 64876ea5 auto // OFFSET: 0x0085D6F0 void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { global_State *g = G(L); diff --git a/Engine/Source/lua-5.1/src/lmemPool.cpp b/Engine/Source/lua-5.1/src/lmemPool.cpp new file mode 100644 index 0000000..c3d63e8 --- /dev/null +++ b/Engine/Source/lua-5.1/src/lmemPool.cpp @@ -0,0 +1,180 @@ +#include +#include "lmemPool.h" +#include "Engine/Source/Storm/H/storm.h" + +// STATIC: 0x00A47FBC +static const uint32_t s_blocksizes[] = { 16, 24, 32, 40, 64, 80, 128, 160, 256 }; + +// VERIFY: a5f551b2 manual +// OFFSET: 0x00855570 +MemChunk::MemChunk(uint32_t blockSize, uint32_t size) { + this->m_blockSize = blockSize; + this->m_numBlocks = size / blockSize; + this->m_size = blockSize * this->m_numBlocks; + this->m_memblocks = SMemAlloc(this->m_size, __FILE__, __LINE__, 0); + + char* block = static_cast(this->m_memblocks); + this->m_free = block; + + while (block < static_cast(this->m_memblocks) + this->m_size - this->m_blockSize) { + *reinterpret_cast(block) = block + this->m_blockSize; + block += this->m_blockSize; + } + + *reinterpret_cast(block) = nullptr; +} + +// INLINED +MemChunk::~MemChunk() { + SMemFree(this->m_memblocks, __FILE__, __LINE__, 0); +} + +// INLINED +MemPool::MemPool() { +} + +// VERIFY: 403cd95b auto +// OFFSET: 0x00855670 +int32_t MemPool::MemFree(void* ptr) { + for (uint32_t i = 0; i < this->m_chunks.Count(); i++) { + MemChunk* chunk = this->m_chunks[i]; + + if (ptr >= chunk->m_memblocks && ptr < static_cast(chunk->m_memblocks) + chunk->m_size) { + *static_cast(ptr) = chunk->m_free; + chunk->m_numBlocks++; + chunk->m_free = ptr; + return 1; + } + } + + return 0; +} + +// VERIFY: d5bd1438 manual +// OFFSET: 0x008556E0 +MemPool::~MemPool() { + for (uint32_t i = this->m_chunks.Count(); i; i--) { + delete this->m_chunks[i - 1]; + } +} + +// VERIFY: 2bca1af4 manual +// OFFSET: 0x00855740 +void* luaM_initPool() { + MemPool** pools = new (__FILE__, __LINE__) MemPool*[sizeof(s_blocksizes) / sizeof(s_blocksizes[0])]; + + for (uint32_t i = 0; i < sizeof(s_blocksizes) / sizeof(s_blocksizes[0]); i++) { + pools[i] = new (__FILE__, __LINE__) MemPool(); + pools[i]->m_blockSize = s_blocksizes[i]; + pools[i]->m_numBlocks = (s_blocksizes[i] * 1024) / s_blocksizes[i]; + pools[i]->m_chunkSize = s_blocksizes[i] * pools[i]->m_numBlocks; + } + + return pools; +} + +// VERIFY: 2d194715 manual +// OFFSET: 0x008557D0 +void luaM_freePool(void* ud) { + MemPool** pools = static_cast(ud); + + if (!pools) { + return; + } + + for (uint32_t i = 0; i < sizeof(s_blocksizes) / sizeof(s_blocksizes[0]); i++) { + delete pools[i]; + } + + SMemFree(pools, __FILE__, __LINE__, 0); +} + +// VERIFY: 48e99a2f manual +// OFFSET: 0x00855820 +void* MemPool::MemAlloc() { + uint32_t count = this->m_chunks.Count(); + + for (uint32_t i = 0; i < count; i++) { + MemChunk* chunk = this->m_chunks[i]; + + if (chunk->m_free) { + void* block = chunk->m_free; + chunk->m_numBlocks--; + chunk->m_free = *static_cast(block); + return block; + } + } + + this->m_chunks.SetCount(count + 1); + this->m_chunks[count] = new (__FILE__, __LINE__) MemChunk(this->m_blockSize, this->m_chunkSize); + + MemChunk* chunk = this->m_chunks[count]; + void* block = nullptr; + + if (chunk->m_free) { + block = chunk->m_free; + chunk->m_numBlocks--; + chunk->m_free = *static_cast(block); + } + + return block; +} + +// VERIFY: f201d154 manual +// OFFSET: 0x008558E0 +void* luaM_reallocPool(void* ud, void* ptr, size_t osize, size_t nsize) { + MemPool** pools = static_cast(ud); + int32_t oldpool = -1; + int32_t newpool = -1; + + if (ptr) { + for (int32_t i = 0; i < static_cast(sizeof(s_blocksizes) / sizeof(s_blocksizes[0])); i++) { + if (osize <= s_blocksizes[i]) { + oldpool = i; + break; + } + } + } + + if (!nsize) { + if (ptr) { + if (oldpool >= 0) { + pools[oldpool]->MemFree(ptr); + return nullptr; + } + + SMemFree(ptr, __FILE__, __LINE__, 0); + } + + return nullptr; + } + + for (int32_t i = 0; i < static_cast(sizeof(s_blocksizes) / sizeof(s_blocksizes[0])); i++) { + if (nsize <= s_blocksizes[i]) { + newpool = i; + break; + } + } + + if (oldpool == newpool) { + if (oldpool < 0) { + return SMemReAlloc(ptr, nsize, __FILE__, __LINE__, 0); + } + + return ptr; + } + + void* newptr = newpool < 0 ? SMemAlloc(nsize, __FILE__, __LINE__, 0) : pools[newpool]->MemAlloc(); + + if (ptr) { + memcpy(newptr, ptr, osize < nsize ? osize : nsize); + + if (oldpool >= 0) { + pools[oldpool]->MemFree(ptr); + } else { + SMemFree(ptr, __FILE__, __LINE__, 0); + } + } + + return newptr; +} diff --git a/Engine/Source/lua-5.1/src/lmemPool.h b/Engine/Source/lua-5.1/src/lmemPool.h new file mode 100644 index 0000000..dfc6d4a --- /dev/null +++ b/Engine/Source/lua-5.1/src/lmemPool.h @@ -0,0 +1,38 @@ +#ifndef lmemPool_h +#define lmemPool_h + +#include +#include +#include "lua.h" +#include "Engine/Source/Storm/H/stpl.h" + +class MemChunk { + public: + /* 0000 */ void* m_memblocks; + /* 0004 */ void* m_free; + /* 0008 */ uint32_t m_size; + /* 000C */ uint32_t m_blockSize; + /* 0010 */ uint32_t m_numBlocks; + + MemChunk(uint32_t blockSize, uint32_t size); + ~MemChunk(); +}; + +class MemPool { + public: + /* 0000 */ TSFixedArray m_chunks; + /* 000C */ uint32_t m_chunkSize; + /* 0010 */ uint32_t m_blockSize; + /* 0014 */ uint32_t m_numBlocks; + + MemPool(); + ~MemPool(); + void* MemAlloc(); + int32_t MemFree(void* ptr); +}; + +LUAI_FUNC void* luaM_initPool(); +LUAI_FUNC void luaM_freePool(void* ud); +LUAI_FUNC void* luaM_reallocPool(void* ud, void* ptr, size_t osize, size_t nsize); + +#endif diff --git a/Engine/Source/lua-5.1/src/lobject.c b/Engine/Source/lua-5.1/src/lobject.c index 833f810..6976be6 100644 --- a/Engine/Source/lua-5.1/src/lobject.c +++ b/Engine/Source/lua-5.1/src/lobject.c @@ -32,6 +32,7 @@ const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if ** eeeee != 0 and (xxx) otherwise. */ +// VERIFY: 9209c4f8 auto // OFFSET: 0x0084D390 int luaO_int2fb (unsigned int x) { int e = 0; /* expoent */ @@ -45,6 +46,7 @@ int luaO_int2fb (unsigned int x) { /* converts back */ +// VERIFY: 29b4d7b5 auto // OFFSET: 0x0084D3D0 int luaO_fb2int (int x) { int e = (x >> 3) & 31; @@ -53,6 +55,7 @@ int luaO_fb2int (int x) { } +// VERIFY: a3663083 auto // OFFSET: 0x0084D3F0 int luaO_log2 (unsigned int x) { static const lu_byte log_2[256] = { @@ -72,6 +75,7 @@ int luaO_log2 (unsigned int x) { } +// VERIFY: 9c0b82bc auto // OFFSET: 0x0084D420 int luaO_rawequalObj (const TValue *t1, const TValue *t2) { if (ttype(t1) != ttype(t2)) return 0; @@ -91,6 +95,7 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) { } +// VERIFY: 3b9b2152 manual // OFFSET: 0x0084D480 int luaO_str2d (const char *s, lua_Number *result) { char *endptr; @@ -106,14 +111,17 @@ int luaO_str2d (const char *s, lua_Number *result) { +// VERIFY: 7e4542e0 auto // OFFSET: 0x0084D520 static void pushstr (lua_State *L, const char *str) { + if (str == NULL) str = "(null)"; setsvalue2s(L, L->top, luaS_new(L, str)); incr_top(L); } /* this function handles only `%d', `%c', %f, %p, and `%s' formats */ +// VERIFY: 0f78e490 manual // OFFSET: 0x0084D580 const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { int n = 1; @@ -176,6 +184,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { } +// VERIFY: 5f15ec17 auto // OFFSET: 0x0084D840 const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { const char *msg; @@ -187,6 +196,7 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { } +// VERIFY: 0300c26e manual // OFFSET: 0x0084D860 void luaO_chunkid (char *out, const char *source, size_t bufflen) { if (*source == '=') { diff --git a/Engine/Source/lua-5.1/src/lobject.h b/Engine/Source/lua-5.1/src/lobject.h index 8ce4405..857d088 100644 --- a/Engine/Source/lua-5.1/src/lobject.h +++ b/Engine/Source/lua-5.1/src/lobject.h @@ -40,7 +40,7 @@ typedef union GCObject GCObject; ** Common Header for all collectable objects (in macro form, to be ** included in other objects) */ -#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked +#define CommonHeader GCObject *next; const char *taint; lu_byte tt; lu_byte marked /* @@ -68,7 +68,7 @@ typedef union { ** Tagged Values */ -#define TValuefields Value value; int tt +#define TValuefields Value value; int tt; const char *taint typedef struct lua_TValue { TValuefields; @@ -114,44 +114,45 @@ typedef struct lua_TValue { /* Macros to set values */ -#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) +#define setnilvalue(obj) \ + { TValue *i_o=(obj); i_o->taint=lua_tainted; i_o->tt=LUA_TNIL; } #define setnvalue(obj,x) \ - { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } + { TValue *i_o=(obj); i_o->taint=lua_tainted; i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } #define setpvalue(obj,x) \ - { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } + { TValue *i_o=(obj); i_o->taint=lua_tainted; i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } #define setbvalue(obj,x) \ - { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } + { TValue *i_o=(obj); i_o->taint=lua_tainted; i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } #define setsvalue(L,obj,x) \ - { TValue *i_o=(obj); \ + { TValue *i_o=(obj); i_o->taint=lua_tainted; \ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ checkliveness(G(L),i_o); } #define setuvalue(L,obj,x) \ - { TValue *i_o=(obj); \ + { TValue *i_o=(obj); i_o->taint=lua_tainted; \ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ checkliveness(G(L),i_o); } #define setthvalue(L,obj,x) \ - { TValue *i_o=(obj); \ + { TValue *i_o=(obj); i_o->taint=lua_tainted; \ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ checkliveness(G(L),i_o); } #define setclvalue(L,obj,x) \ - { TValue *i_o=(obj); \ + { TValue *i_o=(obj); i_o->taint=lua_tainted; \ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ checkliveness(G(L),i_o); } #define sethvalue(L,obj,x) \ - { TValue *i_o=(obj); \ + { TValue *i_o=(obj); i_o->taint=lua_tainted; \ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ checkliveness(G(L),i_o); } #define setptvalue(L,obj,x) \ - { TValue *i_o=(obj); \ + { TValue *i_o=(obj); i_o->taint=lua_tainted; \ i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ checkliveness(G(L),i_o); } @@ -160,7 +161,15 @@ typedef struct lua_TValue { #define setobj(L,obj1,obj2) \ { const TValue *o2=(obj2); TValue *o1=(obj1); \ - o1->value = o2->value; o1->tt=o2->tt; \ + *o1 = *o2; \ + if (o2->taint && lua_taintexpected && !lua_taintedclosure) lua_tainted = o2->taint; \ + checkliveness(G(L),o1); } + +#define setobj2s(L,obj1,obj2) \ + { const TValue *o2=(obj2); TValue *o1=(obj1); \ + *o1 = *o2; \ + if (o2->taint) { if (lua_taintexpected && !lua_taintedclosure) lua_tainted = o2->taint; } \ + else o1->taint = lua_tainted; \ checkliveness(G(L),o1); } @@ -169,9 +178,8 @@ typedef struct lua_TValue { */ /* from stack to (same) stack */ -#define setobjs2s setobj +#define setobjs2s setobj2s /* to stack (not from same stack) */ -#define setobj2s setobj #define setsvalue2s setsvalue #define sethvalue2s sethvalue #define setptvalue2s setptvalue @@ -288,9 +296,17 @@ typedef struct UpVal { ** Closures */ +typedef struct Profile { + int calls; + int depth; + __int64 start; + __int64 time; + __int64 totaltime; +} Profile; + #define ClosureHeader \ CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ - struct Table *env + struct Table *env; struct Profile *profile typedef struct CClosure { ClosureHeader; diff --git a/Engine/Source/lua-5.1/src/lparser.c b/Engine/Source/lua-5.1/src/lparser.c index 568a87a..a96bfea 100644 --- a/Engine/Source/lua-5.1/src/lparser.c +++ b/Engine/Source/lua-5.1/src/lparser.c @@ -68,6 +68,7 @@ static void error_expected (LexState *ls, int token) { } +// VERIFY: 251d1b4e auto // OFFSET: 0x0085ED20 static void errorlimit (FuncState *fs, int limit, const char *what) { const char *msg = (fs->f->linedefined == 0) ? @@ -78,6 +79,7 @@ static void errorlimit (FuncState *fs, int limit, const char *what) { } +// VERIFY: 641ed38f auto // OFFSET: 0x0085ED70 static int testnext (LexState *ls, int c) { if (ls->t.token == c) { @@ -103,6 +105,7 @@ static void checknext (LexState *ls, int c) { +// VERIFY: d8f6aeec auto // OFFSET: 0x0085ED90 static void check_match (LexState *ls, int what, int who, int where) { if (!testnext(ls, what)) { @@ -133,18 +136,21 @@ static void init_exp (expdesc *e, expkind k, int i) { } +// VERIFY: 4bdb896e auto // OFFSET: 0x0085EE00 static void codestring (LexState *ls, expdesc *e, TString *s) { init_exp(e, VK, luaK_stringK(ls->fs, s)); } +// VERIFY: 9652ea85 auto // OFFSET: 0x0085EE20 static void checkname(LexState *ls, expdesc *e) { codestring(ls, e, str_checkname(ls)); } +// VERIFY: 4bade465 manual // OFFSET: 0x0085EE80 static int registerlocalvar (LexState *ls, TString *varname) { FuncState *fs = ls->fs; @@ -170,6 +176,7 @@ static void new_localvar (LexState *ls, TString *name, int n) { } +// VERIFY: 92b494c8 auto // OFFSET: 0x0085EF30 static void adjustlocalvars (LexState *ls, int nvars) { FuncState *fs = ls->fs; @@ -180,6 +187,7 @@ static void adjustlocalvars (LexState *ls, int nvars) { } +// VERIFY: fa0847bb manual // OFFSET: 0x0085EF70 static void removevars (LexState *ls, int tolevel) { FuncState *fs = ls->fs; @@ -188,6 +196,7 @@ static void removevars (LexState *ls, int tolevel) { } +// VERIFY: 9afe60ea auto // OFFSET: 0x0085EFB0 static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { int i; @@ -230,6 +239,7 @@ static void markupval (FuncState *fs, int level) { } +// VERIFY: 52a0f384 auto // OFFSET: 0x0085F100 static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { if (fs == NULL) { /* no more levels? */ @@ -255,6 +265,7 @@ static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { } +// VERIFY: a20ba1d1 auto // OFFSET: 0x0085F1F0 static void singlevar (LexState *ls, expdesc *var) { TString *varname = str_checkname(ls); @@ -264,6 +275,7 @@ static void singlevar (LexState *ls, expdesc *var) { } +// VERIFY: 85d4db83 manual // OFFSET: 0x0085F250 static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { FuncState *fs = ls->fs; @@ -305,6 +317,7 @@ static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) { } +// VERIFY: eb60dbd1 auto // OFFSET: 0x0085F2C0 static void leaveblock (FuncState *fs) { BlockCnt *bl = fs->bl; @@ -320,6 +333,7 @@ static void leaveblock (FuncState *fs) { } +// VERIFY: ed4dc3dc manual // OFFSET: 0x0085F310 static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { FuncState *fs = ls->fs; @@ -339,6 +353,7 @@ static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { } +// VERIFY: 6ee8cacb auto // OFFSET: 0x0085F410 static void open_func (LexState *ls, FuncState *fs) { lua_State *L = ls->L; @@ -368,6 +383,7 @@ static void open_func (LexState *ls, FuncState *fs) { } +// VERIFY: 51baea49 manual // OFFSET: 0x0085F4E0 static void close_func (LexState *ls) { lua_State *L = ls->L; @@ -396,6 +412,7 @@ static void close_func (LexState *ls) { } +// VERIFY: a0a4435a auto // OFFSET: 0x00861AD0 Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { struct LexState lexstate; @@ -432,6 +449,7 @@ static void field (LexState *ls, expdesc *v) { } +// VERIFY: 5e43705a auto // OFFSET: 0x0085F6C0 static void yindex (LexState *ls, expdesc *v) { /* index -> '[' expr ']' */ @@ -458,6 +476,7 @@ struct ConsControl { }; +// VERIFY: 961f8564 auto // OFFSET: 0x0085F710 static void recfield (LexState *ls, struct ConsControl *cc) { /* recfield -> (NAME | `['exp1`]') = exp1 */ @@ -491,6 +510,7 @@ static void closelistfield (FuncState *fs, struct ConsControl *cc) { } +// VERIFY: e1e230ca auto // OFFSET: 0x0085F7E0 static void lastlistfield (FuncState *fs, struct ConsControl *cc) { if (cc->tostore == 0) return; @@ -515,6 +535,7 @@ static void listfield (LexState *ls, struct ConsControl *cc) { } +// VERIFY: 1c42aa53 manual // OFFSET: 0x0085F840 static void constructor (LexState *ls, expdesc *t) { /* constructor -> ?? */ @@ -561,6 +582,7 @@ static void constructor (LexState *ls, expdesc *t) { +// VERIFY: 3070dabc manual // OFFSET: 0x0085FAA0 static void parlist (LexState *ls) { /* parlist -> [ param { `,' param } ] */ @@ -595,6 +617,7 @@ static void parlist (LexState *ls) { } +// VERIFY: cbcd6830 manual // OFFSET: 0x0085FBD0 static void body (LexState *ls, expdesc *e, int needself, int line) { /* body -> `(' parlist `)' chunk END */ @@ -616,6 +639,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { } +// VERIFY: b9e04529 auto // OFFSET: 0x0085FD10 static int explist1 (LexState *ls, expdesc *v) { /* explist1 -> expr { `,' expr } */ @@ -630,6 +654,7 @@ static int explist1 (LexState *ls, expdesc *v) { } +// VERIFY: 4c392e50 auto // OFFSET: 0x0085FD50 static void funcargs (LexState *ls, expdesc *f) { FuncState *fs = ls->fs; @@ -689,6 +714,7 @@ static void funcargs (LexState *ls, expdesc *f) { */ +// VERIFY: e5dce860 auto // OFFSET: 0x0085FE90 static void prefixexp (LexState *ls, expdesc *v) { /* prefixexp -> NAME | '(' expr ')' */ @@ -713,6 +739,7 @@ static void prefixexp (LexState *ls, expdesc *v) { } +// VERIFY: 18ba2668 manual // OFFSET: 0x0085FF00 static void primaryexp (LexState *ls, expdesc *v) { /* primaryexp -> @@ -751,6 +778,7 @@ static void primaryexp (LexState *ls, expdesc *v) { } +// VERIFY: c2ffa1de manual // OFFSET: 0x008601E0 static void simpleexp (LexState *ls, expdesc *v) { /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | @@ -813,6 +841,7 @@ static UnOpr getunopr (int op) { } +// VERIFY: 37c0c307 auto // OFFSET: 0x008603C0 static BinOpr getbinopr (int op) { switch (op) { @@ -854,6 +883,7 @@ static const struct { ** subexpr -> (simpleexp | unop subexpr) { binop subexpr } ** where `binop' is any binary operator with a priority higher than `limit' */ +// VERIFY: b24fdfdf manual // OFFSET: 0x00860570 static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { BinOpr op; @@ -908,6 +938,7 @@ static int block_follow (int token) { } +// VERIFY: 3205c680 auto // OFFSET: 0x00860680 static void block (LexState *ls) { /* block -> chunk */ @@ -936,6 +967,7 @@ struct LHS_assign { ** local value in a safe place and use this safe copy in the previous ** assignment. */ +// VERIFY: abfb6f9e auto // OFFSET: 0x00860700 static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { FuncState *fs = ls->fs; @@ -960,6 +992,7 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { } +// VERIFY: 0679eb88 manual // OFFSET: 0x00860760 static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { expdesc e; @@ -1003,6 +1036,7 @@ static int cond (LexState *ls) { } +// VERIFY: dc0a1f4f auto // OFFSET: 0x00860890 static void breakstat (LexState *ls) { FuncState *fs = ls->fs; @@ -1020,6 +1054,7 @@ static void breakstat (LexState *ls) { } +// VERIFY: 969fd4bc manual // OFFSET: 0x008608F0 static void whilestat (LexState *ls, int line) { /* whilestat -> WHILE cond DO block END */ @@ -1040,6 +1075,7 @@ static void whilestat (LexState *ls, int line) { } +// VERIFY: 601f0d4d auto // OFFSET: 0x00860A10 static void repeatstat (LexState *ls, int line) { /* repeatstat -> REPEAT block UNTIL cond */ @@ -1077,6 +1113,7 @@ static int exp1 (LexState *ls) { } +// VERIFY: f8c587c4 auto // OFFSET: 0x00860B50 static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { /* forbody -> DO block */ @@ -1099,6 +1136,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { } +// VERIFY: 2589dc53 manual // OFFSET: 0x00860CE0 static void fornum (LexState *ls, TString *varname, int line) { /* fornum -> NAME = exp1,exp1[,exp1] forbody */ @@ -1122,6 +1160,7 @@ static void fornum (LexState *ls, TString *varname, int line) { } +// VERIFY: 07096f20 manual // OFFSET: 0x00860F10 static void forlist (LexState *ls, TString *indexname) { /* forlist -> NAME {,NAME} IN explist1 forbody */ @@ -1146,6 +1185,7 @@ static void forlist (LexState *ls, TString *indexname) { } +// VERIFY: d7e59c1b manual // OFFSET: 0x00861190 static void forstat (LexState *ls, int line) { /* forstat -> FOR (fornum | forlist) END */ @@ -1165,6 +1205,7 @@ static void forstat (LexState *ls, int line) { } +// VERIFY: a7f69301 auto // OFFSET: 0x008612B0 static int test_then_block (LexState *ls) { /* test_then_block -> [IF | ELSEIF] cond THEN block */ @@ -1177,6 +1218,7 @@ static int test_then_block (LexState *ls) { } +// VERIFY: 9b44f0b0 auto // OFFSET: 0x00861330 static void ifstat (LexState *ls, int line) { /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ @@ -1202,6 +1244,7 @@ static void ifstat (LexState *ls, int line) { } +// VERIFY: caa5ac31 manual // OFFSET: 0x008613F0 static void localfunc (LexState *ls) { expdesc v, b; @@ -1217,6 +1260,7 @@ static void localfunc (LexState *ls) { } +// VERIFY: 11a5141c manual // OFFSET: 0x00861500 static void localstat (LexState *ls) { /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */ @@ -1237,6 +1281,7 @@ static void localstat (LexState *ls) { } +// VERIFY: 740f0322 manual // OFFSET: 0x00861620 static int funcname (LexState *ls, expdesc *v) { /* funcname -> NAME {field} [`:' NAME] */ @@ -1252,6 +1297,7 @@ static int funcname (LexState *ls, expdesc *v) { } +// VERIFY: 0d1c3aaa auto // OFFSET: 0x00861710 static void funcstat (LexState *ls, int line) { /* funcstat -> FUNCTION funcname body */ @@ -1265,6 +1311,7 @@ static void funcstat (LexState *ls, int line) { } +// VERIFY: e9ab0961 auto // OFFSET: 0x00861760 static void exprstat (LexState *ls) { /* stat -> func | assignment */ @@ -1280,6 +1327,7 @@ static void exprstat (LexState *ls) { } +// VERIFY: 701a88f7 manual // OFFSET: 0x008617C0 static void retstat (LexState *ls) { /* stat -> RETURN explist */ @@ -1314,6 +1362,7 @@ static void retstat (LexState *ls) { } +// VERIFY: 5f951872 manual // OFFSET: 0x008618E0 static int statement (LexState *ls) { int line = ls->linenumber; /* may be needed for error messages */ @@ -1369,6 +1418,7 @@ static int statement (LexState *ls) { } +// VERIFY: ed6868c7 manual // OFFSET: 0x00861A20 static void chunk (LexState *ls) { /* chunk -> { stat [`;'] } */ diff --git a/Engine/Source/lua-5.1/src/lstate.c b/Engine/Source/lua-5.1/src/lstate.c index 0d2fa16..a825ee4 100644 --- a/Engine/Source/lua-5.1/src/lstate.c +++ b/Engine/Source/lua-5.1/src/lstate.c @@ -39,6 +39,7 @@ typedef struct LG { +// VERIFY: e41fde60 auto // OFFSET: 0x00855090 static void stack_init (lua_State *L1, lua_State *L) { /* initialize CallInfo array */ @@ -68,6 +69,7 @@ static void freestack (lua_State *L, lua_State *L1) { /* ** open parts that may cause memory-allocation errors */ +// VERIFY: 3be76c95 manual // OFFSET: 0x00855120 static void f_luaopen (lua_State *L, void *ud) { global_State *g = G(L); @@ -100,10 +102,12 @@ static void preinit_state (lua_State *L, global_State *g) { L->base_ci = L->ci = NULL; L->savedpc = NULL; L->errfunc = 0; + L->externalabort = 0; setnilvalue(gt(L)); } +// VERIFY: 8117eaae manual // OFFSET: 0x008551B0 static void close_state (lua_State *L) { global_State *g = G(L); @@ -119,6 +123,7 @@ static void close_state (lua_State *L) { } +// VERIFY: 4a875a74 manual // OFFSET: 0x00855240 lua_State *luaE_newthread (lua_State *L) { lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); @@ -135,6 +140,7 @@ lua_State *luaE_newthread (lua_State *L) { } +// VERIFY: 912021b9 manual // OFFSET: 0x00855310 void luaE_freethread (lua_State *L, lua_State *L1) { luaF_close(L1, L1->stack); /* close all upvalues for this thread */ @@ -145,8 +151,9 @@ void luaE_freethread (lua_State *L, lua_State *L1) { } +// VERIFY: fdf620e9 manual // OFFSET: 0x00855370 -LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { +LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, int profile) { int i; lua_State *L; global_State *g; @@ -156,7 +163,9 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g = &((LG *)L)->g; L->next = NULL; L->tt = LUA_TTHREAD; + L->taint = (lua_tainted && lua_gctag) ? lua_gctag : lua_tainted; g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); + g->profile = (profile != 0); L->marked = luaC_white(g); set2bits(L->marked, FIXEDBIT, SFIXEDBIT); preinit_state(L, g); @@ -196,6 +205,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { } +// VERIFY: 428df4f0 auto // OFFSET: 0x008554F0 static void callallgcTM (lua_State *L, void *ud) { UNUSED(ud); @@ -203,6 +213,7 @@ static void callallgcTM (lua_State *L, void *ud) { } +// VERIFY: 6dce8f12 auto // OFFSET: 0x00855510 LUA_API void lua_close (lua_State *L) { L = G(L)->mainthread; /* only the main thread can be closed */ diff --git a/Engine/Source/lua-5.1/src/lstate.h b/Engine/Source/lua-5.1/src/lstate.h index d296a4c..b410811 100644 --- a/Engine/Source/lua-5.1/src/lstate.h +++ b/Engine/Source/lua-5.1/src/lstate.h @@ -65,10 +65,25 @@ typedef struct CallInfo { /* ** `global state', shared by all threads of this state */ +typedef struct GCUsage { + const char *tag; + lu_mem usage; + struct GCUsage *next; +} GCUsage; + + +typedef struct GCTime { + const char *tag; + __int64 time; + struct GCTime *next; +} GCTime; + + typedef struct global_State { stringtable strt; /* hash table for strings */ lua_Alloc frealloc; /* function to reallocate memory */ void *ud; /* auxiliary data to `frealloc' */ + lu_byte profile; lu_byte currentwhite; lu_byte gcstate; /* state of garbage collector */ int sweepstrgc; /* position of sweep in `strt' */ @@ -85,6 +100,8 @@ typedef struct global_State { lu_mem gcdept; /* how much GC is `behind schedule' */ int gcpause; /* size of pause between successive GCs */ int gcstepmul; /* GC `granularity' */ + GCUsage *gcusage; + GCTime *gctime; lua_CFunction panic; /* to be called in unprotected errors */ TValue l_registry; struct lua_State *mainthread; @@ -123,6 +140,7 @@ struct lua_State { GCObject *gclist; struct lua_longjmp *errorJmp; /* current error recover point */ ptrdiff_t errfunc; /* current error handling function (stack index) */ + int externalabort; }; diff --git a/Engine/Source/lua-5.1/src/lstring.c b/Engine/Source/lua-5.1/src/lstring.c index b5c2438..08be303 100644 --- a/Engine/Source/lua-5.1/src/lstring.c +++ b/Engine/Source/lua-5.1/src/lstring.c @@ -19,6 +19,7 @@ +// VERIFY: d46cd6e1 manual // OFFSET: 0x00856AF0 void luaS_resize (lua_State *L, int newsize) { GCObject **newhash; @@ -48,6 +49,7 @@ void luaS_resize (lua_State *L, int newsize) { } +// VERIFY: 5d05abd3 auto // OFFSET: 0x00856BC0 static TString *newlstr (lua_State *L, const char *str, size_t l, unsigned int h) { @@ -60,6 +62,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, ts->tsv.hash = h; ts->tsv.marked = luaC_white(G(L)); ts->tsv.tt = LUA_TSTRING; + ts->tsv.taint = (lua_tainted && lua_gctag) ? lua_gctag : lua_tainted; ts->tsv.reserved = 0; memcpy(ts+1, str, l*sizeof(char)); ((char *)(ts+1))[l] = '\0'; /* ending 0 */ @@ -74,6 +77,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, } +// VERIFY: d0824852 manual // OFFSET: 0x00856C80 TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { GCObject *o; @@ -96,6 +100,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { } +// VERIFY: 9451fe49 auto // OFFSET: 0x00856DD0 Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { Udata *u; @@ -104,6 +109,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); u->uv.marked = luaC_white(G(L)); /* is not finalized */ u->uv.tt = LUA_TUSERDATA; + u->uv.taint = (lua_tainted && lua_gctag) ? lua_gctag : lua_tainted; u->uv.len = s; u->uv.metatable = NULL; u->uv.env = e; diff --git a/Engine/Source/lua-5.1/src/lstrlib.c b/Engine/Source/lua-5.1/src/lstrlib.c index 6bcd9c3..096a161 100644 --- a/Engine/Source/lua-5.1/src/lstrlib.c +++ b/Engine/Source/lua-5.1/src/lstrlib.c @@ -19,12 +19,15 @@ #include "lauxlib.h" #include "lualib.h" +#include "Engine/Source/Base/ConvertUTF.h" + /* macro to `unsign' a character */ #define uchar(c) ((unsigned char)(c)) +// VERIFY: e3174524 auto // OFFSET: 0x00852400 static int str_len (lua_State *L) { size_t l; @@ -40,6 +43,7 @@ static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { } +// VERIFY: 6a340463 manual // OFFSET: 0x00852430 static int str_sub (lua_State *L) { size_t l; @@ -55,6 +59,7 @@ static int str_sub (lua_State *L) { } +// VERIFY: 374d96af manual // OFFSET: 0x008524E0 static int str_reverse (lua_State *L) { size_t l; @@ -67,33 +72,60 @@ static int str_reverse (lua_State *L) { } +// VERIFY: 3a9f7a03 manual // OFFSET: 0x00852580 static int str_lower (lua_State *L) { size_t l; size_t i; + int n; luaL_Buffer b; const char *s = luaL_checklstring(L, 1, &l); luaL_buffinit(L, &b); - for (i=0; i= 'A' && c <= 'Z') || (c >= 0xC0 && c <= 0xDE) || (c >= 0x410 && c <= 0x42F)) + c += 32; + else if (c == 0x401) + c = 0x451; + e = sputu8(c, buff); + for (p=buff; p= 'a' && c <= 'z') || (c >= 0xE0 && c <= 0xFE) || (c >= 0x430 && c <= 0x44F)) + c -= 32; + else if (c == 0x451) + c = 0x401; + e = sputu8(c, buff); + for (p=buff; p= sizeof(FLAGS)) - luaL_error(L, "invalid format (repeated flags)"); - if (isdigit(uchar(*p))) p++; /* skip width */ - if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ - if (*p == '.') { - p++; - if (isdigit(uchar(*p))) p++; /* skip precision */ - if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ - } - if (isdigit(uchar(*p))) - luaL_error(L, "invalid format (width or precision too long)"); - *(form++) = '%'; - strncpy(form, strfrmt, p - strfrmt + 1); - form += p - strfrmt + 1; - *form = '\0'; - return p; -} - - static void addintlen (char *form) { size_t l = strlen(form); char spec = form[l - 1]; @@ -785,6 +822,7 @@ static void addintlen (char *form) { } +// VERIFY: 17947359 manual // OFFSET: 0x00853C50 static int str_format (lua_State *L) { int arg = 1; @@ -801,8 +839,31 @@ static int str_format (lua_State *L) { else { /* format item */ char form[MAX_FORMAT]; /* to store the format (`%...') */ char buff[MAX_ITEM]; /* to store the formatted item */ + const char *p = strfrmt; + const char *e; + MatchState ms; + if (isdigit(uchar(*strfrmt))) { + if (strfrmt[1] == '$') { + arg = *strfrmt - '0'; + p = strfrmt + 2; + } + else if (isdigit(uchar(strfrmt[1])) && strfrmt[2] == '$') { + arg = (strfrmt[0] - '0') * 10 + (strfrmt[1] - '0'); + p = strfrmt + 3; + } + } arg++; - strfrmt = scanformat(L, strfrmt, form); + ms.L = L; + ms.src_init = strfrmt; + ms.src_end = strfrmt + strlen(strfrmt) + 1; + ms.level = 0; + e = match(&ms, p, "[-+ #0]*(%d*)%.?(%d*)"); + if (ms.capture[0].len > 2 || ms.capture[1].len > 2 || (size_t)(e - p) > 16) + luaL_error(L, "invalid format (width or precision too long)"); + form[0] = L_ESC; + strncpy(form + 1, p, e - p + 1); + form[e - p + 2] = '\0'; + strfrmt = e; switch (*strfrmt++) { case 'c': { sprintf(buff, form, (int)luaL_checknumber(L, arg)); @@ -823,6 +884,14 @@ static int str_format (lua_State *L) { sprintf(buff, form, (double)luaL_checknumber(L, arg)); break; } + case 'F': { + char *f; + for (f = form; *f; f++) + if (*f == 'F') *f = 'f'; + sprintf(buff, form, (double)luaL_checknumber(L, arg)); + lua_convertdecimal(buff); + break; + } case 'q': { addquoted(L, &b, arg); continue; /* skip the 'addsize' at the end */ @@ -830,7 +899,7 @@ static int str_format (lua_State *L) { case 's': { size_t l; const char *s = luaL_checklstring(L, arg, &l); - if (!strchr(form, '.') && l >= 100) { + if (ms.capture[1].len == 0 && l >= 100) { /* no precision and string is too long to be formatted; keep original string */ lua_pushvalue(L, arg); @@ -843,8 +912,7 @@ static int str_format (lua_State *L) { } } default: { /* also treat cases `pnLlh' */ - return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " - LUA_QL("format"), *(strfrmt - 1)); + return luaL_error(L, "invalid option in `format'"); } } luaL_addlstring(&b, buff, strlen(buff)); @@ -875,6 +943,7 @@ static const luaL_Reg strlib[] = { }; +// VERIFY: 94f001c1 auto // OFFSET: 0x00854070 static void createmetatable (lua_State *L) { lua_createtable(L, 0, 1); /* create metatable for strings */ @@ -891,6 +960,7 @@ static void createmetatable (lua_State *L) { /* ** Open string library */ +// VERIFY: 6c58c0c9 auto // OFFSET: 0x008540D0 LUALIB_API int luaopen_string (lua_State *L) { luaL_register(L, LUA_STRLIBNAME, strlib); diff --git a/Engine/Source/lua-5.1/src/ltable.c b/Engine/Source/lua-5.1/src/ltable.c index ddbcfd5..4ca9748 100644 --- a/Engine/Source/lua-5.1/src/ltable.c +++ b/Engine/Source/lua-5.1/src/ltable.c @@ -81,6 +81,7 @@ static const Node dummynode_ = { /* ** hash for lua_Numbers */ +// VERIFY: 494a25a9 auto // OFFSET: 0x0085BC70 static Node *hashnum (const Table *t, lua_Number n) { unsigned int a[numints]; @@ -98,6 +99,7 @@ static Node *hashnum (const Table *t, lua_Number n) { ** returns the `main' position of an element in a table (that is, the index ** of its hash value) */ +// VERIFY: 94126f53 auto // OFFSET: 0x0085BCB0 static Node *mainposition (const Table *t, const TValue *key) { switch (ttype(key)) { @@ -136,6 +138,7 @@ static int arrayindex (const TValue *key) { ** elements in the array part, then elements in the hash part. The ** beginning of a traversal is signalled by -1. */ +// VERIFY: 83083ac7 manual // OFFSET: 0x0085BD70 static int findindex (lua_State *L, Table *t, StkId key) { int i; @@ -162,6 +165,7 @@ static int findindex (lua_State *L, Table *t, StkId key) { } +// VERIFY: b364618e auto // OFFSET: 0x0085BE30 int luaH_next (lua_State *L, Table *t, StkId key) { int i = findindex(L, t, key); /* find original element */ @@ -190,6 +194,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) { */ +// VERIFY: 0b4dfe9e manual // OFFSET: 0x0085BFD0 static int computesizes (int nums[], int *narray) { int i; @@ -224,6 +229,7 @@ static int countint (const TValue *key, int *nums) { } +// VERIFY: 446ee671 manual // OFFSET: 0x0085C050 static int numusearray (const Table *t, int *nums) { int lg; @@ -250,6 +256,7 @@ static int numusearray (const Table *t, int *nums) { } +// VERIFY: 7ceef321 manual // OFFSET: 0x0085C0D0 static int numusehash (const Table *t, int *nums, int *pnasize) { int totaluse = 0; /* total number of elements */ @@ -267,6 +274,7 @@ static int numusehash (const Table *t, int *nums, int *pnasize) { } +// VERIFY: 7df452d2 manual // OFFSET: 0x0085C190 static void setarrayvector (lua_State *L, Table *t, int size) { int i; @@ -277,6 +285,7 @@ static void setarrayvector (lua_State *L, Table *t, int size) { } +// VERIFY: 60f7338e manual // OFFSET: 0x0085C200 static void setnodevector (lua_State *L, Table *t, int size) { int lsize; @@ -294,7 +303,7 @@ static void setnodevector (lua_State *L, Table *t, int size) { for (i=0; isizearray; int oldhsize = t->lsizenode; Node *nold = t->node; /* save old hash ... */ + int oldexpected = lua_taintexpected; + const char *oldtaint = lua_tainted; + lua_taintexpected = 0; + lua_tainted = NULL; if (nasize > oldasize) /* array part must grow? */ setarrayvector(L, t, nasize); /* create new hash part with appropriate size */ @@ -331,9 +345,12 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) { } if (nold != dummynode) luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ + lua_tainted = oldtaint; + lua_taintexpected = oldexpected; } +// VERIFY: d3ad83eb manual // OFFSET: 0x0085C960 void luaH_resizearray (lua_State *L, Table *t, int nasize) { int nsize = (t->node == dummynode) ? 0 : sizenode(t); @@ -341,6 +358,7 @@ void luaH_resizearray (lua_State *L, Table *t, int nasize) { } +// VERIFY: 8ba09363 manual // OFFSET: 0x0085C9B0 static void rehash (lua_State *L, Table *t, const TValue *ek) { int nasize, na; @@ -367,6 +385,7 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) { */ +// VERIFY: 5980269e manual // OFFSET: 0x0085C2E0 Table *luaH_new (lua_State *L, int narray, int nhash) { Table *t = luaM_new(L, Table); @@ -384,6 +403,7 @@ Table *luaH_new (lua_State *L, int narray, int nhash) { } +// VERIFY: c2c96774 manual // OFFSET: 0x0085C340 void luaH_free (lua_State *L, Table *t) { if (t->node != dummynode) @@ -410,6 +430,7 @@ static Node *getfreepos (Table *t) { ** put new key in its main position; otherwise (colliding node is in its main ** position), new key goes to an empty position. */ +// VERIFY: 87a10331 manual // OFFSET: 0x0085CAB0 static TValue *newkey (lua_State *L, Table *t, const TValue *key) { Node *mp = mainposition(t, key); @@ -447,6 +468,7 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) { /* ** search function for integers */ +// VERIFY: 618e0105 auto // OFFSET: 0x0085C3A0 const TValue *luaH_getnum (Table *t, int key) { /* (1 <= key && key <= t->sizearray) */ @@ -468,6 +490,7 @@ const TValue *luaH_getnum (Table *t, int key) { /* ** search function for strings */ +// VERIFY: 66b1ffe7 auto // OFFSET: 0x0085C430 const TValue *luaH_getstr (Table *t, TString *key) { Node *n = hashstr(t, key); @@ -483,6 +506,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { /* ** main search function */ +// VERIFY: 1c0749e3 auto // OFFSET: 0x0085C470 const TValue *luaH_get (Table *t, const TValue *key) { switch (ttype(key)) { @@ -509,6 +533,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { } +// VERIFY: 32007b3c manual // OFFSET: 0x0085C520 TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { const TValue *p = luaH_get(t, key); @@ -524,6 +549,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { } +// VERIFY: 6c82f50e auto // OFFSET: 0x0085C590 TValue *luaH_setnum (lua_State *L, Table *t, int key) { const TValue *p = luaH_getnum(t, key); @@ -537,6 +563,7 @@ TValue *luaH_setnum (lua_State *L, Table *t, int key) { } +// VERIFY: 969b1564 auto // OFFSET: 0x0085CBC0 TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { const TValue *p = luaH_getstr(t, key); @@ -550,6 +577,7 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { } +// VERIFY: 0db1730b auto // OFFSET: 0x0085C5E0 static int unbound_search (Table *t, unsigned int j) { unsigned int i = j; /* i is zero or a present index */ @@ -579,6 +607,7 @@ static int unbound_search (Table *t, unsigned int j) { ** Try to find a boundary in table `t'. A `boundary' is an integer index ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). */ +// VERIFY: ade11de4 manual // OFFSET: 0x0085C690 int luaH_getn (Table *t) { unsigned int j = t->sizearray; diff --git a/Engine/Source/lua-5.1/src/ltablib.c b/Engine/Source/lua-5.1/src/ltablib.c index a2fab47..4a41f94 100644 --- a/Engine/Source/lua-5.1/src/ltablib.c +++ b/Engine/Source/lua-5.1/src/ltablib.c @@ -19,6 +19,7 @@ #define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) +// VERIFY: 95512ac3 auto // OFFSET: 0x008517C0 static int foreachi (lua_State *L) { int i; @@ -37,6 +38,7 @@ static int foreachi (lua_State *L) { } +// VERIFY: 148a87d7 auto // OFFSET: 0x00851850 static int foreach (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); @@ -55,6 +57,7 @@ static int foreach (lua_State *L) { } +// VERIFY: dcfec438 auto // OFFSET: 0x008518E0 static int maxn (lua_State *L) { lua_Number max = 0; @@ -72,6 +75,7 @@ static int maxn (lua_State *L) { } +// VERIFY: 7ae20129 auto // OFFSET: 0x00851980 static int getn (lua_State *L) { lua_pushinteger(L, aux_getn(L, 1)); @@ -79,6 +83,7 @@ static int getn (lua_State *L) { } +// VERIFY: 84ba01f6 manual // OFFSET: 0x008519B0 static int setn (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); @@ -92,6 +97,7 @@ static int setn (lua_State *L) { } +// VERIFY: e33fbef7 auto // OFFSET: 0x008519E0 static int tinsert (lua_State *L) { int e = aux_getn(L, 1) + 1; /* first empty element */ @@ -121,6 +127,7 @@ static int tinsert (lua_State *L) { } +// VERIFY: 4b813f67 auto // OFFSET: 0x00851A90 static int tremove (lua_State *L) { int e = aux_getn(L, 1); @@ -138,6 +145,32 @@ static int tremove (lua_State *L) { } +// VERIFY: f621cee7 manual +// OFFSET: 0x00851B20 +static int tremovemulti (lua_State *L) { + int e = aux_getn(L, 1); + int pos = luaL_optint(L, 2, e); + int n = luaL_optint(L, 3, 1); + int i; + if (e == 0) return 0; + if (pos <= 0 || n < 0 || pos > e || pos + n - 1 > e) + luaL_error(L, "parameters out of bounds"); + lua_checkstack(L, n); + for (i = pos; i < pos + n; i++) + lua_rawgeti(L, 1, i); + for ( ; pos < e; pos++) { + lua_rawgeti(L, 1, pos + n); + lua_rawseti(L, 1, pos); + } + for ( ; pos < e + n; pos++) { + lua_pushnil(L); + lua_rawseti(L, 1, pos); + } + return n; +} + + +// VERIFY: 371cb669 auto // OFFSET: 0x00851C30 static int tconcat (lua_State *L) { luaL_Buffer b; @@ -189,6 +222,7 @@ static int sort_comp (lua_State *L, int a, int b) { return lua_lessthan(L, a, b); } +// VERIFY: 4db52c72 auto // OFFSET: 0x00851D20 static void auxsort (lua_State *L, int l, int u) { while (l < u) { /* for tail recursion */ @@ -253,6 +287,7 @@ static void auxsort (lua_State *L, int l, int u) { } /* repeat the routine for the larger one */ } +// VERIFY: 2636f99f auto // OFFSET: 0x00852120 static int sort (lua_State *L) { int n = aux_getn(L, 1); @@ -264,6 +299,22 @@ static int sort (lua_State *L) { return 0; } + +// VERIFY: 3133ac54 auto +// OFFSET: 0x00852180 +static int twipe (lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checkstack(L, 3, ""); + lua_pushnil(L); + while (lua_next(L, -2)) { + lua_pop(L, 1); + lua_pushvalue(L, -1); + lua_pushnil(L); + lua_rawset(L, 1); + } + return 1; +} + /* }====================================================== */ @@ -275,12 +326,15 @@ static const luaL_Reg tab_funcs[] = { {"maxn", maxn}, {"insert", tinsert}, {"remove", tremove}, + {"removemulti", tremovemulti}, {"setn", setn}, {"sort", sort}, + {"wipe", twipe}, {NULL, NULL} }; +// VERIFY: 59d8400c auto // OFFSET: 0x008521F0 LUALIB_API int luaopen_table (lua_State *L) { luaL_register(L, LUA_TABLIBNAME, tab_funcs); diff --git a/Engine/Source/lua-5.1/src/ltm.c b/Engine/Source/lua-5.1/src/ltm.c index c078628..df7706f 100644 --- a/Engine/Source/lua-5.1/src/ltm.c +++ b/Engine/Source/lua-5.1/src/ltm.c @@ -27,6 +27,7 @@ const char *const luaT_typenames[] = { }; +// VERIFY: 906a05c7 auto // OFFSET: 0x0085BB70 void luaT_init (lua_State *L) { static const char *const luaT_eventname[] = { /* ORDER TM */ @@ -48,6 +49,7 @@ void luaT_init (lua_State *L) { ** function to be used with macro "fasttm": optimized for absence of ** tag methods */ +// VERIFY: 78511cd5 auto // OFFSET: 0x0085BBE0 const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { const TValue *tm = luaH_getstr(events, ename); @@ -60,6 +62,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { } +// VERIFY: c9dbc6d4 auto // OFFSET: 0x0085BC10 const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { Table *mt; diff --git a/Engine/Source/lua-5.1/src/lua.h b/Engine/Source/lua-5.1/src/lua.h index 064ff6f..142da89 100644 --- a/Engine/Source/lua-5.1/src/lua.h +++ b/Engine/Source/lua-5.1/src/lua.h @@ -104,10 +104,30 @@ typedef LUA_INTEGER lua_Integer; +LUA_API const char *lua_tainted; +LUA_API int lua_taintexpected; +LUA_API int lua_taintedclosure; +LUA_API const char *lua_closuretaint; +LUA_API const char *lua_gctag; + +typedef void (*lua_TaintEventCallback) (lua_State *L, int event, const char *name, const char *taint); +LUA_API lua_TaintEventCallback lua_tainteventcallback; + +LUA_API void (lua_setdecimalconversion) (int convert); +LUA_API void (lua_convertdecimal) (char *s); +LUA_API void (lua_settaint) (lua_State *L, int idx, const char *taint); +LUA_API void (lua_gcupdatesizes) (lua_State *L); +LUA_API size_t (lua_gcgetsize) (lua_State *L, const char *tag); +LUA_API void (lua_gcupdatetimes) (lua_State *L); +LUA_API double (lua_gcgettime) (lua_State *L, const char *tag); +LUA_API void (lua_gcgetfunctiontime) (lua_State *L, double *time, double *totaltime, int *calls); +LUA_API void (lua_gcresettimes) (lua_State *L); + + /* ** state manipulation */ -LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); +LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud, int profile); LUA_API void (lua_close) (lua_State *L); LUA_API lua_State *(lua_newthread) (lua_State *L); @@ -273,7 +293,7 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); #define lua_pushliteral(L, s) \ lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) -#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) +#define lua_setglobal(L,s) (lua_pushstring(L, s), lua_insert(L, -2), lua_rawset(L, LUA_GLOBALSINDEX)) #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) diff --git a/Engine/Source/lua-5.1/src/luaconf.h b/Engine/Source/lua-5.1/src/luaconf.h index f32f1f7..5ebb9bc 100644 --- a/Engine/Source/lua-5.1/src/luaconf.h +++ b/Engine/Source/lua-5.1/src/luaconf.h @@ -161,7 +161,7 @@ #else -#define LUA_API extern +#define LUA_API extern "C" #endif @@ -188,8 +188,8 @@ #define LUAI_DATA LUAI_FUNC #else -#define LUAI_FUNC extern -#define LUAI_DATA extern +#define LUAI_FUNC extern "C" +#define LUAI_DATA extern "C" #endif @@ -333,14 +333,14 @@ ** CHANGE it to undefined as soon as your programs use only '...' to ** access vararg parameters (instead of the old 'arg' table). */ -#define LUA_COMPAT_VARARG +#undef LUA_COMPAT_VARARG /* @@ LUA_COMPAT_MOD controls compatibility with old math.mod function. ** CHANGE it to undefined as soon as your programs use 'math.fmod' or ** the new '%' operator instead of 'math.mod'. */ -#define LUA_COMPAT_MOD +#undef LUA_COMPAT_MOD /* @@ LUA_COMPAT_LSTR controls compatibility with old long string nesting @@ -355,7 +355,7 @@ ** CHANGE it to undefined as soon as you rename 'string.gfind' to ** 'string.gmatch'. */ -#define LUA_COMPAT_GFIND +#undef LUA_COMPAT_GFIND /* @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' @@ -591,7 +591,7 @@ union luai_Cast { double l_d; long l_l; }; ** aligned in 16-byte boundaries, then you should add long double in the ** union.) Probably you do not need to change this. */ -#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } +#define LUAI_USER_ALIGNMENT_T union { void *s; long l; } /* @@ -602,14 +602,7 @@ union luai_Cast { double l_d; long l_l; }; ** compiling as C++ code, with _longjmp/_setjmp when asked to use them, ** and with longjmp/setjmp otherwise. */ -#if defined(__cplusplus) -/* C++ exceptions */ -#define LUAI_THROW(L,c) throw(c) -#define LUAI_TRY(L,c,a) try { a } catch(...) \ - { if ((c)->status == 0) (c)->status = -1; } -#define luai_jmpbuf int /* dummy variable */ - -#elif defined(LUA_USE_ULONGJMP) +#if defined(LUA_USE_ULONGJMP) /* in Unix, try _longjmp/_setjmp (more efficient) */ #define LUAI_THROW(L,c) _longjmp((c)->b, 1) #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } diff --git a/Engine/Source/lua-5.1/src/lualib.h b/Engine/Source/lua-5.1/src/lualib.h index 0c76232..610b1f3 100644 --- a/Engine/Source/lua-5.1/src/lualib.h +++ b/Engine/Source/lua-5.1/src/lualib.h @@ -33,6 +33,8 @@ LUALIB_API int (luaopen_string) (lua_State *L); #define LUA_MATHLIBNAME "math" LUALIB_API int (luaopen_math) (lua_State *L); +LUALIB_API int (luaopen_bit) (lua_State *L); + #define LUA_DBLIBNAME "debug" LUALIB_API int (luaopen_debug) (lua_State *L); diff --git a/Engine/Source/lua-5.1/src/lundump.c b/Engine/Source/lua-5.1/src/lundump.c index 58c9efe..14be8fe 100644 --- a/Engine/Source/lua-5.1/src/lundump.c +++ b/Engine/Source/lua-5.1/src/lundump.c @@ -207,6 +207,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) /* * make header */ +// VERIFY: 101b66c4 manual // OFFSET: 0x00861B90 void luaU_header (char* h) { diff --git a/Engine/Source/lua-5.1/src/lvm.c b/Engine/Source/lua-5.1/src/lvm.c index 5de3a8e..9aa7f7e 100644 --- a/Engine/Source/lua-5.1/src/lvm.c +++ b/Engine/Source/lua-5.1/src/lvm.c @@ -26,12 +26,15 @@ #include "ltm.h" #include "lvm.h" +#include "Engine/Source/Os/TimeManager.h" + /* limit for table tag-method chains (to avoid loops) */ #define MAXTAGLOOP 100 +// VERIFY: ea40a3e5 auto // OFFSET: 0x00856E50 const TValue *luaV_tonumber (const TValue *obj, TValue *n) { lua_Number num; @@ -45,6 +48,7 @@ const TValue *luaV_tonumber (const TValue *obj, TValue *n) { } +// VERIFY: 9b749387 auto // OFFSET: 0x00856EA0 int luaV_tostring (lua_State *L, StkId obj) { if (!ttisnumber(obj)) @@ -59,6 +63,7 @@ int luaV_tostring (lua_State *L, StkId obj) { } +// VERIFY: 4b886ea2 auto // OFFSET: 0x00856F10 static void traceexec (lua_State *L, const Instruction *pc) { lu_byte mask = L->hookmask; @@ -82,6 +87,7 @@ static void traceexec (lua_State *L, const Instruction *pc) { } +// VERIFY: 325398ab manual // OFFSET: 0x00856FA0 static void callTMres (lua_State *L, StkId res, const TValue *f, const TValue *p1, const TValue *p2) { @@ -99,6 +105,7 @@ static void callTMres (lua_State *L, StkId res, const TValue *f, +// VERIFY: d2f1154d manual // OFFSET: 0x00857100 static void callTM (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, const TValue *p3) { @@ -112,6 +119,7 @@ static void callTM (lua_State *L, const TValue *f, const TValue *p1, } +// VERIFY: 5eb97f71 manual // OFFSET: 0x00857250 void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { int loop; @@ -122,6 +130,8 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { const TValue *res = luaH_get(h, key); /* do a primitive get */ if (!ttisnil(res) || /* result is no nil? */ (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ + if (lua_tainteventcallback && hvalue(t) == hvalue(gt(L)) && ttisstring(key) && res->taint && !lua_taintedclosure) + lua_tainteventcallback(L, 2, svalue(key), res->taint); setobj2s(L, val, res); return; } @@ -139,6 +149,7 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { } +// VERIFY: 196f9726 auto // OFFSET: 0x008573C0 void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { int loop; @@ -149,6 +160,9 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ if (!ttisnil(oldval) || /* result is no nil? */ (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ + if (lua_tainteventcallback && hvalue(t) == hvalue(gt(L)) && ttisstring(key) && val->taint && + (ttisnil(oldval) || oldval->taint != val->taint)) + lua_tainteventcallback(L, 1, svalue(key), val->taint); setobj2t(L, oldval, val); luaC_barriert(L, h, val); return; @@ -178,6 +192,7 @@ static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, } +// VERIFY: 6a05f302 manual // OFFSET: 0x00857560 static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, TMS event) { @@ -193,6 +208,7 @@ static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, } +// VERIFY: ba681e21 auto // OFFSET: 0x008575F0 static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, TMS event) { @@ -207,6 +223,7 @@ static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, } +// VERIFY: 26fe3a29 auto // OFFSET: 0x00857670 static int l_strcmp (const TString *ls, const TString *rs) { const char *l = getstr(ls); @@ -230,6 +247,7 @@ static int l_strcmp (const TString *ls, const TString *rs) { } +// VERIFY: 0724e599 manual // OFFSET: 0x008576F0 int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { int res; @@ -245,6 +263,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { } +// VERIFY: 400f3668 auto // OFFSET: 0x00857780 static int lessequal (lua_State *L, const TValue *l, const TValue *r) { int res; @@ -262,6 +281,7 @@ static int lessequal (lua_State *L, const TValue *l, const TValue *r) { } +// VERIFY: 9716a7ed auto // OFFSET: 0x00857820 int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { const TValue *tm; @@ -290,6 +310,7 @@ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { } +// VERIFY: 57f59cce manual // OFFSET: 0x00857900 void luaV_concat (lua_State *L, int total, int last) { do { @@ -324,6 +345,7 @@ void luaV_concat (lua_State *L, int total, int last) { } +// VERIFY: 1b6be1d3 manual // OFFSET: 0x00857AD0 static void Arith (lua_State *L, StkId ra, const TValue *rb, const TValue *rc, TMS op) { @@ -385,6 +407,7 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, +// VERIFY: 9399f4b9 manual // OFFSET: 0x00857CA0 void luaV_execute (lua_State *L, int nexeccalls) { LClosure *cl; @@ -395,6 +418,12 @@ void luaV_execute (lua_State *L, int nexeccalls) { lua_assert(isLua(L->ci)); pc = L->savedpc; cl = &clvalue(L->ci->func)->l; + lua_taintedclosure = 0; + if (cl->taint) { + if (lua_taintexpected) + lua_tainted = cl->taint; + lua_taintedclosure = 1; + } base = L->base; k = cl->p->k; /* main loop of interpreter */ @@ -406,10 +435,13 @@ void luaV_execute (lua_State *L, int nexeccalls) { traceexec(L, pc); if (L->status == LUA_YIELD) { /* did hook yield? */ L->savedpc = pc - 1; + lua_taintedclosure = 0; return; } base = L->base; } + if (L->externalabort) + luaG_runerror(L, "external abort"); /* warning!! several calls may realloc the stack and invalidate `ra' */ ra = RA(i); lua_assert(base == L->base && L->base == L->ci->base); @@ -598,6 +630,8 @@ void luaV_execute (lua_State *L, int nexeccalls) { case OP_CALL: { int b = GETARG_B(i); int nresults = GETARG_C(i) - 1; + const char *oldtaint = lua_taintedclosure ? lua_tainted : NULL; + lua_taintedclosure = 0; if (b != 0) L->top = ra+b; /* else previous instruction set top */ L->savedpc = pc; switch (luaD_precall(L, ra, nresults)) { @@ -609,6 +643,13 @@ void luaV_execute (lua_State *L, int nexeccalls) { /* it was a C function (`precall' called it); adjust results */ if (nresults >= 0) L->top = L->ci->top; base = L->base; + if (oldtaint) { + if (lua_taintexpected) + lua_tainted = oldtaint; + lua_taintedclosure = 1; + } + else + lua_taintedclosure = 0; continue; } default: { @@ -618,6 +659,8 @@ void luaV_execute (lua_State *L, int nexeccalls) { } case OP_TAILCALL: { int b = GETARG_B(i); + const char *oldtaint = lua_taintedclosure ? lua_tainted : NULL; + lua_taintedclosure = 0; if (b != 0) L->top = ra+b; /* else previous instruction set top */ L->savedpc = pc; lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); @@ -641,6 +684,13 @@ void luaV_execute (lua_State *L, int nexeccalls) { } case PCRC: { /* it was a C function (`precall' called it) */ base = L->base; + if (oldtaint) { + if (lua_taintexpected) + lua_tainted = oldtaint; + lua_taintedclosure = 1; + } + else + lua_taintedclosure = 0; continue; } default: { @@ -650,6 +700,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { } case OP_RETURN: { int b = GETARG_B(i); + lua_taintedclosure = 0; if (b != 0) L->top = ra+b-1; if (L->openupval) luaF_close(L, base); L->savedpc = pc; @@ -777,3 +828,468 @@ void luaV_execute (lua_State *L, int nexeccalls) { } } + +// VERIFY: bcf0c3ef manual +// OFFSET: 0x00859160 +void luaV_execute_profile (lua_State *L, int nexeccalls) { + LClosure *cl; + StkId base; + TValue *k; + const Instruction *pc; + Profile *prof; + __int64 last = OsGetAsyncTimeClocks(); + reentry: /* entry point */ + lua_assert(isLua(L->ci)); + pc = L->savedpc; + cl = &clvalue(L->ci->func)->l; + lua_taintedclosure = 0; + if (cl->taint) { + if (lua_taintexpected) + lua_tainted = cl->taint; + lua_taintedclosure = 1; + } + prof = cl->profile; + base = L->base; + k = cl->p->k; + /* main loop of interpreter */ + for (;;) { + const Instruction i = *pc++; + StkId ra; + if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && + (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { + traceexec(L, pc); + if (L->status == LUA_YIELD) { /* did hook yield? */ + __int64 now; + L->savedpc = pc - 1; + lua_taintedclosure = 0; + now = OsGetAsyncTimeClocks(); + prof->time += now - last; + if (!prof->depth) + prof->totaltime += now - last; + return; + } + base = L->base; + } + if (L->externalabort) + luaG_runerror(L, "external abort"); + /* warning!! several calls may realloc the stack and invalidate `ra' */ + ra = RA(i); + lua_assert(base == L->base && L->base == L->ci->base); + lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); + lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); + switch (GET_OPCODE(i)) { + case OP_MOVE: { + setobjs2s(L, ra, RB(i)); + continue; + } + case OP_LOADK: { + setobj2s(L, ra, KBx(i)); + continue; + } + case OP_LOADBOOL: { + setbvalue(ra, GETARG_B(i)); + if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ + continue; + } + case OP_LOADNIL: { + TValue *rb = RB(i); + do { + setnilvalue(rb--); + } while (rb >= ra); + continue; + } + case OP_GETUPVAL: { + int b = GETARG_B(i); + setobj2s(L, ra, cl->upvals[b]->v); + continue; + } + case OP_GETGLOBAL: { + TValue g; + TValue *rb = KBx(i); + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(rb)); + Protect(luaV_gettable(L, &g, rb, ra)); + continue; + } + case OP_GETTABLE: { + Protect(luaV_gettable(L, RB(i), RKC(i), ra)); + continue; + } + case OP_SETGLOBAL: { + TValue g; + sethvalue(L, &g, cl->env); + lua_assert(ttisstring(KBx(i))); + Protect(luaV_settable(L, &g, KBx(i), ra)); + continue; + } + case OP_SETUPVAL: { + UpVal *uv = cl->upvals[GETARG_B(i)]; + setobj(L, uv->v, ra); + luaC_barrier(L, uv, ra); + continue; + } + case OP_SETTABLE: { + Protect(luaV_settable(L, ra, RKB(i), RKC(i))); + continue; + } + case OP_NEWTABLE: { + int b = GETARG_B(i); + int c = GETARG_C(i); + sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); + Protect(luaC_checkGC(L)); + continue; + } + case OP_SELF: { + StkId rb = RB(i); + setobjs2s(L, ra+1, rb); + Protect(luaV_gettable(L, rb, RKC(i), ra)); + continue; + } + case OP_ADD: { + arith_op(luai_numadd, TM_ADD); + continue; + } + case OP_SUB: { + arith_op(luai_numsub, TM_SUB); + continue; + } + case OP_MUL: { + arith_op(luai_nummul, TM_MUL); + continue; + } + case OP_DIV: { + arith_op(luai_numdiv, TM_DIV); + continue; + } + case OP_MOD: { + arith_op(luai_nummod, TM_MOD); + continue; + } + case OP_POW: { + arith_op(luai_numpow, TM_POW); + continue; + } + case OP_UNM: { + TValue *rb = RB(i); + if (ttisnumber(rb)) { + lua_Number nb = nvalue(rb); + setnvalue(ra, luai_numunm(nb)); + } + else { + Protect(Arith(L, ra, rb, rb, TM_UNM)); + } + continue; + } + case OP_NOT: { + int res = l_isfalse(RB(i)); /* next assignment may change this value */ + setbvalue(ra, res); + continue; + } + case OP_LEN: { + const TValue *rb = RB(i); + switch (ttype(rb)) { + case LUA_TTABLE: { + setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); + break; + } + case LUA_TSTRING: { + setnvalue(ra, cast_num(tsvalue(rb)->len)); + break; + } + default: { /* try metamethod */ + Protect( + if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) + luaG_typeerror(L, rb, "get length of"); + ) + } + } + continue; + } + case OP_CONCAT: { + int b = GETARG_B(i); + int c = GETARG_C(i); + Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); + setobjs2s(L, RA(i), base+b); + continue; + } + case OP_JMP: { + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_EQ: { + TValue *rb = RKB(i); + TValue *rc = RKC(i); + Protect( + if (equalobj(L, rb, rc) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LT: { + Protect( + if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_LE: { + Protect( + if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) + dojump(L, pc, GETARG_sBx(*pc)); + ) + pc++; + continue; + } + case OP_TEST: { + if (l_isfalse(ra) != GETARG_C(i)) + dojump(L, pc, GETARG_sBx(*pc)); + pc++; + continue; + } + case OP_TESTSET: { + TValue *rb = RB(i); + if (l_isfalse(rb) != GETARG_C(i)) { + setobjs2s(L, ra, rb); + dojump(L, pc, GETARG_sBx(*pc)); + } + pc++; + continue; + } + case OP_CALL: { + int b = GETARG_B(i); + int nresults = GETARG_C(i) - 1; + const char *oldtaint = lua_taintedclosure ? lua_tainted : NULL; + lua_taintedclosure = 0; + __int64 now; + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + now = OsGetAsyncTimeClocks(); + prof->time += now - last; + if (++prof->depth == 1) { + prof->start = now; + prof->totaltime += now - last; + } + last = now; + switch (luaD_precall_profile(L, ra, nresults, now, &now)) { + case PCRLUA: { + nexeccalls++; + goto reentry; /* restart luaV_execute over new Lua function */ + } + case PCRC: { + /* it was a C function (`precall' called it); adjust results */ + if (nresults >= 0) L->top = L->ci->top; + base = L->base; + if (oldtaint) { + if (lua_taintexpected) + lua_tainted = oldtaint; + lua_taintedclosure = 1; + } + else + lua_taintedclosure = 0; + prof = clvalue(L->ci->func)->l.profile; + if (prof->depth-- == 1) + prof->totaltime += now - prof->start; + last = now; + continue; + } + default: { + Profile *p = clvalue(L->ci->func)->l.profile; + __int64 stop = now; + if (p->depth-- == 1) + p->totaltime += now - p->start; + now = OsGetAsyncTimeClocks(); + p->time += now - stop; + if (!p->depth) + p->totaltime += now - stop; + return; /* yield */ + } + } + } + case OP_TAILCALL: { + int b = GETARG_B(i); + const char *oldtaint = lua_taintedclosure ? lua_tainted : NULL; + lua_taintedclosure = 0; + __int64 now; + if (b != 0) L->top = ra+b; /* else previous instruction set top */ + L->savedpc = pc; + lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); + now = OsGetAsyncTimeClocks(); + prof->time += now - last; + if (!prof->depth) + prof->totaltime += now - last; + last = now; + switch (luaD_precall_profile(L, ra, LUA_MULTRET, now, &now)) { + case PCRLUA: { + /* tail call: put new frame in place of previous one */ + CallInfo *ci = L->ci - 1; /* previous frame */ + int aux; + StkId func = ci->func; + StkId pfunc = (ci+1)->func; /* previous function index */ + if (L->openupval) luaF_close(L, ci->base); + L->base = ci->base = ci->func + ((ci+1)->base - pfunc); + for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ + setobjs2s(L, func+aux, pfunc+aux); + ci->top = L->top = func+aux; /* correct top */ + lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); + ci->savedpc = L->savedpc; + ci->tailcalls++; /* one more call lost */ + L->ci--; /* remove new frame */ + goto reentry; + } + case PCRC: { /* it was a C function (`precall' called it) */ + base = L->base; + if (oldtaint) { + if (lua_taintexpected) + lua_tainted = oldtaint; + lua_taintedclosure = 1; + } + else + lua_taintedclosure = 0; + continue; + } + default: { + return; /* yield */ + } + } + } + case OP_RETURN: { + int b = GETARG_B(i); + lua_taintedclosure = 0; + if (b != 0) L->top = ra+b-1; + __int64 now; + if (L->openupval) luaF_close(L, base); + L->savedpc = pc; + now = OsGetAsyncTimeClocks(); + prof->time += now - last; + if (!prof->depth) + prof->totaltime += now - last; + b = luaD_poscall(L, ra); + if (--nexeccalls == 0) /* was previous function running `here'? */ + return; /* no: return */ + else { /* yes: continue its execution */ + if (b) L->top = L->ci->top; + prof = clvalue(L->ci->func)->l.profile; + if (prof->depth-- == 1) + prof->totaltime += now - prof->start; + last = now; + lua_assert(isLua(L->ci)); + lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); + goto reentry; + } + } + case OP_FORLOOP: { + lua_Number step = nvalue(ra+2); + lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ + lua_Number limit = nvalue(ra+1); + if (luai_numlt(0, step) ? luai_numle(idx, limit) + : luai_numle(limit, idx)) { + dojump(L, pc, GETARG_sBx(i)); /* jump back */ + setnvalue(ra, idx); /* update internal index... */ + setnvalue(ra+3, idx); /* ...and external index */ + } + continue; + } + case OP_FORPREP: { + const TValue *init = ra; + const TValue *plimit = ra+1; + const TValue *pstep = ra+2; + L->savedpc = pc; /* next steps may throw errors */ + if (!tonumber(init, ra)) + luaG_runerror(L, LUA_QL("for") " initial value must be a number"); + else if (!tonumber(plimit, ra+1)) + luaG_runerror(L, LUA_QL("for") " limit must be a number"); + else if (!tonumber(pstep, ra+2)) + luaG_runerror(L, LUA_QL("for") " step must be a number"); + setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); + dojump(L, pc, GETARG_sBx(i)); + continue; + } + case OP_TFORLOOP: { + StkId cb = ra + 3; /* call base */ + setobjs2s(L, cb+2, ra+2); + setobjs2s(L, cb+1, ra+1); + setobjs2s(L, cb, ra); + L->top = cb+3; /* func. + 2 args (state and index) */ + Protect(luaD_call(L, cb, GETARG_C(i))); + L->top = L->ci->top; + cb = RA(i) + 3; /* previous call may change the stack */ + if (!ttisnil(cb)) { /* continue loop? */ + setobjs2s(L, cb-1, cb); /* save control variable */ + dojump(L, pc, GETARG_sBx(*pc)); /* jump back */ + } + pc++; + continue; + } + case OP_SETLIST: { + int n = GETARG_B(i); + int c = GETARG_C(i); + int last; + Table *h; + if (n == 0) { + n = cast_int(L->top - ra) - 1; + L->top = L->ci->top; + } + if (c == 0) c = cast_int(*pc++); + runtime_check(L, ttistable(ra)); + h = hvalue(ra); + last = ((c-1)*LFIELDS_PER_FLUSH) + n; + if (last > h->sizearray) /* needs more space? */ + luaH_resizearray(L, h, last); /* pre-alloc it at once */ + for (; n > 0; n--) { + TValue *val = ra+n; + setobj2t(L, luaH_setnum(L, h, last--), val); + luaC_barriert(L, h, val); + } + continue; + } + case OP_CLOSE: { + luaF_close(L, ra); + continue; + } + case OP_CLOSURE: { + Proto *p; + Closure *ncl; + int nup, j; + p = cl->p->p[GETARG_Bx(i)]; + nup = p->nups; + ncl = luaF_newLclosure(L, nup, cl->env); + ncl->l.p = p; + for (j=0; jl.upvals[j] = cl->upvals[GETARG_B(*pc)]; + else { + lua_assert(GET_OPCODE(*pc) == OP_MOVE); + ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc)); + } + } + setclvalue(L, ra, ncl); + Protect(luaC_checkGC(L)); + continue; + } + case OP_VARARG: { + int b = GETARG_B(i) - 1; + int j; + CallInfo *ci = L->ci; + int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; + if (b == LUA_MULTRET) { + Protect(luaD_checkstack(L, n)); + ra = RA(i); /* previous call may change the stack */ + b = n; + L->top = ra + n; + } + for (j = 0; j < b; j++) { + if (j < n) { + setobjs2s(L, ra + j, ci->base - n + j); + } + else { + setnilvalue(ra + j); + } + } + continue; + } + } + } +} + diff --git a/Engine/Source/lua-5.1/src/lvm.h b/Engine/Source/lua-5.1/src/lvm.h index 788423f..9e4dea9 100644 --- a/Engine/Source/lua-5.1/src/lvm.h +++ b/Engine/Source/lua-5.1/src/lvm.h @@ -31,6 +31,7 @@ LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val); LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); +LUAI_FUNC void luaV_execute_profile (lua_State *L, int nexeccalls); LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); #endif diff --git a/Engine/Source/lua-5.1/src/lzio.c b/Engine/Source/lua-5.1/src/lzio.c index 84a298a..2b2a48f 100644 --- a/Engine/Source/lua-5.1/src/lzio.c +++ b/Engine/Source/lua-5.1/src/lzio.c @@ -18,6 +18,7 @@ #include "lzio.h" +// VERIFY: 66d5ab05 auto // OFFSET: 0x0085D0F0 int luaZ_fill (ZIO *z) { size_t size; @@ -46,6 +47,7 @@ int luaZ_lookahead (ZIO *z) { } +// VERIFY: f02cb73c auto // OFFSET: 0x0085D140 void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { z->L = L; @@ -73,6 +75,7 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) { } /* ------------------------------------------------------------------------ */ +// VERIFY: 367326c8 auto // OFFSET: 0x0085D170 char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { if (n > buff->buffsize) {