mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
parent
470a6e4401
commit
13fcc4a046
949 changed files with 95662 additions and 444 deletions
|
|
@ -25,6 +25,13 @@
|
|||
|
||||
MOZ_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* On OSX, malloc/malloc.h contains the declaration for malloc_good_size,
|
||||
* which will call back in jemalloc, through the zone allocator so just use it.
|
||||
*/
|
||||
#ifdef XP_DARWIN
|
||||
# include <malloc/malloc.h>
|
||||
#else
|
||||
MOZ_MEMORY_API size_t malloc_good_size_impl(size_t size);
|
||||
|
||||
/* Note: the MOZ_GLUE_IN_PROGRAM ifdef below is there to avoid -Werror turning
|
||||
|
|
@ -32,15 +39,15 @@ MOZ_MEMORY_API size_t malloc_good_size_impl(size_t size);
|
|||
* to use weak imports. */
|
||||
|
||||
static inline size_t _malloc_good_size(size_t size) {
|
||||
#if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT)
|
||||
# if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT)
|
||||
if (!malloc_good_size)
|
||||
return size;
|
||||
#endif
|
||||
# endif
|
||||
return malloc_good_size_impl(size);
|
||||
}
|
||||
|
||||
#define malloc_good_size _malloc_good_size
|
||||
|
||||
# define malloc_good_size _malloc_good_size
|
||||
#endif
|
||||
|
||||
MOZ_JEMALLOC_API void jemalloc_stats(jemalloc_stats_t *stats);
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ mozmem_malloc_impl(_ZdaPvRKSt9nothrow_t)(void *ptr)
|
|||
#undef strndup
|
||||
#undef strdup
|
||||
|
||||
#ifndef XP_DARWIN
|
||||
MOZ_MEMORY_API char *
|
||||
strndup_impl(const char *src, size_t len)
|
||||
{
|
||||
|
|
@ -85,6 +86,7 @@ strdup_impl(const char *src)
|
|||
size_t len = strlen(src);
|
||||
return strndup_impl(src, len);
|
||||
}
|
||||
#endif /* XP_DARWIN */
|
||||
|
||||
#ifdef XP_WIN
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@
|
|||
# define mozmem_jemalloc_impl(a) je_ ## a
|
||||
# else
|
||||
# define MOZ_JEMALLOC_API MFBT_API
|
||||
# if defined(XP_WIN)
|
||||
# if (defined(XP_WIN) || defined(XP_DARWIN))
|
||||
# if defined(MOZ_REPLACE_MALLOC)
|
||||
# define mozmem_malloc_impl(a) a ## _impl
|
||||
# else
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@
|
|||
* function resolved with GetProcAddress() instead of weak definitions
|
||||
* of functions.
|
||||
*/
|
||||
#if defined(XP_WIN)
|
||||
#ifdef XP_DARWIN
|
||||
# define MOZ_REPLACE_WEAK __attribute__((weak_import))
|
||||
#elif defined(XP_WIN)
|
||||
# define MOZ_NO_REPLACE_FUNC_DECL
|
||||
#elif defined(__GNUC__)
|
||||
# define MOZ_REPLACE_WEAK __attribute__((weak))
|
||||
|
|
@ -282,6 +284,111 @@ MOZ_MEMORY_API __memalign_hook_type __memalign_hook = memalign_impl;
|
|||
* owned by the allocator.
|
||||
*/
|
||||
|
||||
#ifdef XP_DARWIN
|
||||
#include <stdlib.h>
|
||||
#include <malloc/malloc.h>
|
||||
#include "mozilla/Assertions.h"
|
||||
|
||||
static size_t
|
||||
zone_size(malloc_zone_t *zone, void *ptr)
|
||||
{
|
||||
return malloc_usable_size_impl(ptr);
|
||||
}
|
||||
|
||||
static void *
|
||||
zone_malloc(malloc_zone_t *zone, size_t size)
|
||||
{
|
||||
return malloc_impl(size);
|
||||
}
|
||||
|
||||
static void *
|
||||
zone_calloc(malloc_zone_t *zone, size_t num, size_t size)
|
||||
{
|
||||
return calloc_impl(num, size);
|
||||
}
|
||||
|
||||
static void *
|
||||
zone_realloc(malloc_zone_t *zone, void *ptr, size_t size)
|
||||
{
|
||||
if (malloc_usable_size_impl(ptr))
|
||||
return realloc_impl(ptr, size);
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
|
||||
static void
|
||||
zone_free(malloc_zone_t *zone, void *ptr)
|
||||
{
|
||||
if (malloc_usable_size_impl(ptr)) {
|
||||
free_impl(ptr);
|
||||
return;
|
||||
}
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
static void
|
||||
zone_free_definite_size(malloc_zone_t *zone, void *ptr, size_t size)
|
||||
{
|
||||
size_t current_size = malloc_usable_size_impl(ptr);
|
||||
if (current_size) {
|
||||
MOZ_ASSERT(current_size == size);
|
||||
free_impl(ptr);
|
||||
return;
|
||||
}
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
static void *
|
||||
zone_memalign(malloc_zone_t *zone, size_t alignment, size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
if (posix_memalign_impl(&ptr, alignment, size) == 0)
|
||||
return ptr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *
|
||||
zone_valloc(malloc_zone_t *zone, size_t size)
|
||||
{
|
||||
return valloc_impl(size);
|
||||
}
|
||||
|
||||
static void *
|
||||
zone_destroy(malloc_zone_t *zone)
|
||||
{
|
||||
/* This function should never be called. */
|
||||
MOZ_CRASH();
|
||||
}
|
||||
|
||||
static size_t
|
||||
zone_good_size(malloc_zone_t *zone, size_t size)
|
||||
{
|
||||
return malloc_good_size_impl(size);
|
||||
}
|
||||
|
||||
#ifdef MOZ_JEMALLOC
|
||||
|
||||
#include "jemalloc/internal/jemalloc_internal.h"
|
||||
|
||||
static void
|
||||
zone_force_lock(malloc_zone_t *zone)
|
||||
{
|
||||
/* /!\ This calls into jemalloc. It works because we're linked in the
|
||||
* same library. Stolen from jemalloc's zone.c. */
|
||||
if (isthreaded)
|
||||
jemalloc_prefork();
|
||||
}
|
||||
|
||||
static void
|
||||
zone_force_unlock(malloc_zone_t *zone)
|
||||
{
|
||||
/* /!\ This calls into jemalloc. It works because we're linked in the
|
||||
* same library. Stolen from jemalloc's zone.c. */
|
||||
if (isthreaded)
|
||||
jemalloc_postfork_parent();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define JEMALLOC_ZONE_VERSION 6
|
||||
|
||||
/* Empty implementations are needed, because fork() calls zone->force_(un)lock
|
||||
|
|
@ -296,7 +403,7 @@ zone_force_unlock(malloc_zone_t *zone)
|
|||
{
|
||||
}
|
||||
|
||||
/* --- */
|
||||
#endif
|
||||
|
||||
static malloc_zone_t zone;
|
||||
static struct malloc_introspection_t zone_introspect;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@
|
|||
#define MOZ_MEMORY_IMPL
|
||||
#include "mozmemory_wrap.h"
|
||||
|
||||
#if defined(XP_DARWIN)
|
||||
#include <malloc/malloc.h> // for malloc_size
|
||||
#endif
|
||||
|
||||
// See mozmemory_wrap.h for more details. This file is part of libmozglue, so
|
||||
// it needs to use _impl suffixes. However, with libmozglue growing, this is
|
||||
// becoming cumbersome, so we will likely use a malloc.h wrapper of some sort
|
||||
|
|
@ -149,6 +153,17 @@ moz_posix_memalign(void **ptr, size_t alignment, size_t size)
|
|||
if (code)
|
||||
return code;
|
||||
|
||||
#if defined(XP_DARWIN)
|
||||
// Workaround faulty OSX posix_memalign, which provides memory with the
|
||||
// incorrect alignment sometimes, but returns 0 as if nothing was wrong.
|
||||
size_t mask = alignment - 1;
|
||||
if (((size_t)(*ptr) & mask) != 0) {
|
||||
void* old = *ptr;
|
||||
code = moz_posix_memalign(ptr, alignment, size);
|
||||
free(old);
|
||||
}
|
||||
#endif
|
||||
|
||||
return code;
|
||||
|
||||
}
|
||||
|
|
@ -188,7 +203,9 @@ moz_malloc_usable_size(void *ptr)
|
|||
if (!ptr)
|
||||
return 0;
|
||||
|
||||
#if defined(HAVE_MALLOC_USABLE_SIZE) || defined(MOZ_MEMORY)
|
||||
#if defined(XP_DARWIN)
|
||||
return malloc_size(ptr);
|
||||
#elif defined(HAVE_MALLOC_USABLE_SIZE) || defined(MOZ_MEMORY)
|
||||
return malloc_usable_size_impl(ptr);
|
||||
#elif defined(XP_WIN)
|
||||
return _msize(ptr);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: sw=4 ts=4 et :
|
||||
*/
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
|
@ -150,9 +152,13 @@ MFBT_API void* moz_xvalloc(size_t size)
|
|||
*/
|
||||
|
||||
/* NB: This is defined just to silence vacuous warnings about symbol
|
||||
* visibility on gcc. These symbols are force-inline and not exported.
|
||||
*/
|
||||
#define MOZALLOC_EXPORT_NEW
|
||||
* visibility on OS X/gcc. These symbols are force-inline and not
|
||||
* exported. */
|
||||
#if defined(XP_MACOSX)
|
||||
# define MOZALLOC_EXPORT_NEW MFBT_API
|
||||
#else
|
||||
# define MOZALLOC_EXPORT_NEW
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -76,7 +76,9 @@ private:
|
|||
void* mBuf;
|
||||
size_t mSize;
|
||||
int mLockCount;
|
||||
#if defined(XP_WIN)
|
||||
#ifdef XP_DARWIN
|
||||
bool mHeap;
|
||||
#elif defined(XP_WIN)
|
||||
bool mHeap;
|
||||
bool mFirstLock;
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue