summaryrefslogtreecommitdiffhomepage
path: root/src/string/ntapi_tt_aligned_block_memlock.c
blob: fbc9e049f0ffdcf2dc9f67439cbb33dab1bd1f89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntapi/nt_string.h>
#include <ntapi/nt_sync.h>
#include <ntapi/nt_atomic.h>

#define __CPU_CACHE_SIZE 64

__attr_protected__
uintptr_t * __cdecl __ntapi_tt_aligned_block_memlock(
	__in	uintptr_t *	dst,
	__in	size_t		bytes)
{
	size_t addr = (size_t)dst & ~(size_t)(__CPU_CACHE_SIZE);
	size_t cap  = addr + bytes;

	for (; addr<cap; addr+=__CPU_CACHE_SIZE)
		at_locked_xadd((intptr_t *)addr,0);

	return dst;
}