From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- .../android_system_properties/.cargo-checksum.json | 1 + vendor/android_system_properties/CONTRIBUTING.md | 40 ++++ vendor/android_system_properties/Cargo.lock | 16 ++ vendor/android_system_properties/Cargo.toml | 36 ++++ vendor/android_system_properties/LICENSE-APACHE | 13 ++ vendor/android_system_properties/LICENSE-MIT | 20 ++ vendor/android_system_properties/README.md | 36 ++++ .../examples/time_zone.rs | 9 + vendor/android_system_properties/src/lib.rs | 221 +++++++++++++++++++++ 9 files changed, 392 insertions(+) create mode 100644 vendor/android_system_properties/.cargo-checksum.json create mode 100644 vendor/android_system_properties/CONTRIBUTING.md create mode 100644 vendor/android_system_properties/Cargo.lock create mode 100644 vendor/android_system_properties/Cargo.toml create mode 100644 vendor/android_system_properties/LICENSE-APACHE create mode 100644 vendor/android_system_properties/LICENSE-MIT create mode 100644 vendor/android_system_properties/README.md create mode 100644 vendor/android_system_properties/examples/time_zone.rs create mode 100644 vendor/android_system_properties/src/lib.rs (limited to 'vendor/android_system_properties') diff --git a/vendor/android_system_properties/.cargo-checksum.json b/vendor/android_system_properties/.cargo-checksum.json new file mode 100644 index 000000000..1588ce5b5 --- /dev/null +++ b/vendor/android_system_properties/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"CONTRIBUTING.md":"0834cb3b5e092977688d73d219a05bed23ae0ecb54b6d6e5d866ce07f6583b5e","Cargo.lock":"37ffc00dbbbec58fd27b4f4cb597e5402d6cf615ce0458f62a73a7f0d987e5bd","Cargo.toml":"e9e8c037cdef7adc9794b17c13e5a014421524d67ea5048bc09cf70ef13c782c","LICENSE-APACHE":"216486f29671a4262efe32af6d84a75bef398127f8c5f369b5c8305983887a06","LICENSE-MIT":"80f275e90d799911ed3830a7f242a2ef5a4ade2092fe0aa07bfb2d2cf2f2b95e","README.md":"aba8ff5dbd0712326d97d32bc6a3b66b24d1980a446c238f7e14b96784766cd1","examples/time_zone.rs":"8edb32a946ef2680146ba9ac16c233dd94391ac9f98464e9fb6f87d3954b72a9","src/lib.rs":"0004133d6c3805bf449e7183d2931e9640167511bea6cd12b400805073c4305d"},"package":"819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"} \ No newline at end of file diff --git a/vendor/android_system_properties/CONTRIBUTING.md b/vendor/android_system_properties/CONTRIBUTING.md new file mode 100644 index 000000000..62436f59b --- /dev/null +++ b/vendor/android_system_properties/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Contributing + +Contributions are very much welcome. Here are the guidelines if you are thinking of helping us: + +## Contributions + +Contributions should be made in the form of GitHub pull requests. +Each pull request will be reviewed by a core contributor (someone with +permission to land patches) and either landed in the main tree or +given feedback for changes that would be required. + +Should you wish to work on an issue, please claim it first by commenting on +the GitHub issue that you want to work on it. This is to prevent duplicated +efforts from contributors on the same issue. + +## Pull Request Checklist + +- Branch from the master branch and, if needed, rebase to the current master + branch before submitting your pull request. If it doesn't merge cleanly with + master you may be asked to rebase your changes. + +- Commits should be as small as possible, while ensuring that each commit is + correct independently (i.e., each commit should compile and pass tests). + +- If your patch is not getting reviewed or you need a specific person to review + it, you can @-reply a reviewer asking for a review in the pull request or a + comment. + +- Whenever applicable, add tests relevant to the fixed bug or new feature. + +For specific git instructions, see [GitHub workflow 101](https://github.com/servo/servo/wiki/Github-workflow). + +## Conduct + +We follow the [Rust Code of Conduct](http://www.rust-lang.org/conduct.html). +For escalation or moderation issues, please contact Nical (nical@fastmail.com) instead of the Rust moderation team. + +## License + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed dual MIT/Apache 2, without any additional terms or conditions. diff --git a/vendor/android_system_properties/Cargo.lock b/vendor/android_system_properties/Cargo.lock new file mode 100644 index 000000000..9ee6e3d29 --- /dev/null +++ b/vendor/android_system_properties/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "android_system_properties" +version = "0.1.5" +dependencies = [ + "libc", +] + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" diff --git a/vendor/android_system_properties/Cargo.toml b/vendor/android_system_properties/Cargo.toml new file mode 100644 index 000000000..79e4ea0d2 --- /dev/null +++ b/vendor/android_system_properties/Cargo.toml @@ -0,0 +1,36 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2018" +name = "android_system_properties" +version = "0.1.5" +authors = ["Nicolas Silva "] +description = "Minimal Android system properties wrapper" +homepage = "https://github.com/nical/android_system_properties" +documentation = "https://docs.rs/android_system_properties" +readme = "README.md" +keywords = ["android"] +license = "MIT/Apache-2.0" +repository = "https://github.com/nical/android_system_properties" + +[package.metadata.docs.rs] +targets = [ + "arm-linux-androideabi", + "armv7-linux-androideabi", + "aarch64-linux-android", + "i686-linux-android", + "x86_64-linux-android", + "x86_64-unknown-linux-gnu", +] + +[dependencies.libc] +version = "0.2.126" diff --git a/vendor/android_system_properties/LICENSE-APACHE b/vendor/android_system_properties/LICENSE-APACHE new file mode 100644 index 000000000..47f4fd0e8 --- /dev/null +++ b/vendor/android_system_properties/LICENSE-APACHE @@ -0,0 +1,13 @@ +Copyright 2016 Nicolas Silva + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/vendor/android_system_properties/LICENSE-MIT b/vendor/android_system_properties/LICENSE-MIT new file mode 100644 index 000000000..e6d4b1799 --- /dev/null +++ b/vendor/android_system_properties/LICENSE-MIT @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Nicolas Silva + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/android_system_properties/README.md b/vendor/android_system_properties/README.md new file mode 100644 index 000000000..46f6500b5 --- /dev/null +++ b/vendor/android_system_properties/README.md @@ -0,0 +1,36 @@ +# android_system_properties + +A thin rust wrapper for Android system properties. + +This crate is similar to the `android-properties` crate with the exception that +the necessary Android libc symbols are loaded dynamically instead of linked +statically. In practice this means that the same binary will work with old and +new versions of Android, even though the API for reading system properties changed +around Android L. + +## Example + +```rust +use android_system_properties::AndroidSystemProperties; + +let properties = AndroidSystemProperties::new(); + +if let Some(value) = properties.get("persist.sys.timezone") { + println!("{}", value); +} +``` + +## Listing and setting properties + +For the sake of simplicity this crate currently only contains what's needed by wgpu. +The implementations for listing and setting properties can be added back if anyone needs +them (let me know by filing an issue). + +## License + +Licensed under either of + + * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. diff --git a/vendor/android_system_properties/examples/time_zone.rs b/vendor/android_system_properties/examples/time_zone.rs new file mode 100644 index 000000000..f3a6a3c7b --- /dev/null +++ b/vendor/android_system_properties/examples/time_zone.rs @@ -0,0 +1,9 @@ +/// Prints the current time zone, e.g. "Europe/Paris". + +use android_system_properties::AndroidSystemProperties; + +fn main() { + let android_system_properties = AndroidSystemProperties::new(); + let tz = android_system_properties.get("persist.sys.timezone"); + println!("Your time zone is: {}", tz.as_deref().unwrap_or("")); +} diff --git a/vendor/android_system_properties/src/lib.rs b/vendor/android_system_properties/src/lib.rs new file mode 100644 index 000000000..9cd9d4916 --- /dev/null +++ b/vendor/android_system_properties/src/lib.rs @@ -0,0 +1,221 @@ +//! A thin rust wrapper for Android system properties. +//! +//! This crate is similar to the `android-properties` crate with the exception that +//! the necessary Android libc symbols are loaded dynamically instead of linked +//! statically. In practice this means that the same binary will work with old and +//! new versions of Android, even though the API for reading system properties changed +//! around Android L. +//! +//! ## Example +//! +//! ```rust +//! use android_system_properties::AndroidSystemProperties; +//! +//! let properties = AndroidSystemProperties::new(); +//! +//! if let Some(value) = properties.get("persist.sys.timezone") { +//! println!("{}", value); +//! } +//! ``` +//! +//! ## Listing and setting properties +//! +//! For the sake of simplicity this crate currently only contains what's needed by wgpu. +//! The implementations for listing and setting properties can be added back if anyone needs +//! them (let me know by filing an issue). +//! +//! ## License +//! +//! Licensed under either of +//! +//! * Apache License, Version 2.0 ([LICENSE-APACHE] or ) +//! * MIT license ([LICENSE-MIT] or ) +//! +//! at your option. +//! +//! [LICENSE-APACHE]: https://github.com/nical/android_system_properties/blob/804681c5c1c93d4fab29c1a2f47b7d808dc70fd3/LICENSE-APACHE +//! [LICENSE-MIT]: https://github.com/nical/android_system_properties/blob/804681c5c1c93d4fab29c1a2f47b7d808dc70fd3/LICENSE-MIT + +use std::{ + ffi::{CStr, CString}, + os::raw::{c_char, c_int, c_void}, +}; + +#[cfg(target_os = "android")] +use std::mem; + +unsafe fn property_callback(payload: *mut String, _name: *const c_char, value: *const c_char, _serial: u32) { + let cvalue = CStr::from_ptr(value); + (*payload) = cvalue.to_str().unwrap().to_string(); +} + +type Callback = unsafe fn(*mut String, *const c_char, *const c_char, u32); + +type SystemPropertyGetFn = unsafe extern "C" fn(*const c_char, *mut c_char) -> c_int; +type SystemPropertyFindFn = unsafe extern "C" fn(*const c_char) -> *const c_void; +type SystemPropertyReadCallbackFn = unsafe extern "C" fn(*const c_void, Callback, *mut String) -> *const c_void; + +#[derive(Debug)] +/// An object that can retrieve android system properties. +/// +/// ## Example +/// +/// ``` +/// use android_system_properties::AndroidSystemProperties; +/// +/// let properties = AndroidSystemProperties::new(); +/// +/// if let Some(value) = properties.get("persist.sys.timezone") { +/// println!("{}", value); +/// } +/// ``` +pub struct AndroidSystemProperties { + libc_so: *mut c_void, + get_fn: Option, + find_fn: Option, + read_callback_fn: Option, +} + +unsafe impl Send for AndroidSystemProperties {} +unsafe impl Sync for AndroidSystemProperties {} + +impl AndroidSystemProperties { + #[cfg(not(target_os = "android"))] + /// Create an entry point for accessing Android properties. + pub fn new() -> Self { + AndroidSystemProperties { + libc_so: std::ptr::null_mut(), + find_fn: None, + read_callback_fn: None, + get_fn: None, + } + } + + #[cfg(target_os = "android")] + /// Create an entry point for accessing Android properties. + pub fn new() -> Self { + let libc_so = unsafe { libc::dlopen(b"libc.so\0".as_ptr().cast(), libc::RTLD_NOLOAD) }; + + let mut properties = AndroidSystemProperties { + libc_so, + find_fn: None, + read_callback_fn: None, + get_fn: None, + }; + + if libc_so.is_null() { + return properties; + } + + + unsafe fn load_fn(libc_so: *mut c_void, name: &[u8]) -> Option<*const c_void> { + let fn_ptr = libc::dlsym(libc_so, name.as_ptr().cast()); + + if fn_ptr.is_null() { + return None; + } + + Some(fn_ptr) + } + + unsafe { + properties.read_callback_fn = load_fn(libc_so, b"__system_property_read_callback\0") + .map(|raw| mem::transmute::<*const c_void, SystemPropertyReadCallbackFn>(raw)); + + properties.find_fn = load_fn(libc_so, b"__system_property_find\0") + .map(|raw| mem::transmute::<*const c_void, SystemPropertyFindFn>(raw)); + + // Fallback for old versions of Android. + if properties.read_callback_fn.is_none() || properties.find_fn.is_none() { + properties.get_fn = load_fn(libc_so, b"__system_property_get\0") + .map(|raw| mem::transmute::<*const c_void, SystemPropertyGetFn>(raw)); + } + } + + properties + } + + /// Retrieve a system property. + /// + /// Returns None if the operation fails. + /// + /// # Example + /// + /// ``` + /// # use android_system_properties::AndroidSystemProperties; + /// let properties = AndroidSystemProperties::new(); + /// + /// if let Some(value) = properties.get("persist.sys.timezone") { + /// println!("{}", value); + /// } + /// ``` + pub fn get(&self, name: &str) -> Option { + let cname = CString::new(name).ok()?; + self.get_from_cstr(&cname) + } + + /// Retrieve a system property using a [`CStr`] key. + /// + /// Returns None if the operation fails. + /// + /// # Example + /// + /// ``` + /// # use android_system_properties::AndroidSystemProperties; + /// # use std::ffi::CStr; + /// let properties = AndroidSystemProperties::new(); + /// + /// let key = unsafe { CStr::from_bytes_with_nul_unchecked(b"persist.sys.timezone\0") }; + /// if let Some(value) = properties.get_from_cstr(key) { + /// println!("{}", value); + /// } + /// ``` + pub fn get_from_cstr(&self, cname: &std::ffi::CStr) -> Option { + // If available, use the recommended approach to accessing properties (Android L and onward). + if let (Some(find_fn), Some(read_callback_fn)) = (self.find_fn, self.read_callback_fn) { + let info = unsafe { (find_fn)(cname.as_ptr()) }; + + if info.is_null() { + return None; + } + + let mut result = String::new(); + + unsafe { + (read_callback_fn)(info, property_callback, &mut result); + } + + return Some(result); + } + + // Fall back to the older approach. + if let Some(get_fn) = self.get_fn { + // The constant is PROP_VALUE_MAX in Android's libc/include/sys/system_properties.h + const PROPERTY_VALUE_MAX: usize = 92; + let mut buffer: Vec = Vec::with_capacity(PROPERTY_VALUE_MAX); + let raw = buffer.as_mut_ptr() as *mut c_char; + + let len = unsafe { (get_fn)(cname.as_ptr(), raw) }; + + if len > 0 { + assert!(len as usize <= buffer.capacity()); + unsafe { buffer.set_len(len as usize); } + String::from_utf8(buffer).ok() + } else { + None + } + } else { + None + } + } +} + +impl Drop for AndroidSystemProperties { + fn drop(&mut self) { + if !self.libc_so.is_null() { + unsafe { + libc::dlclose(self.libc_so); + } + } + } +} -- cgit v1.2.3