Skip to content

regular_file.c: don't treat 0 as a bad file descriptor#2616

Merged
sporksmith merged 2 commits intoshadow:mainfrom
sporksmith:zero-is-valid-fd
Dec 16, 2022
Merged

regular_file.c: don't treat 0 as a bad file descriptor#2616
sporksmith merged 2 commits intoshadow:mainfrom
sporksmith:zero-is-valid-fd

Conversation

@sporksmith
Copy link
Copy Markdown
Contributor

@sporksmith sporksmith commented Dec 16, 2022

I wanted to avoid comparing with equality to OSFILE_INVALID everywhere, in case we ever want to add other negative error values. Added an inline helper _fd_isValid instead.

Most of these checks could probably be omitted altogether in favor of letting the native file operation fail and return EBADF for us or us later failing to find the fd in our descriptor table, but probably not worth changing it right now.

Fixes #2604

@sporksmith sporksmith self-assigned this Dec 16, 2022
@github-actions github-actions bot added the Component: Main Composing the core Shadow executable label Dec 16, 2022
I wanted to avoid comparing with equality to OSFILE_INVALID everywhere,
in case we ever want to add other negative error values. Added an
inline helper `_fd_isValid` instead.

Most of these checks could probably be omitted altogether in favor of
letting the native file operation fail and return EBADF for us or us
later failing to find the descriptor, but probably not worth changing it
right now.

Fixes shadow#2604
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 16, 2022

Codecov Report

Base: 67.62% // Head: 66.99% // Decreases project coverage by -0.62% ⚠️

Coverage data is based on head (31e538d) compared to base (c35365d).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2616      +/-   ##
==========================================
- Coverage   67.62%   66.99%   -0.63%     
==========================================
  Files         200      200              
  Lines       29279    29279              
  Branches     5759     5759              
==========================================
- Hits        19800    19616     -184     
- Misses       4887     5092     +205     
+ Partials     4592     4571      -21     
Flag Coverage Δ
tests 66.99% <ø> (-0.63%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/main/host/syscall/handler/time.rs 0.00% <0.00%> (-65.86%) ⬇️
src/main/host/syscall/handler/eventfd.rs 0.00% <0.00%> (-25.72%) ⬇️
src/main/host/syscall/handler/ioctl.rs 31.25% <0.00%> (-21.88%) ⬇️
src/main/host/descriptor/eventfd.rs 0.00% <0.00%> (-21.22%) ⬇️
src/main/host/timer.rs 86.77% <0.00%> (-9.92%) ⬇️
src/main/host/syscall/handler/unistd.rs 55.55% <0.00%> (-9.06%) ⬇️
src/main/host/process.rs 65.62% <0.00%> (-6.25%) ⬇️
src/main/host/descriptor/pipe.rs 78.75% <0.00%> (-5.63%) ⬇️
src/main/host/memory_manager/memory_mapper.rs 66.25% <0.00%> (-5.39%) ⬇️
src/main/host/syscall/handler/mod.rs 77.50% <0.00%> (-5.00%) ⬇️
... and 17 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sporksmith sporksmith requested review from robgjansen and stevenengler and removed request for stevenengler December 16, 2022 02:09
In particular having them before the FILE_TYPE_IN_MEMORY processing
caused those operations to always fail, since those files don't have a
valid descriptor.

We could drop most of these checks altogether and just let the native
calls fail with EBADFD themselves, but there'd be some risk of a
performance regression since we'd no longer be skipping a native syscall
in those cases.
@sporksmith sporksmith enabled auto-merge December 16, 2022 19:12
@sporksmith sporksmith merged commit c2a1f79 into shadow:main Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Main Composing the core Shadow executable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

verify calls to _regularfile_getOSBackedFD are checked for -1, not 0

2 participants