about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2024-07-23 16:10:08 +0200
committerjoboet <jonasboettiger@icloud.com>2024-08-27 11:58:19 +0200
commitd456814842e65a153a1de67960b892897a02ed14 (patch)
tree2b7f252cd52ba3e785fedea291fe3f78c1edf206 /library/std/src/sys
parenta60a9e567a7319b33619f6551dc29522c6f58687 (diff)
downloadrust-d456814842e65a153a1de67960b892897a02ed14.tar.gz
rust-d456814842e65a153a1de67960b892897a02ed14.zip
std: move allocators to `sys`
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/alloc/hermit.rs (renamed from library/std/src/sys/pal/hermit/alloc.rs)1
-rw-r--r--library/std/src/sys/alloc/mod.rs (renamed from library/std/src/sys/pal/common/alloc.rs)67
-rw-r--r--library/std/src/sys/alloc/sgx.rs (renamed from library/std/src/sys/pal/sgx/alloc.rs)7
-rw-r--r--library/std/src/sys/alloc/solid.rs (renamed from library/std/src/sys/pal/solid/alloc.rs)2
-rw-r--r--library/std/src/sys/alloc/uefi.rs (renamed from library/std/src/sys/pal/uefi/alloc.rs)2
-rw-r--r--library/std/src/sys/alloc/unix.rs (renamed from library/std/src/sys/pal/unix/alloc.rs)20
-rw-r--r--library/std/src/sys/alloc/wasm.rs (renamed from library/std/src/sys/pal/wasm/alloc.rs)0
-rw-r--r--library/std/src/sys/alloc/windows.rs (renamed from library/std/src/sys/pal/windows/alloc.rs)15
-rw-r--r--library/std/src/sys/alloc/windows/tests.rs (renamed from library/std/src/sys/pal/windows/alloc/tests.rs)0
-rw-r--r--library/std/src/sys/alloc/xous.rs (renamed from library/std/src/sys/pal/xous/alloc.rs)0
-rw-r--r--library/std/src/sys/alloc/zkvm.rs (renamed from library/std/src/sys/pal/zkvm/alloc.rs)2
-rw-r--r--library/std/src/sys/mod.rs1
-rw-r--r--library/std/src/sys/pal/common/mod.rs1
-rw-r--r--library/std/src/sys/pal/hermit/mod.rs1
-rw-r--r--library/std/src/sys/pal/sgx/mod.rs1
-rw-r--r--library/std/src/sys/pal/solid/mod.rs1
-rw-r--r--library/std/src/sys/pal/teeos/alloc.rs57
-rw-r--r--library/std/src/sys/pal/teeos/mod.rs1
-rw-r--r--library/std/src/sys/pal/uefi/mod.rs4
-rw-r--r--library/std/src/sys/pal/unix/mod.rs1
-rw-r--r--library/std/src/sys/pal/unsupported/alloc.rs23
-rw-r--r--library/std/src/sys/pal/unsupported/mod.rs1
-rw-r--r--library/std/src/sys/pal/wasi/mod.rs2
-rw-r--r--library/std/src/sys/pal/wasip2/mod.rs2
-rw-r--r--library/std/src/sys/pal/wasm/mod.rs1
-rw-r--r--library/std/src/sys/pal/windows/mod.rs1
-rw-r--r--library/std/src/sys/pal/xous/mod.rs1
-rw-r--r--library/std/src/sys/pal/zkvm/mod.rs9
28 files changed, 78 insertions, 146 deletions
diff --git a/library/std/src/sys/pal/hermit/alloc.rs b/library/std/src/sys/alloc/hermit.rs
index f10d5f9227e..77f8200a70a 100644
--- a/library/std/src/sys/pal/hermit/alloc.rs
+++ b/library/std/src/sys/alloc/hermit.rs
@@ -1,4 +1,3 @@
-use super::hermit_abi;
 use crate::alloc::{GlobalAlloc, Layout, System};
 
 #[stable(feature = "alloc_system_type", since = "1.28.0")]
diff --git a/library/std/src/sys/pal/common/alloc.rs b/library/std/src/sys/alloc/mod.rs
index 1b465f95d1b..2c0b533a570 100644
--- a/library/std/src/sys/pal/common/alloc.rs
+++ b/library/std/src/sys/alloc/mod.rs
@@ -1,10 +1,18 @@
 #![forbid(unsafe_op_in_unsafe_fn)]
+
 use crate::alloc::{GlobalAlloc, Layout, System};
-use crate::{cmp, ptr};
+use crate::ptr;
 
 // The minimum alignment guaranteed by the architecture. This value is used to
 // add fast paths for low alignment values.
-#[cfg(any(
+#[allow(dead_code)]
+const MIN_ALIGN: usize = if cfg!(any(
+    all(target_arch = "riscv32", any(target_os = "espidf", target_os = "zkvm")),
+    all(target_arch = "xtensa", target_os = "espidf"),
+)) {
+    // The allocator on the esp-idf and zkvm platforms guarantees 4 byte alignment.
+    4
+} else if cfg!(any(
     target_arch = "x86",
     target_arch = "arm",
     target_arch = "m68k",
@@ -16,11 +24,11 @@ use crate::{cmp, ptr};
     target_arch = "sparc",
     target_arch = "wasm32",
     target_arch = "hexagon",
-    all(target_arch = "riscv32", not(any(target_os = "espidf", target_os = "zkvm"))),
-    all(target_arch = "xtensa", not(target_os = "espidf")),
-))]
-pub const MIN_ALIGN: usize = 8;
-#[cfg(any(
+    target_arch = "riscv32",
+    target_arch = "xtensa",
+)) {
+    8
+} else if cfg!(any(
     target_arch = "x86_64",
     target_arch = "aarch64",
     target_arch = "arm64ec",
@@ -31,16 +39,14 @@ pub const MIN_ALIGN: usize = 8;
     target_arch = "sparc64",
     target_arch = "riscv64",
     target_arch = "wasm64",
-))]
-pub const MIN_ALIGN: usize = 16;
-// The allocator on the esp-idf and zkvm platforms guarantee 4 byte alignment.
-#[cfg(all(any(
-    all(target_arch = "riscv32", any(target_os = "espidf", target_os = "zkvm")),
-    all(target_arch = "xtensa", target_os = "espidf"),
-)))]
-pub const MIN_ALIGN: usize = 4;
+)) {
+    16
+} else {
+    panic!("add a value for MIN_ALIGN")
+};
 
-pub unsafe fn realloc_fallback(
+#[allow(dead_code)]
+unsafe fn realloc_fallback(
     alloc: &System,
     ptr: *mut u8,
     old_layout: Layout,
@@ -52,10 +58,37 @@ pub unsafe fn realloc_fallback(
 
         let new_ptr = GlobalAlloc::alloc(alloc, new_layout);
         if !new_ptr.is_null() {
-            let size = cmp::min(old_layout.size(), new_size);
+            let size = usize::min(old_layout.size(), new_size);
             ptr::copy_nonoverlapping(ptr, new_ptr, size);
             GlobalAlloc::dealloc(alloc, ptr, old_layout);
         }
+
         new_ptr
     }
 }
+
+cfg_if::cfg_if! {
+    if #[cfg(any(
+        target_family = "unix",
+        target_os = "wasi",
+        target_os = "teeos",
+    ))] {
+        mod unix;
+    } else if #[cfg(target_os = "windows")] {
+        mod windows;
+    } else if #[cfg(target_os = "hermit")] {
+        mod hermit;
+    } else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
+        mod sgx;
+    } else if #[cfg(target_os = "solid_asp3")] {
+        mod solid;
+    } else if #[cfg(target_os = "uefi")] {
+        mod uefi;
+    } else if #[cfg(target_family = "wasm")] {
+        mod wasm;
+    } else if #[cfg(target_os = "xous")] {
+        mod xous;
+    } else if #[cfg(target_os = "zkvm")] {
+        mod zkvm;
+    }
+}
diff --git a/library/std/src/sys/pal/sgx/alloc.rs b/library/std/src/sys/alloc/sgx.rs
index f68ede9fcf0..fca9d087e5b 100644
--- a/library/std/src/sys/pal/sgx/alloc.rs
+++ b/library/std/src/sys/alloc/sgx.rs
@@ -1,9 +1,8 @@
-use core::sync::atomic::{AtomicBool, Ordering};
-
-use super::abi::mem as sgx_mem;
-use super::waitqueue::SpinMutex;
 use crate::alloc::{GlobalAlloc, Layout, System};
 use crate::ptr;
+use crate::sync::atomic::{AtomicBool, Ordering};
+use crate::sys::pal::abi::mem as sgx_mem;
+use crate::sys::pal::waitqueue::SpinMutex;
 
 // Using a SpinMutex because we never want to exit the enclave waiting for the
 // allocator.
diff --git a/library/std/src/sys/pal/solid/alloc.rs b/library/std/src/sys/alloc/solid.rs
index 4cf60ac9b2e..abb534a1c5c 100644
--- a/library/std/src/sys/pal/solid/alloc.rs
+++ b/library/std/src/sys/alloc/solid.rs
@@ -1,5 +1,5 @@
+use super::{realloc_fallback, MIN_ALIGN};
 use crate::alloc::{GlobalAlloc, Layout, System};
-use crate::sys::common::alloc::{realloc_fallback, MIN_ALIGN};
 
 #[stable(feature = "alloc_system_type", since = "1.28.0")]
 unsafe impl GlobalAlloc for System {
diff --git a/library/std/src/sys/pal/uefi/alloc.rs b/library/std/src/sys/alloc/uefi.rs
index 15404ac3ea6..5221876e908 100644
--- a/library/std/src/sys/pal/uefi/alloc.rs
+++ b/library/std/src/sys/alloc/uefi.rs
@@ -3,9 +3,9 @@
 
 use r_efi::protocols::loaded_image;
 
-use super::helpers;
 use crate::alloc::{GlobalAlloc, Layout, System};
 use crate::sync::OnceLock;
+use crate::sys::pal::helpers;
 
 #[stable(feature = "alloc_system_type", since = "1.28.0")]
 unsafe impl GlobalAlloc for System {
diff --git a/library/std/src/sys/pal/unix/alloc.rs b/library/std/src/sys/alloc/unix.rs
index 625ba5247f1..46ed7de7162 100644
--- a/library/std/src/sys/pal/unix/alloc.rs
+++ b/library/std/src/sys/alloc/unix.rs
@@ -1,6 +1,6 @@
+use super::{realloc_fallback, MIN_ALIGN};
 use crate::alloc::{GlobalAlloc, Layout, System};
 use crate::ptr;
-use crate::sys::common::alloc::{realloc_fallback, MIN_ALIGN};
 
 #[stable(feature = "alloc_system_type", since = "1.28.0")]
 unsafe impl GlobalAlloc for System {
@@ -11,7 +11,7 @@ unsafe impl GlobalAlloc for System {
         // Also see <https://github.com/rust-lang/rust/issues/45955> and
         // <https://github.com/rust-lang/rust/issues/62251#issuecomment-507580914>.
         if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
-            libc::malloc(layout.size()) as *mut u8
+            unsafe { libc::malloc(layout.size()) as *mut u8 }
         } else {
             // `posix_memalign` returns a non-aligned value if supplied a very
             // large alignment on older versions of Apple's platforms (unknown
@@ -25,7 +25,7 @@ unsafe impl GlobalAlloc for System {
                     return ptr::null_mut();
                 }
             }
-            aligned_malloc(&layout)
+            unsafe { aligned_malloc(&layout) }
         }
     }
 
@@ -33,11 +33,11 @@ unsafe impl GlobalAlloc for System {
     unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
         // See the comment above in `alloc` for why this check looks the way it does.
         if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
-            libc::calloc(layout.size(), 1) as *mut u8
+            unsafe { libc::calloc(layout.size(), 1) as *mut u8 }
         } else {
-            let ptr = self.alloc(layout);
+            let ptr = unsafe { self.alloc(layout) };
             if !ptr.is_null() {
-                ptr::write_bytes(ptr, 0, layout.size());
+                unsafe { ptr::write_bytes(ptr, 0, layout.size()) };
             }
             ptr
         }
@@ -45,15 +45,15 @@ unsafe impl GlobalAlloc for System {
 
     #[inline]
     unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
-        libc::free(ptr as *mut libc::c_void)
+        unsafe { libc::free(ptr as *mut libc::c_void) }
     }
 
     #[inline]
     unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
         if layout.align() <= MIN_ALIGN && layout.align() <= new_size {
-            libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8
+            unsafe { libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 }
         } else {
-            realloc_fallback(self, ptr, layout, new_size)
+            unsafe { realloc_fallback(self, ptr, layout, new_size) }
         }
     }
 }
@@ -81,7 +81,7 @@ cfg_if::cfg_if! {
             // posix_memalign only has one, clear requirement: that the alignment be a multiple of
             // `sizeof(void*)`. Since these are all powers of 2, we can just use max.
             let align = layout.align().max(crate::mem::size_of::<usize>());
-            let ret = libc::posix_memalign(&mut out, align, layout.size());
+            let ret = unsafe { libc::posix_memalign(&mut out, align, layout.size()) };
             if ret != 0 { ptr::null_mut() } else { out as *mut u8 }
         }
     }
diff --git a/library/std/src/sys/pal/wasm/alloc.rs b/library/std/src/sys/alloc/wasm.rs
index ef9d753d7f8..ef9d753d7f8 100644
--- a/library/std/src/sys/pal/wasm/alloc.rs
+++ b/library/std/src/sys/alloc/wasm.rs
diff --git a/library/std/src/sys/pal/windows/alloc.rs b/library/std/src/sys/alloc/windows.rs
index 2205885687d..e91956966aa 100644
--- a/library/std/src/sys/pal/windows/alloc.rs
+++ b/library/std/src/sys/alloc/windows.rs
@@ -1,11 +1,10 @@
-use core::mem::MaybeUninit;
-
+use super::{realloc_fallback, MIN_ALIGN};
 use crate::alloc::{GlobalAlloc, Layout, System};
 use crate::ffi::c_void;
+use crate::mem::MaybeUninit;
 use crate::ptr;
 use crate::sync::atomic::{AtomicPtr, Ordering};
 use crate::sys::c;
-use crate::sys::common::alloc::{realloc_fallback, MIN_ALIGN};
 
 #[cfg(test)]
 mod tests;
