1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include <linux/ashmem.h>
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
20 static void* libhandle() {
21 static void* handle
= dlopen("libandroid.so", RTLD_LAZY
| RTLD_LOCAL
);
25 int ashmem_create(const char* name
, size_t size
) {
27 (int (*)(const char*, size_t))dlsym(libhandle(), "ASharedMemory_create");
30 return fCreate(name
, size
);
33 int fd
= open("/" ASHMEM_NAME_DEF
, O_RDWR
);
39 char str
[ASHMEM_NAME_LEN
];
40 strlcpy(str
, name
, sizeof(str
));
41 ioctl(fd
, ASHMEM_SET_NAME
, str
);
44 if (ioctl(fd
, ASHMEM_SET_SIZE
, size
) != 0) {
52 size_t ashmem_getSize(int fd
) {
53 static auto fGetSize
=
54 (size_t(*)(int))dlsym(libhandle(), "ASharedMemory_getSize");
59 return (size_t)ioctl(fd
, ASHMEM_GET_SIZE
, nullptr);
62 int ashmem_setProt(int fd
, int prot
) {
63 static auto fSetProt
=
64 (int (*)(int, int))dlsym(libhandle(), "ASharedMemory_setProt");
66 return fSetProt(fd
, prot
);
69 return ioctl(fd
, ASHMEM_SET_PROT_MASK
, prot
);
72 } // namespace android
73 } // namespace mozilla