update mac
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,40 +0,0 @@
|
||||
From 0fcdbacd8b06c24f5761a0cf9cb0c43cad05c19b Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Watson <twatson52@icloud.com>
|
||||
Date: Mon, 26 Feb 2024 19:51:12 -0600
|
||||
Subject: [PATCH] fs/fcntl: accept more values as F_DUPFD_CLOEXEC args
|
||||
|
||||
libwebrtc doesn't pass anything as the arg to this function so the
|
||||
minimum fd ends up as random garbage. If it's bigger than the maximum
|
||||
fd, which is likely, then the duplication fails, and libwebrtc breaks.
|
||||
|
||||
The previous patch (081abc5fa701738699705a6c0a41c824df77cb37) rejects
|
||||
args >= 1024 (the default soft max fd) and instead subtitutes a minimum
|
||||
fd of 0 to allow such requests to succeed.
|
||||
|
||||
However, gnulib's test suite can pass the following values and expects
|
||||
them to fail; this patch prevents those from succeeding:
|
||||
* -1 (hard-coded)
|
||||
* 1024 (`ulimit -n` value by default)
|
||||
* 1048576 (`ulimit -n` value in Nix build sandbox)
|
||||
|
||||
Hopefully the garbage values libwebrtc passes do not match very often.
|
||||
---
|
||||
fs/fcntl.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/fs/fcntl.c b/fs/fcntl.c
|
||||
index f18f87419445..65a6861476ec 100644
|
||||
--- a/fs/fcntl.c
|
||||
+++ b/fs/fcntl.c
|
||||
@@ -326,7 +326,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
|
||||
err = f_dupfd(argi, filp, 0);
|
||||
break;
|
||||
case F_DUPFD_CLOEXEC:
|
||||
- if (arg >= 1024)
|
||||
+ if ((arg > 1024) && (argi != 1048576) && (argi != -1))
|
||||
argi = 0; /* Lol libwebrtc */
|
||||
err = f_dupfd(argi, filp, O_CLOEXEC);
|
||||
break;
|
||||
--
|
||||
2.43.0
|
||||
|
||||
66
hosts/mac-nixos/apple-silicon-support/packages/linux-asahi/config
Executable file → Normal file
66
hosts/mac-nixos/apple-silicon-support/packages/linux-asahi/config
Executable file → Normal file
@@ -516,7 +516,7 @@ CONFIG_DMI=y
|
||||
#
|
||||
# Power management options
|
||||
#
|
||||
# CONFIG_SUSPEND is not set
|
||||
CONFIG_SUSPEND=y
|
||||
# CONFIG_HIBERNATION is not set
|
||||
CONFIG_PM=y
|
||||
CONFIG_PM_DEBUG=y
|
||||
@@ -742,6 +742,8 @@ CONFIG_MODULE_UNLOAD=y
|
||||
# CONFIG_MODULE_COMPRESS_NONE is not set
|
||||
# CONFIG_MODULE_COMPRESS_GZIP is not set
|
||||
# CONFIG_MODULE_COMPRESS_XZ is not set
|
||||
CONFIG_MODULE_COMPRESS=y
|
||||
CONFIG_MODULE_COMPRESS_ALL=y
|
||||
CONFIG_MODULE_COMPRESS_ZSTD=y
|
||||
# CONFIG_MODULE_DECOMPRESS is not set
|
||||
# CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS is not set
|
||||
@@ -7782,52 +7784,55 @@ CONFIG_ACPI=y
|
||||
CONFIG_TCG_TPM=y
|
||||
CONFIG_TCG_TIS=m
|
||||
CONFIG_TCG_CRB=m
|
||||
# needed for mounting the installer squashfs
|
||||
# https://github.com/NixOS/nixpkgs/blob/6295433b2b0079b063d78761ae52c4f385180cae/nixos/modules/installer/cd-dvd/iso-image.nix#L725
|
||||
CONFIG_SQUASHFS_CHOICE_DECOMP_BY_MOUNT=y
|
||||
|
||||
# for better efficiency with sound
|
||||
CONFIG_UCLAMP_TASK=y
|
||||
CONFIG_UCLAMP_TASK_GROUP=y
|
||||
CONFIG_UCLAMP_BUCKETS_COUNT=5
|
||||
|
||||
CONFIG_RUST_OVERFLOW_CHECKS=y
|
||||
CONFIG_RUST_PHYLIB_ABSTRACTIONS=y
|
||||
|
||||
# "upstreamed" flags
|
||||
CONFIG_SPI_APPLE=m
|
||||
|
||||
# Fedora Asahi Remix-specific options
|
||||
# generated with something like
|
||||
# git diff --name-only fedora-6.6 fedora-asahi-6.6 redhat/configs/ | xargs cat >> config
|
||||
# in a checkout of https://gitlab.com/fedora-asahi/kernel-asahi/-/tree/fedora-asahi-6.6
|
||||
# git diff --name-only fedora-6.9 fedora-asahi-6.9 redhat/configs/ | grep -v x86 | grep -v s390x | xargs cat | sort >> config
|
||||
# in a checkout of https://gitlab.com/fedora-asahi/kernel-asahi/-/tree/fedora-asahi-6.9
|
||||
|
||||
CONFIG_SUSPEND=y
|
||||
# CONFIG_APPLE_PLATFORMS is not set
|
||||
# CONFIG_DRM_SIMPLEDRM_BACKLIGHT is not set
|
||||
CONFIG_RUST=y
|
||||
# CONFIG_RUST_BUILD_ASSERT_ALLOW is not set
|
||||
# CONFIG_RUST_DEBUG_ASSERTIONS is not set
|
||||
# CONFIG_RUST_EXTRA_LOCKDEP is not set
|
||||
CONFIG_RUST_OVERFLOW_CHECKS=y
|
||||
# CONFIG_SPI_HID_APPLE_OF is not set
|
||||
# CONFIG_USB_XHCI_PCI_ASMEDIA is not set
|
||||
# CONFIG_APPLE_MAILBOX is not set
|
||||
# CONFIG_APPLE_PMGR_MISC is not set
|
||||
CONFIG_ARM64_MEMORY_MODEL_CONTROL=y
|
||||
# CONFIG_ARM_APPLE_CPUIDLE is not set
|
||||
# CONFIG_SND_SOC_CS42L84 is not set
|
||||
CONFIG_DRM_GEM_SHMEM_HELPER=y
|
||||
CONFIG_USB_XHCI_PCI_ASMEDIA=y
|
||||
CONFIG_SND_SOC_CS42L84=m
|
||||
CONFIG_TOUCHSCREEN_APPLE_Z2=m
|
||||
CONFIG_APPLE_AOP=m
|
||||
CONFIG_APPLE_DOCKCHANNEL=m
|
||||
CONFIG_APPLE_MBOX=y
|
||||
CONFIG_APPLE_MAILBOX=y
|
||||
# CONFIG_APPLE_PLATFORMS is not set
|
||||
CONFIG_APPLE_PLATFORMS=y
|
||||
# CONFIG_APPLE_PMGR_MISC is not set
|
||||
CONFIG_APPLE_PMGR_MISC=y
|
||||
CONFIG_APPLE_RTKIT=y
|
||||
CONFIG_APPLE_RTKIT_HELPER=m
|
||||
CONFIG_APPLE_RTKIT=y
|
||||
CONFIG_APPLE_SEP=m
|
||||
CONFIG_APPLE_SIO=m
|
||||
CONFIG_APPLE_SMC=m
|
||||
CONFIG_APPLE_SMC_RTKIT=m
|
||||
CONFIG_ARM64_MEMORY_MODEL_CONTROL=y
|
||||
# CONFIG_ARM_APPLE_CPUIDLE is not set
|
||||
CONFIG_ARM_APPLE_CPUIDLE=y
|
||||
CONFIG_CHARGER_MACSMC=m
|
||||
CONFIG_DRM_ADP=m
|
||||
CONFIG_DRM_APPLE_AUDIO=y
|
||||
# CONFIG_DRM_APPLE_DEBUG is not set
|
||||
CONFIG_DRM_APPLE=m
|
||||
CONFIG_DRM_ASAHI=m
|
||||
# CONFIG_DRM_ASAHI_DEBUG_ALLOCATOR is not set
|
||||
CONFIG_DRM_ASAHI=m
|
||||
# CONFIG_DRM_PANEL_SUMMIT is not set
|
||||
CONFIG_DRM_PANEL_SUMMIT=m
|
||||
CONFIG_GPIO_MACSMC=m
|
||||
CONFIG_HID_DOCKCHANNEL=m
|
||||
CONFIG_IIO_AOP_SENSOR_ALS=m
|
||||
CONFIG_IIO_AOP_SENSOR_LAS=m
|
||||
CONFIG_INPUT_MACSMC_HID=m
|
||||
CONFIG_MFD_APPLE_SPMI_PMU=m
|
||||
CONFIG_MUX_APPLE_DPXBAR=m
|
||||
@@ -7836,10 +7841,15 @@ CONFIG_PHY_APPLE_ATC=m
|
||||
CONFIG_PHY_APPLE_DPTX=m
|
||||
CONFIG_POWER_RESET_MACSMC=m
|
||||
CONFIG_RTC_DRV_MACSMC=m
|
||||
CONFIG_SENSORS_MACSMC=m
|
||||
CONFIG_SND_SOC_APPLE_AOP_AUDIO=m
|
||||
CONFIG_SND_SOC_APPLE_MACAUDIO=m
|
||||
CONFIG_SND_SOC_APPLE_SILICON=m
|
||||
CONFIG_SPI_APPLE=m
|
||||
CONFIG_SND_SOC_CS42L84=m
|
||||
# CONFIG_SPI_HID_APPLE_OF is not set
|
||||
CONFIG_SPI_HID_APPLE_OF=m
|
||||
CONFIG_SPMI_APPLE=m
|
||||
# CONFIG_TOUCHSCREEN_APPLE_Z2 is not set
|
||||
CONFIG_TOUCHSCREEN_APPLE_Z2=m
|
||||
# CONFIG_USB_XHCI_PCI_ASMEDIA is not set
|
||||
CONFIG_USB_XHCI_PCI_ASMEDIA=y
|
||||
CONFIG_VIDEO_APPLE_ISP=m
|
||||
CONFIG_SND_SOC_CS42L84=m
|
||||
|
||||
236
hosts/mac-nixos/apple-silicon-support/packages/linux-asahi/default.nix
Executable file → Normal file
236
hosts/mac-nixos/apple-silicon-support/packages/linux-asahi/default.nix
Executable file → Normal file
@@ -1,13 +1,9 @@
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
callPackage,
|
||||
writeShellScriptBin,
|
||||
writeText,
|
||||
removeReferencesTo,
|
||||
linuxPackagesFor,
|
||||
withRust ? false,
|
||||
_kernelPatches ? [ ],
|
||||
{ lib
|
||||
, callPackage
|
||||
, writeText
|
||||
, linuxPackagesFor
|
||||
, withRust ? true
|
||||
, _kernelPatches ? [ ]
|
||||
}:
|
||||
|
||||
let
|
||||
@@ -15,204 +11,94 @@ let
|
||||
|
||||
# parse <OPT> [ymn]|foo style configuration as found in a patch's extraConfig
|
||||
# into a list of k, v tuples
|
||||
parseExtraConfig =
|
||||
config:
|
||||
parseExtraConfig = config:
|
||||
let
|
||||
lines = builtins.filter (s: s != "") (lib.strings.splitString "\n" config);
|
||||
parseLine =
|
||||
line:
|
||||
let
|
||||
t = lib.strings.splitString " " line;
|
||||
join = l: builtins.foldl' (a: b: "${a} ${b}") (builtins.head l) (builtins.tail l);
|
||||
v = if (builtins.length t) > 2 then join (builtins.tail t) else (i t 1);
|
||||
in
|
||||
[
|
||||
"CONFIG_${i t 0}"
|
||||
v
|
||||
];
|
||||
in
|
||||
map parseLine lines;
|
||||
lines =
|
||||
builtins.filter (s: s != "") (lib.strings.splitString "\n" config);
|
||||
parseLine = line: let
|
||||
t = lib.strings.splitString " " line;
|
||||
join = l: builtins.foldl' (a: b: "${a} ${b}")
|
||||
(builtins.head l) (builtins.tail l);
|
||||
v = if (builtins.length t) > 2 then join (builtins.tail t) else (i t 1);
|
||||
in [ "CONFIG_${i t 0}" v ];
|
||||
in map parseLine lines;
|
||||
|
||||
# parse <OPT>=lib.kernel.(yes|module|no)|lib.kernel.freeform "foo"
|
||||
# style configuration as found in a patch's extraStructuredConfig into
|
||||
# a list of k, v tuples
|
||||
parseExtraStructuredConfig =
|
||||
config:
|
||||
lib.attrsets.mapAttrsToList (k: v: [
|
||||
"CONFIG_${k}"
|
||||
(v.tristate or v.freeform)
|
||||
]) config;
|
||||
parseExtraStructuredConfig = config: lib.attrsets.mapAttrsToList
|
||||
(k: v: [ "CONFIG_${k}" (v.tristate or v.freeform) ] ) config;
|
||||
|
||||
parsePatchConfig =
|
||||
{
|
||||
extraConfig ? "",
|
||||
extraStructuredConfig ? { },
|
||||
...
|
||||
}:
|
||||
(parseExtraConfig extraConfig) ++ (parseExtraStructuredConfig extraStructuredConfig);
|
||||
parsePatchConfig = { extraConfig ? "", extraStructuredConfig ? {}, ... }:
|
||||
(parseExtraConfig extraConfig) ++
|
||||
(parseExtraStructuredConfig extraStructuredConfig);
|
||||
|
||||
# parse CONFIG_<OPT>=[ymn]|"foo" style configuration as found in a config file
|
||||
# into a list of k, v tuples
|
||||
parseConfig =
|
||||
config:
|
||||
parseConfig = config:
|
||||
let
|
||||
parseLine = builtins.match ''(CONFIG_[[:upper:][:digit:]_]+)=(([ymn])|"([^"]*)")'';
|
||||
# get either the [ymn] option or the "foo" option; whichever matched
|
||||
t =
|
||||
l:
|
||||
let
|
||||
v = (i l 2);
|
||||
in
|
||||
[
|
||||
(i l 0)
|
||||
(if v != null then v else (i l 3))
|
||||
];
|
||||
t = l: let v = (i l 2); in [ (i l 0) (if v != null then v else (i l 3)) ];
|
||||
lines = lib.strings.splitString "\n" config;
|
||||
in
|
||||
map t (builtins.filter (l: l != null) (map parseLine lines));
|
||||
in map t (builtins.filter (l: l != null) (map parseLine lines));
|
||||
|
||||
origConfigfile = ./config;
|
||||
|
||||
linux-asahi-pkg =
|
||||
{
|
||||
stdenv,
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
fetchpatch,
|
||||
linuxKernel,
|
||||
rustPlatform,
|
||||
rustc,
|
||||
rustfmt,
|
||||
rust-bindgen,
|
||||
...
|
||||
}@args:
|
||||
linux-asahi-pkg = { stdenv, lib, fetchFromGitHub, fetchpatch, linuxKernel,
|
||||
rustc, rust-bindgen, ... } @ args:
|
||||
let
|
||||
origConfigText = builtins.readFile origConfigfile;
|
||||
|
||||
# extraConfig from all patches in order
|
||||
extraConfig = lib.fold (patch: ex: ex ++ (parsePatchConfig patch)) [ ] _kernelPatches;
|
||||
extraConfig =
|
||||
lib.fold (patch: ex: ex ++ (parsePatchConfig patch)) [] _kernelPatches
|
||||
++ (lib.optional withRust [ "CONFIG_RUST" "y" ]);
|
||||
# config file text for above
|
||||
extraConfigText =
|
||||
let
|
||||
text = k: v: if (v == "y") || (v == "m") || (v == "n") then "${k}=${v}" else ''${k}="${v}"'';
|
||||
in
|
||||
(map (t: text (i t 0) (i t 1)) extraConfig);
|
||||
extraConfigText = let
|
||||
text = k: v: if (v == "y") || (v == "m") || (v == "n")
|
||||
then "${k}=${v}" else ''${k}="${v}"'';
|
||||
in (map (t: text (i t 0) (i t 1)) extraConfig);
|
||||
|
||||
# final config as a text file path
|
||||
configfile =
|
||||
if extraConfig == [ ] then
|
||||
origConfigfile
|
||||
else
|
||||
writeText "config" ''
|
||||
${origConfigText}
|
||||
configfile = if extraConfig == [] then origConfigfile else
|
||||
writeText "config" ''
|
||||
${origConfigText}
|
||||
|
||||
# Patches
|
||||
${lib.strings.concatStringsSep "\n" extraConfigText}
|
||||
'';
|
||||
# Patches
|
||||
${lib.strings.concatStringsSep "\n" extraConfigText}
|
||||
'';
|
||||
# final config as an attrset
|
||||
configAttrs =
|
||||
let
|
||||
makePair = t: lib.nameValuePair (i t 0) (i t 1);
|
||||
configList = (parseConfig origConfigText) ++ extraConfig;
|
||||
in
|
||||
builtins.listToAttrs (map makePair (lib.lists.reverseList configList));
|
||||
|
||||
# used to (ostensibly) keep compatibility for those running stable versions of nixos
|
||||
rustOlder = version: withRust && (lib.versionOlder rustc.version version);
|
||||
bindgenOlder = version: withRust && (lib.versionOlder rust-bindgen.unwrapped.version version);
|
||||
configAttrs = let
|
||||
makePair = t: lib.nameValuePair (i t 0) (i t 1);
|
||||
configList = (parseConfig origConfigText) ++ extraConfig;
|
||||
in builtins.listToAttrs (map makePair (lib.lists.reverseList configList));
|
||||
|
||||
# used to fix issues when nixpkgs gets ahead of the kernel
|
||||
rustAtLeast = version: withRust && (lib.versionAtLeast rustc.version version);
|
||||
bindgenAtLeast = version: withRust && (lib.versionAtLeast rust-bindgen.unwrapped.version version);
|
||||
in
|
||||
(
|
||||
linuxKernel.manualConfig rec {
|
||||
inherit stdenv lib;
|
||||
linuxKernel.manualConfig rec {
|
||||
inherit stdenv lib;
|
||||
|
||||
version = "6.6.0-asahi";
|
||||
modDirVersion = version;
|
||||
extraMeta.branch = "6.6";
|
||||
version = "6.14.8-asahi";
|
||||
modDirVersion = version;
|
||||
extraMeta.branch = "6.14";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
# tracking: https://github.com/AsahiLinux/linux/tree/asahi-wip (w/ fedora verification)
|
||||
owner = "AsahiLinux";
|
||||
repo = "linux";
|
||||
rev = "asahi-6.6-15";
|
||||
hash = "sha256-Jm7wTKWuwd/6ZN0g5F4CNNETiOyGQL31hfSyTDYH85k=";
|
||||
};
|
||||
src = fetchFromGitHub {
|
||||
# tracking: https://github.com/AsahiLinux/linux/tree/asahi-wip (w/ fedora verification)
|
||||
owner = "AsahiLinux";
|
||||
repo = "linux";
|
||||
rev = "asahi-6.14.8-1";
|
||||
hash = "sha256-JrWVw1FiF9LYMiOPm0QI0bg/CrZAMSSVcs4AWNDIH3Q=";
|
||||
};
|
||||
|
||||
kernelPatches =
|
||||
[
|
||||
{
|
||||
name = "coreutils-fix";
|
||||
patch = ./0001-fs-fcntl-accept-more-values-as-F_DUPFD_CLOEXEC-args.patch;
|
||||
}
|
||||
# speaker enablement; we assert on the relevant lsp-plugins patch
|
||||
# before installing speakersafetyd to let the speakers work
|
||||
{
|
||||
name = "speakers-1";
|
||||
patch = fetchpatch {
|
||||
url = "https://github.com/AsahiLinux/linux/commit/385ea7b5023486aba7919cec8b6b3f6a843a1013.patch";
|
||||
hash = "sha256-u7IzhJbUgBPfhJXAcpHw1I6OPzPHc1UKYjH91Ep3QHQ=";
|
||||
};
|
||||
}
|
||||
{
|
||||
name = "speakers-2";
|
||||
patch = fetchpatch {
|
||||
url = "https://github.com/AsahiLinux/linux/commit/6a24102c06c95951ab992e2d41336cc6d4bfdf23.patch";
|
||||
hash = "sha256-wn5x2hN42/kCp/XHBvLWeNLfwlOBB+T6UeeMt2tSg3o=";
|
||||
};
|
||||
}
|
||||
]
|
||||
++ lib.optionals (rustAtLeast "1.75.0") [
|
||||
{
|
||||
name = "rustc-1.75.0";
|
||||
patch = ./0001-check-in-new-alloc-for-1.75.0.patch;
|
||||
}
|
||||
]
|
||||
++ lib.optionals (rustAtLeast "1.76.0") [
|
||||
{
|
||||
name = "rustc-1.76.0";
|
||||
patch = ./rust_1_76_0.patch;
|
||||
}
|
||||
]
|
||||
++ _kernelPatches;
|
||||
kernelPatches = [
|
||||
] ++ _kernelPatches;
|
||||
|
||||
inherit configfile;
|
||||
# hide Rust support from the nixpkgs infra to avoid it re-adding the rust packages.
|
||||
# we can't use it until it's in stable and until we've evaluated the cross-compilation impact.
|
||||
config = configAttrs // {
|
||||
"CONFIG_RUST" = "n";
|
||||
};
|
||||
}
|
||||
// (args.argsOverride or { })
|
||||
).overrideAttrs
|
||||
(
|
||||
old:
|
||||
if withRust then
|
||||
{
|
||||
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
|
||||
rust-bindgen
|
||||
rustfmt
|
||||
rustc
|
||||
removeReferencesTo
|
||||
];
|
||||
# HACK: references shouldn't have been there in the first place
|
||||
# TODO: remove once 23.05 is obsolete
|
||||
postFixup =
|
||||
(old.postFixup or "")
|
||||
+ ''
|
||||
if [ -f $dev/lib/modules/${old.version}/build/vmlinux ]; then
|
||||
remove-references-to -t $out $dev/lib/modules/${old.version}/build/vmlinux
|
||||
fi
|
||||
remove-references-to -t $dev $out/Image
|
||||
'';
|
||||
RUST_LIB_SRC = rustPlatform.rustLibSrc;
|
||||
}
|
||||
else
|
||||
{ }
|
||||
);
|
||||
inherit configfile;
|
||||
config = configAttrs;
|
||||
};
|
||||
|
||||
linux-asahi = (callPackage linux-asahi-pkg { });
|
||||
in
|
||||
lib.recurseIntoAttrs (linuxPackagesFor linux-asahi)
|
||||
in lib.recurseIntoAttrs (linuxPackagesFor linux-asahi)
|
||||
|
||||
@@ -1,426 +0,0 @@
|
||||
diff --git a/rust/alloc/alloc.rs b/rust/alloc/alloc.rs
|
||||
index 08eafb3de807..7cf4edb8b786 100644
|
||||
--- a/rust/alloc/alloc.rs
|
||||
+++ b/rust/alloc/alloc.rs
|
||||
@@ -426,12 +426,14 @@ pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
+#[cfg(not(no_global_oom_handling))]
|
||||
/// Specialize clones into pre-allocated, uninitialized memory.
|
||||
/// Used by `Box::clone` and `Rc`/`Arc::make_mut`.
|
||||
pub(crate) trait WriteCloneIntoRaw: Sized {
|
||||
unsafe fn write_clone_into_raw(&self, target: *mut Self);
|
||||
}
|
||||
|
||||
+#[cfg(not(no_global_oom_handling))]
|
||||
impl<T: Clone> WriteCloneIntoRaw for T {
|
||||
#[inline]
|
||||
default unsafe fn write_clone_into_raw(&self, target: *mut Self) {
|
||||
@@ -441,6 +443,7 @@ impl<T: Clone> WriteCloneIntoRaw for T {
|
||||
}
|
||||
}
|
||||
|
||||
+#[cfg(not(no_global_oom_handling))]
|
||||
impl<T: Copy> WriteCloneIntoRaw for T {
|
||||
#[inline]
|
||||
unsafe fn write_clone_into_raw(&self, target: *mut Self) {
|
||||
diff --git a/rust/alloc/boxed.rs b/rust/alloc/boxed.rs
|
||||
index ed7e2f666178..359b8bcdb7a2 100644
|
||||
--- a/rust/alloc/boxed.rs
|
||||
+++ b/rust/alloc/boxed.rs
|
||||
@@ -1030,10 +1030,18 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
|
||||
/// use std::ptr;
|
||||
///
|
||||
/// let x = Box::new(String::from("Hello"));
|
||||
- /// let p = Box::into_raw(x);
|
||||
+ /// let ptr = Box::into_raw(x);
|
||||
+ /// unsafe {
|
||||
+ /// ptr::drop_in_place(ptr);
|
||||
+ /// dealloc(ptr as *mut u8, Layout::new::<String>());
|
||||
+ /// }
|
||||
+ /// ```
|
||||
+ /// Note: This is equivalent to the following:
|
||||
+ /// ```
|
||||
+ /// let x = Box::new(String::from("Hello"));
|
||||
+ /// let ptr = Box::into_raw(x);
|
||||
/// unsafe {
|
||||
- /// ptr::drop_in_place(p);
|
||||
- /// dealloc(p as *mut u8, Layout::new::<String>());
|
||||
+ /// drop(Box::from_raw(ptr));
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
diff --git a/rust/alloc/collections/mod.rs b/rust/alloc/collections/mod.rs
|
||||
index 2506065d158a..00ffb3b97365 100644
|
||||
--- a/rust/alloc/collections/mod.rs
|
||||
+++ b/rust/alloc/collections/mod.rs
|
||||
@@ -150,6 +150,7 @@ fn fmt(
|
||||
|
||||
/// An intermediate trait for specialization of `Extend`.
|
||||
#[doc(hidden)]
|
||||
+#[cfg(not(no_global_oom_handling))]
|
||||
trait SpecExtend<I: IntoIterator> {
|
||||
/// Extends `self` with the contents of the given iterator.
|
||||
fn spec_extend(&mut self, iter: I);
|
||||
diff --git a/rust/alloc/lib.rs b/rust/alloc/lib.rs
|
||||
index 65b7a02d0956..6cddaf298118 100644
|
||||
--- a/rust/alloc/lib.rs
|
||||
+++ b/rust/alloc/lib.rs
|
||||
@@ -157,6 +157,7 @@
|
||||
#![feature(std_internals)]
|
||||
#![feature(str_internals)]
|
||||
#![feature(strict_provenance)]
|
||||
+#![feature(trusted_fused)]
|
||||
#![feature(trusted_len)]
|
||||
#![feature(trusted_random_access)]
|
||||
#![feature(try_trait_v2)]
|
||||
@@ -276,7 +277,7 @@ pub(crate) mod test_helpers {
|
||||
/// seed not being the same for every RNG invocation too.
|
||||
pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
|
||||
use std::hash::{BuildHasher, Hash, Hasher};
|
||||
- let mut hasher = std::collections::hash_map::RandomState::new().build_hasher();
|
||||
+ let mut hasher = std::hash::RandomState::new().build_hasher();
|
||||
std::panic::Location::caller().hash(&mut hasher);
|
||||
let hc64 = hasher.finish();
|
||||
let seed_vec =
|
||||
diff --git a/rust/alloc/raw_vec.rs b/rust/alloc/raw_vec.rs
|
||||
index 65d5ce15828e..3fb1ee104cff 100644
|
||||
--- a/rust/alloc/raw_vec.rs
|
||||
+++ b/rust/alloc/raw_vec.rs
|
||||
@@ -27,6 +27,16 @@ enum AllocInit {
|
||||
Zeroed,
|
||||
}
|
||||
|
||||
+#[repr(transparent)]
|
||||
+#[cfg_attr(target_pointer_width = "16", rustc_layout_scalar_valid_range_end(0x7fff))]
|
||||
+#[cfg_attr(target_pointer_width = "32", rustc_layout_scalar_valid_range_end(0x7fff_ffff))]
|
||||
+#[cfg_attr(target_pointer_width = "64", rustc_layout_scalar_valid_range_end(0x7fff_ffff_ffff_ffff))]
|
||||
+struct Cap(usize);
|
||||
+
|
||||
+impl Cap {
|
||||
+ const ZERO: Cap = unsafe { Cap(0) };
|
||||
+}
|
||||
+
|
||||
/// A low-level utility for more ergonomically allocating, reallocating, and deallocating
|
||||
/// a buffer of memory on the heap without having to worry about all the corner cases
|
||||
/// involved. This type is excellent for building your own data structures like Vec and VecDeque.
|
||||
@@ -52,7 +62,12 @@ enum AllocInit {
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub(crate) struct RawVec<T, A: Allocator = Global> {
|
||||
ptr: Unique<T>,
|
||||
- cap: usize,
|
||||
+ /// Never used for ZSTs; it's `capacity()`'s responsibility to return usize::MAX in that case.
|
||||
+ ///
|
||||
+ /// # Safety
|
||||
+ ///
|
||||
+ /// `cap` must be in the `0..=isize::MAX` range.
|
||||
+ cap: Cap,
|
||||
alloc: A,
|
||||
}
|
||||
|
||||
@@ -121,7 +136,7 @@ impl<T, A: Allocator> RawVec<T, A> {
|
||||
/// the returned `RawVec`.
|
||||
pub const fn new_in(alloc: A) -> Self {
|
||||
// `cap: 0` means "unallocated". zero-sized types are ignored.
|
||||
- Self { ptr: Unique::dangling(), cap: 0, alloc }
|
||||
+ Self { ptr: Unique::dangling(), cap: Cap::ZERO, alloc }
|
||||
}
|
||||
|
||||
/// Like `with_capacity`, but parameterized over the choice of
|
||||
@@ -203,7 +218,7 @@ fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self {
|
||||
// here should change to `ptr.len() / mem::size_of::<T>()`.
|
||||
Self {
|
||||
ptr: unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) },
|
||||
- cap: capacity,
|
||||
+ cap: unsafe { Cap(capacity) },
|
||||
alloc,
|
||||
}
|
||||
}
|
||||
@@ -228,7 +243,7 @@ fn try_allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Result<Self, T
|
||||
// here should change to `ptr.len() / mem::size_of::<T>()`.
|
||||
Ok(Self {
|
||||
ptr: unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) },
|
||||
- cap: capacity,
|
||||
+ cap: unsafe { Cap(capacity) },
|
||||
alloc,
|
||||
})
|
||||
}
|
||||
@@ -240,12 +255,13 @@ fn try_allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Result<Self, T
|
||||
/// The `ptr` must be allocated (via the given allocator `alloc`), and with the given
|
||||
/// `capacity`.
|
||||
/// The `capacity` cannot exceed `isize::MAX` for sized types. (only a concern on 32-bit
|
||||
- /// systems). ZST vectors may have a capacity up to `usize::MAX`.
|
||||
+ /// systems). For ZSTs capacity is ignored.
|
||||
/// If the `ptr` and `capacity` come from a `RawVec` created via `alloc`, then this is
|
||||
/// guaranteed.
|
||||
#[inline]
|
||||
pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self {
|
||||
- Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc }
|
||||
+ let cap = if T::IS_ZST { Cap::ZERO } else { unsafe { Cap(capacity) } };
|
||||
+ Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap, alloc }
|
||||
}
|
||||
|
||||
/// Gets a raw pointer to the start of the allocation. Note that this is
|
||||
@@ -261,7 +277,7 @@ pub fn ptr(&self) -> *mut T {
|
||||
/// This will always be `usize::MAX` if `T` is zero-sized.
|
||||
#[inline(always)]
|
||||
pub fn capacity(&self) -> usize {
|
||||
- if T::IS_ZST { usize::MAX } else { self.cap }
|
||||
+ if T::IS_ZST { usize::MAX } else { self.cap.0 }
|
||||
}
|
||||
|
||||
/// Returns a shared reference to the allocator backing this `RawVec`.
|
||||
@@ -270,7 +286,7 @@ pub fn allocator(&self) -> &A {
|
||||
}
|
||||
|
||||
fn current_memory(&self) -> Option<(NonNull<u8>, Layout)> {
|
||||
- if T::IS_ZST || self.cap == 0 {
|
||||
+ if T::IS_ZST || self.cap.0 == 0 {
|
||||
None
|
||||
} else {
|
||||
// We could use Layout::array here which ensures the absence of isize and usize overflows
|
||||
@@ -280,7 +296,7 @@ fn current_memory(&self) -> Option<(NonNull<u8>, Layout)> {
|
||||
let _: () = const { assert!(mem::size_of::<T>() % mem::align_of::<T>() == 0) };
|
||||
unsafe {
|
||||
let align = mem::align_of::<T>();
|
||||
- let size = mem::size_of::<T>().unchecked_mul(self.cap);
|
||||
+ let size = mem::size_of::<T>().unchecked_mul(self.cap.0);
|
||||
let layout = Layout::from_size_align_unchecked(size, align);
|
||||
Some((self.ptr.cast().into(), layout))
|
||||
}
|
||||
@@ -404,12 +420,15 @@ fn needs_to_grow(&self, len: usize, additional: usize) -> bool {
|
||||
additional > self.capacity().wrapping_sub(len)
|
||||
}
|
||||
|
||||
- fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize) {
|
||||
+ /// # Safety:
|
||||
+ ///
|
||||
+ /// `cap` must not exceed `isize::MAX`.
|
||||
+ unsafe fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize) {
|
||||
// Allocators currently return a `NonNull<[u8]>` whose length matches
|
||||
// the size requested. If that ever changes, the capacity here should
|
||||
// change to `ptr.len() / mem::size_of::<T>()`.
|
||||
self.ptr = unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) };
|
||||
- self.cap = cap;
|
||||
+ self.cap = unsafe { Cap(cap) };
|
||||
}
|
||||
|
||||
// This method is usually instantiated many times. So we want it to be as
|
||||
@@ -434,14 +453,15 @@ fn grow_amortized(&mut self, len: usize, additional: usize) -> Result<(), TryRes
|
||||
|
||||
// This guarantees exponential growth. The doubling cannot overflow
|
||||
// because `cap <= isize::MAX` and the type of `cap` is `usize`.
|
||||
- let cap = cmp::max(self.cap * 2, required_cap);
|
||||
+ let cap = cmp::max(self.cap.0 * 2, required_cap);
|
||||
let cap = cmp::max(Self::MIN_NON_ZERO_CAP, cap);
|
||||
|
||||
let new_layout = Layout::array::<T>(cap);
|
||||
|
||||
// `finish_grow` is non-generic over `T`.
|
||||
let ptr = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?;
|
||||
- self.set_ptr_and_cap(ptr, cap);
|
||||
+ // SAFETY: finish_grow would have resulted in a capacity overflow if we tried to allocate more than isize::MAX items
|
||||
+ unsafe { self.set_ptr_and_cap(ptr, cap) };
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -460,7 +480,10 @@ fn grow_exact(&mut self, len: usize, additional: usize) -> Result<(), TryReserve
|
||||
|
||||
// `finish_grow` is non-generic over `T`.
|
||||
let ptr = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?;
|
||||
- self.set_ptr_and_cap(ptr, cap);
|
||||
+ // SAFETY: finish_grow would have resulted in a capacity overflow if we tried to allocate more than isize::MAX items
|
||||
+ unsafe {
|
||||
+ self.set_ptr_and_cap(ptr, cap);
|
||||
+ }
|
||||
Ok(())
|
||||
}
|
||||
|
||||
diff --git a/rust/alloc/vec/into_iter.rs b/rust/alloc/vec/into_iter.rs
|
||||
index aac0ec16aef1..136bfe94af6c 100644
|
||||
--- a/rust/alloc/vec/into_iter.rs
|
||||
+++ b/rust/alloc/vec/into_iter.rs
|
||||
@@ -9,7 +9,8 @@
|
||||
use core::array;
|
||||
use core::fmt;
|
||||
use core::iter::{
|
||||
- FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccessNoCoerce,
|
||||
+ FusedIterator, InPlaceIterable, SourceIter, TrustedFused, TrustedLen,
|
||||
+ TrustedRandomAccessNoCoerce,
|
||||
};
|
||||
use core::marker::PhantomData;
|
||||
use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties};
|
||||
@@ -287,9 +288,7 @@ unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> Self::Item
|
||||
// Also note the implementation of `Self: TrustedRandomAccess` requires
|
||||
// that `T: Copy` so reading elements from the buffer doesn't invalidate
|
||||
// them for `Drop`.
|
||||
- unsafe {
|
||||
- if T::IS_ZST { mem::zeroed() } else { ptr::read(self.ptr.add(i)) }
|
||||
- }
|
||||
+ unsafe { if T::IS_ZST { mem::zeroed() } else { ptr::read(self.ptr.add(i)) } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,6 +340,10 @@ fn is_empty(&self) -> bool {
|
||||
#[stable(feature = "fused", since = "1.26.0")]
|
||||
impl<T, A: Allocator> FusedIterator for IntoIter<T, A> {}
|
||||
|
||||
+#[doc(hidden)]
|
||||
+#[unstable(issue = "none", feature = "trusted_fused")]
|
||||
+unsafe impl<T, A: Allocator> TrustedFused for IntoIter<T, A> {}
|
||||
+
|
||||
#[unstable(feature = "trusted_len", issue = "37572")]
|
||||
unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A> {}
|
||||
|
||||
@@ -425,7 +428,10 @@ fn drop(&mut self) {
|
||||
// also refer to the vec::in_place_collect module documentation to get an overview
|
||||
#[unstable(issue = "none", feature = "inplace_iteration")]
|
||||
#[doc(hidden)]
|
||||
-unsafe impl<T, A: Allocator> InPlaceIterable for IntoIter<T, A> {}
|
||||
+unsafe impl<T, A: Allocator> InPlaceIterable for IntoIter<T, A> {
|
||||
+ const EXPAND_BY: Option<NonZeroUsize> = NonZeroUsize::new(1);
|
||||
+ const MERGE_BY: Option<NonZeroUsize> = NonZeroUsize::new(1);
|
||||
+}
|
||||
|
||||
#[unstable(issue = "none", feature = "inplace_iteration")]
|
||||
#[doc(hidden)]
|
||||
diff --git a/rust/alloc/vec/mod.rs b/rust/alloc/vec/mod.rs
|
||||
index 05c70de0227e..2534ec65500e 100644
|
||||
--- a/rust/alloc/vec/mod.rs
|
||||
+++ b/rust/alloc/vec/mod.rs
|
||||
@@ -105,6 +105,7 @@
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
use self::is_zero::IsZero;
|
||||
|
||||
+#[cfg(not(no_global_oom_handling))]
|
||||
mod is_zero;
|
||||
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
@@ -123,7 +124,7 @@
|
||||
mod set_len_on_drop;
|
||||
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
-use self::in_place_drop::{InPlaceDrop, InPlaceDstBufDrop};
|
||||
+use self::in_place_drop::{InPlaceDrop, InPlaceDstDataSrcBufDrop};
|
||||
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
mod in_place_drop;
|
||||
@@ -1837,7 +1838,32 @@ pub fn dedup_by<F>(&mut self, mut same_bucket: F)
|
||||
return;
|
||||
}
|
||||
|
||||
- /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */
|
||||
+ // Check if we ever want to remove anything.
|
||||
+ // This allows to use copy_non_overlapping in next cycle.
|
||||
+ // And avoids any memory writes if we don't need to remove anything.
|
||||
+ let mut first_duplicate_idx: usize = 1;
|
||||
+ let start = self.as_mut_ptr();
|
||||
+ while first_duplicate_idx != len {
|
||||
+ let found_duplicate = unsafe {
|
||||
+ // SAFETY: first_duplicate always in range [1..len)
|
||||
+ // Note that we start iteration from 1 so we never overflow.
|
||||
+ let prev = start.add(first_duplicate_idx.wrapping_sub(1));
|
||||
+ let current = start.add(first_duplicate_idx);
|
||||
+ // We explicitly say in docs that references are reversed.
|
||||
+ same_bucket(&mut *current, &mut *prev)
|
||||
+ };
|
||||
+ if found_duplicate {
|
||||
+ break;
|
||||
+ }
|
||||
+ first_duplicate_idx += 1;
|
||||
+ }
|
||||
+ // Don't need to remove anything.
|
||||
+ // We cannot get bigger than len.
|
||||
+ if first_duplicate_idx == len {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ /* INVARIANT: vec.len() > read > write > write-1 >= 0 */
|
||||
struct FillGapOnDrop<'a, T, A: core::alloc::Allocator> {
|
||||
/* Offset of the element we want to check if it is duplicate */
|
||||
read: usize,
|
||||
@@ -1883,31 +1909,39 @@ fn drop(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
- let mut gap = FillGapOnDrop { read: 1, write: 1, vec: self };
|
||||
- let ptr = gap.vec.as_mut_ptr();
|
||||
-
|
||||
/* Drop items while going through Vec, it should be more efficient than
|
||||
* doing slice partition_dedup + truncate */
|
||||
|
||||
+ // Construct gap first and then drop item to avoid memory corruption if `T::drop` panics.
|
||||
+ let mut gap =
|
||||
+ FillGapOnDrop { read: first_duplicate_idx + 1, write: first_duplicate_idx, vec: self };
|
||||
+ unsafe {
|
||||
+ // SAFETY: we checked that first_duplicate_idx in bounds before.
|
||||
+ // If drop panics, `gap` would remove this item without drop.
|
||||
+ ptr::drop_in_place(start.add(first_duplicate_idx));
|
||||
+ }
|
||||
+
|
||||
/* SAFETY: Because of the invariant, read_ptr, prev_ptr and write_ptr
|
||||
* are always in-bounds and read_ptr never aliases prev_ptr */
|
||||
unsafe {
|
||||
while gap.read < len {
|
||||
- let read_ptr = ptr.add(gap.read);
|
||||
- let prev_ptr = ptr.add(gap.write.wrapping_sub(1));
|
||||
+ let read_ptr = start.add(gap.read);
|
||||
+ let prev_ptr = start.add(gap.write.wrapping_sub(1));
|
||||
|
||||
- if same_bucket(&mut *read_ptr, &mut *prev_ptr) {
|
||||
+ // We explicitly say in docs that references are reversed.
|
||||
+ let found_duplicate = same_bucket(&mut *read_ptr, &mut *prev_ptr);
|
||||
+ if found_duplicate {
|
||||
// Increase `gap.read` now since the drop may panic.
|
||||
gap.read += 1;
|
||||
/* We have found duplicate, drop it in-place */
|
||||
ptr::drop_in_place(read_ptr);
|
||||
} else {
|
||||
- let write_ptr = ptr.add(gap.write);
|
||||
+ let write_ptr = start.add(gap.write);
|
||||
|
||||
- /* Because `read_ptr` can be equal to `write_ptr`, we either
|
||||
- * have to use `copy` or conditional `copy_nonoverlapping`.
|
||||
- * Looks like the first option is faster. */
|
||||
- ptr::copy(read_ptr, write_ptr, 1);
|
||||
+ /* read_ptr cannot be equal to write_ptr because at this point
|
||||
+ * we guaranteed to skip at least one element (before loop starts).
|
||||
+ */
|
||||
+ ptr::copy_nonoverlapping(read_ptr, write_ptr, 1);
|
||||
|
||||
/* We have filled that place, so go further */
|
||||
gap.write += 1;
|
||||
@@ -2802,6 +2836,7 @@ pub fn from_elem_in<T: Clone, A: Allocator>(elem: T, n: usize, alloc: A) -> Vec<
|
||||
<T as SpecFromElem>::from_elem(elem, n, alloc)
|
||||
}
|
||||
|
||||
+#[cfg(not(no_global_oom_handling))]
|
||||
trait ExtendFromWithinSpec {
|
||||
/// # Safety
|
||||
///
|
||||
@@ -2810,6 +2845,7 @@ trait ExtendFromWithinSpec {
|
||||
unsafe fn spec_extend_from_within(&mut self, src: Range<usize>);
|
||||
}
|
||||
|
||||
+#[cfg(not(no_global_oom_handling))]
|
||||
impl<T: Clone, A: Allocator> ExtendFromWithinSpec for Vec<T, A> {
|
||||
default unsafe fn spec_extend_from_within(&mut self, src: Range<usize>) {
|
||||
// SAFETY:
|
||||
@@ -2829,6 +2865,7 @@ impl<T: Clone, A: Allocator> ExtendFromWithinSpec for Vec<T, A> {
|
||||
}
|
||||
}
|
||||
|
||||
+#[cfg(not(no_global_oom_handling))]
|
||||
impl<T: Copy, A: Allocator> ExtendFromWithinSpec for Vec<T, A> {
|
||||
unsafe fn spec_extend_from_within(&mut self, src: Range<usize>) {
|
||||
let count = src.len();
|
||||
@@ -2909,7 +2946,7 @@ fn clone_from(&mut self, other: &Self) {
|
||||
/// ```
|
||||
/// use std::hash::BuildHasher;
|
||||
///
|
||||
-/// let b = std::collections::hash_map::RandomState::new();
|
||||
+/// let b = std::hash::RandomState::new();
|
||||
/// let v: Vec<u8> = vec![0xa8, 0x3c, 0x09];
|
||||
/// let s: &[u8] = &[0xa8, 0x3c, 0x09];
|
||||
/// assert_eq!(b.hash_one(v), b.hash_one(s));
|
||||
Reference in New Issue
Block a user