From 0bd476d28af204c34c62cb3e7b5e4c660838d59b Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Sat, 11 Feb 2023 13:45:07 -0700
Subject: [PATCH] Update to new Rust toolchain

---
 rust-toolchain      |  1 -
 rust-toolchain.toml |  3 +++
 src/lib.rs          |  5 ++++-
 src/platform/pte.rs | 10 +++++-----
 4 files changed, 12 insertions(+), 7 deletions(-)
 delete mode 100644 rust-toolchain
 create mode 100644 rust-toolchain.toml

diff --git a/rust-toolchain b/rust-toolchain
deleted file mode 100644
index 9eed51006..000000000
--- a/rust-toolchain
+++ /dev/null
@@ -1 +0,0 @@
-nightly-2022-03-18
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
new file mode 100644
index 000000000..87f6fe713
--- /dev/null
+++ b/rust-toolchain.toml
@@ -0,0 +1,3 @@
+[toolchain]
+channel = "nightly-2023-01-21"
+components = ["rust-src"]
diff --git a/src/lib.rs b/src/lib.rs
index f03ce4c08..e545fd697 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,6 +2,7 @@
 #![allow(non_camel_case_types)]
 #![allow(non_upper_case_globals)]
 #![allow(unused_variables)]
+#![feature(alloc_error_handler)]
 #![feature(allocator_api)]
 #![feature(array_chunks)]
 #![feature(asm_const)]
@@ -19,6 +20,8 @@
 #![allow(clippy::derive_hash_xor_eq)]
 #![allow(clippy::eval_order_dependence)]
 #![allow(clippy::mut_from_ref)]
+// TODO: fix these
+#![warn(unaligned_references)]
 
 #[macro_use]
 extern crate alloc;
@@ -87,7 +90,7 @@ pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
 pub extern "C" fn rust_eh_personality() {}
 
 #[cfg(not(test))]
-#[lang = "oom"]
+#[alloc_error_handler]
 #[linkage = "weak"]
 #[no_mangle]
 pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! {
diff --git a/src/platform/pte.rs b/src/platform/pte.rs
index 7519150c6..13bf4bbd4 100644
--- a/src/platform/pte.rs
+++ b/src/platform/pte.rs
@@ -384,7 +384,7 @@ pub unsafe extern "C" fn pte_osSemaphoreCancellablePend(
 
 #[no_mangle]
 pub unsafe extern "C" fn pte_osAtomicExchange(ptarg: *mut c_int, val: c_int) -> c_int {
-    intrinsics::atomic_xchg(ptarg, val)
+    intrinsics::atomic_xchg_seqcst(ptarg, val)
 }
 
 #[no_mangle]
@@ -393,22 +393,22 @@ pub unsafe extern "C" fn pte_osAtomicCompareExchange(
     exchange: c_int,
     comp: c_int,
 ) -> c_int {
-    intrinsics::atomic_cxchg(pdest, comp, exchange).0
+    intrinsics::atomic_cxchg_seqcst_seqcst(pdest, comp, exchange).0
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn pte_osAtomicExchangeAdd(pAppend: *mut c_int, value: c_int) -> c_int {
-    intrinsics::atomic_xadd(pAppend, value)
+    intrinsics::atomic_xadd_seqcst(pAppend, value)
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn pte_osAtomicDecrement(pdest: *mut c_int) -> c_int {
-    intrinsics::atomic_xadd(pdest, -1) - 1
+    intrinsics::atomic_xadd_seqcst(pdest, -1) - 1
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn pte_osAtomicIncrement(pdest: *mut c_int) -> c_int {
-    intrinsics::atomic_xadd(pdest, 1) + 1
+    intrinsics::atomic_xadd_seqcst(pdest, 1) + 1
 }
 
 #[no_mangle]
-- 
GitLab