Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inc/system/hunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ typedef struct {
size_t mapped;
} memhunk_t;

// hunk allocation alignment is rounded to cacheline
#define HUNK_ALIGN 64

void Hunk_Init(void);
void Hunk_Begin(memhunk_t *hunk, size_t maxsize);
void *Hunk_TryAlloc(memhunk_t *hunk, size_t size);
Expand Down
6 changes: 3 additions & 3 deletions src/common/bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ static void BSP_LoadBspxNormals(bsp_t* bsp, const byte* in, size_t data_size)

static size_t BSP_ParseNormalsHeader(bsp_t* bsp, const byte* in, size_t data_size)
{
return data_size;
return data_size + HUNK_ALIGN - 1; // extra memory to account for alignment in ALLOC()
}

static void BSP_ParseDecoupledLM(bsp_t *bsp, const byte *in, size_t filelen)
Expand Down Expand Up @@ -1331,7 +1331,7 @@ static size_t BSP_ParseExtensionHeader(bsp_t *bsp, lump_t *out, const byte *buf,
break;
}
if (e->parse_header)
extrasize += e->parse_header(bsp, buf + ofs, len);
extrasize += ALIGN(e->parse_header(bsp, buf + ofs, len), HUNK_ALIGN); // to mirror Hunk_TryAlloc() overallocation
out[j].fileofs = ofs;
out[j].filelen = len;
break;
Expand Down Expand Up @@ -1432,7 +1432,7 @@ int BSP_Load(const char *name, bsp_t **bsp_p)
lump_count[i] = count;

// round to cacheline
memsize += ALIGN(count * info->memsize, 64);
memsize += ALIGN(count * info->memsize, HUNK_ALIGN);
maxpos = max(maxpos, end);
}

Expand Down
4 changes: 2 additions & 2 deletions src/unix/hunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ void *Hunk_TryAlloc(memhunk_t *hunk, size_t size)
{
void *buf;

Q_assert(size <= SIZE_MAX - 63);
Q_assert(size <= SIZE_MAX - (HUNK_ALIGN - 1));
Q_assert(hunk->cursize <= hunk->maxsize);

// round to cacheline
size = ALIGN(size, 64);
size = ALIGN(size, HUNK_ALIGN);
if (size > hunk->maxsize - hunk->cursize)
return NULL;

Expand Down