]>
git.saurik.com Git - apple/xnu.git/blob - tests/pwrite_avoid_sigxfsz_28581610.c
2 * testname: pwrite_avoid_sigxfsz_28581610
5 #include <darwintest.h>
10 #include <sys/resource.h>
14 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
16 #define TMP_FILE_PATH "/tmp/test_pwrite_28581610"
18 static sigjmp_buf xfsz_jmpbuf
;
20 void xfsz_signal(int);
23 xfsz_signal(__unused
int signo
)
25 siglongjmp(xfsz_jmpbuf
, 1);
28 T_DECL(pwrite
, "Tests avoiding SIGXFSZ with pwrite and odd offsets",
35 static const int offs
[] = { -1, -1 * 1024, -1 * 1024 * 16, -1 * 1024 * 1024 * 16, 0 };
36 static unsigned char buffer
[1048576];
39 /* We expect zero SIGXFSZ signals because we have no file size limits */
40 crl
.rlim_cur
= crl
.rlim_max
= RLIM_INFINITY
;
41 ret
= setrlimit(RLIMIT_FSIZE
, &crl
);
42 T_ASSERT_POSIX_SUCCESS(ret
, "setting infinite file size limit");
44 /* we just needed root to setup unlimited file size */
45 remove(TMP_FILE_PATH
);
48 /* We just want an empty regular file to test with */
49 fd
= open(TMP_FILE_PATH
, O_RDWR
| O_CREAT
| O_EXCL
, 0777);
50 T_ASSERT_POSIX_SUCCESS(fd
, "opening fd on temp file %s.", TMP_FILE_PATH
);
52 /* sanity check that this new file is really zero bytes in size */
53 ret
= fstat(fd
, &f_stat
);
54 T_ASSERT_POSIX_SUCCESS(ret
, "stat() fd on temp file.");
55 T_ASSERT_TRUE(0 == f_stat
.st_size
, "ensure %s is empty", TMP_FILE_PATH
);
57 /* sanity check that ftruncate() considers negative offsets an error */
58 for (x
= 0; offs
[x
] != 0; x
++) {
59 ret
= ftruncate(fd
, offs
[x
]);
60 T_ASSERT_TRUE(((ret
== -1) && (errno
== EINVAL
)),
61 "negative offset %d", offs
[x
]);
66 /* we want to get the EFBIG errno but without a SIGXFSZ signal */
67 if (!sigsetjmp(xfsz_jmpbuf
, 1)) {
68 signal(SIGXFSZ
, xfsz_signal
);
69 ret
= pwrite(fd
, buffer
, sizeof buffer
, QUAD_MAX
);
70 T_ASSERT_TRUE(((ret
== -1) && (errno
== EFBIG
)),
71 "large offset %d", 13);
73 signal(SIGXFSZ
, SIG_DFL
);
74 T_FAIL("%s unexpected SIGXFSZ with offset %lX",
75 "<rdar://problem/28581610>", LONG_MAX
);
78 /* Negative offsets are invalid, no SIGXFSZ signals required */
79 for (x
= 0; offs
[x
] != 0; x
++) {
80 if (!sigsetjmp(xfsz_jmpbuf
, 1)) {
81 signal(SIGXFSZ
, xfsz_signal
);
82 ret
= pwrite(fd
, buffer
, sizeof buffer
, offs
[x
]);
83 T_ASSERT_TRUE(((ret
== -1) && (errno
== EINVAL
)),
84 "negative offset %d", offs
[x
]);
86 signal(SIGXFSZ
, SIG_DFL
);
87 T_FAIL("%s unexpected SIGXFSZ with negative offset %d",
88 "<rdar://problem/28581610>", offs
[x
]);
92 remove(TMP_FILE_PATH
);