Skip to content

Correctly handle return value of libc::mmap in fs_calls.rs #451

@qianxichen233

Description

@qianxichen233

The function libc::mmap returns a 64-bit address, which is directly used by several memory-related functions (e.g., shmat, mmap, etc.). However, when libc::mmap fails, its return value is not properly distinguished from a valid address.

Currently, the failure return value is treated as a regular u64 address. Since libc::mmap returns an error code in the same value space, this can lead to incorrect handling (e.g., interpreting an error code as a valid 64-bit address), which causes incorrect behavior or crashes.

We can adopt the same approach used in glibc/lind_syscall/lind_syscall.c to treat any return value that is not page-aligned as errno.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions