From c5af324ec328b6d99971d53f7eeef1dae6bd017f Mon Sep 17 00:00:00 2001 From: Zeev Suraski Date: Wed, 21 Apr 1999 04:02:11 +0000 Subject: [PATCH] More thread safety work --- ext/standard/basic_functions.c | 1 + ext/standard/exec.c | 1 + ext/standard/file.c | 271 ++++++++++++++++++--------------- ext/standard/filestat.c | 41 +++-- ext/standard/link.c | 2 +- main.h | 7 +- main/configuration-parser.y | 5 +- main/fopen_wrappers.c | 10 +- main/main.c | 86 ++++++----- main/php.h | 2 +- main/php_globals.h | 3 + php4.dsw | 12 ++ 12 files changed, 256 insertions(+), 185 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 2c881812749bb..1417a87126c82 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1732,6 +1732,7 @@ void php3_call_user_method(INTERNAL_FUNCTION_PARAMETERS) pval **params; pval retval; int arg_count=ARG_COUNT(ht); + CLS_FETCH(); if (arg_count<2) { WRONG_PARAM_COUNT; diff --git a/ext/standard/exec.c b/ext/standard/exec.c index 3c1f05b202284..3ca66b3c9b6c2 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -342,6 +342,7 @@ PHP_FUNCTION(shell_exec) FILE *in; int readbytes,total_readbytes=0,allocated_space; pval *cmd; + PLS_FETCH(); if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &cmd)==FAILURE) { WRONG_PARAM_COUNT; diff --git a/ext/standard/file.c b/ext/standard/file.c index 5fdefec90199a..df3e48c50b0d7 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -31,6 +31,7 @@ #include "tls.h" #endif #include "php.h" +#include "php_globals.h" #include #include @@ -126,8 +127,8 @@ extern int le_uploads; # endif #endif -char * -tempnam(const char *dir, const char *pfx) + +char *tempnam(const char *dir, const char *pfx) { int save_errno; char *f, *name; @@ -172,6 +173,7 @@ tempnam(const char *dir, const char *pfx) } #endif + function_entry php3_file_functions[] = { {"pclose", php3_pclose, NULL}, {"popen", php3_popen, NULL}, @@ -208,9 +210,11 @@ php3_module_entry php3_file_module_entry = { "PHP_file", php3_file_functions, php3_minit_file, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES }; + /* {{{ proto array get_meta_tags(string filename [, int use_include_path]) Extracts all meta tag content attributes from a file and returns an array */ -void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS) { +void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS) +{ pval *filename, *arg2; FILE *fp; char buf[8192]; @@ -222,20 +226,20 @@ void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS) { /* check args */ switch (ARG_COUNT(ht)) { - case 1: - if (getParameters(ht,1,&filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (getParameters(ht,2,&filename,&arg2) == FAILURE) { + case 1: + if (getParameters(ht,1,&filename) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + case 2: + if (getParameters(ht,2,&filename,&arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg2); + use_include_path = arg2->value.lval; + break; + default: WRONG_PARAM_COUNT; - } - convert_to_long(arg2); - use_include_path = arg2->value.lval; - break; - default: - WRONG_PARAM_COUNT; } convert_to_string(filename); @@ -337,9 +341,11 @@ void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto array file(string filename) Read entire file into an array */ -void php3_file(INTERNAL_FUNCTION_PARAMETERS) { +void php3_file(INTERNAL_FUNCTION_PARAMETERS) +{ pval *filename, *arg2; FILE *fp; char *slashed, buf[8192]; @@ -350,20 +356,20 @@ void php3_file(INTERNAL_FUNCTION_PARAMETERS) { /* check args */ switch (ARG_COUNT(ht)) { - case 1: - if (getParameters(ht,1,&filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (getParameters(ht,2,&filename,&arg2) == FAILURE) { + case 1: + if (getParameters(ht,1,&filename) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + case 2: + if (getParameters(ht,2,&filename,&arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg2); + use_include_path = arg2->value.lval; + break; + default: WRONG_PARAM_COUNT; - } - convert_to_long(arg2); - use_include_path = arg2->value.lval; - break; - default: - WRONG_PARAM_COUNT; } convert_to_string(filename); @@ -408,10 +414,10 @@ void php3_file(INTERNAL_FUNCTION_PARAMETERS) { static void __pclose(FILE *pipe) { -TLS_VARS; GLOBAL(pclose_ret) = pclose(pipe); } + static void _php3_closesocket(int *sock) { int socketd=*sock; if (socketd){ @@ -424,16 +430,17 @@ static void _php3_closesocket(int *sock) { } } -static void _php3_unlink_uploaded_file(char *file) { + +static void _php3_unlink_uploaded_file(char *file) +{ if(file) { unlink(file); } } + int php3_minit_file(INIT_FUNC_ARGS) { - TLS_VARS; - GLOBAL(le_fp) = register_list_destructors(fclose,NULL); GLOBAL(le_pp) = register_list_destructors(__pclose,NULL); GLOBAL(wsa_fp) = register_list_destructors(_php3_closesocket,NULL); @@ -441,14 +448,15 @@ int php3_minit_file(INIT_FUNC_ARGS) return SUCCESS; } + /* {{{ proto string tempnam(string dir, string prefix) Create a unique filename in a directory */ -void php3_tempnam(INTERNAL_FUNCTION_PARAMETERS) { +void php3_tempnam(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1, *arg2; char *d; char *t; char p[64]; - TLS_VARS; if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; @@ -464,9 +472,11 @@ void php3_tempnam(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int fopen(string filename, string mode [, int use_include_path]) Open a file or a URL and return a file pointer */ -void php3_fopen(INTERNAL_FUNCTION_PARAMETERS) { +void php3_fopen(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1, *arg2, *arg3; FILE *fp; char *p; @@ -474,23 +484,22 @@ void php3_fopen(INTERNAL_FUNCTION_PARAMETERS) { int id; int use_include_path = 0; int issock=0, socketd=0; - TLS_VARS; switch(ARG_COUNT(ht)) { - case 2: - if (getParameters(ht,2,&arg1,&arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 3: - if (getParameters(ht,3,&arg1,&arg2,&arg3) == FAILURE) { + case 2: + if (getParameters(ht,2,&arg1,&arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + case 3: + if (getParameters(ht,3,&arg1,&arg2,&arg3) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg3); + use_include_path = arg3->value.lval; + break; + default: WRONG_PARAM_COUNT; - } - convert_to_long(arg3); - use_include_path = arg3->value.lval; - break; - default: - WRONG_PARAM_COUNT; } convert_to_string(arg1); convert_to_string(arg2); @@ -523,13 +532,14 @@ void php3_fopen(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int fclose(int fp) Close an open file pointer */ -void php3_fclose(INTERNAL_FUNCTION_PARAMETERS) { +void php3_fclose(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1; int id, type; FILE *fp; - TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -546,15 +556,17 @@ void php3_fclose(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int popen(string command, string mode) Execute a command and open either a read or a write pipe to it */ -void php3_popen(INTERNAL_FUNCTION_PARAMETERS) { +void php3_popen(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1, *arg2; FILE *fp; int id; char *p; char *b, buf[1024]; - TLS_VARS; + PLS_FETCH(); if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; @@ -563,47 +575,51 @@ void php3_popen(INTERNAL_FUNCTION_PARAMETERS) { convert_to_string(arg2); p = estrndup(arg2->value.str.val,arg2->value.str.len); if (PG(safe_mode)){ - b = strchr(arg1->value.str.val,' '); - if (!b) { - b = strrchr(arg1->value.str.val,'/'); - } else { - char *c; - c = arg1->value.str.val; - while((*b!='/')&&(b!=c)) b--; - if (b==c) b=NULL; - } - if (b) { - snprintf(buf,sizeof(buf),"%s%s",PG(safe_mode_exec_dir),b); - } else { - snprintf(buf,sizeof(buf),"%s/%s",PG(safe_mode_exec_dir),arg1->value.str.val); - } - fp = popen(buf,p); - if (!fp) { - php3_error(E_WARNING,"popen(\"%s\",\"%s\") - %s",buf,p,strerror(errno)); - RETURN_FALSE; - } + b = strchr(arg1->value.str.val,' '); + if (!b) { + b = strrchr(arg1->value.str.val,'/'); + } else { + char *c; + c = arg1->value.str.val; + while((*b!='/')&&(b!=c)) { + b--; + } + if (b==c) { + b=NULL; + } + } + if (b) { + snprintf(buf,sizeof(buf),"%s%s",PG(safe_mode_exec_dir),b); + } else { + snprintf(buf,sizeof(buf),"%s/%s",PG(safe_mode_exec_dir),arg1->value.str.val); + } + fp = popen(buf,p); + if (!fp) { + php3_error(E_WARNING,"popen(\"%s\",\"%s\") - %s",buf,p,strerror(errno)); + RETURN_FALSE; + } } else { - fp = popen(arg1->value.str.val,p); - if (!fp) { - php3_error(E_WARNING,"popen(\"%s\",\"%s\") - %s",arg1->value.str.val,p,strerror(errno)); - efree(p); - RETURN_FALSE; - } + fp = popen(arg1->value.str.val,p); + if (!fp) { + php3_error(E_WARNING,"popen(\"%s\",\"%s\") - %s",arg1->value.str.val,p,strerror(errno)); + efree(p); + RETURN_FALSE; + } } -/* #endif */ id = php3_list_insert(fp,GLOBAL(le_pp)); efree(p); RETURN_LONG(id); } /* }}} */ + /* {{{ proto int pclose(int fp) Close a file pointer opened by popen() */ -void php3_pclose(INTERNAL_FUNCTION_PARAMETERS) { +void php3_pclose(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1; int id,type; FILE *fp; - TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -621,16 +637,17 @@ void php3_pclose(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int feof(int fp) Test for end-of-file on a file pointer */ -void php3_feof(INTERNAL_FUNCTION_PARAMETERS) { +void php3_feof(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1; FILE *fp; int id, type; int issock=0; int socketd=0, *sock; unsigned int temp; - TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -656,6 +673,7 @@ void php3_feof(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int set_socket_blocking(int socket descriptor, int mode) Set blocking/non-blocking mode on a socket */ void php3_set_socket_blocking(INTERNAL_FUNCTION_PARAMETERS) @@ -664,7 +682,6 @@ void php3_set_socket_blocking(INTERNAL_FUNCTION_PARAMETERS) int id, type, block; int flags; int socketd=0, *sock; - TLS_VARS; if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; @@ -746,6 +763,7 @@ void php3_set_socket_timeout(INTERNAL_FUNCTION_PARAMETERS) } #endif + /* {{{ proto string fgets(int fp, int length) Get a line from file pointer */ void php3_fgets(INTERNAL_FUNCTION_PARAMETERS) @@ -795,6 +813,7 @@ void php3_fgets(INTERNAL_FUNCTION_PARAMETERS) } /* }}} */ + /* {{{ proto string fgetc(int fp) Get a character from file pointer */ void php3_fgetc(INTERNAL_FUNCTION_PARAMETERS) { @@ -804,7 +823,6 @@ void php3_fgetc(INTERNAL_FUNCTION_PARAMETERS) { char *buf; int issock=0; int *sock, socketd=0; - TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -836,6 +854,7 @@ void php3_fgetc(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* Strip any HTML tags while reading */ /* {{{ proto string fgetss(int fp, int length) Get a line from file pointer and strip HTML tags */ @@ -847,7 +866,6 @@ void php3_fgetss(INTERNAL_FUNCTION_PARAMETERS) char *buf, *p, *rbuf, *rp, c, lc; int issock=0; int *sock,socketd=0; - TLS_VARS; if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &fd, &bytes) == FAILURE) { WRONG_PARAM_COUNT; @@ -961,6 +979,7 @@ void php3_fgetss(INTERNAL_FUNCTION_PARAMETERS) } /* }}} */ + /* {{{ proto int fwrite(int fp, string str [, int length]) Binary-safe file write */ void php3_fwrite(INTERNAL_FUNCTION_PARAMETERS) @@ -1022,13 +1041,14 @@ void php3_fwrite(INTERNAL_FUNCTION_PARAMETERS) } /* }}} */ + /* {{{ proto int rewind(int fp) Rewind the position of a file pointer */ -void php3_rewind(INTERNAL_FUNCTION_PARAMETERS) { +void php3_rewind(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1; int id,type; FILE *fp; - TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -1045,14 +1065,15 @@ void php3_rewind(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int ftell(int fp) Get file pointer's read/write position */ -void php3_ftell(INTERNAL_FUNCTION_PARAMETERS) { +void php3_ftell(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1; int id, type; long pos; FILE *fp; - TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -1069,14 +1090,15 @@ void php3_ftell(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int fseek(int fp, int offset) Seek on a file pointer */ -void php3_fseek(INTERNAL_FUNCTION_PARAMETERS) { +void php3_fseek(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1, *arg2; int ret,id,type; long pos; FILE *fp; - TLS_VARS; if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; @@ -1105,12 +1127,14 @@ void php3_fseek(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int mkdir(string pathname, int mode) Create a directory */ -void php3_mkdir(INTERNAL_FUNCTION_PARAMETERS) { +void php3_mkdir(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1, *arg2; int ret,mode; - TLS_VARS; + PLS_FETCH(); if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; @@ -1130,12 +1154,14 @@ void php3_mkdir(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int rmdir(string dirname) Remove a directory */ -void php3_rmdir(INTERNAL_FUNCTION_PARAMETERS) { +void php3_rmdir(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1; int ret; - TLS_VARS; + PLS_FETCH(); if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -1153,17 +1179,17 @@ void php3_rmdir(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int readfile(string filename [, int use_include_path]) Output a file or a URL */ -void php3_readfile(INTERNAL_FUNCTION_PARAMETERS) { +void php3_readfile(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1, *arg2; char buf[8192]; FILE *fp; int b, size; int use_include_path = 0; - int issock=0, socketd=0; - TLS_VARS; /* check args */ switch (ARG_COUNT(ht)) { @@ -1214,13 +1240,14 @@ void php3_readfile(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int umask([int mask]) Return or change the umask */ -void php3_fileumask(INTERNAL_FUNCTION_PARAMETERS) { +void php3_fileumask(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1; int oldumask; int arg_count = ARG_COUNT(ht); - TLS_VARS; oldumask = umask(077); @@ -1238,19 +1265,20 @@ void php3_fileumask(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* * Read to EOF on a file descriptor and write the output to stdout. */ /* {{{ proto int fpassthru(int fp) Output all remaining data from a file pointer */ -void php3_fpassthru(INTERNAL_FUNCTION_PARAMETERS) { +void php3_fpassthru(INTERNAL_FUNCTION_PARAMETERS) +{ pval *arg1; FILE *fp; char buf[8192]; int id, size, b, type; int issock=0; int socketd=0, *sock; - TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -1290,28 +1318,30 @@ void php3_fpassthru(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int rename(string old_name, string new_name) Rename a file */ -void php3_rename(INTERNAL_FUNCTION_PARAMETERS) { - pval *OLD, *NEW; - char *old, *new; +void php3_rename(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *old_arg, *new_arg; + char *old_name, *new_name; int ret; - TLS_VARS; + PLS_FETCH(); - if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &OLD, &NEW) == FAILURE) { + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &old_arg, &new_arg) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string(OLD); - convert_to_string(NEW); + convert_to_string(old_arg); + convert_to_string(new_arg); - old = OLD->value.str.val; - new = NEW->value.str.val; + old_name = old_arg->value.str.val; + new_name = new_arg->value.str.val; - if (PG(safe_mode) &&(!_php3_checkuid(old,2))) { + if (PG(safe_mode) &&(!_php3_checkuid(old_name, 2))) { RETURN_FALSE; } - ret = rename(old, new); + ret = rename(old_name, new_name); if (ret == -1) { php3_error(E_WARNING, @@ -1323,6 +1353,7 @@ void php3_rename(INTERNAL_FUNCTION_PARAMETERS) { } /* }}} */ + /* {{{ proto int copy(string source_file, string destination_file) Copy a file */ void php3_file_copy(INTERNAL_FUNCTION_PARAMETERS) @@ -1330,7 +1361,7 @@ void php3_file_copy(INTERNAL_FUNCTION_PARAMETERS) pval *source, *target; char buffer[8192]; int fd_s,fd_t,read_bytes; - TLS_VARS; + PLS_FETCH(); if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &source, &target) == FAILURE) { WRONG_PARAM_COUNT; @@ -1377,6 +1408,7 @@ void php3_file_copy(INTERNAL_FUNCTION_PARAMETERS) } /* }}} */ + /* {{{ proto int fread(int fp, int length) Binary-safe file read */ void php3_fread(INTERNAL_FUNCTION_PARAMETERS) @@ -1422,9 +1454,10 @@ void php3_fread(INTERNAL_FUNCTION_PARAMETERS) } /* }}} */ + /* aparently needed for pdf to be compiled as a module under windows */ -PHPAPI int php3i_get_le_fp(void){ - TLS_VARS; +PHPAPI int php3i_get_le_fp(void) +{ return GLOBAL(le_fp); } diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 9b4810f1cccd2..98a6156353004 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -99,8 +99,6 @@ static struct stat lsb; int php3_init_filestat(INIT_FUNC_ARGS) { - TLS_VARS; - GLOBAL(CurrentStatFile)=NULL; GLOBAL(CurrentStatLength)=0; return SUCCESS; @@ -109,10 +107,9 @@ int php3_init_filestat(INIT_FUNC_ARGS) int php3_shutdown_filestat(SHUTDOWN_FUNC_ARGS) { - TLS_VARS; - - if (GLOBAL(CurrentStatFile)) + if (GLOBAL(CurrentStatFile)) { efree (GLOBAL(CurrentStatFile)); + } return SUCCESS; } @@ -122,11 +119,7 @@ void php3_chgrp(INTERNAL_FUNCTION_PARAMETERS) pval *filename, *group; gid_t gid; struct group *gr=NULL; -#endif int ret; - TLS_VARS; - ret = 0; -#ifndef WINDOWS if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&group)==FAILURE) { WRONG_PARAM_COUNT; @@ -145,11 +138,9 @@ void php3_chgrp(INTERNAL_FUNCTION_PARAMETERS) gid = group->value.lval; } -/* #if PHP_SAFE_MODE */ if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) { RETURN_FALSE; } -/* #endif */ /* Check the basedir */ if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE; @@ -159,10 +150,13 @@ void php3_chgrp(INTERNAL_FUNCTION_PARAMETERS) php3_error(E_WARNING, "chgrp failed: %s", strerror(errno)); RETURN_FALSE; } -#endif RETURN_TRUE; +#else + RETURN_FALSE; +#endif } + void php3_chown(INTERNAL_FUNCTION_PARAMETERS) { #ifndef WINDOWS @@ -170,7 +164,6 @@ void php3_chown(INTERNAL_FUNCTION_PARAMETERS) int ret; uid_t uid; struct passwd *pw = NULL; - TLS_VARS; if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&user)==FAILURE) { WRONG_PARAM_COUNT; @@ -201,16 +194,16 @@ void php3_chown(INTERNAL_FUNCTION_PARAMETERS) php3_error(E_WARNING, "chown failed: %s", strerror(errno)); RETURN_FALSE; } -#else - TLS_VARS; #endif RETURN_TRUE; } -void php3_chmod(INTERNAL_FUNCTION_PARAMETERS) { + +void php3_chmod(INTERNAL_FUNCTION_PARAMETERS) +{ pval *filename, *mode; int ret; - TLS_VARS; + PLS_FETCH(); if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&mode)==FAILURE) { WRONG_PARAM_COUNT; @@ -233,7 +226,9 @@ void php3_chmod(INTERNAL_FUNCTION_PARAMETERS) { RETURN_TRUE; } -void php3_touch(INTERNAL_FUNCTION_PARAMETERS) { + +void php3_touch(INTERNAL_FUNCTION_PARAMETERS) +{ #if HAVE_UTIME pval *filename, *filetime; int ret; @@ -241,7 +236,7 @@ void php3_touch(INTERNAL_FUNCTION_PARAMETERS) { FILE *file; struct utimbuf *newtime = NULL; int ac = ARG_COUNT(ht); - TLS_VARS; + PLS_FETCH(); if (ac == 1 && getParameters(ht,1,&filename) != FAILURE) { #ifndef HAVE_UTIME_NULL @@ -298,19 +293,19 @@ void php3_touch(INTERNAL_FUNCTION_PARAMETERS) { #endif } -void php3_clearstatcache(INTERNAL_FUNCTION_PARAMETERS) { - TLS_VARS; - + +void php3_clearstatcache(INTERNAL_FUNCTION_PARAMETERS) +{ if (GLOBAL(CurrentStatFile)) { efree(GLOBAL(CurrentStatFile)); GLOBAL(CurrentStatFile) = NULL; } } + static void _php3_stat(const char *filename, int type, pval *return_value) { struct stat *stat_sb = &GLOBAL(sb); - TLS_VARS; if (!GLOBAL(CurrentStatFile) || strcmp(filename,GLOBAL(CurrentStatFile))) { if (!GLOBAL(CurrentStatFile) diff --git a/ext/standard/link.c b/ext/standard/link.c index e148858a3c2b0..57af8dbe879e6 100644 --- a/ext/standard/link.c +++ b/ext/standard/link.c @@ -174,7 +174,7 @@ void php3_unlink(INTERNAL_FUNCTION_PARAMETERS) { pval *filename; int ret; - TLS_VARS; + PLS_FETCH(); if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &filename) == FAILURE) { WRONG_PARAM_COUNT; diff --git a/main.h b/main.h index 4106f68cc5bd9..3f4501210c3a6 100644 --- a/main.h +++ b/main.h @@ -36,6 +36,7 @@ #define _MAIN_H #include "zend_globals.h" +#include "php_globals.h" #define INIT_ENVIRONMENT 0x80 #define INIT_REQUEST_INFO 0x400 @@ -46,11 +47,11 @@ #define INIT_WINSOCK 0x100000 #define INIT_CLASS_TABLE 0x400000 -int php3_request_startup(CLS_D ELS_DC); +int php3_request_startup(CLS_D ELS_DC PLS_DC); extern void php3_request_shutdown(void *dummy INLINE_TLS); extern void php3_request_shutdown_for_exec(void *dummy); -extern int php3_module_startup(CLS_D ELS_DC); -extern void php3_module_shutdown(INLINE_TLS_VOID); +extern int php3_module_startup(); +extern void php3_module_shutdown(); extern void php3_module_shutdown_for_exec(void); #ifndef THREAD_SAFE diff --git a/main/configuration-parser.y b/main/configuration-parser.y index 20af47b4db750..f89987b63b5ed 100644 --- a/main/configuration-parser.y +++ b/main/configuration-parser.y @@ -41,6 +41,9 @@ #include "ext/standard/php3_browscap.h" #include "zend_extensions.h" +#undef YYPARSE_PARAM +#undef YYLEX_PARAM + #if WIN32 #define WIN32_LEAN_AND_MEAN #include @@ -154,7 +157,7 @@ static void pvalue_browscap_destructor(pval *pvalue) int php3_init_config(void) { - TLS_VARS; + PLS_FETCH(); if (_php3_hash_init(&configuration_hash, 0, NULL, (void (*)(void *))pvalue_config_destructor, 1)==FAILURE) { return FAILURE; diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 367114bbc96e7..206bfa5c76f24 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -106,6 +106,7 @@ PHPAPI int _php3_check_open_basedir(char *path) char resolved_name[MAXPATHLEN]; char local_open_basedir[MAXPATHLEN]; int local_open_basedir_pos; + PLS_FETCH(); /* Only check when open_basedir is available */ if (PG(open_basedir) && *PG(open_basedir)) { @@ -177,6 +178,8 @@ PHPAPI int _php3_check_open_basedir(char *path) PHPAPI FILE *php3_fopen_wrapper(char *path, char *mode, int options, int *issock, int *socketd) { int cm=2; /* checkuid mode: 2 = if file does not exist, check directory */ + PLS_FETCH(); + #if PHP3_URL_FOPEN if (!(options & IGNORE_URL)) { return php3_fopen_url_wrapper(path, mode, options, issock, socketd); @@ -203,8 +206,7 @@ FILE *php3_fopen_for_parser(void) struct stat st; char *temp, *path_info, *fn; int l; - TLS_VARS; - + PLS_FETCH(); fn = GLOBAL(request_info).filename; path_info = GLOBAL(request_info).path_info; @@ -306,7 +308,7 @@ PHPAPI FILE *php3_fopen_with_path(char *filename, char *mode, char *path, char * struct stat sb; FILE *fp; int cm=2; - TLS_VARS; + PLS_FETCH(); if(!strcmp(mode,"r") || !strcmp(mode,"r+")) cm=0; if (opened_path) { @@ -879,6 +881,8 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i return (fp); } else { + PLS_FETCH(); + if (options & USE_PATH) { fp = php3_fopen_with_path((char *) path, mode, PG(include_path), NULL); } else { diff --git a/main/main.c b/main/main.c index 5c5ed82453d0e..db7f3f7a41ab8 100644 --- a/main/main.c +++ b/main/main.c @@ -97,13 +97,11 @@ struct sapi_request_info *sapi_rqst; #include "getopt.h" #endif -#ifdef ZTS -int compiler_globals_id; -int executor_globals_id; -#endif #ifndef ZTS php_core_globals core_globals; +#else +int core_globals_id; #endif void _php3_build_argv(char * ELS_DC); @@ -381,6 +379,7 @@ PHPAPI void php3_error(int type, const char *format,...) char buffer[1024]; int size = 0; ELS_FETCH(); + PLS_FETCH(); if (!(type & E_CORE)) { if (!GLOBAL(initialized)) { /* don't display further errors after php3_request_shutdown() */ @@ -550,6 +549,7 @@ static void php3_unset_timeout(INLINE_TLS_VOID) void php3_set_time_limit(INTERNAL_FUNCTION_PARAMETERS) { pval *new_timeout; + PLS_FETCH(); if (PG(safe_mode)) { php3_error(E_WARNING, "Cannot set time limit in safe mode"); @@ -589,8 +589,11 @@ static FILE *php_fopen_wrapper_for_zend(const char *filename) static void php_message_handler_for_zend(long message, void *data) { switch (message) { - case ZMSG_ENABLE_TRACK_VARS: - PG(track_vars) = 1; + case ZMSG_ENABLE_TRACK_VARS: { + PLS_FETCH(); + + PG(track_vars) = 1; + } break; case ZMSG_FAILED_INCLUDE_FOPEN: php3_error(E_WARNING, "Failed opening '%s' for inclusion", php3_strip_url_passwd((char *) data)); @@ -627,9 +630,10 @@ static void php_message_handler_for_zend(long message, void *data) } -int php3_request_startup(CLS_D ELS_DC) +int php3_request_startup(CLS_D ELS_DC PLS_DC) { zend_output_startup(); + #if APACHE && defined(CRASH_DETECTION) { char log_message[256]; @@ -795,7 +799,7 @@ void php3_request_shutdown(void *dummy INLINE_TLS) } -static int php3_config_ini_startup(ELS_D) +static int php3_config_ini_startup() { if (php3_init_config() == FAILURE) { php3_printf("PHP: Unable to parse configuration file.\n"); @@ -816,11 +820,15 @@ static void php3_config_ini_shutdown(INLINE_TLS_VOID) #endif } -int php3_module_startup(CLS_D ELS_DC) + +int php3_module_startup() { zend_utility_functions zuf; zend_utility_values zuv; int module_number=0; /* for REGISTER_INI_ENTRIES() */ +#ifdef ZTS + php_core_globals *core_globals; +#endif #if (WIN32|WINNT) && !(USE_SAPI) WORD wVersionRequested; @@ -845,12 +853,15 @@ int php3_module_startup(CLS_D ELS_DC) zend_startup(&zuf, NULL); +#ifdef ZTS + core_globals_id = ts_allocate_id(sizeof(php_core_globals), NULL, NULL); + core_globals = ts_resource(core_globals_id); +#endif + #if HAVE_SETLOCALE setlocale(LC_CTYPE, ""); #endif - EG(error_reporting) = E_ALL; - #if (WIN32|WINNT) && !(USE_SAPI) /* start up winsock services */ if (WSAStartup(wVersionRequested, &wsaData) != 0) { @@ -864,7 +875,7 @@ int php3_module_startup(CLS_D ELS_DC) le_index_ptr = _register_list_destructors(NULL, NULL, 0); FREE_MUTEX(gLock); - if (php3_config_ini_startup(ELS_C) == FAILURE) { + if (php3_config_ini_startup() == FAILURE) { return FAILURE; } @@ -926,7 +937,7 @@ void php3_module_shutdown() /* in 3.1 some of this should move into sapi */ -int _php3_hash_environment(void) +int _php3_hash_environment(PLS_D) { char **env, *p, *t; unsigned char _gpc_flags[3] = {0,0,0}; @@ -1162,7 +1173,7 @@ void _php3_build_argv(char *s ELS_DC) #include "logos.h" -static void php3_parse(zend_file_handle *primary_file CLS_DC ELS_DC) +static void php3_parse(zend_file_handle *primary_file CLS_DC ELS_DC PLS_DC) { zend_file_handle *prepend_file_p, *append_file_p; zend_file_handle prepend_file, append_file; @@ -1272,23 +1283,16 @@ int main(int argc, char *argv[]) #ifdef ZTS zend_compiler_globals *compiler_globals; zend_executor_globals *executor_globals; + php_core_globals *core_globals; #endif +#ifndef ZTS if (setjmp(EG(bailout))!=0) { return -1; } - -#ifdef ZTS - sapi_startup(1,1,0); - compiler_globals_id = ts_allocate_id(sizeof(zend_compiler_globals)); - executor_globals_id = ts_allocate_id(sizeof(zend_executor_globals)); - - compiler_globals = ts_resource(compiler_globals_id); - executor_globals = ts_resource(executor_globals_id); #endif - - + #if WIN32|WINNT _fmode = _O_BINARY; /*sets default for file streams to binary */ setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ @@ -1331,6 +1335,14 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine #endif /* FORCE_CGI_REDIRECT */ } + if (php3_module_startup()==FAILURE) { + return FAILURE; + } +#ifdef ZTS + compiler_globals = ts_resource(compiler_globals_id); + executor_globals = ts_resource(executor_globals_id); + core_globals = ts_resource(core_globals_id); +#endif CG(extended_info) = 0; @@ -1340,7 +1352,8 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine switch (c) { case 'f': if (!_cgi_started){ - if (php3_module_startup(CLS_C ELS_CC) == FAILURE || php3_request_startup(CLS_C ELS_CC) == FAILURE) { + if (php3_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) { + php3_module_shutdown(); return FAILURE; } } @@ -1352,7 +1365,8 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine break; case 'v': if (!_cgi_started) { - if (php3_module_startup(CLS_C ELS_CC) == FAILURE || php3_request_startup(CLS_C ELS_CC) == FAILURE) { + if (php3_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) { + php3_module_shutdown(); return FAILURE; } } @@ -1361,7 +1375,8 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine break; case 'i': if (!_cgi_started) { - if (php3_module_startup(CLS_C ELS_CC) == FAILURE || php3_request_startup(CLS_C ELS_CC) == FAILURE) { + if (php3_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) { + php3_module_shutdown(); return FAILURE; } } @@ -1408,7 +1423,8 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine #endif if (!_cgi_started) { - if (php3_module_startup(CLS_C ELS_CC) == FAILURE || php3_request_startup(CLS_C ELS_CC) == FAILURE) { + if (php3_request_startup(CLS_C ELS_CC PLS_CC)==FAILURE) { + php3_module_shutdown(); return FAILURE; } } @@ -1483,7 +1499,7 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine switch (behavior) { case PHP_MODE_STANDARD: - php3_parse(&file_handle CLS_CC ELS_CC); + php3_parse(&file_handle CLS_CC ELS_CC PLS_CC); break; case PHP_MODE_HIGHLIGHT: { zend_syntax_highlighter_ini syntax_highlighter_ini; @@ -1528,13 +1544,15 @@ PHPAPI int apache_php3_module_main(request_rec * r, int fd, int display_source_m #ifdef ZTS zend_compiler_globals cg; zend_executor_globals eg; + php_core_globals pcg; zend_compiler_globals *compiler_globals=&cg; zend_executor_globals *executor_globals=⪚ + php_core_globals *core_globals=&pcg; #endif GLOBAL(php3_rqst) = r; - if (php3_request_startup(CLS_C ELS_CC) == FAILURE) { + if (php3_request_startup(CLS_C ELS_CC PLS_CC) == FAILURE) { return FAILURE; } php3_TreatHeaders(); @@ -1637,7 +1655,7 @@ int main(int argc, char **argv) setlocale(LC_CTYPE, ""); #endif - if (php3_module_startup(CLS_C ELS_CC) == FAILURE) { + if (php3_module_startup() == FAILURE) { return FAILURE; } signal(SIGPIPE, SIG_IGN); @@ -1891,7 +1909,7 @@ PHPAPI int php3_sapi_main(struct sapi_request_info *sapi_info) return FAILURE; }*/ - if (php3_request_startup(CLS_C ELS_CC) == FAILURE) { + if (php3_request_startup(CLS_C ELS_CC PLS_CC) == FAILURE) { #if DEBUG snprintf(logmessage,1024,"%d:php3_sapi_main: request starup failed\n",GLOBAL(sapi_rqst)->scid); OutputDebugString(logmessage); @@ -2068,7 +2086,7 @@ BOOL WINAPI DllMain(HANDLE hModule, if (php3_config_ini_startup(_INLINE_TLS_VOID) == FAILURE) { return 0; } - if (php3_module_startup(php3_globals) == FAILURE) { + if (php3_module_startup() == FAILURE) { ErrorExit("module startup failed"); return 0; } @@ -2085,7 +2103,7 @@ BOOL WINAPI DllMain(HANDLE hModule, return 0; php3_globals = TlsGetValue(TlsIndex); yy_init_tls(); - if (php3_module_startup(php3_globals) == FAILURE) { + if (php3_module_startup() == FAILURE) { ErrorExit("module startup failed"); #if DEBUG OutputDebugString("PHP_Core DllMain module startup failed\n"); diff --git a/main/php.h b/main/php.h index b087058d15635..06ae5ce7ffa85 100644 --- a/main/php.h +++ b/main/php.h @@ -370,7 +370,7 @@ extern void html_putc(char c); #ifndef THREAD_SAFE extern int end_current_file_execution(int *retval); #endif -extern int _php3_hash_environment(void); +extern int _php3_hash_environment(PLS_D); extern int module_startup_modules(void); /* needed for modules only */ diff --git a/main/php_globals.h b/main/php_globals.h index edde446e66ec9..19dbaa8804c54 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -1,6 +1,8 @@ #ifndef _PHP_GLOBALS_H #define _PHP_GLOBALS_H +#include "zend_globals.h" + typedef struct _php_core_globals php_core_globals; #ifdef ZTS @@ -10,6 +12,7 @@ typedef struct _php_core_globals php_core_globals; # define PLS_CC , PLS_C # define PG(v) (core_globals->v) # define PLS_FETCH() php_core_globals *core_globals = ts_resource(core_globals_id) +extern int core_globals_id; #else # define PLS_D # define PLS_DC diff --git a/php4.dsw b/php4.dsw index f423e89b4b1af..37aaba37f3ca0 100644 --- a/php4.dsw +++ b/php4.dsw @@ -3,6 +3,18 @@ Microsoft Developer Studio Workspace File, Format Version 6.00 ############################################################################### +Project: "TSRM"=..\tsrm\TSRM.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + Project: "libzend"=..\libzend\libzend.dsp - Package Owner=<4> Package=<5>