Skip to content

Support proc_open(), exec(), passthru(), system() #596

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 17 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bale out on empty buffer
  • Loading branch information
adamziel committed Oct 24, 2023
commit d17f211491147bb0d9915cc2b081b2877f68838b
20 changes: 20 additions & 0 deletions packages/php-wasm/compile/build-assets/php7.3.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
diff --git a/php-src/main/streams/plain_wrapper.c b/php-src/main/streams/plain_wrapper.c
index 4d10e688b5..ca50261b8a 100644
--- a/php-src/main/streams/plain_wrapper.c
+++ b/php-src/main/streams/plain_wrapper.c
@@ -408,6 +408,15 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count)
}
#endif
ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
+ if(
+ (errno == EAGAIN || errno == EWOULDBLOCK) &&
+ (stream->flags & O_NONBLOCK) == 0
+ ) {
+ /* This is a blocking read in C but not in Emscripten.
+ Let's poll for data and try once again */
+ php_pollfd_for(data->fd, POLLIN, NULL);
+ ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count));
+ }

if (ret == (size_t)-1 && errno == EINTR) {
/* Read was interrupted, retry once,
diff --git a/php-src/ext/pdo_sqlite/sqlite_statement.c b/php-src/ext/pdo_sqlite/sqlite_statement.c
--- a/php-src/ext/pdo_sqlite/sqlite_statement.c
+++ b/php-src/ext/pdo_sqlite/sqlite_statement.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,13 @@ const LibraryExample = {
const bytesRead = stdinStream.stream_ops.read(stdinStream, buffer, offset, CHUNK_SIZE, null);
if (bytesRead === null || bytesRead === 0) {
break;
}
cp.stdin.write(buffer.subarray(0, bytesRead));
}
try {
cp.stdin.write(buffer.subarray(0, bytesRead));
} catch (e) {
console.error(e);
return 1;
}
if (bytesRead < CHUNK_SIZE) {
break;
}
Expand Down
27 changes: 16 additions & 11 deletions packages/php-wasm/node/public/php_7_0.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dependencyFilename = __dirname + '/php_7_0.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 10399832;
export const dependenciesTotalSize = 11344783;
export function init(RuntimeName, PHPLoader) {
/**
* Overrides Emscripten's default ExitStatus object which gets
Expand Down Expand Up @@ -5533,10 +5533,15 @@ function _js_open_process(command, procopenCallId, stdoutChildFd, stdoutParentFd
let offset = 0;
while (true) {
const bytesRead = stdinStream.stream_ops.read(stdinStream, buffer, offset, CHUNK_SIZE, null);
if (bytesRead === null) {
if (bytesRead === null || bytesRead === 0) {
break;
}
cp.stdin.write(buffer.subarray(0, bytesRead));
try {
cp.stdin.write(buffer.subarray(0, bytesRead));
} catch (e) {
console.error(e);
return 1;
}
if (bytesRead < CHUNK_SIZE) {
break;
}
Expand Down Expand Up @@ -6604,7 +6609,7 @@ ERRNO_CODES = {
};

var asmLibraryArg = {
"j": ___assert_fail,
"k": ___assert_fail,
"Ua": ___call_sighandler,
"Ta": ___syscall__newselect,
"Sa": ___syscall_accept4,
Expand Down Expand Up @@ -6656,7 +6661,7 @@ var asmLibraryArg = {
"ea": __mmap_js,
"da": __munmap_js,
"ca": __tzset_js,
"l": _abort,
"e": _abort,
"z": _emscripten_date_now,
"ba": _emscripten_get_heap_max,
"I": _emscripten_get_now,
Expand All @@ -6678,23 +6683,23 @@ var asmLibraryArg = {
"Z": _getnameinfo,
"Y": _getprotobyname,
"X": _getprotobynumber,
"h": invoke_i,
"i": invoke_i,
"d": invoke_ii,
"b": invoke_iii,
"f": invoke_iiii,
"g": invoke_iiiii,
"g": invoke_iiii,
"h": invoke_iiiii,
"v": invoke_iiiiii,
"u": invoke_iiiiiii,
"t": invoke_iiiiiiii,
"W": invoke_iiiiiiiii,
"y": invoke_iiiiiiiiii,
"e": invoke_v,
"f": invoke_v,
"a": invoke_vi,
"c": invoke_vii,
"k": invoke_viii,
"l": invoke_viii,
"q": invoke_viiii,
"m": invoke_viiiii,
"i": invoke_viiiiii,
"j": invoke_viiiiii,
"x": invoke_viiiiiiiii,
"E": _js_create_input_device,
"V": _js_module_onMessage,
Expand Down
Binary file modified packages/php-wasm/node/public/php_7_0.wasm
Binary file not shown.
29 changes: 17 additions & 12 deletions packages/php-wasm/node/public/php_7_1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dependencyFilename = __dirname + '/php_7_1.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 10594129;
export const dependenciesTotalSize = 11539083;
export function init(RuntimeName, PHPLoader) {
/**
* Overrides Emscripten's default ExitStatus object which gets
Expand Down Expand Up @@ -5533,10 +5533,15 @@ function _js_open_process(command, procopenCallId, stdoutChildFd, stdoutParentFd
let offset = 0;
while (true) {
const bytesRead = stdinStream.stream_ops.read(stdinStream, buffer, offset, CHUNK_SIZE, null);
if (bytesRead === null) {
if (bytesRead === null || bytesRead === 0) {
break;
}
cp.stdin.write(buffer.subarray(0, bytesRead));
try {
cp.stdin.write(buffer.subarray(0, bytesRead));
} catch (e) {
console.error(e);
return 1;
}
if (bytesRead < CHUNK_SIZE) {
break;
}
Expand Down Expand Up @@ -6604,7 +6609,7 @@ ERRNO_CODES = {
};

var asmLibraryArg = {
"j": ___assert_fail,
"k": ___assert_fail,
"Ua": ___call_sighandler,
"Ta": ___syscall__newselect,
"Sa": ___syscall_accept4,
Expand Down Expand Up @@ -6656,7 +6661,7 @@ var asmLibraryArg = {
"da": __mmap_js,
"ca": __munmap_js,
"ba": __tzset_js,
"m": _abort,
"e": _abort,
"z": _emscripten_date_now,
"aa": _emscripten_get_heap_max,
"I": _emscripten_get_now,
Expand All @@ -6678,22 +6683,22 @@ var asmLibraryArg = {
"Y": _getnameinfo,
"X": _getprotobyname,
"W": _getprotobynumber,
"h": invoke_i,
"i": invoke_i,
"d": invoke_ii,
"b": invoke_iii,
"f": invoke_iiii,
"g": invoke_iiiii,
"g": invoke_iiii,
"h": invoke_iiiii,
"v": invoke_iiiiii,
"s": invoke_iiiiiii,
"u": invoke_iiiiiiii,
"y": invoke_iiiiiiiiii,
"e": invoke_v,
"f": invoke_v,
"a": invoke_vi,
"c": invoke_vii,
"l": invoke_viii,
"k": invoke_viiii,
"m": invoke_viii,
"l": invoke_viiii,
"n": invoke_viiiii,
"i": invoke_viiiiii,
"j": invoke_viiiiii,
"x": invoke_viiiiiiiii,
"E": _js_create_input_device,
"V": _js_module_onMessage,
Expand Down
Binary file modified packages/php-wasm/node/public/php_7_1.wasm
Binary file not shown.
31 changes: 18 additions & 13 deletions packages/php-wasm/node/public/php_7_2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dependencyFilename = __dirname + '/php_7_2.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 11001872;
export const dependenciesTotalSize = 11946679;
export function init(RuntimeName, PHPLoader) {
/**
* Overrides Emscripten's default ExitStatus object which gets
Expand Down Expand Up @@ -5533,10 +5533,15 @@ function _js_open_process(command, procopenCallId, stdoutChildFd, stdoutParentFd
let offset = 0;
while (true) {
const bytesRead = stdinStream.stream_ops.read(stdinStream, buffer, offset, CHUNK_SIZE, null);
if (bytesRead === null) {
if (bytesRead === null || bytesRead === 0) {
break;
}
cp.stdin.write(buffer.subarray(0, bytesRead));
try {
cp.stdin.write(buffer.subarray(0, bytesRead));
} catch (e) {
console.error(e);
return 1;
}
if (bytesRead < CHUNK_SIZE) {
break;
}
Expand Down Expand Up @@ -6604,7 +6609,7 @@ ERRNO_CODES = {
};

var asmLibraryArg = {
"j": ___assert_fail,
"k": ___assert_fail,
"Va": ___call_sighandler,
"Ua": ___syscall__newselect,
"Ta": ___syscall_accept4,
Expand Down Expand Up @@ -6656,7 +6661,7 @@ var asmLibraryArg = {
"ea": __mmap_js,
"da": __munmap_js,
"ca": __tzset_js,
"n": _abort,
"e": _abort,
"B": _emscripten_date_now,
"ba": _emscripten_get_heap_max,
"K": _emscripten_get_now,
Expand All @@ -6678,23 +6683,23 @@ var asmLibraryArg = {
"Z": _getnameinfo,
"Y": _getprotobyname,
"X": _getprotobynumber,
"h": invoke_i,
"i": invoke_i,
"d": invoke_ii,
"b": invoke_iii,
"f": invoke_iiii,
"g": invoke_iiiii,
"g": invoke_iiii,
"h": invoke_iiiii,
"u": invoke_iiiiii,
"s": invoke_iiiiiii,
"v": invoke_iiiiiiii,
"A": invoke_iiiiiiiiii,
"e": invoke_v,
"f": invoke_v,
"a": invoke_vi,
"c": invoke_vii,
"z": invoke_viidii,
"l": invoke_viii,
"k": invoke_viiii,
"m": invoke_viiiii,
"i": invoke_viiiiii,
"m": invoke_viii,
"l": invoke_viiii,
"n": invoke_viiiii,
"j": invoke_viiiiii,
"y": invoke_viiiiiiiii,
"G": _js_create_input_device,
"W": _js_module_onMessage,
Expand Down
Binary file modified packages/php-wasm/node/public/php_7_2.wasm
Binary file not shown.
43 changes: 24 additions & 19 deletions packages/php-wasm/node/public/php_7_3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dependencyFilename = __dirname + '/php_7_3.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 10925307;
export const dependenciesTotalSize = 11870309;
export function init(RuntimeName, PHPLoader) {
/**
* Overrides Emscripten's default ExitStatus object which gets
Expand Down Expand Up @@ -5665,10 +5665,15 @@ function _js_open_process(command, procopenCallId, stdoutChildFd, stdoutParentFd
let offset = 0;
while (true) {
const bytesRead = stdinStream.stream_ops.read(stdinStream, buffer, offset, CHUNK_SIZE, null);
if (bytesRead === null) {
if (bytesRead === null || bytesRead === 0) {
break;
}
cp.stdin.write(buffer.subarray(0, bytesRead));
try {
cp.stdin.write(buffer.subarray(0, bytesRead));
} catch (e) {
console.error(e);
return 1;
}
if (bytesRead < CHUNK_SIZE) {
break;
}
Expand Down Expand Up @@ -6736,7 +6741,7 @@ ERRNO_CODES = {
};

var asmLibraryArg = {
"j": ___assert_fail,
"k": ___assert_fail,
"Wa": ___call_sighandler,
"Va": ___syscall__newselect,
"Ua": ___syscall_accept4,
Expand Down Expand Up @@ -6788,7 +6793,7 @@ var asmLibraryArg = {
"fa": __mmap_js,
"ea": __munmap_js,
"da": __tzset_js,
"n": _abort,
"e": _abort,
"C": _emscripten_date_now,
"ca": _emscripten_get_heap_max,
"B": _emscripten_get_now,
Expand All @@ -6811,23 +6816,23 @@ var asmLibraryArg = {
"I": _getnameinfo,
"Z": _getprotobyname,
"Y": _getprotobynumber,
"h": invoke_i,
"i": invoke_i,
"d": invoke_ii,
"b": invoke_iii,
"f": invoke_iiii,
"g": invoke_iiiii,
"g": invoke_iiii,
"h": invoke_iiiii,
"u": invoke_iiiiii,
"t": invoke_iiiiiii,
"v": invoke_iiiiiiii,
"A": invoke_iiiiiiiiii,
"e": invoke_v,
"f": invoke_v,
"a": invoke_vi,
"c": invoke_vii,
"z": invoke_viidii,
"l": invoke_viii,
"k": invoke_viiii,
"m": invoke_viiiii,
"i": invoke_viiiiii,
"m": invoke_viii,
"l": invoke_viiii,
"n": invoke_viiiii,
"j": invoke_viiiiii,
"y": invoke_viiiiiiiii,
"H": _js_create_input_device,
"X": _js_module_onMessage,
Expand Down Expand Up @@ -6863,16 +6868,16 @@ var ___errno_location = Module["___errno_location"] = function() {
return (___errno_location = Module["___errno_location"] = Module["asm"]["bb"]).apply(null, arguments);
};

var _fflush = Module["_fflush"] = function() {
return (_fflush = Module["_fflush"] = Module["asm"]["cb"]).apply(null, arguments);
var _php_pollfd_for = Module["_php_pollfd_for"] = function() {
return (_php_pollfd_for = Module["_php_pollfd_for"] = Module["asm"]["cb"]).apply(null, arguments);
};

var _wasm_php_exec = Module["_wasm_php_exec"] = function() {
return (_wasm_php_exec = Module["_wasm_php_exec"] = Module["asm"]["db"]).apply(null, arguments);
var _fflush = Module["_fflush"] = function() {
return (_fflush = Module["_fflush"] = Module["asm"]["db"]).apply(null, arguments);
};

var _php_pollfd_for = Module["_php_pollfd_for"] = function() {
return (_php_pollfd_for = Module["_php_pollfd_for"] = Module["asm"]["eb"]).apply(null, arguments);
var _wasm_php_exec = Module["_wasm_php_exec"] = function() {
return (_wasm_php_exec = Module["_wasm_php_exec"] = Module["asm"]["eb"]).apply(null, arguments);
};

var _htons = Module["_htons"] = function() {
Expand Down
Binary file modified packages/php-wasm/node/public/php_7_3.wasm
Binary file not shown.
Loading