Browse Source

mpers: add support of conditionally compiled printers

We used to declare and define all printers marked with
MPERS_PRINTER_DECL, including ifdef'ed ones.  That approach left us
no way to conditionally compile mpersified printers, which was not
a problem until btrfs ioctls appeared on the horizon.

With this change, those mpersified printers that are not going
to be compiled are also won't be declared and won't be added to
struct_printers.

This is implemented by filtering all source files containing
MPERS_PRINTER_DECL markers through CPP.  As a nice side effect, this
also lifts an ugly requirement of writing all MPERS_PRINTER_DECL
declarations in a single line.

* README-mpers: Update description of MPERS_PRINTER_DECL syntax.
* defs.h [IN_MPERS_BOOTSTRAP] (MPERS_PRINTER_DECL): Turn into
a recursive variadic macro.
[!IN_MPERS_BOOTSTRAP] (MPERS_PRINTER_DECL): Turn into a variadic macro.
All callers changed.
* Makefile.am (mpers_preproc_files, mpers_printer_decl_pattern):
New variables.
(CLEANFILES): Add $(mpers_preproc_files).
(%.c.mpers.i): New rule.
(printers.h, %_printer_decls.h, %_printer_defs.h): Use
mpers_preproc_files instead of srcdir_mpers_source_files,
use mpers_printer_decl_pattern.
* .gitignore: Add /*.mpers.i.
Dmitry V. Levin 3 years ago
parent
commit
a8fce09e34
16 changed files with 73 additions and 37 deletions
  1. 1
    0
      .gitignore
  2. 16
    7
      Makefile.am
  3. 1
    1
      README-mpers
  4. 11
    7
      defs.h
  5. 2
    1
      fetch_seccomp_fprog.c
  6. 4
    2
      fetch_struct_flock.c
  7. 5
    2
      fetch_struct_statfs.c
  8. 5
    1
      mpers_type.h
  9. 1
    1
      print_mq_attr.c
  10. 2
    1
      print_msgbuf.c
  11. 1
    1
      print_sigevent.c
  12. 16
    8
      print_time.c
  13. 1
    1
      print_timex.c
  14. 1
    1
      printrusage.c
  15. 4
    2
      printsiginfo.c
  16. 2
    1
      v4l2.c

+ 1
- 0
.gitignore View File

@@ -67,3 +67,4 @@ Makefile.in
67 67
 /native_printer_decls.h
68 68
 /native_printer_defs.h
69 69
 /printers.h
70
+/*.mpers.i

+ 16
- 7
Makefile.am View File

@@ -718,13 +718,14 @@ ioctls_all%.h: $(srcdir)/$(OS)/$(ARCH)/ioctls_inc%.h $(srcdir)/$(OS)/$(ARCH)/ioc
718 718
 
719 719
 BUILT_SOURCES = $(ioctl_redefs_h) $(ioctlent_h) \
720 720
 		native_printer_decls.h native_printer_defs.h printers.h sen.h sys_func.h .version
721
-CLEANFILES    = $(ioctl_redefs_h) $(ioctlent_h) \
721
+CLEANFILES    = $(ioctl_redefs_h) $(ioctlent_h) $(mpers_preproc_files) \
722 722
 		native_printer_decls.h native_printer_defs.h printers.h sen.h sys_func.h
723 723
 DISTCLEANFILES = gnu/stubs-32.h gnu/stubs-x32.h
724 724
 
725 725
 # defines mpers_source_files
726 726
 include mpers.am
727 727
 srcdir_mpers_source_files = $(patsubst %,$(srcdir)/%,$(mpers_source_files))
728
+mpers_preproc_files = $(mpers_source_files:.c=.c.mpers.i)
728 729
 
729 730
 mpers_NAME =
730 731
 mpers_PREFIX = $(mpers_NAME)_
@@ -764,28 +765,36 @@ m%_funcs.h: $(srcdir_mpers_source_files)
764 765
 
765 766
 # printers
766 767
 
767
-printers.h: $(srcdir_mpers_source_files)
768
+%.c.mpers.i: $(srcdir)/%.c
769
+	$(CPP) -P $(mpers_sh_opts) -DIN_MPERS_BOOTSTRAP $< -o $@
770
+
771
+mpers_printer_decl_pattern = ^MPERS_PRINTER_DECL(\([^,)]\+\),[[:space:]]*\([^,)]\+\),[[:space:]]*\([^)]\+\))$$
772
+
773
+printers.h: $(mpers_preproc_files)
768 774
 	echo '/* Generated by Makefile from $^; do not edit. */' > $@-t
769 775
 	echo 'typedef struct {' >> $@-t
770 776
 	for f in $^; do \
771
-		sed -n 's/^MPERS_PRINTER_DECL(\([^,]\+\),[[:space:]]*\([^)]\+\))\(.*\)/ \1 (*\2) \3;\n#define \2 MPERS_PRINTER_NAME(\2)\n/p' $$f || exit; \
777
+		sed -n 's/$(mpers_printer_decl_pattern)/ \1 (*\2)(\3);\n#define \2 MPERS_PRINTER_NAME(\2)\n/p' $$f \
778
+		|| exit; \
772 779
 	done >> $@-t
773 780
 	echo '} struct_printers;' >> $@-t
774 781
 	echo 'extern const struct_printers *printers;' >> $@-t
775 782
 	echo '#define MPERS_PRINTER_NAME(printer_name) printers->printer_name' >> $@-t
776 783
 	mv $@-t $@
777 784
 
778
-%_printer_decls.h: $(srcdir_mpers_source_files)
785
+%_printer_decls.h: $(mpers_preproc_files)
779 786
 	echo '/* Generated by Makefile from $^; do not edit. */' > $@-t
780 787
 	for f in $^; do \
781
-		sed -n 's/^MPERS_PRINTER_DECL(\([^,]\+\),[[:space:]]*\([^)]\+\))\(.*\)/extern \1 $(mpers_PREFIX)\2\3;/p' $$f || exit; \
788
+		sed -n 's/$(mpers_printer_decl_pattern)/extern \1 $(mpers_PREFIX)\2(\3);/p' $$f \
789
+		|| exit; \
782 790
 	done >> $@-t
783 791
 	mv $@-t $@
784 792
 
785
-%_printer_defs.h: $(srcdir_mpers_source_files)
793
+%_printer_defs.h: $(mpers_preproc_files)
786 794
 	echo '/* Generated by Makefile from $^; do not edit. */' > $@-t
787 795
 	for f in $^; do \
788
-		sed -n 's/^MPERS_PRINTER_DECL(\([^,]\+\),[[:space:]]*\([^)]\+\))\(.*\)/\.\2 = $(mpers_PREFIX)\2,/p' $$f || exit; \
796
+		sed -n 's/$(mpers_printer_decl_pattern)/\.\2 = $(mpers_PREFIX)\2,/p' $$f \
797
+		|| exit; \
789 798
 	done >> $@-t
790 799
 	mv $@-t $@
791 800
 

+ 1
- 1
README-mpers View File

@@ -8,7 +8,7 @@ be included conditionally;
8 8
 (containing definitions of these types or other behaviour-affecting
9 9
 defines);
10 10
 * printers should be defined
11
-as MPERS_PRINTER_DECL(return_type, function_name)(args),
11
+as MPERS_PRINTER_DECL(return_type, function_name, args),
12 12
 inside files that include MPERS_DEFS these printers should be called
13 13
 as MPERS_FUNC_NAME(function_name)(args), in other files
14 14
 they should be called just as function_name(args).

+ 11
- 7
defs.h View File

@@ -795,11 +795,17 @@ extern unsigned nsignals;
795 795
 extern unsigned nioctlents;
796 796
 extern unsigned num_quals;
797 797
 
798
-#if SUPPORTED_PERSONALITIES > 1
799
-# include "printers.h"
800
-#else
801
-# include "native_printer_decls.h"
802
-#endif
798
+#ifdef IN_MPERS_BOOTSTRAP
799
+/* Transform multi-line MPERS_PRINTER_DECL statements to one-liners.  */
800
+# define MPERS_PRINTER_DECL(type, name, ...) MPERS_PRINTER_DECL(type, name, __VA_ARGS__)
801
+#else /* !IN_MPERS_BOOTSTRAP */
802
+# if SUPPORTED_PERSONALITIES > 1
803
+#  include "printers.h"
804
+# else
805
+#  include "native_printer_decls.h"
806
+# endif
807
+# define MPERS_PRINTER_DECL(type, name, ...) type MPERS_FUNC_NAME(name)(__VA_ARGS__)
808
+#endif /* !IN_MPERS_BOOTSTRAP */
803 809
 
