Merge "Adding parsing for fastboot-info"
diff --git a/debuggerd/crasher/crasher.cpp b/debuggerd/crasher/crasher.cpp
index 6a19878..12ba502 100644
--- a/debuggerd/crasher/crasher.cpp
+++ b/debuggerd/crasher/crasher.cpp
@@ -148,7 +148,7 @@
noinline void leak() {
while (true) {
void* mapping =
- mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ mmap(nullptr, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
static_cast<volatile char*>(mapping)[0] = 'a';
}
}
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp
index 4cd6193..52c1c25 100644
--- a/debuggerd/debuggerd_test.cpp
+++ b/debuggerd/debuggerd_test.cpp
@@ -300,24 +300,7 @@
}
static void ConsumeFd(unique_fd fd, std::string* output) {
- constexpr size_t read_length = PAGE_SIZE;
- std::string result;
-
- while (true) {
- size_t offset = result.size();
- result.resize(result.size() + PAGE_SIZE);
- ssize_t rc = TEMP_FAILURE_RETRY(read(fd.get(), &result[offset], read_length));
- if (rc == -1) {
- FAIL() << "read failed: " << strerror(errno);
- } else if (rc == 0) {
- result.resize(result.size() - PAGE_SIZE);
- break;
- }
-
- result.resize(result.size() - PAGE_SIZE + rc);
- }
-
- *output = std::move(result);
+ ASSERT_TRUE(android::base::ReadFdToString(fd, output));
}
class LogcatCollector {
diff --git a/debuggerd/handler/debuggerd_handler.cpp b/debuggerd/handler/debuggerd_handler.cpp
index c6a535a..1e5365d 100644
--- a/debuggerd/handler/debuggerd_handler.cpp
+++ b/debuggerd/handler/debuggerd_handler.cpp
@@ -721,19 +721,19 @@
}
size_t thread_stack_pages = 8;
- void* thread_stack_allocation = mmap(nullptr, PAGE_SIZE * (thread_stack_pages + 2), PROT_NONE,
+ void* thread_stack_allocation = mmap(nullptr, getpagesize() * (thread_stack_pages + 2), PROT_NONE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (thread_stack_allocation == MAP_FAILED) {
fatal_errno("failed to allocate debuggerd thread stack");
}
- char* stack = static_cast<char*>(thread_stack_allocation) + PAGE_SIZE;
- if (mprotect(stack, PAGE_SIZE * thread_stack_pages, PROT_READ | PROT_WRITE) != 0) {
+ char* stack = static_cast<char*>(thread_stack_allocation) + getpagesize();
+ if (mprotect(stack, getpagesize() * thread_stack_pages, PROT_READ | PROT_WRITE) != 0) {
fatal_errno("failed to mprotect debuggerd thread stack");
}
// Stack grows negatively, set it to the last byte in the page...
- stack = (stack + thread_stack_pages * PAGE_SIZE - 1);
+ stack = (stack + thread_stack_pages * getpagesize() - 1);
// and align it.
stack -= 15;
pseudothread_stack = stack;
diff --git a/debuggerd/libdebuggerd/scudo.cpp b/debuggerd/libdebuggerd/scudo.cpp
index 5a62fe1..837f406 100644
--- a/debuggerd/libdebuggerd/scudo.cpp
+++ b/debuggerd/libdebuggerd/scudo.cpp
@@ -22,6 +22,7 @@
#include <android-base/macros.h>
#include <bionic/macros.h>
+#include <unistd.h>
#include "tombstone.pb.h"
@@ -54,21 +55,21 @@
}
untagged_fault_addr_ = process_info.untagged_fault_address;
- uintptr_t fault_page = untagged_fault_addr_ & ~(PAGE_SIZE - 1);
+ uintptr_t fault_page = untagged_fault_addr_ & ~(getpagesize() - 1);
- uintptr_t memory_begin = fault_page - PAGE_SIZE * 16;
+ uintptr_t memory_begin = fault_page - getpagesize() * 16;
if (memory_begin > fault_page) {
return;
}
- uintptr_t memory_end = fault_page + PAGE_SIZE * 16;
+ uintptr_t memory_end = fault_page + getpagesize() * 16;
if (memory_end < fault_page) {
return;
}
auto memory = std::make_unique<char[]>(memory_end - memory_begin);
- for (auto i = memory_begin; i != memory_end; i += PAGE_SIZE) {
- process_memory->ReadFully(i, memory.get() + i - memory_begin, PAGE_SIZE);
+ for (auto i = memory_begin; i != memory_end; i += getpagesize()) {
+ process_memory->ReadFully(i, memory.get() + i - memory_begin, getpagesize());
}
auto memory_tags = std::make_unique<char[]>((memory_end - memory_begin) / kTagGranuleSize);
diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp
index 7f4959f..e568a9b 100644
--- a/fs_mgr/fs_mgr.cpp
+++ b/fs_mgr/fs_mgr.cpp
@@ -613,7 +613,6 @@
// Read the primary superblock from an f2fs filesystem. On failure return
// false. If it's not an f2fs filesystem, also set FS_STAT_INVALID_MAGIC.
-#define F2FS_BLKSIZE 4096
#define F2FS_SUPER_OFFSET 1024
static bool read_f2fs_superblock(const std::string& blk_device, int* fs_stat) {
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(blk_device.c_str(), O_RDONLY | O_CLOEXEC)));
@@ -628,7 +627,9 @@
PERROR << "Can't read '" << blk_device << "' superblock1";
return false;
}
- if (TEMP_FAILURE_RETRY(pread(fd, &sb2, sizeof(sb2), F2FS_BLKSIZE + F2FS_SUPER_OFFSET)) !=
+ // F2FS only supports block_size=page_size case. So, it is safe to call
+ // `getpagesize()` and use that as size of super block.
+ if (TEMP_FAILURE_RETRY(pread(fd, &sb2, sizeof(sb2), getpagesize() + F2FS_SUPER_OFFSET)) !=
sizeof(sb2)) {
PERROR << "Can't read '" << blk_device << "' superblock2";
return false;
@@ -652,7 +653,7 @@
return false;
}
if (sb == cpu_to_le32(F2FS_SUPER_MAGIC)) return true;
- if (TEMP_FAILURE_RETRY(pread(fd, &sb, sizeof(sb), F2FS_BLKSIZE + F2FS_SUPER_OFFSET)) !=
+ if (TEMP_FAILURE_RETRY(pread(fd, &sb, sizeof(sb), getpagesize() + F2FS_SUPER_OFFSET)) !=
sizeof(sb)) {
return false;
}
diff --git a/fs_mgr/fs_mgr_format.cpp b/fs_mgr/fs_mgr_format.cpp
index 7385f79..622f181 100644
--- a/fs_mgr/fs_mgr_format.cpp
+++ b/fs_mgr/fs_mgr_format.cpp
@@ -32,6 +32,7 @@
#include <selinux/android.h>
#include <selinux/label.h>
#include <selinux/selinux.h>
+#include <string>
#include "fs_mgr_priv.h"
@@ -68,6 +69,13 @@
/* Format the partition using the calculated length */
+ // EXT4 supports 4K block size on 16K page sizes. A 4K block
+ // size formatted EXT4 partition will mount fine on both 4K and 16K page
+ // size kernels.
+ // However, EXT4 does not support 16K block size on 4K systems.
+ // If we want the same userspace code to work on both 4k/16k kernels,
+ // using a hardcoded 4096 block size is a simple solution. Using
+ // getpagesize() here would work as well, but 4096 is simpler.
std::string size_str = std::to_string(dev_sz / 4096);
std::vector<const char*> mke2fs_args = {"/system/bin/mke2fs", "-t", "ext4", "-b", "4096"};
@@ -127,7 +135,7 @@
/* Format the partition using the calculated length */
- std::string size_str = std::to_string(dev_sz / 4096);
+ const auto size_str = std::to_string(dev_sz / getpagesize());
std::vector<const char*> args = {"/system/bin/make_f2fs", "-g", "android"};
if (needs_projid) {
diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp
index c3c10ba..c85e831 100644
--- a/fs_mgr/fs_mgr_fstab.cpp
+++ b/fs_mgr/fs_mgr_fstab.cpp
@@ -51,6 +51,7 @@
namespace {
constexpr char kDefaultAndroidDtDir[] = "/proc/device-tree/firmware/android";
+constexpr char kProcMountsPath[] = "/proc/mounts";
struct FlagList {
const char *name;
@@ -699,9 +700,7 @@
}
}
-bool ReadFstabFromFile(const std::string& path, Fstab* fstab_out) {
- const bool is_proc_mounts = (path == "/proc/mounts");
-
+static bool ReadFstabFromFileCommon(const std::string& path, Fstab* fstab_out) {
std::string fstab_str;
if (!android::base::ReadFileToString(path, &fstab_str, /* follow_symlinks = */ true)) {
PERROR << __FUNCTION__ << "(): failed to read file: '" << path << "'";
@@ -709,11 +708,22 @@
}
Fstab fstab;
- if (!ParseFstabFromString(fstab_str, is_proc_mounts, &fstab)) {
+ if (!ParseFstabFromString(fstab_str, path == kProcMountsPath, &fstab)) {
LERROR << __FUNCTION__ << "(): failed to load fstab from : '" << path << "'";
return false;
}
- if (!is_proc_mounts) {
+
+ EnableMandatoryFlags(&fstab);
+
+ *fstab_out = std::move(fstab);
+ return true;
+}
+
+bool ReadFstabFromFile(const std::string& path, Fstab* fstab) {
+ if (!ReadFstabFromFileCommon(path, fstab)) {
+ return false;
+ }
+ if (path != kProcMountsPath) {
if (!access(android::gsi::kGsiBootedIndicatorFile, F_OK)) {
std::string dsu_slot;
if (!android::gsi::GetActiveDsu(&dsu_slot)) {
@@ -725,20 +735,23 @@
PERROR << __FUNCTION__ << "(): failed to read DSU LP names";
return false;
}
- TransformFstabForDsu(&fstab, dsu_slot, Split(lp_names, ","));
+ TransformFstabForDsu(fstab, dsu_slot, Split(lp_names, ","));
} else if (errno != ENOENT) {
PERROR << __FUNCTION__ << "(): failed to access() DSU booted indicator";
return false;
}
+
+ SkipMountingPartitions(fstab, false /* verbose */);
}
-
- SkipMountingPartitions(&fstab, false /* verbose */);
- EnableMandatoryFlags(&fstab);
-
- *fstab_out = std::move(fstab);
return true;
}
+bool ReadFstabFromProcMounts(Fstab* fstab) {
+ // Don't call `ReadFstabFromFile` because the code for `path != kProcMountsPath` has an extra
+ // code size cost, even if it's never executed.
+ return ReadFstabFromFileCommon(kProcMountsPath, fstab);
+}
+
// Returns fstab entries parsed from the device tree if they exist
bool ReadFstabFromDt(Fstab* fstab, bool verbose) {
std::string fstab_buf = ReadFstabFromDt();
diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp
index f04fc8d..01827d6 100644
--- a/fs_mgr/fs_mgr_overlayfs.cpp
+++ b/fs_mgr/fs_mgr_overlayfs.cpp
@@ -939,7 +939,9 @@
auto command = ""s;
if (!access(kMkF2fs.c_str(), X_OK) && fs_mgr_filesystem_available("f2fs")) {
fs_type = "f2fs";
- command = kMkF2fs + " -w 4096 -f -d1 -l" + android::base::Basename(kScratchMountPoint);
+ command = kMkF2fs + " -w ";
+ command += std::to_string(getpagesize());
+ command += " -f -d1 -l" + android::base::Basename(kScratchMountPoint);
} else if (!access(kMkExt4.c_str(), X_OK) && fs_mgr_filesystem_available("ext4")) {
fs_type = "ext4";
command = kMkExt4 + " -F -b 4096 -t ext4 -m 0 -O has_journal -M " + kScratchMountPoint;
diff --git a/fs_mgr/include_fstab/fstab/fstab.h b/fs_mgr/include_fstab/fstab/fstab.h
index a914b53..9cb1546 100644
--- a/fs_mgr/include_fstab/fstab/fstab.h
+++ b/fs_mgr/include_fstab/fstab/fstab.h
@@ -101,6 +101,7 @@
bool SkipMountWithConfig(const std::string& skip_config, Fstab* fstab, bool verbose);
bool ReadFstabFromFile(const std::string& path, Fstab* fstab);
+bool ReadFstabFromProcMounts(Fstab* fstab);
bool ReadFstabFromDt(Fstab* fstab, bool verbose = true);
bool ReadDefaultFstab(Fstab* fstab);
bool SkipMountingPartitions(Fstab* fstab, bool verbose = false);
diff --git a/libbinderwrapper/Android.bp b/libbinderwrapper/Android.bp
index 75f43ee..87c55fa 100644
--- a/libbinderwrapper/Android.bp
+++ b/libbinderwrapper/Android.bp
@@ -26,13 +26,10 @@
"-Werror",
"-Wno-unused-parameter",
- // for libchrome
- "-Wno-sign-promo",
],
export_include_dirs: ["include"],
shared_libs: [
"libbinder",
- "libchrome",
"libutils",
],
}
diff --git a/libbinderwrapper/binder_wrapper.cc b/libbinderwrapper/binder_wrapper.cc
index ca9c1df..f5e7476 100644
--- a/libbinderwrapper/binder_wrapper.cc
+++ b/libbinderwrapper/binder_wrapper.cc
@@ -16,7 +16,7 @@
#include <binderwrapper/binder_wrapper.h>
-#include <base/logging.h>
+#include <android-base/logging.h>
#include "real_binder_wrapper.h"
diff --git a/libbinderwrapper/include/binderwrapper/binder_test_base.h b/libbinderwrapper/include/binderwrapper/binder_test_base.h
index 06543de..46eca3f 100644
--- a/libbinderwrapper/include/binderwrapper/binder_test_base.h
+++ b/libbinderwrapper/include/binderwrapper/binder_test_base.h
@@ -17,7 +17,6 @@
#ifndef SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_TEST_BASE_H_
#define SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_TEST_BASE_H_
-#include <base/macros.h>
#include <gtest/gtest.h>
namespace android {
@@ -37,7 +36,7 @@
StubBinderWrapper* binder_wrapper_; // Not owned.
private:
- DISALLOW_COPY_AND_ASSIGN(BinderTestBase);
+ BinderTestBase(const BinderTestBase&) = delete;
};
} // namespace android
diff --git a/libbinderwrapper/include/binderwrapper/binder_wrapper.h b/libbinderwrapper/include/binderwrapper/binder_wrapper.h
index a104bff..fc5708b 100644
--- a/libbinderwrapper/include/binderwrapper/binder_wrapper.h
+++ b/libbinderwrapper/include/binderwrapper/binder_wrapper.h
@@ -19,9 +19,9 @@
#include <sys/types.h>
+#include <functional>
#include <string>
-#include <base/callback.h>
#include <utils/StrongPointer.h>
namespace android {
@@ -68,9 +68,8 @@
// Registers |callback| to be invoked when |binder| dies. If another callback
// is currently registered for |binder|, it will be replaced.
- virtual bool RegisterForDeathNotifications(
- const sp<IBinder>& binder,
- const ::base::Closure& callback) = 0;
+ virtual bool RegisterForDeathNotifications(const sp<IBinder>& binder,
+ const std::function<void()>&) = 0;
// Unregisters the callback, if any, for |binder|.
virtual bool UnregisterForDeathNotifications(const sp<IBinder>& binder) = 0;
diff --git a/libbinderwrapper/include/binderwrapper/stub_binder_wrapper.h b/libbinderwrapper/include/binderwrapper/stub_binder_wrapper.h
index 9d4578e..2a7f77e 100644
--- a/libbinderwrapper/include/binderwrapper/stub_binder_wrapper.h
+++ b/libbinderwrapper/include/binderwrapper/stub_binder_wrapper.h
@@ -21,7 +21,6 @@
#include <string>
#include <vector>
-#include <base/macros.h>
#include <binder/Binder.h>
#include <binder/IBinder.h>
#include <binderwrapper/binder_wrapper.h>
@@ -98,7 +97,7 @@
const sp<IBinder>& binder) override;
sp<BBinder> CreateLocalBinder() override;
bool RegisterForDeathNotifications(const sp<IBinder>& binder,
- const ::base::Closure& callback) override;
+ const std::function<void()>& callback) override;
bool UnregisterForDeathNotifications(const sp<IBinder>& binder) override;
uid_t GetCallingUid() override;
pid_t GetCallingPid() override;
@@ -119,13 +118,13 @@
// Map from binder handle to the callback that should be invoked on binder
// death.
- std::map<sp<IBinder>, ::base::Closure> death_callbacks_;
+ std::map<sp<IBinder>, std::function<void()>> death_callbacks_;
// Values to return from GetCallingUid() and GetCallingPid();
uid_t calling_uid_;
pid_t calling_pid_;
- DISALLOW_COPY_AND_ASSIGN(StubBinderWrapper);
+ StubBinderWrapper(const StubBinderWrapper&) = delete;
};
} // namespace android
diff --git a/libbinderwrapper/real_binder_wrapper.cc b/libbinderwrapper/real_binder_wrapper.cc
index f93f183..d214ce3 100644
--- a/libbinderwrapper/real_binder_wrapper.cc
+++ b/libbinderwrapper/real_binder_wrapper.cc
@@ -16,7 +16,8 @@
#include "real_binder_wrapper.h"
-#include <base/logging.h>
+#include <android-base/logging.h>
+
#include <binder/Binder.h>
#include <binder/IBinder.h>
#include <binder/IPCThreadState.h>
@@ -29,20 +30,18 @@
// be awkward.
class RealBinderWrapper::DeathRecipient : public IBinder::DeathRecipient {
public:
- explicit DeathRecipient(const ::base::Closure& callback)
- : callback_(callback) {}
- ~DeathRecipient() = default;
+ explicit DeathRecipient(const std::function<void()>& callback)
+ : callback_(std::move(callback)) {}
+ ~DeathRecipient() = default;
- // IBinder::DeathRecipient:
- void binderDied(const wp<IBinder>& who) override {
- callback_.Run();
- }
+ // IBinder::DeathRecipient:
+ void binderDied(const wp<IBinder>& who) override { callback_(); }
private:
// Callback to run in response to binder death.
- ::base::Closure callback_;
+ std::function<void()> callback_;
- DISALLOW_COPY_AND_ASSIGN(DeathRecipient);
+ DISALLOW_COPY_AND_ASSIGN(DeathRecipient);
};
RealBinderWrapper::RealBinderWrapper() = default;
@@ -83,9 +82,8 @@
return sp<BBinder>(new BBinder());
}
-bool RealBinderWrapper::RegisterForDeathNotifications(
- const sp<IBinder>& binder,
- const ::base::Closure& callback) {
+bool RealBinderWrapper::RegisterForDeathNotifications(const sp<IBinder>& binder,
+ const std::function<void()>& callback) {
sp<DeathRecipient> recipient(new DeathRecipient(callback));
if (binder->linkToDeath(recipient) != OK) {
LOG(ERROR) << "Failed to register for death notifications on "
diff --git a/libbinderwrapper/real_binder_wrapper.h b/libbinderwrapper/real_binder_wrapper.h
index fa05383..d0468f0 100644
--- a/libbinderwrapper/real_binder_wrapper.h
+++ b/libbinderwrapper/real_binder_wrapper.h
@@ -19,7 +19,6 @@
#include <map>
-#include <base/macros.h>
#include <binderwrapper/binder_wrapper.h>
namespace android {
@@ -38,7 +37,7 @@
const sp<IBinder>& binder) override;
sp<BBinder> CreateLocalBinder() override;
bool RegisterForDeathNotifications(const sp<IBinder>& binder,
- const ::base::Closure& callback) override;
+ const std::function<void()>& callback) override;
bool UnregisterForDeathNotifications(const sp<IBinder>& binder) override;
uid_t GetCallingUid() override;
pid_t GetCallingPid() override;
@@ -50,7 +49,7 @@
// death.
std::map<sp<IBinder>, sp<DeathRecipient>> death_recipients_;
- DISALLOW_COPY_AND_ASSIGN(RealBinderWrapper);
+ RealBinderWrapper(const RealBinderWrapper&) = delete;
};
} // namespace android
diff --git a/libbinderwrapper/stub_binder_wrapper.cc b/libbinderwrapper/stub_binder_wrapper.cc
index 8e75f62..fabf122 100644
--- a/libbinderwrapper/stub_binder_wrapper.cc
+++ b/libbinderwrapper/stub_binder_wrapper.cc
@@ -16,7 +16,8 @@
#include <binderwrapper/stub_binder_wrapper.h>
-#include <base/logging.h>
+#include <android-base/logging.h>
+
#include <binder/Binder.h>
#include <binder/IBinder.h>
@@ -41,8 +42,7 @@
void StubBinderWrapper::NotifyAboutBinderDeath(const sp<IBinder>& binder) {
const auto it = death_callbacks_.find(binder);
- if (it != death_callbacks_.end())
- it->second.Run();
+ if (it != death_callbacks_.end()) it->second();
}
sp<IBinder> StubBinderWrapper::GetService(const std::string& service_name) {
@@ -62,9 +62,8 @@
return binder;
}
-bool StubBinderWrapper::RegisterForDeathNotifications(
- const sp<IBinder>& binder,
- const ::base::Closure& callback) {
+bool StubBinderWrapper::RegisterForDeathNotifications(const sp<IBinder>& binder,
+ const std::function<void()>& callback) {
death_callbacks_[binder] = callback;
return true;
}
diff --git a/libcutils/include/cutils/trace.h b/libcutils/include/cutils/trace.h
index 3867f34..7f57637 100644
--- a/libcutils/include/cutils/trace.h
+++ b/libcutils/include/cutils/trace.h
@@ -89,6 +89,36 @@
#error ATRACE_TAG must be defined to be one of the tags defined in cutils/trace.h
#endif
+/** Internal implementation detail. Do not use. */
+void atrace_begin_body(const char*);
+
+/** Internal implementation detail. Do not use. */
+void atrace_end_body();
+
+/** Internal implementation detail. Do not use. */
+void atrace_async_begin_body(const char*, int32_t);
+
+/** Internal implementation detail. Do not use. */
+void atrace_async_end_body(const char*, int32_t);
+
+/** Internal implementation detail. Do not use. */
+void atrace_async_for_track_begin_body(const char*, const char*, int32_t);
+
+/** Internal implementation detail. Do not use. */
+void atrace_async_for_track_end_body(const char*, int32_t);
+
+/** Internal implementation detail. Do not use. */
+void atrace_instant_body(const char*);
+
+/** Internal implementation detail. Do not use. */
+void atrace_instant_for_track_body(const char*, const char*);
+
+/** Internal implementation detail. Do not use. */
+void atrace_int_body(const char*, int32_t);
+
+/** Internal implementation detail. Do not use. */
+void atrace_int64_body(const char*, int64_t);
+
/**
* Opens the trace file for writing and reads the property for initial tags.
* The atrace.tags.enableflags property sets the tags to trace.
@@ -159,7 +189,6 @@
static inline void atrace_begin(uint64_t tag, const char* name)
{
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_begin_body(const char*);
atrace_begin_body(name);
}
}
@@ -172,7 +201,6 @@
static inline void atrace_end(uint64_t tag)
{
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_end_body();
atrace_end_body();
}
}
@@ -190,7 +218,6 @@
int32_t cookie)
{
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_async_begin_body(const char*, int32_t);
atrace_async_begin_body(name, cookie);
}
}
@@ -203,7 +230,6 @@
static inline void atrace_async_end(uint64_t tag, const char* name, int32_t cookie)
{
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_async_end_body(const char*, int32_t);
atrace_async_end_body(name, cookie);
}
}
@@ -221,7 +247,6 @@
static inline void atrace_async_for_track_begin(uint64_t tag, const char* track_name,
const char* name, int32_t cookie) {
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_async_for_track_begin_body(const char*, const char*, int32_t);
atrace_async_for_track_begin_body(track_name, name, cookie);
}
}
@@ -235,7 +260,6 @@
static inline void atrace_async_for_track_end(uint64_t tag, const char* track_name,
int32_t cookie) {
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_async_for_track_end_body(const char*, int32_t);
atrace_async_for_track_end_body(track_name, cookie);
}
}
@@ -252,7 +276,6 @@
#define ATRACE_INSTANT(name) atrace_instant(ATRACE_TAG, name)
static inline void atrace_instant(uint64_t tag, const char* name) {
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_instant_body(const char*);
atrace_instant_body(name);
}
}
@@ -269,7 +292,6 @@
static inline void atrace_instant_for_track(uint64_t tag, const char* track_name,
const char* name) {
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_instant_for_track_body(const char*, const char*);
atrace_instant_for_track_body(track_name, name);
}
}
@@ -282,7 +304,6 @@
static inline void atrace_int(uint64_t tag, const char* name, int32_t value)
{
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_int_body(const char*, int32_t);
atrace_int_body(name, value);
}
}
@@ -295,7 +316,6 @@
static inline void atrace_int64(uint64_t tag, const char* name, int64_t value)
{
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- void atrace_int64_body(const char*, int64_t);
atrace_int64_body(name, value);
}
}
diff --git a/libcutils/trace-host.cpp b/libcutils/trace-host.cpp
index e9f58c3..2bf57eb 100644
--- a/libcutils/trace-host.cpp
+++ b/libcutils/trace-host.cpp
@@ -20,7 +20,6 @@
int atrace_marker_fd = -1;
uint64_t atrace_enabled_tags = 0;
-void atrace_set_debuggable(bool /*debuggable*/) {}
void atrace_set_tracing_enabled(bool /*enabled*/) {}
void atrace_update_tags() { }
void atrace_setup() { }
diff --git a/libmodprobe/libmodprobe.cpp b/libmodprobe/libmodprobe.cpp
index 858b955..5023c79 100644
--- a/libmodprobe/libmodprobe.cpp
+++ b/libmodprobe/libmodprobe.cpp
@@ -230,7 +230,7 @@
}
std::vector<std::string> lines = android::base::Split(cfg_contents, "\n");
- for (const std::string line : lines) {
+ for (const auto& line : lines) {
if (line.empty() || line[0] == '#') {
continue;
}
@@ -421,7 +421,8 @@
}
if (strict && !module_loaded) {
- LOG(ERROR) << "LoadWithAliases was unable to load " << module_name;
+ LOG(ERROR) << "LoadWithAliases was unable to load " << module_name
+ << ", tried: " << android::base::Join(modules_to_load, ", ");
return false;
}
return true;
@@ -524,11 +525,8 @@
std::lock_guard guard(module_loaded_lock_);
// Remove loaded module form mod_with_deps and soft dependencies of other modules
- for (const auto& module_loaded : module_loaded_) {
- if (mod_with_deps.find(module_loaded) != mod_with_deps.end()) {
- mod_with_deps.erase(module_loaded);
- }
- }
+ for (const auto& module_loaded : module_loaded_)
+ mod_with_deps.erase(module_loaded);
// Remove loaded module form dependencies of other modules which are not loaded yet
for (const auto& module_loaded_path : module_loaded_paths_) {
diff --git a/libmodprobe/libmodprobe_ext.cpp b/libmodprobe/libmodprobe_ext.cpp
index 94a1dc4..c4519e3 100644
--- a/libmodprobe/libmodprobe_ext.cpp
+++ b/libmodprobe/libmodprobe_ext.cpp
@@ -84,7 +84,7 @@
}
bool Modprobe::ModuleExists(const std::string& module_name) {
- struct stat fileStat;
+ struct stat fileStat {};
if (blocklist_enabled && module_blocklist_.count(module_name)) {
LOG(INFO) << "module " << module_name << " is blocklisted";
return false;
@@ -95,7 +95,7 @@
return false;
}
if (stat(deps.front().c_str(), &fileStat)) {
- LOG(INFO) << "module " << module_name << " does not exist";
+ PLOG(INFO) << "module " << module_name << " can't be loaded; can't access " << deps.front();
return false;
}
if (!S_ISREG(fileStat.st_mode)) {
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index 5999e39..7cca105 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -362,14 +362,19 @@
return err->error;
}
+// Pass bitwise complement of prefix length to disable DAD, ie. use ~64 instead of 64.
// Returns zero on success and negative errno on failure.
int ifc_add_address(const char *name, const char *address, int prefixlen) {
- return ifc_act_on_address(RTM_NEWADDR, name, address, prefixlen, /*nodad*/ false);
+ bool nodad = (prefixlen < 0);
+ if (nodad) prefixlen = ~prefixlen;
+ return ifc_act_on_address(RTM_NEWADDR, name, address, prefixlen, nodad);
}
// Returns zero on success and negative errno on failure.
int ifc_del_address(const char *name, const char * address, int prefixlen) {
- return ifc_act_on_address(RTM_DELADDR, name, address, prefixlen, /*nodad*/ false);
+ bool nodad = (prefixlen < 0);
+ if (nodad) prefixlen = ~prefixlen;
+ return ifc_act_on_address(RTM_DELADDR, name, address, prefixlen, nodad);
}
/*
diff --git a/libstats/pull_rust/Android.bp b/libstats/pull_rust/Android.bp
index 85a38f8..4609e6b 100644
--- a/libstats/pull_rust/Android.bp
+++ b/libstats/pull_rust/Android.bp
@@ -28,7 +28,6 @@
],
source_stem: "bindings",
bindgen_flags: [
- "--size_t-is-usize",
"--allowlist-function=AStatsEventList_addStatsEvent",
"--allowlist-function=AStatsEvent_.*",
"--allowlist-function=AStatsManager_.*",
diff --git a/libutils/Vector_fuzz.cpp b/libutils/Vector_fuzz.cpp
index f6df051..6fd2baf 100644
--- a/libutils/Vector_fuzz.cpp
+++ b/libutils/Vector_fuzz.cpp
@@ -13,71 +13,203 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "fuzzer/FuzzedDataProvider.h"
-#include "utils/Vector.h"
-static constexpr uint16_t MAX_VEC_SIZE = 5000;
+#include <fuzzer/FuzzedDataProvider.h>
+#include <utils/Log.h>
+#include <utils/Vector.h>
-void runVectorFuzz(const uint8_t* data, size_t size) {
- FuzzedDataProvider dataProvider(data, size);
- android::Vector<uint8_t> vec = android::Vector<uint8_t>();
- // We want to test handling of sizeof as well.
- android::Vector<uint32_t> vec32 = android::Vector<uint32_t>();
+#include <functional>
- // We're going to generate two vectors of this size
- size_t vectorSize = dataProvider.ConsumeIntegralInRange<size_t>(0, MAX_VEC_SIZE);
- vec.setCapacity(vectorSize);
- vec32.setCapacity(vectorSize);
- for (size_t i = 0; i < vectorSize; i++) {
- uint8_t count = dataProvider.ConsumeIntegralInRange<uint8_t>(1, 5);
- vec.insertAt((uint8_t)i, i, count);
- vec32.insertAt((uint32_t)i, i, count);
- vec.push_front(i);
- vec32.push(i);
+using android::Vector;
+
+static constexpr uint16_t MAX_VEC_SIZE = 100;
+static constexpr bool kLog = false;
+
+struct NonTrivialDestructor {
+ NonTrivialDestructor() : mInit(1) {}
+ ~NonTrivialDestructor() {
+ LOG_ALWAYS_FATAL_IF(mInit != 1, "mInit should be 1, but it's: %d", mInit);
+ mInit--;
+ LOG_ALWAYS_FATAL_IF(mInit != 0, "mInit should be 0, but it's: %d", mInit);
}
- // Now we'll perform some test operations with any remaining data
- // Index to perform operations at
- size_t index = dataProvider.ConsumeIntegralInRange<size_t>(0, vec.size());
- std::vector<uint8_t> remainingVec = dataProvider.ConsumeRemainingBytes<uint8_t>();
- // Insert an array and vector
- vec.insertArrayAt(remainingVec.data(), index, remainingVec.size());
- android::Vector<uint8_t> vecCopy = android::Vector<uint8_t>(vec);
- vec.insertVectorAt(vecCopy, index);
- // Same thing for 32 bit vector
- android::Vector<uint32_t> vec32Copy = android::Vector<uint32_t>(vec32);
- vec32.insertArrayAt(vec32Copy.array(), index, vec32.size());
- vec32.insertVectorAt(vec32Copy, index);
- // Replace single character
- if (remainingVec.size() > 0) {
- vec.replaceAt(remainingVec[0], index);
- vec32.replaceAt(static_cast<uint32_t>(remainingVec[0]), index);
- } else {
- vec.replaceAt(0, index);
- vec32.replaceAt(0, index);
+ private:
+ uint8_t mInit;
+};
+
+template <typename T>
+struct VectorFuzzerData {
+ Vector<T> vector;
+ const std::vector<std::function<void(FuzzedDataProvider&, Vector<T>&)>> funcs = {
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ // operator= Vector<TYPE>, still needs for SortedVector
+ if (kLog) ALOGI("operator=");
+ vector = testVector(provider);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("clear");
+ vector.clear();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("size");
+ vector.size();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("isEmpty");
+ vector.isEmpty();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("capacity");
+ vector.capacity();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ size_t vectorSize = provider.ConsumeIntegralInRange<size_t>(0, MAX_VEC_SIZE);
+ if (kLog) ALOGI("setCapacity");
+ vector.setCapacity(vectorSize);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ size_t vectorSize = provider.ConsumeIntegralInRange<size_t>(0, MAX_VEC_SIZE);
+ if (kLog) ALOGI("resize");
+ vector.resize(vectorSize);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("array");
+ vector.array();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("editArray");
+ vector.editArray();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ if (vector.size() == 0) return;
+ size_t idx = provider.ConsumeIntegralInRange<size_t>(0, vector.size() - 1);
+ if (kLog) ALOGI("operator[]");
+ vector[idx]; // returns a const value for Vector
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ if (vector.size() == 0) return;
+ size_t idx = provider.ConsumeIntegralInRange<size_t>(0, vector.size() - 1);
+ if (kLog) ALOGI("itemAt");
+ vector.itemAt(idx);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (vector.size() == 0) return;
+ if (kLog) ALOGI("top");
+ vector.top();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ if (vector.size() == 0) return;
+ size_t idx = provider.ConsumeIntegralInRange<size_t>(0, vector.size() - 1);
+ if (kLog) ALOGI("editItemAt");
+ vector.editItemAt(idx);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (vector.size() == 0) return;
+ if (kLog) ALOGI("editTop");
+ vector.editTop() = T{};
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ uint8_t idx = provider.ConsumeIntegralInRange<uint8_t>(0, vector.size());
+ Vector vec2 = testVector(provider);
+ if (vec2.size() == 0) return; // TODO: maybe we should support this?
+ if (kLog) ALOGI("insertVectorAt %d of size %zu", idx, vec2.size());
+ vector.insertVectorAt(vec2, idx);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ if (kLog) ALOGI("appendVector");
+ vector.appendVector(testVector(provider));
+ },
+ // TODO: insertArrayAt
+ // TODO: appendArray
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ uint8_t idx = provider.ConsumeIntegralInRange<uint8_t>(0, vector.size());
+ uint8_t numItems = provider.ConsumeIntegralInRange<uint8_t>(1, 100);
+ if (kLog) ALOGI("insertAt");
+ vector.insertAt(idx, numItems);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ uint8_t idx = provider.ConsumeIntegralInRange<uint8_t>(0, vector.size());
+ uint8_t numItems = provider.ConsumeIntegralInRange<uint8_t>(1, 100);
+ if (kLog) ALOGI("insertAt");
+ vector.insertAt(T{}, idx, numItems);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (vector.size() == 0) return;
+ if (kLog) ALOGI("pop");
+ vector.pop();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("push");
+ vector.push();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("add");
+ vector.add();
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("add");
+ vector.add(T{});
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ uint8_t idx = provider.ConsumeIntegralInRange<uint8_t>(0, vector.size() - 1);
+ if (kLog) ALOGI("replaceAt");
+ vector.replaceAt(idx);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ uint8_t idx = provider.ConsumeIntegralInRange<uint8_t>(0, vector.size() - 1);
+ if (kLog) ALOGI("replaceAt");
+ vector.replaceAt(T{}, idx);
+ },
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ if (vector.size() == 0) return;
+ uint8_t idx = provider.ConsumeIntegralInRange<uint8_t>(0, vector.size() - 1);
+ if (kLog) ALOGI("remoteItemsAt");
+ vector.removeItemsAt(idx); // TODO: different count
+ },
+ // removeAt is alias for removeItemsAt
+ // TODO: sort
+ [&](FuzzedDataProvider& provider, Vector<T>& vector) {
+ (void)provider;
+ if (kLog) ALOGI("getItemSize");
+ vector.getItemSize();
+ },
+ // TODO: iterators
+ };
+
+ Vector<T> testVector(FuzzedDataProvider& provider) {
+ Vector<T> vec;
+ size_t vectorSize = provider.ConsumeIntegralInRange<size_t>(0, MAX_VEC_SIZE);
+ return vec;
}
- // Add any remaining bytes
- for (uint8_t i : remainingVec) {
- vec.add(i);
- vec32.add(static_cast<uint32_t>(i));
+
+ void fuzz(FuzzedDataProvider&& provider) {
+ while (provider.remaining_bytes()) {
+ size_t funcIdx = provider.ConsumeIntegralInRange<size_t>(0, funcs.size() - 1);
+ funcs[funcIdx](provider, vector);
+ }
}
- // Shrink capactiy
- vec.setCapacity(remainingVec.size());
- vec32.setCapacity(remainingVec.size());
- // Iterate through each pointer
- size_t sum = 0;
- for (auto& it : vec) {
- sum += it;
- }
- for (auto& it : vec32) {
- sum += it;
- }
- // Cleanup
- vec.clear();
- vecCopy.clear();
- vec32.clear();
- vec32Copy.clear();
-}
+};
+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- runVectorFuzz(data, size);
+ FuzzedDataProvider provider(data, size);
+
+ provider.PickValueInArray<std::function<void()>>({
+ [&]() { VectorFuzzerData<uint8_t>().fuzz(std::move(provider)); },
+ [&]() { VectorFuzzerData<int32_t>().fuzz(std::move(provider)); },
+ [&]() { VectorFuzzerData<NonTrivialDestructor>().fuzz(std::move(provider)); },
+ })();
+
return 0;
}
diff --git a/libutils/include/utils/Vector.h b/libutils/include/utils/Vector.h
index be35ea2..d5db3cb 100644
--- a/libutils/include/utils/Vector.h
+++ b/libutils/include/utils/Vector.h
@@ -67,13 +67,10 @@
virtual ~Vector();
/*! copy operator */
- const Vector<TYPE>& operator = (const Vector<TYPE>& rhs) const;
- Vector<TYPE>& operator = (const Vector<TYPE>& rhs);
+ Vector<TYPE>& operator=(const Vector<TYPE>& rhs); // NOLINT(cert-oop54-cpp)
+ Vector<TYPE>& operator=(const SortedVector<TYPE>& rhs); // NOLINT(cert-oop54-cpp)
- const Vector<TYPE>& operator = (const SortedVector<TYPE>& rhs) const;
- Vector<TYPE>& operator = (const SortedVector<TYPE>& rhs);
-
- /*
+ /*
* empty the vector
*/
@@ -248,27 +245,18 @@
finish_vector();
}
-template<class TYPE> inline
-Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) {
- VectorImpl::operator = (rhs);
+template <class TYPE>
+inline Vector<TYPE>& Vector<TYPE>::operator=(const Vector<TYPE>& rhs) // NOLINT(cert-oop54-cpp)
+{
+ VectorImpl::operator=(rhs);
return *this;
}
-template<class TYPE> inline
-const Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) const {
- VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
- return *this;
-}
-
-template<class TYPE> inline
-Vector<TYPE>& Vector<TYPE>::operator = (const SortedVector<TYPE>& rhs) {
- VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
- return *this;
-}
-
-template<class TYPE> inline
-const Vector<TYPE>& Vector<TYPE>::operator = (const SortedVector<TYPE>& rhs) const {
- VectorImpl::operator = (rhs);
+template <class TYPE>
+inline Vector<TYPE>& Vector<TYPE>::operator=(
+ const SortedVector<TYPE>& rhs) // NOLINT(cert-oop54-cpp)
+{
+ VectorImpl::operator=(static_cast<const VectorImpl&>(rhs));
return *this;
}
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 5344368..a8b78d5 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -1129,7 +1129,7 @@
write /dev/sys/fs/by-name/userdata/iostat_enable 1
# set readahead multiplier for POSIX_FADV_SEQUENTIAL files
- write /dev/sys/fs/by-name/userdata/seq_file_ra_mul 16
+ write /dev/sys/fs/by-name/userdata/seq_file_ra_mul 128
# limit discard size to 128MB in order to avoid long IO latency
# for filesystem tuning first (dm or sda)