1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28 #include <new>
29 #include <stdatomic.h>
30 #include <stdio.h>
31 #include <stdint.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <stddef.h>
35 #include <errno.h>
36 #include <poll.h>
37 #include <fcntl.h>
38 #include <stdbool.h>
39 #include <string.h>
41 #include <sys/mman.h>
43 #include <sys/socket.h>
44 #include <sys/un.h>
45 #include <sys/select.h>
46 #include <sys/stat.h>
47 #include <sys/types.h>
48 #include <netinet/in.h>
50 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
51 #include <sys/_system_properties.h>
52 #include <sys/system_properties.h>
54 #include "private/bionic_atomic_inline.h"
55 #include "private/bionic_futex.h"
56 #include "private/bionic_macros.h"
58 static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME;
61 /*
62 * Properties are stored in a hybrid trie/binary tree structure.
63 * Each property's name is delimited at '.' characters, and the tokens are put
64 * into a trie structure. Siblings at each level of the trie are stored in a
65 * binary tree. For instance, "ro.secure"="1" could be stored as follows:
66 *
67 * +-----+ children +----+ children +--------+
68 * | |-------------->| ro |-------------->| secure |
69 * +-----+ +----+ +--------+
70 * / \ / |
71 * left / \ right left / | prop +===========+
72 * v v v +-------->| ro.secure |
73 * +-----+ +-----+ +-----+ +-----------+
74 * | net | | sys | | com | | 1 |
75 * +-----+ +-----+ +-----+ +===========+
76 */
78 // Represents a node in the trie.
79 struct prop_bt {
80 uint8_t namelen;
81 uint8_t reserved[3];
83 // TODO: The following fields should be declared as atomic_uint32_t.
84 // They should be assigned to with release semantics, instead of using
85 // explicit fences. Unfortunately, the read accesses are generally
86 // followed by more dependent read accesses, and the dependence
87 // is assumed to enforce memory ordering. Which it does on supported
88 // hardware. This technically should use memory_order_consume, if
89 // that worked as intended.
90 // We should also avoid rereading these fields redundantly, since not
91 // all processor implementations ensure that multiple loads from the
92 // same field are carried out in the right order.
93 volatile uint32_t prop;
95 volatile uint32_t left;
96 volatile uint32_t right;
98 volatile uint32_t children;
100 char name[0];
102 prop_bt(const char *name, const uint8_t name_length) {
103 this->namelen = name_length;
104 memcpy(this->name, name, name_length);
105 this->name[name_length] = '\0';
106 ANDROID_MEMBAR_FULL(); // TODO: Instead use a release store
107 // for subsequent pointer assignment.
108 }
110 private:
111 DISALLOW_COPY_AND_ASSIGN(prop_bt);
112 };
114 struct prop_area {
115 uint32_t bytes_used;
116 atomic_uint_least32_t serial;
117 uint32_t magic;
118 uint32_t version;
119 uint32_t reserved[28];
120 char data[0];
122 prop_area(const uint32_t magic, const uint32_t version) :
123 magic(magic), version(version) {
124 atomic_init(&serial, 0);
125 memset(reserved, 0, sizeof(reserved));
126 // Allocate enough space for the root node.
127 bytes_used = sizeof(prop_bt);
128 }
130 private:
131 DISALLOW_COPY_AND_ASSIGN(prop_area);
132 };
134 struct prop_info {
135 atomic_uint_least32_t serial;
136 char value[PROP_VALUE_MAX];
137 char name[0];
139 prop_info(const char *name, const uint8_t namelen, const char *value,
140 const uint8_t valuelen) {
141 memcpy(this->name, name, namelen);
142 this->name[namelen] = '\0';
143 atomic_init(&this->serial, valuelen << 24);
144 memcpy(this->value, value, valuelen);
145 this->value[valuelen] = '\0';
146 ANDROID_MEMBAR_FULL(); // TODO: Instead use a release store
147 // for subsequent point assignment.
148 }
149 private:
150 DISALLOW_COPY_AND_ASSIGN(prop_info);
151 };
153 struct find_nth_cookie {
154 uint32_t count;
155 const uint32_t n;
156 const prop_info *pi;
158 find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
159 }
160 };
162 static char property_filename[PATH_MAX] = PROP_FILENAME;
163 static bool compat_mode = false;
164 static size_t pa_data_size;
165 static size_t pa_size;
167 // NOTE: This isn't static because system_properties_compat.c
168 // requires it.
169 prop_area *__system_property_area__ = NULL;
171 static int get_fd_from_env(void)
172 {
173 // This environment variable consistes of two decimal integer
174 // values separated by a ",". The first value is a file descriptor
175 // and the second is the size of the system properties area. The
176 // size is currently unused.
177 char *env = getenv("ANDROID_PROPERTY_WORKSPACE");
179 if (!env) {
180 return -1;
181 }
183 return atoi(env);
184 }
186 static int map_prop_area_rw()
187 {
188 /* dev is a tmpfs that we can use to carve a shared workspace
189 * out of, so let's do that...
190 */
191 const int fd = open(property_filename,
192 O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC | O_EXCL, 0444);
194 if (fd < 0) {
195 if (errno == EACCES) {
196 /* for consistency with the case where the process has already
197 * mapped the page in and segfaults when trying to write to it
198 */
199 abort();
200 }
201 return -1;
202 }
204 if (ftruncate(fd, PA_SIZE) < 0) {
205 close(fd);
206 return -1;
207 }
209 pa_size = PA_SIZE;
210 pa_data_size = pa_size - sizeof(prop_area);
211 compat_mode = false;
213 void *const memory_area = mmap(NULL, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
214 if (memory_area == MAP_FAILED) {
215 close(fd);
216 return -1;
217 }
219 prop_area *pa = new(memory_area) prop_area(PROP_AREA_MAGIC, PROP_AREA_VERSION);
221 /* plug into the lib property services */
222 __system_property_area__ = pa;
224 close(fd);
225 return 0;
226 }
228 static int map_fd_ro(const int fd) {
229 struct stat fd_stat;
230 if (fstat(fd, &fd_stat) < 0) {
231 return -1;
232 }
234 if ((fd_stat.st_uid != 0)
235 || (fd_stat.st_gid != 0)
236 || ((fd_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0)
237 || (fd_stat.st_size < static_cast<off_t>(sizeof(prop_area))) ) {
238 return -1;
239 }
241 pa_size = fd_stat.st_size;
242 pa_data_size = pa_size - sizeof(prop_area);
244 void* const map_result = mmap(NULL, pa_size, PROT_READ, MAP_SHARED, fd, 0);
245 if (map_result == MAP_FAILED) {
246 return -1;
247 }
249 prop_area* pa = reinterpret_cast<prop_area*>(map_result);
250 if ((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION &&
251 pa->version != PROP_AREA_VERSION_COMPAT)) {
252 munmap(pa, pa_size);
253 return -1;
254 }
256 if (pa->version == PROP_AREA_VERSION_COMPAT) {
257 compat_mode = true;
258 }
260 __system_property_area__ = pa;
261 return 0;
262 }
264 static int map_prop_area()
265 {
266 int fd = open(property_filename, O_CLOEXEC | O_NOFOLLOW | O_RDONLY);
267 bool close_fd = true;
268 if (fd == -1 && errno == ENOENT) {
269 /*
270 * For backwards compatibility, if the file doesn't
271 * exist, we use the environment to get the file descriptor.
272 * For security reasons, we only use this backup if the kernel
273 * returns ENOENT. We don't want to use the backup if the kernel
274 * returns other errors such as ENOMEM or ENFILE, since it
275 * might be possible for an external program to trigger this
276 * condition.
277 */
278 fd = get_fd_from_env();
279 close_fd = false;
280 }
282 if (fd < 0) {
283 return -1;
284 }
286 const int map_result = map_fd_ro(fd);
287 if (close_fd) {
288 close(fd);
289 }
291 return map_result;
292 }
294 static void *allocate_obj(const size_t size, uint32_t *const off)
295 {
296 prop_area *pa = __system_property_area__;
297 const size_t aligned = BIONIC_ALIGN(size, sizeof(uint32_t));
298 if (pa->bytes_used + aligned > pa_data_size) {
299 return NULL;
300 }
302 *off = pa->bytes_used;
303 pa->bytes_used += aligned;
304 return pa->data + *off;
305 }
307 static prop_bt *new_prop_bt(const char *name, uint8_t namelen, uint32_t *const off)
308 {
309 uint32_t new_offset;
310 void *const offset = allocate_obj(sizeof(prop_bt) + namelen + 1, &new_offset);
311 if (offset) {
312 prop_bt* bt = new(offset) prop_bt(name, namelen);
313 *off = new_offset;
314 return bt;
315 }
317 return NULL;
318 }
320 static prop_info *new_prop_info(const char *name, uint8_t namelen,
321 const char *value, uint8_t valuelen, uint32_t *const off)
322 {
323 uint32_t off_tmp;
324 void* const offset = allocate_obj(sizeof(prop_info) + namelen + 1, &off_tmp);
325 if (offset) {
326 prop_info* info = new(offset) prop_info(name, namelen, value, valuelen);
327 *off = off_tmp;
328 return info;
329 }
331 return NULL;
332 }
334 static void *to_prop_obj(const uint32_t off)
335 {
336 if (off > pa_data_size)
337 return NULL;
338 if (!__system_property_area__)
339 return NULL;
341 return (__system_property_area__->data + off);
342 }
344 static prop_bt *root_node()
345 {
346 return reinterpret_cast<prop_bt*>(to_prop_obj(0));
347 }
349 static int cmp_prop_name(const char *one, uint8_t one_len, const char *two,
350 uint8_t two_len)
351 {
352 if (one_len < two_len)
353 return -1;
354 else if (one_len > two_len)
355 return 1;
356 else
357 return strncmp(one, two, one_len);
358 }
360 static prop_bt *find_prop_bt(prop_bt *const bt, const char *name,
361 uint8_t namelen, bool alloc_if_needed)
362 {
364 prop_bt* current = bt;
365 while (true) {
366 if (!current) {
367 return NULL;
368 }
370 const int ret = cmp_prop_name(name, namelen, current->name, current->namelen);
371 if (ret == 0) {
372 return current;
373 }
375 if (ret < 0) {
376 if (current->left) {
377 current = reinterpret_cast<prop_bt*>(to_prop_obj(current->left));
378 } else {
379 if (!alloc_if_needed) {
380 return NULL;
381 }
383 // Note that there isn't a race condition here. "clients" never
384 // reach this code-path since It's only the (single threaded) server
385 // that allocates new nodes. Though "bt->left" is volatile, it can't
386 // have changed since the last value was last read.
387 uint32_t new_offset = 0;
388 prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
389 if (new_bt) {
390 current->left = new_offset;
391 }
392 return new_bt;
393 }
394 } else {
395 if (current->right) {
396 current = reinterpret_cast<prop_bt*>(to_prop_obj(current->right));
397 } else {
398 if (!alloc_if_needed) {
399 return NULL;
400 }
402 uint32_t new_offset;
403 prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
404 if (new_bt) {
405 current->right = new_offset;
406 }
407 return new_bt;
408 }
409 }
410 }
411 }
413 static const prop_info *find_property(prop_bt *const trie, const char *name,
414 uint8_t namelen, const char *value, uint8_t valuelen,
415 bool alloc_if_needed)
416 {
417 if (!trie) return NULL;
419 const char *remaining_name = name;
420 prop_bt* current = trie;
421 while (true) {
422 const char *sep = strchr(remaining_name, '.');
423 const bool want_subtree = (sep != NULL);
424 const uint8_t substr_size = (want_subtree) ?
425 sep - remaining_name : strlen(remaining_name);
427 if (!substr_size) {
428 return NULL;
429 }
431 prop_bt* root = NULL;
432 if (current->children) {
433 root = reinterpret_cast<prop_bt*>(to_prop_obj(current->children));
434 } else if (alloc_if_needed) {
435 uint32_t new_bt_offset;
436 root = new_prop_bt(remaining_name, substr_size, &new_bt_offset);
437 if (root) {
438 current->children = new_bt_offset;
439 }
440 }
442 if (!root) {
443 return NULL;
444 }
446 current = find_prop_bt(root, remaining_name, substr_size, alloc_if_needed);
447 if (!current) {
448 return NULL;
449 }
451 if (!want_subtree)
452 break;
454 remaining_name = sep + 1;
455 }
457 if (current->prop) {
458 return reinterpret_cast<prop_info*>(to_prop_obj(current->prop));
459 } else if (alloc_if_needed) {
460 uint32_t new_info_offset;
461 prop_info* new_info = new_prop_info(name, namelen, value, valuelen, &new_info_offset);
462 if (new_info) {
463 current->prop = new_info_offset;
464 }
466 return new_info;
467 } else {
468 return NULL;
469 }
470 }
472 static int send_prop_msg(const prop_msg *msg)
473 {
474 const int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
475 if (fd == -1) {
476 return -1;
477 }
479 const size_t namelen = strlen(property_service_socket);
481 sockaddr_un addr;
482 memset(&addr, 0, sizeof(addr));
483 strlcpy(addr.sun_path, property_service_socket, sizeof(addr.sun_path));
484 addr.sun_family = AF_LOCAL;
485 socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
486 if (TEMP_FAILURE_RETRY(connect(fd, reinterpret_cast<sockaddr*>(&addr), alen)) < 0) {
487 close(fd);
488 return -1;
489 }
491 const int num_bytes = TEMP_FAILURE_RETRY(send(fd, msg, sizeof(prop_msg), 0));
493 int result = -1;
494 if (num_bytes == sizeof(prop_msg)) {
495 // We successfully wrote to the property server but now we
496 // wait for the property server to finish its work. It
497 // acknowledges its completion by closing the socket so we
498 // poll here (on nothing), waiting for the socket to close.
499 // If you 'adb shell setprop foo bar' you'll see the POLLHUP
500 // once the socket closes. Out of paranoia we cap our poll
501 // at 250 ms.
502 pollfd pollfds[1];
503 pollfds[0].fd = fd;
504 pollfds[0].events = 0;
505 const int poll_result = TEMP_FAILURE_RETRY(poll(pollfds, 1, 250 /* ms */));
506 if (poll_result == 1 && (pollfds[0].revents & POLLHUP) != 0) {
507 result = 0;
508 } else {
509 // Ignore the timeout and treat it like a success anyway.
510 // The init process is single-threaded and its property
511 // service is sometimes slow to respond (perhaps it's off
512 // starting a child process or something) and thus this
513 // times out and the caller thinks it failed, even though
514 // it's still getting around to it. So we fake it here,
515 // mostly for ctl.* properties, but we do try and wait 250
516 // ms so callers who do read-after-write can reliably see
517 // what they've written. Most of the time.
518 // TODO: fix the system properties design.
519 result = 0;
520 }
521 }
523 close(fd);
524 return result;
525 }
527 static void find_nth_fn(const prop_info *pi, void *ptr)
528 {
529 find_nth_cookie *cookie = reinterpret_cast<find_nth_cookie*>(ptr);
531 if (cookie->n == cookie->count)
532 cookie->pi = pi;
534 cookie->count++;
535 }
537 static int foreach_property(const uint32_t off,
538 void (*propfn)(const prop_info *pi, void *cookie), void *cookie)
539 {
540 prop_bt *trie = reinterpret_cast<prop_bt*>(to_prop_obj(off));
541 if (!trie)
542 return -1;
544 if (trie->left) {
545 const int err = foreach_property(trie->left, propfn, cookie);
546 if (err < 0)
547 return -1;
548 }
549 if (trie->prop) {
550 prop_info *info = reinterpret_cast<prop_info*>(to_prop_obj(trie->prop));
551 if (!info)
552 return -1;
553 propfn(info, cookie);
554 }
555 if (trie->children) {
556 const int err = foreach_property(trie->children, propfn, cookie);
557 if (err < 0)
558 return -1;
559 }
560 if (trie->right) {
561 const int err = foreach_property(trie->right, propfn, cookie);
562 if (err < 0)
563 return -1;
564 }
566 return 0;
567 }
569 int __system_properties_init()
570 {
571 return map_prop_area();
572 }
574 int __system_property_set_filename(const char *filename)
575 {
576 size_t len = strlen(filename);
577 if (len >= sizeof(property_filename))
578 return -1;
580 strcpy(property_filename, filename);
581 return 0;
582 }
584 int __system_property_area_init()
585 {
586 return map_prop_area_rw();
587 }
589 const prop_info *__system_property_find(const char *name)
590 {
591 if (__predict_false(compat_mode)) {
592 return __system_property_find_compat(name);
593 }
594 return find_property(root_node(), name, strlen(name), NULL, 0, false);
595 }
597 // The C11 standard doesn't allow atomic loads from const fields,
598 // though C++11 does. Fudge it until standards get straightened out.
599 static inline uint_least32_t load_const_atomic(const atomic_uint_least32_t* s,
600 memory_order mo) {
601 atomic_uint_least32_t* non_const_s = const_cast<atomic_uint_least32_t*>(s);
602 return atomic_load_explicit(non_const_s, mo);
603 }
605 int __system_property_read(const prop_info *pi, char *name, char *value)
606 {
607 if (__predict_false(compat_mode)) {
608 return __system_property_read_compat(pi, name, value);
609 }
611 while (true) {
612 uint32_t serial = __system_property_serial(pi); // acquire semantics
613 size_t len = SERIAL_VALUE_LEN(serial);
614 memcpy(value, pi->value, len + 1);
615 // TODO: Fix the synchronization scheme here.
616 // There is no fully supported way to implement this kind
617 // of synchronization in C++11, since the memcpy races with
618 // updates to pi, and the data being accessed is not atomic.
619 // The following fence is unintuitive, but would be the
620 // correct one if memcpy used memory_order_relaxed atomic accesses.
621 // In practice it seems unlikely that the generated code would
622 // would be any different, so this should be OK.
623 atomic_thread_fence(memory_order_acquire);
624 if (serial ==
625 load_const_atomic(&(pi->serial), memory_order_relaxed)) {
626 if (name != 0) {
627 strcpy(name, pi->name);
628 }
629 return len;
630 }
631 }
632 }
634 int __system_property_get(const char *name, char *value)
635 {
636 const prop_info *pi = __system_property_find(name);
638 if (pi != 0) {
639 return __system_property_read(pi, 0, value);
640 } else {
641 value[0] = 0;
642 return 0;
643 }
644 }
646 int __system_property_set(const char *key, const char *value)
647 {
648 if (key == 0) return -1;
649 if (value == 0) value = "";
650 if (strlen(key) >= PROP_NAME_MAX) return -1;
651 if (strlen(value) >= PROP_VALUE_MAX) return -1;
653 prop_msg msg;
654 memset(&msg, 0, sizeof msg);
655 msg.cmd = PROP_MSG_SETPROP;
656 strlcpy(msg.name, key, sizeof msg.name);
657 strlcpy(msg.value, value, sizeof msg.value);
659 const int err = send_prop_msg(&msg);
660 if (err < 0) {
661 return err;
662 }
664 return 0;
665 }
667 int __system_property_update(prop_info *pi, const char *value, unsigned int len)
668 {
669 prop_area *pa = __system_property_area__;
671 if (len >= PROP_VALUE_MAX)
672 return -1;
674 uint32_t serial = atomic_load_explicit(&pi->serial, memory_order_relaxed);
675 serial |= 1;
676 atomic_store_explicit(&pi->serial, serial, memory_order_relaxed);
677 // The memcpy call here also races. Again pretend it
678 // used memory_order_relaxed atomics, and use the analogous
679 // counterintuitive fence.
680 atomic_thread_fence(memory_order_release);
681 memcpy(pi->value, value, len + 1);
682 atomic_store_explicit(
683 &pi->serial,
684 (len << 24) | ((serial + 1) & 0xffffff),
685 memory_order_release);
686 __futex_wake(&pi->serial, INT32_MAX);
688 atomic_store_explicit(
689 &pa->serial,
690 atomic_load_explicit(&pa->serial, memory_order_relaxed) + 1,
691 memory_order_release);
692 __futex_wake(&pa->serial, INT32_MAX);
694 return 0;
695 }
697 int __system_property_add(const char *name, unsigned int namelen,
698 const char *value, unsigned int valuelen)
699 {
700 prop_area *pa = __system_property_area__;
701 const prop_info *pi;
703 if (namelen >= PROP_NAME_MAX)
704 return -1;
705 if (valuelen >= PROP_VALUE_MAX)
706 return -1;
707 if (namelen < 1)
708 return -1;
710 pi = find_property(root_node(), name, namelen, value, valuelen, true);
711 if (!pi)
712 return -1;
714 // There is only a single mutator, but we want to make sure that
715 // updates are visible to a reader waiting for the update.
716 atomic_store_explicit(
717 &pa->serial,
718 atomic_load_explicit(&pa->serial, memory_order_relaxed) + 1,
719 memory_order_release);
720 __futex_wake(&pa->serial, INT32_MAX);
721 return 0;
722 }
724 // Wait for non-locked serial, and retrieve it with acquire semantics.
725 unsigned int __system_property_serial(const prop_info *pi)
726 {
727 uint32_t serial = load_const_atomic(&pi->serial, memory_order_acquire);
728 while (SERIAL_DIRTY(serial)) {
729 __futex_wait(const_cast<volatile void *>(
730 reinterpret_cast<const void *>(&pi->serial)),
731 serial, NULL);
732 serial = load_const_atomic(&pi->serial, memory_order_acquire);
733 }
734 return serial;
735 }
737 unsigned int __system_property_wait_any(unsigned int serial)
738 {
739 prop_area *pa = __system_property_area__;
740 uint32_t my_serial;
742 do {
743 __futex_wait(&pa->serial, serial, NULL);
744 my_serial = atomic_load_explicit(&pa->serial, memory_order_acquire);
745 } while (my_serial == serial);
747 return my_serial;
748 }
750 const prop_info *__system_property_find_nth(unsigned n)
751 {
752 find_nth_cookie cookie(n);
754 const int err = __system_property_foreach(find_nth_fn, &cookie);
755 if (err < 0) {
756 return NULL;
757 }
759 return cookie.pi;
760 }
762 int __system_property_foreach(void (*propfn)(const prop_info *pi, void *cookie),
763 void *cookie)
764 {
765 if (__predict_false(compat_mode)) {
766 return __system_property_foreach_compat(propfn, cookie);
767 }
769 return foreach_property(0, propfn, cookie);
770 }