@@ -204,6 +204,75 @@ TEST(TestRtsanInterceptors, MunmapDiesWhenRealtime) {
204204 ExpectNonRealtimeSurvival (Func);
205205}
206206
207+ class RtsanOpenedMmapTest : public RtsanFileTest {
208+ protected:
209+ void SetUp () override {
210+ RtsanFileTest::SetUp ();
211+ file = fopen (GetTemporaryFilePath (), " w+" );
212+ ASSERT_THAT (file, Ne (nullptr ));
213+ fd = fileno (file);
214+ ASSERT_THAT (fd, Ne (-1 ));
215+ int ret = ftruncate (GetOpenFd (), size);
216+ ASSERT_THAT (ret, Ne (-1 ));
217+ addr =
218+ mmap (nullptr , size, PROT_READ | PROT_WRITE, MAP_SHARED, GetOpenFd (), 0 );
219+ ASSERT_THAT (addr, Ne (MAP_FAILED));
220+ ASSERT_THAT (addr, Ne (nullptr ));
221+ }
222+
223+ void TearDown () override {
224+ if (addr != nullptr && addr != MAP_FAILED)
225+ munmap (addr, size);
226+ RtsanFileTest::TearDown ();
227+ }
228+
229+ void *GetAddr () { return addr; }
230+ static constexpr size_t GetSize () { return size; }
231+
232+ int GetOpenFd () { return fd; }
233+
234+ private:
235+ void *addr = nullptr ;
236+ static constexpr size_t size = 4096 ;
237+ FILE *file = nullptr ;
238+ int fd = -1 ;
239+ };
240+
241+ TEST_F (RtsanOpenedMmapTest, MadviseDiesWhenRealtime) {
242+ auto Func = [this ]() { madvise (GetAddr (), GetSize (), MADV_NORMAL); };
243+ ExpectRealtimeDeath (Func, " madvise" );
244+ ExpectNonRealtimeSurvival (Func);
245+ }
246+
247+ TEST_F (RtsanOpenedMmapTest, PosixMadviseDiesWhenRealtime) {
248+ auto Func = [this ]() { posix_madvise (GetAddr (), GetSize (), MADV_NORMAL); };
249+ ExpectRealtimeDeath (Func, " posix_madvise" );
250+ ExpectNonRealtimeSurvival (Func);
251+ }
252+
253+ TEST_F (RtsanOpenedMmapTest, MprotectDiesWhenRealtime) {
254+ auto Func = [this ]() { mprotect (GetAddr (), GetSize (), PROT_READ); };
255+ ExpectRealtimeDeath (Func, " mprotect" );
256+ ExpectNonRealtimeSurvival (Func);
257+ }
258+
259+ TEST_F (RtsanOpenedMmapTest, MsyncDiesWhenRealtime) {
260+ auto Func = [this ]() { msync (GetAddr (), GetSize (), MS_INVALIDATE); };
261+ ExpectRealtimeDeath (Func, " msync" );
262+ ExpectNonRealtimeSurvival (Func);
263+ }
264+
265+ TEST_F (RtsanOpenedMmapTest, MincoreDiesWhenRealtime) {
266+ #if SANITIZER_APPLE
267+ std::vector<char > vec (GetSize () / 1024 );
268+ #else
269+ std::vector<unsigned char > vec (GetSize () / 1024 );
270+ #endif
271+ auto Func = [this , &vec]() { mincore (GetAddr (), GetSize (), vec.data ()); };
272+ ExpectRealtimeDeath (Func, " mincore" );
273+ ExpectNonRealtimeSurvival (Func);
274+ }
275+
207276TEST (TestRtsanInterceptors, ShmOpenDiesWhenRealtime) {
208277 auto Func = []() { shm_open (" /rtsan_test_shm" , O_CREAT | O_RDWR, 0 ); };
209278 ExpectRealtimeDeath (Func, " shm_open" );
0 commit comments