From 078a4e406035deacbeca985b7c7d613d654bbb7d Mon Sep 17 00:00:00 2001 From: Valentin Gatien-Baron Date: Sun, 1 Aug 2021 07:58:06 -0400 Subject: [PATCH 1/3] group cpp variables according to whether they are set by default --- src/Makefile | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/Makefile b/src/Makefile index ad2b797..15fe96a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,31 +1,11 @@ # # Notes: # -# * Compilation Defines: +# * Compilation Defines that are set by default: # # FAKE_STAT # - Enables time faking also for files' timestamps. # -# FAKE_FILE_TIMESTAMPS, FAKE_UTIME -# - Enables time faking for the utime* functions. If enabled via -# FAKE_UTIME define instead of FAKE_FILE_TIMESTAMPS, the faking -# defaults to off without FAKE_UTIME in the environment. -# -# NO_ATFILE -# - Disables support for the fstatat() group of functions -# -# PTHREAD_SINGLETHREADED_TIME -# - Define this if you want to single-thread time() ... there ARE -# possible caching side-effects in a multithreaded environment -# without this, but the performance impact may require you to -# try it unsynchronized. -# -# FAKE_INTERNAL_CALLS -# - Also intercept libc internal __functions, e.g. not just time(), -# but also __time(). Enhances compatibility with applications -# that make use of low-level system calls, such as Java Virtual -# Machines. -# # FAKE_SLEEP # - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll() # @@ -35,6 +15,28 @@ # FAKE_PTHREAD # - Intercept pthread_cond_timedwait # +# FAKE_INTERNAL_CALLS +# - Also intercept libc internal __functions, e.g. not just time(), +# but also __time(). Enhances compatibility with applications +# that make use of low-level system calls, such as Java Virtual +# Machines. +# +# PTHREAD_SINGLETHREADED_TIME (only set in libfaketimeMT.so) +# - Define this if you want to single-thread time() ... there ARE +# possible caching side-effects in a multithreaded environment +# without this, but the performance impact may require you to +# try it unsynchronized. +# +# * Compilation Defines that are unset by default: +# +# FAKE_FILE_TIMESTAMPS, FAKE_UTIME +# - Enables time faking for the utime* functions. If enabled via +# FAKE_UTIME define instead of FAKE_FILE_TIMESTAMPS, the faking +# defaults to off without FAKE_UTIME in the environment. +# +# NO_ATFILE +# - Disables support for the fstatat() group of functions +# # FAKE_SETTIME # - Intercept clock_settime(), settimeofday(), and adjtime() # From 3155e0ee383d09c2003304f64c64c2376de3f192 Mon Sep 17 00:00:00 2001 From: Valentin Gatien-Baron Date: Sun, 1 Aug 2021 08:02:59 -0400 Subject: [PATCH 2/3] try to clarify the help of a couple of compilatoin variables --- src/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Makefile b/src/Makefile index 15fe96a..15e1c68 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,7 +4,7 @@ # * Compilation Defines that are set by default: # # FAKE_STAT -# - Enables time faking also for files' timestamps. +# - Enables time faking when reading files' timestamps. # # FAKE_SLEEP # - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll() @@ -31,8 +31,9 @@ # # FAKE_FILE_TIMESTAMPS, FAKE_UTIME # - Enables time faking for the utime* functions. If enabled via -# FAKE_UTIME define instead of FAKE_FILE_TIMESTAMPS, the faking -# defaults to off without FAKE_UTIME in the environment. +# FAKE_FILE_TIMESTAMPS, the faking is opt-in at runtime using +# with the FAKE_UTIME environment variable. If enabled via +# FAKE_UTIME, the faking is opt-out at runtime. # # NO_ATFILE # - Disables support for the fstatat() group of functions From e26859e5ca10b669faf357b576f8a9f2300619d8 Mon Sep 17 00:00:00 2001 From: Valentin Gatien-Baron Date: Sun, 1 Aug 2021 08:41:17 -0400 Subject: [PATCH 3/3] add a build variable to opt-out of some behaviors Specifically behaviors that increase the chance that a wrapped program will not behave like an unwrapped program does, thus causing reliability issues. --- src/Makefile | 11 +++++++++++ src/libfaketime.c | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/Makefile b/src/Makefile index 15e1c68..c1b890d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -56,6 +56,17 @@ # -Dvariadic_promotion_t=int into CFLAGS). See src/faketime_common.h for # more info. # +# FAKE_STATELESS +# - Remove support for any functionality that requires sharing state across +# threads of a process, or different processes. This decreases the risk of +# interference with a program's normal execution, at the cost of supporting +# fewer ways of specifying the time. +# Concretely, this currently: +# - disables PTHREAD_SINGLETHREADED_TIME, which can cause deadlocks in +# multithreaded programs that fork due to making clock_gettime not +# async-signal-safe +# - disables all shared-memory across processes +# # FORCE_MONOTONIC_FIX # - If the test program hangs forever on # " pthread_cond_timedwait: CLOCK_MONOTONIC test diff --git a/src/libfaketime.c b/src/libfaketime.c index afafc5d..6def8f2 100644 --- a/src/libfaketime.c +++ b/src/libfaketime.c @@ -60,6 +60,9 @@ #include "time_ops.h" #include "faketime_common.h" +#if defined PTHREAD_SINGLETHREADED_TIME && defined FAKE_STATELESS +#undef PTHREAD_SINGLETHREADED_TIME +#endif /* pthread-handling contributed by David North, TDI in version 0.7 */ #if defined PTHREAD_SINGLETHREADED_TIME || defined FAKE_PTHREAD @@ -2652,7 +2655,11 @@ static void ftpl_init(void) initialized = 1; +#ifdef FAKE_STATELESS + if (0) ft_shm_init(); +#else ft_shm_init(); +#endif #ifdef FAKE_STAT if (getenv("NO_FAKE_STAT")!=NULL) {