-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
std.posix: remove unchecked std.os.linux usage #20303
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3968,7 +3968,7 @@ pub const EpollCtlError = error{ | |||||
| FileDescriptorIncompatibleWithEpoll, | ||||||
| } || UnexpectedError; | ||||||
|
|
||||||
| pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*linux.epoll_event) EpollCtlError!void { | ||||||
| pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*system.epoll_event) EpollCtlError!void { | ||||||
| const rc = system.epoll_ctl(epfd, op, fd, event); | ||||||
| switch (errno(rc)) { | ||||||
| .SUCCESS => return, | ||||||
|
|
@@ -3988,7 +3988,7 @@ pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*linux.epoll_event) EpollC | |||||
| /// Waits for an I/O event on an epoll file descriptor. | ||||||
| /// Returns the number of file descriptors ready for the requested I/O, | ||||||
| /// or zero if no file descriptor became ready during the requested timeout milliseconds. | ||||||
| pub fn epoll_wait(epfd: i32, events: []linux.epoll_event, timeout: i32) usize { | ||||||
| pub fn epoll_wait(epfd: i32, events: []system.epoll_event, timeout: i32) usize { | ||||||
| while (true) { | ||||||
| // TODO get rid of the @intCast | ||||||
| const rc = system.epoll_wait(epfd, events.ptr, @intCast(events.len), timeout); | ||||||
|
|
@@ -7142,32 +7142,35 @@ pub const PerfEventOpenError = error{ | |||||
| } || UnexpectedError; | ||||||
|
|
||||||
| pub fn perf_event_open( | ||||||
| attr: *linux.perf_event_attr, | ||||||
| attr: *system.perf_event_attr, | ||||||
| pid: pid_t, | ||||||
| cpu: i32, | ||||||
| group_fd: fd_t, | ||||||
| flags: usize, | ||||||
| ) PerfEventOpenError!fd_t { | ||||||
| const rc = linux.perf_event_open(attr, pid, cpu, group_fd, flags); | ||||||
| switch (errno(rc)) { | ||||||
| .SUCCESS => return @intCast(rc), | ||||||
| .@"2BIG" => return error.TooBig, | ||||||
| .ACCES => return error.PermissionDenied, | ||||||
| .BADF => unreachable, // group_fd file descriptor is not valid. | ||||||
| .BUSY => return error.DeviceBusy, | ||||||
| .FAULT => unreachable, // Segmentation fault. | ||||||
| .INVAL => unreachable, // Bad attr settings. | ||||||
| .INTR => unreachable, // Mixed perf and ftrace handling for a uprobe. | ||||||
| .MFILE => return error.ProcessResources, | ||||||
| .NODEV => return error.EventRequiresUnsupportedCpuFeature, | ||||||
| .NOENT => unreachable, // Invalid type setting. | ||||||
| .NOSPC => return error.TooManyBreakpoints, | ||||||
| .NOSYS => return error.SampleStackNotSupported, | ||||||
| .OPNOTSUPP => return error.EventNotSupported, | ||||||
| .OVERFLOW => return error.SampleMaxStackOverflow, | ||||||
| .PERM => return error.PermissionDenied, | ||||||
| .SRCH => return error.ProcessNotFound, | ||||||
| else => |err| return unexpectedErrno(err), | ||||||
| if (native_os == .linux) { | ||||||
|
Member
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. I'm fine with how you have it, but I'd probably write it like this:
Suggested change
Member
Author
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. My current code is a bit more resistant to regressions in my opinion, though it does seem highly unlikely that some other OS would add a linux-compatible perf interface :D Either way, I don't think changing this style is worth the energy cost of another CI run, I'll press the merge button shortly. Thanks for the review! |
||||||
| // There is no syscall wrapper for this function exposed by libcs | ||||||
| const rc = linux.perf_event_open(attr, pid, cpu, group_fd, flags); | ||||||
| switch (errno(rc)) { | ||||||
| .SUCCESS => return @intCast(rc), | ||||||
| .@"2BIG" => return error.TooBig, | ||||||
| .ACCES => return error.PermissionDenied, | ||||||
| .BADF => unreachable, // group_fd file descriptor is not valid. | ||||||
| .BUSY => return error.DeviceBusy, | ||||||
| .FAULT => unreachable, // Segmentation fault. | ||||||
| .INVAL => unreachable, // Bad attr settings. | ||||||
| .INTR => unreachable, // Mixed perf and ftrace handling for a uprobe. | ||||||
| .MFILE => return error.ProcessResources, | ||||||
| .NODEV => return error.EventRequiresUnsupportedCpuFeature, | ||||||
| .NOENT => unreachable, // Invalid type setting. | ||||||
| .NOSPC => return error.TooManyBreakpoints, | ||||||
| .NOSYS => return error.SampleStackNotSupported, | ||||||
| .OPNOTSUPP => return error.EventNotSupported, | ||||||
| .OVERFLOW => return error.SampleMaxStackOverflow, | ||||||
| .PERM => return error.PermissionDenied, | ||||||
| .SRCH => return error.ProcessNotFound, | ||||||
| else => |err| return unexpectedErrno(err), | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -7182,8 +7185,8 @@ pub const TimerFdCreateError = error{ | |||||
| pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError; | ||||||
| pub const TimerFdSetError = TimerFdGetError || error{Canceled}; | ||||||
|
|
||||||
| pub fn timerfd_create(clokid: i32, flags: linux.TFD) TimerFdCreateError!fd_t { | ||||||
| const rc = linux.timerfd_create(clokid, flags); | ||||||
| pub fn timerfd_create(clokid: i32, flags: system.TFD) TimerFdCreateError!fd_t { | ||||||
| const rc = system.timerfd_create(clokid, @bitCast(flags)); | ||||||
| return switch (errno(rc)) { | ||||||
| .SUCCESS => @intCast(rc), | ||||||
| .INVAL => unreachable, | ||||||
|
|
@@ -7198,11 +7201,11 @@ pub fn timerfd_create(clokid: i32, flags: linux.TFD) TimerFdCreateError!fd_t { | |||||
|
|
||||||
| pub fn timerfd_settime( | ||||||
| fd: i32, | ||||||
| flags: linux.TFD.TIMER, | ||||||
| new_value: *const linux.itimerspec, | ||||||
| old_value: ?*linux.itimerspec, | ||||||
| flags: system.TFD.TIMER, | ||||||
| new_value: *const system.itimerspec, | ||||||
| old_value: ?*system.itimerspec, | ||||||
| ) TimerFdSetError!void { | ||||||
| const rc = linux.timerfd_settime(fd, flags, new_value, old_value); | ||||||
| const rc = system.timerfd_settime(fd, @bitCast(flags), new_value, old_value); | ||||||
| return switch (errno(rc)) { | ||||||
| .SUCCESS => {}, | ||||||
| .BADF => error.InvalidHandle, | ||||||
|
|
@@ -7213,9 +7216,9 @@ pub fn timerfd_settime( | |||||
| }; | ||||||
| } | ||||||
|
|
||||||
| pub fn timerfd_gettime(fd: i32) TimerFdGetError!linux.itimerspec { | ||||||
| var curr_value: linux.itimerspec = undefined; | ||||||
| const rc = linux.timerfd_gettime(fd, &curr_value); | ||||||
| pub fn timerfd_gettime(fd: i32) TimerFdGetError!system.itimerspec { | ||||||
| var curr_value: system.itimerspec = undefined; | ||||||
| const rc = system.timerfd_gettime(fd, &curr_value); | ||||||
| return switch (errno(rc)) { | ||||||
| .SUCCESS => return curr_value, | ||||||
| .BADF => error.InvalidHandle, | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.