Skip to content

Commit ba10a42

Browse files
vapierldv-alt
authored andcommitted
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 <sys/ipc.h> or <linux/ipc.h> depending on what is available. * ipc_msg.c: Replace <sys/ipc.h> with "ipc_defs.h". Fallback to <linux/msg.h> when available. * ipc_msgctl.c: Include <sys/msg.h>, <asm/msgbuf.h>, or <linux/msg.h> based on what is available. Note missing support for old ipc structs. * ipc_sem.c: Include <sys/sem.h> or <linux/sem.h> depending on what is available. Only decode sembuf when available. * ipc_shm.c: Fallback to <linux/shm.h> when available. * ipc_shmctl.c: Include <sys/shm.h>, <asm/shmbuf.h>, or <linux/shm.h> based on what is available. Note missing support for old ipc structs. * print_mq_attr.c: Fallback to <linux/mqueue.h> when available.
1 parent 3422849 commit ba10a42

File tree

8 files changed

+74
-15
lines changed

8 files changed

+74
-15
lines changed

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,14 @@ AC_CHECK_HEADERS(m4_normalize([
269269
linux/filter.h
270270
linux/hiddev.h
271271
linux/ip_vs.h
272+
linux/ipc.h
272273
linux/mmtimer.h
274+
linux/msg.h
273275
linux/perf_event.h
274276
linux/seccomp.h
275277
linux/securebits.h
278+
linux/sem.h
279+
linux/shm.h
276280
linux/utsname.h
277281
mqueue.h
278282
netinet/sctp.h
@@ -283,11 +287,16 @@ AC_CHECK_HEADERS(m4_normalize([
283287
sys/eventfd.h
284288
sys/fanotify.h
285289
sys/ioctl.h
290+
sys/ipc.h
291+
sys/msg.h
286292
sys/reg.h
293+
sys/sem.h
294+
sys/shm.h
287295
sys/signalfd.h
288296
sys/vfs.h
289297
sys/xattr.h
290298
]))
299+
AC_CHECK_HEADERS([linux/mqueue.h],,, [#include <linux/types.h>])
291300
AC_CHECK_HEADERS([linux/icmp.h linux/in6.h linux/netlink.h linux/if_packet.h],
292301
[], [], [#include <stddef.h>
293302
#include <sys/socket.h>

ipc_defs.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@
2525
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727

28-
#include <sys/ipc.h>
28+
#ifdef HAVE_SYS_IPC_H
29+
# include <sys/ipc.h>
30+
#elif defined HAVE_LINUX_IPC_H
31+
# include <linux/ipc.h>
32+
/* While glibc uses __key, the kernel uses key. */
33+
# define __key key
34+
#endif
2935

3036
#if !defined IPC_64
3137
# define IPC_64 0x100

ipc_msg.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
*/
3232

3333
#include "defs.h"
34+
#include "ipc_defs.h"
3435

35-
#include <sys/ipc.h>
36-
#include <sys/msg.h>
36+
#ifdef HAVE_SYS_MSG_H
37+
# include <sys/msg.h>
38+
#elif defined HAVE_LINUX_MSG_H
39+
# include <linux/msg.h>
40+
#endif
3741

3842
#include "xlat/ipc_msg_flags.h"
3943
#include "xlat/resource_flags.h"

ipc_msgctl.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,29 @@
3131
*/
3232

3333
#include "defs.h"
34-
#include "ipc_defs.h"
3534

36-
#include <sys/msg.h>
3735
#include DEF_MPERS_TYPE(msqid_ds_t)
36+
37+
#include "ipc_defs.h"
38+
39+
#ifdef HAVE_SYS_MSG_H
40+
/* The C library generally exports the struct the current kernel expects. */
41+
# include <sys/msg.h>
3842
typedef struct msqid_ds msqid_ds_t;
43+
#elif defined HAVE_LINUX_MSG_H
44+
/* The linux header might provide the right struct. */
45+
# include <linux/msg.h>
46+
typedef struct msqid64_ds msqid_ds_t;
47+
#endif
48+
3949
#include MPERS_DEFS
4050

4151
#include "xlat/msgctl_flags.h"
4252

4353
static void
4454
print_msqid_ds(struct tcb *tcp, const long addr, int cmd)
4555
{
56+
/* TODO: We don't properly decode old compat ipc calls. */
4657
if (cmd & IPC_64)
4758
cmd &= ~IPC_64;
4859
msqid_ds_t msqid_ds;

ipc_sem.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,29 @@
3333
#include "defs.h"
3434
#include "ipc_defs.h"
3535

36-
#include <sys/sem.h>
36+
#ifdef HAVE_SYS_SEM_H
37+
# include <sys/sem.h>
38+
#elif defined HAVE_LINUX_SEM_H
39+
# include <linux/sem.h>
40+
#endif
3741

3842
#include "xlat/semctl_flags.h"
3943
#include "xlat/semop_flags.h"
4044

45+
#if defined HAVE_SYS_SEM_H || defined HAVE_LINUX_SEM_H
4146
static void
4247
tprint_sembuf(const struct sembuf *sb)
4348
{
4449
tprintf("{%u, %d, ", sb->sem_num, sb->sem_op);
4550
printflags(semop_flags, sb->sem_flg, "SEM_???");
4651
tprints("}");
4752
}
53+
#endif
4854

4955
static void
5056
tprint_sembuf_array(struct tcb *tcp, const long addr, const unsigned long count)
5157
{
58+
#if defined HAVE_SYS_SEM_H || defined HAVE_LINUX_SEM_H
5259
unsigned long max_count;
5360
struct sembuf sb;
5461

@@ -78,6 +85,9 @@ tprint_sembuf_array(struct tcb *tcp, const long addr, const unsigned long count)
7885

7986
tprints("]");
8087
}
88+
#else
89+
printaddr(addr);
90+
#endif
8191
tprintf(", %lu", count);
8292
}
8393

ipc_shm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232

3333
#include "defs.h"
3434

35-
#include <sys/shm.h>
35+
#ifdef HAVE_SYS_SHM_H
36+
# include <sys/shm.h>
37+
#elif defined HAVE_LINUX_SHM_H
38+
# include <linux/shm.h>
39+
#endif
3640

3741
#include "xlat/shm_resource_flags.h"
3842
#include "xlat/shm_flags.h"

ipc_shmctl.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,29 @@
3131
*/
3232

3333
#include "defs.h"
34-
#include "ipc_defs.h"
35-
36-
#include <sys/shm.h>
3734

3835
#include DEF_MPERS_TYPE(shmid_ds_t)
39-
#include <sys/shm.h>
36+
37+
#include "ipc_defs.h"
38+
39+
#ifdef HAVE_SYS_SHM_H
40+
/* The C library generally exports the struct the current kernel expects. */
41+
# include <sys/shm.h>
4042
typedef struct shmid_ds shmid_ds_t;
43+
#elif defined HAVE_LINUX_SHM_H
44+
/* The linux header might provide the right struct. */
45+
# include <linux/shm.h>
46+
typedef struct shmid64_ds shmid_ds_t;
47+
#endif
48+
4149
#include MPERS_DEFS
4250

4351
#include "xlat/shmctl_flags.h"
4452

4553
static void
4654
print_shmid_ds(struct tcb *tcp, const long addr, int cmd)
4755
{
56+
/* TODO: We don't properly decode old compat ipc calls. */
4857
if (cmd & IPC_64)
4958
cmd &= ~IPC_64;
5059
shmid_ds_t shmid_ds;

print_mq_attr.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@
2929
#include "defs.h"
3030

3131
#include DEF_MPERS_TYPE(mq_attr_t)
32+
3233
#ifdef HAVE_MQUEUE_H
3334
# include <mqueue.h>
3435
typedef struct mq_attr mq_attr_t;
36+
#elif defined HAVE_LINUX_MQUEUE_H
37+
# include <linux/types.h>
38+
# include <linux/mqueue.h>
39+
typedef struct mq_attr mq_attr_t;
3540
#endif
41+
3642
#include MPERS_DEFS
3743

3844
MPERS_PRINTER_DECL(void, printmqattr)(struct tcb *tcp, const long addr)
3945
{
40-
# ifndef HAVE_MQUEUE_H
41-
printaddr(addr);
42-
# else
46+
#if defined HAVE_MQUEUE_H || defined HAVE_LINUX_MQUEUE_H
4347
mq_attr_t attr;
4448
if (umove_or_printaddr(tcp, addr, &attr))
4549
return;
@@ -48,5 +52,7 @@ MPERS_PRINTER_DECL(void, printmqattr)(struct tcb *tcp, const long addr)
4852
tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}",
4953
(long) attr.mq_maxmsg, (long) attr.mq_msgsize,
5054
(long) attr.mq_curmsgs);
51-
# endif
55+
#else
56+
printaddr(addr);
57+
#endif
5258
}

0 commit comments

Comments
 (0)