Lines Matching refs:fd
39 int r, fd; in mfd_assert_new() local
41 fd = sys_memfd_create(name, flags); in mfd_assert_new()
42 if (fd < 0) { in mfd_assert_new()
48 r = ftruncate(fd, sz); in mfd_assert_new()
54 return fd; in mfd_assert_new()
70 static unsigned int mfd_assert_get_seals(int fd) in mfd_assert_get_seals() argument
74 r = fcntl(fd, F_GET_SEALS); in mfd_assert_get_seals()
76 printf("GET_SEALS(%d) failed: %m\n", fd); in mfd_assert_get_seals()
83 static void mfd_assert_has_seals(int fd, unsigned int seals) in mfd_assert_has_seals() argument
87 s = mfd_assert_get_seals(fd); in mfd_assert_has_seals()
89 printf("%u != %u = GET_SEALS(%d)\n", seals, s, fd); in mfd_assert_has_seals()
94 static void mfd_assert_add_seals(int fd, unsigned int seals) in mfd_assert_add_seals() argument
99 s = mfd_assert_get_seals(fd); in mfd_assert_add_seals()
100 r = fcntl(fd, F_ADD_SEALS, seals); in mfd_assert_add_seals()
102 printf("ADD_SEALS(%d, %u -> %u) failed: %m\n", fd, s, seals); in mfd_assert_add_seals()
107 static void mfd_fail_add_seals(int fd, unsigned int seals) in mfd_fail_add_seals() argument
112 r = fcntl(fd, F_GET_SEALS); in mfd_fail_add_seals()
118 r = fcntl(fd, F_ADD_SEALS, seals); in mfd_fail_add_seals()
121 fd, s, seals); in mfd_fail_add_seals()
126 static void mfd_assert_size(int fd, size_t size) in mfd_assert_size() argument
131 r = fstat(fd, &st); in mfd_assert_size()
133 printf("fstat(%d) failed: %m\n", fd); in mfd_assert_size()
142 static int mfd_assert_dup(int fd) in mfd_assert_dup() argument
146 r = dup(fd); in mfd_assert_dup()
148 printf("dup(%d) failed: %m\n", fd); in mfd_assert_dup()
155 static void *mfd_assert_mmap_shared(int fd) in mfd_assert_mmap_shared() argument
163 fd, in mfd_assert_mmap_shared()
173 static void *mfd_assert_mmap_private(int fd) in mfd_assert_mmap_private() argument
181 fd, in mfd_assert_mmap_private()
191 static int mfd_assert_open(int fd, int flags, mode_t mode) in mfd_assert_open() argument
196 sprintf(buf, "/proc/self/fd/%d", fd); in mfd_assert_open()
206 static void mfd_fail_open(int fd, int flags, mode_t mode) in mfd_fail_open() argument
211 sprintf(buf, "/proc/self/fd/%d", fd); in mfd_fail_open()
219 static void mfd_assert_read(int fd) in mfd_assert_read() argument
225 l = read(fd, buf, sizeof(buf)); in mfd_assert_read()
236 fd, in mfd_assert_read()
249 fd, in mfd_assert_read()
258 static void mfd_assert_write(int fd) in mfd_assert_write() argument
270 l = write(fd, "\0\0\0\0", 4); in mfd_assert_write()
282 fd, in mfd_assert_write()
296 fd, in mfd_assert_write()
311 fd, in mfd_assert_write()
328 r = fallocate(fd, in mfd_assert_write()
338 static void mfd_fail_write(int fd) in mfd_fail_write() argument
345 l = write(fd, "data", 4); in mfd_fail_write()
356 fd, in mfd_fail_write()
368 fd, in mfd_fail_write()
381 fd, in mfd_fail_write()
392 r = fallocate(fd, in mfd_fail_write()
402 static void mfd_assert_shrink(int fd) in mfd_assert_shrink() argument
406 r = ftruncate(fd, mfd_def_size / 2); in mfd_assert_shrink()
412 mfd_assert_size(fd, mfd_def_size / 2); in mfd_assert_shrink()
414 fd2 = mfd_assert_open(fd, in mfd_assert_shrink()
419 mfd_assert_size(fd, 0); in mfd_assert_shrink()
422 static void mfd_fail_shrink(int fd) in mfd_fail_shrink() argument
426 r = ftruncate(fd, mfd_def_size / 2); in mfd_fail_shrink()
432 mfd_fail_open(fd, in mfd_fail_shrink()
437 static void mfd_assert_grow(int fd) in mfd_assert_grow() argument
441 r = ftruncate(fd, mfd_def_size * 2); in mfd_assert_grow()
447 mfd_assert_size(fd, mfd_def_size * 2); in mfd_assert_grow()
449 r = fallocate(fd, in mfd_assert_grow()
458 mfd_assert_size(fd, mfd_def_size * 4); in mfd_assert_grow()
461 static void mfd_fail_grow(int fd) in mfd_fail_grow() argument
465 r = ftruncate(fd, mfd_def_size * 2); in mfd_fail_grow()
471 r = fallocate(fd, in mfd_fail_grow()
481 static void mfd_assert_grow_write(int fd) in mfd_assert_grow_write() argument
496 l = pwrite(fd, buf, mfd_def_size * 8, 0); in mfd_assert_grow_write()
502 mfd_assert_size(fd, mfd_def_size * 8); in mfd_assert_grow_write()
505 static void mfd_fail_grow_write(int fd) in mfd_fail_grow_write() argument
520 l = pwrite(fd, buf, mfd_def_size * 8, 0); in mfd_fail_grow_write()
577 int fd; in test_create() local
594 fd = mfd_assert_new("", 0, 0); in test_create()
595 close(fd); in test_create()
605 fd = mfd_assert_new("", 0, MFD_CLOEXEC); in test_create()
606 close(fd); in test_create()
609 fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING); in test_create()
610 close(fd); in test_create()
613 fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING | MFD_CLOEXEC); in test_create()
614 close(fd); in test_create()
623 int fd; in test_basic() local
627 fd = mfd_assert_new("kern_memfd_basic", in test_basic()
632 mfd_assert_has_seals(fd, 0); in test_basic()
633 mfd_assert_add_seals(fd, F_SEAL_SHRINK | in test_basic()
635 mfd_assert_has_seals(fd, F_SEAL_SHRINK | in test_basic()
639 mfd_assert_add_seals(fd, F_SEAL_SHRINK | in test_basic()
641 mfd_assert_has_seals(fd, F_SEAL_SHRINK | in test_basic()
645 mfd_assert_add_seals(fd, F_SEAL_GROW | F_SEAL_SEAL); in test_basic()
646 mfd_assert_has_seals(fd, F_SEAL_SHRINK | in test_basic()
652 mfd_fail_add_seals(fd, F_SEAL_GROW); in test_basic()
653 mfd_fail_add_seals(fd, 0); in test_basic()
655 close(fd); in test_basic()
658 fd = mfd_assert_new("kern_memfd_basic", in test_basic()
661 mfd_assert_has_seals(fd, F_SEAL_SEAL); in test_basic()
662 mfd_fail_add_seals(fd, F_SEAL_SHRINK | in test_basic()
665 mfd_assert_has_seals(fd, F_SEAL_SEAL); in test_basic()
666 close(fd); in test_basic()
675 int fd; in test_seal_write() local
679 fd = mfd_assert_new("kern_memfd_seal_write", in test_seal_write()
682 mfd_assert_has_seals(fd, 0); in test_seal_write()
683 mfd_assert_add_seals(fd, F_SEAL_WRITE); in test_seal_write()
684 mfd_assert_has_seals(fd, F_SEAL_WRITE); in test_seal_write()
686 mfd_assert_read(fd); in test_seal_write()
687 mfd_fail_write(fd); in test_seal_write()
688 mfd_assert_shrink(fd); in test_seal_write()
689 mfd_assert_grow(fd); in test_seal_write()
690 mfd_fail_grow_write(fd); in test_seal_write()
692 close(fd); in test_seal_write()
701 int fd; in test_seal_shrink() local
705 fd = mfd_assert_new("kern_memfd_seal_shrink", in test_seal_shrink()
708 mfd_assert_has_seals(fd, 0); in test_seal_shrink()
709 mfd_assert_add_seals(fd, F_SEAL_SHRINK); in test_seal_shrink()
710 mfd_assert_has_seals(fd, F_SEAL_SHRINK); in test_seal_shrink()
712 mfd_assert_read(fd); in test_seal_shrink()
713 mfd_assert_write(fd); in test_seal_shrink()
714 mfd_fail_shrink(fd); in test_seal_shrink()
715 mfd_assert_grow(fd); in test_seal_shrink()
716 mfd_assert_grow_write(fd); in test_seal_shrink()
718 close(fd); in test_seal_shrink()
727 int fd; in test_seal_grow() local
731 fd = mfd_assert_new("kern_memfd_seal_grow", in test_seal_grow()
734 mfd_assert_has_seals(fd, 0); in test_seal_grow()
735 mfd_assert_add_seals(fd, F_SEAL_GROW); in test_seal_grow()
736 mfd_assert_has_seals(fd, F_SEAL_GROW); in test_seal_grow()
738 mfd_assert_read(fd); in test_seal_grow()
739 mfd_assert_write(fd); in test_seal_grow()
740 mfd_assert_shrink(fd); in test_seal_grow()
741 mfd_fail_grow(fd); in test_seal_grow()
742 mfd_fail_grow_write(fd); in test_seal_grow()
744 close(fd); in test_seal_grow()
753 int fd; in test_seal_resize() local
757 fd = mfd_assert_new("kern_memfd_seal_resize", in test_seal_resize()
760 mfd_assert_has_seals(fd, 0); in test_seal_resize()
761 mfd_assert_add_seals(fd, F_SEAL_SHRINK | F_SEAL_GROW); in test_seal_resize()
762 mfd_assert_has_seals(fd, F_SEAL_SHRINK | F_SEAL_GROW); in test_seal_resize()
764 mfd_assert_read(fd); in test_seal_resize()
765 mfd_assert_write(fd); in test_seal_resize()
766 mfd_fail_shrink(fd); in test_seal_resize()
767 mfd_fail_grow(fd); in test_seal_resize()
768 mfd_fail_grow_write(fd); in test_seal_resize()
770 close(fd); in test_seal_resize()
779 int fd, fd2; in test_share_dup() local
783 fd = mfd_assert_new("kern_memfd_share_dup", in test_share_dup()
786 mfd_assert_has_seals(fd, 0); in test_share_dup()
788 fd2 = mfd_assert_dup(fd); in test_share_dup()
791 mfd_assert_add_seals(fd, F_SEAL_WRITE); in test_share_dup()
792 mfd_assert_has_seals(fd, F_SEAL_WRITE); in test_share_dup()
796 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK); in test_share_dup()
799 mfd_assert_add_seals(fd, F_SEAL_SEAL); in test_share_dup()
800 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_SEAL); in test_share_dup()
803 mfd_fail_add_seals(fd, F_SEAL_GROW); in test_share_dup()
805 mfd_fail_add_seals(fd, F_SEAL_SEAL); in test_share_dup()
810 mfd_fail_add_seals(fd, F_SEAL_GROW); in test_share_dup()
811 close(fd); in test_share_dup()
820 int fd; in test_share_mmap() local
825 fd = mfd_assert_new("kern_memfd_share_mmap", in test_share_mmap()
828 mfd_assert_has_seals(fd, 0); in test_share_mmap()
831 p = mfd_assert_mmap_shared(fd); in test_share_mmap()
832 mfd_fail_add_seals(fd, F_SEAL_WRITE); in test_share_mmap()
833 mfd_assert_has_seals(fd, 0); in test_share_mmap()
834 mfd_assert_add_seals(fd, F_SEAL_SHRINK); in test_share_mmap()
835 mfd_assert_has_seals(fd, F_SEAL_SHRINK); in test_share_mmap()
839 p = mfd_assert_mmap_private(fd); in test_share_mmap()
840 mfd_assert_add_seals(fd, F_SEAL_WRITE); in test_share_mmap()
841 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK); in test_share_mmap()
844 close(fd); in test_share_mmap()
855 int fd, fd2; in test_share_open() local
859 fd = mfd_assert_new("kern_memfd_share_open", in test_share_open()
862 mfd_assert_has_seals(fd, 0); in test_share_open()
864 fd2 = mfd_assert_open(fd, O_RDWR, 0); in test_share_open()
865 mfd_assert_add_seals(fd, F_SEAL_WRITE); in test_share_open()
866 mfd_assert_has_seals(fd, F_SEAL_WRITE); in test_share_open()
870 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK); in test_share_open()
873 close(fd); in test_share_open()
874 fd = mfd_assert_open(fd2, O_RDONLY, 0); in test_share_open()
876 mfd_fail_add_seals(fd, F_SEAL_SEAL); in test_share_open()
877 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK); in test_share_open()
881 fd2 = mfd_assert_open(fd, O_RDWR, 0); in test_share_open()
884 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_SEAL); in test_share_open()
888 close(fd); in test_share_open()
897 int fd; in test_share_fork() local
902 fd = mfd_assert_new("kern_memfd_share_fork", in test_share_fork()
905 mfd_assert_has_seals(fd, 0); in test_share_fork()
908 mfd_assert_add_seals(fd, F_SEAL_SEAL); in test_share_fork()
909 mfd_assert_has_seals(fd, F_SEAL_SEAL); in test_share_fork()
911 mfd_fail_add_seals(fd, F_SEAL_WRITE); in test_share_fork()
912 mfd_assert_has_seals(fd, F_SEAL_SEAL); in test_share_fork()
916 mfd_fail_add_seals(fd, F_SEAL_WRITE); in test_share_fork()
917 mfd_assert_has_seals(fd, F_SEAL_SEAL); in test_share_fork()
919 close(fd); in test_share_fork()