support readlink "/proc/self/exe". impl dummy fcntl.getfl
This commit is contained in:
		
							parent
							
								
									a8060f0b24
								
							
						
					
					
						commit
						b2d75f386c
					
				| @ -35,6 +35,7 @@ impl AccessFlags { | ||||
| pub const AT_FDCWD : i32 = -100; | ||||
| 
 | ||||
| pub fn do_faccessat(dirfd: Option<FileDesc>, path: &str, mode: AccessModes, flags: AccessFlags) -> Result<(), Error> { | ||||
|     info!("faccessat: dirfd: {:?}, path: {:?}, mode: {:?}, flags: {:?}", dirfd, path, mode, flags); | ||||
|     match dirfd { | ||||
|         // TODO: handle dirfd
 | ||||
|         Some(dirfd) => errno!(ENOSYS, "cannot accept dirfd"), | ||||
| @ -43,6 +44,7 @@ pub fn do_faccessat(dirfd: Option<FileDesc>, path: &str, mode: AccessModes, flag | ||||
| } | ||||
| 
 | ||||
| pub fn do_access(path: &str, mode: AccessModes) -> Result<(), Error> { | ||||
|     info!("access: path: {:?}, mode: {:?}", path, mode); | ||||
|     let current_ref = process::get_current(); | ||||
|     let mut current = current_ref.lock().unwrap(); | ||||
|     let inode = current.lookup_inode(path)?; | ||||
|  | ||||
| @ -216,6 +216,7 @@ pub fn do_close(fd: FileDesc) -> Result<(), Error> { | ||||
| } | ||||
| 
 | ||||
| pub fn do_pipe2(flags: u32) -> Result<[FileDesc; 2], Error> { | ||||
|     info!("pipe2: flags: {:#x}", flags); | ||||
|     let flags = OpenFlags::from_bits_truncate(flags); | ||||
|     let current_ref = process::get_current(); | ||||
|     let current = current_ref.lock().unwrap(); | ||||
| @ -226,6 +227,7 @@ pub fn do_pipe2(flags: u32) -> Result<[FileDesc; 2], Error> { | ||||
|     let close_on_spawn = flags.contains(OpenFlags::CLOEXEC); | ||||
|     let reader_fd = file_table.put(Arc::new(Box::new(pipe.reader)), close_on_spawn); | ||||
|     let writer_fd = file_table.put(Arc::new(Box::new(pipe.writer)), close_on_spawn); | ||||
|     info!("pipe2: reader_fd: {}, writer_fd: {}", reader_fd, writer_fd); | ||||
|     Ok([reader_fd, writer_fd]) | ||||
| } | ||||
| 
 | ||||
| @ -658,7 +660,7 @@ impl FcntlCmd { | ||||
| } | ||||
| 
 | ||||
| pub fn do_fcntl(fd: FileDesc, cmd: &FcntlCmd) -> Result<isize, Error> { | ||||
|     info!("do_fcntl: {:?}, {:?}", &fd, cmd); | ||||
|     info!("fcntl: fd: {:?}, cmd: {:?}", &fd, cmd); | ||||
|     let current_ref = process::get_current(); | ||||
|     let mut current = current_ref.lock().unwrap(); | ||||
|     let files_ref = current.get_files(); | ||||
| @ -687,15 +689,33 @@ pub fn do_fcntl(fd: FileDesc, cmd: &FcntlCmd) -> Result<isize, Error> { | ||||
|             0 | ||||
|         }, | ||||
|         FcntlCmd::GetFl() => { | ||||
|             unimplemented!(); | ||||
|             let _ = files.get_entry_mut(fd)?; | ||||
|             warn!("fcntl.getfl is unimplemented"); | ||||
|             0 | ||||
|         }, | ||||
|         FcntlCmd::SetFl(flags) => { | ||||
|             unimplemented!(); | ||||
|             let _ = files.get_entry_mut(fd)?; | ||||
|             warn!("fcntl.setfl is unimplemented"); | ||||
|             0 | ||||
|         }, | ||||
|     }) | ||||
| } | ||||
| 
 | ||||
| pub fn do_readlink(path: &str, buf: &mut [u8]) -> Result<usize, Error> { | ||||
|     // TODO: support symbolic links
 | ||||
|     errno!(EINVAL, "not a symbolic link") | ||||
|     info!("readlink: path: {:?}", path); | ||||
|     match path { | ||||
|         "/proc/self/exe" => { | ||||
|             // get cwd
 | ||||
|             let current_ref = process::get_current(); | ||||
|             let current = current_ref.lock().unwrap(); | ||||
|             let cwd = current.get_cwd(); | ||||
|             let len = cwd.len().min(buf.len()); | ||||
|             buf[0..len].copy_from_slice(&cwd.as_bytes()[0..len]); | ||||
|             Ok(0) | ||||
|         } | ||||
|         _ => { | ||||
|             // TODO: support symbolic links
 | ||||
|             errno!(EINVAL, "not a symbolic link") | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -38,7 +38,7 @@ else | ||||
| endif | ||||
| 
 | ||||
| RUST_SGX_SDK_DIR := $(PROJECT_DIR)/deps/rust-sgx-sdk | ||||
| SGX_COMMON_CFLAGS += -I$(RUST_SGX_SDK_DIR)/common/inc/ -I$(RUST_SGX_SDK_DIR)/edl/ | ||||
| SGX_COMMON_CFLAGS += -I$(RUST_SGX_SDK_DIR)/common/ -I$(RUST_SGX_SDK_DIR)/edl/ | ||||
| 
 | ||||
| ifneq ($(SGX_MODE), HW) | ||||
| 	Urts_Library_Name := sgx_urts_sim | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user