Skip to content
Permalink
Browse files
bmalloc: Constify introspect function pointer table
https://bugs.webkit.org/show_bug.cgi?id=156936

Reviewed by Michael Saboff.

* bmalloc/Zone.cpp:
(bmalloc::Zone::Zone): Declaring this function pointer table const puts
it in the read-only section of the binary, providing a little hardening
against overwriting the function pointers at runtime. (We have to
const_cast when assigning because the API declares a pointer to non-const,
but we happen to know it will never try to write through that pointer.
This is not my favorite API.)


Canonical link: https://commits.webkit.org/175046@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199934 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
geoffreygaren committed Apr 22, 2016
1 parent 739c602 commit eee35e5b5802bc84e2537fb063ddecebe56c7e39
Showing with 17 additions and 2 deletions.
  1. +15 −0 Source/bmalloc/ChangeLog
  2. +2 −2 Source/bmalloc/bmalloc/Zone.cpp
@@ -1,3 +1,18 @@
2016-04-22 Geoffrey Garen <ggaren@apple.com>

bmalloc: Constify introspect function pointer table
https://bugs.webkit.org/show_bug.cgi?id=156936

Reviewed by Michael Saboff.

* bmalloc/Zone.cpp:
(bmalloc::Zone::Zone): Declaring this function pointer table const puts
it in the read-only section of the binary, providing a little hardening
against overwriting the function pointers at runtime. (We have to
const_cast when assigning because the API declares a pointer to non-const,
but we happen to know it will never try to write through that pointer.
This is not my favorite API.)

2016-04-19 Geoffrey Garen <ggaren@apple.com>

bmalloc: fix up overflow checks
@@ -104,7 +104,7 @@ static kern_return_t enumerator(task_t task, void* context, unsigned type_mask,
// The memory analysis API requires the contents of this struct to be a static
// constant in the program binary. The leaks process will load this struct
// out of the program binary (and not out of the running process).
static malloc_introspection_t zoneIntrospect = {
static const malloc_introspection_t zoneIntrospect = {
.enumerator = bmalloc::enumerator,
.good_size = bmalloc::good_size,
.check = bmalloc::check,
@@ -119,7 +119,7 @@ Zone::Zone()
{
malloc_zone_t::size = &bmalloc::zoneSize;
malloc_zone_t::zone_name = "WebKit Malloc";
malloc_zone_t::introspect = &bmalloc::zoneIntrospect;
malloc_zone_t::introspect = const_cast<malloc_introspection_t*>(&bmalloc::zoneIntrospect);
malloc_zone_t::version = 4;
malloc_zone_register(this);
}

0 comments on commit eee35e5

Please sign in to comment.