starnix_core/task/limits.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
5use crate::mm::PAGE_SIZE;
6use crate::vfs::inotify::InotifyLimits;
7use starnix_sync::Mutex;
8use std::ops::Range;
9use std::sync::atomic::{AtomicBool, AtomicI32, AtomicUsize};
10
11#[derive(Default, Debug)]
12pub struct SocketLimits {
13 /// The maximum backlog size for a socket.
14 pub max_connections: AtomicI32,
15
16 // Range of GIDs that can create ICMP Ping sockets.
17 pub icmp_ping_gids: Mutex<Range<u32>>,
18}
19
20#[derive(Debug)]
21pub struct SystemLimits {
22 /// Limits applied to inotify objects.
23 pub inotify: InotifyLimits,
24
25 /// Limits applied to socket objects.
26 pub socket: SocketLimits,
27
28 /// The maximum size of pipes in the system.
29 pub pipe_max_size: AtomicUsize,
30
31 /// Whether IoUring is disabled.
32 ///
33 /// 0 -> io_uring is enabled (default)
34 /// 1 -> io_uring is enabled for processes in the io_uring_group
35 /// 2 -> io_uring is disabled
36 ///
37 /// See https://docs.kernel.org/admin-guide/sysctl/kernel.html#io-uring-disabled
38 pub io_uring_disabled: AtomicI32,
39
40 /// If io_uring_disabled is 1, then io_uring is enabled only for processes with CAP_SYS_ADMIN
41 /// or that are members of this group.
42 ///
43 /// See https://docs.kernel.org/admin-guide/sysctl/kernel.html#io-uring-group
44 pub io_uring_group: AtomicI32,
45
46 /// Whether or not the minimum power mode of the device is enabled.
47 ///
48 /// This is a transitional flag that does not exist on Linux.
49 pub force_lowest_power_mode: AtomicBool,
50}
51
52impl Default for SystemLimits {
53 fn default() -> SystemLimits {
54 SystemLimits {
55 inotify: InotifyLimits {
56 max_queued_events: AtomicI32::new(16384),
57 max_user_instances: AtomicI32::new(128),
58 max_user_watches: AtomicI32::new(1048576),
59 },
60 socket: SocketLimits {
61 max_connections: AtomicI32::new(4096),
62 icmp_ping_gids: Mutex::new(1..1),
63 },
64 pipe_max_size: AtomicUsize::new((*PAGE_SIZE * 256) as usize),
65 io_uring_disabled: AtomicI32::new(0),
66 io_uring_group: AtomicI32::new(-1),
67 force_lowest_power_mode: false.into(),
68 }
69 }
70}