Merge changes I73a39c6d,Iab2af242
* changes: Fix test build break. extend the PTRDIFF_MAX size check to mremap
This commit is contained in:
commit
f30170dfa5
3 changed files with 26 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
|
@ -26,12 +26,24 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "private/bionic_macros.h"
|
||||
|
||||
extern "C" void* ___mremap(void*, size_t, size_t, int, void*);
|
||||
|
||||
void* mremap(void* old_address, size_t old_size, size_t new_size, int flags, ...) {
|
||||
// prevent allocations large enough for `end - start` to overflow
|
||||
size_t rounded = BIONIC_ALIGN(new_size, PAGE_SIZE);
|
||||
if (rounded < new_size || rounded > PTRDIFF_MAX) {
|
||||
errno = ENOMEM;
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
void* new_address = nullptr;
|
||||
// The optional argument is only valid if the MREMAP_FIXED flag is set,
|
||||
// so we assume it's not present otherwise.
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/user.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -219,3 +220,15 @@ TEST(sys_mman, posix_madvise_POSIX_MADV_DONTNEED) {
|
|||
TEST(sys_mman, mremap) {
|
||||
ASSERT_EQ(MAP_FAILED, mremap(nullptr, 0, 0, 0));
|
||||
}
|
||||
|
||||
const size_t huge = size_t(PTRDIFF_MAX) + 1;
|
||||
|
||||
TEST(sys_mman, mmap_PTRDIFF_MAX) {
|
||||
ASSERT_EQ(MAP_FAILED, mmap(nullptr, huge, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
|
||||
}
|
||||
|
||||
TEST(sys_mman, mremap_PTRDIFF_MAX) {
|
||||
void* map = mmap(nullptr, PAGE_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
ASSERT_NE(MAP_FAILED, map);
|
||||
ASSERT_EQ(MAP_FAILED, mremap(map, PAGE_SIZE, huge, MREMAP_MAYMOVE));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue