mirror of
https://github.com/seedds/nxnative.git
synced 2026-11-23 11:39:42 -10:00
fs: file handles reach the guest 16-byte aligned; backslashes separate path components (PR #513)
On Horizon a FileHandle is a pointer to the SDK's FileAccessor, so its low bits are clear, and Metroid Prime 4: Beyond's file device masks them off (handle & ~7) before ReadFile. The host's RomFS image handle kept the entry index in its low bits, so entry 7 was read as entry 0: a 10-byte read of another file, then a null pointer at boot. The guest now gets the host's handle shifted left by 4 (FH_OUT), and each call that takes one shifts it back (FH_IN); the image flag moved from bit 62 to bit 58, so the guest still sees it at bit 62. Horizon's file system accessor replaces every backslash in a path with a slash before it normalizes the path (FileSystemAccessor::SetUpPath), on every mount but the PC host's; Metroid Prime 4 names its files rom:\StartupUI.pak. Each guest path resolver (img_path, host_path_ex, set_guest_name, dir_snapshot) converts them first, so overlay folders, ".." and guest names see the same path. PR #513 taught two of the parsers instead. t_fs: 10 new checks (masked handle on an image entry, backslash paths on a folder with an overlay, an image, an image with an overlay, directory listings, a save's create, rename and guest name): all fail before, all pass now. t_fs_commit_list decoded a handle as an fd and hung with any shift; it now uses FH_IN. All host tests and tsan-threads pass. Reference entry in docs/reference/services.md. regress.py check on 5 games (Mac, M4 Pro, shared with three other harness runs): ANIMAL WELL PASS; Pokemon Scarlet reached the end at 29.9 fps as before (its "new" red lines are shader libraries missing in both runs); Tears of the Kingdom and Breath of the Wild did not run (the baseline's shader build stopped); Super Mario Bros. Wonder frame p99 16.9 -> 47.6 ms under that load, unexplained, to re-run on an idle machine. Co-authored-by: Lilun Xu <[email protected]>
This commit is contained in:
1 parent
9333825d6b
commit
7c23cc039a
5 files changed
+56
-17
No files matched your search
+31
-16
@@ -2,7 +2,7 @@
|
||||
// rom → $DM_ROMFS (default $DM_ROOT/romfs, read-only; the game parses the storage blocks in it itself)
|
||||
// save → $DM_SAVE (must be set, pointing to this run's copy of the standard save save_ref; if unset, report a failure and abort)
|
||||
// temp → $DM_TEMP (default $DM_ROOT/run/platform/temp)
|
||||
// Paths look like "rom:/data/x". FileHandle / DirectoryHandle are 8 bytes passed by value, here they store the host fd / DIR*.
|
||||
// Paths look like "rom:/data/x". FileHandle / DirectoryHandle are 8 bytes passed by value, here they store the host fd (FH_OUT) / DIR*.
|
||||
// Struct layout follows the public Horizon ABI: DirectoryEntry = {char name[0x301], pad[3], s8 type, pad[3], s64 size} (0x310 bytes).
|
||||
#include "hle.h"
|
||||
#include <mach/mach.h>
|
||||
@@ -37,12 +37,17 @@ _Static_assert(sizeof(DirectoryEntry) == 0x310, "DirectoryEntry layout");
|
||||
// all game reads and writes happen in the working directory; Commit = clonefile(work → <commit>.new), then renamex_np(RENAME_SWAP) swaps it atomically with commit, then the swapped-out old version is deleted.
|
||||
// Killed at any moment, commit is either the old version or the new version, never half-written / a mix of old and new; the next mount discards leftover .work / .new.
|
||||
// RomFS image (dm/tools/romfs_image.py): DM_ROMFS may name one image file instead of a folder. Its index is read at mount; a file handle is then an entry of the image
|
||||
// (IMG_HANDLE, bit 62 set, never a valid fd), read with pread at its offset in the one descriptor kept open, and a directory lists its consecutive child entries.
|
||||
// (IMG_HANDLE, bit 58 set, never a valid fd), read with pread at its offset in the one descriptor kept open, and a directory lists its consecutive child entries.
|
||||
// One file instead of a few hundred thousand copies to an iPhone at full speed: a folder copy of Tears of the Kingdom's 304,000 files ran the phone's file service out of open files
|
||||
#define IMG_HANDLE(mi, k) ((1ull << 62) | ((uint64_t)(mi) << 32) | (uint64_t)(k))
|
||||
#define IMG_H(h) (((h) >> 62) == 1)
|
||||
#define IMG_M(h) ((int)(((h) >> 32) & 0x3fffffff))
|
||||
#define IMG_HANDLE(mi, k) ((1ull << 58) | ((uint64_t)(mi) << 32) | (uint64_t)(k))
|
||||
#define IMG_H(h) (((h) >> 58) == 1)
|
||||
#define IMG_M(h) ((int)(((h) >> 32) & 0x3ffffff))
|
||||
#define IMG_K(h) ((uint32_t)(h))
|
||||
// On Horizon a FileHandle is a pointer to the SDK's FileAccessor, a heap object, so its low bits are clear, and a game may use them: Metroid Prime 4's file device masks
|
||||
// them off (handle & ~7) before ReadFile, which read image entry 7 as entry 0 (another file, then a null pointer at boot). The guest sees the host's handle shifted
|
||||
// left by 4, 16-byte aligned as AArch64 heap blocks are (the image flag then lands on bit 62, as before): FH_OUT where a handle goes to the guest, FH_IN in each call that takes one
|
||||
#define FH_OUT(h) ((uint64_t)(h) << 4)
|
||||
#define FH_IN(h) ((uint64_t)(h) >> 4)
|
||||
typedef struct {
|
||||
char name[32]; char dir[1024]; char overlay[4096]; char commit[1024];
|
||||
romfs_img *img; // non-NULL: dir is a RomFS image file
|
||||
@@ -154,11 +159,19 @@ static int64_t img_find(const romfs_img *m, const char *rest) {
|
||||
}
|
||||
return (int64_t)k;
|
||||
}
|
||||
// Horizon's file system accessor turns each backslash in a path into a slash before it normalizes the path (FileSystemAccessor::SetUpPath, InitializeWithReplaceBackslash),
|
||||
// on every mount but the PC host's: Metroid Prime 4 (SDK 19) names its RomFS files rom:\StartupUI.pak. Each guest path resolver takes p through here first: p itself, or
|
||||
// its copy in buf with slashes (a path too long for buf is left as it is, and is not found)
|
||||
static const char *fwd_slashes(const char *p, char *buf, size_t n) {
|
||||
if (!p || !strchr(p, '\\') || strlen(p) >= n) return p;
|
||||
size_t i = 0; for (; p[i]; i++) buf[i] = p[i] == '\\' ? '/' : p[i];
|
||||
buf[i] = 0; return buf;
|
||||
}
|
||||
static int norm_rest(const char *rest, char *out, size_t n);
|
||||
static int rom_overlay_path(const mount_t *m, const char *rest, char *out, size_t n);
|
||||
// A path on an image mount: returns 1 with the mount in *mi and the entry in *k (-1 with errno set when there is none); 0 for a path on any other mount, or one an overlay folder (DM_ROMFS_OVERLAY) has, which then opens as a host file
|
||||
static int img_path(const char *p, int *mi, int64_t *k) {
|
||||
PATH_LOCK(); const char *c = p ? strchr(p, ':') : NULL; if (!c) return 0;
|
||||
PATH_LOCK(); char fwd[1024]; p = fwd_slashes(p, fwd, sizeof fwd); const char *c = p ? strchr(p, ':') : NULL; if (!c) return 0;
|
||||
size_t ln = c - p;
|
||||
for (int i = 0; i < g_nmnt; i++) {
|
||||
if (strlen(g_mnt[i].name) != ln || strncmp(g_mnt[i].name, p, ln)) continue;
|
||||
@@ -360,7 +373,7 @@ static int norm_rest(const char *rest, char *out, size_t n) {
|
||||
}
|
||||
// create only allows the last component to not exist yet; intermediate directories still need an exact match.
|
||||
static int host_path_ex(const char *p, char *out, size_t n, int *ro, int create) {
|
||||
const char *c = strchr(p, ':');
|
||||
char fwd[1024]; p = fwd_slashes(p, fwd, sizeof fwd); const char *c = strchr(p, ':');
|
||||
if (!c) { errno = ENOENT; return 0; }
|
||||
size_t ln = c - p;
|
||||
for (int i = 0; i < g_nmnt; i++) {
|
||||
@@ -388,6 +401,7 @@ static int host_path_ex(const char *p, char *out, size_t n, int *ro, int create)
|
||||
}
|
||||
static int host_path(const char *p, char *out, size_t n, int *ro) { return host_path_ex(p, out, n, ro, 0); }
|
||||
static int set_guest_name(const char *hp, const char *path) {
|
||||
char fwd[1024]; path = fwd_slashes(path, fwd, sizeof fwd);
|
||||
const char *end = path + strlen(path); while (end > path && end[-1] == '/') end--;
|
||||
const char *start = end; while (start > path && start[-1] != '/' && start[-1] != ':') start--;
|
||||
char guest[0x301]; size_t k = end - start;
|
||||
@@ -700,7 +714,7 @@ HLE_FORCE("_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci", "fsp-srv → open(2)", Re
|
||||
if (k < 0) return err_res("open", path);
|
||||
if (!g_mnt[mi].img->e[k].type) return RES_PATH_NOT_FOUND;
|
||||
if (mode & (MODE_WRITE | MODE_APPEND)) { LOG("fs write to a read-only mount: %s", path); return RES_FAIL; }
|
||||
*out = IMG_HANDLE(mi, k);
|
||||
*out = FH_OUT(IMG_HANDLE(mi, k));
|
||||
if (g_flag.fs) LOG("fs open [%.2fs] %s mode=%d → image entry %lld", (now_ns() - g_t0_ns) / 1e9, path, mode, (long long)k);
|
||||
return RES_OK;
|
||||
}
|
||||
@@ -711,7 +725,7 @@ HLE_FORCE("_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci", "fsp-srv → open(2)", Re
|
||||
struct stat st; fstat(fd, &st);
|
||||
if (S_ISDIR(st.st_mode)) { close(fd); return RES_PATH_NOT_FOUND; }
|
||||
if (fd >= (int)sizeof g_fmode) die("fd beyond the table");
|
||||
g_fmode[fd] = (uint8_t)mode; *out = (uint64_t)fd;
|
||||
g_fmode[fd] = (uint8_t)mode; *out = FH_OUT(fd);
|
||||
{ const char *c = strchr(path, ':'); size_t ln = c ? (size_t)(c - path) : 0; uint16_t token = 0;
|
||||
for (int i = 0; c && i < g_nmnt; i++) if (strlen(g_mnt[i].name) == ln && !strncmp(g_mnt[i].name, path, ln) && g_mnt[i].txn_root >= 0) { token = (uint16_t)(g_mnt[i].txn_root + 1); break; }
|
||||
atomic_store(&g_ftxn[fd], token); }
|
||||
@@ -720,7 +734,7 @@ HLE_FORCE("_ZN2nn2fs8OpenFileEPNS0_10FileHandleEPKci", "fsp-srv → open(2)", Re
|
||||
if (g_flag.fs) LOG("fs open [%.2fs] %s mode=%d → fd %d", (now_ns() - g_t0_ns) / 1e9, path, mode, fd);
|
||||
return RES_OK;
|
||||
}
|
||||
HLE_FORCE("_ZN2nn2fs8ReadFileEPmNS0_10FileHandleElPvm", "fsp-srv → pread(2)", Result, h_fs_ReadFile, size_t *out, uint64_t h, int64_t off, void *buf, size_t sz) {
|
||||
HLE_FORCE("_ZN2nn2fs8ReadFileEPmNS0_10FileHandleElPvm", "fsp-srv → pread(2)", Result, h_fs_ReadFile, size_t *out, uint64_t h, int64_t off, void *buf, size_t sz) { h = FH_IN(h);
|
||||
if (!h) { *out = 0; return RES_FAIL; } // a file handle is an fd; 0 is stdin and never a file the game opened: the null handle the game keeps using after a failed open
|
||||
size_t got = 0; int reprep = 0, fd = (int)h; int64_t base = 0;
|
||||
if (IMG_H(h)) { // an image entry: read the image's descriptor at the entry's offset, never past its end
|
||||
@@ -762,7 +776,7 @@ HLE_FORCE("_ZN2nn2fs8ReadFileEPmNS0_10FileHandleElPvm", "fsp-srv → pread(2)",
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
HLE_FORCE("_ZN2nn2fs9WriteFileENS0_10FileHandleElPKvmRKNS0_11WriteOptionE", "fsp-srv → pwrite(2)", Result, h_fs_WriteFile, uint64_t h, int64_t off, const void *buf, size_t sz, const void *opt) {
|
||||
HLE_FORCE("_ZN2nn2fs9WriteFileENS0_10FileHandleElPKvmRKNS0_11WriteOptionE", "fsp-srv → pwrite(2)", Result, h_fs_WriteFile, uint64_t h, int64_t off, const void *buf, size_t sz, const void *opt) { h = FH_IN(h);
|
||||
if (!h || IMG_H(h)) return RES_FAIL;
|
||||
int fd = (int)h & 0xffff; uint16_t token = atomic_load(&g_ftxn[fd]); int txn = token ? token - 1 : -1;
|
||||
pthread_rwlock_t *txn_guard __attribute__((cleanup(txn_unlock))) = NULL;
|
||||
@@ -783,13 +797,13 @@ HLE_FORCE("_ZN2nn2fs9WriteFileENS0_10FileHandleElPKvmRKNS0_11WriteOptionE", "fsp
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
HLE_FORCE("_ZN2nn2fs11GetFileSizeEPlNS0_10FileHandleE", "fsp-srv → fstat(2)", Result, h_fs_GetFileSize, int64_t *out, uint64_t h) {
|
||||
HLE_FORCE("_ZN2nn2fs11GetFileSizeEPlNS0_10FileHandleE", "fsp-srv → fstat(2)", Result, h_fs_GetFileSize, int64_t *out, uint64_t h) { h = FH_IN(h);
|
||||
if (!h) return RES_FAIL;
|
||||
if (IMG_H(h)) { *out = (int64_t)g_mnt[IMG_M(h)].img->e[IMG_K(h)].b; return RES_OK; }
|
||||
struct stat st; if (fstat((int)h, &st)) return err_res("fstat", "fd");
|
||||
*out = st.st_size; return RES_OK;
|
||||
}
|
||||
HLE_FORCE("_ZN2nn2fs11SetFileSizeENS0_10FileHandleEl", "fsp-srv → ftruncate(2)", Result, h_fs_SetFileSize, uint64_t h, int64_t sz) {
|
||||
HLE_FORCE("_ZN2nn2fs11SetFileSizeENS0_10FileHandleEl", "fsp-srv → ftruncate(2)", Result, h_fs_SetFileSize, uint64_t h, int64_t sz) { h = FH_IN(h);
|
||||
if (!h || IMG_H(h)) return RES_FAIL;
|
||||
int fd = (int)h & 0xffff; uint16_t token = atomic_load(&g_ftxn[fd]); int txn = token ? token - 1 : -1;
|
||||
pthread_rwlock_t *txn_guard __attribute__((cleanup(txn_unlock))) = NULL;
|
||||
@@ -799,11 +813,11 @@ HLE_FORCE("_ZN2nn2fs11SetFileSizeENS0_10FileHandleEl", "fsp-srv → ftruncate(2)
|
||||
return err_res("ftruncate", "fd");
|
||||
}
|
||||
HLE_FORCE("_ZN2nn2fs9FlushFileENS0_10FileHandleE", "fsp-srv; host writes are already in the page cache, flushing is a no-op", Result, h_fs_FlushFile, uint64_t h) { (void)h; return RES_OK; }
|
||||
HLE_FORCE("_ZN2nn2fs9CloseFileENS0_10FileHandleE", "fsp-srv → close(2)", void, h_fs_CloseFile, uint64_t h) {
|
||||
HLE_FORCE("_ZN2nn2fs9CloseFileENS0_10FileHandleE", "fsp-srv → close(2)", void, h_fs_CloseFile, uint64_t h) { h = FH_IN(h);
|
||||
if (!h || IMG_H(h)) return; // the null handle after a failed open (see ReadFile): do not touch fd 0; an image entry holds no descriptor
|
||||
g_fmode[(int)h & 0xffff] = 0; atomic_store(&g_ftxn[(int)h & 0xffff], 0);
|
||||
close((int)h); }
|
||||
HLE_FORCE("_ZN2nn2fs15GetFileOpenModeENS0_10FileHandleE", "fsp-srv; the open mode is recorded by the host", int, h_fs_GetFileOpenMode, uint64_t h) { return IMG_H(h) ? MODE_READ : g_fmode[(int)h & 0xffff]; }
|
||||
HLE_FORCE("_ZN2nn2fs15GetFileOpenModeENS0_10FileHandleE", "fsp-srv; the open mode is recorded by the host", int, h_fs_GetFileOpenMode, uint64_t h) { h = FH_IN(h); return IMG_H(h) ? MODE_READ : g_fmode[(int)h & 0xffff]; }
|
||||
|
||||
// ---------- Path operations ----------
|
||||
HLE_FORCE("_ZN2nn2fs10CreateFileEPKcl", "fsp-srv → open(O_CREAT|O_EXCL)+ftruncate", Result, h_fs_CreateFile, const char *path, int64_t sz) {
|
||||
@@ -891,6 +905,7 @@ HLE_FORCE("_ZN2nn2fs12GetEntryTypeEPNS0_18DirectoryEntryTypeEPKc", "fsp-srv →
|
||||
// ---------- Directories ----------
|
||||
typedef struct { DIR *d; char path[1024]; DIR *od; char opath[1024]; DirectoryEntry *snap; int64_t nsnap, psnap; int mode; } dirh_t;
|
||||
static void dir_snapshot(dirh_t *h, const mount_t *m, const char *rest) {
|
||||
char fwd[1024]; rest = fwd_slashes(rest, fwd, sizeof fwd);
|
||||
char *roots = strdup(m->overlay);
|
||||
size_t cap = 2048; char (*names)[0x301] = malloc(cap * sizeof *names);
|
||||
const char **all = calloc(65, sizeof *all);
|
||||
@@ -988,7 +1003,7 @@ HLE_FORCE("_ZN2nn2fs8MountRomEPKc", "fsp-srv; rom → host RomFS directory (over
|
||||
HLE_FORCE("_ZN2nn2fs8ReadFileENS0_10FileHandleElPvm", "fsp-srv → pread(2), must read in full", Result, h_fs_ReadFileExact, uint64_t h, int64_t off, void *buf, size_t sz) {
|
||||
size_t got = 0; Result r = h_fs_ReadFile(&got, h, off, buf, sz);
|
||||
if (r != RES_OK) return r;
|
||||
if (got != sz) { LOG("fs ReadFile short read: fd %d offset %lld wanted %zu got %zu", (int)h, (long long)off, sz, got); return RES_FAIL; }
|
||||
if (got != sz) { LOG("fs ReadFile short read: fd %d offset %lld wanted %zu got %zu", (int)FH_IN(h), (long long)off, sz, got); return RES_FAIL; }
|
||||
return RES_OK;
|
||||
}
|
||||
HLE_FORCE("_ZN2nn2fs8ReadFileEPmNS0_10FileHandleElPvmRKNS0_10ReadOptionE", "fsp-srv → pread(2) (overload with read options, which the host ignores)", Result, h_fs_ReadFileOpt,
|
||||
|
||||
@@ -51,6 +51,8 @@ int main(void) {
|
||||
setenv("DM_ROMFS", rom, 1); setenv("DM_ROMFS_OVERLAY", overlay, 1); CHECK(h_fs_MountRom("rom", NULL, 0) == RES_OK, "mount RomFS with two layers (base + overlay)");
|
||||
CHECK(read_fs("rom:/data/same", got, sizeof got) && !strcmp(got, "overlay"), "the overlay file wins"); CHECK(read_fs("rom:/data/base", got, sizeof got) && !strcmp(got, "only-base"), "falls back to the base when the overlay lacks the file");
|
||||
uint64_t rh; CHECK(h_fs_OpenFile(&rh, "rom:/data/same", MODE_WRITE) == RES_FAIL, "the two-layer mount refuses writes");
|
||||
CHECK(read_fs("rom:\\data\\over", got, sizeof got) && !strcmp(got, "only-overlay") && read_fs("rom:\\data\\base", got, sizeof got) && !strcmp(got, "only-base"), "backslashes separate as slashes do, in both layers");
|
||||
CHECK(h_fs_OpenFile(&rh, "rom:/data/base", MODE_READ) == RES_OK && rh && !(rh & 15), "a folder file's handle is 16-byte aligned, as a Horizon FileAccessor pointer is (%#llx)", (unsigned long long)rh); h_fs_CloseFile(rh);
|
||||
g_nmnt = 0;
|
||||
|
||||
printf("RomFS image\n"); // written by hand in romfs_image.py's layout: /data/a = "hello", /data/b empty directory, /data/c = "xy"
|
||||
@@ -63,6 +65,10 @@ int main(void) {
|
||||
uint64_t h; size_t n = 0; int64_t sz = 0; char b[16] = {0};
|
||||
CHECK(h_fs_OpenFile(&h, "rom:/data/a", MODE_READ) == RES_OK && h_fs_ReadFile(&n, h, 3, b, 10) == RES_OK && n == 2 && !memcmp(b, "lo", 2), "a read stops at the end of the file (got %zu)", n);
|
||||
CHECK(h_fs_GetFileSize(&sz, h) == RES_OK && sz == 5 && h_fs_GetFileOpenMode(h) == MODE_READ, "size 5, open for reading"); h_fs_CloseFile(h);
|
||||
// entry 4: its index has low bits set, which Metroid Prime 4's file device masks off (handle & ~7) as it may of a Horizon pointer
|
||||
CHECK(h_fs_OpenFile(&h, "rom:/data/c", MODE_READ) == RES_OK && !(h & 15) && h_fs_ReadFile(&n, h & ~7ull, 0, b, 10) == RES_OK && n == 2 && !memcmp(b, "xy", 2), "entry 4 still reads after its handle's low bits are masked off (%#llx)", (unsigned long long)h);
|
||||
CHECK(h_fs_GetFileSize(&sz, h & ~7ull) == RES_OK && sz == 2, "and is 2 bytes"); h_fs_CloseFile(h & ~7ull);
|
||||
CHECK(read_fs("rom:\\data\\c", got, sizeof got) && !strcmp(got, "xy") && read_fs("rom:\\data\\..\\data\\a", got, sizeof got) && !strcmp(got, "hello"), "backslash paths, also through ..");
|
||||
CHECK(h_fs_OpenFile(&h, "rom:/data/x", MODE_READ) == RES_PATH_NOT_FOUND, "a missing file is not found");
|
||||
CHECK(h_fs_OpenFile(&h, "rom:/data/A", MODE_READ) == RES_PATH_NOT_FOUND, "names are case-sensitive");
|
||||
CHECK(h_fs_OpenFile(&h, "rom:/data/b", MODE_READ) == RES_PATH_NOT_FOUND, "a directory does not open as a file");
|
||||
@@ -82,6 +88,8 @@ int main(void) {
|
||||
CHECK(h_fs_OpenDirectory(&h, "rom:/data", DIRMODE_DIR | DIRMODE_FILE) == RES_OK && h_fs_ReadDirectory(&cnt, de, h, 4) == RES_OK && cnt == 4, "the listing merges both, once each (%lld)", (long long)cnt);
|
||||
int seen = 0; for (int i = 0; i < cnt; i++) { if (!strcmp(de[i].name, "a")) seen += de[i].size == 3; if (!strcmp(de[i].name, "b")) seen += de[i].type == ENT_DIR; if (!strcmp(de[i].name, "c")) seen += de[i].size == 2; if (!strcmp(de[i].name, "new")) seen += de[i].size == 5; }
|
||||
CHECK(seen == 4, "with the right types and sizes"); h_fs_CloseDirectory(h);
|
||||
CHECK(read_fs("rom:\\data\\a", got, sizeof got) && !strcmp(got, "mod") && read_fs("rom:\\data\\c", got, sizeof got) && !strcmp(got, "xy"), "backslash paths reach the overlay folder and the image");
|
||||
h = 0; cnt = -1; CHECK(h_fs_OpenDirectory(&h, "rom:\\data", DIRMODE_DIR | DIRMODE_FILE) == RES_OK && h_fs_DirCount(&cnt, h) == RES_OK && cnt == 4, "and list the merged directory (%lld)", (long long)cnt); h_fs_CloseDirectory(h);
|
||||
unsetenv("DM_ROMFS_OVERLAY"); g_nmnt = 0;
|
||||
snprintf(fn, sizeof fn, "%s/2.img", root); CHECK(!link(ip, fn), "stage a DLC image"); setenv("DM_AOC_DIR", root, 1);
|
||||
size_t cache = 0;
|
||||
@@ -175,6 +183,14 @@ int main(void) {
|
||||
CHECK(h_fs_MountSave("save", NULL) == RES_OK && write_save("save:/a", "ok3") == RES_OK && h_fs_Commit("save") == RES_OK, "remount without injection: transactional as usual, writing a=ok3 and committing succeed");
|
||||
snprintf(p, sizeof p, "%s/a", save); CHECK(same(p, "ok3"), "committed a = ok3");
|
||||
|
||||
printf("⑦ backslash paths on a save\n");
|
||||
{ uint64_t h; DirectoryEntry de[4]; int64_t cnt = 0; int32_t t = -1;
|
||||
CHECK(h_fs_CreateDirectory("save:\\dir") == RES_OK && h_fs_CreateFile("save:\\dir\\f", 0) == RES_OK && write_save("save:\\dir\\f", "bs") == RES_OK, "create and write save:\\dir\\f");
|
||||
CHECK(read_fs("save:/dir/f", got, sizeof got) && !strcmp(got, "bs"), "it is save:/dir/f");
|
||||
CHECK(h_fs_RenameFile("save:\\dir\\f", "save:\\dir\\g") == RES_OK && h_fs_GetEntryType(&t, "save:/dir/g") == RES_OK && t == ENT_FILE, "rename by backslash path");
|
||||
h = 0; CHECK(h_fs_OpenDirectory(&h, "save:\\dir", DIRMODE_FILE) == RES_OK && h_fs_ReadDirectory(&cnt, de, h, 4) == RES_OK && cnt == 1 && !strcmp(de[0].name, "g"), "the directory lists g, not a name with backslashes (%s)", cnt ? de[0].name : "-"); h_fs_CloseDirectory(h);
|
||||
}
|
||||
|
||||
|
||||
char cmd[1200]; snprintf(cmd, sizeof cmd, "rm -rf '%s'", root); system(cmd);
|
||||
printf("== %d checks, %d failed ==\n", checks, fails);
|
||||
|
||||
@@ -259,7 +259,7 @@ int main(void) {
|
||||
CHECK(h_fs_OpenFile(&io.h, "alias:/a", MODE_WRITE) == RES_OK, "open alias for overlapping I/O");
|
||||
CHECK(h_fs_SetFileSize(io.h, 3) == RES_OK, "truncate A before overlapping I/O");
|
||||
pthread_mutex_lock(&io_lock);
|
||||
block_fd = (int)io.h; block_op = op; block_entered = block_release = 0;
|
||||
block_fd = (int)FH_IN(io.h); block_op = op; block_entered = block_release = 0;
|
||||
pthread_mutex_unlock(&io_lock);
|
||||
pthread_t writer, committer;
|
||||
if (pthread_create(&writer, NULL, blocked_save_io, &io)) return 2;
|
||||
|
||||
@@ -123,6 +123,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
|
||||
- abort in `sm::Initialize` under `nn::friends::GetBlockedUserList` after the opening movie. → [SDK 4's `friends::GetBlockedUserList` without a `Uid`](../reference/services.md#sdk-4s-friendsgetblockeduserlist-without-a-uid)
|
||||
- the first loading screen never ends; `DM_FS=1` shows `save:/system` "not found" and no `fs mount save`. → [SDK 6's `account::OpenPreselectedUser` returns a Result](../reference/services.md#sdk-6s-accountopenpreselecteduser-returns-a-result)
|
||||
- IL2CPP "Could not open …/global-metadata.dat" (then a crash in its logger). → [The SDK's own `fs::IsMounted` reads an empty mount table](../reference/services.md#the-sdks-own-fsismounted-reads-an-empty-mount-table)
|
||||
- a 10-byte read of the wrong RomFS file, then a null pointer at boot; files named `rom:\StartupUI.pak` are not found. → [File handles with low bits set, and backslash paths](../reference/services.md#file-handles-with-low-bits-set-and-backslash-paths)
|
||||
- Addressables never start (no `StreamingAssets/aa/settings.json` in the `DM_FS=1` output at all), then a null asset crash (`main+0x31100ec`). → [C library path checks ask the file system's limits](../reference/services.md#c-library-path-checks-ask-the-file-systems-limits)
|
||||
- an Atk task aborts in a `switch` default (`UnexpectedDefaultImpl`, then `AbortImpl`) while a stream sound loads. → [Paths with `.` and `..` components](../reference/services.md#paths-with--and--components)
|
||||
- a long black screen at boot with nothing in the log (Engage: about 17 s on the Mac, 32 s on an iPhone); sampling the process (`sample <pid> 3`) shows `getxattr` under `path_component` at the top of stack. → [RomFS lookups on large directories](../reference/services.md#romfs-lookups-on-large-directories)
|
||||
|
||||
@@ -87,6 +87,13 @@ Most service calls can be found before they crash, before the first boot or the
|
||||
- **Fix:** answer from the host's mount table (`hle_fs.c`).
|
||||
- **Note:** the C library's path checks read the same empty table through `IsPathMounted` ([C library path checks ask the file system's limits](#c-library-path-checks-ask-the-file-systems-limits)).
|
||||
|
||||
### File handles with low bits set, and backslash paths
|
||||
|
||||
- **Symptom:** a 10-byte read of the wrong RomFS file, then a null pointer at boot; files named `rom:\StartupUI.pak` are not found.
|
||||
- **Cause:** on Horizon a `FileHandle` is a pointer to the SDK's `FileAccessor`, a heap object, so its low bits are clear, and a game's file device may mask them off (`handle & ~7`) before `ReadFile`. The host's RomFS-image handle kept the entry index in its low bits, so entry 7 was read as entry 0. Separately, Horizon's file system accessor turns every backslash in a path into a slash before it normalizes the path (`FileSystemAccessor::SetUpPath`, on every mount except the PC host's); the host treated a backslash as part of a name.
|
||||
- **Fix:** the guest gets the host's handle shifted left by 4, 16-byte aligned like an AArch64 heap block (`FH_OUT` / `FH_IN`). Each guest path resolver (`img_path`, `host_path_ex`, `set_guest_name`, `dir_snapshot`) turns backslashes into slashes first, so overlays, `..` and guest names see the same path (`hle_fs.c`; `dm/host/tests/t_fs.c`).
|
||||
- **Found on:** Metroid Prime 4: Beyond (SDK 19; bring-up in [issue #229](https://github.com/seedds/nxnative/issues/229), from [PR #513](https://github.com/seedds/nxnative/pull/513)); not in the games table yet.
|
||||
|
||||
### C library path checks ask the file system's limits
|
||||
|
||||
- **Symptom:** Addressables never start (no `StreamingAssets/aa/settings.json` in the `DM_FS=1` output at all), then a null asset crash (`main+0x31100ec`).
|
||||
|
||||
Reference in new issue
Block a user