git: mmap - honour hint address (properly) even if randomization is on
lhmwzy
lhmwzy at gmail.com
Sat Feb 15 01:39:38 PST 2014
I modify Luajit 2.0.2 as following and luajit works like a charm.
--- lj_arch.h.ori 2014-02-15 15:31:02.455765000 +0000
+++ lj_arch.h 2014-02-15 15:31:39.595775000 +0000
@@ -67,7 +67,7 @@
#elif defined(__MACH__) && defined(__APPLE__)
#define LUAJIT_OS LUAJIT_OS_OSX
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
- defined(__NetBSD__) || defined(__OpenBSD__)
+ defined(__NetBSD__) || defined(__OpenBSD__)|| defined(__DragonFly__)
#define LUAJIT_OS LUAJIT_OS_BSD
#elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__)
#define LUAJIT_OS LUAJIT_OS_POSIX
-#elif LJ_TARGET_OSX || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|| defined(__OpenBSD__) || defined(__sun__)
+#elif LJ_TARGET_OSX || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|| defined(__OpenBSD__) || defined(__sun__)|| defined(__DragonFly__)
/* OSX and FreeBSD mmap() use a naive first-fit linear search.
** That's perfect for us. Except that -pagezero_size must be set for OSX,
@@ -197,6 +197,8 @@
*/
#if LJ_TARGET_OSX
#define MMAP_REGION_START ((uintptr_t)0x10000)
+#elif defined(__DragonFly__)
+#define MMAP_REGION_START ((uintptr_t)0x10000)
#else
#define MMAP_REGION_START ((uintptr_t)0x10000000)
#endif
2014-02-15 15:36 GMT+08:00 lhmwzy <lhmwzy at gmail.com>:
> The John Marino'patch was following:
>
>
> --- lj_arch.h.org 2014-02-14 16:32:03.125932000 +0000
> +++ lj_arch.h 2014-02-14 16:32:34.725951000 +0000
>
>
> @@ -67,7 +67,7 @@
> #elif defined(__MACH__) && defined(__APPLE__)
> #define LUAJIT_OS LUAJIT_OS_OSX
> #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
> - defined(__NetBSD__) || defined(__OpenBSD__)
> + defined(__NetBSD__) || defined(__OpenBSD__)|| defined(__DragonFly__)
>
> #define LUAJIT_OS LUAJIT_OS_BSD
> #elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__)
> #define LUAJIT_OS LUAJIT_OS_POSIX
>
> --- lj_alloc.c.org 2014-02-14 16:33:19.015979000 +0000
> +++ lj_alloc.c 2014-02-14 16:32:50.225961000 +0000
> @@ -188,6 +188,33 @@
> return ptr;
> }
>
> +#elif defined(__DragonFly__)
> +
> +#define MMAP_REGION_START ((uintptr_t)0x1000)
> +#define MMAP_REGION_END ((uintptr_t)0x80000000)
> +
> +static LJ_AINLINE void *CALL_MMAP(size_t size)
> +{
> + int olderr = errno;
> + /* Hint for next allocation. Doesn't need to be thread-safe. */
> + static uintptr_t alloc_hint = MMAP_REGION_START;
> + int retry = 0;
> + for (;;) {
> + void *p = mmap((void *)alloc_hint, size, MMAP_PROT, MMAP_FLAGS, -1, 0);
> + if ((uintptr_t)p >= 0 && (uintptr_t)p + size < MMAP_REGION_END) {
> + alloc_hint = (uintptr_t)p + size;
> + errno = olderr;
> + return p;
> + }
> + if (p != CMFAIL) munmap(p, size);
> + if (retry) break;
> + retry = 1;
> + alloc_hint += 0x100000;
> + }
> + errno = olderr;
> + return CMFAIL;
> +}
> +
>
>
> 2014-02-15 15:34 GMT+08:00 lhmwzy <lhmwzy at gmail.com>:
>
> Here is the modify
>>
>> --- lj_arch.h 2014-02-15 15:31:39.595775000 +0000
>> +++ lj_arch.h.ori 2014-02-15 15:31:02.455765000 +0000
>> @@ -67,7 +67,7 @@
>> #elif defined(__MACH__) && defined(__APPLE__)
>> #define LUAJIT_OS LUAJIT_OS_OSX
>> #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
>> - defined(__NetBSD__) || defined(__OpenBSD__)||
>> defined(__DragonFly__)
>> + defined(__NetBSD__) || defined(__OpenBSD__)
>> #define LUAJIT_OS LUAJIT_OS_BSD
>> #elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__)
>> #define LUAJIT_OS LUAJIT_OS_POSIX
>>
>> --- lj_alloc.c 2014-02-15 15:32:47.735793000 +0000
>> +++ lj_alloc.c.ori 2014-02-15 15:31:12.435768000 +0000
>> @@ -188,7 +188,7 @@
>> return ptr;
>> }
>>
>> -#elif LJ_TARGET_OSX || defined(__FreeBSD__) ||
>> defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__sun__)||
>> defined(__DragonFly__)
>> +#elif LJ_TARGET_OSX || defined(__FreeBSD__) ||
>> defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__sun__)
>>
>> /* OSX and FreeBSD mmap() use a naive first-fit linear search.
>> ** That's perfect for us. Except that -pagezero_size must be set for OSX,
>> @@ -202,7 +202,7 @@
>> #endif
>> #define MMAP_REGION_END ((uintptr_t)0x80000000)
>>
>> -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)||
>> defined(__DragonFly__)
>> +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
>> #include <sys/resource.h>
>> #endif
>>
>> @@ -212,7 +212,7 @@
>> /* Hint for next allocation. Doesn't need to be thread-safe. */
>> static uintptr_t alloc_hint = MMAP_REGION_START;
>> int retry = 0;
>> -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)||
>> defined(__DragonFly__)
>> +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
>> static int rlimit_modified = 0;
>> if (LJ_UNLIKELY(rlimit_modified == 0)) {
>> struct rlimit rlim;
>>
>> When make completed,run luajit
>> ./luajit
>> ./luajit: cannot create state: not enough memory
>>
>> kdump result:
>> kdump
>> 2424 ktrace RET ktrace 0
>> 2424 ktrace CALL execve(0x7ffffffffb97,0x7ffffffff948,0x7ffffffff958)
>> 2424 ktrace NAMI "./luajit"
>> 2424 ktrace NAMI "/usr/libexec/ld-elf.so.2"
>> 2424 luajit RET execve 0
>> 2424 luajit CALL
>> __sysctl(0x7fffffffefe0,0x2,0x800897b60,0x7fffffffefd8,0,0)
>> 2424 luajit RET __sysctl 0
>> 2424 luajit CALL
>> mmap(0,0x8000,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,0xffffffff,0,0)
>> 2424 luajit RET mmap 6901760/0x695000
>> 2424 luajit CALL issetugid
>> 2424 luajit RET issetugid 0
>> 2424 luajit CALL lstat(0x80069a000,0x7fffffffeef0)
>> 2424 luajit NAMI "/etc"
>> 2424 luajit RET lstat 0
>> 2424 luajit CALL lstat(0x80069a000,0x7fffffffeef0)
>> 2424 luajit NAMI "/etc/libmap.conf"
>> 2424 luajit RET lstat -1 errno 2 No such file or directory
>> 2424 luajit CALL open(0x80069a000,O_CLOEXEC,<unused>0)
>> 2424 luajit NAMI "/etc/libmap.conf"
>> 2424 luajit RET open -1 errno 2 No such file or directory
>> 2424 luajit CALL access(0x80069a000,F_OK)
>> 2424 luajit NAMI "/usr/lib/gcc47/libm.so.4"
>> 2424 luajit RET access -1 errno 2 No such file or directory
>> 2424 luajit CALL open(0x80068c906,O_CLOEXEC,<unused>0x8)
>> 2424 luajit NAMI "/var/run/ld-elf.so.hints"
>> 2424 luajit RET open 3
>> 2424 luajit CALL read(0x3,0x7fffffffed60,0x80)
>> 2424 luajit GIO fd 3 read 128 bytes
>>
>> "Ehnt\^A\0\0\0\M^@\0\0\0>\0\0\0\0\0\0\0=\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
>> \0\0\0\0\0\0\0"
>> 2424 luajit RET read 128/0x80
>> 2424 luajit CALL lseek(0x3,0,0x80,SEEK_SET)
>> 2424 luajit RET lseek 128/0x80
>> 2424 luajit CALL read(0x3,0x800697180,0x3e)
>> 2424 luajit GIO fd 3 read 62 bytes
>> "/usr/lib:/usr/lib/compat:/usr/local/lib:/usr/local/lib/event2\0"
>> 2424 luajit RET read 62/0x3e
>> 2424 luajit CALL close(0x3)
>> 2424 luajit RET close 0
>> 2424 luajit CALL access(0x80069a000,F_OK)
>> 2424 luajit NAMI "/usr/lib/libm.so.4"
>> 2424 luajit RET access 0
>> 2424 luajit CALL open(0x800699040,O_CLOEXEC,<unused>0x8)
>> 2424 luajit NAMI "/usr/lib/libm.so.4"
>> 2424 luajit RET open 3
>> 2424 luajit CALL fstat(0x3,0x7fffffffef70)
>> 2424 luajit RET fstat 0
>> 2424 luajit CALL mmap(0,0x1000,PROT_READ,MAP_PRIVATE,0x3,0,0)
>> 2424 luajit RET mmap 6934528/0x69d000
>> 2424 luajit CALL
>> mmap(0,0x22a000,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,0xffffffff,0,0)
>> 2424 luajit RET mmap 9027584/0x89c000
>> 2424 luajit CALL
>> mmap(0x80089c000,0x2a000,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE,0x3,0,0)
>> 2424 luajit RET mmap 9027584/0x89c000
>> 2424 luajit CALL
>> mmap(0x800ac5000,0x1000,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,0x3,0,0x29000)
>> 2424 luajit RET mmap 11292672/0xac5000
>> 2424 luajit CALL munmap(0x80069d000,0x1000)
>> 2424 luajit RET munmap 0
>> 2424 luajit CALL close(0x3)
>> 2424 luajit RET close 0
>> 2424 luajit CALL access(0x80069a000,F_OK)
>> 2424 luajit NAMI "/usr/lib/gcc47/libc.so.8"
>> 2424 luajit RET access -1 errno 2 No such file or directory
>> 2424 luajit CALL access(0x80069a000,F_OK)
>> 2424 luajit NAMI "/usr/lib/libc.so.8"
>> 2424 luajit RET access 0
>> 2424 luajit CALL open(0x800699080,O_CLOEXEC,<unused>0x8)
>> 2424 luajit NAMI "/usr/lib/libc.so.8"
>> 2424 luajit RET open 3
>> 2424 luajit CALL fstat(0x3,0x7fffffffef70)
>> 2424 luajit RET fstat 0
>> 2424 luajit CALL mmap(0,0x1000,PROT_READ,MAP_PRIVATE,0x3,0,0)
>> 2424 luajit RET mmap 6934528/0x69d000
>> 2424 luajit CALL
>> mmap(0,0x34e000,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,0xffffffff,0,0)
>> 2424 luajit RET mmap 11296768/0xac6000
>> 2424 luajit CALL
>> mmap(0x800ac6000,0x123000,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE,0x3,0,0)
>> 2424 luajit RET mmap 11296768/0xac6000
>> 2424 luajit CALL
>> mmap(0x800de9000,0xc000,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,0x3,0,0x123000)
>> 2424 luajit RET mmap 14585856/0xde9000
>> 2424 luajit CALL
>> mmap(0x800df5000,0x1f000,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,0xffffffff,0,0)
>> 2424 luajit RET mmap 14635008/0xdf5000
>> 2424 luajit CALL munmap(0x80069d000,0x1000)
>> 2424 luajit RET munmap 0
>> 2424 luajit CALL close(0x3)
>> 2424 luajit RET close 0
>> 2424 luajit CALL
>> mmap(0,0x19000,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,0xffffffff,0x800000000,0)
>> 2424 luajit RET mmap 6934528/0x69d000
>> 2424 luajit CALL sigprocmask(SIG_BLOCK,0x800897a10,0x7ffffffff880)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_SETMASK,0x800897a30,0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL set_tls_area(0,0x7ffffffff960,0x10)
>> 2424 luajit RET set_tls_area 0
>> 2424 luajit CALL sigprocmask(SIG_BLOCK,0x800897a10,0x7ffffffff8b0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_SETMASK,0x800897a30,0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL issetugid
>> 2424 luajit RET issetugid 0
>> 2424 luajit CALL open(0x800bbf388,O_RDONLY,<unused>0xfffffffffffffff7)
>> 2424 luajit NAMI "/dev/urandom"
>> 2424 luajit RET open 3
>> 2424 luajit CALL read(0x3,0x800df5ea0,0x40)
>> 2424 luajit GIO fd 3 read 64 bytes
>>
>> "Sk\M-X\M-vH\M-s\r\M-y\b1C?\M^JeWt\M-Sq\M-L,\M-w:P\M-*\^U\M^Q$\M-uV/\M^@\M-+q\M-\\M^Z\^]\M^W?\\_1\M-d^\M-S\^C\^R\
>> f\M-3[\M-%\M^OE\^R\M-h\M-T\M-A\M-NBm+\M-kX\M^Ym"
>> 2424 luajit RET read 64/0x40
>> 2424 luajit CALL close(0x3)
>> 2424 luajit RET close 0
>> 2424 luajit CALL sigprocmask(SIG_BLOCK,0x800897a10,0x7ffffffff870)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_SETMASK,0x800897a30,0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_BLOCK,0x800897a10,0x7ffffffff870)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_SETMASK,0x800897a30,0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_BLOCK,0x800897a10,0x7ffffffff870)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_SETMASK,0x800897a30,0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL setrlimit(RLIMIT_DATA,0x7ffffffff910)
>> 2424 luajit RET setrlimit 0
>> 2424 luajit CALL
>> mmap(0x10000000,0x20000,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,0xffffffff,0,0)
>> 2424 luajit RET mmap 7036928/0x6b6000
>> 2424 luajit CALL munmap(0x8006b6000,0x20000)
>> 2424 luajit RET munmap 0
>> 2424 luajit CALL
>> mmap(0x10000000,0x20000,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,0xffffffff,0,0)
>> 2424 luajit RET mmap 7036928/0x6b6000
>> 2424 luajit CALL munmap(0x8006b6000,0x20000)
>> 2424 luajit RET munmap 0
>> 2424 luajit CALL write(0x2,0x7ffffffff230,0xa)
>> 2424 luajit GIO fd 2 wrote 10 bytes
>> "./luajit: "
>> 2424 luajit RET write 10/0xa
>> 2424 luajit CALL write(0x2,0x7ffffffff230,0x27)
>> 2424 luajit GIO fd 2 wrote 39 bytes
>> "cannot create state: not enough memory
>> "
>> 2424 luajit RET write 39/0x27
>> 2424 luajit CALL sigprocmask(SIG_BLOCK,0x800897a10,0x7ffffffff820)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_SETMASK,0x800897a30,0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_BLOCK,0x800897a10,0x7ffffffff7c0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_SETMASK,0x800897a30,0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_BLOCK,0x800897a10,0x7ffffffff7c0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_SETMASK,0x800897a30,0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_BLOCK,0x800897a10,0x7ffffffff7c0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL sigprocmask(SIG_SETMASK,0x800897a30,0)
>> 2424 luajit RET sigprocmask 0
>> 2424 luajit CALL exit(0x1)
>>
>>
>>
>>
>> 2014-02-15 15:26 GMT+08:00 Alex Hornung <alex at alexhornung.com>:
>>
>> On 15/02/14 07:24, lhmwzy wrote:
>>>
>>> I make buildworld and make kernel after your fix
>>> But the luajit won't work unless use John Marino'patch
>>>
>>> What does 'doesn't work' mean? You still need to add a ||
>>> defined(__DragonFly__) if you don't use marino's patch. That should then
>>> build and work fine.
>>>
>>> Cheers,
>>> Alex
>>>
>>>
>>>
>>>
>>> 2014-02-15 15:21 GMT+08:00 Alex Hornung <alex at alexhornung.com>:
>>>
>>>>
>>>> On 15/02/14 02:07, lhmwzy wrote:
>>>>
>>>> To use this fix
>>>> buildworld or buildkernel is needed?
>>>>
>>>>
>>>> You need to rebuild the kernel for this to work.
>>>>
>>>>
>>>>
>>>>
>>>> 2014-02-15 4:59 GMT+08:00 Alex Hornung <alexh at crater.dragonflybsd.org>:
>>>>
>>>>>
>>>>> commit d9c783bb278bae8373395931126396bb6d6cdd71
>>>>> Author: Alex Hornung <alex at alexhornung.com>
>>>>> Date: Fri Feb 14 20:57:16 2014 +0000
>>>>>
>>>>> mmap - honour hint address (properly) even if randomization is on
>>>>>
>>>>> Summary of changes:
>>>>> sys/vm/vm_map.c | 5 +----
>>>>> 1 file changed, 1 insertion(+), 4 deletions(-)
>>>>>
>>>>>
>>>>> http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/d9c783bb278bae8373395931126396bb6d6cdd71
>>>>>
>>>>>
>>>>> --
>>>>> DragonFly BSD source repository
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dragonflybsd.org/pipermail/commits/attachments/20140215/47feb6d7/attachment-0002.html>
More information about the Commits
mailing list