Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 1 | //===-- sanitizer_platform_limits_posix.cc --------------------------------===// |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 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 | // |
Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 10 | // This file is a part of Sanitizer common code. |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 11 | // |
| 12 | // Sizes and layouts of platform-specific POSIX data structures. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Evgeniy Stepanov | 24e1372 | 2013-03-19 14:33:38 +0000 | [diff] [blame] | 15 | |
| 16 | #include "sanitizer_platform.h" |
| 17 | #if SANITIZER_LINUX || SANITIZER_MAC |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 18 | |
Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 19 | #include "sanitizer_internal_defs.h" |
| 20 | #include "sanitizer_platform_limits_posix.h" |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 21 | |
Evgeniy Stepanov | 9530eb7 | 2013-04-23 14:05:15 +0000 | [diff] [blame] | 22 | #include <arpa/inet.h> |
Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 23 | #include <dirent.h> |
Evgeniy Stepanov | 103a63e | 2013-04-23 12:01:20 +0000 | [diff] [blame] | 24 | #include <grp.h> |
Evgeniy Stepanov | 10fd322 | 2013-03-13 09:01:40 +0000 | [diff] [blame] | 25 | #include <pthread.h> |
Evgeniy Stepanov | e4bdda5 | 2013-04-01 14:47:21 +0000 | [diff] [blame] | 26 | #include <pwd.h> |
| 27 | #include <signal.h> |
Evgeniy Stepanov | 0228452 | 2013-05-17 13:30:48 +0000 | [diff] [blame] | 28 | #include <stddef.h> |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 29 | #include <sys/utsname.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/stat.h> |
Evgeniy Stepanov | 447ef19 | 2013-05-22 12:50:26 +0000 | [diff] [blame] | 32 | #include <sys/socket.h> |
Evgeniy Stepanov | e03345b | 2013-01-17 13:42:17 +0000 | [diff] [blame] | 33 | #include <sys/time.h> |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 34 | #include <sys/resource.h> |
Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 35 | #include <sys/socket.h> |
Evgeniy Stepanov | 447ef19 | 2013-05-22 12:50:26 +0000 | [diff] [blame] | 36 | #include <netdb.h> |
Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 37 | #include <time.h> |
| 38 | |
Evgeniy Stepanov | 4fb04a8 | 2013-04-04 09:21:48 +0000 | [diff] [blame] | 39 | #if !SANITIZER_ANDROID |
| 40 | #include <sys/ucontext.h> |
| 41 | #endif // !SANITIZER_ANDROID |
| 42 | |
Evgeniy Stepanov | 24e1372 | 2013-03-19 14:33:38 +0000 | [diff] [blame] | 43 | #if SANITIZER_LINUX |
Evgeniy Stepanov | 1aad6b5 | 2013-05-17 12:51:13 +0000 | [diff] [blame] | 44 | #include <link.h> |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 45 | #include <sys/vfs.h> |
| 46 | #include <sys/epoll.h> |
Alexey Samsonov | 46f9395 | 2013-04-03 07:24:35 +0000 | [diff] [blame] | 47 | #endif // SANITIZER_LINUX |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 48 | |
Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 49 | namespace __sanitizer { |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 50 | unsigned struct_utsname_sz = sizeof(struct utsname); |
| 51 | unsigned struct_stat_sz = sizeof(struct stat); |
| 52 | unsigned struct_stat64_sz = sizeof(struct stat64); |
Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 53 | unsigned struct_rusage_sz = sizeof(struct rusage); |
| 54 | unsigned struct_tm_sz = sizeof(struct tm); |
Evgeniy Stepanov | e4bdda5 | 2013-04-01 14:47:21 +0000 | [diff] [blame] | 55 | unsigned struct_passwd_sz = sizeof(struct passwd); |
Evgeniy Stepanov | 103a63e | 2013-04-23 12:01:20 +0000 | [diff] [blame] | 56 | unsigned struct_group_sz = sizeof(struct group); |
Evgeniy Stepanov | 897a4ae | 2013-04-09 14:34:59 +0000 | [diff] [blame] | 57 | unsigned siginfo_t_sz = sizeof(siginfo_t); |
Evgeniy Stepanov | e4bdda5 | 2013-04-01 14:47:21 +0000 | [diff] [blame] | 58 | unsigned struct_sigaction_sz = sizeof(struct sigaction); |
| 59 | unsigned struct_itimerval_sz = sizeof(struct itimerval); |
| 60 | unsigned pthread_t_sz = sizeof(pthread_t); |
Evgeniy Stepanov | 4fb04a8 | 2013-04-04 09:21:48 +0000 | [diff] [blame] | 61 | |
| 62 | #if !SANITIZER_ANDROID |
Evgeniy Stepanov | 0727702 | 2013-04-04 09:03:56 +0000 | [diff] [blame] | 63 | unsigned ucontext_t_sz = sizeof(ucontext_t); |
Evgeniy Stepanov | 4fb04a8 | 2013-04-04 09:21:48 +0000 | [diff] [blame] | 64 | #endif // !SANITIZER_ANDROID |
Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 65 | |
Evgeniy Stepanov | 24e1372 | 2013-03-19 14:33:38 +0000 | [diff] [blame] | 66 | #if SANITIZER_LINUX |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 67 | unsigned struct_rlimit_sz = sizeof(struct rlimit); |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 68 | unsigned struct_dirent_sz = sizeof(struct dirent); |
| 69 | unsigned struct_statfs_sz = sizeof(struct statfs); |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 70 | unsigned struct_epoll_event_sz = sizeof(struct epoll_event); |
Evgeniy Stepanov | e4bdda5 | 2013-04-01 14:47:21 +0000 | [diff] [blame] | 71 | unsigned struct_timespec_sz = sizeof(struct timespec); |
Alexey Samsonov | 46f9395 | 2013-04-03 07:24:35 +0000 | [diff] [blame] | 72 | #endif // SANITIZER_LINUX |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 73 | |
Evgeniy Stepanov | 24e1372 | 2013-03-19 14:33:38 +0000 | [diff] [blame] | 74 | #if SANITIZER_LINUX && !SANITIZER_ANDROID |
Evgeniy Stepanov | e4cded9 | 2013-03-14 13:24:03 +0000 | [diff] [blame] | 75 | unsigned struct_dirent64_sz = sizeof(struct dirent64); |
Evgeniy Stepanov | b711ca6 | 2013-02-19 11:06:41 +0000 | [diff] [blame] | 76 | unsigned struct_rlimit64_sz = sizeof(struct rlimit64); |
| 77 | unsigned struct_statfs64_sz = sizeof(struct statfs64); |
Alexey Samsonov | 46f9395 | 2013-04-03 07:24:35 +0000 | [diff] [blame] | 78 | #endif // SANITIZER_LINUX && !SANITIZER_ANDROID |
Evgeniy Stepanov | b711ca6 | 2013-02-19 11:06:41 +0000 | [diff] [blame] | 79 | |
Evgeniy Stepanov | 06658ea | 2013-04-04 08:22:52 +0000 | [diff] [blame] | 80 | uptr sig_ign = (uptr)SIG_IGN; |
| 81 | uptr sig_dfl = (uptr)SIG_DFL; |
| 82 | |
Evgeniy Stepanov | 06658ea | 2013-04-04 08:22:52 +0000 | [diff] [blame] | 83 | uptr __sanitizer_get_sigaction_sa_sigaction(void *act) { |
| 84 | struct sigaction *a = (struct sigaction *)act; |
| 85 | // Check that sa_sigaction and sa_handler are the same. |
| 86 | CHECK((void *)&(a->sa_sigaction) == (void *)&(a->sa_handler)); |
| 87 | return (uptr) a->sa_sigaction; |
| 88 | } |
| 89 | void __sanitizer_set_sigaction_sa_sigaction(void *act, uptr cb) { |
| 90 | struct sigaction *a = (struct sigaction *)act; |
| 91 | a->sa_sigaction = (void (*)(int, siginfo_t *, void *))cb; |
| 92 | } |
| 93 | bool __sanitizer_get_sigaction_sa_siginfo(void *act) { |
| 94 | struct sigaction *a = (struct sigaction *)act; |
| 95 | return a->sa_flags & SA_SIGINFO; |
| 96 | } |
Evgeniy Stepanov | 9530eb7 | 2013-04-23 14:05:15 +0000 | [diff] [blame] | 97 | |
| 98 | uptr __sanitizer_in_addr_sz(int af) { |
| 99 | if (af == AF_INET) |
| 100 | return sizeof(struct in_addr); |
| 101 | else if (af == AF_INET6) |
| 102 | return sizeof(struct in6_addr); |
| 103 | else |
| 104 | return 0; |
| 105 | } |
Evgeniy Stepanov | 9358c58 | 2013-02-19 09:19:16 +0000 | [diff] [blame] | 106 | } // namespace __sanitizer |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 107 | |
Evgeniy Stepanov | 10fd322 | 2013-03-13 09:01:40 +0000 | [diff] [blame] | 108 | COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t)); |
Evgeniy Stepanov | 06658ea | 2013-04-04 08:22:52 +0000 | [diff] [blame] | 109 | COMPILER_CHECK(sizeof(__sanitizer::struct_sigaction_max_sz) >= |
| 110 | sizeof(__sanitizer::struct_sigaction_sz)); |
Evgeniy Stepanov | 1aad6b5 | 2013-05-17 12:51:13 +0000 | [diff] [blame] | 111 | #if SANITIZER_LINUX |
| 112 | COMPILER_CHECK(offsetof(struct __sanitizer_dl_phdr_info, dlpi_addr) == |
| 113 | offsetof(struct dl_phdr_info, dlpi_addr)); |
| 114 | COMPILER_CHECK(offsetof(struct __sanitizer_dl_phdr_info, dlpi_name) == |
| 115 | offsetof(struct dl_phdr_info, dlpi_name)); |
| 116 | COMPILER_CHECK(offsetof(struct __sanitizer_dl_phdr_info, dlpi_phdr) == |
| 117 | offsetof(struct dl_phdr_info, dlpi_phdr)); |
| 118 | COMPILER_CHECK(offsetof(struct __sanitizer_dl_phdr_info, dlpi_phnum) == |
| 119 | offsetof(struct dl_phdr_info, dlpi_phnum)); |
| 120 | #endif |
| 121 | |
Evgeniy Stepanov | 9666d89 | 2013-05-29 11:30:00 +0000 | [diff] [blame] | 122 | COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned)); |
| 123 | |
Evgeniy Stepanov | 447ef19 | 2013-05-22 12:50:26 +0000 | [diff] [blame] | 124 | COMPILER_CHECK(sizeof(struct __sanitizer_addrinfo) == sizeof(struct addrinfo)); |
| 125 | COMPILER_CHECK(offsetof(struct __sanitizer_addrinfo, ai_addr) == |
| 126 | offsetof(struct addrinfo, ai_addr)); |
| 127 | COMPILER_CHECK(offsetof(struct __sanitizer_addrinfo, ai_canonname) == |
| 128 | offsetof(struct addrinfo, ai_canonname)); |
| 129 | COMPILER_CHECK(offsetof(struct __sanitizer_addrinfo, ai_next) == |
| 130 | offsetof(struct addrinfo, ai_next)); |
| 131 | |
Evgeniy Stepanov | 0a2cc37 | 2013-05-23 11:10:23 +0000 | [diff] [blame] | 132 | COMPILER_CHECK(sizeof(struct __sanitizer_hostent) == sizeof(struct hostent)); |
| 133 | COMPILER_CHECK(offsetof(struct __sanitizer_hostent, h_name) == |
| 134 | offsetof(struct hostent, h_name)); |
| 135 | COMPILER_CHECK(offsetof(struct __sanitizer_hostent, h_aliases) == |
| 136 | offsetof(struct hostent, h_aliases)); |
| 137 | COMPILER_CHECK(offsetof(struct __sanitizer_hostent, h_addr_list) == |
| 138 | offsetof(struct hostent, h_addr_list)); |
| 139 | |
Evgeniy Stepanov | 9666d89 | 2013-05-29 11:30:00 +0000 | [diff] [blame] | 140 | COMPILER_CHECK(sizeof(struct __sanitizer_iovec) == sizeof(struct iovec)); |
| 141 | COMPILER_CHECK(offsetof(struct __sanitizer_iovec, iov_base) == |
| 142 | offsetof(struct iovec, iov_base)); |
| 143 | COMPILER_CHECK(offsetof(struct __sanitizer_iovec, iov_len) == |
| 144 | offsetof(struct iovec, iov_len)); |
| 145 | |
| 146 | COMPILER_CHECK(sizeof(struct __sanitizer_msghdr) == sizeof(struct msghdr)); |
| 147 | COMPILER_CHECK(offsetof(struct __sanitizer_msghdr, msg_name) == |
| 148 | offsetof(struct msghdr, msg_name)); |
| 149 | COMPILER_CHECK(offsetof(struct __sanitizer_msghdr, msg_namelen) == |
| 150 | offsetof(struct msghdr, msg_namelen)); |
| 151 | COMPILER_CHECK(offsetof(struct __sanitizer_msghdr, msg_iov) == |
| 152 | offsetof(struct msghdr, msg_iov)); |
| 153 | COMPILER_CHECK(offsetof(struct __sanitizer_msghdr, msg_iovlen) == |
| 154 | offsetof(struct msghdr, msg_iovlen)); |
| 155 | COMPILER_CHECK(offsetof(struct __sanitizer_msghdr, msg_control) == |
| 156 | offsetof(struct msghdr, msg_control)); |
| 157 | COMPILER_CHECK(offsetof(struct __sanitizer_msghdr, msg_controllen) == |
| 158 | offsetof(struct msghdr, msg_controllen)); |
| 159 | COMPILER_CHECK(offsetof(struct __sanitizer_msghdr, msg_flags) == |
| 160 | offsetof(struct msghdr, msg_flags)); |
| 161 | |
| 162 | COMPILER_CHECK(sizeof(struct __sanitizer_cmsghdr) == sizeof(struct cmsghdr)); |
| 163 | COMPILER_CHECK(offsetof(struct __sanitizer_cmsghdr, cmsg_len) == |
| 164 | offsetof(struct cmsghdr, cmsg_len)); |
| 165 | COMPILER_CHECK(offsetof(struct __sanitizer_cmsghdr, cmsg_level) == |
| 166 | offsetof(struct cmsghdr, cmsg_level)); |
| 167 | COMPILER_CHECK(offsetof(struct __sanitizer_cmsghdr, cmsg_type) == |
| 168 | offsetof(struct cmsghdr, cmsg_type)); |
| 169 | |
Alexey Samsonov | 46f9395 | 2013-04-03 07:24:35 +0000 | [diff] [blame] | 170 | #endif // SANITIZER_LINUX || SANITIZER_MAC |