Skip to content

Commit

Permalink
Fix loading newer libc++
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX committed Jun 28, 2020
1 parent cdeba56 commit ab54671
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#ifdef __APPLE__
#include <xlocale.h>
#endif
#include <inttypes.h>

using namespace shim;

Expand Down Expand Up @@ -196,6 +197,14 @@ void* shim::__memcpy_chk(void *dst, const void *src, size_t size, size_t max_len
return ::memcpy(dst, src, size);
}

void* shim::__memmove_chk(void *dst, const void *src, size_t size, size_t max_len) {
if (size > max_len) {
fprintf(stderr, "detected copy past buffer size");
abort();
}
return ::memmove(dst, src, size);
}

size_t shim::ctype_get_mb_cur_max() {
return MB_CUR_MAX;
}
Expand All @@ -210,6 +219,10 @@ int shim::gettimeofday(bionic::timeval *tv, void *p) {
return ret;
}

ssize_t shim::__read_chk(int fd, void *buf, size_t count, size_t buf_size) {
return read(fd, buf, count);
}


void shim::add_common_shimmed_symbols(std::vector<shim::shimmed_symbol> &list) {
list.insert(list.end(), {
Expand Down Expand Up @@ -280,6 +293,8 @@ void shim::add_stdlib_shimmed_symbols(std::vector<shim::shimmed_symbol> &list) {
{"strtoull_l", WithErrnoUpdate(strtoull_l)},
{"strtof_l", WithErrnoUpdate(strtof_l)},
{"strtold_l", WithErrnoUpdate(strtold_l)},
{"strtoumax", WithErrnoUpdate(strtoumax)},
{"strtoimax", WithErrnoUpdate(strtoimax)},

{"realpath", realpath},
{"bsearch", bsearch},
Expand Down Expand Up @@ -385,6 +400,7 @@ void shim::add_unistd_shimmed_symbols(std::vector<shim::shimmed_symbol> &list) {
{"lseek", WithErrnoUpdate(::lseek)},
{"close", WithErrnoUpdate(::close)},
{"read", WithErrnoUpdate(::read)},
{"__read_chk", __read_chk},
{"write", WithErrnoUpdate(::write)},
{"pipe", WithErrnoUpdate(::pipe)},
{"alarm", WithErrnoUpdate(::alarm)},
Expand Down Expand Up @@ -460,6 +476,7 @@ void shim::add_string_shimmed_symbols(std::vector<shim::shimmed_symbol> &list) {
{"memcpy", ::memcpy},
{"__memcpy_chk", __memcpy_chk},
{"memmove", ::memmove},
{"__memmove_chk", __memmove_chk},
{"memset", ::memset},
{"memmem", ::memmem},
{"strchr", (char *(*)(char *, int)) ::strchr},
Expand Down
4 changes: 4 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ namespace shim {

void *__memcpy_chk(void *dst, const void *src, size_t size, size_t max_len);

void *__memmove_chk(void *dst, const void *src, size_t size, size_t max_len);

size_t ctype_get_mb_cur_max();

int gettimeofday(bionic::timeval *tv, void *p);

ssize_t __read_chk(int fd, void* buf, size_t count, size_t buf_size);

void add_common_shimmed_symbols(std::vector<shimmed_symbol> &list);

void add_stdlib_shimmed_symbols(std::vector<shimmed_symbol> &list);
Expand Down
8 changes: 8 additions & 0 deletions src/file_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ int shim::open(const char *pathname, bionic::file_status_flags flags, ...) {
return ret;
}

int shim::open_2(const char *pathname, bionic::file_status_flags flags) {
int hflags = bionic::to_host_file_status_flags(flags);
int ret = ::open(pathname, hflags, 0);
bionic::update_errno();
return ret;
}

int shim::fcntl(int fd, bionic::fcntl_index cmd, void *arg) {
switch (cmd) {
case bionic::fcntl_index::SETFD:
Expand Down Expand Up @@ -155,6 +162,7 @@ void shim::add_ioctl_shimmed_symbols(std::vector<shim::shimmed_symbol> &list) {
void shim::add_fcntl_shimmed_symbols(std::vector<shim::shimmed_symbol> &list) {
list.insert(list.end(), {
{"open", open},
{"__open_2", open_2},
{"fcntl", WithErrnoUpdate(fcntl)},
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/file_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace shim {

int open(const char *pathname, bionic::file_status_flags flags, ...);

int open_2(const char *pathname, bionic::file_status_flags flags);

int fcntl(int fd, bionic::fcntl_index cmd, void *arg);

int poll_via_select(pollfd *fds, nfds_t nfds, int timeout);
Expand Down

0 comments on commit ab54671

Please sign in to comment.