mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 16:22:29 +00:00
Pay off more technical debt
This makes breaking changes to add underscores to many non-standard function names provided by the c library. MODE=tiny is now tinier and we now use smaller locks that are better for tiny apps in this mode. Some headers have been renamed to be in the same folder as the build package, so it'll be easier to know which build dependency is needed. Certain old misguided interfaces have been removed. Intel intrinsics headers are now listed in libc/isystem (but not in the amalgamation) to help further improve open source compatibility. Header complexity has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
parent
b69f3d2488
commit
6f7d0cb1c3
960 changed files with 4072 additions and 4873 deletions
8
third_party/dlmalloc/dlmalloc.c
vendored
8
third_party/dlmalloc/dlmalloc.c
vendored
|
@ -2,11 +2,11 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/bsr.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "libc/nexgen32e/rdtsc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/sysconf.h"
|
||||
|
@ -696,8 +696,8 @@ void* dlmalloc(size_t bytes) {
|
|||
|
||||
mem = sys_alloc(gm, nb);
|
||||
POSTACTION(gm);
|
||||
if (mem == MAP_FAILED && weaken(__oom_hook)) {
|
||||
weaken(__oom_hook)(bytes);
|
||||
if (mem == MAP_FAILED && _weaken(__oom_hook)) {
|
||||
_weaken(__oom_hook)(bytes);
|
||||
}
|
||||
return mem;
|
||||
|
||||
|
@ -919,7 +919,7 @@ static void* internal_memalign(mstate m, size_t alignment, size_t bytes) {
|
|||
if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */
|
||||
alignment = MIN_CHUNK_SIZE;
|
||||
/* alignment is 32+ bytes rounded up to nearest two power */
|
||||
alignment = 2ul << bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1);
|
||||
alignment = 2ul << _bsrl(MAX(MIN_CHUNK_SIZE, alignment) - 1);
|
||||
if (bytes >= MAX_REQUEST - alignment) {
|
||||
if (m != 0) { /* Test isn't needed but avoids compiler warning */
|
||||
MALLOC_FAILURE_ACTION;
|
||||
|
|
7
third_party/dlmalloc/dlmalloc.mk
vendored
7
third_party/dlmalloc/dlmalloc.mk
vendored
|
@ -49,12 +49,15 @@ $(THIRD_PARTY_DLMALLOC_A).pkg: \
|
|||
$(THIRD_PARTY_DLMALLOC_A_OBJS) \
|
||||
$(foreach x,$(THIRD_PARTY_DLMALLOC_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
ifneq ($(MODE),tiny)
|
||||
ifneq ($(MODE),tinylinux)
|
||||
# README file recommends -O3
|
||||
# It does double performance in default mode
|
||||
o//third_party/dlmalloc/dlmalloc.o \
|
||||
o/rel/third_party/dlmalloc/dlmalloc.o: private \
|
||||
o/$(MODE)/third_party/dlmalloc/dlmalloc.o: private \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-O3
|
||||
endif
|
||||
endif
|
||||
|
||||
# we can't use address sanitizer because:
|
||||
# address sanitizer depends on dlmalloc
|
||||
|
|
4
third_party/dlmalloc/dlmalloc_abort.greg.c
vendored
4
third_party/dlmalloc/dlmalloc_abort.greg.c
vendored
|
@ -16,8 +16,8 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -26,6 +26,6 @@
|
|||
|
||||
void dlmalloc_abort(void) {
|
||||
write(2, MESSAGE, strlen(MESSAGE));
|
||||
if (weaken(__die)) weaken(__die)();
|
||||
if (_weaken(__die)) _weaken(__die)();
|
||||
_Exit(44);
|
||||
}
|
||||
|
|
31
third_party/dlmalloc/locks.inc
vendored
31
third_party/dlmalloc/locks.inc
vendored
|
@ -1,5 +1,8 @@
|
|||
// clang-format off
|
||||
#include "third_party/nsync/mu.h"
|
||||
#include "libc/atomic.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
/* --------------------------- Lock preliminaries ------------------------ */
|
||||
|
@ -32,12 +35,40 @@
|
|||
|
||||
*/
|
||||
|
||||
static int malloc_lock(atomic_int *lk) {
|
||||
if (!__threaded) return 0;
|
||||
while (atomic_exchange_explicit(lk, 1, memory_order_acquire)) {
|
||||
sched_yield();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int malloc_trylock(atomic_int *lk) {
|
||||
if (!__threaded) return 1;
|
||||
return !atomic_exchange_explicit(lk, 1, memory_order_acquire);
|
||||
}
|
||||
|
||||
static inline int malloc_unlock(atomic_int *lk) {
|
||||
atomic_store_explicit(lk, 0, memory_order_release);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !USE_LOCKS
|
||||
#define USE_LOCK_BIT (0U)
|
||||
#define INITIAL_LOCK(l) (0)
|
||||
#define DESTROY_LOCK(l) (0)
|
||||
#define ACQUIRE_MALLOC_GLOBAL_LOCK()
|
||||
#define RELEASE_MALLOC_GLOBAL_LOCK()
|
||||
#elif defined(TINY)
|
||||
#define MLOCK_T atomic_int
|
||||
#define ACQUIRE_LOCK(lk) malloc_lock(lk)
|
||||
#define RELEASE_LOCK(lk) malloc_unlock(lk)
|
||||
#define TRY_LOCK(lk) malloc_trylock(lk)
|
||||
#define INITIAL_LOCK(lk) (*lk = 0, 0)
|
||||
#define DESTROY_LOCK(lk)
|
||||
#define ACQUIRE_MALLOC_GLOBAL_LOCK() ACQUIRE_LOCK(&malloc_global_mutex);
|
||||
#define RELEASE_MALLOC_GLOBAL_LOCK() RELEASE_LOCK(&malloc_global_mutex);
|
||||
static MLOCK_T malloc_global_mutex;
|
||||
#else
|
||||
#define MLOCK_T nsync_mu
|
||||
#define ACQUIRE_LOCK(lk) (__threaded && (nsync_mu_lock(lk), 0))
|
||||
|
|
4
third_party/dlmalloc/mspaces.inc
vendored
4
third_party/dlmalloc/mspaces.inc
vendored
|
@ -208,8 +208,8 @@ void* mspace_malloc(mspace msp, size_t bytes) {
|
|||
|
||||
mem = sys_alloc(ms, nb);
|
||||
POSTACTION(ms);
|
||||
if (mem == MAP_FAILED && weaken(__oom_hook)) {
|
||||
weaken(__oom_hook)(bytes);
|
||||
if (mem == MAP_FAILED && _weaken(__oom_hook)) {
|
||||
_weaken(__oom_hook)(bytes);
|
||||
}
|
||||
return mem;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue