You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@teaclave.apache.org by Zhaofeng Chen <no...@github.com> on 2020/07/17 21:10:57 UTC

[apache/incubator-teaclave-sgx-sdk] Change sgx_libc Interface for Rust Crates. (#258)

This PR makes changes to the `sgx_libc` and its corresponding call sites inside `sgx_tsts`to provide better interfaces for Rust SGX cates. Any crate using `sgx_libc` APIs expects a return value with type OCallResult&lt;T, OCallError&gt;, which wraps a sanitized Ok value with type T or an error with type OCallError. The OCallError is also convertible to `std::io::Error`, making it easier for error handling.    
You can view, comment on, or merge this pull request online at:

  https://github.com/apache/incubator-teaclave-sgx-sdk/pull/258

-- Commit Summary --

  * Change sgx_libc interface.

-- File Changes --

    M edl/sgx_env.edl (12)
    M edl/sgx_fd.edl (4)
    M edl/sgx_file.edl (4)
    M edl/sgx_net.edl (8)
    M edl/sgx_socket.edl (2)
    M samplecode/hello-rust/enclave/Enclave.edl (3)
    M samplecode/hello-rust/enclave/src/lib.rs (2)
    M samplecode/http_req/Makefile (4)
    M samplecode/unit-test/enclave/Cargo.toml (2)
    M samplecode/unit-test/enclave/Enclave.edl (2)
    M samplecode/unit-test/enclave/src/lib.rs (7)
    M samplecode/unit-test/enclave/src/test_env.rs (5)
    A samplecode/unit-test/enclave/src/test_net.rs (8)
    M samplecode/unit-test/enclave/src/test_path.rs (70)
    M samplecode/unit-test/enclave/src/test_signal.rs (2)
    M sgx_backtrace_sys/build.rs (5)
    M sgx_backtrace_sys/libbacktrace/mmap.c (6)
    M sgx_backtrace_sys/libbacktrace/mmapio.c (7)
    M sgx_edl/edl/sgx_env.edl (12)
    M sgx_edl/edl/sgx_fd.edl (4)
    M sgx_edl/edl/sgx_file.edl (4)
    M sgx_edl/edl/sgx_net.edl (8)
    M sgx_edl/edl/sgx_socket.edl (2)
    M sgx_edl/edl/sgx_sys.edl (1)
    M sgx_libc/src/linux/x86_64/mod.rs (418)
    M sgx_libc/src/linux/x86_64/ocall.rs (4222)
    M sgx_libc/src/macros.rs (45)
    M sgx_tstd/src/io/error.rs (50)
    M sgx_tstd/src/sys/ext/net.rs (87)
    M sgx_tstd/src/sys/fd.rs (89)
    M sgx_tstd/src/sys/fs.rs (217)
    M sgx_tstd/src/sys/mod.rs (69)
    M sgx_tstd/src/sys/net.rs (118)
    M sgx_tstd/src/sys/os.rs (184)
    M sgx_tstd/src/sys/pipe.rs (13)
    M sgx_tstd/src/sys/time.rs (76)
    M sgx_tstd/src/sys_common/net.rs (185)
    M sgx_urts/src/env.rs (85)
    M sgx_urts/src/fd.rs (124)
    M sgx_urts/src/file.rs (208)
    M sgx_urts/src/net.rs (62)

-- Patch Links --

https://github.com/apache/incubator-teaclave-sgx-sdk/pull/258.patch
https://github.com/apache/incubator-teaclave-sgx-sdk/pull/258.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/pull/258

Re: [apache/incubator-teaclave-sgx-sdk] Change sgx_libc Interface for Rust Crates. (#258)

Posted by Zhaofeng Chen <no...@github.com>.
> In the next few days, I will focus on reviewing the code of sgx_libc::ocall.
> 
> I have two questions:
> 
> 1. When ocall fails, should errno be set with set_errno?
> 2. Should the return value type of the following functions also be of type OCallResult<T, OCallError>?
>    mmap
>    munmap
>    msync
>    mprotect
>    sched_setaffinity
>    sched_getaffinity
>    pipe
>    sched_yield
>    nanosleep
>    sigaction
>    sigprocmask
>    raise
>    pthread_sigmask

1. When ocall fails, should errno be set with set_errno?
Currently not set. We can set_errno in the `eos!` macro. However, the caller is encouraged to use OCallResult/OCallError to handle all kinds of error (including the OS error),  instead of using the conventional `get_errno` function.

2. Should the return value type of the following functions also be of type OCallResult<T, OCallError>?
Yes. Ideally, we should make every API in the `sgx_libc` follow the same convention. This PR is still on-going work.  Besides return value, we should also unify the parameter conventions based on the semantics of those APIs, such as your comments in `gai_strerror`/`pipe`/`pipe2`.  I believe you will find more when digging in `ocall.rs` .
The ultimate goal is to provide a better interface with deterministic semantic and sanitized results for Rust callers in the Rust SGX ecosystem.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/pull/258#issuecomment-660686480

Re: [apache/incubator-teaclave-sgx-sdk] Change sgx_libc Interface for Rust Crates. (#258)

Posted by Zhaofeng Chen <no...@github.com.INVALID>.
Closed #258.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/pull/258#event-4597410629

Re: [apache/incubator-teaclave-sgx-sdk] Change sgx_libc Interface for Rust Crates. (#258)

Posted by Zhaofeng Chen <no...@github.com.INVALID>.
I have pushed the changes to the [sec-liboc](https://github.com/apache/incubator-teaclave-sgx-sdk/tree/sec-liboc) branch for future updates.  Close this PR for now. We can discuss/modify these breaking changes in future PRs to that branch.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/pull/258#issuecomment-820163821

Re: [apache/incubator-teaclave-sgx-sdk] Change sgx_libc Interface for Rust Crates. (#258)

Posted by Yu Ding <no...@github.com>.
and we need review from @volcano0dr 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/pull/258#issuecomment-660340169

Re: [apache/incubator-teaclave-sgx-sdk] Change sgx_libc Interface for Rust Crates. (#258)

Posted by Zhaofeng Chen <no...@github.com>.
@volcano0dr  I have updated the interfaces. You can review the latest code now. 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/pull/258#issuecomment-671111219