[Updated] Add process_info/1 and process_info/2 with list argument#2374
[Updated] Add process_info/1 and process_info/2 with list argument#2374bettio wants to merge 12 commits into
Conversation
| .. doxygenstruct:: BuiltInAtomRequestSignal | ||
| .. doxygenstruct:: ProcessInfoRequestSignal | ||
| :allow-dot-graphs: | ||
| .. doxygenstruct:: BuiltInAtomSignal |
| } | ||
| } // else: sender died | ||
|
|
||
| if (signal->len == 0) { |
There was a problem hiding this comment.
Let's make it an assert instead (or two, (signal->mode == PROCESS_INFO_LIST) and len > 0). nif_erlang_process_info doesn't send PROCESS_INFO_LIST if length is 0.
|
AMP, usual caveats: PR review:
|
ce3e299 to
712dd87
Compare
|
AMP keeps insisting on these, your call.. Follow-up review:
|
712dd87 to
054d8ce
Compare
My answers: 1. High — Reply allocation can crash the VM or leave the requester trapped foreverI don't think this really applies to the PR. The issue is eventually somewhere else. 2. Medium —
|
054d8ce to
b708c0c
Compare
Signed-off-by: Mateusz Furga <mateusz.furga@swmansion.com>
process_info/1 is by OTP definition one process_info/2 list call plus a presentation rule, so implement it in Erlang, which simplifies the C code and makes it easier to maintain. The /1 tests move to tests/libs/estdlib accordingly, and the previously commented out cross-process check is enabled. Signed-off-by: Davide Bettio <davide@uninstall.it>
OTP raises badarg for external pids and validates the info request argument before checking whether the target process is alive, so an invalid item or an improper list is a badarg even for a dead pid. Match that. Signed-off-by: Davide Bettio <davide@uninstall.it>
A failed request signal allocation left the caller trapped forever waiting for an answer: raise out_of_memory instead. Also bound the accumulated result heap size, which a request repeating dynamically sized items could otherwise overflow. Signed-off-by: Davide Bettio <davide@uninstall.it>
Erlang/OTP answers undefined for an exiting process, but a request processed from the destroy path answered with a mid-destruction snapshot. Reply undefined there instead; the destroy path is uniquely identified by process_table_locked, as context_destroy is the only caller holding the process table write lock. Signed-off-by: Davide Bettio <davide@uninstall.it>
message_queue_len counted unprocessed system signals in the mailbox, while Erlang/OTP counts only ordinary messages, including accepted alias messages even if the alias is deactivated before reception. Count NormalMessage and AliasMessageSignal entries only. Signed-off-by: Davide Bettio <davide@uninstall.it>
The exception path of a trap completion did not clear the Trap flag, so a process that caught the exception parked for good at the next signal processing point, never draining its mailbox again. Clear it like the answer path does. Signed-off-by: Davide Bettio <davide@uninstall.it>
Follow C_CODING_STYLE.md naming for the new identifiers, replace unreachable branches with asserts, use size_t for the list build loops, remove redundant comments and wrap over-limit lines. Signed-off-by: Davide Bettio <davide@uninstall.it>
The CodeQL allocations-without-ensure-free query flagged the item validity probes, which cannot allocate, and its suppression window cannot cover the multi-line call sites. Validate items against a new non-allocating key switch instead. Signed-off-by: Davide Bettio <davide@uninstall.it>
Assert invariants instead of exact double-read equality for metrics that GC may change between two reads, and do not require the OTP-wise unspecified registered_name position on BEAM. Add missing coverage: memory growth with queued messages, trap_exit values, port and nested-list badargs, and C-level mailbox_normal_message_len tests. Signed-off-by: Davide Bettio <davide@uninstall.it>
Document process_info/1 and the list form in erlang.erl and in the programmers guide, record in UPDATING.md that process_info/2 no longer accepts port identifiers, and fix the stale ImmediateSignal entry in the data structures docs. Signed-off-by: Davide Bettio <davide@uninstall.it>
AtomsHashTable was removed in 2ab1acb, but the API documentation still listed it, leaving a directive that resolves to nothing. Signed-off-by: Davide Bettio <davide@uninstall.it>
b708c0c to
e72f93f
Compare
|
AMP: https://ampcode.com/threads/T-019f9561-3858-759a-8ed8-13c4ff1ccd17
seems happy - except for this allocate reply pattern, as adressed before.. PR review:
|
| case TrapAnswerSignal: { | ||
| struct TermSignal *trap_answer | ||
| = CONTAINER_OF(signal_message, struct TermSignal, base); | ||
| if (UNLIKELY(!context_process_signal_trap_answer(ctx, trap_answer))) { |
There was a problem hiding this comment.
As you're fixing the trap flag clear below, we could take advantage of this to change the signature of this function as it seems it always returns true.
Implement erlang:process_info/1 and the list-of-keys form of
erlang:process_info/2, matching Erlang/OTP behaviour. Both are needed
by Popcorn.
This revamps the original, stalled effort by Mateusz Furga (Software
Mansion) in #2219.
Main differences from that approach:
simplifying the native code and making the default key set easier
to maintain.
badarg for an invalid argument even when the target process is dead.
message_queue_len no longer counts queued signals, a request racing
process teardown answers undefined, and a caught trap exception no
longer leaves the process wedged.
and the result heap size is bounded.
Closes: #2190, #2191
See also: #2219
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later