diff options
author | Felix Fietkau <nbd@openwrt.org> | 2009-03-23 17:56:28 +0000 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2009-03-23 17:56:28 +0000 |
commit | 2b419ade23452e6481efa2794cbbfb5be9f5e8c6 (patch) | |
tree | 0578b4c71aab8f3d979d3181a922382acf050816 /toolchain/uClibc/patches-0.9.29/001-fix_mmap.patch | |
parent | 2f50ebd847f5cb4e00c5f63ae9aab873d38adafe (diff) | |
download | master-187ad058-2b419ade23452e6481efa2794cbbfb5be9f5e8c6.tar.gz master-187ad058-2b419ade23452e6481efa2794cbbfb5be9f5e8c6.tar.bz2 master-187ad058-2b419ade23452e6481efa2794cbbfb5be9f5e8c6.zip |
clean up uclibc patch/config version handling a bit
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@14994 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'toolchain/uClibc/patches-0.9.29/001-fix_mmap.patch')
-rw-r--r-- | toolchain/uClibc/patches-0.9.29/001-fix_mmap.patch | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/toolchain/uClibc/patches-0.9.29/001-fix_mmap.patch b/toolchain/uClibc/patches-0.9.29/001-fix_mmap.patch new file mode 100644 index 0000000000..38cf60a96a --- /dev/null +++ b/toolchain/uClibc/patches-0.9.29/001-fix_mmap.patch @@ -0,0 +1,91 @@ +--- /dev/null ++++ b/test/mmap/mmap2.c +@@ -0,0 +1,41 @@ ++/* When trying to map /dev/mem with offset 0xFFFFF000 on the ARM platform, mmap ++ * returns -EOVERFLOW. ++ * ++ * Since off_t is defined as a long int and the sign bit is set in the address, ++ * the shift operation shifts in ones instead of zeroes ++ * from the left. This results the offset sent to the kernel function becomes ++ * 0xFFFFFFFF instead of 0x000FFFFF with MMAP2_PAGE_SHIFT set to 12. ++ */ ++ ++#include <unistd.h> ++#include <stdio.h> ++#include <stdlib.h> ++#include <string.h> ++#include <errno.h> ++#include <fcntl.h> ++#include <sys/mman.h> ++ ++#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ ++ __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) ++ ++#define MAP_SIZE 4096UL ++#define MAP_MASK (MAP_SIZE - 1) ++ ++int main(int argc, char **argv) { ++ void* map_base = 0; ++ int fd; ++ off_t target = 0xfffff000; ++ if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL; ++ printf("/dev/mem opened.\n"); ++ fflush(stdout); ++ ++ /* Map one page */ ++ map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, ++ fd, target & ~MAP_MASK); ++ if(map_base == (void *) -1) FATAL; ++ printf("Memory mapped at address %p.\n", map_base); ++ fflush(stdout); ++ if(munmap(map_base, MAP_SIZE) == -1) FATAL; ++ close(fd); ++ return 0; ++} +--- a/libc/sysdeps/linux/arm/mmap.c ++++ b/libc/sysdeps/linux/arm/mmap.c +@@ -27,7 +27,6 @@ __ptr_t mmap(__ptr_t addr, size_t len, i + + #elif defined (__NR_mmap2) + #define __NR__mmap __NR_mmap2 +- + #ifndef MMAP2_PAGE_SHIFT + # define MMAP2_PAGE_SHIFT 12 + #endif +@@ -39,9 +38,17 @@ __ptr_t mmap(__ptr_t addr, size_t len, i + { + /* check if offset is page aligned */ + if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) ++ { ++ __set_errno(EINVAL); + return MAP_FAILED; ++ } ++#ifdef __USE_FILE_OFFSET64 ++ return (__ptr_t) _mmap (addr, len, prot, flags, ++ fd,((__u_quad_t) offset >> MMAP2_PAGE_SHIFT)); ++#else + return (__ptr_t) _mmap (addr, len, prot, flags, +- fd,(off_t) (offset >> MMAP2_PAGE_SHIFT)); ++ fd,((__u_long) offset >> MMAP2_PAGE_SHIFT)); ++#endif + } + #elif defined (__NR_mmap) + # define __NR__mmap __NR_mmap +--- a/libc/sysdeps/linux/common/mmap64.c ++++ b/libc/sysdeps/linux/common/mmap64.c +@@ -58,8 +58,13 @@ __ptr_t mmap64(__ptr_t addr, size_t len, + __set_errno(EINVAL); + return MAP_FAILED; + } +- +- return __syscall_mmap2(addr, len, prot, flags, fd, (off_t) (offset >> MMAP2_PAGE_SHIFT)); ++#ifdef __USE_FILE_OFFSET64 ++ return __syscall_mmap2(addr, len, prot, flags, ++ fd,((__u_quad_t)offset >> MMAP2_PAGE_SHIFT)); ++#else ++ return __syscall_mmap2(addr, len, prot, flags, ++ fd,((__u_long)offset >> MMAP2_PAGE_SHIFT)); ++#endif + } + + # endif |