19#if defined (__cplusplus)
34#ifndef ZSTD_CWKSP_ASAN_REDZONE_SIZE
35#define ZSTD_CWKSP_ASAN_REDZONE_SIZE 128
181#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
191 if (phase >
ws->phase) {
194 ws->tableValidEnd =
ws->objectEnd;
205 ws->allocStart = (
BYTE*)
ws->allocStart - ((
size_t)
ws->allocStart & (
sizeof(
U32)-1));
206 if (
ws->allocStart <
ws->tableValidEnd) {
207 ws->tableValidEnd =
ws->allocStart;
218 return (
ptr !=
NULL) && (
ws->workspace <=
ptr) && (ptr <= ws->workspaceEnd);
231#
if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
236 DEBUGLOG(5,
"cwksp: reserving %p %zd bytes, %zd bytes remaining",
241 DEBUGLOG(4,
"cwksp: alloc failed!");
245 if (alloc < ws->tableValidEnd) {
250#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
284 void*
top =
ws->allocStart;
286 DEBUGLOG(5,
"cwksp: reserving %p table %zd bytes, %zd bytes remaining",
293 DEBUGLOG(4,
"cwksp: table alloc failed!");
299#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
314#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
320 "cwksp: reserving %p object %zd bytes (rounded to %zd), %zd bytes remaining",
327 DEBUGLOG(4,
"cwksp: object alloc failed!");
333 ws->tableValidEnd =
end;
335#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
346 DEBUGLOG(4,
"cwksp: ZSTD_cwksp_mark_tables_dirty");
348#if defined (MEMORY_SANITIZER) && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
355 __msan_poison(
ws->objectEnd,
size);
361 ws->tableValidEnd =
ws->objectEnd;
366 DEBUGLOG(4,
"cwksp: ZSTD_cwksp_mark_tables_clean");
369 if (
ws->tableValidEnd <
ws->tableEnd) {
370 ws->tableValidEnd =
ws->tableEnd;
379 DEBUGLOG(4,
"cwksp: ZSTD_cwksp_clean_tables");
382 if (
ws->tableValidEnd <
ws->tableEnd) {
393 DEBUGLOG(4,
"cwksp: clearing tables!");
395#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
398 __asan_poison_memory_region(
ws->objectEnd,
size);
402 ws->tableEnd =
ws->objectEnd;
413#if defined (MEMORY_SANITIZER) && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
420 __msan_poison(
ws->tableValidEnd,
size);
424#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
427 __asan_poison_memory_region(
ws->objectEnd,
size);
431 ws->tableEnd =
ws->objectEnd;
432 ws->allocStart =
ws->workspaceEnd;
446 DEBUGLOG(4,
"cwksp: init'ing workspace with %zd bytes",
size);
450 ws->objectEnd =
ws->workspace;
451 ws->tableValidEnd =
ws->objectEnd;
454 ws->workspaceOversizedDuration = 0;
460 DEBUGLOG(4,
"cwksp: creating new workspace with %zd bytes",
size);
467 void *
ptr =
ws->workspace;
468 DEBUGLOG(4,
"cwksp: freeing workspace");
483 return (
size_t)((
BYTE*)
ws->workspaceEnd - (
BYTE*)
ws->workspace);
487 return ws->allocFailed;
495 return (
size_t)((
BYTE*)
ws->allocStart - (
BYTE*)
ws->tableEnd);
513 ZSTD_cwksp* ws,
size_t additionalNeededSpace) {
515 ws->workspaceOversizedDuration++;
517 ws->workspaceOversizedDuration = 0;
521#if defined (__cplusplus)
static unsigned char bytes[4]
int align(int length, int align)
GLdouble GLdouble GLdouble GLdouble top
int workspaceOversizedDuration
ZSTD_cwksp_alloc_phase_e phase
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
MEM_STATIC size_t ZSTD_cwksp_create(ZSTD_cwksp *ws, size_t size, ZSTD_customMem customMem)
MEM_STATIC size_t ZSTD_cwksp_align(size_t size, size_t const align)
MEM_STATIC void ZSTD_cwksp_mark_tables_clean(ZSTD_cwksp *ws)
MEM_STATIC int ZSTD_cwksp_reserve_failed(const ZSTD_cwksp *ws)
MEM_STATIC void ZSTD_cwksp_move(ZSTD_cwksp *dst, ZSTD_cwksp *src)
MEM_STATIC void ZSTD_cwksp_clean_tables(ZSTD_cwksp *ws)
MEM_STATIC int ZSTD_cwksp_check_too_large(ZSTD_cwksp *ws, size_t additionalNeededSpace)
MEM_STATIC void ZSTD_cwksp_clear_tables(ZSTD_cwksp *ws)
MEM_STATIC void ZSTD_cwksp_assert_internal_consistency(ZSTD_cwksp *ws)
MEM_STATIC void ZSTD_cwksp_internal_advance_phase(ZSTD_cwksp *ws, ZSTD_cwksp_alloc_phase_e phase)
MEM_STATIC int ZSTD_cwksp_owns_buffer(const ZSTD_cwksp *ws, const void *ptr)
MEM_STATIC int ZSTD_cwksp_check_wasteful(ZSTD_cwksp *ws, size_t additionalNeededSpace)
MEM_STATIC size_t ZSTD_cwksp_sizeof(const ZSTD_cwksp *ws)
MEM_STATIC void ZSTD_cwksp_bump_oversized_duration(ZSTD_cwksp *ws, size_t additionalNeededSpace)
MEM_STATIC void ZSTD_cwksp_mark_tables_dirty(ZSTD_cwksp *ws)
@ ZSTD_cwksp_alloc_objects
@ ZSTD_cwksp_alloc_buffers
@ ZSTD_cwksp_alloc_aligned
MEM_STATIC void ZSTD_cwksp_free(ZSTD_cwksp *ws, ZSTD_customMem customMem)
MEM_STATIC void * ZSTD_cwksp_reserve_internal(ZSTD_cwksp *ws, size_t bytes, ZSTD_cwksp_alloc_phase_e phase)
MEM_STATIC BYTE * ZSTD_cwksp_reserve_buffer(ZSTD_cwksp *ws, size_t bytes)
MEM_STATIC void ZSTD_cwksp_clear(ZSTD_cwksp *ws)
MEM_STATIC void * ZSTD_cwksp_reserve_object(ZSTD_cwksp *ws, size_t bytes)
MEM_STATIC size_t ZSTD_cwksp_alloc_size(size_t size)
MEM_STATIC int ZSTD_cwksp_check_available(ZSTD_cwksp *ws, size_t additionalNeededSpace)
MEM_STATIC void * ZSTD_cwksp_reserve_table(ZSTD_cwksp *ws, size_t bytes)
#define ZSTD_CWKSP_ASAN_REDZONE_SIZE
MEM_STATIC void ZSTD_cwksp_init(ZSTD_cwksp *ws, void *start, size_t size)
MEM_STATIC void * ZSTD_cwksp_reserve_aligned(ZSTD_cwksp *ws, size_t bytes)
MEM_STATIC size_t ZSTD_cwksp_available_space(ZSTD_cwksp *ws)
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION
#define RETURN_ERROR_IF(cond, err,...)
#define ZSTD_WORKSPACETOOLARGE_FACTOR