summaryrefslogtreecommitdiffhomepage
path: root/src/string
diff options
context:
space:
mode:
Diffstat (limited to 'src/string')
-rw-r--r--src/string/ntapi_tt_aligned_block_memlock.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/string/ntapi_tt_aligned_block_memlock.c b/src/string/ntapi_tt_aligned_block_memlock.c
new file mode 100644
index 0000000..5aa3a7e
--- /dev/null
+++ b/src/string/ntapi_tt_aligned_block_memlock.c
@@ -0,0 +1,23 @@
+/********************************************************/
+/* ntapi: Native API core library */
+/* Copyright (C) 2013--2018 Z. Gilboa */
+/* 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>
+
+uintptr_t * __cdecl __ntapi_tt_aligned_block_memlock(
+ __in uintptr_t * dst,
+ __in size_t bytes)
+{
+ size_t addr = (size_t)dst & ~(size_t)(NT_SYNC_BLOCK_SIZE);
+ size_t cap = addr + bytes;
+
+ for (; addr<cap; addr+=NT_SYNC_BLOCK_SIZE)
+ at_locked_xadd((intptr_t *)addr,0);
+
+ return dst;
+}