Skip to content

fix: copy_file skip files larger than 1GB (Fixes #4039)#4048

Closed
IamHuskar wants to merge 3 commits intorr-debugger:masterfrom
IamHuskar:fix_dotnet_2tb_doublemapping
Closed

fix: copy_file skip files larger than 1GB (Fixes #4039)#4048
IamHuskar wants to merge 3 commits intorr-debugger:masterfrom
IamHuskar:fix_dotnet_2tb_doublemapping

Conversation

@IamHuskar
Copy link

Dotnet runtime may create 2TB memory-mapped files. 'copy_file' will persist this file.

Dotnet runtime may create 2TB memory-mapped files. 'copy_file' will persist this file.
@IamHuskar
Copy link
Author

IamHuskar commented Jan 29, 2026

I'm not completely certain this is the correct fix, and English isn't my first language. Feel free to modify anything in this PR
@rocallahan @khuey

@rocallahan
Copy link
Collaborator

I think this fix should be in TraceWriter::write_mapped_region(), in copy_file_or_trace in particular. As I said in the linked issue, the code that starts if ((km.prot() & PROT_EXEC) tries to copy executable files into the trace for use by debuggers. But if the file is too big, then we shouldn't be doing this. We can check the size of km, we don't need to re-stat anything.

@IamHuskar
Copy link
Author

I think this fix should be in TraceWriter::write_mapped_region(), in copy_file_or_trace in particular. As I said in the linked issue, the code that starts if ((km.prot() & PROT_EXEC) tries to copy executable files into the trace for use by debuggers. But if the file is too big, then we shouldn't be doing this. We can check the size of km, we don't need to re-stat anything.

I previously attempted to modify this part, but the size of km is not equal to the file size obtained through the fstat function call. I have already added a test case in the PR. Did I misunderstand something? I think I should place the file size check function in copy_file_or_trace, rather than inside the copy_file function.
rr_png_png

@IamHuskar
Copy link
Author

the CI test failed on ARM, but it works fine on my ARM device.

@rocallahan
Copy link
Collaborator

I previously attempted to modify this part, but the size of km is not equal to the file size obtained through the fstat function call. I have already added a test case in the PR. Did I misunderstand something? I think I should place the file size check function in copy_file_or_trace, rather than inside the copy_file function.

I see. Ok then, check the file size --- that makes sense, actually, since we're going to copy the whole file, and we don't want to copy too much.

But this check should still go next to the PROT_EXEC condition, because the goal here is "copy files when the mapping is PROT_EXEC, unless the file is too big".

@IamHuskar
Copy link
Author

Why is the MAP_SHARED check placed after copy_file? Can we change the order of these if conditions?
If the km region is MAP_SHARED, src.setTrace will be executed, but at that point, the file copying has already been completed.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants