summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-24 14:47:34 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-24 14:47:34 +0000
commit10362d66fffcd99bd5ced983e4b389dfeba114d0 (patch)
treeae8c70de46a077ca5cd55908fe483219c13251d5 /lib/sanitizer_common
parent1161eb4bff61908074699f6459eabce25839f966 (diff)
downloadcompiler-rt-10362d66fffcd99bd5ced983e4b389dfeba114d0.tar.gz
compiler-rt-10362d66fffcd99bd5ced983e4b389dfeba114d0.tar.bz2
compiler-rt-10362d66fffcd99bd5ced983e4b389dfeba114d0.tar.xz
[sanitizer] Intercept shmctl.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193348 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common')
-rw-r--r--lib/sanitizer_common/sanitizer_common_interceptors.inc23
-rw-r--r--lib/sanitizer_common/sanitizer_platform_interceptors.h1
-rw-r--r--lib/sanitizer_common/sanitizer_platform_limits_posix.cc12
-rw-r--r--lib/sanitizer_common/sanitizer_platform_limits_posix.h9
4 files changed, 45 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 9cef9380..4beedd21 100644
--- a/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -2504,6 +2504,28 @@ INTERCEPTOR(__sanitizer_ether_addr *, ether_aton_r, char *buf,
#define INIT_ETHER_R
#endif
+#if SANITIZER_INTERCEPT_SHMCTL
+INTERCEPTOR(int, shmctl, int shmid, int cmd, void *buf) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, shmctl, shmid, cmd, buf);
+ int res = REAL(shmctl)(shmid, cmd, buf);
+ if (res >= 0) {
+ unsigned sz = 0;
+ if (cmd == shmctl_ipc_stat || cmd == shmctl_shm_stat)
+ sz = struct_shmid_ds_sz;
+ else if (cmd == shmctl_ipc_info)
+ sz = struct_shminfo_sz;
+ else if (cmd == shmctl_shm_info)
+ sz = struct_shm_info_sz;
+ if (sz) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, sz);
+ }
+ return res;
+}
+#define INIT_SHMCTL INTERCEPT_FUNCTION(shmctl);
+#else
+#define INIT_SHMCTL
+#endif
+
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_STRCMP; \
INIT_STRNCMP; \
@@ -2597,4 +2619,5 @@ INTERCEPTOR(__sanitizer_ether_addr *, ether_aton_r, char *buf,
INIT_INITGROUPS; \
INIT_ETHER; \
INIT_ETHER_R; \
+ INIT_SHMCTL; \
/**/
diff --git a/lib/sanitizer_common/sanitizer_platform_interceptors.h b/lib/sanitizer_common/sanitizer_platform_interceptors.h
index a20b9268..401c7d3a 100644
--- a/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -135,6 +135,7 @@
# define SANITIZER_INTERCEPT_INITGROUPS SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_ETHER SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_ETHER_R SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_SHMCTL SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT__EXIT SI_LINUX
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
index 4cdf3694..7aca7f7e 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -92,6 +92,8 @@
#include <linux/scc.h>
#include <linux/serial.h>
#include <sys/msg.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
#if SANITIZER_ANDROID
@@ -180,6 +182,16 @@ namespace __sanitizer {
int e_tabsz = (int)E_TABSZ;
#endif
+
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+ unsigned struct_shminfo_sz = sizeof(struct shminfo);
+ unsigned struct_shm_info_sz = sizeof(struct shm_info);
+ int shmctl_ipc_stat = (int)IPC_STAT;
+ int shmctl_ipc_info = (int)IPC_INFO;
+ int shmctl_shm_info = (int)SHM_INFO;
+ int shmctl_shm_stat = (int)SHM_INFO;
+#endif
+
int af_inet = (int)AF_INET;
int af_inet6 = (int)AF_INET6;
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 3cbd0f64..ae99403d 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -356,6 +356,15 @@ namespace __sanitizer {
extern int ptrace_setregset;
#endif
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+ extern unsigned struct_shminfo_sz;
+ extern unsigned struct_shm_info_sz;
+ extern int shmctl_ipc_stat;
+ extern int shmctl_ipc_info;
+ extern int shmctl_shm_info;
+ extern int shmctl_shm_stat;
+#endif
+
// ioctl arguments
struct __sanitizer_ifconf {
int ifc_len;