Implement missing kernel and startup library imports #772

Manually merged
github merged 2 commits from gh-pr/772/head into gh-pr/772/base 2026-11-26 09:32:11 +00:00
Owner

@⁠tototomate123 on GitHub · 2026-09-22 19:32 UTC · original
tototomate123:fix/kernel-startup-hfw → main · +235 −0 · 8 files · 2 commits · merged 2026-09-23 11:57 UTC

Adds reusable implementations for kernel filesystem and startup APIs encountered by Horizon Forbidden West and potentially other titles:

  • Implement preadv, pwritev, and chmod in the shared kernel/filesystem paths, with filesystem tests
  • Return the no-entitlement result for unavailable NP entitlement keys.
  • Report VRR as unavailable for Kyty's fixed-refresh output through VideoOutVrrStatus.

HFW now runs through startup, language selection, and the intro to the title menu. Selecting Start still fails during compute shader resource tracking with GetImageResource reporting an invalid runtime value; gameplay loading is not fixed here.

The private VideoOutVrrStatus import uses an inferred ABI and should be reviewed.

Validation: Linux emulator and filesystem-test targets built; the focused kernel_file_system test and configured clang-format hook passed. Windows and macOS were not tested locally; the PR workflow covers those platforms.

Screenshot_20260922_211205

Horizon Forbidden West reaching the title screen in a local development build

**@⁠tototomate123** on GitHub · 2026-09-22 19:32 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/772) `tototomate123:fix/kernel-startup-hfw` → `main` · +235 −0 · 8 files · 2 commits · merged 2026-09-23 11:57 UTC Adds reusable implementations for kernel filesystem and startup APIs encountered by Horizon Forbidden West and potentially other titles: - Implement `preadv`, `pwritev`, and `chmod` in the shared kernel/filesystem paths, with filesystem tests - Return the no-entitlement result for unavailable NP entitlement keys. - Report VRR as unavailable for Kyty's fixed-refresh output through `VideoOutVrrStatus`. HFW now runs through startup, language selection, and the intro to the title menu. Selecting Start still fails during compute shader resource tracking with `GetImageResource` reporting an invalid runtime value; gameplay loading is not fixed here. The private `VideoOutVrrStatus` import uses an inferred ABI and should be reviewed. Validation: Linux emulator and filesystem-test targets built; the focused `kernel_file_system` test and configured clang-format hook passed. Windows and macOS were not tested locally; the PR workflow covers those platforms. <img width="1277" height="752" alt="Screenshot_20260922_211205" src="https://github.com/user-attachments/assets/1cbe2063-b113-48d3-9258-7bd33c110841" /> *Horizon Forbidden West reaching the title screen in a local development build*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:32:08 +00:00
github manually merged commit 1a9780ed4f into gh-pr/772/base 2026-11-26 09:32:11 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-22 19:44 UTC · original · edited 2026-09-22 19:45 UTC

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

The change adds KernelPreadv, KernelPwritev, and KernelChmod, including descriptor state, permission handling, error translation, and library exports. It adds VideoOutGetVrrStatus and entitlement-key access APIs with library registration. It also adds tests for validation, positioned I/O, permissions, concurrency, socket behavior, and symbol imports.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Feature

Merge Risk: 🔵 Low · up to 16122

Large vectored I/O requests and some permission failures may behave incorrectly; these localized fixes should be applied before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the main changes: implementing missing kernel APIs and startup library imports. It is concise and specific enough for the pull request scope.
Description check ✅ Passed The description directly explains the filesystem APIs, entitlement behavior, VRR behavior, testing, and Horizon Forbidden West progress covered by the changeset.

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-22 19:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/772#issuecomment-5782884558) · edited 2026-09-22 19:45 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/772"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The change adds `KernelPreadv`, `KernelPwritev`, and `KernelChmod`, including descriptor state, permission handling, error translation, and library exports. It adds `VideoOutGetVrrStatus` and entitlement-key access APIs with library registration. It also adds tests for validation, positioned I/O, permissions, concurrency, socket behavior, and symbol imports. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"1612207d9a9ebb5519cd82ff51a8f0629acb7b65" --> **Change:** Feature <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🔵 Low_ · up to `16122` <!-- final_review_risk_coverage:{"sourceCommitId":"1612207d9a9ebb5519cd82ff51a8f0629acb7b65","coveredCommitId":"1612207d9a9ebb5519cd82ff51a8f0629acb7b65","kind":"reviewed"} --> Large vectored I/O requests and some permission failures may behave incorrectly; these localized fixes should be applied before merge. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 9 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Title check | ✅ Passed | The title accurately summarizes the main changes: implementing missing kernel APIs and startup library imports. It is concise and specific enough for the pull request scope. | | Description check | ✅ Passed | The description directly explains the filesystem APIs, entitlement behavior, VRR behavior, testing, and Horizon Forbidden West progress covered by the changeset. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-22 19:44 UTC · original
On src/kernel/fileSystem.cpp line 130 (outdated):

