1 // Copyright 2024, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! Low-level stack support.
16 
17 /// Configures the maximum size of the stack.
18 #[macro_export]
19 macro_rules! limit_stack_size {
20     ($len:expr) => {
21         #[export_name = "vmbase_stack_limit_client"]
22         fn __vmbase_stack_limit_client() -> Option<usize> {
23             Some($len)
24         }
25     };
26 }
27 
max_stack_size() -> Option<usize>28 pub(crate) fn max_stack_size() -> Option<usize> {
29     extern "Rust" {
30         fn vmbase_stack_limit() -> Option<usize>;
31     }
32     // SAFETY: This function is safe to call as the linker script aliases it to either:
33     // - the safe vmbase_stack_limit_default();
34     // - the safe vmbase_stack_limit_client() potentially defined using limit_stack_size!()
35     unsafe { vmbase_stack_limit() }
36 }
37 
38 #[no_mangle]
vmbase_stack_limit_default() -> Option<usize>39 fn vmbase_stack_limit_default() -> Option<usize> {
40     None
41 }
42