Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion os/StarryOS/kernel/src/mm/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl ElfCacheEntry {
fn load(loc: Location) -> AxResult<Result<Self, Vec<u8>>> {
let cache = CachedFile::get_or_create(loc)?;

let mut data = vec![0; 4096];
let mut data = vec![0; PAGE_SIZE_4K];
let read = cache.read_at(&mut data[..], 0)?;
data.truncate(read);
match ElfCacheEntry::try_new_or_recover::<AxError>(cache.clone(), data, |data| {
Expand Down
4 changes: 2 additions & 2 deletions os/StarryOS/kernel/src/pseudofs/dev/card0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use super::drm::{
DRM_IOCTL_PRIME_HANDLE_TO_FD, DRM_IOCTL_SET_CLIENT_CAP, DRM_IOCTL_SET_MASTER,
DRM_IOCTL_SET_VERSION, DRM_IOCTL_VERSION, DRM_IOCTL_WAIT_VBLANK, DRM_MODE_ATOMIC_ALLOW_MODESET,
DRM_MODE_ATOMIC_NONBLOCK, DRM_MODE_ATOMIC_TEST_ONLY, DRM_MODE_CONNECTED,
DRM_MODE_CONNECTOR_VIRTUAL, DRM_MODE_ENCODER_VIRTUAL, DRM_MODE_FB_MODIFIERS,
DRM_MODE_CONNECTOR_VIRTUAL, DRM_MODE_ENCODER_VIRTUAL, DRM_MODE_FB_MODIFIERS, DRM_MODE_NAME_LEN,
DRM_MODE_OBJECT_CONNECTOR, DRM_MODE_OBJECT_CRTC, DRM_MODE_OBJECT_PLANE,
DRM_MODE_PAGE_FLIP_EVENT, DRM_MODE_PROP_ATOMIC, DRM_MODE_PROP_BLOB, DRM_MODE_PROP_ENUM,
DRM_MODE_PROP_IMMUTABLE, DRM_MODE_PROP_OBJECT, DRM_MODE_PROP_RANGE, DRM_PLANE_TYPE_PRIMARY,
Expand Down Expand Up @@ -508,7 +508,7 @@ const DEFAULT_VREFRESH: u32 = 60;
/// Synthesized mode matching the display's current resolution.
fn current_mode() -> DrmModeModeInfo {
let (w, h) = display_resolution();
let mut name = [0u8; 32];
let mut name = [0u8; DRM_MODE_NAME_LEN];
let s = b"current";
name[..s.len()].copy_from_slice(s);

Expand Down
3 changes: 2 additions & 1 deletion os/StarryOS/kernel/src/pseudofs/dev/card1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ impl DeviceOps for Card1 {
}

_ => {
panic!("card1: unsupported ioctl nr {nr:#x}");
warn!("card1: unsupported ioctl nr {nr:#x}");
return Err(VfsError::OperationNotSupported);
}
}
copy_to_user(arg as _, stack_data.as_mut_ptr(), out_size)?;
Expand Down
11 changes: 8 additions & 3 deletions os/StarryOS/kernel/src/pseudofs/dev/loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ use crate::{
pseudofs::{DeviceMmap, DeviceOps},
};

/// Default read-ahead sector count for loop devices (matches Linux).
const LOOP_DEFAULT_RA: u32 = 512;
/// Maximum length of the backing-file path attached to a loop device.
const LOOP_NAME_SIZE: usize = 64;

/// HDIO_GETGEO ioctl command (get drive geometry).
/// Not defined in linux-raw-sys, so we use the standard value directly.
const HDIO_GETGEO: u32 = 0x0301;
Expand Down Expand Up @@ -60,8 +65,8 @@ impl LoopDevice {
dev_id,
file: Mutex::new(None),
ro: AtomicBool::new(false),
ra: AtomicU32::new(512),
file_name: Mutex::new([0u8; 64]),
ra: AtomicU32::new(LOOP_DEFAULT_RA),
file_name: Mutex::new([0u8; LOOP_NAME_SIZE]),
flags: AtomicU32::new(0),
exclusive: AtomicBool::new(false),
#[cfg(feature = "ext4")]
Expand Down Expand Up @@ -194,7 +199,7 @@ impl DeviceOps for LoopDevice {
self.detach_block_cache(guard.as_ref())?;

*guard = None;
*self.file_name.lock() = [0u8; 64];
*self.file_name.lock() = [0u8; LOOP_NAME_SIZE];
self.flags.store(0, Ordering::Relaxed);
}
LOOP_GET_STATUS => {
Expand Down
13 changes: 9 additions & 4 deletions os/StarryOS/kernel/src/pseudofs/dev/memtrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ use crate::{
};

static STAMPED_GENERATION: AtomicU64 = AtomicU64::new(0);

/// Buffer size for recording stack-based allocation samples.
const SAMPLE_ALLOC_BUF_SIZE: usize = 4096;
/// Buffer size for deeper call-stack allocation samples.
const SAMPLE_HARD_LEAF_BUF_SIZE: usize = 8192;
static SAMPLE_ALLOCATION: SpinNoIrq<Option<Vec<u8>>> = SpinNoIrq::new(None);

#[derive(PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -79,17 +84,17 @@ fn run_memory_analysis() {

#[inline(never)]
fn record_sample_allocation() {
let mut sample = Vec::with_capacity(4096);
sample.resize(4096, 0xa5);
let mut sample = Vec::with_capacity(SAMPLE_ALLOC_BUF_SIZE);
sample.resize(SAMPLE_ALLOC_BUF_SIZE, 0xa5);
*SAMPLE_ALLOCATION.lock() = Some(sample);
ax_println!("Memory allocation sample recorded");
}

#[unsafe(no_mangle)]
#[inline(never)]
fn starry_memtrack_sample_hard_leaf() -> Vec<u8> {
let mut sample = Vec::with_capacity(8192);
sample.resize(8192, 0x5a);
let mut sample = Vec::with_capacity(SAMPLE_HARD_LEAF_BUF_SIZE);
sample.resize(SAMPLE_HARD_LEAF_BUF_SIZE, 0x5a);
core::hint::black_box(sample.as_ptr());
sample
}
Expand Down
5 changes: 4 additions & 1 deletion os/StarryOS/kernel/src/pseudofs/dev/tty/terminal/ldisc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,10 @@ impl<R: TtyRead, W: TtyWrite> LineDiscipline<R, W> {
} else {
let vtime = term.special_char(VTIME);
if vtime > 0 {
todo!();
// VTIME inter-byte / read-interval timer not yet
// implemented. Reads proceed as if VTIME=0, which is
// a best-effort approximation that avoids blocking
// forever when the timer would have expired.
}
term.special_char(VMIN) as usize
};
Expand Down
13 changes: 9 additions & 4 deletions os/StarryOS/kernel/src/pseudofs/tmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use axpoll::{IoEvents, Pollable};
use hashbrown::HashMap;
use slab::Slab;

/// StatFs total block count reported for tmpfs (~4 GiB at 4096-byte blocks).
const TMPFS_REPORTED_BLOCKS: u64 = 1 << 20;
/// StatFs free inode count reported for tmpfs.
const TMPFS_REPORTED_FREE_INODES: u64 = 1 << 16;

const TMPFS_NESTED_DIR_ENTRIES_SUBCLASS: u32 = 1;

fn fs_events_to_io(events: FsIoEvents) -> IoEvents {
Expand Down Expand Up @@ -154,11 +159,11 @@ impl FilesystemOps for MemoryFs {
Ok(StatFs {
fs_type: 0x01021994,
block_size: 4096,
blocks: 1 << 20,
blocks_free: 1 << 20,
blocks_available: 1 << 20,
blocks: TMPFS_REPORTED_BLOCKS,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议更新 PR body 中的常量名称描述,使其与实际代码一致:

  • DRM_FB_NUM_PLANES(=32) → 实际为 DRM_MODE_NAME_LEN(从 drm.rs 导入)
  • LO_SECTOR_SIZE(512) / LO_MAX_SEGMENTS(64) → 实际为 LOOP_DEFAULT_RA / LOOP_NAME_SIZE
  • SAMPLE_TOTAL_BYTES(72) / SAMPLE_PADDING(24) → 实际为 SAMPLE_ALLOC_BUF_SIZE(4096) / SAMPLE_HARD_LEAF_BUF_SIZE(8192)
  • STATFS_FRSIZE/STATFS_BLOCKS/STATFS_BSIZE → 实际为 TMPFS_REPORTED_BLOCKS / TMPFS_REPORTED_FREE_INODES

这可能是合并前旧 PR 的描述未更新导致的。

blocks_free: TMPFS_REPORTED_BLOCKS,
blocks_available: TMPFS_REPORTED_BLOCKS,
file_count: 0,
free_file_count: 1 << 16,
free_file_count: TMPFS_REPORTED_FREE_INODES,
name_length: axfs_ng_vfs::path::MAX_NAME_LEN as _,
fragment_size: 4096,
mount_flags: 0,
Expand Down
7 changes: 5 additions & 2 deletions os/StarryOS/kernel/src/syscall/fs/ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ use crate::{
time::TimeValueLike,
};

/// Maximum length of tracepoint path buffers (matches Linux TRACE_PATH_MAX).
const TRACE_PATH_BUF_SIZE: usize = 64;

/// `FIOCLEX` / `FIONCLEX`: set / clear the close-on-exec flag on a file descriptor
/// via `ioctl` (the ioctl spelling of `fcntl(fd, F_SETFD, ...)`). libc/musl and CPython
/// use these on freshly-opened fds; Linux implements them generically for any fd.
Expand Down Expand Up @@ -131,12 +134,12 @@ ktracepoint::define_event_trace!(
TP_PROTO(path:&str, mode: u16),
TP_STRUCT__entry {
mode: u16,
path: [u8;64],
path: [u8; TRACE_PATH_BUF_SIZE],
},
TP_fast_assign {
mode: mode,
path: {
let mut buf = [0u8; 64];
let mut buf = [0u8; TRACE_PATH_BUF_SIZE];
let bytes = path.as_bytes();
let mut len = bytes.len().min(63);
while !path.is_char_boundary(len) {
Expand Down