Skip to main content

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::{IcmpPingGidsLock, LockDepMutex};
8use std::ops::Range;
9use std::sync::atomic::{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: LockDepMutex<Range<u32>, IcmpPingGidsLock>,
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
47impl Default for SystemLimits {
48    fn default() -> SystemLimits {
49        SystemLimits {
50            inotify: InotifyLimits {
51                max_queued_events: AtomicI32::new(16384),
52                max_user_instances: AtomicI32::new(128),
53                max_user_watches: AtomicI32::new(1048576),
54            },
55            socket: SocketLimits {
56                max_connections: AtomicI32::new(4096),
57                icmp_ping_gids: LockDepMutex::new(1..1),
58            },
59            pipe_max_size: AtomicUsize::new((*PAGE_SIZE * 256) as usize),
60            io_uring_disabled: AtomicI32::new(0),
61            io_uring_group: AtomicI32::new(-1),
62        }
63    }
64}