Skip to content

Add default convention to CallingConvention. #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3d0d875
Added default convention to ICallingConvention.
CookStar Aug 5, 2020
fb87d77
Changed constructor to create the default convention from MakeDynamic…
CookStar Aug 14, 2020
f2c403c
Removed "ICallingConventionWrapper *" from the held type.
CookStar Aug 15, 2020
025a421
Fixed removal of setting null.
CookStar Aug 15, 2020
dd295d3
Changed m_pCallingConvention to m_pDefaultCallingConvention.
CookStar Aug 15, 2020
f39a6c4
Simplified CFunction destructor.
CookStar Aug 16, 2020
adbc65a
Fixed a crash introduced by removing "ICallingConventionWrapper *".
CookStar Aug 16, 2020
f3aa765
Removed the convention headers.
CookStar Aug 17, 2020
854d96f
Fixed a crash on unloading Source.Python.
CookStar Aug 24, 2020
f275acc
Fix for VC++ 2010.
CookStar Aug 25, 2020
c47ca12
Fix2 for VC++ 2010.
CookStar Aug 25, 2020
1ae3f1d
Merge branch 'master' into add_default_callingconvention
CookStar Aug 29, 2020
0062175
Added an overload for C-type functions to CFunction::AddHook.
CookStar Sep 1, 2020
3c4935b
Resolved conflicts.
CookStar Sep 29, 2020
8aab63b
Fixed CallingConvention's leaks/issues.
jordanbriere Oct 2, 2020
6b68369
Minor fixes.
jordanbriere Oct 2, 2020
118070b
Merge pull request #2 from jordanbriere/add_default_callingconvention
CookStar Oct 3, 2020
b4cb2c0
Modified CFunction to initialize CallingConvention with default_conve…
CookStar Oct 5, 2020
121a496
Added custom_convention(m_oCallingConvention) attribute to Function.
CookStar Oct 5, 2020
282bf03
Added post-construction initialization support.
jordanbriere Oct 5, 2020
6d26bca
Fixed built-in conventions leaking when they are being unhooked while…
jordanbriere Oct 5, 2020
98d9853
Replaced the post-construction wrapper with stackable policies.
jordanbriere Oct 6, 2020
958cb03
Merge pull request #3 from jordanbriere/add_default_callingconvention
CookStar Oct 6, 2020
f651f57
Fixed namespace issue.
CookStar Oct 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplified CFunction destructor.
  • Loading branch information
CookStar committed Aug 16, 2020
commit f39a6c48a566987b573e8d4c049d307c69159268
50 changes: 18 additions & 32 deletions src/core/modules/memory/memory_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int GetDynCallConvention(Convention_t eConv)
case CONV_STDCALL: return DC_CALL_C_X86_WIN32_STD;
#endif
}

BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Unsupported calling convention.")
return -1;
}
Expand Down Expand Up @@ -143,9 +143,6 @@ CFunction::CFunction(unsigned long ulAddr, object oCallingConvention, object oAr
// If this line succeeds the user wants to create a function with the built-in calling conventions
m_eCallingConvention = extract<Convention_t>(oCallingConvention);
m_pCallingConvention = MakeDynamicHooksConvention(m_eCallingConvention, ObjectToDataTypeVector(m_tArgs), m_eReturnType);

// We allocated the calling convention, we are responsible to cleanup.
m_bAllocatedCallingConvention = true;
}
catch( ... )
{
Expand All @@ -161,13 +158,13 @@ CFunction::CFunction(unsigned long ulAddr, object oCallingConvention, object oAr
// TODO: Pretty sure this was required due to the missing held type definition. It was added, but wasn't tested yet.
Py_INCREF(m_oCallingConvention.ptr());
m_pCallingConvention = extract<ICallingConvention*>(m_oCallingConvention);

// We didn't allocate the calling convention, someone else is responsible for it.
m_bAllocatedCallingConvention = false;
}

// Step 4: Get the DynCall calling convention
m_iCallingConvention = GetDynCallConvention(m_eCallingConvention);

// We allocated the calling convention, we are responsible to cleanup.
m_bAllocatedCallingConvention = true;
}

CFunction::CFunction(unsigned long ulAddr, Convention_t eCallingConvention,
Expand All @@ -189,32 +186,21 @@ CFunction::CFunction(unsigned long ulAddr, Convention_t eCallingConvention,

CFunction::~CFunction()
{
// If we created custom calling convention, clean it up.
// This does not apply to hooked calling convention.
if (!m_oCallingConvention.is_none())
{
CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr);
if (!pHook || pHook->m_pCallingConvention != m_pCallingConvention)
{
Py_DECREF(m_oCallingConvention.ptr());
m_pCallingConvention = NULL;
}

return;
}

// If we didn't allocate the calling convention, then it is not our responsibility.
if (!m_bAllocatedCallingConvention)
return;

CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr);

// DynamicHooks will take care of it for us from there.
if (pHook && pHook->m_pCallingConvention == m_pCallingConvention)
return;
// If we created calling convention, clean it up.
// This does not apply to hooked calling convention.
if (m_oCallingConvention.is_none())
{
delete m_pCallingConvention;
}
else
{
Py_DECREF(m_oCallingConvention.ptr());
}

// Cleanup.
delete m_pCallingConvention;
m_pCallingConvention = NULL;
}

Expand Down Expand Up @@ -290,7 +276,7 @@ object CFunction::Call(tuple args, dict kw)

dcArgPointer(g_pCallVM, ulAddr);
break;
}
}
case DATA_TYPE_STRING: dcArgPointer(g_pCallVM, (unsigned long) (void *) extract<char *>(arg)); break;
default: BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Unknown argument type.")
}
Expand Down Expand Up @@ -362,10 +348,10 @@ void CFunction::AddHook(HookType_t eType, PyObject* pCallable)
{
if (!IsHookable())
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Function is not hookable.")

Validate();
CHook* pHook = GetHookManager()->FindHook((void *) m_ulAddr);

// Prepare arguments for log message
str type = str(eType);
const char* szType = extract<const char*>(type);
Expand Down Expand Up @@ -400,7 +386,7 @@ void CFunction::AddHook(HookType_t eType, PyObject* pCallable)
// DynamicHooks will handle our convention from there, regardless if we allocated it or not.
m_bAllocatedCallingConvention = false;
}

// Add the hook handler. If it's already added, it won't be added twice
pHook->AddCallback(eType, (HookHandlerFn *) (void *) &SP_HookHandler);
g_mapCallbacks[pHook][eType].push_back(object(handle<>(borrowed(pCallable))));
Expand Down