Skip to content

Commit 8c87b85

Browse files
author
Vasili Novikov
committed
Code review (async-usercalls)
Address code review comments
1 parent 8887fab commit 8c87b85

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ matrix:
2626
- clang-11
2727
- musl-tools
2828
rust:
29+
- nightly
2930
- nightly-2023-05-07
3031
env:
3132
- RUST_BACKTRACE=1

Diff for: intel-sgx/async-usercalls/src/callback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ macro_rules! define_callback {
6262
};
6363
}
6464

65-
invoke_with_usercalls!(define_callback);
65+
invoke_with_usercalls!(define_callback);

Diff for: intel-sgx/async-usercalls/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,4 +436,4 @@ mod tests {
436436
}
437437
}
438438
}
439-
}
439+
}

Diff for: intel-sgx/enclave-runner/src/usercalls/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use futures::future::Future;
1919

2020
type Register = u64;
2121

22-
pub(super) trait RegisterArgument {
22+
trait RegisterArgument {
2323
fn from_register(_: Register) -> Self;
2424
fn into_register(self) -> Register;
2525
}

Diff for: intel-sgx/enclave-runner/src/usercalls/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ use sgxs::loader::Tcs as SgxsTcs;
3838
use crate::loader::{EnclavePanic, ErasedTcs};
3939
use crate::tcs::{self, CoResult, ThreadResult};
4040
use self::abi::dispatch;
41+
use self::abi::ReturnValue;
4142
use self::abi::UsercallList;
43+
use self::interface::ToSgxResult;
4244
use self::interface::{Handler, OutputBuffer};
4345

4446
pub(crate) mod abi;
@@ -793,9 +795,6 @@ impl EnclaveState {
793795
let mut input = IOHandlerInput { enclave: enclave.clone(), tcs, work_sender: &work_sender };
794796
let handler = Handler(&mut input);
795797
let result = {
796-
use self::interface::ToSgxResult;
797-
use self::abi::ReturnValue;
798-
799798
let (p1, p2, p3, p4, p5) = parameters;
800799
match notifier_rx {
801800
None => dispatch(handler, p1, p2, p3, p4, p5).await.1,

Diff for: ipc-queue/src/position.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,26 @@ impl<T> PositionMonitor<T> {
2727
pub fn read_position(&self) -> ReadPosition {
2828
let current = self.fifo.current_offsets(Ordering::Relaxed);
2929
let read_epoch = self.read_epoch.load(Ordering::Relaxed);
30-
let read_epoch_shifted = read_epoch
30+
let read_epoch_shifted = (read_epoch as u64)
3131
.checked_shl(32)
32-
.expect("Reading from position of over 2^32 (2 to the power of 32). This is unsupported.");
32+
.expect("Read epoch is >= 2^32 (2 to the power of 32). This is unsupported.");
3333
ReadPosition(read_epoch_shifted | (current.read_offset() as u64))
3434
}
3535

3636
pub fn write_position(&self) -> WritePosition {
3737
let current = self.fifo.current_offsets(Ordering::Relaxed);
3838
let mut write_epoch = self.read_epoch.load(Ordering::Relaxed);
39+
// Write epoch keeps track of how many times the write offset wrapped around
40+
// the ring buffer. Write epochs are not tracked separately, only read epoch are.
41+
// We know, however, that objects are always written to the buffer first.
42+
// So, the high bit used in the write and read offsets tell us whether writes
43+
// already wrapped around the ring buffer, while reads have not yet.
3944
if current.read_high_bit() != current.write_high_bit() {
4045
write_epoch += 1;
4146
}
4247
let write_epoch_shifted = write_epoch
4348
.checked_shl(32)
44-
.expect("Writing to position of over 2^32 (2 to the power of 32). This is unsupported.");
49+
.expect("Write epoch is >= 2^32 (2 to the power of 32). This is unsupported.");
4550
WritePosition(write_epoch_shifted | (current.write_offset() as u64))
4651
}
4752
}
@@ -57,8 +62,7 @@ impl<T> Clone for PositionMonitor<T> {
5762

5863
impl ReadPosition {
5964
/// A `WritePosition` can be compared to a `ReadPosition` **correctly** if
60-
/// at most 2³¹ (2 to the power of 31) writes
61-
/// have occurred since the write position was recorded.
65+
/// the ring buffer wrapped around at most 2³¹ (2 to the power of 31) times.
6266
pub fn is_past(&self, write: &WritePosition) -> bool {
6367
let (read, write) = (self.0, write.0);
6468
let hr = read & (1 << 63);
@@ -68,4 +72,4 @@ impl ReadPosition {
6872
}
6973
true
7074
}
71-
}
75+
}

0 commit comments

Comments
 (0)