Skip to content

Commit f658e8b

Browse files
committed
Support across the board
1 parent 61a05fb commit f658e8b

20 files changed

+116
-227
lines changed

packages/php-wasm/compile/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ RUN echo -n ' -s ASYNCIFY=1 -s ASYNCIFY_IGNORE_INDIRECT=1 ' >> /root/.emcc-php-w
709709
"ZEND_ISSET_ISEMPTY_PROP_OBJ_SPEC_TMPVAR_CONST_HANDLER",\
710710
"ZEND_ISSET_ISEMPTY_PROP_OBJ_SPEC_TMPVAR_HANDLER",\
711711
"cli",\
712+
"wasm_sleep",\
712713
"wasm_php_exec",\
713714
"wasm_sapi_handle_request",\
714715
"_call_user_function_ex",\
@@ -957,6 +958,7 @@ RUN source /root/emsdk/emsdk_env.sh && \
957958
"_phpwasm_destroy_uploaded_files_hash", \n\
958959
"_phpwasm_init_uploaded_files_hash", \n\
959960
"_phpwasm_register_uploaded_file", \n\
961+
"_emscripten_sleep", \n\
960962
"_wasm_sleep", \n\
961963
"_wasm_set_phpini_path", \n\
962964
"_wasm_set_phpini_entries", \n\

packages/php-wasm/compile/build-assets/proc_open7.0.c

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
+----------------------------------------------------------------------+
33
| PHP Version 7 |
44
+----------------------------------------------------------------------+
5-
| Copyright (c) 1997-2017 The PHP Group |
5+
| Copyright (c) 1997-2018 The PHP Group |
66
+----------------------------------------------------------------------+
77
| This source file is subject to version 3.01 of the PHP license, |
88
| that is bundled with this package in the file LICENSE, and is |
@@ -15,13 +15,12 @@
1515
| Author: Wez Furlong <wez@thebrainroom.com> |
1616
+----------------------------------------------------------------------+
1717
*/
18-
/* $Id$ */
1918

2019
#if 0 && (defined(__linux__) || defined(sun) || defined(__IRIX__))
2120
# define _BSD_SOURCE /* linux wants this when XOPEN mode is on */
22-
# define _BSD_COMPAT /* irix: uint */
21+
# define _BSD_COMPAT /* irix: uint32_t */
2322
# define _XOPEN_SOURCE 500 /* turn on Unix98 */
24-
# define __EXTENSIONS__ 1 /* Solaris: uint */
23+
# define __EXTENSIONS__ 1 /* Solaris: uint32_t */
2524
#endif
2625

2726
#include "php.h"
@@ -36,11 +35,6 @@
3635
#include "SAPI.h"
3736
#include "main/php_network.h"
3837

39-
#ifdef NETWARE
40-
#include <proc.h>
41-
#include <library.h>
42-
#endif
43-
4438
#if HAVE_SYS_WAIT_H
4539
#include <sys/wait.h>
4640
#endif
@@ -60,7 +54,6 @@
6054
* Other platforms may modify that configure check and add suitable #ifdefs
6155
* around the alternate code.
6256
* */
63-
6457
#if 0 && HAVE_PTSNAME && HAVE_GRANTPT && HAVE_UNLOCKPT && HAVE_SYS_IOCTL_H && HAVE_TERMIOS_H
6558
# include <sys/ioctl.h>
6659
# include <termios.h>
@@ -108,7 +101,11 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
108101
str = zval_get_string(element);
109102

110103
if (ZSTR_LEN(str) == 0) {
104+
#if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 3)
105+
zend_string_release_ex(str, 0);
106+
#else
111107
zend_string_release(str);
108+
#endif
112109
continue;
113110
}
114111

@@ -147,10 +144,14 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
147144
#endif
148145
p += ZSTR_LEN(str) + 1;
149146
}
150-
zend_string_release(str);
147+
#if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 3)
148+
zend_string_release_ex(str, 0);
149+
#else
150+
zend_string_release(str);
151+
#endif
151152
} ZEND_HASH_FOREACH_END();
152153

153-
assert((uint)(p - env.envp) <= sizeenv);
154+
assert((uint32_t)(p - env.envp) <= sizeenv);
154155

155156
zend_hash_destroy(env_hash);
156157
FREE_HASHTABLE(env_hash);
@@ -189,10 +190,10 @@ static void proc_open_rsrc_dtor(zend_resource *rsrc)
189190
/* Close all handles to avoid a deadlock */
190191
for (i = 0; i < proc->npipes; i++) {
191192
if (proc->pipes[i] != 0) {
192-
#if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION < 3)
193-
GC_REFCOUNT(proc->pipes[i])--;
194-
#else
193+
#if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 3)
195194
GC_DELREF(proc->pipes[i]);
195+
#else
196+
GC_REFCOUNT(proc->pipes[i])--;
196197
#endif
197198
zend_list_close(proc->pipes[i]);
198199
proc->pipes[i] = 0;
@@ -247,17 +248,19 @@ PHP_MINIT_FUNCTION(proc_open)
247248
}
248249
/* }}} */
249250

250-
/* {{{ proto bool proc_terminate(resource process [, long signal])
251+
/* {{{ proto bool proc_terminate(resource process [, int signal])
251252
kill a process opened by proc_open */
252253
PHP_FUNCTION(proc_terminate)
253254
{
254255
zval *zproc;
255256
struct php_process_handle *proc;
256257
zend_long sig_no = SIGTERM;
257258

258-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &zproc, &sig_no) == FAILURE) {
259-
RETURN_FALSE;
260-
}
259+
ZEND_PARSE_PARAMETERS_START(1, 2)
260+
Z_PARAM_RESOURCE(zproc)
261+
Z_PARAM_OPTIONAL
262+
Z_PARAM_LONG(sig_no)
263+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
261264

262265
if ((proc = (struct php_process_handle *)zend_fetch_resource(Z_RES_P(zproc), "process", le_proc_open)) == NULL) {
263266
RETURN_FALSE;
@@ -286,9 +289,9 @@ PHP_FUNCTION(proc_close)
286289
zval *zproc;
287290
struct php_process_handle *proc;
288291

289-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zproc) == FAILURE) {
290-
RETURN_FALSE;
291-
}
292+
ZEND_PARSE_PARAMETERS_START(1, 1)
293+
Z_PARAM_RESOURCE(zproc)
294+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
292295

293296
if ((proc = (struct php_process_handle *)zend_fetch_resource(Z_RES_P(zproc), "process", le_proc_open)) == NULL) {
294297
RETURN_FALSE;
@@ -316,9 +319,9 @@ PHP_FUNCTION(proc_get_status)
316319
int running = 1, signaled = 0, stopped = 0;
317320
int exitcode = -1, termsig = 0, stopsig = 0;
318321

319-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zproc) == FAILURE) {
320-
RETURN_FALSE;
321-
}
322+
ZEND_PARSE_PARAMETERS_START(1, 1)
323+
Z_PARAM_RESOURCE(zproc)
324+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
322325

323326
if ((proc = (struct php_process_handle *)zend_fetch_resource(Z_RES_P(zproc), "process", le_proc_open)) == NULL) {
324327
RETURN_FALSE;
@@ -349,11 +352,8 @@ PHP_FUNCTION(proc_get_status)
349352
if (WIFSIGNALED(wstatus)) {
350353
running = 0;
351354
signaled = 1;
352-
#ifdef NETWARE
353-
termsig = WIFTERMSIG(wstatus);
354-
#else
355+
355356
termsig = WTERMSIG(wstatus);
356-
#endif
357357
}
358358
if (WIFSTOPPED(wstatus)) {
359359
stopped = 1;
@@ -424,6 +424,7 @@ PHP_FUNCTION(proc_open)
424424
php_process_env_t env;
425425
int ndesc = 0;
426426
int i;
427+
int current_procopen_call_id = ++procopen_call_id;
427428
zval *descitem = NULL;
428429
zend_string *str_index;
429430
zend_ulong nindex;
@@ -432,20 +433,14 @@ PHP_FUNCTION(proc_open)
432433
#ifdef PHP_WIN32
433434
PROCESS_INFORMATION pi;
434435
HANDLE childHandle;
435-
STARTUPINFO si;
436+
STARTUPINFOW si;
436437
BOOL newprocok;
437438
SECURITY_ATTRIBUTES security;
438439
DWORD dwCreateFlags = 0;
439-
char *command_with_cmd;
440440
UINT old_error_mode;
441441
char cur_cwd[MAXPATHLEN];
442-
#endif
443-
#ifdef NETWARE
444-
char** child_argv = NULL;
445-
char* command_dup = NULL;
446-
char* orig_cwd = NULL;
447-
int command_num_args = 0;
448-
wiring_t channel;
442+
wchar_t *cmdw = NULL, *cwdw = NULL, *envpw = NULL;
443+
size_t tmp_len;
449444
#endif
450445
php_process_id_t child;
451446
struct php_process_handle *proc;
@@ -459,13 +454,16 @@ PHP_FUNCTION(proc_open)
459454
php_file_descriptor_t dev_ptmx = -1; /* master */
460455
php_file_descriptor_t slave_pty = -1;
461456
#endif
462-
463-
int current_procopen_call_id = ++procopen_call_id;
464-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "saz/|s!a!a!", &command,
465-
&command_len, &descriptorspec, &pipes, &cwd, &cwd_len, &environment,
466-
&other_options) == FAILURE) {
467-
RETURN_FALSE;
468-
}
457+
458+
ZEND_PARSE_PARAMETERS_START(3, 6)
459+
Z_PARAM_STRING(command, command_len)
460+
Z_PARAM_ARRAY(descriptorspec)
461+
Z_PARAM_ZVAL_DEREF(pipes)
462+
Z_PARAM_OPTIONAL
463+
Z_PARAM_STRING_EX(cwd, cwd_len, 1, 0)
464+
Z_PARAM_ARRAY_EX(environment, 1, 0)
465+
Z_PARAM_ARRAY_EX(other_options, 1, 0)
466+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
469467

