ReactOS 0.4.15-dev-7918-g2a2556c
zstd_cwksp.h File Reference
#include "zstd_internal.h"
Include dependency graph for zstd_cwksp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ZSTD_cwksp
 

Macros

#define ZSTD_CWKSP_ASAN_REDZONE_SIZE   128
 

Enumerations

enum  ZSTD_cwksp_alloc_phase_e { ZSTD_cwksp_alloc_objects , ZSTD_cwksp_alloc_buffers , ZSTD_cwksp_alloc_aligned }
 

Functions

MEM_STATIC size_t ZSTD_cwksp_available_space (ZSTD_cwksp *ws)
 
MEM_STATIC void ZSTD_cwksp_assert_internal_consistency (ZSTD_cwksp *ws)
 
MEM_STATIC size_t ZSTD_cwksp_align (size_t size, size_t const align)
 
MEM_STATIC size_t ZSTD_cwksp_alloc_size (size_t size)
 
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 voidZSTD_cwksp_reserve_internal (ZSTD_cwksp *ws, size_t bytes, ZSTD_cwksp_alloc_phase_e phase)
 
MEM_STATIC BYTEZSTD_cwksp_reserve_buffer (ZSTD_cwksp *ws, size_t bytes)
 
MEM_STATIC voidZSTD_cwksp_reserve_aligned (ZSTD_cwksp *ws, size_t bytes)
 
MEM_STATIC voidZSTD_cwksp_reserve_table (ZSTD_cwksp *ws, size_t bytes)
 
MEM_STATIC voidZSTD_cwksp_reserve_object (ZSTD_cwksp *ws, size_t bytes)
 
MEM_STATIC void ZSTD_cwksp_mark_tables_dirty (ZSTD_cwksp *ws)
 
MEM_STATIC void ZSTD_cwksp_mark_tables_clean (ZSTD_cwksp *ws)
 
MEM_STATIC void ZSTD_cwksp_clean_tables (ZSTD_cwksp *ws)
 
MEM_STATIC void ZSTD_cwksp_clear_tables (ZSTD_cwksp *ws)
 
MEM_STATIC void ZSTD_cwksp_clear (ZSTD_cwksp *ws)
 
MEM_STATIC void ZSTD_cwksp_init (ZSTD_cwksp *ws, void *start, size_t size)
 
MEM_STATIC size_t ZSTD_cwksp_create (ZSTD_cwksp *ws, size_t size, ZSTD_customMem customMem)
 
MEM_STATIC void ZSTD_cwksp_free (ZSTD_cwksp *ws, ZSTD_customMem customMem)
 
MEM_STATIC void ZSTD_cwksp_move (ZSTD_cwksp *dst, ZSTD_cwksp *src)
 
MEM_STATIC size_t ZSTD_cwksp_sizeof (const ZSTD_cwksp *ws)
 
MEM_STATIC int ZSTD_cwksp_reserve_failed (const ZSTD_cwksp *ws)
 
MEM_STATIC int ZSTD_cwksp_check_available (ZSTD_cwksp *ws, size_t additionalNeededSpace)
 
MEM_STATIC int ZSTD_cwksp_check_too_large (ZSTD_cwksp *ws, size_t additionalNeededSpace)
 
MEM_STATIC int ZSTD_cwksp_check_wasteful (ZSTD_cwksp *ws, size_t additionalNeededSpace)
 
MEM_STATIC void ZSTD_cwksp_bump_oversized_duration (ZSTD_cwksp *ws, size_t additionalNeededSpace)
 

Macro Definition Documentation

◆ ZSTD_CWKSP_ASAN_REDZONE_SIZE

#define ZSTD_CWKSP_ASAN_REDZONE_SIZE   128

Definition at line 35 of file zstd_cwksp.h.

Enumeration Type Documentation

◆ ZSTD_cwksp_alloc_phase_e

Enumerator
ZSTD_cwksp_alloc_objects 
ZSTD_cwksp_alloc_buffers 
ZSTD_cwksp_alloc_aligned 

Definition at line 41 of file zstd_cwksp.h.

41 {
ZSTD_cwksp_alloc_phase_e
Definition: zstd_cwksp.h:41
@ ZSTD_cwksp_alloc_objects
Definition: zstd_cwksp.h:42
@ ZSTD_cwksp_alloc_buffers
Definition: zstd_cwksp.h:43
@ ZSTD_cwksp_alloc_aligned
Definition: zstd_cwksp.h:44

Function Documentation

◆ ZSTD_cwksp_align()

MEM_STATIC size_t ZSTD_cwksp_align ( size_t  size,
size_t const  align 
)

Align must be a power of 2.

Definition at line 164 of file zstd_cwksp.h.

164 {
165 size_t const mask = align - 1;
166 assert((align & mask) == 0);
167 return (size + mask) & ~mask;
168}
#define assert(x)
Definition: debug.h:53
int align(int length, int align)
Definition: dsound8.c:36
GLsizeiptr size
Definition: glext.h:5919
GLenum GLint GLuint mask
Definition: glext.h:6028

Referenced by ZSTD_createCDict_advanced(), ZSTD_cwksp_reserve_aligned(), ZSTD_cwksp_reserve_object(), ZSTD_estimateCDictSize_advanced(), ZSTD_initCDict_internal(), and ZSTD_initStaticCDict().

◆ ZSTD_cwksp_alloc_size()

MEM_STATIC size_t ZSTD_cwksp_alloc_size ( size_t  size)

Use this to determine how much space in the workspace we will consume to allocate this object. (Normally it should be exactly the size of the object, but under special conditions, like ASAN, where we pad each object, it might be larger.)

Since tables aren't currently redzoned, you don't need to call through this to figure out how much space you need for the matchState tables. Everything else is though.

Definition at line 180 of file zstd_cwksp.h.

180 {
181#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
183#else
184 return size;
185#endif
186}
#define ZSTD_CWKSP_ASAN_REDZONE_SIZE
Definition: zstd_cwksp.h:35

Referenced by ZSTD_createCDict_advanced(), ZSTD_estimateCCtxSize_usingCCtxParams(), ZSTD_estimateCDictSize_advanced(), ZSTD_estimateCStreamSize_usingCCtxParams(), ZSTD_initStaticCDict(), ZSTD_ldm_getTableSize(), ZSTD_resetCCtx_internal(), and ZSTD_sizeof_matchState().

◆ ZSTD_cwksp_assert_internal_consistency()

MEM_STATIC void ZSTD_cwksp_assert_internal_consistency ( ZSTD_cwksp ws)

Definition at line 151 of file zstd_cwksp.h.

151 {
152 (void)ws;
153 assert(ws->workspace <= ws->objectEnd);
154 assert(ws->objectEnd <= ws->tableEnd);
155 assert(ws->objectEnd <= ws->tableValidEnd);
156 assert(ws->tableEnd <= ws->allocStart);
157 assert(ws->tableValidEnd <= ws->allocStart);
158 assert(ws->allocStart <= ws->workspaceEnd);
159}
const char * ws
Definition: skip_ws.cpp:7

Referenced by ZSTD_cwksp_clear(), ZSTD_cwksp_clear_tables(), ZSTD_cwksp_init(), ZSTD_cwksp_mark_tables_clean(), ZSTD_cwksp_mark_tables_dirty(), ZSTD_cwksp_reserve_internal(), ZSTD_cwksp_reserve_object(), and ZSTD_cwksp_reserve_table().

◆ ZSTD_cwksp_available_space()

MEM_STATIC size_t ZSTD_cwksp_available_space ( ZSTD_cwksp ws)

Definition at line 494 of file zstd_cwksp.h.

494 {
495 return (size_t)((BYTE*)ws->allocStart - (BYTE*)ws->tableEnd);
496}
unsigned char BYTE
Definition: xxhash.c:193

Referenced by ZSTD_cwksp_check_available(), ZSTD_cwksp_reserve_internal(), ZSTD_cwksp_reserve_object(), ZSTD_cwksp_reserve_table(), and ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_bump_oversized_duration()

MEM_STATIC void ZSTD_cwksp_bump_oversized_duration ( ZSTD_cwksp ws,
size_t  additionalNeededSpace 
)

Definition at line 512 of file zstd_cwksp.h.

513 {
514 if (ZSTD_cwksp_check_too_large(ws, additionalNeededSpace)) {
515 ws->workspaceOversizedDuration++;
516 } else {
517 ws->workspaceOversizedDuration = 0;
518 }
519}
MEM_STATIC int ZSTD_cwksp_check_too_large(ZSTD_cwksp *ws, size_t additionalNeededSpace)
Definition: zstd_cwksp.h:502

Referenced by ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_check_available()

MEM_STATIC int ZSTD_cwksp_check_available ( ZSTD_cwksp ws,
size_t  additionalNeededSpace 
)

Definition at line 498 of file zstd_cwksp.h.

498 {
499 return ZSTD_cwksp_available_space(ws) >= additionalNeededSpace;
500}
MEM_STATIC size_t ZSTD_cwksp_available_space(ZSTD_cwksp *ws)
Definition: zstd_cwksp.h:494

Referenced by ZSTD_cwksp_check_too_large(), ZSTD_initStaticCCtx(), and ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_check_too_large()

MEM_STATIC int ZSTD_cwksp_check_too_large ( ZSTD_cwksp ws,
size_t  additionalNeededSpace 
)

Definition at line 502 of file zstd_cwksp.h.

502 {
504 ws, additionalNeededSpace * ZSTD_WORKSPACETOOLARGE_FACTOR);
505}
MEM_STATIC int ZSTD_cwksp_check_available(ZSTD_cwksp *ws, size_t additionalNeededSpace)
Definition: zstd_cwksp.h:498
#define ZSTD_WORKSPACETOOLARGE_FACTOR

Referenced by ZSTD_cwksp_bump_oversized_duration(), and ZSTD_cwksp_check_wasteful().

◆ ZSTD_cwksp_check_wasteful()

MEM_STATIC int ZSTD_cwksp_check_wasteful ( ZSTD_cwksp ws,
size_t  additionalNeededSpace 
)

Definition at line 507 of file zstd_cwksp.h.

507 {
508 return ZSTD_cwksp_check_too_large(ws, additionalNeededSpace)
509 && ws->workspaceOversizedDuration > ZSTD_WORKSPACETOOLARGE_MAXDURATION;
510}
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION

Referenced by ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_clean_tables()

MEM_STATIC void ZSTD_cwksp_clean_tables ( ZSTD_cwksp ws)

Zero the part of the allocated tables not already marked clean.

Definition at line 378 of file zstd_cwksp.h.

378 {
379 DEBUGLOG(4, "cwksp: ZSTD_cwksp_clean_tables");
380 assert(ws->tableValidEnd >= ws->objectEnd);
381 assert(ws->tableValidEnd <= ws->allocStart);
382 if (ws->tableValidEnd < ws->tableEnd) {
383 memset(ws->tableValidEnd, 0, (BYTE*)ws->tableEnd - (BYTE*)ws->tableValidEnd);
384 }
386}
#define DEBUGLOG(l,...)
Definition: debug.h:106
#define memset(x, y, z)
Definition: compat.h:39
MEM_STATIC void ZSTD_cwksp_mark_tables_clean(ZSTD_cwksp *ws)
Definition: zstd_cwksp.h:365

Referenced by ZSTD_reset_matchState().

◆ ZSTD_cwksp_clear()

MEM_STATIC void ZSTD_cwksp_clear ( ZSTD_cwksp ws)

Invalidates all buffer, aligned, and table allocations. Object allocations remain valid.

Definition at line 410 of file zstd_cwksp.h.

410 {
411 DEBUGLOG(4, "cwksp: clearing!");
412
413#if defined (MEMORY_SANITIZER) && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
414 /* To validate that the context re-use logic is sound, and that we don't
415 * access stuff that this compression hasn't initialized, we re-"poison"
416 * the workspace (or at least the non-static, non-table parts of it)
417 * every time we start a new compression. */
418 {
419 size_t size = (BYTE*)ws->workspaceEnd - (BYTE*)ws->tableValidEnd;
420 __msan_poison(ws->tableValidEnd, size);
421 }
422#endif
423
424#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
425 {
426 size_t size = (BYTE*)ws->workspaceEnd - (BYTE*)ws->objectEnd;
427 __asan_poison_memory_region(ws->objectEnd, size);
428 }
429#endif
430
431 ws->tableEnd = ws->objectEnd;
432 ws->allocStart = ws->workspaceEnd;
433 ws->allocFailed = 0;
434 if (ws->phase > ZSTD_cwksp_alloc_buffers) {
436 }
438}
MEM_STATIC void ZSTD_cwksp_assert_internal_consistency(ZSTD_cwksp *ws)
Definition: zstd_cwksp.h:151

Referenced by ZSTD_cwksp_init(), and ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_clear_tables()

MEM_STATIC void ZSTD_cwksp_clear_tables ( ZSTD_cwksp ws)

Invalidates table allocations. All other allocations remain valid.

Definition at line 392 of file zstd_cwksp.h.

392 {
393 DEBUGLOG(4, "cwksp: clearing tables!");
394
395#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
396 {
397 size_t size = (BYTE*)ws->tableValidEnd - (BYTE*)ws->objectEnd;
398 __asan_poison_memory_region(ws->objectEnd, size);
399 }
400#endif
401
402 ws->tableEnd = ws->objectEnd;
404}

Referenced by ZSTD_reset_matchState().

◆ ZSTD_cwksp_create()

MEM_STATIC size_t ZSTD_cwksp_create ( ZSTD_cwksp ws,
size_t  size,
ZSTD_customMem  customMem 
)

Definition at line 458 of file zstd_cwksp.h.

458 {
459 void* workspace = ZSTD_malloc(size, customMem);
460 DEBUGLOG(4, "cwksp: creating new workspace with %zd bytes", size);
461 RETURN_ERROR_IF(workspace == NULL, memory_allocation, "NULL pointer!");
462 ZSTD_cwksp_init(ws, workspace, size);
463 return 0;
464}
#define NULL
Definition: types.h:112
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
Definition: zstd_common.c:56
MEM_STATIC void ZSTD_cwksp_init(ZSTD_cwksp *ws, void *start, size_t size)
Definition: zstd_cwksp.h:445
#define RETURN_ERROR_IF(cond, err,...)
Definition: zstd_internal.h:91

Referenced by ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_free()

MEM_STATIC void ZSTD_cwksp_free ( ZSTD_cwksp ws,
ZSTD_customMem  customMem 
)

Definition at line 466 of file zstd_cwksp.h.

466 {
467 void *ptr = ws->workspace;
468 DEBUGLOG(4, "cwksp: freeing workspace");
469 memset(ws, 0, sizeof(ZSTD_cwksp));
470 ZSTD_free(ptr, customMem);
471}
static PVOID ptr
Definition: dispmode.c:27
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
Definition: zstd_common.c:70

Referenced by ZSTD_freeCCtxContent(), ZSTD_freeCDict(), and ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_init()

MEM_STATIC void ZSTD_cwksp_init ( ZSTD_cwksp ws,
void start,
size_t  size 
)

The provided workspace takes ownership of the buffer [start, start+size). Any existing values in the workspace are ignored (the previously managed buffer, if present, must be separately freed).

Definition at line 445 of file zstd_cwksp.h.

