scudo/
lib.rs

1// Copyright 2025 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5mod raw_api {
6    extern "C" {
7        /// Adjusts parameters or performs specific maintenance operations on the memory
8        /// allocator. Returns 1 on success, 0 on error.
9        pub fn mallopt(
10            param: std::os::raw::c_int,
11            value: std::os::raw::c_int,
12        ) -> std::os::raw::c_int;
13    }
14}
15
16// mallopt() option to set the minimum time between attempts to release unused pages to
17// to the operating system in milliseconds. The value is clamped on allocator config
18// `MinReleaseToOsIntervalMs` and `MinReleaseToOsIntervalMs`.
19pub const M_DECAY_TIME: i32 = -100;
20
21// mallopt() option to immediately purge any memory not in use. This will release the memory back
22// to the kernel. The value is ignored.
23pub const M_PURGE: i32 = -101;
24
25// mallopt() option to immediately purge all possible memory back to the kernel. This call can take
26// longer than a normal purge since it examines everything. In some cases, it can take more than
27// twice the time of a M_PURGE call. The value is ignored.
28pub const M_PURGE_ALL: i32 = -104;
29
30/// mallopt() option to set the minimum time between attempts to release unused pages to
31/// the operating system in milliseconds. The value is clamped on allocator config
32/// `MinReleaseToOsIntervalMs` and `MinReleaseToOsIntervalMs`.
33pub fn mallopt(param: i32, value: i32) -> Result<(), ()> {
34    let result = unsafe { raw_api::mallopt(param, value) };
35    if result == 1 {
36        Ok(())
37    } else {
38        Err(())
39    }
40}