Skip to content

Conversation

watchgou
Copy link
Contributor

@watchgou watchgou commented Sep 16, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #issue_id

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Bug Fixes
    • Improved UNIX platform compatibility and stability for low-level memory residency checks, reducing potential crashes or undefined behavior under certain conditions.
    • No changes expected to app behavior; Windows unaffected.
    • Enhances reliability and consistency of resource usage reporting on UNIX systems.
    • No configuration or user action required. No public APIs changed.

Copy link
Contributor

coderabbitai bot commented Sep 16, 2025

Walkthrough

Switched UNIX-side FFI binding for mincore from using libc c_uchar pointers to c_char pointers, updating the cast of the residency vector accordingly. Function signatures and Windows-specific code remain unchanged; no public API changes reported.

Changes

Cohort / File(s) Summary
UNIX FFI pointer type update
rocketmq-store/src/utils/ffi.rs
In the UNIX branch, changed pointer type in mincore call from *mut c_uchar to *mut c_char and adjusted cast. Windows branch unchanged. No public API signature changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my ears at FFI night,
From uchar to char—just set it right.
No Windows stir, no public fright,
A tiny hop, a pointer’s bite.
Now mincore maps are snug and tight—
Thump-thump! Onward to the next byte. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Syscall parameter type" accurately and concisely describes the primary change in the diff, which adjusts the parameter/pointer type used for the mincore syscall on Unix (c_uchar -> c_char); it is directly related to the main change and avoids extraneous detail.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@watchgou 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rocketmq-store/src/utils/ffi.rs (1)

91-99: Make vec a *mut u8 and use libc::c_uchar — avoid const-to-mutable cast (soundness + Clippy).

Repo scan: only a commented call found at rocketmq-store/src/log_file/mapped_file/default_mapped_file_impl.rs:758; no active callers.

- pub fn mincore(addr: *const u8, len: usize, vec: *const u8) -> i32 {
+ pub fn mincore(addr: *const u8, len: usize, vec: *mut u8) -> i32 {
     #[cfg(unix)]
     {
         use std::ffi::c_void;
-        use libc::c_char;
-        unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_char) }
+        use libc::c_uchar;
+        unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_uchar) }
     }
🧹 Nitpick comments (2)
rocketmq-store/src/utils/ffi.rs (2)

100-104: Windows stub currently returns success; consider signaling “not supported.”

Returning 0 may be interpreted as success by callers. Consider -1 (and documenting this) or gating call sites on cfg(unix) so Windows never calls this path.

Minimal change:

-        // Windows does not have mincore, so we just return 0
-        0
+        // Windows does not have mincore; signal unsupported
+        -1

Please confirm no Windows call sites rely on the current behavior.


45-50: Comment mismatch with behavior on Windows mlock/munlock.

Comments say “just return Ok” but the code calls VirtualLock/VirtualUnlock and can error. Update comments for accuracy.

-        // Windows does not have mlock, so we just return Ok
+        // Windows does not have mlock; use VirtualLock and map errors
...
-        // Windows does not have munlock, so we just return Ok
+        // Windows does not have munlock; use VirtualUnlock and map errors

Also applies to: 71-75

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c4201c and eff1404.

📒 Files selected for processing (1)
  • rocketmq-store/src/utils/ffi.rs (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: CI
rocketmq-store/src/utils/ffi.rs

[error] 98-98: Command cargo clippy -- -D warnings failed due to compile error: mismatched types in FFI call to libc::mincore. The function expects vec: *mut c_uchar, but vec is passed as *mut c_char in rocketmq-store/src/utils/ffi.rs:98 (E0308).

🪛 GitHub Actions: Codecov
rocketmq-store/src/utils/ffi.rs

[error] 98-98: Rust compile error: mismatched types in mincore call. expected *mut u8, found *mut i8 for vec parameter in unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_char) } at rocketmq-store/src/utils/ffi.rs:98.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: auto-approve

Comment on lines +96 to 99
use libc::c_char;

unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_uchar) }
unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_char) }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix FFI type for mincore vec: use c_uchar, not c_char (compile error E0308).

libc::mincore expects vec: *mut c_uchar (aka *mut u8). Passing *mut c_char (*mut i8) causes the current CI failure.

Apply this diff:

-        use libc::c_char;
+        use libc::c_uchar;

-        unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_char) }
+        unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_uchar) }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use libc::c_char;
unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_uchar) }
unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_char) }
}
use libc::c_uchar;
unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_uchar) }
}
🧰 Tools
🪛 GitHub Actions: CI

[error] 98-98: Command cargo clippy -- -D warnings failed due to compile error: mismatched types in FFI call to libc::mincore. The function expects vec: *mut c_uchar, but vec is passed as *mut c_char in rocketmq-store/src/utils/ffi.rs:98 (E0308).

🪛 GitHub Actions: Codecov

[error] 98-98: Rust compile error: mismatched types in mincore call. expected *mut u8, found *mut i8 for vec parameter in unsafe { libc::mincore(addr as *mut c_void, len, vec as *mut c_char) } at rocketmq-store/src/utils/ffi.rs:98.

🤖 Prompt for AI Agents
In rocketmq-store/src/utils/ffi.rs around lines 96 to 99, the FFI call to
libc::mincore uses a pointer typed as *mut c_char which is incorrect and causes
E0308; change the type to *mut c_uchar (and import/use libc::c_uchar if not
already) and cast vec to that pointer when calling mincore so the third
parameter matches libc::mincore's expected *mut c_uchar.

@watchgou watchgou closed this Sep 16, 2025
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Sep 16, 2025
@watchgou watchgou deleted the syscall-parameter-type branch September 16, 2025 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI review first Ai review pr first approved PR has approved auto merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants