Skip to content
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

syscall: use statx to provide functionality of fstat/fstatat if they are not provided. #18772

Closed
wants to merge 3 commits into from

Conversation

yxd-ym
Copy link
Contributor

@yxd-ym yxd-ym commented Feb 1, 2024

For some platform (e.g. loongarch64), fstat and fstatat system calls are not implemented in Linux kernel. Use statx system call to implement os.fstat and os.fstat if it exists.

This will benefit adding loongarch64 support to zig. See patch here: yxd-ym/zig-bootstrap#1

The implementation comes from the idea of golang's implementation https://go-review.googlesource.com/c/go/+/407694

@yxd-ym yxd-ym changed the title Use statx to provide functionality of fstat and fstatat. Use statx to provide functionality of fstat and fstatat if they are not provided. Feb 4, 2024
@yxd-ym yxd-ym changed the title Use statx to provide functionality of fstat and fstatat if they are not provided. syscall: use statx to provide functionality of fstat/fstatat if they are not provided. Feb 5, 2024
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to me like we should follow musl's lead and implement fstatat with fstatx on Linux.

The way this works in the Zig codebase is to have std.os.linux faithfully provide syscalls without emulating missing ones. In other words, provide both fstatat and fstatx, and make it a compile error to call one that does not exist.

Meanwhile, it is the task of std.os to provide fstatat and implement it using the fstatx call on linux.

Edit: I forgot to mention, hello, and thank you for sending this patch :-)

Feel free to leave this here and, eventually, someone will complete it for you.

}
return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.NOSYS))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a compile error rather than ENOSYS at runtime. I suggest to retain the pattern that was here before, making the else block call statx.

@yxd-ym
Copy link
Contributor Author

yxd-ym commented Feb 6, 2024

OK, I will wait for a more proper implementation.

@andrewrk andrewrk closed this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants