Skip to content
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

Switching to using memfd for input data #990

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

quantum5
Copy link
Member

@quantum5 quantum5 commented Jan 30, 2022

Breaking changes:

  • All interactors using _interact_with_process

This closes #835.

@codecov-commenter
Copy link

codecov-commenter commented Jan 30, 2022

Codecov Report

Merging #990 (66437a7) into master (700b6f6) will increase coverage by 3.08%.
The diff coverage is 88.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #990      +/-   ##
==========================================
+ Coverage   80.83%   83.91%   +3.08%     
==========================================
  Files         139      142       +3     
  Lines        4716     4905     +189     
==========================================
+ Hits         3812     4116     +304     
+ Misses        904      789     -115     
Impacted Files Coverage Δ
dmoj/executors/shell_executor.py 0.00% <0.00%> (ø)
dmoj/cptbox/lazy_bytes.py 69.23% <69.23%> (ø)
dmoj/cptbox/utils.py 87.75% <86.66%> (-12.25%) ⬇️
dmoj/problem.py 91.69% <97.05%> (+0.46%) ⬆️
dmoj/checkers/bridged.py 100.00% <100.00%> (ø)
dmoj/cptbox/isolate.py 86.77% <100.00%> (+47.93%) ⬆️
dmoj/executors/base_executor.py 85.43% <100.00%> (+0.14%) ⬆️
dmoj/graders/bridged.py 100.00% <100.00%> (ø)
dmoj/graders/interactive.py 73.33% <100.00%> (+0.60%) ⬆️
dmoj/graders/standard.py 97.95% <100.00%> (+0.04%) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 700b6f6...66437a7. Read the comment docs.

@quantum5 quantum5 force-pushed the memfd-judge branch 8 times, most recently from 4b68ee6 to 5688538 Compare January 30, 2022 20:41
@quantum5 quantum5 force-pushed the memfd-judge branch 2 times, most recently from 71f78a6 to e30f7b1 Compare January 30, 2022 20:59
super().__init__(memory_fd_create(), 'r+')
_name: Optional[str] = None

def __init__(self, prefill: Optional[bytes] = None, seal=False) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe one or both of these should be required kwargs. I'm thinking the second should. What is the difference between prefilling with nothing, and passing None?

with NamedTemporaryFile(delete=False) as f:
self._name = f.name
super().__init__(os.dup(f.fileno()), 'r+')
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to dup and specify delete=False ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely. Otherwise the fd gets closed or the file gets unlinked, respectively.

if e.errno == errno.ENOSYS:
# FreeBSD
self.seek(0, os.SEEK_SET)
return
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not quite sure what this does. Does it deserve more of a comment?

self._input_data_fd = self._make_input_data_fd()
return self._input_data_fd

def _make_input_data_fd(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this needs to be typed to return MemoryIO now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Any file object will do, MemoryIO is just a special hack.

@@ -306,7 +306,7 @@ int memory_fd_create(void) {
#ifdef __FreeBSD__
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, is this function called on FreeBSD anymore? Are you creating the tempfile in Python instead?

try:
os.dup2(new_fd, fd)
finally:
os.close(new_fd)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could use a comment about why this dup is needed. Also, why isn't it implemented in the C function?

Copy link
Member Author

Choose a reason for hiding this comment

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

C code is just that much more painful to maintain.

@@ -21,10 +21,10 @@ def get_fs(self):
def get_allowed_syscalls(self):
return super().get_allowed_syscalls() + ['fork', 'waitpid', 'wait4']

def get_security(self, launch_kwargs=None):
def get_security(self, launch_kwargs=None, extra_fs=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Not that this is a direct result of this PR, but maybe this should be converted to **kwargs instead?

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.

Use memfd for file data
3 participants