-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: test case ut_lind_fs_getdents
#74
Conversation
src/tests/fs_tests.rs
Outdated
|
||
unsafe { | ||
let first_dirent = baseptr as *mut interface::ClippedDirent; | ||
assert!((*first_dirent).d_off == 24); | ||
let reclen_matched: bool = ((*first_dirent).d_reclen == 24); | ||
// Copy packed fields into local variables to avoid alignment issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain more what this is doing? What alignment? Do you mean word, etc. alignment? Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a byte alignment issue, the fields in the packed structure (ClippedDirent) are tightly packed without the usual padding that would align them on word boundaries (like 4 or 8 bytes). Because of this, directly accessing these fields cause problems on some systems that expect memory to be accessed in larger chunks (like words).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this in the comment in more detail? Once this happens, I'll approve
@@ -2540,6 +2552,7 @@ pub mod fs_tests { | |||
assert_eq!(cage.exit_syscall(libc::EXIT_SUCCESS), libc::EXIT_SUCCESS); | |||
lindrustfinalize(); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I added a new line between the 2 test functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worked with Qianxi on testing getdents
before, and we encountered issues related to memory alignment and differences in the data structures between 32-bit and 64-bit layouts when checking the returned structure. I'm really glad to see that your test is comprehensive in addressing these concerns.
Description
Fixes # (issue)
This pull request focuses on resolving alignment issues in the
ut_lind_fs_getdents
test and ensuring proper handling of directory entries when interacting with packed fields. The primary changes involve:ClippedDirent
struct resulted in alignment issues, particularly ford_off
andd_reclen
. These fields have been safely accessed by copying them into local variables to ensure proper memory alignment./getdents
directory is properly cleaned up before the test is executed. If the directory already exists, it is removed to avoid conflicts. This ensures the test runs in a clean environment each time.Type of change
Dependencies
This change does not introduce new dependencies, but it ensures better integration with existing modules (e.g.,
native-client
,lind-glibc
, andlind-project
). No updates are required in those modules for this change to be effective.How Has This Been Tested?
cargo test ut_lind_fs_getdents
Checklist: