-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
spirv: fix null file handle crash & improve flush err handling #24296
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
Open
nuIIpointerexception
wants to merge
3
commits into
ziglang:master
Choose a base branch
from
nuIIpointerexception:fix-spirv-linker-null-handle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,6 +180,28 @@ pub fn flush( | |
tid: Zcu.PerThread.Id, | ||
prog_node: std.Progress.Node, | ||
) link.File.FlushError!void { | ||
const tracy = trace(@src()); | ||
defer tracy.end(); | ||
|
||
const comp = self.base.comp; | ||
const diags = &comp.link_diags; | ||
|
||
const sub_prog_node = prog_node.start("SPIR-V Flush", 0); | ||
defer sub_prog_node.end(); | ||
|
||
return flushInner(self, arena, tid, sub_prog_node) catch |err| switch (err) { | ||
error.OutOfMemory => return error.OutOfMemory, | ||
error.LinkFailure => return error.LinkFailure, | ||
else => |e| return diags.fail("SPIR-V flush failed: {s}", .{@errorName(e)}), | ||
}; | ||
} | ||
|
||
fn flushInner( | ||
self: *SpirV, | ||
arena: Allocator, | ||
tid: Zcu.PerThread.Id, | ||
prog_node: std.Progress.Node, | ||
) !void { | ||
// The goal is to never use this because it's only needed if we need to | ||
// write to InternPool, but flush is too late to be writing to the | ||
// InternPool. | ||
|
@@ -189,12 +211,6 @@ pub fn flush( | |
@panic("Attempted to compile for architecture that was disabled by build configuration"); | ||
} | ||
|
||
const tracy = trace(@src()); | ||
defer tracy.end(); | ||
|
||
const sub_prog_node = prog_node.start("Flush Module", 0); | ||
defer sub_prog_node.end(); | ||
|
||
const comp = self.base.comp; | ||
const spv = &self.object.spv; | ||
const diags = &comp.link_diags; | ||
|
@@ -235,13 +251,14 @@ pub fn flush( | |
const module = try spv.finalize(arena); | ||
errdefer arena.free(module); | ||
|
||
const linked_module = self.linkModule(arena, module, sub_prog_node) catch |err| switch (err) { | ||
const linked_module = self.linkModule(arena, module, prog_node) catch |err| switch (err) { | ||
error.OutOfMemory => return error.OutOfMemory, | ||
else => |other| return diags.fail("error while linking: {s}", .{@errorName(other)}), | ||
}; | ||
|
||
self.base.file.?.writeAll(std.mem.sliceAsBytes(linked_module)) catch |err| | ||
return diags.fail("failed to write: {s}", .{@errorName(err)}); | ||
try self.base.makeWritable(); | ||
try self.pwriteAll(std.mem.sliceAsBytes(linked_module), 0); | ||
try self.setEndPos(linked_module.len * @sizeOf(Word)); | ||
Comment on lines
+260
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't abstract them into mini functions. just use - try self.pwriteAll(std.mem.sliceAsBytes(linked_module), 0);
- try self.setEndPos(linked_module.len * @sizeOf(Word));
+ try self.base.file.?.pwriteAll(std.mem.sliceAsBytes(linked_module), 0);
+ try self.base.file.?.setEndPos(linked_module.len * @sizeOf(Word)); |
||
} | ||
|
||
fn linkModule(self: *SpirV, a: Allocator, module: []Word, progress: std.Progress.Node) ![]Word { | ||
|
@@ -261,3 +278,19 @@ fn linkModule(self: *SpirV, a: Allocator, module: []Word, progress: std.Progress | |
|
||
return binary.finalize(a); | ||
} | ||
|
||
pub fn pwriteAll(spirv_file: *SpirV, bytes: []const u8, offset: u64) error{LinkFailure}!void { | ||
const comp = spirv_file.base.comp; | ||
const diags = &comp.link_diags; | ||
spirv_file.base.file.?.pwriteAll(bytes, offset) catch |err| { | ||
return diags.fail("failed to write: {s}", .{@errorName(err)}); | ||
}; | ||
} | ||
|
||
pub fn setEndPos(spirv_file: *SpirV, length: u64) error{LinkFailure}!void { | ||
const comp = spirv_file.base.comp; | ||
const diags = &comp.link_diags; | ||
spirv_file.base.file.?.setEndPos(length) catch |err| { | ||
return diags.fail("failed to set file end pos: {s}", .{@errorName(err)}); | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return
LinkFailure
for every other error: