Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nim Hot Code Reloading tests fail on OpenBSD #12140

Open
euantorano opened this issue Sep 5, 2019 · 1 comment
Open

Nim Hot Code Reloading tests fail on OpenBSD #12140

euantorano opened this issue Sep 5, 2019 · 1 comment

Comments

@euantorano
Copy link
Contributor

There are several nimhcr tests that fail on OpenBSD with a Not supported [OSError] error. THe problem appears to be in the reservedmem module as they all fail with a stacktrace similar to the following:

Category: dll
Name: tests/dll/nimhcr_unit.nim C
Action: run
Result: reExitcodesDiffer
-------- Expected -------
exitcode: 0
--------- Given  --------
exitcode: 1

Output:
nimhcr_unit.nim(107)     nimhcr_unit
/home/administrator/build/Nim/lib/nimhcr.nim(342) hcrRegisterProc
/home/administrator/build/Nim/lib/pure/reservedmem.nim(217) setLen
/home/administrator/build/Nim/lib/pure/reservedmem.nim(94) setLen
/home/administrator/build/Nim/lib/pure/includes/oserr.nim(94) raiseOSError
Error: unhandled exception: Not supported [OSError]
@timotheecour
Copy link
Member

timotheecour commented Dec 12, 2020

The stacktrace isn't super helpful because check is a template, not a proc, so it can't (currently! refs timotheecour#447) tell which line it was called from:

  template check(expr) =
    if not expr:
      raiseOSError(osLastError())

but as I saw in #16329 it actually points to one of these failing:
check mprotect or check posix_madvise

proc setLen*(m: var ReservedMem, newLen: int) =
  let len = m.len
  m.usedMemEnd = m.memStart.shift(newLen)
  if newLen > len:
    let d = distance(m.committedMemEnd, m.usedMemEnd)
    if d > 0:
      let commitExtensionSize = nextAlignedOffset(d, allocationGranularity)
      when defined(windows):
        check virtualAlloc(m.committedMemEnd, commitExtensionSize,
                           MEM_COMMIT, m.accessFlags.cint)
      else:
        check mprotect(m.committedMemEnd, commitExtensionSize,
            m.accessFlags.cint) == 0
  else:
    let d = distance(m.usedMemEnd, m.committedMemEnd) -
            m.maxCommittedAndUnusedPages * allocationGranularity
    if d > 0:
      let commitSizeShrinkage = nextAlignedOffset(d, allocationGranularity)
      let newCommitEnd = m.committedMemEnd.shift(-commitSizeShrinkage)

      when defined(windows):
        check virtualFree(newCommitEnd, commitSizeShrinkage, MEM_DECOMMIT)
      else:
        check posix_madvise(newCommitEnd, commitSizeShrinkage,
                            POSIX_MADV_DONTNEED) == 0

      m.committedMemEnd = newCommitEnd

upon further investigation i found this comment:

OpenBSD however doesn't implement posix_madvise().

in https://patchwork.ozlabs.org/project/qemu-devel/patch/1284224755-11299-1-git-send-email-andreas.faerber@web.de/

but there's some contradiction with other sources I found on the topic; it my depend on glibc etc

links

EDIT

looks like it's in fact check mprotect the culprit (really hard to debug via CI)

        check mprotect(m.committedMemEnd, commitExtensionSize,
            m.accessFlags.cint) == 0

I can't find any relevant reference on the web / nim sources to "Not supported" from the errmsg
Error: unhandled exception: Not supported [OSError] so it's not clear where that comes from.

Further investigation needs to look what was this equal to: m.accessFlags.cint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants