[all-commits] [llvm/llvm-project] f93b55: [Sanitizers] Add interceptor for xdrrec_create

Gui Andrade via All-commits all-commits at lists.llvm.org
Wed Jul 22 10:30:03 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: f93b55a5ab9d15ee80532642cfa30f9fe8af72c3
      https://github.com/llvm/llvm-project/commit/f93b55a5ab9d15ee80532642cfa30f9fe8af72c3
  Author: Gui Andrade <guiand at google.com>
  Date:   2020-07-22 (Wed, 22 Jul 2020)

  Changed paths:
    M compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
    M compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
    A compiler-rt/test/sanitizer_common/TestCases/Linux/xdrrec.cpp

  Log Message:
  -----------
  [Sanitizers] Add interceptor for xdrrec_create

For now, xdrrec_create is only intercepted Linux as its signature
is different on Solaris.

The method of intercepting xdrrec_create isn't super ideal but I
couldn't think of a way around it: Using an AddrHashMap combined
with wrapping the userdata field.

We can't just allocate a handle on the heap in xdrrec_create and leave
it at that, since there'd be no way to free it later. This is because it
doesn't seem to be possible to access handle from the XDR struct, which
is the only argument to xdr_destroy.
On the other hand, the callbacks don't have a way to get at the
x_private field of XDR, which is what I chose for the HashMap key. So we
need to wrap the handle parameter of the callbacks. But we can't just
pass x_private as handle (as it hasn't been set yet). We can't put the
wrapper struct into the HashMap and pass its pointer as handle, as the
key we need (x_private again) hasn't been set yet.

So I allocate the wrapper struct on the heap, pass its pointer as
handle, and put it into the HashMap so xdr_destroy can find it later and
destroy it.

Differential Revision: https://reviews.llvm.org/D83358




More information about the All-commits mailing list