1*1b191cb5SApple OSS Distributions #include <fcntl.h> 2*1b191cb5SApple OSS Distributions #include <sys/fcntl.h> 3*1b191cb5SApple OSS Distributions #include <darwintest.h> 4*1b191cb5SApple OSS Distributions #include <darwintest_utils.h> 5*1b191cb5SApple OSS Distributions 6*1b191cb5SApple OSS Distributions 7*1b191cb5SApple OSS Distributions T_GLOBAL_META( 8*1b191cb5SApple OSS Distributions T_META_NAMESPACE("xnu.ipc"), 9*1b191cb5SApple OSS Distributions T_META_RADAR_COMPONENT_NAME("xnu"), 10*1b191cb5SApple OSS Distributions T_META_RADAR_COMPONENT_VERSION("IPC"), 11*1b191cb5SApple OSS Distributions T_META_OWNER("jonathan_w_adams"), 12*1b191cb5SApple OSS Distributions T_META_RUN_CONCURRENTLY(TRUE)); 13*1b191cb5SApple OSS Distributions 14*1b191cb5SApple OSS Distributions /* 15*1b191cb5SApple OSS Distributions * See rdar://77264182: xnu's lockf implementation had trouble 16*1b191cb5SApple OSS Distributions * with l_len = 0 (e.g. go to EOF) being treated differently 17*1b191cb5SApple OSS Distributions * than (l_start + l_len - 1) == OFF_MAX, even though they are 18*1b191cb5SApple OSS Distributions * effectively the same thing. ~25 loops of this test was enough 19*1b191cb5SApple OSS Distributions * to get an Intel mac into an infinite loop in the kernel. 20*1b191cb5SApple OSS Distributions */ 21*1b191cb5SApple OSS Distributions T_DECL(lockf_EOF_77264182, 22*1b191cb5SApple OSS Distributions "try to stress out lockf requests around OFF_MAX/EOF", 23*1b191cb5SApple OSS Distributions T_META_CHECK_LEAKS(false)) 24*1b191cb5SApple OSS Distributions { 25*1b191cb5SApple OSS Distributions const char *dir = dt_tmpdir(); 26*1b191cb5SApple OSS Distributions int fd; 27*1b191cb5SApple OSS Distributions T_ASSERT_POSIX_SUCCESS(chdir(dir), "chdir(%s)", dir); 28*1b191cb5SApple OSS Distributions 29*1b191cb5SApple OSS Distributions T_ASSERT_POSIX_SUCCESS((fd = open("lockf_EOF_test", O_CREAT | O_RDWR, 0666)), "open(lockf_EOF_test)"); 30*1b191cb5SApple OSS Distributions 31*1b191cb5SApple OSS Distributions /* 32*1b191cb5SApple OSS Distributions * At each loop, we do: 33*1b191cb5SApple OSS Distributions * write lock [OFF_MAX - loop, EOF) 34*1b191cb5SApple OSS Distributions * unlock [OFF_MAX - loop, OFF_MAX) 35*1b191cb5SApple OSS Distributions * write lock [OFF_MAX - loop - 1, OFF_MAX) 36*1b191cb5SApple OSS Distributions */ 37*1b191cb5SApple OSS Distributions int loops; 38*1b191cb5SApple OSS Distributions for (loops = 0; loops < 100; loops++) { 39*1b191cb5SApple OSS Distributions struct flock fl = { 40*1b191cb5SApple OSS Distributions .l_start = OFF_MAX - loops, 41*1b191cb5SApple OSS Distributions .l_len = 0, 42*1b191cb5SApple OSS Distributions .l_pid = getpid(), 43*1b191cb5SApple OSS Distributions .l_type = F_WRLCK, 44*1b191cb5SApple OSS Distributions .l_whence = SEEK_SET 45*1b191cb5SApple OSS Distributions }; 46*1b191cb5SApple OSS Distributions T_ASSERT_POSIX_SUCCESS(fcntl(fd, F_SETLK, &fl), "wrlock"); 47*1b191cb5SApple OSS Distributions fl.l_len = OFF_MAX - fl.l_start + 1; 48*1b191cb5SApple OSS Distributions fl.l_type = F_UNLCK; 49*1b191cb5SApple OSS Distributions T_ASSERT_POSIX_SUCCESS(fcntl(fd, F_SETLK, &fl), "unlock"); 50*1b191cb5SApple OSS Distributions fl.l_start--; 51*1b191cb5SApple OSS Distributions fl.l_len++; 52*1b191cb5SApple OSS Distributions fl.l_type = F_WRLCK; 53*1b191cb5SApple OSS Distributions T_ASSERT_POSIX_SUCCESS(fcntl(fd, F_SETLK, &fl), "wrlock 2"); 54*1b191cb5SApple OSS Distributions } 55*1b191cb5SApple OSS Distributions T_PASS("did %d loops", loops); 56*1b191cb5SApple OSS Distributions } 57