[PATCH v2] wdscore: Implement CurrentIP.

Giovanni Mascellani gmascellani at codeweavers.com
Fri Jan 14 08:06:02 CST 2022


Hi,

Il 14/01/22 12:28, Mohamad Al-Jaf ha scritto:
> +/***********************************************************************
> + *           CurrentIP (wdscore.@)
> + */
> +#ifdef __i386__
> +__ASM_STDCALL_FUNC(CurrentIP, 0,
> +    "movl 0(%esp), %eax\n\t"
> +    "ret" )
> +#elif defined(__x86_64__)
> +__ASM_STDCALL_FUNC(CurrentIP, 0,
> +    "movq 0(%rsp), %rax\n\t"
> +    "ret" )
> +#elif defined(__arm__)
> +__ASM_STDCALL_FUNC(CurrentIP, 0,
> +    "mov lr, r0\n\t"
> +    "bx lr" )
> +#elif defined(__aarch64__)
> +__ASM_STDCALL_FUNC(CurrentIP, 0,
> +    "mov lr, x0\n\t"
> +    "ret" )
> +#else
> +int WINAPI CurrentIP(void)
> +{
> +    FIXME( "not implemented\n" );
> +    return 0;
> +}
> +#endif

Given your implementation, it seems more likely that CurrentIP returns 
void *, instead of int (which would get the pointer truncated, e.g., on 
i386). This is also hinted by this snippet that was mentioned in the bug:

 
https://github.com/seven-mile/CallCbsCore/blob/6465d9c6801768c56c7ca1faebc65f15e40a07a8/StackManager.cpp#L358

> +static void test_CurrentIP(void)
> +{
> +    int ret;
> +
> +    ret = CurrentIP();
> +    trace("CurrentIP() = %d\n", ret);
> +    ok(ret != 0, "Unsupported architecture\n");
> +}

Same here. Notice that CurrentIP is not declared here, so the compiler 
defaults to the terrible fallback of believing it returns int, though I 
don't think this is appropriate here. And you should declare it anyway. 
I don't know if there is a header in which it is sensible to put the 
declaration.

But just tracing the result is not very useful for testing. Given that 
your hypothesis seems to be that CurrentIP returns the return address of 
the call, you could try to check that such address is in the caller 
function. There is no portable way to do that, but a reasonable attempt 
is to check that ret is higher than &test_CurrentIP and lower than, say, 
&test_CurrentIP + 0x100. I did a quick test and this seems indeed to be 
the case:

   https://testbot.winehq.org/JobDetails.pl?Key=105255

Giovanni.



More information about the wine-devel mailing list