[compiler-rt] r223477 - [ASan] Fix Win build following r223419.

Timur Iskhodzhanov timurrrr at google.com
Wed Dec 24 06:22:37 PST 2014


In fact this is still incorrect if a thread is started in a suspended
state, which is not rare on Windows.

On Fri Dec 05 2014 at 7:57:22 PM Sergey Matveev <earthdok at google.com> wrote:

> Author: smatveev
> Date: Fri Dec  5 10:53:58 2014
> New Revision: 223477
>
> URL: http://llvm.org/viewvc/llvm-project?rev=223477&view=rev
> Log:
> [ASan] Fix Win build following r223419.
>
> Modified:
>     compiler-rt/trunk/lib/asan/asan_interceptors.cc
>
> Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/
> asan/asan_interceptors.cc?rev=223477&r1=223476&r2=223477&view=diff
> ============================================================
> ==================
> --- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
> +++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Fri Dec  5 10:53:58
> 2014
> @@ -731,13 +731,25 @@ INTERCEPTOR_WINAPI(DWORD, CreateThread,
>    if (flags()->strict_init_order)
>      StopInitOrderChecking();
>    GET_STACK_TRACE_THREAD;
> -  u32 current_tid = GetCurrentTidOrInvalid();
> -  AsanThread *t = AsanThread::Create(start_routine, arg);
> -  CreateThreadContextArgs args = { t, &stack };
>    bool detached = false;  // FIXME: how can we determine it on Windows?
> -  asanThreadRegistry().CreateThread(*(uptr*)t, detached, current_tid,
> &args);
> -  return REAL(CreateThread)(security, stack_size,
> -                            asan_thread_start, t, thr_flags, tid);
> +  ThreadStartParam param;
> +  atomic_store(&param.t, 0, memory_order_relaxed);
> +  atomic_store(&param.is_registered, 0, memory_order_relaxed);
> +  DWORD result = REAL(CreateThread)(security, stack_size,
> asan_thread_start,
> +                                    &param, thr_flags, tid);
> +  if (result) {
> +    u32 current_tid = GetCurrentTidOrInvalid();
> +    AsanThread *t = AsanThread::Create(start_routine, arg);
> +    CreateThreadContextArgs args = { t, &stack };
> +    asanThreadRegistry().CreateThread(*reinterpret_cast<uptr *>(t),
> detached,
> +                                      current_tid, &args);
> +    atomic_store(&param.t, reinterpret_cast<uptr>(t),
> memory_order_release);
> +    // The pthread_create interceptor waits here, so we do the same for
> +    // consistency.
> +    while (atomic_load(&param.is_registered, memory_order_acquire) == 0)
> +      internal_sched_yield();
> +  }
> +  return result;
>  }
>
>  namespace __asan {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141224/c1b6b899/attachment.html>


More information about the llvm-commits mailing list