fix SgxFile seek after the end
This commit is contained in:
parent
4811044c14
commit
58ff7b88b5
@ -4,7 +4,7 @@ use rcore_fs_sefs::dev::*;
|
|||||||
use std::boxed::Box;
|
use std::boxed::Box;
|
||||||
use std::io::{Read, Seek, SeekFrom, Write};
|
use std::io::{Read, Seek, SeekFrom, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sgxfs::{OpenOptions, remove, SgxFile};
|
use std::sgxfs::{remove, OpenOptions, SgxFile};
|
||||||
use std::sync::SgxMutex as Mutex;
|
use std::sync::SgxMutex as Mutex;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
@ -80,6 +80,20 @@ impl File for LockedFile {
|
|||||||
return Ok(0);
|
return Ok(0);
|
||||||
}
|
}
|
||||||
let mut file = self.0.lock().unwrap();
|
let mut file = self.0.lock().unwrap();
|
||||||
|
|
||||||
|
// SgxFile do not support seek a position after the end.
|
||||||
|
// So check the size and padding zeros if necessary.
|
||||||
|
let file_size = file.seek(SeekFrom::End(0)).expect("failed to tell SgxFile") as usize;
|
||||||
|
if file_size < offset {
|
||||||
|
static ZEROS: [u8; 0x1000] = [0; 0x1000];
|
||||||
|
let mut rest_len = offset - file_size;
|
||||||
|
while rest_len != 0 {
|
||||||
|
let l = rest_len.min(0x1000);
|
||||||
|
let len = file.write(&ZEROS[..l]).expect("failed to write SgxFile");
|
||||||
|
rest_len -= len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let offset = offset as u64;
|
let offset = offset as u64;
|
||||||
file.seek(SeekFrom::Start(offset))
|
file.seek(SeekFrom::Start(offset))
|
||||||
.expect("failed to seek SgxFile");
|
.expect("failed to seek SgxFile");
|
||||||
|
@ -38,7 +38,7 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
RUST_SGX_SDK_DIR := $(PROJECT_DIR)/deps/rust-sgx-sdk
|
RUST_SGX_SDK_DIR := $(PROJECT_DIR)/deps/rust-sgx-sdk
|
||||||
SGX_COMMON_CFLAGS += -I$(RUST_SGX_SDK_DIR)/common/ -I$(RUST_SGX_SDK_DIR)/edl/
|
SGX_COMMON_CFLAGS += -I$(RUST_SGX_SDK_DIR)/common/ -I$(RUST_SGX_SDK_DIR)/common/inc/ -I$(RUST_SGX_SDK_DIR)/edl/
|
||||||
|
|
||||||
ifneq ($(SGX_MODE), HW)
|
ifneq ($(SGX_MODE), HW)
|
||||||
Urts_Library_Name := sgx_urts_sim
|
Urts_Library_Name := sgx_urts_sim
|
||||||
|
Loading…
Reference in New Issue
Block a user