sanitizer_platform_limits_posix.cc revision 251034
1//===-- sanitizer_platform_limits_posix.cc --------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of Sanitizer common code.
11//
12// Sizes and layouts of platform-specific POSIX data structures.
13//===----------------------------------------------------------------------===//
14
15
16#include "sanitizer_platform.h"
17#if SANITIZER_LINUX || SANITIZER_MAC
18
19#include "sanitizer_internal_defs.h"
20#include "sanitizer_platform_limits_posix.h"
21
22#include <arpa/inet.h>
23#include <dirent.h>
24#include <grp.h>
25#include <pthread.h>
26#include <pwd.h>
27#include <signal.h>
28#include <stddef.h>
29#include <sys/utsname.h>
30#include <sys/types.h>
31#include <sys/stat.h>
32#include <sys/socket.h>
33#include <sys/time.h>
34#include <sys/resource.h>
35#include <sys/socket.h>
36#include <netdb.h>
37#include <time.h>
38
39#if !SANITIZER_ANDROID
40#include <sys/ucontext.h>
41#endif // !SANITIZER_ANDROID
42
43#if SANITIZER_LINUX
44#include <link.h>
45#include <sys/vfs.h>
46#include <sys/epoll.h>
47#endif // SANITIZER_LINUX
48
49namespace __sanitizer {
50  unsigned struct_utsname_sz = sizeof(struct utsname);
51  unsigned struct_stat_sz = sizeof(struct stat);
52  unsigned struct_stat64_sz = sizeof(struct stat64);
53  unsigned struct_rusage_sz = sizeof(struct rusage);
54  unsigned struct_tm_sz = sizeof(struct tm);
55  unsigned struct_passwd_sz = sizeof(struct passwd);
56  unsigned struct_group_sz = sizeof(struct group);
57  unsigned siginfo_t_sz = sizeof(siginfo_t);
58  unsigned struct_sigaction_sz = sizeof(struct sigaction);
59  unsigned struct_itimerval_sz = sizeof(struct itimerval);
60  unsigned pthread_t_sz = sizeof(pthread_t);
61  unsigned struct_sockaddr_sz = sizeof(struct sockaddr);
62
63#if !SANITIZER_ANDROID
64  unsigned ucontext_t_sz = sizeof(ucontext_t);
65#endif // !SANITIZER_ANDROID
66
67#if SANITIZER_LINUX
68  unsigned struct_rlimit_sz = sizeof(struct rlimit);
69  unsigned struct_dirent_sz = sizeof(struct dirent);
70  unsigned struct_statfs_sz = sizeof(struct statfs);
71  unsigned struct_epoll_event_sz = sizeof(struct epoll_event);
72  unsigned struct_timespec_sz = sizeof(struct timespec);
73#endif // SANITIZER_LINUX
74
75#if SANITIZER_LINUX && !SANITIZER_ANDROID
76  unsigned struct_dirent64_sz = sizeof(struct dirent64);
77  unsigned struct_rlimit64_sz = sizeof(struct rlimit64);
78  unsigned struct_statfs64_sz = sizeof(struct statfs64);
79#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
80
81  uptr sig_ign = (uptr)SIG_IGN;
82  uptr sig_dfl = (uptr)SIG_DFL;
83
84  void* __sanitizer_get_msghdr_iov_iov_base(void* msg, int idx) {
85    return ((struct msghdr *)msg)->msg_iov[idx].iov_base;
86  }
87
88  uptr __sanitizer_get_msghdr_iov_iov_len(void* msg, int idx) {
89    return ((struct msghdr *)msg)->msg_iov[idx].iov_len;
90  }
91
92  uptr __sanitizer_get_msghdr_iovlen(void* msg) {
93    return ((struct msghdr *)msg)->msg_iovlen;
94  }
95
96  uptr __sanitizer_get_socklen_t(void* socklen_ptr) {
97    return *(socklen_t*)socklen_ptr;
98  }
99
100  uptr __sanitizer_get_sigaction_sa_sigaction(void *act) {
101    struct sigaction *a = (struct sigaction *)act;
102    // Check that sa_sigaction and sa_handler are the same.
103    CHECK((void *)&(a->sa_sigaction) == (void *)&(a->sa_handler));
104    return (uptr) a->sa_sigaction;
105  }
106  void __sanitizer_set_sigaction_sa_sigaction(void *act, uptr cb) {
107    struct sigaction *a = (struct sigaction *)act;
108    a->sa_sigaction = (void (*)(int, siginfo_t *, void *))cb;
109  }
110  bool __sanitizer_get_sigaction_sa_siginfo(void *act) {
111    struct sigaction *a = (struct sigaction *)act;
112    return a->sa_flags & SA_SIGINFO;
113  }
114
115  uptr __sanitizer_in_addr_sz(int af) {
116    if (af == AF_INET)
117      return sizeof(struct in_addr);
118    else if (af == AF_INET6)
119      return sizeof(struct in6_addr);
120    else
121      return 0;
122  }
123}  // namespace __sanitizer
124
125COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t));
126COMPILER_CHECK(sizeof(__sanitizer::struct_sigaction_max_sz) >=
127                   sizeof(__sanitizer::struct_sigaction_sz));
128#if SANITIZER_LINUX
129COMPILER_CHECK(offsetof(struct __sanitizer_dl_phdr_info, dlpi_addr) ==
130               offsetof(struct dl_phdr_info, dlpi_addr));
131COMPILER_CHECK(offsetof(struct __sanitizer_dl_phdr_info, dlpi_name) ==
132               offsetof(struct dl_phdr_info, dlpi_name));
133COMPILER_CHECK(offsetof(struct __sanitizer_dl_phdr_info, dlpi_phdr) ==
134               offsetof(struct dl_phdr_info, dlpi_phdr));
135COMPILER_CHECK(offsetof(struct __sanitizer_dl_phdr_info, dlpi_phnum) ==
136               offsetof(struct dl_phdr_info, dlpi_phnum));
137#endif
138
139COMPILER_CHECK(sizeof(struct __sanitizer_addrinfo) == sizeof(struct addrinfo));
140COMPILER_CHECK(offsetof(struct __sanitizer_addrinfo, ai_addr) ==
141               offsetof(struct addrinfo, ai_addr));
142COMPILER_CHECK(offsetof(struct __sanitizer_addrinfo, ai_canonname) ==
143               offsetof(struct addrinfo, ai_canonname));
144COMPILER_CHECK(offsetof(struct __sanitizer_addrinfo, ai_next) ==
145               offsetof(struct addrinfo, ai_next));
146
147COMPILER_CHECK(sizeof(struct __sanitizer_hostent) == sizeof(struct hostent));
148COMPILER_CHECK(offsetof(struct __sanitizer_hostent, h_name) ==
149               offsetof(struct hostent, h_name));
150COMPILER_CHECK(offsetof(struct __sanitizer_hostent, h_aliases) ==
151               offsetof(struct hostent, h_aliases));
152COMPILER_CHECK(offsetof(struct __sanitizer_hostent, h_addr_list) ==
153               offsetof(struct hostent, h_addr_list));
154
155#endif  // SANITIZER_LINUX || SANITIZER_MAC
156