From f3d3cca63d1e2500764279f7b4fc302fd8106676 Mon Sep 17 00:00:00 2001 From: Frank Busse Date: Wed, 3 Oct 2018 22:23:49 +0100 Subject: add support for klee-replay on OSX * also adds klee-replay as dependency for systemtests --- tools/klee-replay/CMakeLists.txt | 16 +++++----------- tools/klee-replay/file-creator.c | 26 +++++++++++++++++++++----- tools/klee-replay/klee-replay.c | 10 +++++++++- tools/klee-replay/klee-replay.h | 1 + 4 files changed, 36 insertions(+), 17 deletions(-) (limited to 'tools') diff --git a/tools/klee-replay/CMakeLists.txt b/tools/klee-replay/CMakeLists.txt index e0eb8d07..6388df50 100644 --- a/tools/klee-replay/CMakeLists.txt +++ b/tools/klee-replay/CMakeLists.txt @@ -6,7 +6,7 @@ # License. See LICENSE.TXT for details. # #===------------------------------------------------------------------------===# -if (HAVE_PTY_H) +if (HAVE_PTY_H OR HAVE_UTIL_H) add_executable(klee-replay fd_init.c file-creator.c @@ -15,16 +15,10 @@ if (HAVE_PTY_H) ) target_link_libraries(klee-replay PRIVATE kleeBasic ${LIBCAP_LIBRARIES}) - # FIXME: This isn't quite right. This is actually an implementation detail - # of glibc not Linux. Really we need to test if we can use `openpty()` - # with/without an additional library. - if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") - if (NOT LIBUTIL_LIBRARIES) - message(FATAL_ERROR "klee-replay needs libutil under Linux") - endif() + if (openpty_in_libutil) target_link_libraries(klee-replay PRIVATE ${LIBUTIL_LIBRARIES}) - endif() -install(TARGETS klee-replay RUNTIME DESTINATION bin) + endif (openpty_in_libutil) + install(TARGETS klee-replay RUNTIME DESTINATION bin) else() - message(WARNING "Not building klee-replay due to missing \"pty.h\" header file") + message(WARNING "Not building klee-replay due to missing library for pty functions.") endif() diff --git a/tools/klee-replay/file-creator.c b/tools/klee-replay/file-creator.c index 505fb8d7..714a1112 100644 --- a/tools/klee-replay/file-creator.c +++ b/tools/klee-replay/file-creator.c @@ -17,13 +17,23 @@ #include #include #include -#include -#include #include #include #include #include +#ifdef HAVE_PTY_H +#include +#elif defined(HAVE_UTIL_H) +#include +#endif + +#if defined(__APPLE__) +#include +#else +#include +#endif + static void create_file(int target_fd, const char *target_name, exe_disk_file_t *dfile, @@ -105,7 +115,9 @@ static int create_char_dev(const char *fname, exe_disk_file_t *dfile, ts->c_oflag = 5; ts->c_cflag = 1215; ts->c_lflag = 35287; +#ifndef __APPLE__ ts->c_line = 0; +#endif ts->c_cc[0] = '\x03'; ts->c_cc[1] = '\x1c'; ts->c_cc[2] = '\x7f'; @@ -152,16 +164,20 @@ static int create_char_dev(const char *fname, exe_disk_file_t *dfile, fprintf(stderr, "note: pty slave: setting raw mode\n"); { - struct termio mode; + struct termios mode; - int res = ioctl(aslave, TCGETA, &mode); + int res = tcgetattr(aslave, &mode); assert(!res); mode.c_iflag = IGNBRK; +#if defined(__APPLE__) + mode.c_oflag &= ~(ONLCR | OCRNL | ONLRET); +#else mode.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONLRET); +#endif mode.c_lflag = 0; mode.c_cc[VMIN] = 1; mode.c_cc[VTIME] = 0; - res = ioctl(aslave, TCSETA, &mode); + res = tcsetattr(aslave, TCSANOW, &mode); assert(res == 0); } diff --git a/tools/klee-replay/klee-replay.c b/tools/klee-replay/klee-replay.c index 6b4fb8f4..150a82e8 100644 --- a/tools/klee-replay/klee-replay.c +++ b/tools/klee-replay/klee-replay.c @@ -22,9 +22,17 @@ #include #include #include -#include + #include +#if defined(__APPLE__) +#include +#define fgetc_unlocked(x) fgetc (x) +#define fputc_unlocked(x,y) fputc (x,y) +#else +#include +#endif + #ifdef HAVE_SYS_CAPABILITY_H #include #endif diff --git a/tools/klee-replay/klee-replay.h b/tools/klee-replay/klee-replay.h index 668b5e3e..09cb6603 100644 --- a/tools/klee-replay/klee-replay.h +++ b/tools/klee-replay/klee-replay.h @@ -13,6 +13,7 @@ #define _LARGEFILE64_SOURCE #define _FILE_OFFSET_BITS 64 +#include "klee/Config/config.h" // FIXME: This is a hack. #include "../../runtime/POSIX/fd.h" #include -- cgit 1.4.1