[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#861291: marked as done (RFS: luajit/2.1.0~beta2+dfsg-3.1 -- [NMU,RC/experimental])



Your message dated Mon, 8 May 2017 11:01:50 +0000 (UTC)
with message-id <1371357977.8706630.1494241310068@mail.yahoo.com>
and subject line Re: Bug#861291: Fwd: RFS: luajit/2.1.0~beta2+dfsg-3.1 -- [NMU,RC/experimental]
has caused the Debian Bug report #861291,
regarding RFS: luajit/2.1.0~beta2+dfsg-3.1 -- [NMU,RC/experimental]
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
861291: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=861291
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Package: sponsorship-requests
Severity: important
X-Debbugs-CC: 818616@bugs.debian.org, wookey@wookware.org,
dannf@dannf.org, gareuselesinge@debian.org

NOTE: not approved by maintainer (Enrico Tassi) yet.

  Dear mentors,

  I am looking for a sponsor for my package "luajit"

 * Package name    : luajit
   Version         : 2.1.0~beta2+dfsg-3.1
   Upstream Author : [fill in name and email of upstream]
 * URL             : [fill in URL of upstreams web site]
 * License         : [fill in]
   Section         : interpreters

  It builds those binary packages:

    libluajit-5.1-2 - Just in time compiler for Lua - library version
 libluajit-5.1-common - Just in time compiler for Lua - common files
 libluajit-5.1-dev - Just in time compiler for Lua - development files
 luajit     - Just in time compiler for Lua programming language version 5.1

  To access further information about this package, please visit the
following URL:

  https://mentors.debian.net/package/luajit


  Alternatively, one can download the package with dget using this command:

    dget -x https://mentors.debian.net/debian/pool/main/l/luajit/luajit_2.1.0~beta2+dfsg-3.1.dsc

  More information about hello can be obtained from https://www.example.com.

luajit (2.1.0~beta2+dfsg-3.1) experimental; urgency=medium

  * Non-maintainer upload.
  * Add patch Rewrite-memory-block-allocator.patch to fix arm64 segfault.
    (Thanks to dann frazier <dannf@dannf.org> for verifying the patch)
    (Closes: #818616)
  * Bump debhelper compat to 10.
  * Bump Standards Version to 3.9.8 .
  * Fix misspelled-closes-bug #789321 in previous changelog.
  * Fix not-binnmuable-any-depends-any: source:Version -> binary:Version .
  * Build-Depends on debhelper (>= 10~).

Git-formatted patches are attached.
From d41b841dcb96274c39ee6da7ef1ebd3cb5df76e2 Mon Sep 17 00:00:00 2001
From: Zhou Mo <cdluminate@gmail.com>
Date: Thu, 27 Apr 2017 02:40:00 +0000
Subject: [PATCH 1/7] patches: close 818616

---
 debian/changelog                                   |   9 +
 .../0005-rewrite-memory-block-allocator.patch      | 388 +++++++++++++++++++++
 debian/patches/series                              |   1 +
 3 files changed, 398 insertions(+)
 create mode 100644 debian/patches/0005-rewrite-memory-block-allocator.patch

diff --git a/debian/changelog b/debian/changelog
index 9c053c9..17f5abe 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+luajit (2.1.0~beta2+dfsg-3.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Add patch Rewrite-memory-block-allocator.patch to fix arm64 segfault.
+    (Thanks to dann frazier <dannf@dannf.org> for verifying the patch)
+    (Closes: #818616)
+
+ -- Zhou Mo <cdluminate@gmail.com>  Thu, 27 Apr 2017 02:28:26 +0000
+
 luajit (2.1.0~beta2+dfsg-3) experimental; urgency=medium
 
   * Add ppc64el to Architecture: field in the packages, so ppc64el
diff --git a/debian/patches/0005-rewrite-memory-block-allocator.patch b/debian/patches/0005-rewrite-memory-block-allocator.patch
new file mode 100644
index 0000000..a3caa2b
--- /dev/null
+++ b/debian/patches/0005-rewrite-memory-block-allocator.patch
@@ -0,0 +1,388 @@
+From: Mike Pall <mike>
+Date: Mon, 18 Apr 2016 10:57:49 +0200
+Subject: [PATCH] Rewrite memory block allocator.
+
+Use a mix of linear probing and pseudo-random probing.
+Workaround for 1GB MAP_32BIT limit on Linux/x64. Now 2GB with !LJ_GC64.
+Enforce 128TB LJ_GC64 limit for > 47 bit memory layouts (ARM64).
+
+Origin: backported, https://github.com/LuaJIT/LuaJIT/commit/0c6fdc1039a3a4450d366fba7af4b29de73f0dc6
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818616
+Last-Updated: 2016-06-06
+
+Index: luajit-2.1.0~beta2+dfsg/src/lj_alloc.c
+===================================================================
+--- luajit-2.1.0~beta2+dfsg.orig/src/lj_alloc.c
++++ luajit-2.1.0~beta2+dfsg/src/lj_alloc.c
+@@ -72,13 +72,56 @@
+ 
+ #define IS_DIRECT_BIT		(SIZE_T_ONE)
+ 
++
++/* Determine system-specific block allocation method. */
+ #if LJ_TARGET_WINDOWS
+ 
+ #define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
+ 
++#define LJ_ALLOC_VIRTUALALLOC	1
++
+ #if LJ_64 && !LJ_GC64
++#define LJ_ALLOC_NTAVM		1
++#endif
++
++#else
++
++#include <errno.h>
++/* If this include fails, then rebuild with: -DLUAJIT_USE_SYSMALLOC */
++#include <sys/mman.h>
++
++#define LJ_ALLOC_MMAP		1
++
++#if LJ_64
++
++#define LJ_ALLOC_MMAP_PROBE	1
++
++#if LJ_GC64
++#define LJ_ALLOC_MBITS		47	/* 128 TB in LJ_GC64 mode. */
++#elif LJ_TARGET_X64 && LJ_HASJIT
++/* Due to limitations in the x64 compiler backend. */
++#define LJ_ALLOC_MBITS		31	/* 2 GB on x64 with !LJ_GC64. */
++#else
++#define LJ_ALLOC_MBITS		32	/* 4 GB on other archs with !LJ_GC64. */
++#endif
++
++#endif
++
++#if LJ_64 && !LJ_GC64 && defined(MAP_32BIT)
++#define LJ_ALLOC_MMAP32		1
++#endif
++
++#if LJ_TARGET_LINUX
++#define LJ_ALLOC_MREMAP		1
++#endif
++
++#endif
+ 
++
++#if LJ_ALLOC_VIRTUALALLOC
++
++#if LJ_ALLOC_NTAVM
+ /* Undocumented, but hey, that's what we all love so much about Windows. */
+ typedef long (*PNTAVM)(HANDLE handle, void **addr, ULONG zbits,
+ 		       size_t *size, ULONG alloctype, ULONG prot);
+@@ -89,14 +132,15 @@ static PNTAVM ntavm;
+ */
+ #define NTAVM_ZEROBITS		1
+ 
+-static void INIT_MMAP(void)
++static void init_mmap(void)
+ {
+   ntavm = (PNTAVM)GetProcAddress(GetModuleHandleA("ntdll.dll"),
+ 				 "NtAllocateVirtualMemory");
+ }
++#define INIT_MMAP()	init_mmap()
+ 
+ /* Win64 32 bit MMAP via NtAllocateVirtualMemory. */
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
++static void *CALL_MMAP(size_t size)
+ {
+   DWORD olderr = GetLastError();
+   void *ptr = NULL;
+@@ -107,7 +151,7 @@ static LJ_AINLINE void *CALL_MMAP(size_t
+ }
+ 
+ /* For direct MMAP, use MEM_TOP_DOWN to minimize interference */
+-static LJ_AINLINE void *DIRECT_MMAP(size_t size)
++static void *DIRECT_MMAP(size_t size)
+ {
+   DWORD olderr = GetLastError();
+   void *ptr = NULL;
+@@ -119,10 +163,8 @@ static LJ_AINLINE void *DIRECT_MMAP(size
+ 
+ #else
+ 
+-#define INIT_MMAP()		((void)0)
+-
+ /* Win32 MMAP via VirtualAlloc */
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
++static void *CALL_MMAP(size_t size)
+ {
+   DWORD olderr = GetLastError();
+   void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
+@@ -131,7 +173,7 @@ static LJ_AINLINE void *CALL_MMAP(size_t
+ }
+ 
+ /* For direct MMAP, use MEM_TOP_DOWN to minimize interference */
+-static LJ_AINLINE void *DIRECT_MMAP(size_t size)
++static void *DIRECT_MMAP(size_t size)
+ {
+   DWORD olderr = GetLastError();
+   void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,
+@@ -143,7 +185,7 @@ static LJ_AINLINE void *DIRECT_MMAP(size
+ #endif
+ 
+ /* This function supports releasing coalesed segments */
+-static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)
++static int CALL_MUNMAP(void *ptr, size_t size)
+ {
+   DWORD olderr = GetLastError();
+   MEMORY_BASIC_INFORMATION minfo;
+@@ -163,10 +205,7 @@ static LJ_AINLINE int CALL_MUNMAP(void *
+   return 0;
+ }
+ 
+-#else
+-
+-#include <errno.h>
+-#include <sys/mman.h>
++#elif LJ_ALLOC_MMAP
+ 
+ #define MMAP_PROT		(PROT_READ|PROT_WRITE)
+ #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
+@@ -174,107 +213,145 @@ static LJ_AINLINE int CALL_MUNMAP(void *
+ #endif
+ #define MMAP_FLAGS		(MAP_PRIVATE|MAP_ANONYMOUS)
+ 
+-#if LJ_64 && !LJ_GC64
+-/* 64 bit mode with 32 bit pointers needs special support for allocating
+-** memory in the lower 2GB.
+-*/
+-
+-#if defined(MAP_32BIT)
++#if LJ_ALLOC_MMAP_PROBE
+ 
+-#if defined(__sun__)
+-#define MMAP_REGION_START	((uintptr_t)0x1000)
+-#else
+-/* Actually this only gives us max. 1GB in current Linux kernels. */
+-#define MMAP_REGION_START	((uintptr_t)0)
+-#endif
++#define LJ_ALLOC_MMAP_PROBE_MAX		30
++#define LJ_ALLOC_MMAP_PROBE_LINEAR	5
+ 
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
+-{
+-  int olderr = errno;
+-  void *ptr = mmap((void *)MMAP_REGION_START, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0);
+-  errno = olderr;
+-  return ptr;
+-}
+-
+-#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun__) || defined(__CYGWIN__)
++#define LJ_ALLOC_MMAP_PROBE_LOWER	((uintptr_t)0x4000)
+ 
+-/* 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,
+-** otherwise the lower 4GB are blocked. And the 32GB RLIMIT_DATA needs
+-** to be reduced to 250MB on FreeBSD.
++/* No point in a giant ifdef mess. Just try to open /dev/urandom.
++** It doesn't really matter if this fails, since we get some ASLR bits from
++** every unsuitable allocation, too. And we prefer linear allocation, anyway.
+ */
+-#if LJ_TARGET_OSX || defined(__DragonFly__)
+-#define MMAP_REGION_START	((uintptr_t)0x10000)
+-#elif LJ_TARGET_PS4
+-#define MMAP_REGION_START	((uintptr_t)0x4000)
+-#else
+-#define MMAP_REGION_START	((uintptr_t)0x10000000)
+-#endif
+-#define MMAP_REGION_END		((uintptr_t)0x80000000)
++#include <fcntl.h>
++#include <unistd.h>
+ 
+-#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
+-#include <sys/resource.h>
+-#endif
++static uintptr_t mmap_probe_seed(void)
++{
++  uintptr_t val;
++  int fd = open("/dev/urandom", O_RDONLY);
++  if (fd != -1) {
++    int ok = ((size_t)read(fd, &val, sizeof(val)) == sizeof(val));
++    (void)close(fd);
++    if (ok) return val;
++  }
++  return 1;  /* Punt. */
++}
+ 
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
++static void *mmap_probe(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;
+-#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
+-  static int rlimit_modified = 0;
+-  if (LJ_UNLIKELY(rlimit_modified == 0)) {
+-    struct rlimit rlim;
+-    rlim.rlim_cur = rlim.rlim_max = MMAP_REGION_START;
+-    setrlimit(RLIMIT_DATA, &rlim);  /* Ignore result. May fail below. */
+-    rlimit_modified = 1;
+-  }
+-#endif
+-  for (;;) {
+-    void *p = mmap((void *)alloc_hint, size, MMAP_PROT, MMAP_FLAGS, -1, 0);
+-    if ((uintptr_t)p >= MMAP_REGION_START &&
+-	(uintptr_t)p + size < MMAP_REGION_END) {
+-      alloc_hint = (uintptr_t)p + size;
++  static uintptr_t hint_addr = 0;
++  static uintptr_t hint_prng = 0;
++  int olderr = errno;
++  int retry;
++  for (retry = 0; retry < LJ_ALLOC_MMAP_PROBE_MAX; retry++) {
++    void *p = mmap((void *)hint_addr, size, MMAP_PROT, MMAP_FLAGS, -1, 0);
++    uintptr_t addr = (uintptr_t)p;
++    if ((addr >> LJ_ALLOC_MBITS) == 0 && addr >= LJ_ALLOC_MMAP_PROBE_LOWER) {
++      /* We got a suitable address. Bump the hint address. */
++      hint_addr = addr + size;
+       errno = olderr;
+       return p;
+     }
+-    if (p != CMFAIL) munmap(p, size);
+-#if defined(__sun__) || defined(__DragonFly__)
+-    alloc_hint += 0x1000000;  /* Need near-exhaustive linear scan. */
+-    if (alloc_hint + size < MMAP_REGION_END) continue;
+-#endif
+-    if (retry) break;
+-    retry = 1;
+-    alloc_hint = MMAP_REGION_START;
++    if (p != MFAIL) {
++      munmap(p, size);
++    } else if (errno == ENOMEM) {
++      return MFAIL;
++    }
++    if (hint_addr) {
++      /* First, try linear probing. */
++      if (retry < LJ_ALLOC_MMAP_PROBE_LINEAR) {
++	hint_addr += 0x1000000;
++	if (((hint_addr + size) >> LJ_ALLOC_MBITS) != 0)
++	  hint_addr = 0;
++	continue;
++      } else if (retry == LJ_ALLOC_MMAP_PROBE_LINEAR) {
++	/* Next, try a no-hint probe to get back an ASLR address. */
++	hint_addr = 0;
++	continue;
++      }
++    }
++    /* Finally, try pseudo-random probing. */
++    if (LJ_UNLIKELY(hint_prng == 0)) {
++      hint_prng = mmap_probe_seed();
++    }
++    /* The unsuitable address we got has some ASLR PRNG bits. */
++    hint_addr ^= addr & ~((uintptr_t)(LJ_PAGESIZE-1));
++    do {  /* The PRNG itself is very weak, but see above. */
++      hint_prng = hint_prng * 1103515245 + 12345;
++      hint_addr ^= hint_prng * (uintptr_t)LJ_PAGESIZE;
++      hint_addr &= (((uintptr_t)1 << LJ_ALLOC_MBITS)-1);
++    } while (hint_addr < LJ_ALLOC_MMAP_PROBE_LOWER);
+   }
+   errno = olderr;
+-  return CMFAIL;
++  return MFAIL;
+ }
+ 
++#endif
++
++#if LJ_ALLOC_MMAP32
++
++#if defined(__sun__)
++#define LJ_ALLOC_MMAP32_START	((uintptr_t)0x1000)
+ #else
++#define LJ_ALLOC_MMAP32_START	((uintptr_t)0)
++#endif
+ 
+-#error "NYI: need an equivalent of MAP_32BIT for this 64 bit OS"
++static void *mmap_map32(size_t size)
++{
++#if LJ_ALLOC_MMAP_PROBE
++  static int fallback = 0;
++  if (fallback)
++    return mmap_probe(size);
++#endif
++  {
++    int olderr = errno;
++    void *ptr = mmap((void *)LJ_ALLOC_MMAP32_START, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0);
++    errno = olderr;
++    /* This only allows 1GB on Linux. So fallback to probing to get 2GB. */
++#if LJ_ALLOC_MMAP_PROBE
++    if (ptr == MFAIL) {
++      fallback = 1;
++      return mmap_probe(size);
++    }
++#endif
++    return ptr;
++  }
++}
+ 
+ #endif
+ 
++#if LJ_ALLOC_MMAP32
++#define CALL_MMAP(size)		mmap_map32(size)
++#elif LJ_ALLOC_MMAP_PROBE
++#define CALL_MMAP(size)		mmap_probe(size)
+ #else
+-
+-/* 32 bit mode and GC64 mode is easy. */
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
++static void *CALL_MMAP(size_t size)
+ {
+   int olderr = errno;
+   void *ptr = mmap(NULL, size, MMAP_PROT, MMAP_FLAGS, -1, 0);
+   errno = olderr;
+   return ptr;
+ }
+-
+ #endif
+ 
+-#define INIT_MMAP()		((void)0)
+-#define DIRECT_MMAP(s)		CALL_MMAP(s)
++#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
++
++#include <sys/resource.h>
++
++static void init_mmap(void)
++{
++  struct rlimit rlim;
++  rlim.rlim_cur = rlim.rlim_max = 0x10000;
++  setrlimit(RLIMIT_DATA, &rlim);  /* Ignore result. May fail later. */
++}
++#define INIT_MMAP()	init_mmap()
++
++#endif
+ 
+-static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)
++static int CALL_MUNMAP(void *ptr, size_t size)
+ {
+   int olderr = errno;
+   int ret = munmap(ptr, size);
+@@ -282,10 +359,9 @@ static LJ_AINLINE int CALL_MUNMAP(void *
+   return ret;
+ }
+ 
+-#if LJ_TARGET_LINUX
++#if LJ_ALLOC_MREMAP
+ /* Need to define _GNU_SOURCE to get the mremap prototype. */
+-static LJ_AINLINE void *CALL_MREMAP_(void *ptr, size_t osz, size_t nsz,
+-				     int flags)
++static void *CALL_MREMAP_(void *ptr, size_t osz, size_t nsz, int flags)
+ {
+   int olderr = errno;
+   ptr = mremap(ptr, osz, nsz, flags);
+@@ -305,6 +381,15 @@ static LJ_AINLINE void *CALL_MREMAP_(voi
+ 
+ #endif
+ 
++
++#ifndef INIT_MMAP
++#define INIT_MMAP()		((void)0)
++#endif
++
++#ifndef DIRECT_MMAP
++#define DIRECT_MMAP(s)		CALL_MMAP(s)
++#endif
++
+ #ifndef CALL_MREMAP
+ #define CALL_MREMAP(addr, osz, nsz, mv) ((void)osz, MFAIL)
+ #endif
diff --git a/debian/patches/series b/debian/patches/series
index 2fbbdc6..cd3c0e9 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,4 @@
 0002-Enable-debugging-symbols-in-the-build.patch
 0003-Get-rid-of-LUAJIT_VERSION_SYM-that-changes-ABI-on-ev.patch
 0004-Add-ppc64-support-based-on-https-github.com-PPC64-Lu.patch
+0005-rewrite-memory-block-allocator.patch
-- 
2.11.0

From 36b548d993d06516b8d33eaef31803ed6f90559b Mon Sep 17 00:00:00 2001
From: Zhou Mo <cdluminate@gmail.com>
Date: Thu, 27 Apr 2017 02:40:36 +0000
Subject: [PATCH 2/7] dh: compat to 10

---
 debian/changelog | 1 +
 debian/compat    | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 17f5abe..084b1d9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,7 @@ luajit (2.1.0~beta2+dfsg-3.1) UNRELEASED; urgency=medium
   * Add patch Rewrite-memory-block-allocator.patch to fix arm64 segfault.
     (Thanks to dann frazier <dannf@dannf.org> for verifying the patch)
     (Closes: #818616)
+  * Bump debhelper compat to 10.
 
  -- Zhou Mo <cdluminate@gmail.com>  Thu, 27 Apr 2017 02:28:26 +0000
 
diff --git a/debian/compat b/debian/compat
index ec63514..f599e28 100644
--- a/debian/compat
+++ b/debian/compat
@@ -1 +1 @@
-9
+10
-- 
2.11.0

From 69ebd489311ff981626d4602259f611476740025 Mon Sep 17 00:00:00 2001
From: Zhou Mo <cdluminate@gmail.com>
Date: Thu, 27 Apr 2017 02:42:38 +0000
Subject: [PATCH 3/7] control: bump standards

---
 debian/changelog | 1 +
 debian/control   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 084b1d9..65edb3f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,7 @@ luajit (2.1.0~beta2+dfsg-3.1) UNRELEASED; urgency=medium
     (Thanks to dann frazier <dannf@dannf.org> for verifying the patch)
     (Closes: #818616)
   * Bump debhelper compat to 10.
+  * Bump Standards Version to 3.9.8 .
 
  -- Zhou Mo <cdluminate@gmail.com>  Thu, 27 Apr 2017 02:28:26 +0000
 
diff --git a/debian/control b/debian/control
index 75b9298..4c67c84 100644
--- a/debian/control
+++ b/debian/control
@@ -4,7 +4,7 @@ Priority: optional
 Maintainer: Enrico Tassi <gareuselesinge@debian.org>
 Uploaders: Ondřej Surý <ondrej@debian.org>
 Build-Depends: debhelper (>= 9~)
-Standards-Version: 3.9.7
+Standards-Version: 3.9.8
 Vcs-Git: git://anonscm.debian.org/pkg-lua/luajit.git
 Vcs-Browser: https://anonscm.debian.org/gitweb/?p=pkg-lua/luajit.git
 Homepage: http://luajit.org
-- 
2.11.0

From df01daa46b40ba459c797b859d4bdbc2685d88fb Mon Sep 17 00:00:00 2001
From: Zhou Mo <cdluminate@gmail.com>
Date: Thu, 27 Apr 2017 02:47:16 +0000
Subject: [PATCH 4/7] dch: fix misspelled-closes-bug

---
 debian/changelog | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 65edb3f..bdcc077 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,6 +6,7 @@ luajit (2.1.0~beta2+dfsg-3.1) UNRELEASED; urgency=medium
     (Closes: #818616)
   * Bump debhelper compat to 10.
   * Bump Standards Version to 3.9.8 .
+  * Fix misspelled-closes-bug #789321 in previous changelog.
 
  -- Zhou Mo <cdluminate@gmail.com>  Thu, 27 Apr 2017 02:28:26 +0000
 
@@ -71,7 +72,7 @@ luajit (2.1.0~beta1+dfsg-1) experimental; urgency=medium
 
 luajit (2.0.4+dfsg-1) unstable; urgency=medium
 
-  * New upstream release (Close: #789321)
+  * New upstream release (Closes: #789321)
   * Build on Hurd (Close: #712975)
 
  -- Enrico Tassi <gareuselesinge@debian.org>  Fri, 14 Aug 2015 16:40:52 +0200
-- 
2.11.0

From 53674f055dae00793636e91493f3ea795c7fa012 Mon Sep 17 00:00:00 2001
From: Zhou Mo <cdluminate@gmail.com>
Date: Thu, 27 Apr 2017 02:51:17 +0000
Subject: [PATCH 5/7] control: fix not-binmuable

---
 debian/changelog | 1 +
 debian/control   | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index bdcc077..41ec2e4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,7 @@ luajit (2.1.0~beta2+dfsg-3.1) UNRELEASED; urgency=medium
   * Bump debhelper compat to 10.
   * Bump Standards Version to 3.9.8 .
   * Fix misspelled-closes-bug #789321 in previous changelog.
+  * Fix not-binnmuable-any-depends-any: source:Version -> binary:Version .
 
  -- Zhou Mo <cdluminate@gmail.com>  Thu, 27 Apr 2017 02:28:26 +0000
 
diff --git a/debian/control b/debian/control
index 4c67c84..abf5ff5 100644
--- a/debian/control
+++ b/debian/control
@@ -14,7 +14,7 @@ Architecture: any
 Multi-Arch: foreign
 Pre-Depends: ${misc:Pre-Depends}
 Depends: libluajit-5.1-2 (= ${binary:Version}),
-         libluajit-5.1-common (= ${source:Version}),
+         libluajit-5.1-common (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
 Description: Just in time compiler for Lua programming language version 5.1
@@ -38,7 +38,7 @@ Package: libluajit-5.1-2
 Architecture: any-i386 any-amd64 arm64 armel armhf mips mipsel powerpc ppc64el
 Multi-Arch: same
 Pre-Depends: ${misc:Pre-Depends}
-Depends: libluajit-5.1-common (= ${source:Version}),
+Depends: libluajit-5.1-common (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
 Description: Just in time compiler for Lua - library version
-- 
2.11.0

From c46a1384e4f3646bf92b511db34db0697429884b Mon Sep 17 00:00:00 2001
From: Zhou Mo <cdluminate@gmail.com>
Date: Thu, 27 Apr 2017 02:51:38 +0000
Subject: [PATCH 6/7] dch: release to exp

---
 debian/changelog | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 41ec2e4..40eff64 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-luajit (2.1.0~beta2+dfsg-3.1) UNRELEASED; urgency=medium
+luajit (2.1.0~beta2+dfsg-3.1) experimental; urgency=medium
 
   * Non-maintainer upload.
   * Add patch Rewrite-memory-block-allocator.patch to fix arm64 segfault.
@@ -9,7 +9,7 @@ luajit (2.1.0~beta2+dfsg-3.1) UNRELEASED; urgency=medium
   * Fix misspelled-closes-bug #789321 in previous changelog.
   * Fix not-binnmuable-any-depends-any: source:Version -> binary:Version .
 
- -- Zhou Mo <cdluminate@gmail.com>  Thu, 27 Apr 2017 02:28:26 +0000
+ -- Zhou Mo <cdluminate@gmail.com>  Thu, 27 Apr 2017 02:51:26 +0000
 
 luajit (2.1.0~beta2+dfsg-3) experimental; urgency=medium
 
-- 
2.11.0

From 40709df3ec45c3c8fe314f5338847a3bb15f394e Mon Sep 17 00:00:00 2001
From: Zhou Mo <cdluminate@gmail.com>
Date: Thu, 27 Apr 2017 02:58:48 +0000
Subject: [PATCH 7/7] control: B-D on debhelper 10

---
 debian/changelog | 1 +
 debian/control   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 40eff64..26a5049 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -8,6 +8,7 @@ luajit (2.1.0~beta2+dfsg-3.1) experimental; urgency=medium
   * Bump Standards Version to 3.9.8 .
   * Fix misspelled-closes-bug #789321 in previous changelog.
   * Fix not-binnmuable-any-depends-any: source:Version -> binary:Version .
+  * Build-Depends on debhelper (>= 10~).
 
  -- Zhou Mo <cdluminate@gmail.com>  Thu, 27 Apr 2017 02:51:26 +0000
 
diff --git a/debian/control b/debian/control
index abf5ff5..1af74f4 100644
--- a/debian/control
+++ b/debian/control
@@ -3,7 +3,7 @@ Section: interpreters
 Priority: optional
 Maintainer: Enrico Tassi <gareuselesinge@debian.org>
 Uploaders: Ondřej Surý <ondrej@debian.org>
-Build-Depends: debhelper (>= 9~)
+Build-Depends: debhelper (>= 10~)
 Standards-Version: 3.9.8
 Vcs-Git: git://anonscm.debian.org/pkg-lua/luajit.git
 Vcs-Browser: https://anonscm.debian.org/gitweb/?p=pkg-lua/luajit.git
-- 
2.11.0


--- End Message ---
--- Begin Message ---
Hello,


>https://mentors.debian.net/debian/pool/main/l/luajit/luajit_2.1.0~beta2+dfsg-3.1.dsc


since changes are quite invasive, I sponsored it in deferred/15, I hope
maintainers will have enough time to react and look at it
(it is an experimental upload, so I hope nobody will complain for such changes).
In general please avoid doing useless changes for non-maintainer uploads,
and try to concentrate to fixing bugs (but when the works has been already done,
it is a shame to throw it out)


G.
diff --git a/debian/changelog b/debian/changelog
index 9c053c9..279770c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,19 @@
+luajit (2.1.0~beta2+dfsg-3.1) experimental; urgency=medium
+
+  * Non-maintainer upload.
+  * Add patch Rewrite-memory-block-allocator.patch to fix arm64 segfault.
+    (Thanks to dann frazier <dannf@dannf.org> for verifying the patch)
+    (Closes: #818616)
+  * Bump debhelper compat to 10.
+  * Bump Standards Version to 3.9.8 .
+  * Fix misspelled-closes-bug #789321 in previous changelog.
+  * Fix not-binnmuable-any-depends-any: source:Version -> binary:Version .
+  * Build-Depends on debhelper (>= 10~).
+  * Update Vcs-* links.
+  * Remove Pre-Depends: ${misc:Pre-Depends} from control file.
+
+ -- Zhou Mo <cdluminate@gmail.com>  Thu, 27 Apr 2017 02:51:26 +0000
+
 luajit (2.1.0~beta2+dfsg-3) experimental; urgency=medium
 
   * Add ppc64el to Architecture: field in the packages, so ppc64el
@@ -60,7 +76,7 @@ luajit (2.1.0~beta1+dfsg-1) experimental; urgency=medium
 
 luajit (2.0.4+dfsg-1) unstable; urgency=medium
 
-  * New upstream release (Close: #789321)
+  * New upstream release (Closes: #789321)
   * Build on Hurd (Close: #712975)
 
  -- Enrico Tassi <gareuselesinge@debian.org>  Fri, 14 Aug 2015 16:40:52 +0200
diff --git a/debian/compat b/debian/compat
index ec63514..f599e28 100644
--- a/debian/compat
+++ b/debian/compat
@@ -1 +1 @@
-9
+10
diff --git a/debian/control b/debian/control
index 75b9298..22e6b8f 100644
--- a/debian/control
+++ b/debian/control
@@ -3,18 +3,17 @@ Section: interpreters
 Priority: optional
 Maintainer: Enrico Tassi <gareuselesinge@debian.org>
 Uploaders: OndÅ?ej Surý <ondrej@debian.org>
-Build-Depends: debhelper (>= 9~)
-Standards-Version: 3.9.7
-Vcs-Git: git://anonscm.debian.org/pkg-lua/luajit.git
-Vcs-Browser: https://anonscm.debian.org/gitweb/?p=pkg-lua/luajit.git
+Build-Depends: debhelper (>= 10~)
+Standards-Version: 3.9.8
+Vcs-Git: https://anonscm.debian.org/git/pkg-lua/luajit.git
+Vcs-Browser: https://anonscm.debian.org/cgit/pkg-lua/luajit.git
 Homepage: http://luajit.org
 
 Package: luajit
 Architecture: any
 Multi-Arch: foreign
-Pre-Depends: ${misc:Pre-Depends}
 Depends: libluajit-5.1-2 (= ${binary:Version}),
-         libluajit-5.1-common (= ${source:Version}),
+         libluajit-5.1-common (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
 Description: Just in time compiler for Lua programming language version 5.1
@@ -37,8 +36,7 @@ Description: Just in time compiler for Lua - common files
 Package: libluajit-5.1-2
 Architecture: any-i386 any-amd64 arm64 armel armhf mips mipsel powerpc ppc64el
 Multi-Arch: same
-Pre-Depends: ${misc:Pre-Depends}
-Depends: libluajit-5.1-common (= ${source:Version}),
+Depends: libluajit-5.1-common (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
 Description: Just in time compiler for Lua - library version
@@ -52,7 +50,6 @@ Description: Just in time compiler for Lua - library version
 Package: libluajit-5.1-dev
 Section: libdevel
 Multi-Arch: same
-Pre-Depends: ${misc:Pre-Depends}
 Architecture: any-i386 any-amd64 arm64 armel armhf mips mipsel powerpc ppc64el
 Depends: libluajit-5.1-2 (= ${binary:Version}),
          ${misc:Depends},
diff --git a/debian/patches/0005-rewrite-memory-block-allocator.patch b/debian/patches/0005-rewrite-memory-block-allocator.patch
new file mode 100644
index 0000000..a3caa2b
--- /dev/null
+++ b/debian/patches/0005-rewrite-memory-block-allocator.patch
@@ -0,0 +1,388 @@
+From: Mike Pall <mike>
+Date: Mon, 18 Apr 2016 10:57:49 +0200
+Subject: [PATCH] Rewrite memory block allocator.
+
+Use a mix of linear probing and pseudo-random probing.
+Workaround for 1GB MAP_32BIT limit on Linux/x64. Now 2GB with !LJ_GC64.
+Enforce 128TB LJ_GC64 limit for > 47 bit memory layouts (ARM64).
+
+Origin: backported, https://github.com/LuaJIT/LuaJIT/commit/0c6fdc1039a3a4450d366fba7af4b29de73f0dc6
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818616
+Last-Updated: 2016-06-06
+
+Index: luajit-2.1.0~beta2+dfsg/src/lj_alloc.c
+===================================================================
+--- luajit-2.1.0~beta2+dfsg.orig/src/lj_alloc.c
++++ luajit-2.1.0~beta2+dfsg/src/lj_alloc.c
+@@ -72,13 +72,56 @@
+ 
+ #define IS_DIRECT_BIT		(SIZE_T_ONE)
+ 
++
++/* Determine system-specific block allocation method. */
+ #if LJ_TARGET_WINDOWS
+ 
+ #define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
+ 
++#define LJ_ALLOC_VIRTUALALLOC	1
++
+ #if LJ_64 && !LJ_GC64
++#define LJ_ALLOC_NTAVM		1
++#endif
++
++#else
++
++#include <errno.h>
++/* If this include fails, then rebuild with: -DLUAJIT_USE_SYSMALLOC */
++#include <sys/mman.h>
++
++#define LJ_ALLOC_MMAP		1
++
++#if LJ_64
++
++#define LJ_ALLOC_MMAP_PROBE	1
++
++#if LJ_GC64
++#define LJ_ALLOC_MBITS		47	/* 128 TB in LJ_GC64 mode. */
++#elif LJ_TARGET_X64 && LJ_HASJIT
++/* Due to limitations in the x64 compiler backend. */
++#define LJ_ALLOC_MBITS		31	/* 2 GB on x64 with !LJ_GC64. */
++#else
++#define LJ_ALLOC_MBITS		32	/* 4 GB on other archs with !LJ_GC64. */
++#endif
++
++#endif
++
++#if LJ_64 && !LJ_GC64 && defined(MAP_32BIT)
++#define LJ_ALLOC_MMAP32		1
++#endif
++
++#if LJ_TARGET_LINUX
++#define LJ_ALLOC_MREMAP		1
++#endif
++
++#endif
+ 
++
++#if LJ_ALLOC_VIRTUALALLOC
++
++#if LJ_ALLOC_NTAVM
+ /* Undocumented, but hey, that's what we all love so much about Windows. */
+ typedef long (*PNTAVM)(HANDLE handle, void **addr, ULONG zbits,
+ 		       size_t *size, ULONG alloctype, ULONG prot);
+@@ -89,14 +132,15 @@ static PNTAVM ntavm;
+ */
+ #define NTAVM_ZEROBITS		1
+ 
+-static void INIT_MMAP(void)
++static void init_mmap(void)
+ {
+   ntavm = (PNTAVM)GetProcAddress(GetModuleHandleA("ntdll.dll"),
+ 				 "NtAllocateVirtualMemory");
+ }
++#define INIT_MMAP()	init_mmap()
+ 
+ /* Win64 32 bit MMAP via NtAllocateVirtualMemory. */
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
++static void *CALL_MMAP(size_t size)
+ {
+   DWORD olderr = GetLastError();
+   void *ptr = NULL;
+@@ -107,7 +151,7 @@ static LJ_AINLINE void *CALL_MMAP(size_t
+ }
+ 
+ /* For direct MMAP, use MEM_TOP_DOWN to minimize interference */
+-static LJ_AINLINE void *DIRECT_MMAP(size_t size)
++static void *DIRECT_MMAP(size_t size)
+ {
+   DWORD olderr = GetLastError();
+   void *ptr = NULL;
+@@ -119,10 +163,8 @@ static LJ_AINLINE void *DIRECT_MMAP(size
+ 
+ #else
+ 
+-#define INIT_MMAP()		((void)0)
+-
+ /* Win32 MMAP via VirtualAlloc */
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
++static void *CALL_MMAP(size_t size)
+ {
+   DWORD olderr = GetLastError();
+   void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
+@@ -131,7 +173,7 @@ static LJ_AINLINE void *CALL_MMAP(size_t
+ }
+ 
+ /* For direct MMAP, use MEM_TOP_DOWN to minimize interference */
+-static LJ_AINLINE void *DIRECT_MMAP(size_t size)
++static void *DIRECT_MMAP(size_t size)
+ {
+   DWORD olderr = GetLastError();
+   void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,
+@@ -143,7 +185,7 @@ static LJ_AINLINE void *DIRECT_MMAP(size
+ #endif
+ 
+ /* This function supports releasing coalesed segments */
+-static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)
++static int CALL_MUNMAP(void *ptr, size_t size)
+ {
+   DWORD olderr = GetLastError();
+   MEMORY_BASIC_INFORMATION minfo;
+@@ -163,10 +205,7 @@ static LJ_AINLINE int CALL_MUNMAP(void *
+   return 0;
+ }
+ 
+-#else
+-
+-#include <errno.h>
+-#include <sys/mman.h>
++#elif LJ_ALLOC_MMAP
+ 
+ #define MMAP_PROT		(PROT_READ|PROT_WRITE)
+ #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
+@@ -174,107 +213,145 @@ static LJ_AINLINE int CALL_MUNMAP(void *
+ #endif
+ #define MMAP_FLAGS		(MAP_PRIVATE|MAP_ANONYMOUS)
+ 
+-#if LJ_64 && !LJ_GC64
+-/* 64 bit mode with 32 bit pointers needs special support for allocating
+-** memory in the lower 2GB.
+-*/
+-
+-#if defined(MAP_32BIT)
++#if LJ_ALLOC_MMAP_PROBE
+ 
+-#if defined(__sun__)
+-#define MMAP_REGION_START	((uintptr_t)0x1000)
+-#else
+-/* Actually this only gives us max. 1GB in current Linux kernels. */
+-#define MMAP_REGION_START	((uintptr_t)0)
+-#endif
++#define LJ_ALLOC_MMAP_PROBE_MAX		30
++#define LJ_ALLOC_MMAP_PROBE_LINEAR	5
+ 
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
+-{
+-  int olderr = errno;
+-  void *ptr = mmap((void *)MMAP_REGION_START, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0);
+-  errno = olderr;
+-  return ptr;
+-}
+-
+-#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun__) || defined(__CYGWIN__)
++#define LJ_ALLOC_MMAP_PROBE_LOWER	((uintptr_t)0x4000)
+ 
+-/* 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,
+-** otherwise the lower 4GB are blocked. And the 32GB RLIMIT_DATA needs
+-** to be reduced to 250MB on FreeBSD.
++/* No point in a giant ifdef mess. Just try to open /dev/urandom.
++** It doesn't really matter if this fails, since we get some ASLR bits from
++** every unsuitable allocation, too. And we prefer linear allocation, anyway.
+ */
+-#if LJ_TARGET_OSX || defined(__DragonFly__)
+-#define MMAP_REGION_START	((uintptr_t)0x10000)
+-#elif LJ_TARGET_PS4
+-#define MMAP_REGION_START	((uintptr_t)0x4000)
+-#else
+-#define MMAP_REGION_START	((uintptr_t)0x10000000)
+-#endif
+-#define MMAP_REGION_END		((uintptr_t)0x80000000)
++#include <fcntl.h>
++#include <unistd.h>
+ 
+-#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
+-#include <sys/resource.h>
+-#endif
++static uintptr_t mmap_probe_seed(void)
++{
++  uintptr_t val;
++  int fd = open("/dev/urandom", O_RDONLY);
++  if (fd != -1) {
++    int ok = ((size_t)read(fd, &val, sizeof(val)) == sizeof(val));
++    (void)close(fd);
++    if (ok) return val;
++  }
++  return 1;  /* Punt. */
++}
+ 
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
++static void *mmap_probe(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;
+-#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
+-  static int rlimit_modified = 0;
+-  if (LJ_UNLIKELY(rlimit_modified == 0)) {
+-    struct rlimit rlim;
+-    rlim.rlim_cur = rlim.rlim_max = MMAP_REGION_START;
+-    setrlimit(RLIMIT_DATA, &rlim);  /* Ignore result. May fail below. */
+-    rlimit_modified = 1;
+-  }
+-#endif
+-  for (;;) {
+-    void *p = mmap((void *)alloc_hint, size, MMAP_PROT, MMAP_FLAGS, -1, 0);
+-    if ((uintptr_t)p >= MMAP_REGION_START &&
+-	(uintptr_t)p + size < MMAP_REGION_END) {
+-      alloc_hint = (uintptr_t)p + size;
++  static uintptr_t hint_addr = 0;
++  static uintptr_t hint_prng = 0;
++  int olderr = errno;
++  int retry;
++  for (retry = 0; retry < LJ_ALLOC_MMAP_PROBE_MAX; retry++) {
++    void *p = mmap((void *)hint_addr, size, MMAP_PROT, MMAP_FLAGS, -1, 0);
++    uintptr_t addr = (uintptr_t)p;
++    if ((addr >> LJ_ALLOC_MBITS) == 0 && addr >= LJ_ALLOC_MMAP_PROBE_LOWER) {
++      /* We got a suitable address. Bump the hint address. */
++      hint_addr = addr + size;
+       errno = olderr;
+       return p;
+     }
+-    if (p != CMFAIL) munmap(p, size);
+-#if defined(__sun__) || defined(__DragonFly__)
+-    alloc_hint += 0x1000000;  /* Need near-exhaustive linear scan. */
+-    if (alloc_hint + size < MMAP_REGION_END) continue;
+-#endif
+-    if (retry) break;
+-    retry = 1;
+-    alloc_hint = MMAP_REGION_START;
++    if (p != MFAIL) {
++      munmap(p, size);
++    } else if (errno == ENOMEM) {
++      return MFAIL;
++    }
++    if (hint_addr) {
++      /* First, try linear probing. */
++      if (retry < LJ_ALLOC_MMAP_PROBE_LINEAR) {
++	hint_addr += 0x1000000;
++	if (((hint_addr + size) >> LJ_ALLOC_MBITS) != 0)
++	  hint_addr = 0;
++	continue;
++      } else if (retry == LJ_ALLOC_MMAP_PROBE_LINEAR) {
++	/* Next, try a no-hint probe to get back an ASLR address. */
++	hint_addr = 0;
++	continue;
++      }
++    }
++    /* Finally, try pseudo-random probing. */
++    if (LJ_UNLIKELY(hint_prng == 0)) {
++      hint_prng = mmap_probe_seed();
++    }
++    /* The unsuitable address we got has some ASLR PRNG bits. */
++    hint_addr ^= addr & ~((uintptr_t)(LJ_PAGESIZE-1));
++    do {  /* The PRNG itself is very weak, but see above. */
++      hint_prng = hint_prng * 1103515245 + 12345;
++      hint_addr ^= hint_prng * (uintptr_t)LJ_PAGESIZE;
++      hint_addr &= (((uintptr_t)1 << LJ_ALLOC_MBITS)-1);
++    } while (hint_addr < LJ_ALLOC_MMAP_PROBE_LOWER);
+   }
+   errno = olderr;
+-  return CMFAIL;
++  return MFAIL;
+ }
+ 
++#endif
++
++#if LJ_ALLOC_MMAP32
++
++#if defined(__sun__)
++#define LJ_ALLOC_MMAP32_START	((uintptr_t)0x1000)
+ #else
++#define LJ_ALLOC_MMAP32_START	((uintptr_t)0)
++#endif
+ 
+-#error "NYI: need an equivalent of MAP_32BIT for this 64 bit OS"
++static void *mmap_map32(size_t size)
++{
++#if LJ_ALLOC_MMAP_PROBE
++  static int fallback = 0;
++  if (fallback)
++    return mmap_probe(size);
++#endif
++  {
++    int olderr = errno;
++    void *ptr = mmap((void *)LJ_ALLOC_MMAP32_START, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0);
++    errno = olderr;
++    /* This only allows 1GB on Linux. So fallback to probing to get 2GB. */
++#if LJ_ALLOC_MMAP_PROBE
++    if (ptr == MFAIL) {
++      fallback = 1;
++      return mmap_probe(size);
++    }
++#endif
++    return ptr;
++  }
++}
+ 
+ #endif
+ 
++#if LJ_ALLOC_MMAP32
++#define CALL_MMAP(size)		mmap_map32(size)
++#elif LJ_ALLOC_MMAP_PROBE
++#define CALL_MMAP(size)		mmap_probe(size)
+ #else
+-
+-/* 32 bit mode and GC64 mode is easy. */
+-static LJ_AINLINE void *CALL_MMAP(size_t size)
++static void *CALL_MMAP(size_t size)
+ {
+   int olderr = errno;
+   void *ptr = mmap(NULL, size, MMAP_PROT, MMAP_FLAGS, -1, 0);
+   errno = olderr;
+   return ptr;
+ }
+-
+ #endif
+ 
+-#define INIT_MMAP()		((void)0)
+-#define DIRECT_MMAP(s)		CALL_MMAP(s)
++#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
++
++#include <sys/resource.h>
++
++static void init_mmap(void)
++{
++  struct rlimit rlim;
++  rlim.rlim_cur = rlim.rlim_max = 0x10000;
++  setrlimit(RLIMIT_DATA, &rlim);  /* Ignore result. May fail later. */
++}
++#define INIT_MMAP()	init_mmap()
++
++#endif
+ 
+-static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)
++static int CALL_MUNMAP(void *ptr, size_t size)
+ {
+   int olderr = errno;
+   int ret = munmap(ptr, size);
+@@ -282,10 +359,9 @@ static LJ_AINLINE int CALL_MUNMAP(void *
+   return ret;
+ }
+ 
+-#if LJ_TARGET_LINUX
++#if LJ_ALLOC_MREMAP
+ /* Need to define _GNU_SOURCE to get the mremap prototype. */
+-static LJ_AINLINE void *CALL_MREMAP_(void *ptr, size_t osz, size_t nsz,
+-				     int flags)
++static void *CALL_MREMAP_(void *ptr, size_t osz, size_t nsz, int flags)
+ {
+   int olderr = errno;
+   ptr = mremap(ptr, osz, nsz, flags);
+@@ -305,6 +381,15 @@ static LJ_AINLINE void *CALL_MREMAP_(voi
+ 
+ #endif
+ 
++
++#ifndef INIT_MMAP
++#define INIT_MMAP()		((void)0)
++#endif
++
++#ifndef DIRECT_MMAP
++#define DIRECT_MMAP(s)		CALL_MMAP(s)
++#endif
++
+ #ifndef CALL_MREMAP
+ #define CALL_MREMAP(addr, osz, nsz, mv) ((void)osz, MFAIL)
+ #endif
diff --git a/debian/patches/series b/debian/patches/series
index 2fbbdc6..cd3c0e9 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,4 @@
 0002-Enable-debugging-symbols-in-the-build.patch
 0003-Get-rid-of-LUAJIT_VERSION_SYM-that-changes-ABI-on-ev.patch
 0004-Add-ppc64-support-based-on-https-github.com-PPC64-Lu.patch
+0005-rewrite-memory-block-allocator.patch

--- End Message ---

Reply to: