I checked a simple Laravel CRUD application's home page under Callgrind
and found that the line:
char resolved_path[MAXPATHLEN] = {0};
took up about 0.95% of the spent instruction count.
This is because when opcache revalidates the timestamps, it has to go
through the function virtual_file_ex() which contains that line. That
line will memset 4096 bytes on my system to all zeroes. This is bad for
the data cache and for the runtime.
I found that this memsetting is unnecessary in most cases, and that
we can fix the one remaining case:
* Lines 1020-1027 don't do anything with resolved_path, so that's okay.
* Lines 1033-1098:
- The !IS_ABSOLUTE_PATH branch will always result in a memcpy from
path to resolved_path (+ sometimes an offset) with the total copied
amount equal to path_length+1, so that includes a NUL byte.
- The else branch either takes the WIN32 path or the non-WIN32 path.
° WIN32: There's a copy from path+2 with length path_length-1.
Note that we chop off the first 2 bytes, so this also
includes the NUL byte.
° Non-WIN32: Copies path_length+1 bytes, so that includes a NUL byte.
At this point we know that resolved_path ends in a NUL byte. Going
further in the code:
* Lines 1100-1106 don't write to resolved_path, so no NUL byte is removed.
* Lines 1108-1136:
- The IS_UNC_PATH branch:
° Lines 1111-1112 don't overwrite the NUL byte, because we know the
path length is at least 2 due to the IS_UNC_PATH check.
° Both while loops uppercase the path until a slash is found. If a
NUL byte was found then it jumps to verify. Therefore, no NUL byte
can be overwritten. Furthermore, Lines 1121 and 1129 cannot
overwrite a NUL byte because the check at lines 1115 and 1123
would've jumped to verify when a NUL byte would be encountered.
Therefore, the IS_UNC_PATH branch cannot overwrite a NUL byte, so
the NUL byte we know we already got stays in place.
- The else branch:
° We know the path length is at least 2 due to IS_ABSOLUTE_PATH.
That means the earliest NUL byte can be at index 2, which can be
overwritten on line 1133. We fix this by adding one byte write if
the length is 2.
All uses of resolved_path in lines 1139-1141 have a NUL byte at the end
now.
Lines 1154-1164 do a bunch of post-processing but line 1164 will make
sure resolved_path still ends in a NUL byte.
So therefore I propose to remove the huge memset, and add a single byte
write in that one else branch I mentioned earlier.
Looking at Callgrind, the instruction count before this patch for 200
requests is 14,264,569,942; and after the patch it's 14,129,358,195
(averaged over a handful of runs).
Given that Windows ignores trailing dots and spaces in filenames, we
catch that ourselves to avoid confusion with the respective filenames
without these characters.
Closes GH-9229.
If ZTS is enabled, this can cause cwd_globals_ctor() to be called
multiple times, each with a freshly allocated virtual_cwd_globals
instance. At shutdown time however, cwd_globals_dtor() will call
realpath_cache_clean(), which then possibly cleans up the same
realpath_cache instance more than once. Using AddressSanitzer, this
shows up as a heap use-after-free.
To avoid this, add a helper function to do the actual work on one
instance of a realpath_cache, and call it both from cwd_globals_dtor()
and realpath_cache_clean(). The former uses the virtual_cwd_globals
parameter passed in via the destructor, the latter uses the CWDG()
macro.
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
Firstly, we must not forget to set appropriate error codes for "manual"
checks in `virtual_file_ex()`.
Secondly, we must not call `php_error_docref2()` for warnings regarding
unary functions; thus, we introduce `php_win32_docref1_from_error()`.
Closes GH-6872.
This PR corrects misspellings identified by the check-spelling action.
The misspellings have been reported at jsoref@b6ba3e2#commitcomment-48946465
The action reports that the changes in this PR would make it happy: jsoref@602417c
Closes GH-6822.
A recent bug fix regarding symlinks claimed:
> After resolving reparse points, the path still may be a reparse
> point; in that case we have to resolve that reparse point as well.
While that is basically correct, some reparse points may point to
inaccessible system folders (e.g. `IO_REPARSE_TAG_DEDUP` points to
"\System Volume Information"). Since we don't know details about
arbitrary reparse points, and are mainly interested in nested symlinks,
we take a step back, and only resolve `IO_REPARSE_TAG_SYMLINK` for now.
Close GH-6354.
Voidification of Zend API which always succeeded
Use bool argument types instead of int for boolean arguments
Use bool return type for functions which return true/false (1/0)
Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics
Closes GH-6002
As of Windows 1903, when the OneDrive on-demand feature is enabled, the
OneDrive folder is reported as reparse point by `FindFirstFile()`, but
trying to get information about the reparse point using
`DeviceIoControl()` fails with `ERROR_NOT_A_REPARSE_POINT`. We work
around this problem by falling back to `GetFileInformationByHandle()`
if that happens, but only if the reparse point is reported as cloud
reparse point, and only if PHP is running on Windows 1903 or later.
The patch has been developed in collaboration with ab@php.net.
We should keep an eye on the somewhat quirky OneDrive behavior, since
it might change again in a future Windows release.
This patch removes the so called local variables defined per
file basis for certain editors to properly show tab width, and
similar settings. These are mainly used by Vim and Emacs editors
yet with recent changes the once working definitions don't work
anymore in Vim without custom plugins or additional configuration.
Neither are these settings synced across the PHP code base.
A simpler and better approach is EditorConfig and fixing code
using some code style fixing tools in the future instead.
This patch also removes the so called modelines for Vim. Modelines
allow Vim editor specifically to set some editor configuration such as
syntax highlighting, indentation style and tab width to be set in the
first line or the last 5 lines per file basis. Since the php test
files have syntax highlighting already set in most editors properly and
EditorConfig takes care of the indentation settings, this patch removes
these as well for the Vim 6.0 and newer versions.
With the removal of local variables for certain editors such as
Emacs and Vim, the footer is also probably not needed anymore when
creating extensions using ext_skel.php script.
Additionally, Vim modelines for setting php syntax and some editor
settings has been removed from some *.phpt files. All these are
mostly not relevant for phpt files neither work properly in the
middle of the file.
Keep compatibility with 7.2 and below which better comply with
realpath(3). This might have been fixable another way, say by checking
of QueryDosDevice or alike, sadly that comes with a huge performance
impact. The new internal realpath API is kept available so is
usable when bind or network mount or other OS specific realpath
variants are needed. If not used by default, a userspace function for
this specific case might be considered to be offered in next minor.