Conversation
* man page says: "If MREMAP_FIXED is specified, then MREMAP_MAYMOVE must also be specified. So, new_address is used if "flags | MREMAP_FIXED", not just "flags == MREMAP_FIXED".
|
Warning Rate limit exceeded@gc00 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 50 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (3)
WalkthroughRestyles parameter wrapping and comment text in Changes
Sequence Diagram(s)sequenceDiagram
participant App as Caller
participant Wrap as mmapwrappers.cpp
participant Real as _real_mremap
rect rgb(250,250,250)
note right of Wrap: Updated behavior — treat MREMAP_FIXED as a bitwise flag
App->>Wrap: mremap(old_addr, old_len, new_len, flags[, new_addr])
alt flags & MREMAP_FIXED
Wrap->>Real: _real_mremap(..., new_addr)
else
Wrap->>Real: _real_mremap(...)
end
Real-->>Wrap: result (addr or MAP_FAILED)
Wrap-->>App: return result
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
test/mremap.c (1)
1-24: Test logic is sound; consider small robustness/portability tweaksThe loop correctly exercises
mremapwithMREMAP_MAYMOVE | MREMAP_FIXEDand verifies that the mapping ends up atold_addr2, which should catch the wrapper bug.Two non‑blocking suggestions to make the test more robust:
Use runtime page size instead of hard‑coding 4096. On systems with a different page size,
munmap(old_addr2, 4096)can fail and leaveold_addr2still mapped, making themremapprecondition false. Usinggetpagesize()(already available via<unistd.h>) avoids this:int main() { size_t page_size = (size_t)getpagesize(); void *old_addr1, *old_addr2, *new_addr; for (;;) { old_addr1 = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); assert(old_addr1 != MAP_FAILED); old_addr2 = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); assert(old_addr2 != MAP_FAILED); assert(munmap(old_addr2, page_size) == 0); new_addr = mremap(old_addr1, page_size, page_size, MREMAP_MAYMOVE | MREMAP_FIXED, old_addr2); assert(new_addr == old_addr2); assert(munmap(old_addr2, page_size) == 0); sleep(1); } }Add basic
mmap/munmaperror checks. As above, simpleassertchecks give clearer failures if the environment is misconfigured, rather than letting later calls behave unexpectedly.If you want to keep the test minimal, even just switching to
getpagesize()would address the main portability concern.src/mtcp/mtcp_restart.c (1)
971-995: Comment update abovemremap_moveis accurate; optional spelling nitThe added note that
MREMAP_MAYMOVEis required when usingMREMAP_FIXEDis correct and aligns with howmremap_moveinvokesmtcp_sys_mremap.Minor nit (optional): in the comment, “desgination” could be corrected to “destination” for clarity:
// the memory was moved to the wrong destination. Undo the move, and return -1.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/mtcp/mtcp_restart.c(3 hunks)src/plugin/alloc/mmapwrappers.cpp(1 hunks)test/autotest.py(1 hunks)test/mremap.c(1 hunks)
🧰 Additional context used
🪛 Clang (14.0.6)
test/mremap.c
[error] 2-2: 'assert.h' file not found
(clang-diagnostic-error)
⏰ 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: build
🔇 Additional comments (3)
test/autotest.py (1)
898-901: Newmremapautotest wiring looks consistentThe added
runTest("mremap", 1, ["./test/mremap"])matches existing patterns (name, arg count, path) and being placed right aftermmap1makes sense logically. No issues from the harness side.src/plugin/alloc/mmapwrappers.cpp (1)
56-71: Bitwise check forMREMAP_FIXEDcorrectly fixes mixed‑flag usageSwitching to
if (flags & MREMAP_FIXED)ensures the wrapper handles cases likeMREMAP_MAYMOVE | MREMAP_FIXEDand still pullsnew_addressfrom varargs, matching the kernel/glibc contract. The 4‑arg vs 5‑arg calls to_real_mremapremain consistent with the original ABI.src/mtcp/mtcp_restart.c (1)
650-683: Refactoring/formatting aroundrestore_vdso_vvar_workis harmlessSignature wrapping and the corresponding call for
[vvar_vclock]are purely cosmetic; they don't alter arguments or control flow. The vdso/vvar handling logic remains intact.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
test/mremap.c (2)
11-15: Consider adding error handling for mmap and munmap calls.While test programs may have relaxed error handling, adding checks for
MAP_FAILEDon mmap calls and return value checks on munmap would make test failures more explicit and easier to debug.Example:
old_addr1 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + assert(old_addr1 != MAP_FAILED); old_addr2 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + assert(old_addr2 != MAP_FAILED); - munmap(old_addr2, PAGE_SIZE); + assert(munmap(old_addr2, PAGE_SIZE) == 0);
20-21: Consider checking munmap return value for consistency.Similar to Line 15, checking the return value of this munmap call would maintain consistency with error handling suggestions.
- munmap(old_addr2, PAGE_SIZE); + assert(munmap(old_addr2, PAGE_SIZE) == 0);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/mtcp/mtcp_restart.c(3 hunks)test/autotest.py(1 hunks)test/mremap.c(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- test/autotest.py
🧰 Additional context used
🪛 Clang (14.0.6)
test/mremap.c
[error] 2-2: 'assert.h' file not found
(clang-diagnostic-error)
⏰ 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: build
🔇 Additional comments (5)
test/mremap.c (2)
2-2: Static analysis error is a false positive.The Clang error about 'assert.h' not found is a false positive—this is a standard C header and will be available in the build environment.
17-19: LGTM! Core test logic correctly exercises MREMAP_FIXED.The test correctly uses
MREMAP_MAYMOVE | MREMAP_FIXEDtogether, which aligns with the PR objective to fix the mremap wrapper to handle MREMAP_FIXED as a bitwise flag. The assertion will properly catch any mremap failures (which would returnMAP_FAILED).src/mtcp/mtcp_restart.c (3)
650-651: LGTM! Formatting improvement.The parameter wrapping improves readability of the function signature.
681-682: LGTM! Consistent formatting.The function call wrapping is consistent with the declaration formatting and improves readability.
972-974: LGTM! Documentation improvement aligns with PR objective.The comment clarification that
MREMAP_MAYMOVEis required when usingMREMAP_FIXEDdirectly supports the PR's objective to fix mremap wrapper handling of these flags.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/mtcp/mtcp_restart.c(4 hunks)test/autotest.py(1 hunks)test/mremap.c(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- test/autotest.py
🧰 Additional context used
🪛 Clang (14.0.6)
test/mremap.c
[error] 2-2: 'assert.h' file not found
(clang-diagnostic-error)
⏰ 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: build
🔇 Additional comments (4)
src/mtcp/mtcp_restart.c (4)
650-651: LGTM!The function signature wrapping improves readability with no functional changes.
681-682: LGTM!The function call wrapping maintains consistency with the signature formatting.
972-974: LGTM!The comment clarification accurately documents the requirement that
MREMAP_MAYMOVEmust be specified when usingMREMAP_FIXED, which aligns with the PR objectives.
992-992: LGTM!The comment wording improvement enhances clarity.
test/mremap.c
Outdated
| old_addr1 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, | ||
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
| old_addr2 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, | ||
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
There was a problem hiding this comment.
Add error checking for mmap calls.
Both mmap calls should verify that the returned address is not MAP_FAILED before proceeding.
Apply this diff:
old_addr1 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ assert(old_addr1 != MAP_FAILED);
old_addr2 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ assert(old_addr2 != MAP_FAILED);📝 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.
| old_addr1 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, | |
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
| old_addr2 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, | |
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
| old_addr1 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, | |
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
| assert(old_addr1 != MAP_FAILED); | |
| old_addr2 = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, | |
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
| assert(old_addr2 != MAP_FAILED); |
🤖 Prompt for AI Agents
In test/mremap.c around lines 11 to 14, the two mmap() calls currently assume
success; add checks that the returned pointers are not MAP_FAILED and handle
errors if they are: after each mmap, test (old_addr1 == MAP_FAILED) and
(old_addr2 == MAP_FAILED), call perror("mmap") or fprintf(stderr, ...) to report
the failure and exit with a non-zero status (or return an error) so the test
does not continue with invalid addresses; ensure any already-mapped region is
munmap'ed before exiting if appropriate.
flags | MREMAP_FIXED, not justflags == MREMAP_FIXEDas before.Summary by CodeRabbit
Bug Fixes
Tests
Style