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

musl: add more syscall constants #4028

Merged
merged 1 commit into from
Nov 16, 2024
Merged

Conversation

wolfv
Copy link
Contributor

@wolfv wolfv commented Nov 12, 2024

I hit a compilation issue where the SYS_rseq constant is not defined for some musl targets. For this PR I compared with upstream syscall.h.in files and added constants that I found where missing.

I wanted to double check if this is something we can easily adjust. If a PR like this is accepted, I can also see to adjust more of the remaining files that I haven't touched yet, and potentially write a small script for the conversion.

The changes in s390x are a little bigger because the integers were in relatively random order.

References:

@rustbot
Copy link
Collaborator

rustbot commented Nov 12, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Current nightly has a bug on s390x & sparc so I can't merge now, should be fixed tomorrow.

@tgross35 tgross35 assigned tgross35 and unassigned JohnTitor Nov 14, 2024
@wolfv
Copy link
Contributor Author

wolfv commented Nov 15, 2024

@tgross35 I can come up with a Python script to make these lists more consistent either with MUSL upstream or the Linux sources upstream. What do you think about that?

@tgross35 tgross35 added this pull request to the merge queue Nov 16, 2024
Merged via the queue into rust-lang:main with commit 0508535 Nov 16, 2024
43 checks passed
@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Nov 17, 2024
@tgross35
Copy link
Contributor

@tgross35 I can come up with a Python script to make these lists more consistent either with MUSL upstream or the Linux sources upstream. What do you think about that?

Thanks for offering! I am in favor of better comparison against sources but I'm not sure what would be best here. A script to compare syscalls would be somewhat limited, but it would be great to do something like compare against bindgen's output.

Happy to discuss something more in an issue if you're up for helping out, our tests could definitely be improved in a variety of ways.

tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 17, 2024
(backport <rust-lang#4028>)
(cherry picked from commit 9aa7e35)
@tgross35 tgross35 mentioned this pull request Nov 17, 2024
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 17, 2024
(backport <rust-lang#4028>)
(cherry picked from commit 9aa7e35)
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 17, 2024
(backport <rust-lang#4028>)
(cherry picked from commit 9aa7e35)
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 17, 2024
(backport <rust-lang#4028>)
(cherry picked from commit 9aa7e35)
@tgross35 tgross35 added stable-applied This PR has been cherry-picked to libc's stable release branch and removed stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Nov 17, 2024
@wolfv
Copy link
Contributor Author

wolfv commented Nov 17, 2024

@tgross35 I had a Python script that looked like this and used the musl source code, but I am wondering if it would be more appropriate to use the Linux headers? I guess these files are the definite source: https://github.com/torvalds/linux/blob/4a5df37964673effcd9f84041f7423206a5ae5f2/arch/x86/entry/syscalls/syscall_64.tbl

import re
from pathlib import Path

def convert_to_rust(input_file, output_file):
    # Updated pattern to capture the entire value/expression
    pattern = r'#define\s+__NR_(\w+)\s+(\(?\s*(?:0x[0-9a-fA-F]+)?\s*\+?\s*\d+\s*\)?|\d+)'

    # Read input file and convert to Rust format
    with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
        for line in infile:
            match = re.match(pattern, line.strip())
            if match:
                syscall_name, value = match.groups()
                # Keep the value exactly as is, just remove any extra whitespace
                value = ''.join(value.split())
                # Convert snake_case to the Rust SYS_ format
                rust_line = f'pub const SYS_{syscall_name}: ::c_long = {value};\n'
                outfile.write(rust_line)


def run(input_file):
    print("Running for file: ", input_file)
    output_file = input_file.parent / 'syscalls.rs'
    convert_to_rust(input_file, output_file)
    print(f"Successfully converted {input_file} to {output_file}")
    print("===============================\n\n\n")

    
def main():
    paths = Path('.').rglob('**/syscall.h.in')
    for path in paths:
        print(path)
        run(path)


if __name__ == '__main__':
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review stable-applied This PR has been cherry-picked to libc's stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants