Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge panic-abort and panic-log crates into mc-sgx-panic #48

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ jobs:
components: rustfmt
- uses: r7kamura/rust-problem-matchers@v1
- run: cargo fmt --all -- --check
- run: cargo fmt --all -- --check
working-directory: panic/abort
- run: cargo fmt --all -- --check
working-directory: panic/log

markdown-lint:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -60,10 +56,6 @@ jobs:
- uses: actions/checkout@v3
- run: cargo install cargo-sort
- run: cargo sort --workspace --check >/dev/null
- run: cargo sort --workspace --check >/dev/null
working-directory: panic/abort
- run: cargo sort --workspace --check >/dev/null
working-directory: panic/log

clippy:
runs-on: ubuntu-22.04
Expand All @@ -82,10 +74,6 @@ jobs:
components: clippy
- uses: r7kamura/rust-problem-matchers@v1
- run: cargo +${{ matrix.rust }} clippy --all --all-features -- -D warnings
- run: cargo +${{ matrix.rust }} clippy --all --all-features -- -D warnings
working-directory: panic/abort
- run: cargo +${{ matrix.rust }} clippy --all --all-features -- -D warnings
working-directory: panic/log

build:
runs-on: ubuntu-22.04
Expand All @@ -106,10 +94,6 @@ jobs:
toolchain: ${{ matrix.rust }}
- uses: r7kamura/rust-problem-matchers@v1
- run: cargo +${{ matrix.rust }} build --release
- run: cargo +${{ matrix.rust }} build --release
working-directory: panic/abort
- run: cargo +${{ matrix.rust }} build --release
working-directory: panic/log

test:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -147,10 +131,6 @@ jobs:
toolchain: ${{ matrix.rust }}
- uses: r7kamura/rust-problem-matchers@v1
- run: cargo +${{ matrix.rust }} doc --release --no-deps
- run: cargo +${{ matrix.rust }} doc --release --no-deps
working-directory: panic/abort
- run: cargo +${{ matrix.rust }} doc --release --no-deps
working-directory: panic/log

coverage:
runs-on: ubuntu-22.04
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ members = [
"io",
"io/untrusted",
"panic",
"panic/sys",
"sync",
]
exclude = [
"panic/abort",
"panic/log",
"test_enclave",
]

Expand Down
7 changes: 6 additions & 1 deletion panic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ rust-version = "1.62.1"
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/mobilecoinfoundation/sgx-std"
description = "Common panic handling behavior for SGX enclaves"
description = "Panic handler for SGX enclaves"
categories = ["hardware-support", "no-std"]
keywords = ["sgx", "no-std", "panic"]

[features]
log = ["dep:mc-sgx-io", "dep:mc-sgx-sync"]

[dependencies]
mc-sgx-io = { path = "../io", version = "0.1.0", optional = true }
mc-sgx-sync = { path = "../sync", version = "0.1.0", optional = true }
11 changes: 10 additions & 1 deletion panic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
-->[![Docs Status][docs-image]][docs-link]<!--
-->[![Dependency Status][deps-image]][deps-link]

Common panic handling behavior for SGX enclaves
Panic handler for use in SGX enclaves

The panic handler will redirect to the SGX SDK `abort()` method to mark the
enclave as crashed.

## Features

- `log`: Log panic messages during panic handling. The panic messages will be
directed to the host via
[mc-sgx-io::stderr_write_all](https://docs.rs/mc-sgx-io/latest/mc_sgx_io/fn.stderr_write_all.html).

[chat-image]: https://img.shields.io/discord/844353360348971068?style=flat-square
[chat-link]: https://mobilecoin.chat
Expand Down
36 changes: 0 additions & 36 deletions panic/abort/Cargo.toml

This file was deleted.

21 changes: 0 additions & 21 deletions panic/abort/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions panic/abort/src/lib.rs

This file was deleted.

36 changes: 0 additions & 36 deletions panic/log/Cargo.toml

This file was deleted.

21 changes: 0 additions & 21 deletions panic/log/README.md

This file was deleted.

26 changes: 21 additions & 5 deletions panic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
// Copyright (c) 2023 The MobileCoin Foundation
#![feature(thread_local)]
// Copyright (c) 2022-2023 The MobileCoin Foundation

#![doc = include_str!("../README.md")]
#![deny(missing_docs, missing_debug_implementations, unsafe_code)]
#![deny(missing_docs, missing_debug_implementations)]
#![no_std]

mod panicking;
pub mod thread;
#[cfg(not(test))]
use core::panic::PanicInfo;

#[cfg(feature = "log")]
mod log;

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
#[cfg(feature = "log")]
log::log_panic_info(_info);

extern "C" {
fn abort() -> !;
}

unsafe { abort() }
}
14 changes: 3 additions & 11 deletions panic/log/src/lib.rs → panic/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2022 The MobileCoin Foundation
// Copyright (c) 2022-2023 The MobileCoin Foundation

#![doc = include_str!("../README.md")]
#![deny(missing_docs, missing_debug_implementations)]
#![no_std]
//! Logging utilities used during panic handling

use core::fmt::Write;
use core::panic::PanicInfo;
Expand All @@ -14,20 +12,14 @@ use mc_sgx_sync::Mutex;
/// the cause of the panic.
static MESSAGE_BUFFER: Mutex<WriteBuffer> = Mutex::new(WriteBuffer::new());

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
log_panic_info(info);
loop {}
}

/// Log information during a panic
///
/// If for some reason the `info` exceeds the size of the [`MESSAGE_BUFFER`]
/// then this will log a default message.
///
/// # Arguments:
/// * `info` - The panic information to log
fn log_panic_info(info: &PanicInfo) {
pub(crate) fn log_panic_info(info: &PanicInfo) {
if let Ok(mut buffer) = MESSAGE_BUFFER.lock() {
buffer.clear();
let message = match write!(buffer, "{info}") {
Expand Down
14 changes: 14 additions & 0 deletions panic/sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "mc-sgx-panic-sys"
version = "0.1.0"
edition = "2021"
authors = ["MobileCoin"]
rust-version = "1.65"
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/mobilecoinfoundation/sgx-std"
description = "Common panic handling behavior for SGX enclaves"
categories = ["hardware-support", "no-std"]
keywords = ["sgx", "no-std", "panic"]

[dependencies]
21 changes: 21 additions & 0 deletions panic/sys/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MobileCoin: System specific logic for panic handling

[![Project Chat][chat-image]][chat-link]<!--
-->![License][license-image]<!--
-->![Target][target-image]<!--
-->[![Crates.io][crate-image]][crate-link]<!--
-->[![Docs Status][docs-image]][docs-link]<!--
-->[![Dependency Status][deps-image]][deps-link]

System specific logic for panic handling

[chat-image]: https://img.shields.io/discord/844353360348971068?style=flat-square
[chat-link]: https://mobilecoin.chat
[license-image]: https://img.shields.io/crates/l/mc-sgx-panic-sys?style=flat-square
[target-image]: https://img.shields.io/badge/target-x86__64-blue?style=flat-square
[crate-image]: https://img.shields.io/crates/v/mc-sgx-panic-sys.svg?style=flat-square
[crate-link]: https://crates.io/crates/mc-sgx-panic-sys
[docs-image]: https://img.shields.io/docsrs/mc-sgx-panic-sys?style=flat-square
[docs-link]: https://docs.rs/crate/mc-sgx-panic-sys
[deps-image]: https://deps.rs/crate/mc-sgx-panic-sys/0.1.0/status.svg?style=flat-square
[deps-link]: https://deps.rs/crate/mc-sgx-panic-sys/0.1.0
8 changes: 8 additions & 0 deletions panic/sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2022-2023 The MobileCoin Foundation
#![feature(thread_local)]
#![doc = include_str!("../README.md")]
#![deny(missing_docs, missing_debug_implementations, unsafe_code)]
#![no_std]

mod panicking;
pub mod thread;
File renamed without changes.
2 changes: 1 addition & 1 deletion panic/src/thread.rs → panic/sys/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::panicking;
/// # Examples
///
/// ```should_panic
/// use mc_sgx_panic::thread;
/// use mc_sgx_panic_sys::thread;
///
/// struct SomeStruct;
///
Expand Down
2 changes: 1 addition & 1 deletion sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ test = false
doctest = false

[dependencies]
mc-sgx-panic = { path = "../panic", version = "=0.1.0" }
mc-sgx-panic-sys = { path = "../panic/sys", version = "=0.1.0" }
mc-sgx-tstdc = "0.4.1"
2 changes: 1 addition & 1 deletion sync/src/poison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use core::error::Error;
use core::fmt;
use core::sync::atomic::{AtomicBool, Ordering};
use mc_sgx_panic::thread;
use mc_sgx_panic_sys::thread;

pub(crate) struct Flag {
failed: AtomicBool,
Expand Down