Skip to content

Comments

Display Windows NTSTATUS exit codes in hex#11504

Merged
Leonidas-from-XIV merged 2 commits intoocaml:mainfrom
MisterDA:win32-exit-code
Feb 28, 2025
Merged

Display Windows NTSTATUS exit codes in hex#11504
Leonidas-from-XIV merged 2 commits intoocaml:mainfrom
MisterDA:win32-exit-code

Conversation

@MisterDA
Copy link
Contributor

On Windows, "negative" exit codes are probably NTSTATUS values. For example, if a program accesses an invalid memory location, Unix sends a SIGSEGV signal which, if unhandled, will terminate the process (setting some kind of non-zero exit code - for example, Linux sets the exit code to 128 + signal number to give a fairly memorable 139). In the equivalent scenario, Windows throws an EXCEPTION_ACCESS_VIOLATION which, if handled by the default exception handler, will terminate the process with exit code STATUS_ACCESS_VIOLATION. These codes are large negative numbers, which are not terribly memorable in decimal, so for negative exit codes we instead display them in hexadecimal as 0xc0000005 is slightly more memorable than -1073741819.

@maiste maiste added the windows Issues that relate to Dune on Microsoft Windows label Feb 25, 2025
Copy link
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, can you sign the DCO?

On Windows, "negative" exit codes are probably NTSTATUS values. For
example, if a program accesses an invalid memory location, Unix sends
a SIGSEGV signal which, if unhandled, will terminate the
process (setting some kind of non-zero exit code - for example, Linux
sets the exit code to 128 + signal number to give a fairly memorable
139). In the equivalent scenario, Windows throws an
EXCEPTION_ACCESS_VIOLATION which, if handled by the default exception
handler, will terminate the process with exit code
STATUS_ACCESS_VIOLATION. These codes are large negative numbers, which
are not terribly memorable in decimal, so for negative exit codes we
instead display them in hexadecimal as 0xc0000005 is slightly more
memorable than -1073741819.

Co-authored-by: David Allsopp <david.allsopp@metastack.com>
Signed-off-by: Antonin Décimo <antonin@tarides.com>
Signed-off-by: Marek Kubica <marek@tarides.com>
@Leonidas-from-XIV Leonidas-from-XIV merged commit 059bb2c into ocaml:main Feb 28, 2025
24 of 25 checks passed
Leonidas-from-XIV added a commit to Leonidas-from-XIV/dune that referenced this pull request Mar 6, 2025
* Display Windows NTSTATUS exit codes in hex

On Windows, "negative" exit codes are probably NTSTATUS values. For
example, if a program accesses an invalid memory location, Unix sends
a SIGSEGV signal which, if unhandled, will terminate the
process (setting some kind of non-zero exit code - for example, Linux
sets the exit code to 128 + signal number to give a fairly memorable
139). In the equivalent scenario, Windows throws an
EXCEPTION_ACCESS_VIOLATION which, if handled by the default exception
handler, will terminate the process with exit code
STATUS_ACCESS_VIOLATION. These codes are large negative numbers, which
are not terribly memorable in decimal, so for negative exit codes we
instead display them in hexadecimal as 0xc0000005 is slightly more
memorable than -1073741819.

Co-authored-by: David Allsopp <david.allsopp@metastack.com>
Signed-off-by: Antonin Décimo <antonin@tarides.com>

* Add changelog entry

Signed-off-by: Marek Kubica <marek@tarides.com>

---------

Signed-off-by: Antonin Décimo <antonin@tarides.com>
Signed-off-by: Marek Kubica <marek@tarides.com>
Co-authored-by: David Allsopp <david.allsopp@metastack.com>
Co-authored-by: Marek Kubica <marek@tarides.com>
maiste added a commit to maiste/opam-repository that referenced this pull request Mar 31, 2025
CHANGES:

### Fixed

