summaryrefslogtreecommitdiff
path: root/ext/tap-mac/tuntap/src/mem.cc
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-11-06 11:01:34 -0500
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-11-06 11:01:34 -0500
commit6b8c90bffd4f052cdeb3a09f0c9d44c2767dd0a4 (patch)
tree483a94332a42f52ed9b55c3bdec3c2f3e9e849db /ext/tap-mac/tuntap/src/mem.cc
parent9455b1cc810eff7517f51f50eee828344af3526a (diff)
downloadinfinitytier-6b8c90bffd4f052cdeb3a09f0c9d44c2767dd0a4.tar.gz
infinitytier-6b8c90bffd4f052cdeb3a09f0c9d44c2767dd0a4.zip
Upgrade LZ4, remove extraneous files, put tap-mac into ext/ to declutter root.
Diffstat (limited to 'ext/tap-mac/tuntap/src/mem.cc')
-rw-r--r--ext/tap-mac/tuntap/src/mem.cc76
1 files changed, 76 insertions, 0 deletions
diff --git a/ext/tap-mac/tuntap/src/mem.cc b/ext/tap-mac/tuntap/src/mem.cc
new file mode 100644
index 00000000..cd3264fa
--- /dev/null
+++ b/ext/tap-mac/tuntap/src/mem.cc
@@ -0,0 +1,76 @@
+/*
+ * ip tunnel/ethertap device for MacOSX. Common functionality of tap_interface and tun_interface.
+ *
+ * Memory management implementation.
+ */
+/*
+ * Copyright (c) 2011 Mattias Nissler <mattias.nissler@gmx.de>
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "mem.h"
+
+extern "C" {
+
+#include <libkern/OSMalloc.h>
+
+}
+
+#if 0
+#define dprintf(...) log(LOG_INFO, __VA_ARGS__)
+#else
+#define dprintf(...)
+#endif
+
+static int inited = 0;
+static OSMallocTag tag;
+
+void
+mem_initialize(const char* name) {
+
+ if (!inited) {
+ tag = OSMalloc_Tagalloc(name, OSMT_DEFAULT);
+ inited = 1;
+ }
+}
+
+void
+mem_shutdown() {
+
+ if (inited) {
+ OSMalloc_Tagfree(tag);
+ inited = 0;
+ }
+}
+
+void *
+mem_alloc(uint32_t size) {
+
+ return OSMalloc(size, tag);
+}
+
+void
+mem_free(void *addr, uint32_t size) {
+
+ OSFree(addr, size, tag);
+}
+