@@ -112,6 +113,34 @@ static void SecToTimespec(KernelTimespec* ts, double sec) {
 	ts->tv_nsec = static_cast<int64_t>((sec - static_cast<double>(ts->tv_sec)) * 1000000000.0);
 }
 
+static uint16_t GetFileMode(const std::filesystem::path& path, uint16_t type) {
+	std::error_code error;
+	const auto      permissions = std::filesystem::status(path, error).permissions();
+	if (error) {
+		return static_cast<uint16_t>(type | 0000777u);
+	}
+	return static_cast<uint16_t>(type | (static_cast<uint32_t>(permissions) & 00007777u));
+}
+
+static int FileSystemErrorToKernel(const std::error_code& error) {
+	if (error == std::errc::no_such_file_or_directory) {
+		return KERNEL_ERROR_ENOENT;
+	}
+	if (error == std::errc::permission_denied || error == std::errc::operation_not_permitted) {
+		return KERNEL_ERROR_EACCES;

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Map operation_not_permitted to KERNEL_ERROR_EPERM.

KernelChmod passes std::filesystem::permissions errors to FileSystemErrorToKernel. This branch maps std::errc::operation_not_permitted to KERNEL_ERROR_EACCES. The repository defines distinct EPERM and EACCES values, so a matching chmod failure reaches the guest as EACCES instead of EPERM.

Suggested fix
-	if (error == std::errc::permission_denied || error == std::errc::operation_not_permitted) {
+	if (error == std::errc::permission_denied) {
 		return KERNEL_ERROR_EACCES;
 	}
+	if (error == std::errc::operation_not_permitted) {
+		return KERNEL_ERROR_EPERM;
+	}
**@⁠coderabbitai[bot]** on GitHub · 2026-09-22 19:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/772#discussion_r4075733490) On `src/kernel/fileSystem.cpp` line 130 (outdated): ```diff @@ -112,6 +113,34 @@ static void SecToTimespec(KernelTimespec* ts, double sec) { ts->tv_nsec = static_cast<int64_t>((sec - static_cast<double>(ts->tv_sec)) * 1000000000.0); } +static uint16_t GetFileMode(const std::filesystem::path& path, uint16_t type) { + std::error_code error; + const auto permissions = std::filesystem::status(path, error).permissions(); + if (error) { + return static_cast<uint16_t>(type | 0000777u); + } + return static_cast<uint16_t>(type | (static_cast<uint32_t>(permissions) & 00007777u)); +} + +static int FileSystemErrorToKernel(const std::error_code& error) { + if (error == std::errc::no_such_file_or_directory) { + return KERNEL_ERROR_ENOENT; + } + if (error == std::errc::permission_denied || error == std::errc::operation_not_permitted) { + return KERNEL_ERROR_EACCES; ``` _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ **Map `operation_not_permitted` to `KERNEL_ERROR_EPERM`.** `KernelChmod` passes `std::filesystem::permissions` errors to `FileSystemErrorToKernel`. This branch maps `std::errc::operation_not_permitted` to `KERNEL_ERROR_EACCES`. The repository defines distinct `EPERM` and `EACCES` values, so a matching chmod failure reaches the guest as `EACCES` instead of `EPERM`. <details><summary>Suggested fix</summary> ```diff - if (error == std::errc::permission_denied || error == std::errc::operation_not_permitted) { + if (error == std::errc::permission_denied) { return KERNEL_ERROR_EACCES; } + if (error == std::errc::operation_not_permitted) { + return KERNEL_ERROR_EPERM; + } ``` </details> <!-- fingerprinting:phantom:medusa:caracal --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:ce8e8d67992ada5b51eb0626 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-22 19:44 UTC · original
On src/kernel/fileSystem.cpp line 813 (outdated):

@@ -761,6 +792,96 @@ int64_t KYTY_SYSV_ABI KernelPread(int d, void* buf, size_t nbytes, int64_t offse
 	return bytes_read;
 }
 
+int64_t KYTY_SYSV_ABI KernelPreadv(int d, const KernelIovec* iov, int iovcnt, int64_t offset) {
+	PRINT_NAME();
+
+	constexpr int MaxIov = 1024;
+	if (iovcnt < 0 || iovcnt > MaxIov || offset < 0) {
+		return KERNEL_ERROR_EINVAL;
+	}
+	if (iov == nullptr && iovcnt != 0) {
+		return KERNEL_ERROR_EFAULT;
+	}
+
+	std::vector<KernelIovec> buffers;
+	if (iovcnt != 0) {
+		buffers.assign(iov, iov + iovcnt);
+	}
+	size_t total = 0;
+	for (const auto& buffer: buffers) {
+		if (buffer.iov_len > INT_MAX - total) {
+			return KERNEL_ERROR_EINVAL;

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- vector definitions and surrounding code ---'
sed -n '795,818p;941,960p' src/kernel/fileSystem.cpp
printf '%s\n' '--- scalar positional callers ---'
sed -n '732,780p;885,923p' src/kernel/fileSystem.cpp
printf '%s\n' '--- public size declarations ---'
sed -n '45,72p' src/common/file.h
printf '%s\n' '--- relevant declarations/usages/registrations ---'
rg -n -C 3 'KernelPreadv|KernelPwritev|KernelIovec' src

Repository: KytyPS5/KytyPS5

Length of output: 8210


Use UINT_MAX for aggregate vector-length validation.

KernelPreadv and KernelPwritev are registered in src/libs/libKernel.cpp and reject aggregate lengths above INT_MAX before performing I/O. A reachable vector with total length from INT_MAX + 1 through UINT_MAX therefore returns KERNEL_ERROR_EINVAL, although KernelIovec::iov_len, Common::File::Read/Write, and scalar positional callers support that range.

Suggested fix
-		if (buffer.iov_len > INT_MAX - total) {
+		if (buffer.iov_len > UINT_MAX - total) {

Apply the same change to the corresponding check in KernelPwritev.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

		if (buffer.iov_len > UINT_MAX - total) {
			return KERNEL_ERROR_EINVAL;
**@⁠coderabbitai[bot]** on GitHub · 2026-09-22 19:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/772#discussion_r4075733507) On `src/kernel/fileSystem.cpp` line 813 (outdated): ```diff @@ -761,6 +792,96 @@ int64_t KYTY_SYSV_ABI KernelPread(int d, void* buf, size_t nbytes, int64_t offse return bytes_read; } +int64_t KYTY_SYSV_ABI KernelPreadv(int d, const KernelIovec* iov, int iovcnt, int64_t offset) { + PRINT_NAME(); + + constexpr int MaxIov = 1024; + if (iovcnt < 0 || iovcnt > MaxIov || offset < 0) { + return KERNEL_ERROR_EINVAL; + } + if (iov == nullptr && iovcnt != 0) { + return KERNEL_ERROR_EFAULT; + } + + std::vector<KernelIovec> buffers; + if (iovcnt != 0) { + buffers.assign(iov, iov + iovcnt); + } + size_t total = 0; + for (const auto& buffer: buffers) { + if (buffer.iov_len > INT_MAX - total) { + return KERNEL_ERROR_EINVAL; ``` _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash set -e printf '%s\n' '--- vector definitions and surrounding code ---' sed -n '795,818p;941,960p' src/kernel/fileSystem.cpp printf '%s\n' '--- scalar positional callers ---' sed -n '732,780p;885,923p' src/kernel/fileSystem.cpp printf '%s\n' '--- public size declarations ---' sed -n '45,72p' src/common/file.h printf '%s\n' '--- relevant declarations/usages/registrations ---' rg -n -C 3 'KernelPreadv|KernelPwritev|KernelIovec' src ``` Repository: KytyPS5/KytyPS5 Length of output: 8210 --- </details> **Use `UINT_MAX` for aggregate vector-length validation.** `KernelPreadv` and `KernelPwritev` are registered in `src/libs/libKernel.cpp` and reject aggregate lengths above `INT_MAX` before performing I/O. A reachable vector with total length from `INT_MAX + 1` through `UINT_MAX` therefore returns `KERNEL_ERROR_EINVAL`, although `KernelIovec::iov_len`, `Common::File::Read`/`Write`, and scalar positional callers support that range. <details><summary>Suggested fix</summary> ```diff - if (buffer.iov_len > INT_MAX - total) { + if (buffer.iov_len > UINT_MAX - total) { ``` Apply the same change to the corresponding check in `KernelPwritev`. </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion if (buffer.iov_len > UINT_MAX - total) { return KERNEL_ERROR_EINVAL; ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:caracal --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:1f0618b8115623205165cf96 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-22 19:44 UTC · original · reviewed

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e6a7f4fb-cb33-4c22-b062-554b6732d802

📥 Commits

Reviewing files that changed from the base of the PR and between 8b095caefe and 1612207d9a.

📒 Files selected for processing (9)
  • src/graphics/presentation/videoOut.cpp
  • src/graphics/presentation/videoOut.h
  • src/kernel/fileSystem.cpp
  • src/kernel/fileSystem.h
  • src/libs/libKernel.cpp
  • src/libs/libNet.cpp
  • src/libs/libVideoOut.cpp
  • src/libs/libs.cpp
  • tests/KernelFileSystemTests.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-22 19:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/772#pullrequestreview-5282890919) · **reviewed** **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `e6a7f4fb-cb33-4c22-b062-554b6732d802` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 8b095caefecc2b0066b1b66425d24fd90f29a609 and 1612207d9a9ebb5519cd82ff51a8f0629acb7b65. </details> <details> <summary>📒 Files selected for processing (9)</summary> * `src/graphics/presentation/videoOut.cpp` * `src/graphics/presentation/videoOut.h` * `src/kernel/fileSystem.cpp` * `src/kernel/fileSystem.h` * `src/libs/libKernel.cpp` * `src/libs/libNet.cpp` * `src/libs/libVideoOut.cpp` * `src/libs/libs.cpp` * `tests/KernelFileSystemTests.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
This discussion has been locked. Commenting is limited to contributors.
No description provided.