Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/devel/ElectricFence/files/patch-efence.c
18160 views
1
--- efence.c.orig 2019-02-26 17:53:52.941236000 +0100
2
+++ efence.c 2019-02-26 17:56:18.688752000 +0100
3
@@ -38,6 +38,7 @@
4
# include <pthread.h>
5
# include <semaphore.h>
6
#endif
7
+#include <errno.h>
8
9
#ifdef malloc
10
#undef malloc
11
@@ -670,6 +671,27 @@
12
release();
13
14
return address;
15
+}
16
+
17
+extern C_LINKAGE int
18
+posix_memalign(void **memptr, size_t alignment, size_t userSize)
19
+{
20
+ /*
21
+ * Per standard, posix_memalign returns EINVAL when alignment
22
+ * is not a power of two or power of sizeof(void*). efence
23
+ * doesn't check the value of alignment in memalign, but then
24
+ * again, memalign was never specified very well, and on some
25
+ * systems odd alignments could indeed have been allowed.
26
+ */
27
+ if ((alignment & (alignment - 1))
28
+ || alignment % sizeof (void *))
29
+ return EINVAL;
30
+
31
+ void *ptr = memalign (alignment, userSize);
32
+ if (ptr == NULL)
33
+ return ENOMEM;
34
+ *memptr = ptr;
35
+ return 0;
36
}
37
38
/*
39
40