@@ -395,6 +395,7 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
struct encl_segment *heap;
unsigned long total_mem;
int ret, errno_save;
+ unsigned long count;
unsigned long addr;
unsigned long i;
@@ -458,16 +459,30 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
modt_ioc.offset = heap->offset;
modt_ioc.length = heap->size;
modt_ioc.page_type = SGX_PAGE_TYPE_TRIM;
-
+ count = 0;
TH_LOG("Changing type of %zd bytes to trimmed may take a while ...",
heap->size);
- ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
- errno_save = ret == -1 ? errno : 0;
+ do {
+ ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
+
+ errno_save = ret == -1 ? errno : 0;
+ if (errno_save != EAGAIN)
+ break;
+
+ EXPECT_EQ(modt_ioc.result, 0);
+
+ count += modt_ioc.count;
+ modt_ioc.offset += modt_ioc.count;
+ modt_ioc.length -= modt_ioc.count;
+ modt_ioc.result = 0;
+ modt_ioc.count = 0;
+ } while (modt_ioc.length != 0);
EXPECT_EQ(ret, 0);
EXPECT_EQ(errno_save, 0);
EXPECT_EQ(modt_ioc.result, 0);
- EXPECT_EQ(modt_ioc.count, heap->size);
+ count += modt_ioc.count;
+ EXPECT_EQ(count, heap->size);
/* EACCEPT all removed pages. */
addr = self->encl.encl_base + heap->offset;
@@ -495,15 +510,26 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
remove_ioc.offset = heap->offset;
remove_ioc.length = heap->size;
-
+ count = 0;
TH_LOG("Removing %zd bytes from enclave may take a while ...",
heap->size);
- ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc);
- errno_save = ret == -1 ? errno : 0;
+ do {
+ ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc);
+
+ errno_save = ret == -1 ? errno : 0;
+ if (errno_save != EAGAIN)
+ break;
+
+ count += remove_ioc.count;
+ remove_ioc.offset += remove_ioc.count;
+ remove_ioc.length -= remove_ioc.count;
+ remove_ioc.count = 0;
+ } while (remove_ioc.length != 0);
EXPECT_EQ(ret, 0);
EXPECT_EQ(errno_save, 0);
- EXPECT_EQ(remove_ioc.count, heap->size);
+ count += remove_ioc.count;
+ EXPECT_EQ(count, heap->size);
}
TEST_F(enclave, clobbered_vdso)