Skip to content
Snippets Groups Projects
Commit cf6725b6 authored by pln's avatar pln
Browse files

!Send !Sync don't work

parent f46b0a39
Branches
No related tags found
No related merge requests found
//#![feature(const_size_of)]
#![feature(optin_builtin_traits)]
#![feature(const_fn)]
//use std::mem::{transmute, size_of};
//use std::marker::Sized;
......@@ -38,13 +39,15 @@ mod trusted {
}
impl<T> Sec<T> {
pub unsafe fn new(d: T) -> Self {
pub const unsafe fn new(d: T) -> Self {
Sec { data: d }
}
pub unsafe fn get(&self) -> &T {
&self.data
}
}
impl<T> !Send for Sec<T> {}
impl<T> !Sync for Sec<T> {}
// safe API for operating on Sec<u32>
pub fn sec_add_u32(s1: &Sec<u32>, s2: &Sec<u32>) -> Sec<u32> {
......@@ -57,9 +60,9 @@ mod trusted {
T: Sized,
F: FnMut(&mut u8),
{
let ptr: *mut u8 = s as *mut T as *mut u8;
let ptr = s as *mut T as *mut u8;
for i in 0..size_of::<T>() {
println!("{} {}", i, unsafe { *ptr.offset(i as isize) } as u8);
//println!("{} {}", i, unsafe { *ptr.offset(i as isize) } as u8);
f(unsafe { &mut *ptr.offset(i as isize) });
}
}
......@@ -80,6 +83,10 @@ mod trusted {
Enc { data: c }
}
pub const unsafe fn new_(d: T) -> Self {
Enc { data: d }
}
pub unsafe fn get_unsafe(&self) -> Sec<T> {
let mut c = self.data.clone();
cipher(&mut c, |i| { *i -= 1; });
......@@ -102,6 +109,9 @@ fn main() {
user1(&d, &e);
}
static mut S: Sec<u32> = unsafe { Sec::new(0u32) };
static mut E: Enc<u32> = unsafe { Enc::new_(0u32) };
// user code in `safe` Rust
fn user1(d: &Sec<u32>, e: &Enc<u32>) {
println!("user1 {:?}, {:?}", d, e);
......@@ -109,6 +119,9 @@ fn user1(d: &Sec<u32>, e: &Enc<u32>) {
user2(&sec_add_u32(d, &e.get(a)));
user3(d, &e.get(a));
user4(d, e, a);
user5(d, e);
//unsafe { S = *d }
unsafe { S = e.get(a) }
}
fn user2(d: &Sec<u32>) {
......@@ -120,7 +133,13 @@ fn user3(d1: &Sec<u32>, d2: &Sec<u32>) {
}
fn user4(d: &Sec<u32>, e: &Enc<u32>, a: &Auth) {
println!("user3 {:?}", sec_add_u32(d, &e.get(a)));
println!("user4 {:?}", sec_add_u32(d, &e.get(a)));
}
fn user5(d: &Sec<u32>, e: &Enc<u32>) {
println!("user5 {:?}, {:?}", d, e);
//unsafe { S = *d }
}
/*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment