Skip to content

Commit

Permalink
Merge #3300
Browse files Browse the repository at this point in the history
3300: 2.1.1: Fix syscall return codes for wrong driver_number r=hudson-ayers a=alexandruradovici

### Pull Request Overview

This PR is not for the master branch, but for the `release-2.1`. As there is no branch for it, I am can to reopen this towards another branch.

This pull request fixes the value returned by the `subscribe` and `allow` system calls. Before this PR: 
- providing a wrong driver_number would return `NOMEM`. The issue is presented in #3278;
- providing a wrong subscribe or allow number would return `INVAL`, now it returns `NOSUPPORT`.

This PR will be superseded by  #3276, it is only for releasing Tock 2.1.1. This PR will have a slightly different behavior than its successor:

| |Tock 2.1.1 (this PR) | master (#3276) |
| --- |-----------|---------|
| `subscribe (invalid_number, invalid_callback, ...)` | `INVAL` | `NODEVICE` |
| `subscribe (invalid_number, valid_callback, ...)` | `NODEVICE` | `NODEVICE` |
| `allow... (invalid_number, invalid_reference, ...)` | `INVAL` | `NODEVICE` |
| `allow... (invalid_number, valid_reference, ...)` | `NODEVICE` | `NODEVICE` |

In #3276 the check for a valid driver is performed before the check for parameters, while in this PR the check is performed after. Checking for a valid driver before the validity of arguments will add at least 600 KB of code to the kernel, while this adds only 32 B.

### Testing Strategy

This pull request was tested by...


### TODO or Help Wanted

N/A

### Documentation Updated

- [x] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [x] Ran `make prepush`.


Co-authored-by: Alexandru RADOVICI <[email protected]>
Co-authored-by: Alexandru Radovici <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2022
2 parents ffa5ce0 + 4f2ada6 commit 1827bba
Show file tree
Hide file tree
Showing 2 changed files with 435 additions and 365 deletions.
6 changes: 3 additions & 3 deletions kernel/src/grant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ pub(crate) fn subscribe(
// Success!
Ok(old_upcall)
}
None => Err((upcall, ErrorCode::INVAL)),
None => Err((upcall, ErrorCode::NOSUPPORT)),
}
}

Expand Down Expand Up @@ -866,7 +866,7 @@ pub(crate) fn allow_ro(
// Success!
Ok(old_allow)
}
None => Err((buffer, ErrorCode::INVAL)),
None => Err((buffer, ErrorCode::NOSUPPORT)),
}
}

Expand Down Expand Up @@ -914,7 +914,7 @@ pub(crate) fn allow_rw(
// Success!
Ok(old_allow)
}
None => Err((buffer, ErrorCode::INVAL)),
None => Err((buffer, ErrorCode::NOSUPPORT)),
}
}

Expand Down
Loading

0 comments on commit 1827bba

Please sign in to comment.