1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include <sys/cdefs.h>
- #include <unistd.h>
- #include <functional>
- #include "Binder.h"
- #include "log.h"
- __BEGIN_DECLS
- ssize_t __attribute__((weak)) getBinderKernelReferences(size_t, uintptr_t*);
- ssize_t __attribute__((weak)) getHWBinderKernelReferences(size_t, uintptr_t*);
- __END_DECLS
- namespace android {
- static bool BinderReferencesToVector(allocator::vector<uintptr_t>& refs,
- std::function<ssize_t(size_t, uintptr_t*)> fn) {
- if (fn == nullptr) {
- return true;
- }
- size_t size = refs.size();
- do {
- refs.resize(size);
- ssize_t ret = fn(refs.size(), refs.data());
- if (ret < 0) {
- return false;
- }
- size = ret;
- } while (size > refs.size());
- refs.resize(size);
- return true;
- }
- bool BinderReferences(allocator::vector<uintptr_t>& refs) {
- refs.clear();
- allocator::vector<uintptr_t> binder_refs{refs.get_allocator()};
- if (BinderReferencesToVector(refs, getBinderKernelReferences)) {
- refs.insert(refs.end(), binder_refs.begin(), binder_refs.end());
- } else {
- MEM_ALOGE("getBinderKernelReferences failed");
- }
- allocator::vector<uintptr_t> hwbinder_refs{refs.get_allocator()};
- if (BinderReferencesToVector(hwbinder_refs, getHWBinderKernelReferences)) {
- refs.insert(refs.end(), hwbinder_refs.begin(), hwbinder_refs.end());
- } else {
- MEM_ALOGE("getHWBinderKernelReferences failed");
- }
- return true;
- }
- }
|