470468
command = pestrdup(command, is_persistent);
471469

@@ -547,7 +545,7 @@ PHP_FUNCTION(proc_open)
547545
#else
548546
descriptors[ndesc].childend = dup(fd);
549547
if (descriptors[ndesc].childend < 0) {
550-
php_error_docref(NULL, E_WARNING, "unable to dup File-Handle for descriptor %pd - %s", nindex, strerror(errno));
548+
php_error_docref(NULL, E_WARNING, "unable to dup File-Handle for descriptor " ZEND_ULONG_FMT " - %s", nindex, strerror(errno));
551549
goto exit_fail;
552550
}
553551
#endif
@@ -592,15 +590,15 @@ PHP_FUNCTION(proc_open)
592590
descriptors[ndesc].childend = current_procopen_call_id;
593591
descriptors[ndesc].parentend = open(device_path, O_WRONLY);
594592
} else {
595-
if (strncmp(Z_STRVAL_P(zmode), "w", 1) != 0) {
596-
descriptors[ndesc].parentend = newpipe[1];
597-
descriptors[ndesc].childend = newpipe[0];
598-
descriptors[ndesc].mode |= DESC_PARENT_MODE_WRITE;
599-
} else {
600-
descriptors[ndesc].parentend = newpipe[0];
601-
descriptors[ndesc].childend = newpipe[1];
602-
}
603-
}
593+
if (strncmp(Z_STRVAL_P(zmode), "w", 1) != 0) {
594+
descriptors[ndesc].parentend = newpipe[1];
595+
descriptors[ndesc].childend = newpipe[0];
596+
descriptors[ndesc].mode |= DESC_PARENT_MODE_WRITE;
597+
} else {
598+
descriptors[ndesc].parentend = newpipe[0];
599+
descriptors[ndesc].childend = newpipe[1];
600+
}
601+
}
604602
#ifdef PHP_WIN32
605603
/* don't let the child inherit the parent side of the pipe */
606604
descriptors[ndesc].parentend = dup_handle(descriptors[ndesc].parentend, FALSE, TRUE);
@@ -689,6 +687,7 @@ PHP_FUNCTION(proc_open)
689687
ndesc++;
690688
} ZEND_HASH_FOREACH_END();
691689

690+
692691
// the wasm way {{{
693692
js_open_process(
694693
command,
@@ -698,7 +697,7 @@ PHP_FUNCTION(proc_open)
698697
descriptors[2].childend,
699698
descriptors[2].parentend
700699
);
701-
// }}}
700+
// }}}
702701
/* we forked/spawned and this is the parent */
703702

704703
proc = (struct php_process_handle*)pemalloc(sizeof(struct php_process_handle), is_persistent);
@@ -712,10 +711,7 @@ PHP_FUNCTION(proc_open)
712711
#endif
713712
proc->env = env;
714713

715-
if (pipes != NULL) {
716-
zval_dtor(pipes);
717-
}
718-
714+
zval_ptr_dtor(pipes);
719715
array_init(pipes);
720716

721717
#if PHP_CAN_DO_PTS
@@ -791,6 +787,11 @@ PHP_FUNCTION(proc_open)
791787
efree(descriptors);
792788
_php_free_envp(env, is_persistent);
793789
pefree(command, is_persistent);
790+
#ifdef PHP_WIN32
791+
free(cwdw);
792+
free(cmdw);
793+
free(envpw);
794+
#endif
794795
#if PHP_CAN_DO_PTS
795796
if (dev_ptmx >= 0) {
796797
close(dev_ptmx);
@@ -803,12 +804,3 @@ PHP_FUNCTION(proc_open)
803804

804805
}
805806
/* }}} */
806-
807-
/*
808-
* Local variables:
809-
* tab-width: 4
810-
* c-basic-offset: 4
811-
* End:
812-
* vim600: sw=4 ts=4 fdm=marker
813-
* vim<600: sw=4 ts=4
814-
*/

0 commit comments

Comments
 (0)