| Tom Cherry | fd44b9f | 2017-11-08 14:01:00 -0800 | [diff] [blame] | 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 |  | 
| Tom Cherry | e275d6d | 2017-12-11 23:31:33 -0800 | [diff] [blame] | 29 | #include "system_properties/prop_info.h" | 
| Tom Cherry | fd44b9f | 2017-11-08 14:01:00 -0800 | [diff] [blame] | 30 |  | 
|  | 31 | #include <string.h> | 
|  | 32 |  | 
| Elliott Hughes | 3008884 | 2023-09-14 18:35:11 +0000 | [diff] [blame] | 33 | static constexpr const char kLongLegacyError[] = | 
| Tom Cherry | fd44b9f | 2017-11-08 14:01:00 -0800 | [diff] [blame] | 34 | "Must use __system_property_read_callback() to read"; | 
|  | 35 | static_assert(sizeof(kLongLegacyError) < prop_info::kLongLegacyErrorBufferSize, | 
|  | 36 | "Error message for long properties read by legacy libc must fit within 56 chars"); | 
|  | 37 |  | 
|  | 38 | prop_info::prop_info(const char* name, uint32_t namelen, const char* value, uint32_t valuelen) { | 
|  | 39 | memcpy(this->name, name, namelen); | 
|  | 40 | this->name[namelen] = '\0'; | 
|  | 41 | atomic_init(&this->serial, valuelen << 24); | 
|  | 42 | memcpy(this->value, value, valuelen); | 
|  | 43 | this->value[valuelen] = '\0'; | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | prop_info::prop_info(const char* name, uint32_t namelen, uint32_t long_offset) { | 
|  | 47 | memcpy(this->name, name, namelen); | 
|  | 48 | this->name[namelen] = '\0'; | 
|  | 49 |  | 
|  | 50 | auto error_value_len = sizeof(kLongLegacyError) - 1; | 
|  | 51 | atomic_init(&this->serial, error_value_len << 24 | kLongFlag); | 
|  | 52 | memcpy(this->long_property.error_message, kLongLegacyError, sizeof(kLongLegacyError)); | 
|  | 53 |  | 
|  | 54 | this->long_property.offset = long_offset; | 
|  | 55 | } |