Skip to content

Commit

Permalink
Merge pull request #2325 from ivan-mogilko/361--win-largeaddressaware
Browse files Browse the repository at this point in the history
Windows: enable /LARGEADDRESSAWARE for 32-bit builds
  • Loading branch information
ivan-mogilko committed Feb 3, 2024
2 parents 3f97628 + 941db37 commit a455bda
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 28 deletions.
9 changes: 9 additions & 0 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,15 @@ if (WIN32)
set_target_properties(ags PROPERTIES
WIN32_EXECUTABLE TRUE
)
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
# enable more than 2 GB in a 32-bit application
if (MINGW)
target_link_options(ags PUBLIC "-Wl,--large-address-aware")
endif ()
if (MSVC)
target_link_options(ags PUBLIC "/LARGEADDRESSAWARE")
endif ()
endif ()
endif()

# Test
Expand Down
2 changes: 1 addition & 1 deletion Engine/gfx/ali3dogl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ size_t OGLGraphicsDriver::RenderSpriteBatch(const OGLSpriteBatch &batch, size_t
if (e.skip)
continue;

switch (reinterpret_cast<intptr_t>(e.ddb))
switch (reinterpret_cast<uintptr_t>(e.ddb))
{
case DRAWENTRY_STAGECALLBACK:
// raw-draw plugin support
Expand Down
6 changes: 3 additions & 3 deletions Engine/gfx/gfxdriverbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ class GraphicsDriverBase : public IGraphicsDriver

protected:
// Special internal values, applied to DrawListEntry
static const intptr_t DRAWENTRY_STAGECALLBACK = 0x0;
static const intptr_t DRAWENTRY_FADE = 0x1;
static const intptr_t DRAWENTRY_TINT = 0x2;
static const uintptr_t DRAWENTRY_STAGECALLBACK = 0x0;
static const uintptr_t DRAWENTRY_FADE = 0x1;
static const uintptr_t DRAWENTRY_TINT = 0x2;

// Called after graphics driver was initialized for use for the first time
virtual void OnInit();
Expand Down
2 changes: 1 addition & 1 deletion Engine/platform/windows/gfx/ali3dd3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ size_t D3DGraphicsDriver::RenderSpriteBatch(const D3DSpriteBatch &batch, size_t
if (e.skip)
continue;

switch (reinterpret_cast<intptr_t>(e.ddb))
switch (reinterpret_cast<uintptr_t>(e.ddb))
{
case DRAWENTRY_STAGECALLBACK:
// raw-draw plugin support
Expand Down
13 changes: 7 additions & 6 deletions Engine/script/cc_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,13 +1279,13 @@ int ccInstance::Run(int32_t curpc)
int32_t instId = codeOp.Instruction.InstanceId;
// determine the offset into the code of the instance we want
runningInst = loadedInstances[instId];
intptr_t callAddr = reg1.PtrU8 - reinterpret_cast<uint8_t*>(&runningInst->code[0]);
if (callAddr % sizeof(intptr_t) != 0)
uintptr_t callAddr = reg1.PtrU8 - reinterpret_cast<uint8_t*>(&runningInst->code[0]);
if (callAddr % sizeof(uintptr_t) != 0)
{
cc_error("call address not aligned");
return -1;
}
callAddr /= sizeof(intptr_t); // size of ccScript::code elements
callAddr /= sizeof(uintptr_t); // size of ccScript::code elements

if (Run(static_cast<int32_t>(callAddr)))
return -1;
Expand Down Expand Up @@ -1331,11 +1331,11 @@ int ccInstance::Run(int32_t curpc)
{
RuntimeScriptValue obj_rval = registers[SREG_OP];
obj_rval.DirectPtrObj();
int_ret_val = call_function((intptr_t)reg1.Ptr, &obj_rval, num_args_to_func, func_callstack.GetHead() + 1);
int_ret_val = call_function(reg1.Ptr, &obj_rval, num_args_to_func, func_callstack.GetHead() + 1);
}
else
{
int_ret_val = call_function((intptr_t)reg1.Ptr, nullptr, num_args_to_func, func_callstack.GetHead() + 1);
int_ret_val = call_function(reg1.Ptr, nullptr, num_args_to_func, func_callstack.GetHead() + 1);
}

if (GlobalReturnValue.IsValid())
Expand Down Expand Up @@ -1870,7 +1870,8 @@ bool ccInstance::_Create(PScript scri, const ccInstance * joined)
{
// NOTE: unfortunately, there seems to be no way to know if
// that's an extender function that expects object pointer
exports[i].SetCodePtr((static_cast<intptr_t>(eaddr) * sizeof(intptr_t) + reinterpret_cast<uint8_t*>(&code[0])));
exports[i].SetCodePtr(reinterpret_cast<uint8_t*>(&code[0])
+ (static_cast<uintptr_t>(eaddr) * sizeof(uintptr_t)));
}
else if (etype == EXPORT_DATA)
{
Expand Down
6 changes: 3 additions & 3 deletions Engine/script/runtimescriptvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ RuntimeScriptValue &RuntimeScriptValue::DirectPtrObj()
return *this;
}

intptr_t RuntimeScriptValue::GetDirectPtr() const
void *RuntimeScriptValue::GetDirectPtr() const
{
const RuntimeScriptValue *temp_val = this;
int ival = temp_val->IValue;
Expand All @@ -223,7 +223,7 @@ intptr_t RuntimeScriptValue::GetDirectPtr() const
ival += temp_val->IValue;
}
if (temp_val->Type == kScValScriptObject)
return (intptr_t)temp_val->ObjMgr->GetFieldPtr(temp_val->Ptr, ival);
return temp_val->ObjMgr->GetFieldPtr(temp_val->Ptr, ival);
else
return (intptr_t)(temp_val->PtrU8 + ival);
return temp_val->PtrU8 + ival;
}
2 changes: 1 addition & 1 deletion Engine/script/runtimescriptvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ struct RuntimeScriptValue
// tell for certain that we are expecting a pointer to the object and not its (first) field.
RuntimeScriptValue &DirectPtrObj();
// Resolve and return direct pointer to the referenced data; non pointer types return IValue
intptr_t GetDirectPtr() const;
void * GetDirectPtr() const;
};

#endif // __AGS_EE_SCRIPT__RUNTIMESCRIPTVALUE_H
24 changes: 12 additions & 12 deletions Engine/script/script_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ void ccSetDebugHook(new_line_hook_type jibble)
new_line_hook = jibble;
}

int call_function(intptr_t addr, const RuntimeScriptValue *object, int numparm, const RuntimeScriptValue *parms)
int call_function(void *fn_addr, const RuntimeScriptValue *object, int numparm, const RuntimeScriptValue *parms)
{
if (!addr)
if (!fn_addr)
{
cc_error("null function pointer in call_function");
return -1;
Expand Down Expand Up @@ -212,61 +212,61 @@ int call_function(intptr_t addr, const RuntimeScriptValue *object, int numparm,
case 0:
{
int (*fparam) ();
fparam = (int (*)())addr;
fparam = (int (*)())fn_addr;
return fparam();
}
case 1:
{
int (*fparam) (intptr_t);
fparam = (int (*)(intptr_t))addr;
fparam = (int (*)(intptr_t))fn_addr;
return fparam(parm_value[0]);
}
case 2:
{
int (*fparam) (intptr_t, intptr_t);
fparam = (int (*)(intptr_t, intptr_t))addr;
fparam = (int (*)(intptr_t, intptr_t))fn_addr;
return fparam(parm_value[0], parm_value[1]);
}
case 3:
{
int (*fparam) (intptr_t, intptr_t, intptr_t);
fparam = (int (*)(intptr_t, intptr_t, intptr_t))addr;
fparam = (int (*)(intptr_t, intptr_t, intptr_t))fn_addr;
return fparam(parm_value[0], parm_value[1], parm_value[2]);
}
case 4:
{
int (*fparam) (intptr_t, intptr_t, intptr_t, intptr_t);
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t))addr;
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t))fn_addr;
return fparam(parm_value[0], parm_value[1], parm_value[2], parm_value[3]);
}
case 5:
{
int (*fparam) (intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))addr;
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))fn_addr;
return fparam(parm_value[0], parm_value[1], parm_value[2], parm_value[3], parm_value[4]);
}
case 6:
{
int (*fparam) (intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))addr;
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))fn_addr;
return fparam(parm_value[0], parm_value[1], parm_value[2], parm_value[3], parm_value[4], parm_value[5]);
}
case 7:
{
int (*fparam) (intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))addr;
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))fn_addr;
return fparam(parm_value[0], parm_value[1], parm_value[2], parm_value[3], parm_value[4], parm_value[5], parm_value[6]);
}
case 8:
{
int (*fparam) (intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))addr;
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))fn_addr;
return fparam(parm_value[0], parm_value[1], parm_value[2], parm_value[3], parm_value[4], parm_value[5], parm_value[6], parm_value[7]);
}
case 9:
{
int (*fparam) (intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))addr;
fparam = (int (*)(intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t))fn_addr;
return fparam(parm_value[0], parm_value[1], parm_value[2], parm_value[3], parm_value[4], parm_value[5], parm_value[6], parm_value[7], parm_value[8]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/script/script_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ void ccSetScriptAliveTimer(unsigned sys_poll_timeout, unsigned abort_timeout, un
// reset the current while loop counter
void ccNotifyScriptStillAlive();
// for calling exported plugin functions old-style
int call_function(intptr_t addr, const RuntimeScriptValue *object, int numparm, const RuntimeScriptValue *parms);
int call_function(void *fn_addr, const RuntimeScriptValue *object, int numparm, const RuntimeScriptValue *parms);

#endif // __AGS_EE_CC__SCRIPTRUNTIME_H
4 changes: 4 additions & 0 deletions Solutions/Engine.App/Engine.App.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
<LargeAddressAware>true</LargeAddressAware>
</Link>
<Manifest>
<EnableDpiAwareness>true</EnableDpiAwareness>
Expand Down Expand Up @@ -277,6 +278,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
<LargeAddressAware>true</LargeAddressAware>
</Link>
<Manifest>
<EnableDpiAwareness>true</EnableDpiAwareness>
Expand Down Expand Up @@ -337,6 +339,7 @@
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
<LargeAddressAware>true</LargeAddressAware>
</Link>
<Manifest>
<EnableDpiAwareness>true</EnableDpiAwareness>
Expand Down Expand Up @@ -408,6 +411,7 @@
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<LargeAddressAware>true</LargeAddressAware>
</Link>
<Manifest>
<EnableDpiAwareness>true</EnableDpiAwareness>
Expand Down

0 comments on commit a455bda

Please sign in to comment.