Merge changes Ibcd45e9b,I1ff5c0fa
* changes:
Do not munmap in MmapFile::~MmapFile
Build bionic/tests with cpp_std experimental.
diff --git a/libc/bionic/grp_pwd_file.cpp b/libc/bionic/grp_pwd_file.cpp
index 4b8b8a9..37493a7 100644
--- a/libc/bionic/grp_pwd_file.cpp
+++ b/libc/bionic/grp_pwd_file.cpp
@@ -193,10 +193,13 @@
lock_.init(false);
}
-MmapFile::~MmapFile() {
+void MmapFile::Unmap() {
if (status_ == FileStatus::Initialized) {
size_t size = end_ - start_ + 1;
munmap(const_cast<char*>(start_), size);
+ status_ = FileStatus::Uninitialized;
+ start_ = nullptr;
+ end_ = nullptr;
}
}
diff --git a/libc/bionic/grp_pwd_file.h b/libc/bionic/grp_pwd_file.h
index 93dd852..048cd82 100644
--- a/libc/bionic/grp_pwd_file.h
+++ b/libc/bionic/grp_pwd_file.h
@@ -38,12 +38,12 @@
class MmapFile {
public:
MmapFile(const char* filename);
- ~MmapFile();
template <typename Line>
bool FindById(uid_t uid, Line* line);
template <typename Line>
bool FindByName(const char* name, Line* line);
+ void Unmap();
DISALLOW_COPY_AND_ASSIGN(MmapFile);
@@ -73,6 +73,9 @@
bool FindById(uid_t id, passwd_state_t* passwd_state);
bool FindByName(const char* name, passwd_state_t* passwd_state);
+ void Unmap() {
+ mmap_file_.Unmap();
+ }
DISALLOW_COPY_AND_ASSIGN(PasswdFile);
@@ -86,6 +89,9 @@
bool FindById(gid_t id, group_state_t* group_state);
bool FindByName(const char* name, group_state_t* group_state);
+ void Unmap() {
+ mmap_file_.Unmap();
+ }
DISALLOW_COPY_AND_ASSIGN(GroupFile);
diff --git a/tests/Android.bp b/tests/Android.bp
index 5483b6a..ec90296 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -17,6 +17,7 @@
cc_defaults {
name: "bionic_tests_defaults",
host_supported: true,
+ cpp_std: "experimental",
target: {
darwin: {
enabled: false,
diff --git a/tests/grp_pwd_file_test.cpp b/tests/grp_pwd_file_test.cpp
index 79f9a10..d6f3c9f 100644
--- a/tests/grp_pwd_file_test.cpp
+++ b/tests/grp_pwd_file_test.cpp
@@ -23,6 +23,19 @@
#if defined(__BIONIC__)
#include "../libc/bionic/grp_pwd_file.cpp"
+template <typename T>
+class FileUnmapper {
+ public:
+ FileUnmapper(T& file) : file_(file) {
+ }
+ ~FileUnmapper() {
+ file_.Unmap();
+ }
+
+ private:
+ T& file_;
+};
+
void FindAndCheckPasswdEntry(PasswdFile* file, const char* name, uid_t uid, gid_t gid,
const char* dir, const char* shell) {
passwd_state_t name_passwd_state;
@@ -82,6 +95,7 @@
write(file.fd, test_string, sizeof(test_string) - 1);
PasswdFile passwd_file(file.filename);
+ FileUnmapper unmapper(passwd_file);
FindAndCheckPasswdEntry(&passwd_file, "name", 1, 2, "dir", "shell");
@@ -101,6 +115,7 @@
write(file.fd, test_string, sizeof(test_string) - 1);
GroupFile group_file(file.filename);
+ FileUnmapper unmapper(group_file);
FindAndCheckGroupEntry(&group_file, "name", 1);
@@ -136,6 +151,7 @@
write(file.fd, test_string, sizeof(test_string) - 1);
PasswdFile passwd_file(file.filename);
+ FileUnmapper unmapper(passwd_file);
FindAndCheckPasswdEntry(&passwd_file, "first", 1, 2, "dir", "shell");
FindAndCheckPasswdEntry(&passwd_file, "middle-ish", 13, 4, "/", "/system/bin/sh");
@@ -171,6 +187,7 @@
write(file.fd, test_string, sizeof(test_string) - 1);
GroupFile group_file(file.filename);
+ FileUnmapper unmapper(group_file);
FindAndCheckGroupEntry(&group_file, "first", 1);
FindAndCheckGroupEntry(&group_file, "middle-ish", 6);
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 5e55415..dd7879c 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -914,7 +914,7 @@
ASSERT_EQ(0, pthread_rwlock_rdlock(&wakeup_arg.lock));
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
wakeup_arg.tid = 0;
- wakeup_arg.trylock_function = pthread_rwlock_trywrlock;
+ wakeup_arg.trylock_function = &pthread_rwlock_trywrlock;
wakeup_arg.lock_function = lock_function;
pthread_t thread;
@@ -950,7 +950,7 @@
ASSERT_EQ(0, pthread_rwlock_wrlock(&wakeup_arg.lock));
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
wakeup_arg.tid = 0;
- wakeup_arg.trylock_function = pthread_rwlock_tryrdlock;
+ wakeup_arg.trylock_function = &pthread_rwlock_tryrdlock;
wakeup_arg.lock_function = lock_function;
pthread_t thread;
@@ -1010,8 +1010,8 @@
ASSERT_EQ(0, pthread_rwlock_wrlock(&wakeup_arg.lock));
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
wakeup_arg.tid = 0;
- wakeup_arg.trylock_function = pthread_rwlock_tryrdlock;
- wakeup_arg.timed_lock_function = pthread_rwlock_timedrdlock;
+ wakeup_arg.trylock_function = &pthread_rwlock_tryrdlock;
+ wakeup_arg.timed_lock_function = &pthread_rwlock_timedrdlock;
pthread_t thread;
ASSERT_EQ(0, pthread_create(&thread, nullptr,
@@ -1031,8 +1031,8 @@
ASSERT_EQ(0, pthread_rwlock_rdlock(&wakeup_arg.lock));
wakeup_arg.progress = RwlockWakeupHelperArg::LOCK_INITIALIZED;
wakeup_arg.tid = 0;
- wakeup_arg.trylock_function = pthread_rwlock_trywrlock;
- wakeup_arg.timed_lock_function = pthread_rwlock_timedwrlock;
+ wakeup_arg.trylock_function = &pthread_rwlock_trywrlock;
+ wakeup_arg.timed_lock_function = &pthread_rwlock_timedwrlock;
pthread_t thread;
ASSERT_EQ(0, pthread_create(&thread, nullptr,