445 {
446 DEBUGLOG(4, "cwksp: init'ing workspace with %zd bytes", size);
447 assert(((size_t)start & (sizeof(void*)-1)) == 0); /* ensure correct alignment */
448 ws->workspace = start;
449 ws->workspaceEnd = (BYTE*)start + size;
450 ws->objectEnd = ws->workspace;
451 ws->tableValidEnd = ws->objectEnd;
454 ws->workspaceOversizedDuration = 0;
456}
GLuint start
Definition: gl.h:1545
MEM_STATIC void ZSTD_cwksp_clear(ZSTD_cwksp *ws)
Definition: zstd_cwksp.h:410

Referenced by ZSTD_createCDict_advanced(), ZSTD_cwksp_create(), ZSTD_initStaticCCtx(), and ZSTD_initStaticCDict().

◆ ZSTD_cwksp_internal_advance_phase()

MEM_STATIC void ZSTD_cwksp_internal_advance_phase ( ZSTD_cwksp ws,
ZSTD_cwksp_alloc_phase_e  phase 
)

Definition at line 188 of file zstd_cwksp.h.

189 {
190 assert(phase >= ws->phase);
191 if (phase > ws->phase) {
192 if (ws->phase < ZSTD_cwksp_alloc_buffers &&
193 phase >= ZSTD_cwksp_alloc_buffers) {
194 ws->tableValidEnd = ws->objectEnd;
195 }
196 if (ws->phase < ZSTD_cwksp_alloc_aligned &&
197 phase >= ZSTD_cwksp_alloc_aligned) {
198 /* If unaligned allocations down from a too-large top have left us
199 * unaligned, we need to realign our alloc ptr. Technically, this
200 * can consume space that is unaccounted for in the neededSpace
201 * calculation. However, I believe this can only happen when the
202 * workspace is too large, and specifically when it is too large
203 * by a larger margin than the space that will be consumed. */
204 /* TODO: cleaner, compiler warning friendly way to do this??? */
205 ws->allocStart = (BYTE*)ws->allocStart - ((size_t)ws->allocStart & (sizeof(U32)-1));
206 if (ws->allocStart < ws->tableValidEnd) {
207 ws->tableValidEnd = ws->allocStart;
208 }
209 }
210 ws->phase = phase;
211 }
212}
unsigned int U32
Definition: xxhash.c:195

Referenced by ZSTD_cwksp_reserve_internal(), and ZSTD_cwksp_reserve_table().

◆ ZSTD_cwksp_mark_tables_clean()

MEM_STATIC void ZSTD_cwksp_mark_tables_clean ( ZSTD_cwksp ws)

Definition at line 365 of file zstd_cwksp.h.

365 {
366 DEBUGLOG(4, "cwksp: ZSTD_cwksp_mark_tables_clean");
367 assert(ws->tableValidEnd >= ws->objectEnd);
368 assert(ws->tableValidEnd <= ws->allocStart);
369 if (ws->tableValidEnd < ws->tableEnd) {
370 ws->tableValidEnd = ws->tableEnd;
371 }
373}

Referenced by ZSTD_copyCCtx_internal(), ZSTD_cwksp_clean_tables(), ZSTD_overflowCorrectIfNeeded(), and ZSTD_resetCCtx_byCopyingCDict().

◆ ZSTD_cwksp_mark_tables_dirty()

MEM_STATIC void ZSTD_cwksp_mark_tables_dirty ( ZSTD_cwksp ws)

Definition at line 345 of file zstd_cwksp.h.

345 {
346 DEBUGLOG(4, "cwksp: ZSTD_cwksp_mark_tables_dirty");
347
348#if defined (MEMORY_SANITIZER) && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
349 /* To validate that the table re-use logic is sound, and that we don't
350 * access table space that we haven't cleaned, we re-"poison" the table
351 * space every time we mark it dirty. */
352 {
353 size_t size = (BYTE*)ws->tableValidEnd - (BYTE*)ws->objectEnd;
354 assert(__msan_test_shadow(ws->objectEnd, size) == -1);
355 __msan_poison(ws->objectEnd, size);
356 }
357#endif
358
359 assert(ws->tableValidEnd >= ws->objectEnd);
360 assert(ws->tableValidEnd <= ws->allocStart);
361 ws->tableValidEnd = ws->objectEnd;
363}

Referenced by ZSTD_copyCCtx_internal(), ZSTD_overflowCorrectIfNeeded(), ZSTD_reset_matchState(), and ZSTD_resetCCtx_byCopyingCDict().

◆ ZSTD_cwksp_move()

MEM_STATIC void ZSTD_cwksp_move ( ZSTD_cwksp dst,
ZSTD_cwksp src 
)

Moves the management of a workspace from one cwksp to another. The src cwksp is left in an invalid state (src must be re-init()'ed before its used again).

Definition at line 477 of file zstd_cwksp.h.

477 {
478 *dst = *src;
479 memset(src, 0, sizeof(ZSTD_cwksp));
480}
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_createCDict_advanced(), ZSTD_initStaticCCtx(), and ZSTD_initStaticCDict().

◆ ZSTD_cwksp_owns_buffer()

MEM_STATIC int ZSTD_cwksp_owns_buffer ( const ZSTD_cwksp ws,
const void ptr 
)

Returns whether this object/buffer/etc was allocated in this workspace.

Definition at line 217 of file zstd_cwksp.h.

217 {
218 return (ptr != NULL) && (ws->workspace <= ptr) && (ptr <= ws->workspaceEnd);
219}

Referenced by ZSTD_freeCCtx(), and ZSTD_freeCDict().

◆ ZSTD_cwksp_reserve_aligned()

MEM_STATIC void * ZSTD_cwksp_reserve_aligned ( ZSTD_cwksp ws,
size_t  bytes 
)

Reserves and returns memory sized on and aligned on sizeof(unsigned).

Definition at line 270 of file zstd_cwksp.h.

270 {
271 assert((bytes & (sizeof(U32)-1)) == 0);
273}
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
MEM_STATIC size_t ZSTD_cwksp_align(size_t size, size_t const align)
Definition: zstd_cwksp.h:164
MEM_STATIC void * ZSTD_cwksp_reserve_internal(ZSTD_cwksp *ws, size_t bytes, ZSTD_cwksp_alloc_phase_e phase)
Definition: zstd_cwksp.h:224

Referenced by ZSTD_reset_matchState(), and ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_reserve_buffer()

MEM_STATIC BYTE * ZSTD_cwksp_reserve_buffer ( ZSTD_cwksp ws,
size_t  bytes 
)

Reserves and returns unaligned memory.

Definition at line 263 of file zstd_cwksp.h.

Referenced by ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_reserve_failed()

MEM_STATIC int ZSTD_cwksp_reserve_failed ( const ZSTD_cwksp ws)

Definition at line 486 of file zstd_cwksp.h.

486 {
487 return ws->allocFailed;
488}

Referenced by ZSTD_reset_matchState().

◆ ZSTD_cwksp_reserve_internal()

MEM_STATIC void * ZSTD_cwksp_reserve_internal ( ZSTD_cwksp ws,
size_t  bytes,
ZSTD_cwksp_alloc_phase_e  phase 
)

Internal function. Do not use directly.

Definition at line 224 of file zstd_cwksp.h.

225 {
226 void* alloc;
227 void* bottom = ws->tableEnd;
229 alloc = (BYTE *)ws->allocStart - bytes;
230
231#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
232 /* over-reserve space */
234#endif
235
236 DEBUGLOG(5, "cwksp: reserving %p %zd bytes, %zd bytes remaining",
239 assert(alloc >= bottom);
240 if (alloc < bottom) {
241 DEBUGLOG(4, "cwksp: alloc failed!");
242 ws->allocFailed = 1;
243 return NULL;
244 }
245 if (alloc < ws->tableValidEnd) {
246 ws->tableValidEnd = alloc;
247 }
248 ws->allocStart = alloc;
249
250#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
251 /* Move alloc so there's ZSTD_CWKSP_ASAN_REDZONE_SIZE unused space on
252 * either size. */
254 __asan_unpoison_memory_region(alloc, bytes);
255#endif
256
257 return alloc;
258}
GLint GLint bottom
Definition: glext.h:7726
#define alloc
Definition: rosglue.h:13
MEM_STATIC void ZSTD_cwksp_internal_advance_phase(ZSTD_cwksp *ws, ZSTD_cwksp_alloc_phase_e phase)
Definition: zstd_cwksp.h:188

Referenced by ZSTD_cwksp_reserve_aligned(), and ZSTD_cwksp_reserve_buffer().

◆ ZSTD_cwksp_reserve_object()

MEM_STATIC void * ZSTD_cwksp_reserve_object ( ZSTD_cwksp ws,
size_t  bytes 
)

Aligned on sizeof(void*).

Definition at line 309 of file zstd_cwksp.h.

309 {
310 size_t roundedBytes = ZSTD_cwksp_align(bytes, sizeof(void*));
311 void* alloc = ws->objectEnd;
312 void* end = (BYTE*)alloc + roundedBytes;
313
314#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
315 /* over-reserve space */
317#endif
318
319 DEBUGLOG(5,
320 "cwksp: reserving %p object %zd bytes (rounded to %zd), %zd bytes remaining",
321 alloc, bytes, roundedBytes, ZSTD_cwksp_available_space(ws) - roundedBytes);
322 assert(((size_t)alloc & (sizeof(void*)-1)) == 0);
323 assert((bytes & (sizeof(void*)-1)) == 0);
325 /* we must be in the first phase, no advance is possible */
326 if (ws->phase != ZSTD_cwksp_alloc_objects || end > ws->workspaceEnd) {
327 DEBUGLOG(4, "cwksp: object alloc failed!");
328 ws->allocFailed = 1;
329 return NULL;
330 }
331 ws->objectEnd = end;
332 ws->tableEnd = end;
333 ws->tableValidEnd = end;
334
335#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
336 /* Move alloc so there's ZSTD_CWKSP_ASAN_REDZONE_SIZE unused space on
337 * either size. */
339 __asan_unpoison_memory_region(alloc, bytes);
340#endif
341
342 return alloc;
343}
GLuint GLuint end
Definition: gl.h:1545

Referenced by ZSTD_createCDict_advanced(), ZSTD_initCDict_internal(), ZSTD_initStaticCCtx(), ZSTD_initStaticCDict(), and ZSTD_resetCCtx_internal().

◆ ZSTD_cwksp_reserve_table()

MEM_STATIC void * ZSTD_cwksp_reserve_table ( ZSTD_cwksp ws,
size_t  bytes 
)

Aligned on sizeof(unsigned). These buffers have the special property that their values remain constrained, allowing us to re-use them without memset()-ing them.

Definition at line 280 of file zstd_cwksp.h.

280 {
282 void* alloc = ws->tableEnd;
283 void* end = (BYTE *)alloc + bytes;
284 void* top = ws->allocStart;
285
286 DEBUGLOG(5, "cwksp: reserving %p table %zd bytes, %zd bytes remaining",
288 assert((bytes & (sizeof(U32)-1)) == 0);
291 assert(end <= top);
292 if (end > top) {
293 DEBUGLOG(4, "cwksp: table alloc failed!");
294 ws->allocFailed = 1;
295 return NULL;
296 }
297 ws->tableEnd = end;
298
299#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
300 __asan_unpoison_memory_region(alloc, bytes);
301#endif
302
303 return alloc;
304}
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859

Referenced by ZSTD_reset_matchState().

◆ ZSTD_cwksp_sizeof()

MEM_STATIC size_t ZSTD_cwksp_sizeof ( const ZSTD_cwksp ws)

Definition at line 482 of file zstd_cwksp.h.

482 {
483 return (size_t)((BYTE*)ws->workspaceEnd - (BYTE*)ws->workspace);
484}

Referenced by ZSTD_resetCCtx_internal(), ZSTD_sizeof_CCtx(), and ZSTD_sizeof_CDict().