@@ -53,21 +53,21 @@ namespace {
5353 */
5454
5555/* Callback used with __system_property_read_callback. */
56- void prop_read_int (void * cookie,
57- const char * name,
58- const char * value,
59- uint32_t serial) {
56+ void ReadIntProperty (void * cookie,
57+ const char * name,
58+ const char * value,
59+ uint32_t serial) {
6060 *reinterpret_cast <int *>(cookie) = atoi (value);
6161 (void )name;
6262 (void )serial;
6363}
6464
65- int system_property_get_int (const char * name) {
65+ int SystemPropertyGetInt (const char * name) {
6666 int result = 0 ;
6767 if (__builtin_available (android 26 , *)) {
6868 const prop_info* info = __system_property_find (name);
6969 if (info) {
70- __system_property_read_callback (info, &prop_read_int , &result);
70+ __system_property_read_callback (info, &ReadIntProperty , &result);
7171 }
7272 } else {
7373 char value[PROP_VALUE_MAX] = {};
@@ -78,10 +78,10 @@ int system_property_get_int(const char* name) {
7878 return result;
7979}
8080
81- int vendor_api_level () {
81+ int VendorApiLevel () {
8282 static int v_api_level = -1 ;
8383 if (v_api_level < 0 ) {
84- v_api_level = system_property_get_int (" ro.vendor.api_level" );
84+ v_api_level = SystemPropertyGetInt (" ro.vendor.api_level" );
8585 }
8686 return v_api_level;
8787}
@@ -96,7 +96,7 @@ AshmemStatus s_ashmem_status = ASHMEM_STATUS_INIT;
9696dev_t s_ashmem_dev;
9797
9898/* Return the dev_t of a given file path, or 0 if not available, */
99- dev_t ashmem_find_dev (const char * path) {
99+ dev_t FindAshmemDevice (const char * path) {
100100 struct stat st;
101101 dev_t result = 0 ;
102102 if (stat (path, &st) == 0 && S_ISCHR (st.st_mode )) {
@@ -105,48 +105,30 @@ dev_t ashmem_find_dev(const char* path) {
105105 return result;
106106}
107107
108- AshmemStatus ashmem_get_status () {
108+ AshmemStatus GetAshmemSupportStatus () {
109109 /* NOTE: No need to make this thread-safe, assuming that
110110 * all threads will find the same value. */
111111 if (s_ashmem_status != ASHMEM_STATUS_INIT) {
112112 return s_ashmem_status;
113113 }
114114
115- s_ashmem_dev = ashmem_find_dev (ASHMEM_DEVICE);
115+ s_ashmem_dev = FindAshmemDevice (ASHMEM_DEVICE);
116116 s_ashmem_status = (s_ashmem_dev == 0 ) ? ASHMEM_STATUS_NOT_SUPPORTED
117117 : ASHMEM_STATUS_SUPPORTED;
118118 return s_ashmem_status;
119119}
120120
121121/* Returns true iff the ashmem device ioctl should be used for a given fd.
122122 * NOTE: Try not to use fstat() when possible to avoid performance issues. */
123- bool is_ashmem_fd (int fd) {
124- if (ashmem_get_status () == ASHMEM_STATUS_SUPPORTED) {
123+ bool IsAshmemFd (int fd) {
124+ if (GetAshmemSupportStatus () == ASHMEM_STATUS_SUPPORTED) {
125125 struct stat st;
126126 return (fstat (fd, &st) == 0 && S_ISCHR (st.st_mode ) && st.st_dev != 0 &&
127127 st.st_dev == s_ashmem_dev);
128128 }
129129 return false ;
130130}
131131
132- int ashmem_dev_get_prot_region (int fd) {
133- return ioctl (fd, ASHMEM_GET_PROT_MASK);
134- }
135-
136- int ashmem_dev_pin_region (int fd, size_t offset, size_t len) {
137- struct ashmem_pin pin = {static_cast <__u32>(offset), static_cast <__u32>(len)};
138- return ioctl (fd, ASHMEM_PIN, &pin);
139- }
140-
141- int ashmem_dev_unpin_region (int fd, size_t offset, size_t len) {
142- struct ashmem_pin pin = {static_cast <__u32>(offset), static_cast <__u32>(len)};
143- return ioctl (fd, ASHMEM_UNPIN, &pin);
144- }
145-
146- size_t ashmem_dev_get_size_region (int fd) {
147- return ioctl (fd, ASHMEM_GET_SIZE, NULL );
148- }
149-
150132// Starting with API level 26, the following functions from
151133// libandroid.so should be used to create shared memory regions,
152134// unless the device's vendor.api_level is 202604 (Android 17)
@@ -167,7 +149,7 @@ struct ASharedMemoryFuncs {
167149ASharedMemoryFuncs s_ashmem_funcs = {};
168150pthread_once_t s_ashmem_funcs_once = PTHREAD_ONCE_INIT;
169151
170- int memfd_create_region (const char * name, size_t size) {
152+ int MemfdCreateRegion (const char * name, size_t size) {
171153 int fd = syscall (__NR_memfd_create, name, MFD_CLOEXEC | MFD_ALLOW_SEALING);
172154 if (fd < 0 ) {
173155 LOG_E (" memfd_create(%s, %zd) failed: %m" , name, size);
@@ -226,18 +208,18 @@ int memfd_set_prot_region(int fd, int prot) {
226208 return 0 ;
227209}
228210
229- int memfd_get_prot_region (int fd) {
211+ int MemfdGetProtRegion (int fd) {
230212 int prot = PROT_READ;
231213 int seals = fcntl (fd, F_GET_SEALS);
232214 if (seals == -1 ) {
233- LOG_E (" memfd_get_prot_region (%d): F_GET_SEALS failed: %m" , fd);
215+ LOG_E (" MemfdGetProtRegion (%d): F_GET_SEALS failed: %m" , fd);
234216 } else if (!(seals & (F_SEAL_FUTURE_WRITE | F_SEAL_WRITE))) {
235217 prot |= PROT_WRITE;
236218 }
237219 return prot;
238220}
239221
240- void ashmem_init_funcs () {
222+ void InitAshmemFuncs () {
241223 ASharedMemoryFuncs* funcs = &s_ashmem_funcs;
242224 /*
243225 * When a device conforms to the VSR for API level 202604 (Android 17),
@@ -249,8 +231,8 @@ void ashmem_init_funcs() {
249231 * the existing sepolicy for appdomain_tmpfs files, just allocate memfds
250232 * directly if the device conforms to the VSR for API level 202604.
251233 */
252- if (vendor_api_level () >= 202604 ) {
253- funcs->create = &memfd_create_region ;
234+ if (VendorApiLevel () >= 202604 ) {
235+ funcs->create = &MemfdCreateRegion ;
254236 funcs->setProt = &memfd_set_prot_region;
255237 } else {
256238 /* Leaked intentionally! */
@@ -262,12 +244,12 @@ void ashmem_init_funcs() {
262244 }
263245}
264246
265- const ASharedMemoryFuncs* ashmem_get_funcs () {
266- pthread_once (&s_ashmem_funcs_once, &ashmem_init_funcs );
247+ const ASharedMemoryFuncs* GetAshmemFuncs () {
248+ pthread_once (&s_ashmem_funcs_once, &InitAshmemFuncs );
267249 return &s_ashmem_funcs;
268250}
269251
270- bool is_memfd_fd (int fd) {
252+ bool IsMemfdFd (int fd) {
271253 if (fcntl (fd, F_GET_SEALS, 0 ) == -1 ) {
272254 return false ;
273255 }
@@ -276,57 +258,47 @@ bool is_memfd_fd(int fd) {
276258
277259} // namespace
278260
279- int ashmem_create_region (const char * name, size_t size) {
280- return ashmem_get_funcs ()->create (name, size);
261+ int SharedMemoryRegionCreate (const char * name, size_t size) {
262+ return GetAshmemFuncs ()->create (name, size);
281263}
282264
283- int ashmem_set_prot_region (int fd, int prot) {
284- return ashmem_get_funcs ()->setProt (fd, prot);
265+ int SharedMemoryRegionSetProtectionFlags (int fd, int prot) {
266+ return GetAshmemFuncs ()->setProt (fd, prot);
285267}
286268
287- int ashmem_get_prot_region (int fd) {
288- if (is_memfd_fd (fd)) {
289- return memfd_get_prot_region (fd);
269+ int SharedMemoryRegionGetProtectionFlags (int fd) {
270+ if (IsMemfdFd (fd)) {
271+ return MemfdGetProtRegion (fd);
290272 }
291273
292- if (is_ashmem_fd (fd)) {
293- return ashmem_dev_get_prot_region (fd);
274+ if (IsAshmemFd (fd)) {
275+ return ioctl (fd, ASHMEM_GET_PROT_MASK );
294276 }
295277
296278 return -1 ;
297279}
298280
299- int ashmem_pin_region (int fd, size_t offset, size_t len) {
300- if (is_ashmem_fd (fd)) {
301- return ashmem_dev_pin_region (fd, offset, len);
281+ int AshmemPinRegion (int fd, size_t offset, size_t len) {
282+ if (IsAshmemFd (fd)) {
283+ struct ashmem_pin pin = {static_cast <__u32>(offset),
284+ static_cast <__u32>(len)};
285+ return ioctl (fd, ASHMEM_PIN, &pin);
302286 }
303287 return ASHMEM_NOT_PURGED;
304288}
305289
306- int ashmem_unpin_region (int fd, size_t offset, size_t len) {
307- if (is_ashmem_fd (fd)) {
308- return ashmem_dev_unpin_region (fd, offset, len);
290+ int AshmemUnpinRegion (int fd, size_t offset, size_t len) {
291+ if (IsAshmemFd (fd)) {
292+ struct ashmem_pin pin = {static_cast <__u32>(offset),
293+ static_cast <__u32>(len)};
294+ return ioctl (fd, ASHMEM_UNPIN, &pin);
309295 }
310296 /* NOTE: It is not possible to use madvise() here because it requires a
311297 * memory address. This could be done in the caller though, instead of
312298 * this function. */
313299 return 0 ;
314300}
315301
316- int ashmem_get_size_region (int fd) {
317- if (is_ashmem_fd (fd)) {
318- return ashmem_dev_get_size_region (fd);
319- }
320-
321- struct stat sb;
322- if (fstat (fd, &sb) == -1 ) {
323- LOG_E (" fstat(%d) failed: %m" , fd);
324- return -1 ;
325- }
326-
327- return sb.st_size ;
328- }
329-
330- int ashmem_device_is_supported () {
331- return ashmem_get_status () == ASHMEM_STATUS_SUPPORTED;
302+ int AshmemDeviceIsSupported () {
303+ return GetAshmemSupportStatus () == ASHMEM_STATUS_SUPPORTED;
332304}
0 commit comments