[compiler-rt] r226926 - [compiler-rt] Fix the prototype of ioctl interceptor

Kuba Brecka kuba.brecka at gmail.com
Fri Jan 23 11:17:20 PST 2015


Author: kuba.brecka
Date: Fri Jan 23 13:17:20 2015
New Revision: 226926

URL: http://llvm.org/viewvc/llvm-project?rev=226926&view=rev
Log:
[compiler-rt] Fix the prototype of ioctl interceptor

The interceptor of ioctl is using a non-standard prototype:

  INTERCEPTOR(int, ioctl, int d, unsigned request, void *arg)

At least on OS X, the request argument should be unsigned long and not 
just unsigned, and also instead of the last argument (arg), the function
should be accepting a variable number of arguments, so the prototype
should be:

  int ioctl(int fildes, unsigned long request, ...);

We can still keep using `unsigned` internally to save space, because we
know that all possible values of `request` will fit into it.

Reviewed at http://reviews.llvm.org/D7038


Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=226926&r1=226925&r2=226926&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Jan 23 13:17:20 2015
@@ -1028,8 +1028,12 @@ FORMAT_INTERCEPTOR_IMPL(__isoc99_snprint
 
 #if SANITIZER_INTERCEPT_IOCTL
 #include "sanitizer_common_interceptors_ioctl.inc"
-INTERCEPTOR(int, ioctl, int d, unsigned request, void *arg) {
+INTERCEPTOR(int, ioctl, int d, unsigned long request, ...) {
   void *ctx;
+  va_list ap;
+  va_start(ap, request);
+  void *arg = va_arg(ap, void *);
+  va_end(ap);
   COMMON_INTERCEPTOR_ENTER(ctx, ioctl, d, request, arg);
 
   CHECK(ioctl_initialized);
@@ -1038,6 +1042,10 @@ INTERCEPTOR(int, ioctl, int d, unsigned
   // This effectively disables ioctl handling in TSan.
   if (!common_flags()->handle_ioctl) return REAL(ioctl)(d, request, arg);
 
+  // Although request is unsigned long, the rest of the interceptor uses it
+  // as just "unsigned" to save space, because we know that all values fit in
+  // "unsigned" - they are compile-time constants.
+
   const ioctl_desc *desc = ioctl_lookup(request);
   ioctl_desc decoded_desc;
   if (!desc) {





More information about the llvm-commits mailing list