@@ -285,6 +285,33 @@ INTERCEPTOR(int, unlinkat, int fd, const char *pathname, int flag) {
285285 return REAL (unlinkat)(fd, pathname, flag);
286286}
287287
288+ INTERCEPTOR (int , truncate, const char *pathname, off_t length) {
289+ __rtsan_notify_intercepted_call (" truncate" );
290+ return REAL (truncate)(pathname, length);
291+ }
292+
293+ INTERCEPTOR (int , ftruncate, int fd, off_t length) {
294+ __rtsan_notify_intercepted_call (" ftruncate" );
295+ return REAL (ftruncate)(fd, length);
296+ }
297+
298+ #if SANITIZER_LINUX
299+ INTERCEPTOR (int , truncate64, const char *pathname, off64_t length) {
300+ __rtsan_notify_intercepted_call (" truncate64" );
301+ return REAL (truncate64)(pathname, length);
302+ }
303+
304+ INTERCEPTOR (int , ftruncate64, int fd, off64_t length) {
305+ __rtsan_notify_intercepted_call (" ftruncate64" );
306+ return REAL (ftruncate64)(fd, length);
307+ }
308+ #define RTSAN_MAYBE_INTERCEPT_TRUNCATE64 INTERCEPT_FUNCTION (truncate64)
309+ #define RTSAN_MAYBE_INTERCEPT_FTRUNCATE64 INTERCEPT_FUNCTION (ftruncate64)
310+ #else
311+ #define RTSAN_MAYBE_INTERCEPT_TRUNCATE64
312+ #define RTSAN_MAYBE_INTERCEPT_FTRUNCATE64
313+ #endif
314+
288315// Streams
289316
290317INTERCEPTOR (FILE *, fopen, const char *path, const char *mode) {
@@ -1437,6 +1464,10 @@ void __rtsan::InitializeInterceptors() {
14371464 RTSAN_MAYBE_INTERCEPT_READLINKAT;
14381465 INTERCEPT_FUNCTION (unlink);
14391466 INTERCEPT_FUNCTION (unlinkat);
1467+ INTERCEPT_FUNCTION (truncate);
1468+ INTERCEPT_FUNCTION (ftruncate);
1469+ RTSAN_MAYBE_INTERCEPT_TRUNCATE64;
1470+ RTSAN_MAYBE_INTERCEPT_FTRUNCATE64;
14401471 INTERCEPT_FUNCTION (fopen);
14411472 RTSAN_MAYBE_INTERCEPT_FOPEN64;
14421473 RTSAN_MAYBE_INTERCEPT_FREOPEN64;
0 commit comments