1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! Port of `NetBSDProcess.c` — the NetBSD process object.
//!
//! Ported (self-contained, on the base [`Process`] + [`Process_init`]):
//! - the [`NetBSDProcess`] object struct (`NetBSDProcess.h:20` — just an
//! embedded `Process super`; NetBSD adds no per-process fields).
//! - [`NetBSDProcess_new`] (`NetBSDProcess.c:218`).
//! - the leaf column renderer [`NetBSDProcess_rowWriteField`]
//! (`NetBSDProcess.c:231`) and comparator [`NetBSDProcess_compareByKey`]
//! (`NetBSDProcess.c:248`). NetBSD defines no platform-specific
//! `ProcessField`s, so both switch statements have only the `default` arm
//! and delegate wholesale to the base [`Process_writeField`] /
//! [`Process_compareByKey_Base`].
//!
//! Still `todo!()`:
//! - `Process_delete` (`NetBSDProcess.c:225`) is a pure `free()` teardown —
//! `Process_done(&this->super)` then `free(this)` (no NetBSD-only heap
//! fields). Rust owns the [`NetBSDProcess`] allocation and its base
//! `Option<String>` fields, so `Drop` reclaims them; there is no faithful
//! safe-Rust analog (the darwin/linux `Process_delete` precedent).
//!
//! The `Process_fields[]` field-descriptor table (`NetBSDProcess.c:23`) is
//! data, not a function, and is deferred until the shared `ProcessField`
//! layer models the NetBSD column titles.
use Any;
use crateMachine;
use crate;
use crate;
use crateRichString;
use crate;
use crateRowField;
use c_void;
/// Port of htop's `struct NetBSDProcess_` (`NetBSDProcess.h:20`). "Extends"
/// [`Process`] via the embedded `super_` field (htop's `Process super;` first
/// member); NetBSD carries no platform-specific per-process fields.
///
/// `#[repr(C)]` guarantees `super_` sits at offset 0, so htop's
/// `(NetBSDProcess*)processPtr` downcast — a `*const Process` obtained from a
/// `NetBSDProcess` allocation, cast back — is sound.
/// `NetBSDProcess` "is a" `Object` (via `Process` via `Row`). Every class /
/// display / compare slot delegates to the embedded [`Process`] (the
/// `NetBSDProcess_class` vtable overrides no base slots that are ported yet),
/// while the base-view accessors expose this object's embedded [`Row`] /
/// [`Process`] — the mechanism a [`Table`](crate::ported::table::Table) of
/// `Box<dyn Object>` rows uses to recover them.
/// Port of `Process* NetBSDProcess_new(const Machine* host)` from
/// `NetBSDProcess.c:218`. C `xCalloc`s a `NetBSDProcess`, sets its class, runs
/// `Process_init` on the embedded base, and returns `(Process*)this`.
///
/// The returned `Box<NetBSDProcess>` is the owner (C's heap allocation);
/// `&mut box.super_` is the `*mut Process`. `Object_setClass` /
/// `Class(NetBSDProcess)` are dropped — class identity is the Rust type.
/// TODO: port of `void Process_delete(Object* cast)` from
/// `NetBSDProcess.c:225`. Kept stubbed: the C body is a pure teardown —
/// `Process_done(&this->super)` followed by `free(this)` (no NetBSD-only heap
/// fields to release). Rust owns the [`NetBSDProcess`] allocation and its
/// `Option<String>` base fields, so `Drop` reclaims them automatically; there
/// is no faithful safe-Rust analog (the darwin/linux `Process_delete`
/// precedent).
/// Port of `static void NetBSDProcess_rowWriteField(const Row* super,
/// RichString* str, ProcessField field)` from `NetBSDProcess.c:231` — the
/// NetBSD-specific per-field renderer. NetBSD defines no platform-specific
/// `ProcessField`s, so the C `switch (field)` has only the `default` arm,
/// which delegates to the base [`Process_writeField`]; the unreachable
/// `RichString_appendWide` tail is omitted.
///
/// This is the `writeField` [`RowClass`] vtable slot for `NetBSDProcess`; the
/// C `const Row* super` receiver is a `&dyn Object` downcast to
/// [`NetBSDProcess`] (C's `(const NetBSDProcess*)super`).
/// Port of `static int NetBSDProcess_compareByKey(const Process* v1, const
/// Process* v2, ProcessField key)` from `NetBSDProcess.c:248`. NetBSD defines
/// no platform-specific `ProcessField`s, so the C `switch (key)` has only the
/// `default` arm, which delegates to [`Process_compareByKey_Base`].
///
/// This is the `compareByKey` [`ProcessClass`] slot; the C `const Process*`
/// receivers are `&dyn Object` downcast to [`NetBSDProcess`].