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

Attention: Patch coverage is 88.37209% with 25 lines in your changes missing coverage. Please review.

Project coverage is 83.91%. Comparing base (700b6f6) to head (66437a7).
Report is 254 commits behind head on master.

Files with missing lines Patch % Lines
dmoj/cptbox/lazy_bytes.py 69.23% 16 Missing ⚠️
dmoj/cptbox/utils.py 86.66% 6 Missing ⚠️
dmoj/executors/shell_executor.py 0.00% 2 Missing ⚠️
dmoj/problem.py 97.05% 1 Missing ⚠️
Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@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