@@ -113,28 +112,28 @@ fn init_or_get_process_heap() -> c::HANDLE {
 extern "C" fn process_heap_init_and_alloc(
     _heap: MaybeUninit<c::HANDLE>, // We pass this argument to match the ABI of `HeapAlloc`
     flags: u32,
-    dwBytes: usize,
+    bytes: usize,
 ) -> *mut c_void {
     let heap = init_or_get_process_heap();
     if core::intrinsics::unlikely(heap.is_null()) {
         return ptr::null_mut();
     }
     // SAFETY: `heap` is a non-null handle returned by `GetProcessHeap`.
-    unsafe { HeapAlloc(heap, flags, dwBytes) }
+    unsafe { HeapAlloc(heap, flags, bytes) }
 }
 
 #[inline(never)]
 fn process_heap_alloc(
     _heap: MaybeUninit<c::HANDLE>, // We pass this argument to match the ABI of `HeapAlloc`,
     flags: u32,
-    dwBytes: usize,
+    bytes: usize,
 ) -> *mut c_void {
     let heap = HEAP.load(Ordering::Relaxed);
     if core::intrinsics::likely(!heap.is_null()) {
         // SAFETY: `heap` is a non-null handle returned by `GetProcessHeap`.
-        unsafe { HeapAlloc(heap, flags, dwBytes) }
+        unsafe { HeapAlloc(heap, flags, bytes) }
     } else {
-        process_heap_init_and_alloc(MaybeUninit::uninit(), flags, dwBytes)
+        process_heap_init_and_alloc(MaybeUninit::uninit(), flags, bytes)
     }
 }
 
diff --git a/library/std/src/sys/pal/windows/alloc/tests.rs b/library/std/src/sys/alloc/windows/tests.rs
index 674a3e1d92d..674a3e1d92d 100644
--- a/library/std/src/sys/pal/windows/alloc/tests.rs
+++ b/library/std/src/sys/alloc/windows/tests.rs
diff --git a/library/std/src/sys/pal/xous/alloc.rs b/library/std/src/sys/alloc/xous.rs
index 9ea43445d02..9ea43445d02 100644
--- a/library/std/src/sys/pal/xous/alloc.rs
+++ b/library/std/src/sys/alloc/xous.rs
diff --git a/library/std/src/sys/pal/zkvm/alloc.rs b/library/std/src/sys/alloc/zkvm.rs
index 2fdca223524..a600cfa2220 100644
--- a/library/std/src/sys/pal/zkvm/alloc.rs
+++ b/library/std/src/sys/alloc/zkvm.rs
@@ -1,5 +1,5 @@
-use super::abi;
 use crate::alloc::{GlobalAlloc, Layout, System};
+use crate::sys::pal::abi;
 
 #[stable(feature = "alloc_system_type", since = "1.28.0")]
 unsafe impl GlobalAlloc for System {
diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs
index a86b3628f24..1ef17dd530f 100644
--- a/library/std/src/sys/mod.rs
+++ b/library/std/src/sys/mod.rs
@@ -5,6 +5,7 @@
 /// descriptors.
 mod pal;
 
+mod alloc;
 mod personality;
 
 pub mod anonymous_pipe;
diff --git a/library/std/src/sys/pal/common/mod.rs b/library/std/src/sys/pal/common/mod.rs
index 29fc0835d76..9af4dee401c 100644
--- a/library/std/src/sys/pal/common/mod.rs
+++ b/library/std/src/sys/pal/common/mod.rs
@@ -10,7 +10,6 @@
 
 #![allow(dead_code)]
 
-pub mod alloc;
 pub mod small_c_string;
 
 #[cfg(test)]
diff --git a/library/std/src/sys/pal/hermit/mod.rs b/library/std/src/sys/pal/hermit/mod.rs
index ef406b9ec7f..1f2e5d9469f 100644
--- a/library/std/src/sys/pal/hermit/mod.rs
+++ b/library/std/src/sys/pal/hermit/mod.rs
@@ -18,7 +18,6 @@
 
 use crate::os::raw::c_char;
 
-pub mod alloc;
 pub mod args;
 pub mod env;
 pub mod fd;
diff --git a/library/std/src/sys/pal/sgx/mod.rs b/library/std/src/sys/pal/sgx/mod.rs
index 851ab9b9f97..8d29b2ec619 100644
--- a/library/std/src/sys/pal/sgx/mod.rs
+++ b/library/std/src/sys/pal/sgx/mod.rs
@@ -9,7 +9,6 @@ use crate::io::ErrorKind;
 use crate::sync::atomic::{AtomicBool, Ordering};
 
 pub mod abi;
-pub mod alloc;
 pub mod args;
 pub mod env;
 pub mod fd;
diff --git a/library/std/src/sys/pal/solid/mod.rs b/library/std/src/sys/pal/solid/mod.rs
index cbf34286878..6ebcf5b7c48 100644
--- a/library/std/src/sys/pal/solid/mod.rs
+++ b/library/std/src/sys/pal/solid/mod.rs
@@ -16,7 +16,6 @@ pub mod itron {
     use super::unsupported;
 }
 
-pub mod alloc;
 #[path = "../unsupported/args.rs"]
 pub mod args;
 pub mod env;
diff --git a/library/std/src/sys/pal/teeos/alloc.rs b/library/std/src/sys/pal/teeos/alloc.rs
deleted file mode 100644
index b280d1dd76f..00000000000
--- a/library/std/src/sys/pal/teeos/alloc.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-use crate::alloc::{GlobalAlloc, Layout, System};
-use crate::ptr;
-use crate::sys::common::alloc::{realloc_fallback, MIN_ALIGN};
-
-#[stable(feature = "alloc_system_type", since = "1.28.0")]
-unsafe impl GlobalAlloc for System {
-    #[inline]
-    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
-        // jemalloc provides alignment less than MIN_ALIGN for small allocations.
-        // So only rely on MIN_ALIGN if size >= align.
-        // Also see <https://github.com/rust-lang/rust/issues/45955> and
-        // <https://github.com/rust-lang/rust/issues/62251#issuecomment-507580914>.
-        if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
-            unsafe { libc::malloc(layout.size()) as *mut u8 }
-        } else {
-            unsafe { aligned_malloc(&layout) }
-        }
-    }
-
-    #[inline]
-    unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
-        // See the comment above in `alloc` for why this check looks the way it does.
-        if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
-            unsafe { libc::calloc(layout.size(), 1) as *mut u8 }
-        } else {
-            let ptr = unsafe { self.alloc(layout) };
-            if !ptr.is_null() {
-                unsafe { ptr::write_bytes(ptr, 0, layout.size()) };
-            }
-            ptr
-        }
-    }
-
-    #[inline]
-    unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
-        unsafe { libc::free(ptr as *mut libc::c_void) }
-    }
-
-    #[inline]
-    unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
-        if layout.align() <= MIN_ALIGN && layout.align() <= new_size {
-            unsafe { libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 }
-        } else {
-            unsafe { realloc_fallback(self, ptr, layout, new_size) }
-        }
-    }
-}
-
-#[inline]
-unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
-    let mut out = ptr::null_mut();
-    // posix_memalign requires that the alignment be a multiple of `sizeof(void*)`.
-    // Since these are all powers of 2, we can just use max.
-    let align = layout.align().max(crate::mem::size_of::<usize>());
-    let ret = unsafe { libc::posix_memalign(&mut out, align, layout.size()) };
-    if ret != 0 { ptr::null_mut() } else { out as *mut u8 }
-}
diff --git a/library/std/src/sys/pal/teeos/mod.rs b/library/std/src/sys/pal/teeos/mod.rs
index adefd1bb42c..00e38604240 100644
--- a/library/std/src/sys/pal/teeos/mod.rs
+++ b/library/std/src/sys/pal/teeos/mod.rs
@@ -8,7 +8,6 @@
 
 pub use self::rand::hashmap_random_keys;
 
-pub mod alloc;
 #[path = "../unsupported/args.rs"]
 pub mod args;
 #[path = "../unsupported/env.rs"]
diff --git a/library/std/src/sys/pal/uefi/mod.rs b/library/std/src/sys/pal/uefi/mod.rs
index 851bcea4c1e..ac22f4ded88 100644
--- a/library/std/src/sys/pal/uefi/mod.rs
+++ b/library/std/src/sys/pal/uefi/mod.rs
@@ -13,11 +13,11 @@
 //! [`OsString`]: crate::ffi::OsString
 #![forbid(unsafe_op_in_unsafe_fn)]
 
-pub mod alloc;
 pub mod args;
 pub mod env;
 #[path = "../unsupported/fs.rs"]
 pub mod fs;
+pub mod helpers;
 #[path = "../unsupported/io.rs"]
 pub mod io;
 #[path = "../unsupported/net.rs"]
@@ -30,8 +30,6 @@ pub mod stdio;
 pub mod thread;
 pub mod time;
 
-mod helpers;
-
 #[cfg(test)]
 mod tests;
 
diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs
index 10df3306f92..ba2f58f9c10 100644
--- a/library/std/src/sys/pal/unix/mod.rs
+++ b/library/std/src/sys/pal/unix/mod.rs
@@ -7,7 +7,6 @@ use crate::io::ErrorKind;
 #[macro_use]
 pub mod weak;
 
-pub mod alloc;
 pub mod args;
 pub mod env;
 pub mod fd;
diff --git a/library/std/src/sys/pal/unsupported/alloc.rs b/library/std/src/sys/pal/unsupported/alloc.rs
deleted file mode 100644
index d715ae45401..00000000000
--- a/library/std/src/sys/pal/unsupported/alloc.rs
+++ /dev/null
@@ -1,23 +0,0 @@
-use crate::alloc::{GlobalAlloc, Layout, System};
-use crate::ptr::null_mut;
-
-#[stable(feature = "alloc_system_type", since = "1.28.0")]
-unsafe impl GlobalAlloc for System {
-    #[inline]
-    unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
-        null_mut()
-    }
-
-    #[inline]
-    unsafe fn alloc_zeroed(&self, _layout: Layout) -> *mut u8 {
-        null_mut()
-    }
-
-    #[inline]
-    unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
-
-    #[inline]
-    unsafe fn realloc(&self, _ptr: *mut u8, _layout: Layout, _new_size: usize) -> *mut u8 {
-        null_mut()
-    }
-}
diff --git a/library/std/src/sys/pal/unsupported/mod.rs b/library/std/src/sys/pal/unsupported/mod.rs
index 442e6042ad5..01d516f7568 100644
--- a/library/std/src/sys/pal/unsupported/mod.rs
+++ b/library/std/src/sys/pal/unsupported/mod.rs
@@ -1,6 +1,5 @@
 #![deny(unsafe_op_in_unsafe_fn)]
 
-pub mod alloc;
 pub mod args;
 pub mod env;
 pub mod fs;
diff --git a/library/std/src/sys/pal/wasi/mod.rs b/library/std/src/sys/pal/wasi/mod.rs
index f4dc3ebd414..8051021a588 100644
--- a/library/std/src/sys/pal/wasi/mod.rs
+++ b/library/std/src/sys/pal/wasi/mod.rs
@@ -14,8 +14,6 @@
 //! compiling for wasm. That way it's a compile time error for something that's
 //! guaranteed to be a runtime error!
 
-#[path = "../unix/alloc.rs"]
-pub mod alloc;
 pub mod args;
 pub mod env;
 pub mod fd;
diff --git a/library/std/src/sys/pal/wasip2/mod.rs b/library/std/src/sys/pal/wasip2/mod.rs
index f20630e10cf..546fadbe501 100644
--- a/library/std/src/sys/pal/wasip2/mod.rs
+++ b/library/std/src/sys/pal/wasip2/mod.rs
@@ -6,8 +6,6 @@
 //! To begin with, this target mirrors the wasi target 1 to 1, but over
 //! time this will change significantly.
 
-#[path = "../unix/alloc.rs"]
-pub mod alloc;
 #[path = "../wasi/args.rs"]
 pub mod args;
 #[path = "../wasi/env.rs"]
diff --git a/library/std/src/sys/pal/wasm/mod.rs b/library/std/src/sys/pal/wasm/mod.rs
index 4c34859e918..8141bfac49a 100644
--- a/library/std/src/sys/pal/wasm/mod.rs
+++ b/library/std/src/sys/pal/wasm/mod.rs
@@ -16,7 +16,6 @@
 
 #![deny(unsafe_op_in_unsafe_fn)]
 
-pub mod alloc;
 #[path = "../unsupported/args.rs"]
 pub mod args;
 pub mod env;
diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs
index 6ed77fbc3d4..272fadd9150 100644
--- a/library/std/src/sys/pal/windows/mod.rs
+++ b/library/std/src/sys/pal/windows/mod.rs
@@ -15,7 +15,6 @@ pub mod compat;
 
 mod api;
 
-pub mod alloc;
 pub mod args;
 pub mod c;
 pub mod env;
diff --git a/library/std/src/sys/pal/xous/mod.rs b/library/std/src/sys/pal/xous/mod.rs
index 961d45c5e83..b211e94db65 100644
--- a/library/std/src/sys/pal/xous/mod.rs
+++ b/library/std/src/sys/pal/xous/mod.rs
@@ -1,6 +1,5 @@
 #![forbid(unsafe_op_in_unsafe_fn)]
 
-pub mod alloc;
 #[path = "../unsupported/args.rs"]
 pub mod args;
 #[path = "../unsupported/env.rs"]
diff --git a/library/std/src/sys/pal/zkvm/mod.rs b/library/std/src/sys/pal/zkvm/mod.rs
index 651f25d6623..20fdb7468a4 100644
--- a/library/std/src/sys/pal/zkvm/mod.rs
+++ b/library/std/src/sys/pal/zkvm/mod.rs
@@ -10,7 +10,7 @@
 
 const WORD_SIZE: usize = core::mem::size_of::<u32>();
 
-pub mod alloc;
+pub mod abi;
 #[path = "../zkvm/args.rs"]
 pub mod args;
 pub mod env;
@@ -26,13 +26,10 @@ pub mod pipe;
 #[path = "../unsupported/process.rs"]
 pub mod process;
 pub mod stdio;
-#[path = "../unsupported/time.rs"]
-pub mod time;
-
 #[path = "../unsupported/thread.rs"]
 pub mod thread;
-
-mod abi;
+#[path = "../unsupported/time.rs"]
+pub mod time;
 
 use crate::io as std_io;