Skip to content

Add missing filedesc and fdescenttbl in FreeBSD #4327

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

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@GuillaumeGomez GuillaumeGomez force-pushed the missing-freebsd-items branch 2 times, most recently from ee9d810 to 49c2dd2 Compare March 12, 2025 17:26
@tgross35
Copy link
Contributor

Cc @asomers for FreeBSD

Copy link
Contributor

@asomers asomers left a comment

Choose a reason for hiding this comment

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

There are a lot of new definitions here. I suggest you check how many of these fields you truly need to use. For those that you don't, you can make the field private and opaque. That eases the maintenance burden on libc, and makes it possible to change the fields later if needed.

Comment on lines 1379 to 1380
// This is normally `struct file`.
pub fde_file: *mut c_void,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you defining it as "c_void" instead of struct file just so you won't have to add a definition for the latter, because you don't need it? In that case, I suggest you make the field private. That way it will be easier to change the field later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, gonna do that.

pub fd_freefile: c_int,
pub fd_refcnt: c_int,
pub fd_holdcnt: c_int,
pub fd_sx: sx,
Copy link
Contributor

Choose a reason for hiding this comment

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

You should make this field private and opaque. It isn't used by userspace.

Copy link
Member Author

Choose a reason for hiding this comment

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

I made them private, but wdym by opaque? To get the size and alignment right, we still need to define the inner types, or do you mean something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to get the size and alignment correct with a suitably constructed array of bytes, longs, etc. But if that's too much work then it's ok to define the real structs instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I find it preferrable to have definitions matching C as it makes it easier for us to update it if changed but really as you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

For 1.0 we are going to make all opaque / padding fields MaybeUninit, that could be an option here

@GuillaumeGomez GuillaumeGomez force-pushed the missing-freebsd-items branch 5 times, most recently from feb4c4c to 6150594 Compare March 12, 2025 19:31
@GuillaumeGomez GuillaumeGomez force-pushed the missing-freebsd-items branch from 6150594 to ca3621f Compare March 12, 2025 19:36
@GuillaumeGomez
Copy link
Member Author

I didn't expect the segfault. XD

@tgross35
Copy link
Contributor

FreeBSD13 CI has a spurious segfault. I have no idea why, haven't had a chance to look into it.

Retried the job

@GuillaumeGomez GuillaumeGomez marked this pull request as ready for review March 13, 2025 09:42
@GuillaumeGomez
Copy link
Member Author

CI passed! \o/

@GuillaumeGomez
Copy link
Member Author

@tgross35 Is there anything else to be done here?

@GuillaumeGomez GuillaumeGomez force-pushed the missing-freebsd-items branch from ca3621f to 560c090 Compare March 19, 2025 16:37
@GuillaumeGomez
Copy link
Member Author

Just realized two things:

  • seqc_t type was unused so I removed it
  • I forgot to update the kinfo_proc::ki_fd field type so I updated it as well

@GuillaumeGomez GuillaumeGomez force-pushed the missing-freebsd-items branch from 1b93184 to e55f459 Compare April 1, 2025 19:53
@GuillaumeGomez
Copy link
Member Author

Rebased on main branch.

@tgross35 tgross35 requested a review from asomers April 2, 2025 20:00
@tgross35
Copy link
Contributor

tgross35 commented Apr 2, 2025

I think this looks fine to me with one note that there should be a comment about why some of these are #[doc(hidden)]. It would be better to just have them non-pub or pub(crate) but I don't think the macros allow that, maybe it should be a FIXME(pub).

I'm not sure about the change to kinfo_proc; that is breaking so I'm not sure @asomers would want to backport it, in which case that needs to be split to a separate commit so I can backport the rest.

Could you add a permalink to the relevant headers in the PR descripton?

@tgross35 tgross35 changed the title Add missing items in FreeBSD Add missing filedesc and fdescenttbl in FreeBSD Apr 2, 2025
@GuillaumeGomez
Copy link
Member Author

About the changes to kinfo_proc: you cannot access the data pointed by the pointer as is because it's a kernel pointer, you need to send this pointer to kvm_read to get the actual struct.

So although the pointer type changes, is it really an issue considering you cannot access the data as is?

@GuillaumeGomez
Copy link
Member Author

Oh also I added the permalinks in the first comment.

@GuillaumeGomez GuillaumeGomez force-pushed the missing-freebsd-items branch from e0c9011 to 5b5ec23 Compare April 2, 2025 20:19
@tgross35
Copy link
Contributor

tgross35 commented Apr 2, 2025

About the changes to kinfo_proc: you cannot access the data pointed by the pointer as is because it's a kernel pointer, you need to send this pointer to kvm_read to get the actual struct.

So although the pointer type changes, is it really an issue considering you cannot access the data as is?

Good point, it's probably not a problem in practice then. I'm fine with backporting everything as long as Alan okays it.

@GuillaumeGomez
Copy link
Member Author

Thanks, that'd allow me to remove a lot of code from sysinfo. :)

@asomers
Copy link
Contributor

asomers commented Apr 2, 2025

I'm ok with backporting the kinfo_proc change to the 0.2 branch.

@tgross35
Copy link
Contributor

tgross35 commented Apr 3, 2025

@asomers was there anything else you wanted here or is this good to merge?

@asomers
Copy link
Contributor

asomers commented Apr 3, 2025

@asomers was there anything else you wanted here or is this good to merge?

I would prefer that types like sx weren't declared, since they will never be used in userland. It would be better to make those fields just an opaque byte array. But if you like it this way instead, I'm ok with it.

@GuillaumeGomez
Copy link
Member Author

I'd prefer to keep the struct declaration. In future version, we can make the macro allow to have private types.

@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Apr 9, 2025
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.

I think that is fine, should be easier than calculating by hand. We've had some CI problems this week but they should be fixed now so this is all set.

Would you be able to squash?

@GuillaumeGomez GuillaumeGomez force-pushed the missing-freebsd-items branch from 5b5ec23 to a23e0e0 Compare April 9, 2025 17:51
@GuillaumeGomez
Copy link
Member Author

Sure, done.

@tgross35 tgross35 added this pull request to the merge queue Apr 9, 2025
Merged via the queue into rust-lang:main with commit 139801f Apr 9, 2025
44 of 45 checks passed
@GuillaumeGomez GuillaumeGomez deleted the missing-freebsd-items branch April 9, 2025 19:12
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Apr 11, 2025
[ edited the message to be more specific - Trevor ]
(backport <rust-lang#4327>)
(cherry picked from commit a23e0e0)
@tgross35 tgross35 mentioned this pull request Apr 11, 2025
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Apr 11, 2025
[ edited the message to be more specific - Trevor ]
(backport <rust-lang#4327>)
(cherry picked from commit a23e0e0)
@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 Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix 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