- Support HaikuOS: don't call `execve` since it's not allowed if other pthreads
  have been created. The fact that Haiku can't call `execve` from other threads
  than the principal thread of a process (a team in haiku jargon), is a
  discrepancy to POSIX and hence there is a [bug about
  it](https://dev.haiku-os.org/ticket/18665). (@Sylvain78, ocaml/dune#10953)
- Fix flag ordering in generated Merlin configurations (ocaml/dune#11503, @voodoos, fixes
  ocaml/merlin#1900, reported by @vouillon)

### Added

- Add `(format-dune-file <src> <dst>)` action. It provides a replacement to
  `dune format-dune-file` command.  (ocaml/dune#11166, @nojb)
- Allow the `--prefix` flag when configuring dune with `ocaml configure.ml`.
  This allows to set the prefix just like `$ dune install --prefix`. (ocaml/dune#11172,
  @rgrinberg)
- Allow arguments starting with `+` in preprocessing definitions (starting with
  `(lang dune 3.18)`). (@amonteiro, ocaml/dune#11234)
- Support for opam `(maintenance_intent ...)` in dune-project (ocaml/dune#11274, @art-w)
- Validate opam `maintenance_intent` (ocaml/dune#11308, @art-w)
- Support `not` in package dependencies constraints (ocaml/dune#11404, @art-w, reported
  by @hannesm)

### Changed

- Warn when failing to discover root due to reads failing. The previous
  behavior was to abort. (@KoviRobi, ocaml/dune#11173)
- Use shorter path for inline-tests artifacts. (@hhugo, ocaml/dune#11307)
- Allow dash in `dune init` project name (ocaml/dune#11402, @art-w, reported by @saroupille)
- On Windows, under heavy load, file delete operations can sometimes fail due to
  AV programs, etc. Guard against it by retrying the operation up to 30x with a
  1s waiting gap (ocaml/dune#11437, fixes ocaml/dune#11425, @MSoegtropIMC)
- Cache: we now only store the executable permission bit for files (ocaml/dune#11541,
  fixes ocaml/dune#11533, @ElectreAAS)
- Display negative error codes on Windows in hex which is the more customary
  way to display `NTSTATUS` codes (ocaml/dune#11504, @MisterDA)
maiste added a commit to maiste/opam-repository that referenced this pull request Apr 3, 2025
CHANGES:

### Fixed

- Support HaikuOS: don't call `execve` since it's not allowed if other pthreads
  have been created. The fact that Haiku can't call `execve` from other threads
  than the principal thread of a process (a team in haiku jargon), is a
  discrepancy to POSIX and hence there is a [bug about
  it](https://dev.haiku-os.org/ticket/18665). (@Sylvain78, ocaml/dune#10953)
- Fix flag ordering in generated Merlin configurations (ocaml/dune#11503, @voodoos, fixes
  ocaml/merlin#1900, reported by @vouillon)

### Added

- Add `(format-dune-file <src> <dst>)` action. It provides a replacement to
  `dune format-dune-file` command.  (ocaml/dune#11166, @nojb)
- Allow the `--prefix` flag when configuring dune with `ocaml configure.ml`.
  This allows to set the prefix just like `$ dune install --prefix`. (ocaml/dune#11172,
  @rgrinberg)
- Allow arguments starting with `+` in preprocessing definitions (starting with
  `(lang dune 3.18)`). (@amonteiro, ocaml/dune#11234)
- Support for opam `(maintenance_intent ...)` in dune-project (ocaml/dune#11274, @art-w)
- Validate opam `maintenance_intent` (ocaml/dune#11308, @art-w)
- Support `not` in package dependencies constraints (ocaml/dune#11404, @art-w, reported
  by @hannesm)

### Changed

- Warn when failing to discover root due to reads failing. The previous
  behavior was to abort. (@KoviRobi, ocaml/dune#11173)
- Use shorter path for inline-tests artifacts. (@hhugo, ocaml/dune#11307)
- Allow dash in `dune init` project name (ocaml/dune#11402, @art-w, reported by @saroupille)
- On Windows, under heavy load, file delete operations can sometimes fail due to
  AV programs, etc. Guard against it by retrying the operation up to 30x with a
  1s waiting gap (ocaml/dune#11437, fixes ocaml/dune#11425, @MSoegtropIMC)
- Cache: we now only store the executable permission bit for files (ocaml/dune#11541,
  fixes ocaml/dune#11533, @ElectreAAS)
- Display negative error codes on Windows in hex which is the more customary
  way to display `NTSTATUS` codes (ocaml/dune#11504, @MisterDA)
@MisterDA
Copy link
Contributor Author

MisterDA commented Apr 7, 2025

The NTSTATUS code isn't formatted when Dune is run in --verbose mode. Where should this happen?

@MisterDA MisterDA deleted the win32-exit-code branch April 7, 2025 16:42
@maiste
Copy link
Collaborator

maiste commented Apr 8, 2025

@MisterDA, I didn't test, but my bet would be it is in the verbose function. Maybe by modifying this variable you can get the verbose output correct.

anmonteiro pushed a commit to anmonteiro/dune that referenced this pull request Apr 22, 2025
* Display Windows NTSTATUS exit codes in hex

On Windows, "negative" exit codes are probably NTSTATUS values. For
example, if a program accesses an invalid memory location, Unix sends
a SIGSEGV signal which, if unhandled, will terminate the
process (setting some kind of non-zero exit code - for example, Linux
sets the exit code to 128 + signal number to give a fairly memorable
139). In the equivalent scenario, Windows throws an
EXCEPTION_ACCESS_VIOLATION which, if handled by the default exception
handler, will terminate the process with exit code
STATUS_ACCESS_VIOLATION. These codes are large negative numbers, which
are not terribly memorable in decimal, so for negative exit codes we
instead display them in hexadecimal as 0xc0000005 is slightly more
memorable than -1073741819.

Co-authored-by: David Allsopp <david.allsopp@metastack.com>
Signed-off-by: Antonin Décimo <antonin@tarides.com>

* Add changelog entry

Signed-off-by: Marek Kubica <marek@tarides.com>

---------

Signed-off-by: Antonin Décimo <antonin@tarides.com>
Signed-off-by: Marek Kubica <marek@tarides.com>
Co-authored-by: David Allsopp <david.allsopp@metastack.com>
Co-authored-by: Marek Kubica <marek@tarides.com>
Sudha247 pushed a commit to Sudha247/dune that referenced this pull request Jul 23, 2025
* Display Windows NTSTATUS exit codes in hex

On Windows, "negative" exit codes are probably NTSTATUS values. For
example, if a program accesses an invalid memory location, Unix sends
a SIGSEGV signal which, if unhandled, will terminate the
process (setting some kind of non-zero exit code - for example, Linux
sets the exit code to 128 + signal number to give a fairly memorable
139). In the equivalent scenario, Windows throws an
EXCEPTION_ACCESS_VIOLATION which, if handled by the default exception
handler, will terminate the process with exit code
STATUS_ACCESS_VIOLATION. These codes are large negative numbers, which
are not terribly memorable in decimal, so for negative exit codes we
instead display them in hexadecimal as 0xc0000005 is slightly more
memorable than -1073741819.

Co-authored-by: David Allsopp <david.allsopp@metastack.com>
Signed-off-by: Antonin Décimo <antonin@tarides.com>

* Add changelog entry

Signed-off-by: Marek Kubica <marek@tarides.com>

---------

Signed-off-by: Antonin Décimo <antonin@tarides.com>
Signed-off-by: Marek Kubica <marek@tarides.com>
Co-authored-by: David Allsopp <david.allsopp@metastack.com>
Co-authored-by: Marek Kubica <marek@tarides.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

windows Issues that relate to Dune on Microsoft Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants