Commit Graph

472 Commits

Author SHA1 Message Date
George Peter Banyard
fa8d9b1183 Improve type declarations for Zend APIs
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
2020-08-28 15:41:27 +02:00
Nikita Popov
5db44e39b1 Fix tracked_realloc
We should only drop the information about the old allocation after
checking the memory limit. This makes the code a bit more awkward...
2020-08-28 11:37:42 +02:00
Nikita Popov
bd6feb7b12 Enforce memory limit in tracked allocation mode
A very basic limit (for single allocations) was already enforced.
This extends it to count the total memory allocations.

This is useful to avoid out of memory conditions while fuzzing.
2020-08-27 10:18:18 +02:00
tangl163
7d4ae7fa23 Drop the unneeded pointer casting
The standard says that "A pointer to void may be converted to or from a
pointer to any object type". So the casting is unneeded.

REF:
    * c11: http://port70.net/~nsz/c/c11/n1570.html#6.3.2.3p1
    * c99: http://port70.net/~nsz/c/c99/n1256.html

Closes GH-5916
2020-08-03 02:05:14 +01:00
Nikita Popov
370c00e9cf Add crude memory limit to tracked alloc
Check whether the requested allocation size exceeds limit (rather
than the cumulative size).

This is useful to prevent allocations triggering OOM during fuzzing.
2020-04-21 10:44:15 +02:00
Dmitry Stogov
4786207ecc Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed incorrect behavior of internal memory debugger
2020-02-27 12:28:09 +03:00
Dmitry Stogov
d9f56903ad Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed incorrect behavior of internal memory debugger
2020-02-27 12:27:58 +03:00
Dmitry Stogov
45b4368d5c Fixed incorrect behavior of internal memory debugger 2020-02-27 12:27:22 +03:00
Tyson Andre
9d48bf5152 Fix miscellaneous typos in docs and error messages
Closes GH-4863.
2019-10-28 11:44:08 +01:00
Rasmus Lerdorf
af57b6330b Reverting push to wrong repo 2019-10-23 14:34:12 -07:00
Rasmus Lerdorf
5870efbcf5 Update alloc patch 2019-10-23 14:31:27 -07:00
Christoph M. Becker
6627f782d6 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #78620: Out of memory error
2019-10-04 09:11:18 +02:00
Christoph M. Becker
cf183a5e2c Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix #78620: Out of memory error
2019-10-04 09:09:39 +02:00
Christoph M. Becker
abaf9a76dc Fix #78620: Out of memory error
The integer addition in `ZEND_MM_ALIGNED_SIZE_EX` can overflow, what we
have to catch early.
2019-10-04 09:08:01 +02:00
Christoph M. Becker
2508131588 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Revert "Fix #78620: Out of memory error"
2019-10-02 19:03:25 +02:00
Christoph M. Becker
d295e1dce2 Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Revert "Fix #78620: Out of memory error"
2019-10-02 19:02:28 +02:00
Christoph M. Becker
f2fb37a772 Revert "Fix #78620: Out of memory error"
This reverts commit 8ce04df7e0.

Cf. <https://github.com/php/php-src/pull/4766#discussion_r330658679>.
2019-10-02 19:01:35 +02:00
Christoph M. Becker
b262b24beb Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #78620: Out of memory error
2019-10-02 18:21:50 +02:00
Christoph M. Becker
752a34fb2c Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix #78620: Out of memory error
2019-10-02 18:20:09 +02:00
Christoph M. Becker
8ce04df7e0 Fix #78620: Out of memory error
If the integer addition in `ZEND_MM_ALIGNED_SIZE_EX` overflows, the
macro evaluates to `0`, what we should catch early.
2019-10-02 18:18:52 +02:00
David Carlier
ce25fa0d24 Monitoring anonymous pages on mac via vmmap tag 2019-09-17 12:54:46 +02:00
Nikita Popov
bad49e55b9 Merge branch 'PHP-7.3' into PHP-7.4 2019-08-26 10:27:08 +02:00
Nikita Popov
a26f63213d Merge branch 'PHP-7.2' into PHP-7.3 2019-08-26 10:26:49 +02:00
Nikita Popov
16d35eb643 Fix overflow in memory limit checks
Due to overflows in the memory limit checks, we were missing cases
where the allocation size was close to the address space size, and
caused an OOM condition rather than a memory limit error.
2019-08-26 10:25:30 +02:00
Nikita Popov
70fa4715a4 Fix custom heap free
This seems to be designed around the use-case where the custom
allocator is a wrapper around ZMM.
2019-06-28 09:13:45 +02:00
Nikita Popov
cfeda978df Add tracked allocator mode
In this case we will use the system allocator, but still remember
all allocations and free them the same way that Zend MM does. This
allows us to accurately model leak behavior.

Enabled using USE_ZEND_ALLOC=0 USE_TRACKED_ALLOC=1.
2019-06-27 14:19:48 +02:00
Nikita Popov
3d4298697b Fix shift UB in constants
We were shifting out the top bit of a signed integer.
2019-06-19 15:09:00 +02:00
Anatol Belski
08a0030b33 Fix conditional compilation
The new symbols are shared and don't need to depend on the availability
of __builtin_constant_p.
2019-05-29 02:40:09 +02:00
Dmitry Stogov
8c0b0c6a1e Avoid cold code duplication 2019-05-29 01:43:27 +03:00
Peter Kokot
3c92b79ea0 Remove unused functions
- zend_mm_bitset_find_zero
- zend_mm_bitset_find_one
- zend_mm_bitset_find_zero_and_set
- zend_is_by_ref_func_arg_fetch
2019-05-08 22:02:39 +02:00
Peter Kokot
5f8915786f Remove HAVE_SIGNAL_H
The `<signal.h>` header file is part of the standard C89 headers [1] and
on current systems can be included unconditionally.

Since file requires at least C89 or greater, the `HAVE_SIGNAL_H` symbol
defined by Autoconf in Zend.m4 [2] can be ommitted and simplifed.

The bundled libmagic (file) also ommits the usage of HAVE_SIGNAL_H since
5.35 however current version in PHP is very modified 5.34 version and
will be refactored separately. Check for HAVE_SIGNAL_H is therefore
still done in the configure.ac.

Refs:
[1] https://port70.net/~nsz/c/c89/c89-draft.html#4.1.2
[2] https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/headers.m4
2019-04-07 15:55:34 +02:00
Peter Kokot
fd1ad1e25a Remove HAVE_LIMITS_H
The `<limits.h>` header file is part of the standard C89 headers [1]
and on current systems can be included unconditionally.

Since PHP requires at least C89 or greater, the `HAVE_LIMITS_H` symbol
defined by Autoconf in configure.ac [2] can be ommitted and simplifed
however due to bundled file library (libmagic) and timelib still using
it, the removal there was omitted and done only in Zend.m4 file.

Current bundled libraries libtime, oniguruma, and libmagic still include
partial `HAVE_LIMITS_H` usage and will be more refactored when this is
possible.

Refs:
[1] https://port70.net/~nsz/c/c89/c89-draft.html#4.1.2
[2] https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/headers.m4
2019-04-07 15:20:02 +02:00
Dmitry Stogov
9499484ed2 Implemented a faster way to access predefined TSRM resources - CG(), EG(), etc. 2019-03-14 03:01:01 +03:00
Dmitry Stogov
04b67bac32 Avoid reinitailization of ZTS cache pointer. Initialize it once in TSRM.c 2019-03-12 17:35:50 +03:00
Stanislav Malyshev
db777e9199 Fix shifting signed values too far
Signed shift of 31 for int and 63 for long is flagged as undefined
behavior by UBSan (-fsanitize=undefined) and seems to be indeed so
according to the standard.

The patch converts such cases to use unsigned.
2019-03-06 00:50:09 -08:00
Dmitry Stogov
c896b3ea48 Unused parameter 2019-03-01 14:34:17 +03:00
Dmitry Stogov
a1109b28f4 Keep original debug info 2019-03-01 14:11:37 +03:00
Tyson Andre
da3316ff0f Fix typos in code comments in Zend/ [skip ci] 2019-02-18 17:56:28 +01:00
Nikita Popov
709b8aaf9f Merge branch 'PHP-7.3' into PHP-7.4 2019-02-18 14:04:30 +01:00
Nikita Popov
3b3fafa637 Merge branch 'PHP-7.2' into PHP-7.3 2019-02-18 14:04:15 +01:00
Nikita Popov
928c42211f Make MADV_HUGEPAGE conditional on USE_ZEND_ALLOC_HUGE_PAGES
There have been multiple reports of large slowdowns due to the
use of MADV_HUGEPAGE, so make it conditional on
USE_ZEND_ALLOC_HUGE_PAGES, just like MAP_HUGETLB already is.
2019-02-18 14:03:07 +01:00
Nikita Popov
7d0d94e230 Use mremap in zend_mm_chunk_extend if available
As suggested by https://twitter.com/grsecurity. This saves an
mmap+munmap cycle in case the mapping cannot be extended in-place.
2019-02-18 12:06:59 +01:00
Peter Kokot
92ac598aab Remove local variables
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.
2019-02-03 21:03:00 +01:00
Zeev Suraski
a81202ac49 Adios, yearly copyright ranges 2019-01-30 11:48:28 +01:00
Dmitry Stogov
662243cb30 Don't hide real peak usage. 2019-01-25 13:36:32 +03:00
Dmitry Stogov
bf774d4d75 Reduce amount of updated memory 2019-01-24 18:01:24 +03:00
Dmitry Stogov
4d0a2f68a9 Provide is_zend_ptr() function to check if a pointer lays in Zend MM heap. 2018-12-12 13:02:28 +03:00
David Carlier
5d4938956a Support huge pages on FreeBSD
FreeBSD provides MAP_ALIGNED_SUPER for a similar purpose as
MAP_HUGETLB on Linux, so add it as an alias.

Huge pages still have to be explicitly enabled through the
USE_ZEND_ALLOC_HUGE_PAGES environment variable.
2018-11-27 19:48:24 +01:00
Zeev Suraski
9afce019e0 Future-proof email addresses 2018-11-01 18:35:32 +02:00
Zeev Suraski
54dc07f3dc Update email addresses. We're still @Zend, but future proofing it... 2018-11-01 17:20:07 +02:00