blob: ec3d04bf77d8c3dd58146a967def51240b58a0f9 [file] [log] [blame]
Narayan Kamathc9ae21a2014-02-19 17:59:05 +00001/*
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 <stdio.h>
30#include <stdint.h>
31#include <stdlib.h>
32#include <unistd.h>
33#include <stddef.h>
34#include <errno.h>
35#include <poll.h>
36#include <fcntl.h>
37#include <stdbool.h>
38#include <string.h>
39
40#include <sys/mman.h>
41
42#include <sys/socket.h>
43#include <sys/un.h>
44#include <sys/select.h>
45#include <sys/stat.h>
46#include <sys/types.h>
47#include <netinet/in.h>
48#include <unistd.h>
49
50#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
51#include <sys/_system_properties.h>
52#include <sys/system_properties.h>
53
54#include <sys/atomics.h>
55
56#include "private/bionic_atomic_inline.h"
Elliott Hughes8eac9af2014-05-09 19:12:08 -070057#include "private/bionic_macros.h"
Narayan Kamathc9ae21a2014-02-19 17:59:05 +000058
59#define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
60
61
62static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME;
63
64
65/*
66 * Properties are stored in a hybrid trie/binary tree structure.
67 * Each property's name is delimited at '.' characters, and the tokens are put
68 * into a trie structure. Siblings at each level of the trie are stored in a
69 * binary tree. For instance, "ro.secure"="1" could be stored as follows:
70 *
71 * +-----+ children +----+ children +--------+
72 * | |-------------->| ro |-------------->| secure |
73 * +-----+ +----+ +--------+
74 * / \ / |
75 * left / \ right left / | prop +===========+
76 * v v v +-------->| ro.secure |
77 * +-----+ +-----+ +-----+ +-----------+
78 * | net | | sys | | com | | 1 |
79 * +-----+ +-----+ +-----+ +===========+
80 */
81
82// Represents a node in the trie.
83struct prop_bt {
84 uint8_t namelen;
85 uint8_t reserved[3];
86
87 volatile uint32_t prop;
88
89 volatile uint32_t left;
90 volatile uint32_t right;
91
92 volatile uint32_t children;
93
94 char name[0];
95
96 prop_bt(const char *name, const uint8_t name_length) {
97 this->namelen = name_length;
98 memcpy(this->name, name, name_length);
99 this->name[name_length] = '\0';
100 ANDROID_MEMBAR_FULL();
101 }
102
103private:
Elliott Hughes8eac9af2014-05-09 19:12:08 -0700104 DISALLOW_COPY_AND_ASSIGN(prop_bt);
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000105};
106
107struct prop_area {
108 uint32_t bytes_used;
109 volatile uint32_t serial;
110 uint32_t magic;
111 uint32_t version;
112 uint32_t reserved[28];
113 char data[0];
114
115 prop_area(const uint32_t magic, const uint32_t version) :
116 serial(0), magic(magic), version(version) {
117 memset(reserved, 0, sizeof(reserved));
118 // Allocate enough space for the root node.
119 bytes_used = sizeof(prop_bt);
120 }
121
122private:
Elliott Hughes8eac9af2014-05-09 19:12:08 -0700123 DISALLOW_COPY_AND_ASSIGN(prop_area);
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000124};
125
126struct prop_info {
127 volatile uint32_t serial;
128 char value[PROP_VALUE_MAX];
129 char name[0];
130
131 prop_info(const char *name, const uint8_t namelen, const char *value,
132 const uint8_t valuelen) {
133 memcpy(this->name, name, namelen);
134 this->name[namelen] = '\0';
135 this->serial = (valuelen << 24);
136 memcpy(this->value, value, valuelen);
137 this->value[valuelen] = '\0';
138 ANDROID_MEMBAR_FULL();
139 }
140private:
Elliott Hughes8eac9af2014-05-09 19:12:08 -0700141 DISALLOW_COPY_AND_ASSIGN(prop_info);
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000142};
143
144struct find_nth_cookie {
145 uint32_t count;
146 const uint32_t n;
147 const prop_info *pi;
148
149 find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
150 }
151};
152
153static char property_filename[PATH_MAX] = PROP_FILENAME;
154static bool compat_mode = false;
155static size_t pa_data_size;
156static size_t pa_size;
157
158// NOTE: This isn't static because system_properties_compat.c
159// requires it.
160prop_area *__system_property_area__ = NULL;
161
162static int get_fd_from_env(void)
163{
164 // This environment variable consistes of two decimal integer
165 // values separated by a ",". The first value is a file descriptor
166 // and the second is the size of the system properties area. The
167 // size is currently unused.
168 char *env = getenv("ANDROID_PROPERTY_WORKSPACE");
169
170 if (!env) {
171 return -1;
172 }
173
174 return atoi(env);
175}
176
177static int map_prop_area_rw()
178{
179 /* dev is a tmpfs that we can use to carve a shared workspace
180 * out of, so let's do that...
181 */
182 const int fd = open(property_filename,
183 O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC | O_EXCL, 0444);
184
185 if (fd < 0) {
186 if (errno == EACCES) {
187 /* for consistency with the case where the process has already
188 * mapped the page in and segfaults when trying to write to it
189 */
190 abort();
191 }
192 return -1;
193 }
194
195 // TODO: Is this really required ? Does android run on any kernels that
196 // don't support O_CLOEXEC ?
197 const int ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
198 if (ret < 0) {
199 close(fd);
200 return -1;
201 }
202
203 if (ftruncate(fd, PA_SIZE) < 0) {
204 close(fd);
205 return -1;
206 }
207
208 pa_size = PA_SIZE;
209 pa_data_size = pa_size - sizeof(prop_area);
210 compat_mode = false;
211
212 void *const memory_area = mmap(NULL, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
213 if (memory_area == MAP_FAILED) {
214 close(fd);
215 return -1;
216 }
217
218 prop_area *pa = new(memory_area) prop_area(PROP_AREA_MAGIC, PROP_AREA_VERSION);
219
220 /* plug into the lib property services */
221 __system_property_area__ = pa;
222
223 close(fd);
224 return 0;
225}
226
227static int map_fd_ro(const int fd) {
228 struct stat fd_stat;
229 if (fstat(fd, &fd_stat) < 0) {
230 return -1;
231 }
232
233 if ((fd_stat.st_uid != 0)
234 || (fd_stat.st_gid != 0)
235 || ((fd_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0)
Narayan Kamath37e95702014-02-24 11:05:02 +0000236 || (fd_stat.st_size < static_cast<off_t>(sizeof(prop_area))) ) {
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000237 return -1;
238 }
239
240 pa_size = fd_stat.st_size;
241 pa_data_size = pa_size - sizeof(prop_area);
242
243 void* const map_result = mmap(NULL, pa_size, PROT_READ, MAP_SHARED, fd, 0);
244 if (map_result == MAP_FAILED) {
245 return -1;
246 }
247
248 prop_area* pa = reinterpret_cast<prop_area*>(map_result);
249 if ((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION &&
250 pa->version != PROP_AREA_VERSION_COMPAT)) {
251 munmap(pa, pa_size);
252 return -1;
253 }
254
255 if (pa->version == PROP_AREA_VERSION_COMPAT) {
256 compat_mode = true;
257 }
258
259 __system_property_area__ = pa;
260 return 0;
261}
262
263static int map_prop_area()
264{
265 int fd(open(property_filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC));
266 if (fd >= 0) {
267 /* For old kernels that don't support O_CLOEXEC */
268 const int ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
269 if (ret < 0) {
270 close(fd);
271 return -1;
272 }
273 }
274
275 bool close_fd = true;
276 if ((fd < 0) && (errno == ENOENT)) {
277 /*
278 * For backwards compatibility, if the file doesn't
279 * exist, we use the environment to get the file descriptor.
280 * For security reasons, we only use this backup if the kernel
281 * returns ENOENT. We don't want to use the backup if the kernel
282 * returns other errors such as ENOMEM or ENFILE, since it
283 * might be possible for an external program to trigger this
284 * condition.
285 */
286 fd = get_fd_from_env();
287 close_fd = false;
288 }
289
290 if (fd < 0) {
291 return -1;
292 }
293
294 const int map_result = map_fd_ro(fd);
295 if (close_fd) {
296 close(fd);
297 }
298
299 return map_result;
300}
301
302static void *allocate_obj(const size_t size, uint32_t *const off)
303{
304 prop_area *pa = __system_property_area__;
305 const size_t aligned = ALIGN(size, sizeof(uint32_t));
306 if (pa->bytes_used + aligned > pa_data_size) {
307 return NULL;
308 }
309
310 *off = pa->bytes_used;
311 pa->bytes_used += aligned;
312 return pa->data + *off;
313}
314
315static prop_bt *new_prop_bt(const char *name, uint8_t namelen, uint32_t *const off)
316{
317 uint32_t new_offset;
318 void *const offset = allocate_obj(sizeof(prop_bt) + namelen + 1, &new_offset);
319 if (offset) {
320 prop_bt* bt = new(offset) prop_bt(name, namelen);
321 *off = new_offset;
322 return bt;
323 }
324
325 return NULL;
326}
327
328static prop_info *new_prop_info(const char *name, uint8_t namelen,
329 const char *value, uint8_t valuelen, uint32_t *const off)
330{
331 uint32_t off_tmp;
332 void* const offset = allocate_obj(sizeof(prop_info) + namelen + 1, &off_tmp);
333 if (offset) {
334 prop_info* info = new(offset) prop_info(name, namelen, value, valuelen);
335 *off = off_tmp;
336 return info;
337 }
338
339 return NULL;
340}
341
342static void *to_prop_obj(const uint32_t off)
343{
344 if (off > pa_data_size)
345 return NULL;
346 if (!__system_property_area__)
347 return NULL;
348
349 return (__system_property_area__->data + off);
350}
351
352static prop_bt *root_node()
353{
354 return reinterpret_cast<prop_bt*>(to_prop_obj(0));
355}
356
357static int cmp_prop_name(const char *one, uint8_t one_len, const char *two,
358 uint8_t two_len)
359{
360 if (one_len < two_len)
361 return -1;
362 else if (one_len > two_len)
363 return 1;
364 else
365 return strncmp(one, two, one_len);
366}
367
368static prop_bt *find_prop_bt(prop_bt *const bt, const char *name,
369 uint8_t namelen, bool alloc_if_needed)
370{
371
372 prop_bt* current = bt;
373 while (true) {
374 if (!current) {
375 return NULL;
376 }
377
378 const int ret = cmp_prop_name(name, namelen, current->name, current->namelen);
379 if (ret == 0) {
380 return current;
381 }
382
383 if (ret < 0) {
384 if (current->left) {
385 current = reinterpret_cast<prop_bt*>(to_prop_obj(current->left));
386 } else {
387 if (!alloc_if_needed) {
388 return NULL;
389 }
390
391 // Note that there isn't a race condition here. "clients" never
392 // reach this code-path since It's only the (single threaded) server
393 // that allocates new nodes. Though "bt->left" is volatile, it can't
394 // have changed since the last value was last read.
395 uint32_t new_offset = 0;
396 prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
397 if (new_bt) {
398 current->left = new_offset;
399 }
400 return new_bt;
401 }
402 } else {
403 if (current->right) {
404 current = reinterpret_cast<prop_bt*>(to_prop_obj(current->right));
405 } else {
406 if (!alloc_if_needed) {
407 return NULL;
408 }
409
410 uint32_t new_offset;
411 prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
412 if (new_bt) {
413 current->right = new_offset;
414 }
415 return new_bt;
416 }
417 }
418 }
419}
420
421static const prop_info *find_property(prop_bt *const trie, const char *name,
422 uint8_t namelen, const char *value, uint8_t valuelen,
423 bool alloc_if_needed)
424{
425 if (!trie) return NULL;
426
427 const char *remaining_name = name;
428 prop_bt* current = trie;
429 while (true) {
430 const char *sep = strchr(remaining_name, '.');
431 const bool want_subtree = (sep != NULL);
432 const uint8_t substr_size = (want_subtree) ?
433 sep - remaining_name : strlen(remaining_name);
434
435 if (!substr_size) {
436 return NULL;
437 }
438
439 prop_bt* root = NULL;
440 if (current->children) {
441 root = reinterpret_cast<prop_bt*>(to_prop_obj(current->children));
442 } else if (alloc_if_needed) {
443 uint32_t new_bt_offset;
444 root = new_prop_bt(remaining_name, substr_size, &new_bt_offset);
445 if (root) {
446 current->children = new_bt_offset;
447 }
448 }
449
450 if (!root) {
451 return NULL;
452 }
453
454 current = find_prop_bt(root, remaining_name, substr_size, alloc_if_needed);
455 if (!current) {
456 return NULL;
457 }
458
459 if (!want_subtree)
460 break;
461
462 remaining_name = sep + 1;
463 }
464
465 if (current->prop) {
466 return reinterpret_cast<prop_info*>(to_prop_obj(current->prop));
467 } else if (alloc_if_needed) {
468 uint32_t new_info_offset;
469 prop_info* new_info = new_prop_info(name, namelen, value, valuelen, &new_info_offset);
470 if (new_info) {
471 current->prop = new_info_offset;
472 }
473
474 return new_info;
475 } else {
476 return NULL;
477 }
478}
479
480static int send_prop_msg(const prop_msg *msg)
481{
482 const int fd = socket(AF_LOCAL, SOCK_STREAM, 0);
483 if (fd < 0) {
484 return -1;
485 }
486
487 const size_t namelen = strlen(property_service_socket);
488
489 sockaddr_un addr;
490 memset(&addr, 0, sizeof(addr));
491 strlcpy(addr.sun_path, property_service_socket, sizeof(addr.sun_path));
492 addr.sun_family = AF_LOCAL;
493 socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
494 if (TEMP_FAILURE_RETRY(connect(fd, reinterpret_cast<sockaddr*>(&addr), alen)) < 0) {
495 close(fd);
496 return -1;
497 }
498
499 const int num_bytes = TEMP_FAILURE_RETRY(send(fd, msg, sizeof(prop_msg), 0));
500
501 int result = -1;
502 if (num_bytes == sizeof(prop_msg)) {
503 // We successfully wrote to the property server but now we
504 // wait for the property server to finish its work. It
505 // acknowledges its completion by closing the socket so we
506 // poll here (on nothing), waiting for the socket to close.
507 // If you 'adb shell setprop foo bar' you'll see the POLLHUP
508 // once the socket closes. Out of paranoia we cap our poll
509 // at 250 ms.
510 pollfd pollfds[1];
511 pollfds[0].fd = fd;
512 pollfds[0].events = 0;
513 const int poll_result = TEMP_FAILURE_RETRY(poll(pollfds, 1, 250 /* ms */));
514 if (poll_result == 1 && (pollfds[0].revents & POLLHUP) != 0) {
515 result = 0;
516 } else {
517 // Ignore the timeout and treat it like a success anyway.
518 // The init process is single-threaded and its property
519 // service is sometimes slow to respond (perhaps it's off
520 // starting a child process or something) and thus this
521 // times out and the caller thinks it failed, even though
522 // it's still getting around to it. So we fake it here,
523 // mostly for ctl.* properties, but we do try and wait 250
524 // ms so callers who do read-after-write can reliably see
525 // what they've written. Most of the time.
526 // TODO: fix the system properties design.
527 result = 0;
528 }
529 }
530
531 close(fd);
532 return result;
533}
534
535static void find_nth_fn(const prop_info *pi, void *ptr)
536{
537 find_nth_cookie *cookie = reinterpret_cast<find_nth_cookie*>(ptr);
538
539 if (cookie->n == cookie->count)
540 cookie->pi = pi;
541
542 cookie->count++;
543}
544
545static int foreach_property(const uint32_t off,
546 void (*propfn)(const prop_info *pi, void *cookie), void *cookie)
547{
548 prop_bt *trie = reinterpret_cast<prop_bt*>(to_prop_obj(off));
549 if (!trie)
550 return -1;
551
552 if (trie->left) {
553 const int err = foreach_property(trie->left, propfn, cookie);
554 if (err < 0)
555 return -1;
556 }
557 if (trie->prop) {
558 prop_info *info = reinterpret_cast<prop_info*>(to_prop_obj(trie->prop));
559 if (!info)
560 return -1;
561 propfn(info, cookie);
562 }
563 if (trie->children) {
564 const int err = foreach_property(trie->children, propfn, cookie);
565 if (err < 0)
566 return -1;
567 }
568 if (trie->right) {
569 const int err = foreach_property(trie->right, propfn, cookie);
570 if (err < 0)
571 return -1;
572 }
573
574 return 0;
575}
576
577int __system_properties_init()
578{
579 return map_prop_area();
580}
581
582int __system_property_set_filename(const char *filename)
583{
584 size_t len = strlen(filename);
585 if (len >= sizeof(property_filename))
586 return -1;
587
588 strcpy(property_filename, filename);
589 return 0;
590}
591
592int __system_property_area_init()
593{
594 return map_prop_area_rw();
595}
596
597const prop_info *__system_property_find(const char *name)
598{
599 if (__predict_false(compat_mode)) {
600 return __system_property_find_compat(name);
601 }
602 return find_property(root_node(), name, strlen(name), NULL, 0, false);
603}
604
605int __system_property_read(const prop_info *pi, char *name, char *value)
606{
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000607 if (__predict_false(compat_mode)) {
608 return __system_property_read_compat(pi, name, value);
609 }
610
jiaguo879d3302014-03-13 17:39:58 +0800611 while (true) {
612 uint32_t serial = __system_property_serial(pi);
613 size_t len = SERIAL_VALUE_LEN(serial);
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000614 memcpy(value, pi->value, len + 1);
615 ANDROID_MEMBAR_FULL();
jiaguo879d3302014-03-13 17:39:58 +0800616 if (serial == pi->serial) {
617 if (name != 0) {
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000618 strcpy(name, pi->name);
619 }
620 return len;
621 }
622 }
623}
624
625int __system_property_get(const char *name, char *value)
626{
627 const prop_info *pi = __system_property_find(name);
628
629 if (pi != 0) {
630 return __system_property_read(pi, 0, value);
631 } else {
632 value[0] = 0;
633 return 0;
634 }
635}
636
637int __system_property_set(const char *key, const char *value)
638{
639 if (key == 0) return -1;
640 if (value == 0) value = "";
641 if (strlen(key) >= PROP_NAME_MAX) return -1;
642 if (strlen(value) >= PROP_VALUE_MAX) return -1;
643
644 prop_msg msg;
645 memset(&msg, 0, sizeof msg);
646 msg.cmd = PROP_MSG_SETPROP;
647 strlcpy(msg.name, key, sizeof msg.name);
648 strlcpy(msg.value, value, sizeof msg.value);
649
650 const int err = send_prop_msg(&msg);
651 if (err < 0) {
652 return err;
653 }
654
655 return 0;
656}
657
658int __system_property_wait(const prop_info *pi)
659{
660 if (pi == 0) {
661 prop_area *pa = __system_property_area__;
662 const uint32_t n = pa->serial;
663 do {
664 __futex_wait(&pa->serial, n, NULL);
665 } while (n == pa->serial);
666 } else {
667 const uint32_t n = pi->serial;
668 do {
669 __futex_wait((volatile void *)&pi->serial, n, NULL);
jiaguo879d3302014-03-13 17:39:58 +0800670 } while (n == pi->serial);
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000671 }
672 return 0;
673}
674
675int __system_property_update(prop_info *pi, const char *value, unsigned int len)
676{
677 prop_area *pa = __system_property_area__;
678
679 if (len >= PROP_VALUE_MAX)
680 return -1;
681
682 pi->serial = pi->serial | 1;
683 ANDROID_MEMBAR_FULL();
684 memcpy(pi->value, value, len + 1);
685 ANDROID_MEMBAR_FULL();
686 pi->serial = (len << 24) | ((pi->serial + 1) & 0xffffff);
687 __futex_wake(&pi->serial, INT32_MAX);
688
689 pa->serial++;
690 __futex_wake(&pa->serial, INT32_MAX);
691
692 return 0;
693}
jiaguo879d3302014-03-13 17:39:58 +0800694
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000695int __system_property_add(const char *name, unsigned int namelen,
696 const char *value, unsigned int valuelen)
697{
698 prop_area *pa = __system_property_area__;
699 const prop_info *pi;
700
701 if (namelen >= PROP_NAME_MAX)
702 return -1;
703 if (valuelen >= PROP_VALUE_MAX)
704 return -1;
705 if (namelen < 1)
706 return -1;
707
708 pi = find_property(root_node(), name, namelen, value, valuelen, true);
709 if (!pi)
710 return -1;
711
712 pa->serial++;
713 __futex_wake(&pa->serial, INT32_MAX);
714 return 0;
715}
716
717unsigned int __system_property_serial(const prop_info *pi)
718{
jiaguo879d3302014-03-13 17:39:58 +0800719 uint32_t serial = pi->serial;
720 while (SERIAL_DIRTY(serial)) {
721 __futex_wait(const_cast<volatile uint32_t*>(&pi->serial), serial, NULL);
722 serial = pi->serial;
723 }
724 return serial;
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000725}
726
727unsigned int __system_property_wait_any(unsigned int serial)
728{
729 prop_area *pa = __system_property_area__;
730
731 do {
732 __futex_wait(&pa->serial, serial, NULL);
jiaguo879d3302014-03-13 17:39:58 +0800733 } while (pa->serial == serial);
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000734
735 return pa->serial;
736}
737
738const prop_info *__system_property_find_nth(unsigned n)
739{
740 find_nth_cookie cookie(n);
741
742 const int err = __system_property_foreach(find_nth_fn, &cookie);
743 if (err < 0) {
744 return NULL;
745 }
746
747 return cookie.pi;
748}
749
750int __system_property_foreach(void (*propfn)(const prop_info *pi, void *cookie),
751 void *cookie)
752{
753 if (__predict_false(compat_mode)) {
754 return __system_property_foreach_compat(propfn, cookie);
755 }
756
757 return foreach_property(0, propfn, cookie);
758}