sefs: fix SGX memory allocation fail, clear cache and retry

master
WangRunji 6 years ago
parent d7a2006cc3
commit 08518e5034

@ -45,7 +45,6 @@ use std::io::{Read, Seek, SeekFrom, Write};
use std::path::PathBuf; use std::path::PathBuf;
use std::sgxfs::{OpenOptions, SgxFile}; use std::sgxfs::{OpenOptions, SgxFile};
use std::sync::{SgxMutex as Mutex, SgxRwLock as RwLock}; use std::sync::{SgxMutex as Mutex, SgxRwLock as RwLock};
use std::vec::Vec;
use sgx_types::sgx_key_128bit_t; use sgx_types::sgx_key_128bit_t;
#[no_mangle] #[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; let mut rest_len = len - current_len;
while rest_len != 0 { while rest_len != 0 {
let l = rest_len.min(0x1000); let l = rest_len.min(0x1000);
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])); try_io!(file.write(&ZEROS[..l]));
} else {
try_io!(Err(e));
}
}
rest_len -= l; rest_len -= l;
} }
// NOTE: Don't try to write a large slice at once. // NOTE: Don't try to write a large slice at once.

Loading…
Cancel
Save