Skip to content

Commit 60554a9

Browse files
committed
Move to user space params that require less php-wasm recompilation
1 parent 38cdd83 commit 60554a9

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

packages/php-wasm/universal/src/lib/os-user-space.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,23 @@ export type OSUserSpaceContext = {
6464
HEAPU64: BigUint64Array;
6565
HEAPF64: Float64Array;
6666
};
67-
builtins: {
68-
fd_close: (fd: number) => number;
69-
fcntl64: (fd: number, cmd: number, varargs?: any) => number;
70-
getStreamFromFD: (fd: number) => Emscripten.FS.FSStream;
67+
wasmImports: {
68+
builtin_fcntl64: (fd: number, cmd: number, varargs?: any) => number;
69+
builtin_fd_close: (fd: number) => number;
70+
};
71+
wasmExports: {
72+
wasm_get_end_offset: (fd: number) => bigint;
7173
};
72-
helpers: {
73-
get_end_offset_for_fd: (fd: number) => bigint;
74+
syscalls: {
75+
getStreamFromFD: (fd: number) => Emscripten.FS.FSStream;
7476
};
7577
FS: typeof Emscripten.FS;
7678
PROXYFS: typeof Emscripten.PROXYFS & {
79+
// TODO: Add this method to our main Emscripten FS types
7780
realPath(node: FSNode): string;
7881
};
7982
NODEFS: typeof Emscripten.NODEFS & {
83+
// TODO: Add this method to our main Emscripten FS types
8084
realPath(node: FSNode): string;
8185
};
8286
// TODO: Likely rename this. There's no reason it should be different from the rest of the names.
@@ -87,6 +91,7 @@ export function bindUserSpace(
8791
{ fileLockManager }: OSKernelSpace,
8892
{
8993
pid,
94+
memory: { HEAP16, HEAP64, HEAP32 },
9095
constants: {
9196
F_RDLCK,
9297
F_WRLCK,
@@ -110,9 +115,9 @@ export function bindUserSpace(
110115
LOCK_UN,
111116
},
112117
errnoCodes: { EBADF, EINVAL, EAGAIN, EDEADLK, EWOULDBLOCK },
113-
memory: { HEAP16, HEAP64, HEAP32 },
114-
builtins,
115-
helpers,
118+
wasmImports: { builtin_fcntl64, builtin_fd_close },
119+
wasmExports: { wasm_get_end_offset },
120+
syscalls: { getStreamFromFD },
116121
FS,
117122
PROXYFS,
118123
NODEFS,
@@ -187,7 +192,7 @@ export function bindUserSpace(
187192
return false;
188193
},
189194
get_fd_access_mode(fd: number) {
190-
return builtins.fcntl64(fd, F_GETFL) & O_ACCMODE;
195+
return builtin_fcntl64(fd, F_GETFL) & O_ACCMODE;
191196
},
192197
get_vfs_path_from_fd(fd: number): ResultTuple<string> {
193198
try {
@@ -370,7 +375,7 @@ export function bindUserSpace(
370375
break;
371376
case SEEK_CUR:
372377
try {
373-
const stream = builtins.getStreamFromFD(fd);
378+
const stream = getStreamFromFD(fd);
374379
baseAddress = FS.llseek(stream, 0, whence);
375380
} catch (e) {
376381
_js_wasm_trace(
@@ -384,7 +389,7 @@ export function bindUserSpace(
384389
}
385390
break;
386391
case SEEK_END:
387-
baseAddress = helpers.get_end_offset_for_fd(fd);
392+
baseAddress = wasm_get_end_offset(fd);
388393
break;
389394
default:
390395
return [null, EINVAL];
@@ -676,7 +681,7 @@ export function bindUserSpace(
676681
arg = varArgsAccessor.getNextAsInt();
677682
}
678683

679-
const stream = builtins.getStreamFromFD(fd);
684+
const stream = getStreamFromFD(fd);
680685

681686
// Update the stream flags
682687
const SETFL_MASK = O_APPEND | O_NONBLOCK;
@@ -686,7 +691,7 @@ export function bindUserSpace(
686691
return 0;
687692
}
688693
default:
689-
return builtins.fcntl64(fd, cmd, varargs);
694+
return builtin_fcntl64(fd, cmd, varargs);
690695
}
691696
}
692697

@@ -805,7 +810,7 @@ export function bindUserSpace(
805810
const [vfsPath, vfsPathResolutionErrno] =
806811
locking.get_vfs_path_from_fd(fd);
807812

808-
const fdCloseResult = builtins.fd_close(fd);
813+
const fdCloseResult = builtin_fd_close(fd);
809814
if (fdCloseResult !== 0 || !locking.maybeLockedFds.has(fd)) {
810815
_js_wasm_trace('fd_close(%d) result %d', fd, fdCloseResult);
811816
return fdCloseResult;

0 commit comments

Comments
 (0)