From 08518e503499520f6fca5b3827a772d24cc7399c Mon Sep 17 00:00:00 2001 From: WangRunji Date: Wed, 10 Apr 2019 16:26:03 +0800 Subject: [PATCH] sefs: fix SGX memory allocation fail, clear cache and retry --- sefs-fuse/enclave/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sefs-fuse/enclave/src/lib.rs b/sefs-fuse/enclave/src/lib.rs index 976bc66..141414c 100644 --- a/sefs-fuse/enclave/src/lib.rs +++ b/sefs-fuse/enclave/src/lib.rs @@ -45,7 +45,6 @@ use std::io::{Read, Seek, SeekFrom, Write}; use std::path::PathBuf; use std::sgxfs::{OpenOptions, SgxFile}; use std::sync::{SgxMutex as Mutex, SgxRwLock as RwLock}; -use std::vec::Vec; use sgx_types::sgx_key_128bit_t; #[no_mangle] @@ -147,7 +146,16 @@ pub extern "C" fn ecall_file_set_len(fd: usize, len: usize) -> i32 { let mut rest_len = len - current_len; while rest_len != 0 { let l = rest_len.min(0x1000); - try_io!(file.write(&ZEROS[..l])); + let ret = file.write(&ZEROS[..l]); + if let Err(e) = ret { + if e.raw_os_error().unwrap() == 12 { + warn!("Error 12: \"Cannot allocate memory\". Clear cache and try again."); + try_io!(file.clear_cache()); + try_io!(file.write(&ZEROS[..l])); + } else { + try_io!(Err(e)); + } + } rest_len -= l; } // NOTE: Don't try to write a large slice at once.