diff options
Diffstat (limited to 'advanced/unsafe-rust')
23 files changed, 79 insertions, 0 deletions
diff --git a/advanced/unsafe-rust/Cargo.toml b/advanced/unsafe-rust/Cargo.toml new file mode 100644 index 0000000..b37474a --- /dev/null +++ b/advanced/unsafe-rust/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "unsafe-rust" +version = "0.1.0" +authors = ["Adam Carpenter <53hornet@gmail.com>"] +edition = "2018" + +[dependencies] diff --git a/advanced/unsafe-rust/src/main.rs b/advanced/unsafe-rust/src/main.rs new file mode 100644 index 0000000..c9967a8 --- /dev/null +++ b/advanced/unsafe-rust/src/main.rs @@ -0,0 +1,62 @@ +fn main() { + let mut num = 5; + + let r1 = &num as *const i32; + let r2 = &mut num as *mut i32; + + let address = 0x012345usize; + let r = address as *const i32; + + unsafe { + println!("{}", *r1); + println!("{}", *r2); + } + + unsafe { + dangerous(); + } + + + unsafe { + println!("c call: {}", abs(-3)); + } + + + unsafe { + HELLO_WORLD = "test"; + println!("{}", HELLO_WORLD); + } + println!("{}", HI_THERE); + + add_to_count(3); + + unsafe { + println!("counter: {}", COUNTER); + } +} + +unsafe fn dangerous() {} + +extern "C" { + fn abs(input: i32) -> i32; +} + +static mut HELLO_WORLD: &str = "hello world"; +static mut COUNTER: u32 = 0; + +fn add_to_count(inc: u32) { + unsafe { + COUNTER += inc; + } +} + +const HI_THERE: &str = "hi there"; + +unsafe trait Foo { + // methods +} + +unsafe impl Foo for i32 { + // implementations +} + diff --git a/advanced/unsafe-rust/target/.rustc_info.json b/advanced/unsafe-rust/target/.rustc_info.json new file mode 100644 index 0000000..9d7b53d --- /dev/null +++ b/advanced/unsafe-rust/target/.rustc_info.json @@ -0,0 +1 @@ +{"rustc_fingerprint":13873747241073698561,"outputs":{"15337506775154344876":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/carpenat/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""],"1164083562126845933":["rustc 1.33.0 (2aa4c46cf 2019-02-28)\nbinary: rustc\ncommit-hash: 2aa4c46cfdd726e97360c2734835aa3515e8c858\ncommit-date: 2019-02-28\nhost: x86_64-unknown-linux-gnu\nrelease: 1.33.0\nLLVM version: 8.0\n",""],"1617349019360157463":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/carpenat/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""]},"successes":{}}
\ No newline at end of file diff --git a/advanced/unsafe-rust/target/debug/.cargo-lock b/advanced/unsafe-rust/target/debug/.cargo-lock new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/.cargo-lock diff --git a/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/bin-unsafe_rust-c28e180aed6b1879 b/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/bin-unsafe_rust-c28e180aed6b1879 new file mode 100644 index 0000000..482713d --- /dev/null +++ b/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/bin-unsafe_rust-c28e180aed6b1879 @@ -0,0 +1 @@ +c1637025d3fcd0b5
\ No newline at end of file diff --git a/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/bin-unsafe_rust-c28e180aed6b1879.json b/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/bin-unsafe_rust-c28e180aed6b1879.json new file mode 100644 index 0000000..57b65ce --- /dev/null +++ b/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/bin-unsafe_rust-c28e180aed6b1879.json @@ -0,0 +1 @@ +{"rustc":14715343205281380114,"features":"[]","target":13550359907968648163,"profile":11066475326754421590,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1553195584,22060500],".fingerprint/unsafe-rust-c28e180aed6b1879/dep-bin-unsafe_rust-c28e180aed6b1879"]}],"rustflags":[],"edition":"Edition2018"}
\ No newline at end of file diff --git a/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/dep-bin-unsafe_rust-c28e180aed6b1879 b/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/dep-bin-unsafe_rust-c28e180aed6b1879 Binary files differnew file mode 100644 index 0000000..e046c38 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/dep-bin-unsafe_rust-c28e180aed6b1879 diff --git a/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/invoked.timestamp b/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/invoked.timestamp new file mode 100644 index 0000000..e00328d --- /dev/null +++ b/advanced/unsafe-rust/target/debug/.fingerprint/unsafe-rust-c28e180aed6b1879/invoked.timestamp @@ -0,0 +1 @@ +This file has an mtime of when this was started.
\ No newline at end of file diff --git a/advanced/unsafe-rust/target/debug/deps/unsafe_rust-c28e180aed6b1879 b/advanced/unsafe-rust/target/debug/deps/unsafe_rust-c28e180aed6b1879 Binary files differnew file mode 100755 index 0000000..4e2ac17 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/deps/unsafe_rust-c28e180aed6b1879 diff --git a/advanced/unsafe-rust/target/debug/deps/unsafe_rust-c28e180aed6b1879.d b/advanced/unsafe-rust/target/debug/deps/unsafe_rust-c28e180aed6b1879.d new file mode 100644 index 0000000..f91b92f --- /dev/null +++ b/advanced/unsafe-rust/target/debug/deps/unsafe_rust-c28e180aed6b1879.d @@ -0,0 +1,5 @@ +/home/carpenat/devel/learning-rust/advanced/unsafe-rust/target/debug/deps/unsafe_rust-c28e180aed6b1879: src/main.rs + +/home/carpenat/devel/learning-rust/advanced/unsafe-rust/target/debug/deps/unsafe_rust-c28e180aed6b1879.d: src/main.rs + +src/main.rs: diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/1gfyn0tm39r747ad.o b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/1gfyn0tm39r747ad.o Binary files differnew file mode 100644 index 0000000..f32ee36 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/1gfyn0tm39r747ad.o diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/23eb85ricvscbd12.o b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/23eb85ricvscbd12.o Binary files differnew file mode 100644 index 0000000..af6cc3b --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/23eb85ricvscbd12.o diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/2sdrl1lm2yvj0gxu.o b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/2sdrl1lm2yvj0gxu.o Binary files differnew file mode 100644 index 0000000..41b97d1 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/2sdrl1lm2yvj0gxu.o diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/30gce4cd2hq0uwsp.o b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/30gce4cd2hq0uwsp.o Binary files differnew file mode 100644 index 0000000..710891c --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/30gce4cd2hq0uwsp.o diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/3iheyheinuvmg6ds.o b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/3iheyheinuvmg6ds.o Binary files differnew file mode 100644 index 0000000..12ea699 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/3iheyheinuvmg6ds.o diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/4hodvrxy8ugbncf7.o b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/4hodvrxy8ugbncf7.o Binary files differnew file mode 100644 index 0000000..bb0d9b2 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/4hodvrxy8ugbncf7.o diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/5oo0hnz9c2qo9ox.o b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/5oo0hnz9c2qo9ox.o Binary files differnew file mode 100644 index 0000000..70db773 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/5oo0hnz9c2qo9ox.o diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/dep-graph.bin b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/dep-graph.bin Binary files differnew file mode 100644 index 0000000..8e2b895 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/dep-graph.bin diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/query-cache.bin b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/query-cache.bin Binary files differnew file mode 100644 index 0000000..ef70a51 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/query-cache.bin diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/work-products.bin b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/work-products.bin Binary files differnew file mode 100644 index 0000000..fd9cb86 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi-2a6ycufm2z9xi/work-products.bin diff --git a/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi.lock b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi.lock new file mode 100755 index 0000000..e69de29 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/incremental/unsafe_rust-1at6ysk050g0v/s-fak878gvcu-15iobpi.lock diff --git a/advanced/unsafe-rust/target/debug/unsafe-rust b/advanced/unsafe-rust/target/debug/unsafe-rust Binary files differnew file mode 100755 index 0000000..4e2ac17 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/unsafe-rust diff --git a/advanced/unsafe-rust/target/debug/unsafe-rust.d b/advanced/unsafe-rust/target/debug/unsafe-rust.d new file mode 100644 index 0000000..4a06b79 --- /dev/null +++ b/advanced/unsafe-rust/target/debug/unsafe-rust.d @@ -0,0 +1 @@ +/home/carpenat/devel/learning-rust/advanced/unsafe-rust/target/debug/unsafe-rust: /home/carpenat/devel/learning-rust/advanced/unsafe-rust/src/main.rs |