Hidlized version of IMemory.

- Add hidl_memory type.
- Add android.hidl.memory@1.0 package
  - IMapper
  - IAllocator
  - IMemory
- Add libhidlmemory
- Add default implementation of android.hidl.memory@1.0
  - Ashmem
  - Ion (TODO, probably in another CL)

Test: compiles (WIP)
Change-Id: I4632eeb6a0051551b54ce04d919aaf551dfc5f28
diff --git a/transport/memory/1.0/Android.bp b/transport/memory/1.0/Android.bp
new file mode 100644
index 0000000..5839197
--- /dev/null
+++ b/transport/memory/1.0/Android.bp
@@ -0,0 +1,66 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+genrule {
+    name: "android.hidl.memory@1.0_genc++",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.memory@1.0",
+    srcs: [
+        "IAllocator.hal",
+        "IMapper.hal",
+        "IMemory.hal",
+    ],
+    out: [
+        "android/hidl/memory/1.0/AllocatorAll.cpp",
+        "android/hidl/memory/1.0/MapperAll.cpp",
+        "android/hidl/memory/1.0/MemoryAll.cpp",
+    ],
+}
+
+genrule {
+    name: "android.hidl.memory@1.0_genc++_headers",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.memory@1.0",
+    srcs: [
+        "IAllocator.hal",
+        "IMapper.hal",
+        "IMemory.hal",
+    ],
+    out: [
+        "android/hidl/memory/1.0/IAllocator.h",
+        "android/hidl/memory/1.0/IHwAllocator.h",
+        "android/hidl/memory/1.0/BnAllocator.h",
+        "android/hidl/memory/1.0/BpAllocator.h",
+        "android/hidl/memory/1.0/BsAllocator.h",
+        "android/hidl/memory/1.0/IMapper.h",
+        "android/hidl/memory/1.0/IHwMapper.h",
+        "android/hidl/memory/1.0/BnMapper.h",
+        "android/hidl/memory/1.0/BpMapper.h",
+        "android/hidl/memory/1.0/BsMapper.h",
+        "android/hidl/memory/1.0/IMemory.h",
+        "android/hidl/memory/1.0/IHwMemory.h",
+        "android/hidl/memory/1.0/BnMemory.h",
+        "android/hidl/memory/1.0/BpMemory.h",
+        "android/hidl/memory/1.0/BsMemory.h",
+    ],
+}
+
+cc_library_shared {
+    name: "android.hidl.memory@1.0",
+    generated_sources: ["android.hidl.memory@1.0_genc++"],
+    generated_headers: ["android.hidl.memory@1.0_genc++_headers"],
+    export_generated_headers: ["android.hidl.memory@1.0_genc++_headers"],
+    shared_libs: [
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "liblog",
+        "libutils",
+        "libcutils",
+    ],
+    export_shared_lib_headers: [
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "libutils",
+    ],
+}
diff --git a/transport/memory/1.0/IAllocator.hal b/transport/memory/1.0/IAllocator.hal
new file mode 100644
index 0000000..7f540aa
--- /dev/null
+++ b/transport/memory/1.0/IAllocator.hal
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hidl.memory@1.0;
+
+/**
+ * Interface which allocates the required memory.
+ */
+interface IAllocator {
+
+    /**
+     * Return memory must have instance name corresponding to this type of memory.
+     *
+     * @param size Size of memory to allocate in bytes.
+     * @return success Whether allocation succeeded.
+     * @return memory Unmapped memory object.
+     */
+    allocate(uint64_t size) generates (bool success, memory mem);
+};
\ No newline at end of file
diff --git a/transport/memory/1.0/IMapper.hal b/transport/memory/1.0/IMapper.hal
new file mode 100644
index 0000000..6f730a0
--- /dev/null
+++ b/transport/memory/1.0/IMapper.hal
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hidl.memory@1.0;
+
+import IMemory;
+
+interface IMapper {
+
+    /**
+     * @param mem Reference to shared memory.
+     * @return mappedMemory Object representing memory mapped in this process.
+     *                      This will be null if mapping fails.
+     */
+    mapMemory(memory mem) generates (IMemory mappedMemory);
+};
diff --git a/transport/memory/1.0/IMemory.hal b/transport/memory/1.0/IMemory.hal
new file mode 100644
index 0000000..1b38336
--- /dev/null
+++ b/transport/memory/1.0/IMemory.hal
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hidl.memory@1.0;
+
+interface IMemory {
+
+    /**
+     * Notify that you are about to use this memory.
+     */
+    update();
+
+    /**
+     * Notify that you are done modifying this memory.
+     */
+    commit();
+
+    /**
+     * @return ptr Actual pointer to underlying memory.
+     */
+    getPointer() generates (pointer ptr);
+
+    /**
+     * @return size Size in bytes of underlying memory.
+     */
+    getSize() generates (uint64_t size);
+
+};
\ No newline at end of file
diff --git a/transport/memory/1.0/default/Android.bp b/transport/memory/1.0/default/Android.bp
new file mode 100644
index 0000000..b5079e8
--- /dev/null
+++ b/transport/memory/1.0/default/Android.bp
@@ -0,0 +1,57 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_shared {
+    name: "android.hidl.memory@1.0-impl",
+    relative_install_path: "hw",
+    srcs: [
+        "AshmemAllocator.cpp",
+        "AshmemMapper.cpp",
+        "AshmemMemory.cpp",
+        "HidlFetch.cpp"
+    ],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libhardware",
+        "libhwbinder",
+        "libbase",
+        "libcutils",
+        "libutils",
+        "libhidlbase",
+        "libhidltransport",
+        "android.hidl.memory@1.0",
+    ],
+}
+
+cc_binary {
+    name: "android.hidl.memory@1.0-service",
+    relative_install_path: "hw",
+    srcs: ["service.cpp"],
+    init_rc: ["android.hidl.memory@1.0-service.rc"],
+
+    shared_libs: [
+        "android.hidl.memory@1.0",
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "liblog",
+        "libutils",
+    ],
+
+    required: [
+        // only one implementation is allowed
+        "android.hidl.memory@1.0-impl"
+    ]
+}
diff --git a/transport/memory/1.0/default/AshmemAllocator.cpp b/transport/memory/1.0/default/AshmemAllocator.cpp
new file mode 100644
index 0000000..59ae3e1
--- /dev/null
+++ b/transport/memory/1.0/default/AshmemAllocator.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "AshmemAllocator.h"
+
+#include <cutils/ashmem.h>
+
+namespace android {
+namespace hidl {
+namespace memory {
+namespace V1_0 {
+namespace implementation {
+
+// Methods from ::android::hidl::memory::V1_0::IAllocator follow.
+Return<void> AshmemAllocator::allocate(uint64_t size, allocate_cb _hidl_cb) {
+    int fd = ashmem_create_region("AshmemAllocator_hidl", size);
+    if (fd < 0) {
+        _hidl_cb(false /* success */, hidl_memory());
+        return Void();
+    }
+
+    native_handle_t* handle = native_handle_create(1, 0);
+    handle->data[0] = fd;
+    hidl_memory memory("ashmem", handle, size);
+
+    _hidl_cb(true /* success */, memory);
+    return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace memory
+}  // namespace hidl
+}  // namespace android
diff --git a/transport/memory/1.0/default/AshmemAllocator.h b/transport/memory/1.0/default/AshmemAllocator.h
new file mode 100644
index 0000000..35ad420
--- /dev/null
+++ b/transport/memory/1.0/default/AshmemAllocator.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_HIDL_ASHMEM_MEMORY_V1_0_ALLOCATOR_H
+#define ANDROID_HIDL_ASHMEM_MEMORY_V1_0_ALLOCATOR_H
+
+#include <android/hidl/memory/1.0/IAllocator.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hidl {
+namespace memory {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hidl::memory::V1_0::IAllocator;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct AshmemAllocator : public IAllocator {
+    // Methods from ::android::hidl::memory::V1_0::IAllocator follow.
+    Return<void> allocate(uint64_t size, allocate_cb _hidl_cb) override;
+
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace memory
+}  // namespace hidl
+}  // namespace android
+
+#endif  // ANDROID_HIDL_ASHMEM_MEMORY_V1_0_ALLOCATOR_H
diff --git a/transport/memory/1.0/default/AshmemMapper.cpp b/transport/memory/1.0/default/AshmemMapper.cpp
new file mode 100644
index 0000000..37eb8af
--- /dev/null
+++ b/transport/memory/1.0/default/AshmemMapper.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "AshmemMapper.h"
+
+#include <sys/mman.h>
+
+#include "AshmemMemory.h"
+
+namespace android {
+namespace hidl {
+namespace memory {
+namespace V1_0 {
+namespace implementation {
+
+// Methods from ::android::hidl::memory::V1_0::IMapper follow.
+Return<void> AshmemMapper::mapMemory(const hidl_memory& mem, mapMemory_cb _hidl_cb) {
+    if (mem.handle()->numFds == 0) {
+        _hidl_cb(nullptr);
+        return Void();
+    }
+
+    int fd = mem.handle()->data[0];
+    void* data = mmap(0, mem.size(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+    if (data == MAP_FAILED) {
+        // mmap never maps at address zero without MAP_FIXED, so we can avoid
+        // exposing clients to MAP_FAILED.
+        _hidl_cb(nullptr);
+        return Void();
+    }
+
+    sp<IMemory> memory = new AshmemMemory(mem, data);
+
+    _hidl_cb(memory);
+    return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace memory
+}  // namespace hidl
+}  // namespace android
diff --git a/transport/memory/1.0/default/AshmemMapper.h b/transport/memory/1.0/default/AshmemMapper.h
new file mode 100644
index 0000000..c6cfc37
--- /dev/null
+++ b/transport/memory/1.0/default/AshmemMapper.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_HIDL_ASHMEM_MEMORY_V1_0_MAPPER_H
+#define ANDROID_HIDL_ASHMEM_MEMORY_V1_0_MAPPER_H
+
+#include <android/hidl/memory/1.0/IMapper.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hidl {
+namespace memory {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hidl::memory::V1_0::IMapper;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct AshmemMapper : public IMapper {
+    // Methods from ::android::hidl::memory::V1_0::IMapper follow.
+    Return<void> mapMemory(const hidl_memory& mem, mapMemory_cb _hidl_cb) override;
+
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace memory
+}  // namespace hidl
+}  // namespace android
+
+#endif  // ANDROID_HIDL_ASHMEM_MEMORY_V1_0_MAPPER_H
diff --git a/transport/memory/1.0/default/AshmemMemory.cpp b/transport/memory/1.0/default/AshmemMemory.cpp
new file mode 100644
index 0000000..31626ea
--- /dev/null
+++ b/transport/memory/1.0/default/AshmemMemory.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/mman.h>
+
+#include "AshmemMemory.h"
+
+namespace android {
+namespace hidl {
+namespace memory {
+namespace V1_0 {
+namespace implementation {
+
+AshmemMemory::AshmemMemory(const hidl_memory& memory, void* data)
+  : mMemory(memory),
+    mData(data)
+{}
+
+AshmemMemory::~AshmemMemory()
+{
+    // TODO: Move implementation to mapper class
+    munmap(mData, mMemory.size());
+}
+
+// Methods from ::android::hidl::memory::V1_0::IMemory follow.
+Return<void> AshmemMemory::update() {
+    // NOOP
+    return Void();
+}
+
+Return<void> AshmemMemory::commit() {
+    // NOOP
+    return Void();
+}
+
+Return<void*> AshmemMemory::getPointer() {
+    return mData;
+}
+
+Return<uint64_t> AshmemMemory::getSize() {
+    return mMemory.size();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace memory
+}  // namespace hidl
+}  // namespace android
diff --git a/transport/memory/1.0/default/AshmemMemory.h b/transport/memory/1.0/default/AshmemMemory.h
new file mode 100644
index 0000000..9dbe1fe
--- /dev/null
+++ b/transport/memory/1.0/default/AshmemMemory.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_HIDL_ASHMEM_MEMORY_V1_0_MEMORY_H
+#define ANDROID_HIDL_ASHMEM_MEMORY_V1_0_MEMORY_H
+
+#include <android/hidl/memory/1.0/IMemory.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hidl {
+namespace memory {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hidl::memory::V1_0::IMemory;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct AshmemMemory : public IMemory {
+
+    AshmemMemory(const hidl_memory& memory, void* mappedMemory);
+    ~AshmemMemory();
+
+    // Methods from ::android::hidl::memory::V1_0::IMemory follow.
+    Return<void> update() override;
+    Return<void> commit() override;
+    Return<void*> getPointer() override;
+    Return<uint64_t> getSize() override;
+
+private:
+    // Holding onto hidl_memory reference because it contains
+    // handle and size, and handle will also be required for
+    // the remoted case.
+    hidl_memory mMemory;
+
+    // Mapped memory in process.
+    void* mData;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace memory
+}  // namespace hidl
+}  // namespace android
+
+#endif  // ANDROID_HIDL_ASHMEM_MEMORY_V1_0_MEMORY_H
diff --git a/transport/memory/1.0/default/HidlFetch.cpp b/transport/memory/1.0/default/HidlFetch.cpp
new file mode 100644
index 0000000..8236055
--- /dev/null
+++ b/transport/memory/1.0/default/HidlFetch.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "HidlFetch.h"
+
+#include "AshmemAllocator.h"
+#include "AshmemMapper.h"
+
+static std::string kAshmemMemoryName = "ashmem";
+
+namespace android {
+namespace hidl {
+namespace memory {
+namespace V1_0 {
+namespace implementation {
+
+IAllocator* HIDL_FETCH_IAllocator(const char* name) {
+    if (name == kAshmemMemoryName) {
+        return new AshmemAllocator;
+    }
+
+    return nullptr;
+}
+
+IMapper* HIDL_FETCH_IMapper(const char* name) {
+    if (name == kAshmemMemoryName) {
+        return new AshmemMapper;
+    }
+
+    return nullptr;
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace memory
+}  // namespace hidl
+}  // namespace android
diff --git a/transport/memory/1.0/default/HidlFetch.h b/transport/memory/1.0/default/HidlFetch.h
new file mode 100644
index 0000000..a9d366f
--- /dev/null
+++ b/transport/memory/1.0/default/HidlFetch.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HIDL_FETCH_H
+#define HIDL_FETCH_H
+
+#include <android/hidl/memory/1.0/IAllocator.h>
+#include <android/hidl/memory/1.0/IMapper.h>
+
+namespace android {
+namespace hidl {
+namespace memory {
+namespace V1_0 {
+namespace implementation {
+
+// TODO: disable passthrough allocator. It's much better if it's in a centralized location
+extern "C" IAllocator* HIDL_FETCH_IAllocator(const char* name);
+
+extern "C" IMapper* HIDL_FETCH_IMapper(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace memory
+}  // namespace hidl
+}  // namespace android
+
+#endif  // HIDL_FETCH_H
\ No newline at end of file
diff --git a/transport/memory/1.0/default/android.hidl.memory@1.0-service.rc b/transport/memory/1.0/default/android.hidl.memory@1.0-service.rc
new file mode 100644
index 0000000..1caaae9
--- /dev/null
+++ b/transport/memory/1.0/default/android.hidl.memory@1.0-service.rc
@@ -0,0 +1,4 @@
+service hidl_memory /system/bin/hw/android.hidl.memory@1.0-service
+    class hal
+    user system
+    group system
diff --git a/transport/memory/1.0/default/service.cpp b/transport/memory/1.0/default/service.cpp
new file mode 100644
index 0000000..ff3a8e8
--- /dev/null
+++ b/transport/memory/1.0/default/service.cpp
@@ -0,0 +1,12 @@
+#define LOG_TAG "android.hidl.memory@1.0-service"
+
+#include <android/hidl/memory/1.0/IAllocator.h>
+
+#include <hidl/LegacySupport.h>
+
+using android::hidl::memory::V1_0::IAllocator;
+using android::hardware::defaultPassthroughServiceImplementation;
+
+int main() {
+    return defaultPassthroughServiceImplementation<IAllocator>("ashmem");
+}