11evan opened PR #5173 from jit-system-errors to main:
The JIT module has several places where it
expects orpanics on syscall or allocator errors. For example,mmapandmprotectcan fail if Linuxvm.max_map_countis not high enough, and some users may wish to handle this error rather than immediately crashing.This commit plumbs these errors upward as new
ModuleErrortypes, so that callers of jit module functions likefinalize_definitionsanddefine_functioncan handle them (or justunwrap(), as desired).<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
bjorn3 submitted PR review.
bjorn3 created PR review comment:
I think this one should be placed behind the
Backendvariant.
11evan updated PR #5173 from jit-system-errors to main.
11evan created PR review comment:
Do you mean it should be reordered to come after
Backend? Or does "behind" mean a multi level error enum likeenum BackendError { Allocation { ... } Syscall { ... } Other { ... } }?
11evan submitted PR review.
11evan updated PR #5173 from jit-system-errors to main.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
No, I mean the
anyhow::Errorfield ofModuleError::Backendshould be used to store this error I think.anyhow::Errorallows storing any type implementingstd::error::Error, including thestd::io::Erroryou have here.
11evan submitted PR review.
11evan created PR review comment:
Ah, I see. Yeah,
anyhow::Errorcan store anio::Error, and we could use it to get rid of theAllocationandSyscallerror variants, and useModuleError::Backendfor all cases.The difference is that the separate variants make it possible for the code catching the error to distinguish between allocation/syscall and other failures, since it can
matchand tell them apart. If all cases areanyhow::Error, the caller can't really disambiguate an allocation failure, from a syscall failure, from otherBackenderrors that already exist.
bjorn3 created PR review comment:
For allocation failure having a separate
ModuleErrorvariant makes sense to me. For syscall failure, I don't think you would ever want to distinguish it from any otherio::Error, but if that is necessary it would be possible to add a new error type to cranelift-jit wrappingio::Errorin that case and then store this new type inanyhow::Error.
bjorn3 submitted PR review.
11evan updated PR #5173 from jit-system-errors to main.
bjorn3 submitted PR review.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
This may not necessarily be correct. Not every global allocator impl sets errno. In fact I believe most don't.
11evan submitted PR review.
11evan created PR review comment:
Ah, I didn't realize. Maybe it would be better to just return
io::Error::from(io::ErrorKind::OutOfMemory)ourselves here, then?
11evan updated PR #5173 from jit-system-errors to main.
bjorn3 created PR review comment:
Yeah, that makes sense.
bjorn3 submitted PR review.
11evan submitted PR review.
11evan created PR review comment:
Updated to directly return
OutOfMemoryinstead of trying to uselast_os_error()
abrown submitted PR review.
abrown merged PR #5173.
Last updated: Dec 13 2025 at 19:03 UTC