Browse Source

failtest: compile fix for OpenBSD

OpenBSD doesn't idempotent-wrap sys/mman.h, so when we #define mmap to
an alternative, it fails to compile when sys/mman.h is included again.

Workaround is not to #define mmap to add arguments on Open BSD.
Rusty Russell 14 years ago
parent
commit
e18e80fe17
3 changed files with 17 additions and 0 deletions
  1. 9 0
      ccan/failtest/failtest.c
  2. 6 0
      ccan/failtest/failtest_override.h
  3. 2 0
      ccan/failtest/failtest_proto.h

+ 9 - 0
ccan/failtest/failtest.c

@@ -1177,6 +1177,15 @@ void *failtest_mmap(void *addr, size_t length, int prot, int flags,
 	return p->u.mmap.ret;
 	return p->u.mmap.ret;
 }
 }
 
 
+/* Since OpenBSD can't handle adding args, we use this file and line.
+ * This will make all mmaps look the same, reducing coverage. */
+void *failtest_mmap_noloc(void *addr, size_t length, int prot, int flags,
+			  int fd, off_t offset)
+{
+	return failtest_mmap(addr, length, prot, flags, fd, offset,
+			     __FILE__, __LINE__);
+}
+
 static void cleanup_pipe(struct pipe_call *call, bool restore)
 static void cleanup_pipe(struct pipe_call *call, bool restore)
 {
 {
 	trace("cleaning up pipe fd=%i%s,%i%s\n",
 	trace("cleaning up pipe fd=%i%s,%i%s\n",

+ 6 - 0
ccan/failtest/failtest_override.h

@@ -64,9 +64,15 @@
 #define fcntl(fd, ...) failtest_fcntl((fd), __FILE__, __LINE__, __VA_ARGS__)
 #define fcntl(fd, ...) failtest_fcntl((fd), __FILE__, __LINE__, __VA_ARGS__)
 
 
 #undef mmap
 #undef mmap
+/* OpenBSD doesn't idempotent-protect sys/mman.h, so we can't add args. */
+#ifdef __OpenBSD__
+#define mmap(addr, length, prot, flags, fd, offset)			\
+	failtest_mmap_noloc((addr), (length), (prot), (flags), (fd), (offset))
+#else
 #define mmap(addr, length, prot, flags, fd, offset)			\
 #define mmap(addr, length, prot, flags, fd, offset)			\
 	failtest_mmap((addr), (length), (prot), (flags), (fd), (offset), \
 	failtest_mmap((addr), (length), (prot), (flags), (fd), (offset), \
 		      __FILE__, __LINE__)
 		      __FILE__, __LINE__)
+#endif /* !__OpenBSD__ */
 
 
 #undef lseek
 #undef lseek
 #define lseek(fd, offset, whence)					\
 #define lseek(fd, offset, whence)					\

+ 2 - 0
ccan/failtest/failtest_proto.h

@@ -23,6 +23,8 @@ ssize_t failtest_pwrite(int fd, const void *buf, size_t count, off_t offset,
 			const char *file, unsigned line);
 			const char *file, unsigned line);
 void *failtest_mmap(void *addr, size_t length, int prot, int flags,
 void *failtest_mmap(void *addr, size_t length, int prot, int flags,
 		    int fd, off_t offset, const char *file, unsigned line);
 		    int fd, off_t offset, const char *file, unsigned line);
+void *failtest_mmap_noloc(void *addr, size_t length, int prot, int flags,
+			  int fd, off_t offset);
 off_t failtest_lseek(int fd, off_t offset, int whence,
 off_t failtest_lseek(int fd, off_t offset, int whence,
 		     const char *file, unsigned line);
 		     const char *file, unsigned line);
 int failtest_close(int fd, const char *file, unsigned line);
 int failtest_close(int fd, const char *file, unsigned line);