From: Mike Frysinger Date: Sat, 31 Oct 2015 04:47:53 +0000 (-0400) Subject: Support C libraries without System V shared memory/ipc X-Git-Tag: v4.11~113 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba10a421b85b7f622975f2e9f92249cfe3dcfcbd;p=strace Support C libraries without System V shared memory/ipc Some systems (like Bionic) omit support for SysV related code. That means no C library headers for strace to include. Add configure tests to probe the headers from the kernel and use them when they are available. It might make more sense to never rely on the C library's headers as there is no guarantee or requirement that the structure layout between apps and the C library match that what is passed to the kernel. * configure.ac (AC_CHECK_HEADERS): Check for linux/ipc.h, linux/mqueue.h, linux/msg.h, linux/sem.h, linux/shm.h, sys/ipc.h, sys/msg.h, sys/sem.h, and sys/shm.h. * ipc_defs.h: Include or depending on what is available. * ipc_msg.c: Replace with "ipc_defs.h". Fallback to when available. * ipc_msgctl.c: Include , , or based on what is available. Note missing support for old ipc structs. * ipc_sem.c: Include or depending on what is available. Only decode sembuf when available. * ipc_shm.c: Fallback to when available. * ipc_shmctl.c: Include , , or based on what is available. Note missing support for old ipc structs. * print_mq_attr.c: Fallback to when available. --- diff --git a/configure.ac b/configure.ac index 9a1134e9..286db29c 100644 --- a/configure.ac +++ b/configure.ac @@ -269,10 +269,14 @@ AC_CHECK_HEADERS(m4_normalize([ linux/filter.h linux/hiddev.h linux/ip_vs.h + linux/ipc.h linux/mmtimer.h + linux/msg.h linux/perf_event.h linux/seccomp.h linux/securebits.h + linux/sem.h + linux/shm.h linux/utsname.h mqueue.h netinet/sctp.h @@ -283,11 +287,16 @@ AC_CHECK_HEADERS(m4_normalize([ sys/eventfd.h sys/fanotify.h sys/ioctl.h + sys/ipc.h + sys/msg.h sys/reg.h + sys/sem.h + sys/shm.h sys/signalfd.h sys/vfs.h sys/xattr.h ])) +AC_CHECK_HEADERS([linux/mqueue.h],,, [#include ]) AC_CHECK_HEADERS([linux/icmp.h linux/in6.h linux/netlink.h linux/if_packet.h], [], [], [#include #include diff --git a/ipc_defs.h b/ipc_defs.h index 31f7ab31..b6c85c1a 100644 --- a/ipc_defs.h +++ b/ipc_defs.h @@ -25,7 +25,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#ifdef HAVE_SYS_IPC_H +# include +#elif defined HAVE_LINUX_IPC_H +# include +/* While glibc uses __key, the kernel uses key. */ +# define __key key +#endif #if !defined IPC_64 # define IPC_64 0x100 diff --git a/ipc_msg.c b/ipc_msg.c index 55747cbb..965e2e49 100644 --- a/ipc_msg.c +++ b/ipc_msg.c @@ -31,9 +31,13 @@ */ #include "defs.h" +#include "ipc_defs.h" -#include -#include +#ifdef HAVE_SYS_MSG_H +# include +#elif defined HAVE_LINUX_MSG_H +# include +#endif #include "xlat/ipc_msg_flags.h" #include "xlat/resource_flags.h" diff --git a/ipc_msgctl.c b/ipc_msgctl.c index a97dd1a1..e46f6e2e 100644 --- a/ipc_msgctl.c +++ b/ipc_msgctl.c @@ -31,11 +31,21 @@ */ #include "defs.h" -#include "ipc_defs.h" -#include #include DEF_MPERS_TYPE(msqid_ds_t) + +#include "ipc_defs.h" + +#ifdef HAVE_SYS_MSG_H +/* The C library generally exports the struct the current kernel expects. */ +# include typedef struct msqid_ds msqid_ds_t; +#elif defined HAVE_LINUX_MSG_H +/* The linux header might provide the right struct. */ +# include +typedef struct msqid64_ds msqid_ds_t; +#endif + #include MPERS_DEFS #include "xlat/msgctl_flags.h" @@ -43,6 +53,7 @@ typedef struct msqid_ds msqid_ds_t; static void print_msqid_ds(struct tcb *tcp, const long addr, int cmd) { + /* TODO: We don't properly decode old compat ipc calls. */ if (cmd & IPC_64) cmd &= ~IPC_64; msqid_ds_t msqid_ds; diff --git a/ipc_sem.c b/ipc_sem.c index e98f8ef6..c7351ae8 100644 --- a/ipc_sem.c +++ b/ipc_sem.c @@ -33,11 +33,16 @@ #include "defs.h" #include "ipc_defs.h" -#include +#ifdef HAVE_SYS_SEM_H +# include +#elif defined HAVE_LINUX_SEM_H +# include +#endif #include "xlat/semctl_flags.h" #include "xlat/semop_flags.h" +#if defined HAVE_SYS_SEM_H || defined HAVE_LINUX_SEM_H static void tprint_sembuf(const struct sembuf *sb) { @@ -45,10 +50,12 @@ tprint_sembuf(const struct sembuf *sb) printflags(semop_flags, sb->sem_flg, "SEM_???"); tprints("}"); } +#endif static void tprint_sembuf_array(struct tcb *tcp, const long addr, const unsigned long count) { +#if defined HAVE_SYS_SEM_H || defined HAVE_LINUX_SEM_H unsigned long max_count; struct sembuf sb; @@ -78,6 +85,9 @@ tprint_sembuf_array(struct tcb *tcp, const long addr, const unsigned long count) tprints("]"); } +#else + printaddr(addr); +#endif tprintf(", %lu", count); } diff --git a/ipc_shm.c b/ipc_shm.c index 4a41690a..c418884a 100644 --- a/ipc_shm.c +++ b/ipc_shm.c @@ -32,7 +32,11 @@ #include "defs.h" -#include +#ifdef HAVE_SYS_SHM_H +# include +#elif defined HAVE_LINUX_SHM_H +# include +#endif #include "xlat/shm_resource_flags.h" #include "xlat/shm_flags.h" diff --git a/ipc_shmctl.c b/ipc_shmctl.c index 4bd6c85c..3498455d 100644 --- a/ipc_shmctl.c +++ b/ipc_shmctl.c @@ -31,13 +31,21 @@ */ #include "defs.h" -#include "ipc_defs.h" - -#include #include DEF_MPERS_TYPE(shmid_ds_t) -#include + +#include "ipc_defs.h" + +#ifdef HAVE_SYS_SHM_H +/* The C library generally exports the struct the current kernel expects. */ +# include typedef struct shmid_ds shmid_ds_t; +#elif defined HAVE_LINUX_SHM_H +/* The linux header might provide the right struct. */ +# include +typedef struct shmid64_ds shmid_ds_t; +#endif + #include MPERS_DEFS #include "xlat/shmctl_flags.h" @@ -45,6 +53,7 @@ typedef struct shmid_ds shmid_ds_t; static void print_shmid_ds(struct tcb *tcp, const long addr, int cmd) { + /* TODO: We don't properly decode old compat ipc calls. */ if (cmd & IPC_64) cmd &= ~IPC_64; shmid_ds_t shmid_ds; diff --git a/print_mq_attr.c b/print_mq_attr.c index f9bff342..a43d4376 100644 --- a/print_mq_attr.c +++ b/print_mq_attr.c @@ -29,17 +29,21 @@ #include "defs.h" #include DEF_MPERS_TYPE(mq_attr_t) + #ifdef HAVE_MQUEUE_H # include typedef struct mq_attr mq_attr_t; +#elif defined HAVE_LINUX_MQUEUE_H +# include +# include +typedef struct mq_attr mq_attr_t; #endif + #include MPERS_DEFS MPERS_PRINTER_DECL(void, printmqattr)(struct tcb *tcp, const long addr) { -# ifndef HAVE_MQUEUE_H - printaddr(addr); -# else +#if defined HAVE_MQUEUE_H || defined HAVE_LINUX_MQUEUE_H mq_attr_t attr; if (umove_or_printaddr(tcp, addr, &attr)) return; @@ -48,5 +52,7 @@ MPERS_PRINTER_DECL(void, printmqattr)(struct tcb *tcp, const long addr) tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}", (long) attr.mq_maxmsg, (long) attr.mq_msgsize, (long) attr.mq_curmsgs); -# endif +#else + printaddr(addr); +#endif }