804 810
 /*
805 811
  * If you need non-NULL sysent[scno].sys_func and sysent[scno].sys_name
@@ -819,8 +825,6 @@ extern unsigned num_quals;
819 825
 
820 826
 #define SYS_FUNC(syscall_name) int SYS_FUNC_NAME(sys_ ## syscall_name)(struct tcb *tcp)
821 827
 
822
-#define MPERS_PRINTER_DECL(type, name) type MPERS_FUNC_NAME(name)
823
-
824 828
 /*
825 829
  * The kernel used to define 64-bit types on 64-bit systems on a per-arch
826 830
  * basis.  Some architectures would use unsigned long and others would use

+ 2
- 1
fetch_seccomp_fprog.c View File

@@ -34,7 +34,8 @@ typedef struct seccomp_fprog seccomp_fprog_t;
34 34
 
35 35
 #include MPERS_DEFS
36 36
 
37
-MPERS_PRINTER_DECL(bool, fetch_seccomp_fprog)(struct tcb *tcp, const long addr, void *p)
37
+MPERS_PRINTER_DECL(bool, fetch_seccomp_fprog,
38
+		   struct tcb *tcp, const long addr, void *p)
38 39
 {
39 40
 	struct seccomp_fprog *pfp = p;
40 41
 	seccomp_fprog_t mfp;

+ 4
- 2
fetch_struct_flock.c View File

@@ -51,7 +51,8 @@ typedef struct_kernel_flock64 struct_flock64;
51 51
 	 && FLOCK_MEMBERS_EQ(type, l_len) \
52 52
 	 && FLOCK_MEMBERS_EQ(type, l_pid))
53 53
 
54
-MPERS_PRINTER_DECL(bool, fetch_struct_flock)(struct tcb *tcp, const long addr, void *p)
54
+MPERS_PRINTER_DECL(bool, fetch_struct_flock,
55
+		   struct tcb *tcp, const long addr, void *p)
55 56
 {
56 57
 	struct_kernel_flock64 *pfl = p;
57 58
 	struct_flock mfl;
@@ -70,7 +71,8 @@ MPERS_PRINTER_DECL(bool, fetch_struct_flock)(struct tcb *tcp, const long addr, v
70 71
 	return true;
71 72
 }
72 73
 
73
-MPERS_PRINTER_DECL(bool, fetch_struct_flock64)(struct tcb *tcp, const long addr, void *p)
74
+MPERS_PRINTER_DECL(bool, fetch_struct_flock64,
75
+		   struct tcb *tcp, const long addr, void *p)
74 76
 {
75 77
 	struct_kernel_flock64 *pfl = p;
76 78
 	struct_flock64 mfl;

+ 5
- 2
fetch_struct_statfs.c View File

@@ -47,7 +47,8 @@ typedef struct statfs64 struct_statfs64;
47 47
 	else						\
48 48
 		dst = (unsigned long long) (src)
49 49
 
50
-MPERS_PRINTER_DECL(bool, fetch_struct_statfs)(struct tcb *tcp, const long addr, struct strace_statfs *p)
50
+MPERS_PRINTER_DECL(bool, fetch_struct_statfs,
51
+		   struct tcb *tcp, const long addr, struct strace_statfs *p)
51 52
 {
52 53
 	struct_statfs b;
53 54
 
@@ -84,7 +85,9 @@ MPERS_PRINTER_DECL(bool, fetch_struct_statfs)(struct tcb *tcp, const long addr,
84 85
 # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct_statfs64) + 4)
85 86
 #endif
86 87
 
87
-MPERS_PRINTER_DECL(bool, fetch_struct_statfs64)(struct tcb *tcp, const long addr, const unsigned long size, struct strace_statfs *p)
88
+MPERS_PRINTER_DECL(bool, fetch_struct_statfs64,
89
+		   struct tcb *tcp, const long addr, const unsigned long size,
90
+		   struct strace_statfs *p)
88 91
 {
89 92
 	struct_statfs64 b;
90 93
 

+ 5
- 1
mpers_type.h View File

@@ -39,5 +39,9 @@
39 39
 #else
40 40
 # define MPERS_PREFIX
41 41
 # define DEF_MPERS_TYPE(args) "empty.h"
42
-# define MPERS_DEFS "native_defs.h"
42
+# if IN_MPERS_BOOTSTRAP
43
+#  define MPERS_DEFS "empty.h"
44
+# else
45
+#  define MPERS_DEFS "native_defs.h"
46
+# endif
43 47
 #endif

+ 1
- 1
print_mq_attr.c View File

@@ -41,7 +41,7 @@ typedef struct mq_attr mq_attr_t;
41 41
 
42 42
 #include MPERS_DEFS
43 43
 
44
-MPERS_PRINTER_DECL(void, printmqattr)(struct tcb *tcp, const long addr)
44
+MPERS_PRINTER_DECL(void, printmqattr, struct tcb *tcp, const long addr)
45 45
 {
46 46
 #if defined HAVE_MQUEUE_H || defined HAVE_LINUX_MQUEUE_H
47 47
 	mq_attr_t attr;

+ 2
- 1
print_msgbuf.c View File

@@ -38,7 +38,8 @@
38 38
 typedef struct msgbuf msgbuf_t;
39 39
 #include MPERS_DEFS
40 40
 
41
-MPERS_PRINTER_DECL(void, tprint_msgbuf)(struct tcb *tcp, const long addr, const unsigned long count)
41
+MPERS_PRINTER_DECL(void, tprint_msgbuf,
42
+		   struct tcb *tcp, const long addr, const unsigned long count)
42 43
 {
43 44
 	msgbuf_t msg;
44 45
 

+ 1
- 1
print_sigevent.c View File

@@ -35,7 +35,7 @@
35 35
 #include <signal.h>
36 36
 #include "xlat/sigev_value.h"
37 37
 
38
-MPERS_PRINTER_DECL(void, print_sigevent)(struct tcb *tcp, const long addr)
38
+MPERS_PRINTER_DECL(void, print_sigevent, struct tcb *tcp, const long addr)
39 39
 {
40 40
 	struct_sigevent sev;
41 41
 

+ 16
- 8
print_time.c View File

@@ -73,7 +73,8 @@ print_timeval_t(const timeval_t *t)
73 73
 	tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
74 74
 }
75 75
 
76
-MPERS_PRINTER_DECL(void, print_timespec)(struct tcb *tcp, const long addr)
76
+MPERS_PRINTER_DECL(void, print_timespec,
77
+		   struct tcb *tcp, const long addr)
77 78
 {
78 79
 	timespec_t t;
79 80
 
@@ -83,7 +84,8 @@ MPERS_PRINTER_DECL(void, print_timespec)(struct tcb *tcp, const long addr)
83 84
 	print_timespec_t(&t);
84 85
 }
85 86
 
86
-MPERS_PRINTER_DECL(const char *, sprint_timespec)(struct tcb *tcp, const long addr)
87
+MPERS_PRINTER_DECL(const char *, sprint_timespec,
88
+		   struct tcb *tcp, const long addr)
87 89
 {
88 90
 	timespec_t t;
89 91
 	static char buf[sizeof(time_fmt) + 3 * sizeof(t)];
@@ -101,7 +103,8 @@ MPERS_PRINTER_DECL(const char *, sprint_timespec)(struct tcb *tcp, const long ad
101 103
 	return buf;
102 104
 }
103 105
 
104
-MPERS_PRINTER_DECL(void, print_timespec_utime_pair)(struct tcb *tcp, const long addr)
106
+MPERS_PRINTER_DECL(void, print_timespec_utime_pair,
107
+		   struct tcb *tcp, const long addr)
105 108
 {
106 109
 	timespec_t t[2];
107 110
 
@@ -115,7 +118,8 @@ MPERS_PRINTER_DECL(void, print_timespec_utime_pair)(struct tcb *tcp, const long
115 118
 	tprints("]");
116 119
 }
117 120
 
118
-MPERS_PRINTER_DECL(void, print_itimerspec)(struct tcb *tcp, const long addr)
121
+MPERS_PRINTER_DECL(void, print_itimerspec,
122
+		   struct tcb *tcp, const long addr)
119 123
 {
120 124
 	timespec_t t[2];
121 125
 
@@ -129,7 +133,8 @@ MPERS_PRINTER_DECL(void, print_itimerspec)(struct tcb *tcp, const long addr)
129 133
 	tprints("}");
130 134
 }
131 135
 
132
-MPERS_PRINTER_DECL(void, print_timeval)(struct tcb *tcp, const long addr)
136
+MPERS_PRINTER_DECL(void, print_timeval,
137
+		   struct tcb *tcp, const long addr)
133 138
 {
134 139
 	timeval_t t;
135 140
 
@@ -139,7 +144,8 @@ MPERS_PRINTER_DECL(void, print_timeval)(struct tcb *tcp, const long addr)
139 144
 	print_timeval_t(&t);
140 145
 }
141 146
 
142
-MPERS_PRINTER_DECL(void, print_timeval_pair)(struct tcb *tcp, const long addr)
147
+MPERS_PRINTER_DECL(void, print_timeval_pair,
148
+		   struct tcb *tcp, const long addr)
143 149
 {
144 150
 	timeval_t t[2];
145 151
 
@@ -153,7 +159,8 @@ MPERS_PRINTER_DECL(void, print_timeval_pair)(struct tcb *tcp, const long addr)
153 159
 	tprints("]");
154 160
 }
155 161
 
156
-MPERS_PRINTER_DECL(const char *, sprint_timeval)(struct tcb *tcp, const long addr)
162
+MPERS_PRINTER_DECL(const char *, sprint_timeval,
163
+		   struct tcb *tcp, const long addr)
157 164
 {
158 165
 	timeval_t t;
159 166
 	static char buf[sizeof(time_fmt) + 3 * sizeof(t)];
@@ -171,7 +178,8 @@ MPERS_PRINTER_DECL(const char *, sprint_timeval)(struct tcb *tcp, const long add
171 178
 	return buf;
172 179
 }
173 180
 
174
-MPERS_PRINTER_DECL(void, print_itimerval)(struct tcb *tcp, const long addr)
181
+MPERS_PRINTER_DECL(void, print_itimerval,
182
+		   struct tcb *tcp, const long addr)
175 183
 {
176 184
 	timeval_t t[2];
177 185
 

+ 1
- 1
print_timex.c View File

@@ -40,7 +40,7 @@ typedef struct timex struct_timex;
40 40
 #include "xlat/adjtimex_modes.h"
41 41
 #include "xlat/adjtimex_status.h"
42 42
 
43
-MPERS_PRINTER_DECL(int, print_timex)(struct tcb *tcp, const long addr)
43
+MPERS_PRINTER_DECL(int, print_timex, struct tcb *tcp, const long addr)
44 44
 {
45 45
 	struct_timex tx;
46 46
 

+ 1
- 1
printrusage.c View File

@@ -37,7 +37,7 @@ typedef struct rusage rusage_t;
37 37
 
38 38
 #include MPERS_DEFS
39 39
 
40
-MPERS_PRINTER_DECL(void, printrusage)(struct tcb *tcp, long addr)
40
+MPERS_PRINTER_DECL(void, printrusage, struct tcb *tcp, long addr)
41 41
 {
42 42
 	rusage_t ru;
43 43
 

+ 4
- 2
printsiginfo.c View File

@@ -228,7 +228,8 @@ printsiginfo(const siginfo_t *sip)
228 228
 	tprints("}");
229 229
 }
230 230
 
231
-MPERS_PRINTER_DECL(void, printsiginfo_at)(struct tcb *tcp, long addr)
231
+MPERS_PRINTER_DECL(void, printsiginfo_at,
232
+		   struct tcb *tcp, long addr)
232 233
 {
233 234
 	siginfo_t si;
234 235
 
@@ -243,7 +244,8 @@ print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
243 244
 	return true;
244 245
 }
245 246
 
246
-MPERS_PRINTER_DECL(void, print_siginfo_array)(struct tcb *tcp, unsigned long addr, unsigned long len)
247
+MPERS_PRINTER_DECL(void, print_siginfo_array,
248
+		   struct tcb *tcp, unsigned long addr, unsigned long len)
247 249
 {
248 250
 	siginfo_t si;
249 251
 

+ 2
- 1
v4l2.c View File

@@ -846,7 +846,8 @@ print_v4l2_create_buffers(struct tcb *tcp, const long arg)
846 846
 }
847 847
 #endif /* VIDIOC_CREATE_BUFS */
848 848
 
849
-MPERS_PRINTER_DECL(int, v4l2_ioctl)(struct tcb *tcp, const unsigned int code, const long arg)
849
+MPERS_PRINTER_DECL(int, v4l2_ioctl,
850
+		   struct tcb *tcp, const unsigned int code, const long arg)
850 851
 {
851 852
 	if (!verbose(tcp))
852 853
 		return RVAL_DECODED;

Loading…
Cancel
Save