Skip to content

libsel4muslcsys: Add fstat syscall#100

Open
dasch8-neutrality wants to merge 5 commits intoseL4:masterfrom
Neutrality-ch:master
Open

libsel4muslcsys: Add fstat syscall#100
dasch8-neutrality wants to merge 5 commits intoseL4:masterfrom
Neutrality-ch:master

Conversation

@dasch8-neutrality
Copy link

@dasch8-neutrality dasch8-neutrality commented Mar 21, 2025

The implementation only sets the file mode.
It is also only implemented for STDIN, STDOUT and STDERR.

This is to support libraries that insist on calling fstat on file descriptors before doing I/O.

The implementation only sets the file mode.
It is also only implemented for STDIN, STDOUT and STDERR.

This is to support libraries that insist on calling fstat on
file descriptors before doing I/O.

Signed-off-by: Daniel Schwyn <[email protected]>
@lsf37 lsf37 added the hw-build do all sel4test hardware builds on this PR label Mar 21, 2025
@dasch8-neutrality dasch8-neutrality force-pushed the master branch 2 times, most recently from 3ff410c to b28b020 Compare March 24, 2025 11:35
musllibc does not define the fstat syscall number for some architectures
(e.g. RISCV32).

In addition, also install the syscall for the explicit 64bit version if
its syscall number is defined. The implementation does not depend on the
word size.

Signed-off-by: Daniel Schwyn <[email protected]>
@dasch8-neutrality
Copy link
Author

I've fixed the Gitlint issue with the 2nd commit.

Copy link
Member

@lsf37 lsf37 left a comment

Choose a reason for hiding this comment

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

This looks fine from my side.

@lsf37 lsf37 self-assigned this Apr 3, 2025
long sys_fstat(va_list ap)
{
int fd = va_arg(ap, int);
struct stat *statbuf = va_arg(ap, struct stat *);
Copy link
Member

Choose a reason for hiding this comment

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

I think this type may need to be struct kstat because muslc uses a separate user type than the abi type it uses for the kernel.

Copy link
Author

@dasch8-neutrality dasch8-neutrality Apr 4, 2025

Choose a reason for hiding this comment

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

Ah yes, I think you are right, thanks. This makes it a bit trickier though as the kstat.h header is not exported by musllibc. The cleanest solution I can think of is to add another interface library to the musllibc CMake build that has arch/${muslc_arch}/ and arch/generic as include directories. Probably copied to the muslc build directory to exclude the bits subdirectories that are already part of musllibc's public includes. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

Or alternatively to keep the changes local use the MUSLLIBC_CURRENT_DIR variable set in Findmusllibc.cmake to add the include directories.

Copy link
Author

Choose a reason for hiding this comment

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

I implemented the first option and opened the corresponding pull request in the muslc repo: seL4/musllibc#25

musllibc expects fstat to return the internal type struct kstat.

Signed-off-by: Daniel Schwyn <[email protected]>
@dasch8-neutrality
Copy link
Author

Is the library with the internal musllibc headers an acceptable solution? Let me know if there is something I should still do to get this merged.

@dasch8-neutrality
Copy link
Author

dasch8-neutrality commented Nov 11, 2025

Where are we on this? Let me know if something needs doing to merge seL4/musllibc#25 and this.

Copy link
Contributor

@Indanz Indanz left a comment

Choose a reason for hiding this comment

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

A bit of a hack to get stdio working to be honest.

But I doubt that propagating this all the way to the UART driver or whoever takes care of stdio is any better/easier though.

@Indanz
Copy link
Contributor

Indanz commented Nov 11, 2025

Not sure what I'm doing wrong with the "Test-with: seL4/musllibc#25", I thought that would fix the build errors.

@lsf37
Copy link
Member

lsf37 commented Nov 11, 2025

Not sure what I'm doing wrong with the "Test-with: seL4/musllibc#25", I thought that would fix the build errors.

The syntax is Test with not Test-with. Have updated and restarted the build.

@Indanz
Copy link
Contributor

Indanz commented Nov 11, 2025

Hmm, this fails sometimes (or always on Aarch64?) with:

creating config.mak... done
  cp: will not overwrite just-created '/github/workspace/build/apps/sel4test-driver/musllibc/build-temp/stage/include-internal/fp_arch.h' with '/github/workspace/projects/musllibc/arch/generic/fp_arch.h'
  ninja: build stopped: subcommand failed.

@Indanz
Copy link
Contributor

Indanz commented Nov 11, 2025

The syntax is Test with not Test-with. Have updated and restarted the build.

Thanks. Is this documented anywhere btw? Now that other commit is merged, I removed the line again.

@lsf37
Copy link
Member

lsf37 commented Nov 11, 2025

The syntax is Test with not Test-with. Have updated and restarted the build.

Thanks. Is this documented anywhere btw? Now that other commit is merged, I removed the line again.

Like all totally intuitive almost natural language commands of course this one didn't need any documentation, because we would never get it wrong :) By which I mean, I've been lazy and haven't found a good place to put it, so deferred it indefinitely.

Where would you first look for docs for it? Would the README of the ci-actions repo be a good place? Or would a page on the docsite be better?

Edit: the "spec", i.e. tests are here: https://github.com/seL4/ci-actions/blob/996e12ca25fde30ef6567c840cfd63697d202cb8/scripts/get-prs#L74

@midnightveil
Copy link
Contributor

Where would you first look for docs for it? Would the README of the ci-actions repo be a good place? Or would a page on the docsite be better?

In the past I think I've gone to ci-actions. I don't tend to look at the docsite much, personally... Mostly because also I know that if I search the strings I'll find get-prs.

@midnightveil
Copy link
Contributor

Hmm, this fails sometimes (or always on Aarch64?) with:

creating config.mak... done
  cp: will not overwrite just-created '/github/workspace/build/apps/sel4test-driver/musllibc/build-temp/stage/include-internal/fp_arch.h' with '/github/workspace/projects/musllibc/arch/generic/fp_arch.h'
  ninja: build stopped: subcommand failed.

I don't think this is caused by this, but I think was actually because of seL4/musllibc#25 as I saw it on another PR.

@dasch8-neutrality
Copy link
Author

dasch8-neutrality commented Nov 12, 2025

Hmm, this fails sometimes (or always on Aarch64?) with:

creating config.mak... done
  cp: will not overwrite just-created '/github/workspace/build/apps/sel4test-driver/musllibc/build-temp/stage/include-internal/fp_arch.h' with '/github/workspace/projects/musllibc/arch/generic/fp_arch.h'
  ninja: build stopped: subcommand failed.

I don't think this is caused by this, but I think was actually because of seL4/musllibc#25 as I saw it on another PR.

Ah, I overlooked that arch/generic contains some default headers that e.g. for aarch64 are replaced with architecture specific ones. I should have done the copy in two steps, first the generic headers and then the architecture specific ones so that the specific version wins. @Indanz should I file a new pull request in the muslc repo?

@Indanz
Copy link
Contributor

Indanz commented Nov 12, 2025

I don't think this is caused by this, but I think was actually because of seL4/musllibc#25 as I saw it on another PR.

Ah, I overlooked that arch/generic contains some default headers that e.g. for aarch64 are replaced with architecture specific ones. I should have done the copy in two steps, first the generic headers and then the architecture specific ones so that the specific version wins. @Indanz should I file a new pull request in the muslc repo?

Yes please, otherwise I'll revert that other commit.

@dasch8-neutrality
Copy link
Author

I don't think this is caused by this, but I think was actually because of seL4/musllibc#25 as I saw it on another PR.

Ah, I overlooked that arch/generic contains some default headers that e.g. for aarch64 are replaced with architecture specific ones. I should have done the copy in two steps, first the generic headers and then the architecture specific ones so that the specific version wins. @Indanz should I file a new pull request in the muslc repo?

Yes please, otherwise I'll revert that other commit.

I've opened a pull request with the fix: seL4/musllibc#27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hw-build do all sel4test hardware builds on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants