[PATCH 4/7] msvcrt: Use trampoline for _beginthreadex().

Arkadiusz Hiler ahiler at codeweavers.com
Tue May 4 07:57:32 CDT 2021


On Tue, May 04, 2021 at 02:46:24PM +0200, Piotr Caban wrote:
> Hi Arek,
> 
> On 5/4/21 1:49 PM, Arkadiusz Hiler wrote:
> > +/*********************************************************************
> > + *		_beginthreadex_trampoline
> > + */
> > +static DWORD CALLBACK _beginthreadex_trampoline(LPVOID arg)
> > +{
> > +    unsigned int retval;
> > +    _beginthread_trampoline_t local_trampoline;
> > +    thread_data_t *data = msvcrt_get_thread_data();
> > +
> > +    memcpy(&local_trampoline, arg, sizeof(local_trampoline));
> > +    data->handle = local_trampoline.thread;
> > +    free(arg);
> > +
> > +    retval = local_trampoline.start_address_ex(local_trampoline.arglist);
> > +    _endthreadex(retval);
> > +}
> Compilation warning:
> warning: no return statement in function returning non-void

I'll add the retrun then.

What are you compiling those with?

I don't get those warnings locally due to DECLSPEC_NORETURN on _endthread[ex]().
Marvin also doesn't seem to complain.

> >   /*********************************************************************
> >    *		_beginthreadex (MSVCRT.@)
> >    */
> > @@ -161,12 +180,35 @@ uintptr_t CDECL _beginthreadex(
> >     unsigned int initflag,   /* [in] Initial state of new thread (0 for running or CREATE_SUSPEND for suspended) */
> >     unsigned int *thrdaddr)  /* [out] Points to a 32-bit variable that receives the thread identifier */
> >   {
> > +  _beginthread_trampoline_t* trampoline;
> > +  HANDLE thread;
> > +
> >     TRACE("(%p, %d, %p, %p, %d, %p)\n", security, stack_size, start_address, arglist, initflag, thrdaddr);
> > -  /* FIXME */
> > -  return (uintptr_t)CreateThread(security, stack_size,
> > -				     start_address, arglist,
> > -				     initflag, thrdaddr);
> > +  if(!start_address) {
> > +      *_errno() = EINVAL;
> > +      return -1;
> > +  }
> The function returns 0 in ucrtbase on invalid argument. I didn't test what
> version it changes in.

Oh, it's even more horrible than what's documented... Thanks for
spotting this. I'll do a sweep and add tests in ucrtbase.

I wonder if the other returns are consistent wrt returning 0 and -1. Sadly,
I haven't manage to make beginthread fail in any other way while testing.

-- 
Cheers,
Arek



More information about the wine-devel mailing list