]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/sgx/os.rs
SGX target: implement synchronization primitives and threading
[rust.git] / src / libstd / sys / sgx / os.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use fortanix_sgx_abi::{Error, RESULT_SUCCESS};
12
13 use error::Error as StdError;
14 use ffi::{OsString, OsStr};
15 use fmt;
16 use io;
17 use path::{self, PathBuf};
18 use str;
19 use sys::{unsupported, Void, sgx_ineffective, decode_error_kind};
20
21 pub fn errno() -> i32 {
22     RESULT_SUCCESS
23 }
24
25 pub fn error_string(errno: i32) -> String {
26     if errno == RESULT_SUCCESS {
27         "operation succesful".into()
28     } else if ((Error::UserRangeStart as _)..=(Error::UserRangeEnd as _)).contains(&errno) {
29         format!("user-specified error {:08x}", errno)
30     } else {
31         decode_error_kind(errno).as_str().into()
32     }
33 }
34
35 pub fn getcwd() -> io::Result<PathBuf> {
36     unsupported()
37 }
38
39 pub fn chdir(_: &path::Path) -> io::Result<()> {
40     sgx_ineffective(())
41 }
42
43 pub struct SplitPaths<'a>(&'a Void);
44
45 pub fn split_paths(_unparsed: &OsStr) -> SplitPaths {
46     panic!("unsupported")
47 }
48
49 impl<'a> Iterator for SplitPaths<'a> {
50     type Item = PathBuf;
51     fn next(&mut self) -> Option<PathBuf> {
52         match *self.0 {}
53     }
54 }
55
56 #[derive(Debug)]
57 pub struct JoinPathsError;
58
59 pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
60     where I: Iterator<Item=T>, T: AsRef<OsStr>
61 {
62     Err(JoinPathsError)
63 }
64
65 impl fmt::Display for JoinPathsError {
66     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
67         "not supported in SGX yet".fmt(f)
68     }
69 }
70
71 impl StdError for JoinPathsError {
72     fn description(&self) -> &str {
73         "not supported in SGX yet"
74     }
75 }
76
77 pub fn current_exe() -> io::Result<PathBuf> {
78     unsupported()
79 }
80
81 pub struct Env;
82
83 impl Iterator for Env {
84     type Item = (OsString, OsString);
85     fn next(&mut self) -> Option<(OsString, OsString)> {
86         None
87     }
88 }
89
90 pub fn env() -> Env {
91     Env
92 }
93
94 pub fn getenv(_k: &OsStr) -> io::Result<Option<OsString>> {
95     Ok(None)
96 }
97
98 pub fn setenv(_k: &OsStr, _v: &OsStr) -> io::Result<()> {
99     sgx_ineffective(()) // FIXME: this could trigger a panic higher up the stack
100 }
101
102 pub fn unsetenv(_k: &OsStr) -> io::Result<()> {
103     sgx_ineffective(()) // FIXME: this could trigger a panic higher up the stack
104 }
105
106 pub fn temp_dir() -> PathBuf {
107     panic!("no filesystem in SGX")
108 }
109
110 pub fn home_dir() -> Option<PathBuf> {
111     None
112 }
113
114 pub fn exit(code: i32) -> ! {
115     super::abi::exit_with_code(code as _)
116 }
117
118 pub fn getpid() -> u32 {
119     panic!("no pids in SGX")
120 }