summaryrefslogtreecommitdiff
path: root/zap/src/mem/memgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'zap/src/mem/memgen.c')
-rw-r--r--zap/src/mem/memgen.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/zap/src/mem/memgen.c b/zap/src/mem/memgen.c
new file mode 100644
index 0000000..a39e326
--- /dev/null
+++ b/zap/src/mem/memgen.c
@@ -0,0 +1,25 @@
+/*
+ Copyright 2022 Gabriel Jensen.
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+ If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
+*/
+
+#include <zap/priv.h>
+
+/*.globl zap_memgen
+
+zap_memgen:*/
+
+ /*
+ void * ptr
+ zap_sz sz
+ zap_sz num
+ void (* fn)(zap_sz,void *)
+ */
+
+void zap_memgen(void * const _ptr,zap_sz const _sz,zap_sz const _num,void (* const _fn)(zap_sz,void *)) {
+ unsigned char * ptr = _ptr;
+ unsigned char * const afterbuf = ptr + _sz * _num;
+ for (;ptr != afterbuf;ptr += _sz) {_fn((ptr - (unsigned char *)_ptr) / _sz,ptr);}
+}
+