summaryrefslogtreecommitdiffstats
path: root/libc/bionic
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-03-31 10:56:58 -0700
committerElliott Hughes <enh@google.com>2015-03-31 10:56:58 -0700
commit6170693e28dd72a1517c267f3f62b3f37477b8bb (patch)
treef7cf73e397d83074a6da0b6cce4459b51af334cf /libc/bionic
parent611fd2cc91f79be6759f6e630e1e81998326dfe8 (diff)
downloadbionic-6170693e28dd72a1517c267f3f62b3f37477b8bb.zip
bionic-6170693e28dd72a1517c267f3f62b3f37477b8bb.tar.gz
bionic-6170693e28dd72a1517c267f3f62b3f37477b8bb.tar.bz2
Make ThreadLocalBuffer a class rather than a macro.
Bug: 19995392 Change-Id: I497c512648fbe66257da3fb3bcd5c9911f983705
Diffstat (limited to 'libc/bionic')
-rw-r--r--libc/bionic/libgen.cpp18
-rw-r--r--libc/bionic/mntent.cpp11
-rw-r--r--libc/bionic/pty.cpp16
-rw-r--r--libc/bionic/strerror.cpp10
-rw-r--r--libc/bionic/strsignal.cpp6
-rw-r--r--libc/bionic/stubs.cpp30
6 files changed, 42 insertions, 49 deletions
diff --git a/libc/bionic/libgen.cpp b/libc/bionic/libgen.cpp
index b98f504..2f29d7b 100644
--- a/libc/bionic/libgen.cpp
+++ b/libc/bionic/libgen.cpp
@@ -36,6 +36,9 @@
#include "private/ThreadLocalBuffer.h"
+static ThreadLocalBuffer<char, MAXPATHLEN> g_basename_tls_buffer;
+static ThreadLocalBuffer<char, MAXPATHLEN> g_dirname_tls_buffer;
+
__LIBC64_HIDDEN__ int basename_r(const char* path, char* buffer, size_t buffer_size) {
const char* startp = NULL;
const char* endp = NULL;
@@ -147,17 +150,14 @@ __LIBC64_HIDDEN__ int dirname_r(const char* path, char* buffer, size_t buffer_si
return result;
}
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(basename);
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(dirname);
-
char* basename(const char* path) {
- LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, basename, MAXPATHLEN);
- int rc = basename_r(path, basename_tls_buffer, basename_tls_buffer_size);
- return (rc < 0) ? NULL : basename_tls_buffer;
+ char* buf = g_basename_tls_buffer.get();
+ int rc = basename_r(path, buf, g_basename_tls_buffer.size());
+ return (rc < 0) ? NULL : buf;
}
char* dirname(const char* path) {
- LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, dirname, MAXPATHLEN);
- int rc = dirname_r(path, dirname_tls_buffer, dirname_tls_buffer_size);
- return (rc < 0) ? NULL : dirname_tls_buffer;
+ char* buf = g_dirname_tls_buffer.get();
+ int rc = dirname_r(path, buf, g_dirname_tls_buffer.size());
+ return (rc < 0) ? NULL : buf;
}
diff --git a/libc/bionic/mntent.cpp b/libc/bionic/mntent.cpp
index 4afacda..d169e29 100644
--- a/libc/bionic/mntent.cpp
+++ b/libc/bionic/mntent.cpp
@@ -31,14 +31,13 @@
#include "private/ThreadLocalBuffer.h"
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(getmntent_mntent);
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(getmntent_strings);
+static ThreadLocalBuffer<mntent> g_getmntent_mntent_tls_buffer;
+static ThreadLocalBuffer<char, BUFSIZ> g_getmntent_strings_tls_buffer;
mntent* getmntent(FILE* fp) {
- LOCAL_INIT_THREAD_LOCAL_BUFFER(mntent*, getmntent_mntent, sizeof(mntent));
- LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, getmntent_strings, BUFSIZ);
- return getmntent_r(fp, getmntent_mntent_tls_buffer,
- getmntent_strings_tls_buffer, getmntent_strings_tls_buffer_size);
+ return getmntent_r(fp, g_getmntent_mntent_tls_buffer.get(),
+ g_getmntent_strings_tls_buffer.get(),
+ g_getmntent_strings_tls_buffer.size());
}
mntent* getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf_len) {
diff --git a/libc/bionic/pty.cpp b/libc/bionic/pty.cpp
index 8847147..1a37847 100644
--- a/libc/bionic/pty.cpp
+++ b/libc/bionic/pty.cpp
@@ -38,8 +38,8 @@
#include "private/ThreadLocalBuffer.h"
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(ptsname);
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(ttyname);
+static ThreadLocalBuffer<char, 32> g_ptsname_tls_buffer;
+static ThreadLocalBuffer<char, 64> g_ttyname_tls_buffer;
int getpt() {
return posix_openpt(O_RDWR|O_NOCTTY);
@@ -54,9 +54,9 @@ int posix_openpt(int flags) {
}
char* ptsname(int fd) {
- LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, ptsname, 32);
- int error = ptsname_r(fd, ptsname_tls_buffer, ptsname_tls_buffer_size);
- return (error == 0) ? ptsname_tls_buffer : NULL;
+ char* buf = g_ptsname_tls_buffer.get();
+ int error = ptsname_r(fd, buf, g_ptsname_tls_buffer.size());
+ return (error == 0) ? buf : NULL;
}
int ptsname_r(int fd, char* buf, size_t len) {
@@ -80,9 +80,9 @@ int ptsname_r(int fd, char* buf, size_t len) {
}
char* ttyname(int fd) {
- LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, ttyname, 64);
- int error = ttyname_r(fd, ttyname_tls_buffer, ttyname_tls_buffer_size);
- return (error == 0) ? ttyname_tls_buffer : NULL;
+ char* buf = g_ttyname_tls_buffer.get();
+ int error = ttyname_r(fd, buf, g_ttyname_tls_buffer.size());
+ return (error == 0) ? buf : NULL;
}
int ttyname_r(int fd, char* buf, size_t len) {
diff --git a/libc/bionic/strerror.cpp b/libc/bionic/strerror.cpp
index d1518ff..f74194f 100644
--- a/libc/bionic/strerror.cpp
+++ b/libc/bionic/strerror.cpp
@@ -31,16 +31,16 @@
extern "C" const char* __strerror_lookup(int);
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(strerror);
+static ThreadLocalBuffer<char, NL_TEXTMAX> g_strerror_tls_buffer;
char* strerror(int error_number) {
// Just return the original constant in the easy cases.
char* result = const_cast<char*>(__strerror_lookup(error_number));
- if (result != NULL) {
+ if (result != nullptr) {
return result;
}
- LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, strerror, NL_TEXTMAX);
- strerror_r(error_number, strerror_tls_buffer, strerror_tls_buffer_size);
- return strerror_tls_buffer;
+ result = g_strerror_tls_buffer.get();
+ strerror_r(error_number, result, g_strerror_tls_buffer.size());
+ return result;
}
diff --git a/libc/bionic/strsignal.cpp b/libc/bionic/strsignal.cpp
index 9f0193a..c389ddd 100644
--- a/libc/bionic/strsignal.cpp
+++ b/libc/bionic/strsignal.cpp
@@ -32,7 +32,7 @@
extern "C" const char* __strsignal_lookup(int);
extern "C" const char* __strsignal(int, char*, size_t);
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(strsignal);
+static ThreadLocalBuffer<char, NL_TEXTMAX> g_strsignal_tls_buffer;
char* strsignal(int signal_number) {
// Just return the original constant in the easy cases.
@@ -41,6 +41,6 @@ char* strsignal(int signal_number) {
return result;
}
- LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, strsignal, NL_TEXTMAX);
- return const_cast<char*>(__strsignal(signal_number, strsignal_tls_buffer, strsignal_tls_buffer_size));
+ return const_cast<char*>(__strsignal(signal_number, g_strsignal_tls_buffer.get(),
+ g_strsignal_tls_buffer.size()));
}
diff --git a/libc/bionic/stubs.cpp b/libc/bionic/stubs.cpp
index f9a31b9..d4440c4 100644
--- a/libc/bionic/stubs.cpp
+++ b/libc/bionic/stubs.cpp
@@ -49,25 +49,12 @@
// functions to share state, but <grp.h> functions can't clobber <passwd.h>
// functions' state and vice versa.
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(group);
-
struct group_state_t {
group group_;
char* group_members_[2];
char group_name_buffer_[32];
};
-static group_state_t* __group_state() {
- LOCAL_INIT_THREAD_LOCAL_BUFFER(group_state_t*, group, sizeof(group_state_t));
- if (group_tls_buffer != NULL) {
- memset(group_tls_buffer, 0, sizeof(group_state_t));
- group_tls_buffer->group_.gr_mem = group_tls_buffer->group_members_;
- }
- return group_tls_buffer;
-}
-
-GLOBAL_INIT_THREAD_LOCAL_BUFFER(passwd);
-
struct passwd_state_t {
passwd passwd_;
char name_buffer_[32];
@@ -75,9 +62,16 @@ struct passwd_state_t {
char sh_buffer_[32];
};
-static passwd_state_t* __passwd_state() {
- LOCAL_INIT_THREAD_LOCAL_BUFFER(passwd_state_t*, passwd, sizeof(passwd_state_t));
- return passwd_tls_buffer;
+static ThreadLocalBuffer<group_state_t> g_group_tls_buffer;
+static ThreadLocalBuffer<passwd_state_t> g_passwd_tls_buffer;
+
+static group_state_t* __group_state() {
+ group_state_t* result = g_group_tls_buffer.get();
+ if (result != nullptr) {
+ memset(result, 0, sizeof(group_state_t));
+ result->group_.gr_mem = result->group_members_;
+ }
+ return result;
}
static int do_getpw_r(int by_name, const char* name, uid_t uid,
@@ -361,7 +355,7 @@ static group* app_id_to_group(gid_t gid, group_state_t* state) {
}
passwd* getpwuid(uid_t uid) { // NOLINT: implementing bad function.
- passwd_state_t* state = __passwd_state();
+ passwd_state_t* state = g_passwd_tls_buffer.get();
if (state == NULL) {
return NULL;
}
@@ -374,7 +368,7 @@ passwd* getpwuid(uid_t uid) { // NOLINT: implementing bad function.
}
passwd* getpwnam(const char* login) { // NOLINT: implementing bad function.
- passwd_state_t* state = __passwd_state();
+ passwd_state_t* state = g_passwd_tls_buffer.get();
if (state == NULL) {
return NULL;
}