Skip to content

Commit a9235ae

Browse files
committed
[compiler-rt] Don't handle Linux-specific shmctl commands in sanitizer
Despite being defined in the system headers, these commands are not in fact part of the FreeBSD system call interface. They exist solely for the Linuxulator, i.e. running Linux binaries on FreeBSD, and any attempt to use them from a FreeBSD binary will return EINVAL. The fact we needed to define _KERNEL (which, as the name implies, means we are compiling the kernel) to even get the definition of shminfo should have been a strong indicator that IPC_INFO at least was not a userspace interface.
1 parent 2b5b8db commit a9235ae

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <sys/mtio.h>
3030
#include <sys/ptrace.h>
3131
#include <sys/resource.h>
32+
#include <sys/shm.h>
3233
#include <sys/signal.h>
3334
#include <sys/socket.h>
3435
#include <sys/sockio.h>
@@ -87,10 +88,6 @@
8788
#include <wchar.h>
8889
#include <wordexp.h>
8990

90-
#define _KERNEL // to declare 'shminfo' structure
91-
#include <sys/shm.h>
92-
#undef _KERNEL
93-
9491
#undef IOC_DIRMASK
9592

9693
// Include these after system headers to avoid name clashes and ambiguities.
@@ -141,8 +138,6 @@ unsigned struct_timeb_sz = sizeof(struct timeb);
141138
unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds);
142139
unsigned struct_mq_attr_sz = sizeof(struct mq_attr);
143140
unsigned struct_statvfs_sz = sizeof(struct statvfs);
144-
unsigned struct_shminfo_sz = sizeof(struct shminfo);
145-
unsigned struct_shm_info_sz = sizeof(struct shm_info);
146141
unsigned struct_regmatch_sz = sizeof(regmatch_t);
147142
unsigned struct_regex_sz = sizeof(regex_t);
148143
unsigned struct_fstab_sz = sizeof(struct fstab);
@@ -156,9 +151,6 @@ const uptr sig_err = (uptr)SIG_ERR;
156151
const uptr sa_siginfo = (uptr)SA_SIGINFO;
157152

158153
int shmctl_ipc_stat = (int)IPC_STAT;
159-
int shmctl_ipc_info = (int)IPC_INFO;
160-
int shmctl_shm_info = (int)SHM_INFO;
161-
int shmctl_shm_stat = (int)SHM_STAT;
162154
unsigned struct_utmpx_sz = sizeof(struct utmpx);
163155

164156
int map_fixed = MAP_FIXED;

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,14 @@ struct __sanitizer_wordexp_t {
419419

420420
typedef void __sanitizer_FILE;
421421

422-
extern unsigned struct_shminfo_sz;
423-
extern unsigned struct_shm_info_sz;
424422
extern int shmctl_ipc_stat;
425-
extern int shmctl_ipc_info;
426-
extern int shmctl_shm_info;
427-
extern int shmctl_shm_stat;
423+
424+
// This simplifies generic code
425+
#define struct_shminfo_sz -1
426+
#define struct_shm_info_sz -1
427+
#define shmctl_shm_stat -1
428+
#define shmctl_ipc_info -1
429+
#define shmctl_shm_info -1
428430

429431
extern unsigned struct_utmpx_sz;
430432

0 commit comments

Comments
 (0)