Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: gcc 5.3 version of libasan is broken



On 2016/06/07 23:42, Christos Zoulas wrote:
I think it is better to do what linux does and write an internal_syscall()
macro that just DTRT's instead of special-casing each syscall.

Sorry, I cannot grasp what you mean. Let me explain more in details what I
did. First, I defined three macros:

#define  internal_syscall     syscall
#define  internal_syscall64   __syscall
#if SANITIZER_WORDSIZE == 64
# define internal_syscall_ptr __syscall
#else
# define internal_syscall_ptr syscall
#endif

Then, I used an appropriate one depending on a return value, i.e.,

(1) internal_syscall for int or pid_t, e.g.,

  int internal_fork() {
    return internal_syscall(SYS_fork);
  }

(2) internal_syscal64 for off_t, e.g.,

  uptr internal_lseek(fd_t fd, OFF_T offset, int whence) {
    return internal_syscall64(SYSCALL(lseek), fd, 0, offset, whence);
  }

(3) internal_syscall_ptr for pointer or (s)size_t, e.g.,

  uptr internal_mmap(void *addr, uptr length, int prot, int flags,
                      int fd, u64 offset) {
     return internal_syscall_ptr(SYSCALL(mmap), addr, length, prot, flags, fd,
                                (long)0, offset);
  }

At this stage, no casting is involving.

Next, I rearranged the arguments for syscalls appropriately, namely,

(a) inserted paddings, e.g.,

  +#if SANITIZER_NETBSD
  +  return internal_syscall64(SYSCALL(lseek), fd, 0, offset, whence);
  +#else
     return internal_syscall(SYSCALL(lseek), fd, offset, whence);
  +#endif

(b) corrected length of arguments via casting, e.g.,

  +#if SANITIZER_NETBSD
  +  internal_syscall(SYSCALL(gettimeofday), &tv, NULL);
  +#else
     internal_syscall(SYSCALL(gettimeofday), (uptr)&tv, 0);
  +#endif

  (in this case, the length of the last argument was wrong for LP64, so
   I used casting, NULL <--> (void *) 0)

In summary, I used casting only for (b). What do you mean by "special-casing"?
I may have misunderstood something, if so, please let me know.

Thanks,
Rin


Home | Main Index | Thread Index | Old Index