Bug 498373

Summary: querying memory/physical/buffer crashes ksystemstats on FreeBSD
Product: [Frameworks and Libraries] ksystemstats Reporter: Henry Hu <henry.hu.sh>
Component: GeneralAssignee: Plasma Bugs List <plasma-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: ahiemstra, kde, nate
Priority: NOR    
Version First Reported In: 6.2.4   
Target Milestone: ---   
Platform: FreeBSD Ports   
OS: FreeBSD   
Latest Commit: Version Fixed In: 6.3.0
Sentry Crash Report:

Description Henry Hu 2025-01-08 05:09:01 UTC
SUMMARY

querying memory/physical/buffer crashes ksystemstats on FreeBSD

STEPS TO REPRODUCE
1. run "kstatsviewer memory/physical/buffer"

OBSERVED RESULT

ksystemstats crashes

EXPECTED RESULT

Return the amount of memory used for buffer (FreeBSD shows that in top).

SOFTWARE/OS VERSIONS
FreeBSD/KDE Plasma: FreeBSD 15-CURRENT
KDE Plasma Version: 6.2.4
KDE Frameworks Version: 6.9.0
Qt Version: 6.7.3

ADDITIONAL INFORMATION

I think dbus library called abort(): I see this when it crashed

QDBusMarshaller: type 'ulong' (35) is not registered with D-Bus. Use qDBusRegisterMetaType to register it
dbus[48596]: Array or variant type requires that type variant be written, but end_struct was written.
The overall signature expected here was 'a(sv)' and we are on byte 3 of that signature.

I'll try to debug it. Here's the stack trace:

#7  thr_kill () at thr_kill.S:4
#8  0x000000082c820af4 in __raise (s=s@entry=6) at /usr/src/lib/libc/gen/raise.c:48
#9  0x000000082c8d56d9 in abort () at /usr/src/lib/libc/stdlib/abort.c:61
#10 0x000000083114c72c in _dbus_abort () from /usr/local/lib/libdbus-1.so.3
#11 0x000000083114101c in _dbus_warn_check_failed () from /usr/local/lib/libdbus-1.so.3
#12 0x000000083112c21a in ?? () from /usr/local/lib/libdbus-1.so.3
#13 0x000000083112c11d in _dbus_type_writer_unrecurse () from /usr/local/lib/libdbus-1.so.3
#14 0x0000000831131989 in dbus_message_iter_close_container () from /usr/local/lib/libdbus-1.so.3
#15 0x000000082370a916 in ?? () from /usr/local/lib/qt6/libQt6DBus.so.6
#16 0x000000082370a9ae in ?? () from /usr/local/lib/qt6/libQt6DBus.so.6
#17 0x0000000823708534 in ?? () from /usr/local/lib/qt6/libQt6DBus.so.6
#18 0x000000082373f1db in ?? () from /usr/local/lib/qt6/libQt6DBus.so.6
#19 0x000000082371f0f9 in ?? () from /usr/local/lib/qt6/libQt6DBus.so.6
#20 0x000000000023b886 in Client::sendValues (this=0x2bc99e260450, entries=...) at /home/henryhu/proj/ksystemstats/src/client.cpp:91
#21 0x000000000023b5b0 in Client::sendFrame (this=0x2bc99e260450) at /home/henryhu/proj/ksystemstats/src/client.cpp:76
#22 0x000000000021d080 in Daemon::sendFrame (this=0x820527680) at /home/henryhu/proj/ksystemstats/src/daemon.cpp:269
#23 0x0000000000233e9d in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (Daemon::*)()>::call(void (Daemon::*)(), Daemon*, void**) (f=(void (Daemon::*)(Daemon * const)) 0x21cfb0 <Daemon::sendFrame()>, o=0x820527680, arg=0x8205271b0) at /usr/local/include/qt6/QtCore/qobjectdefs_impl.h:145
#24 0x0000000000233dfd in QtPrivate::FunctionPointer<void (Daemon::*)()>::call<QtPrivate::List<>, void>(void (Daemon::*)(), Daemon*, void**) (f=(void (Daemon::*)(Daemon * const)) 0x21cfb0 <Daemon::sendFrame()>, o=0x820527680, arg=0x8205271b0) at /usr/local/include/qt6/QtCore/qobjectdefs_impl.h:182
#25 0x0000000000233d26 in QtPrivate::QCallableObject<void (Daemon::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (which=1, this_=0x2bc99e21afc0, r=0x820527680, a=0x8205271b0, ret=0x0) at /usr/local/include/qt6/QtCore/qobjectdefs_impl.h:553
#26 0x000000082a546676 in ?? () from /usr/local/lib/qt6/libQt6Core.so.6
#27 0x000000082a557566 in QTimer::timerEvent(QTimerEvent*) () from /usr/local/lib/qt6/libQt6Core.so.6
#28 0x000000082a53a394 in QObject::event(QEvent*) () from /usr/local/lib/qt6/libQt6Core.so.6
#29 0x000000082a4f1864 in QCoreApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/local/lib/qt6/libQt6Core.so.6
#30 0x000000082a4f12de in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/local/lib/qt6/libQt6Core.so.6
#31 0x000000082a67d15a in QTimerInfoList::activateTimers() () from /usr/local/lib/qt6/libQt6Core.so.6
#32 0x000000082a76a09d in ?? () from /usr/local/lib/qt6/libQt6Core.so.6
#33 0x0000000832e9534b in ?? () from /usr/local/lib/libglib-2.0.so.0
#34 0x0000000832e95716 in ?? () from /usr/local/lib/libglib-2.0.so.0
#35 0x0000000832e957b6 in g_main_context_iteration () from /usr/local/lib/libglib-2.0.so.0
#36 0x000000082a76979e in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/local/lib/qt6/libQt6Core.so.6
#37 0x000000082a4fac16 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/local/lib/qt6/libQt6Core.so.6
#38 0x000000082a4f1ac4 in QCoreApplication::exec() () from /usr/local/lib/qt6/libQt6Core.so.6
#39 0x000000000021c58b in main (argc=1, argv=0x8205279f0) at /home/henryhu/proj/ksystemstats/src/main.cpp:39
[Inferior 1 (process 16823) detached]
Comment 1 Henry Hu 2025-01-08 05:26:23 UTC
I think the 'application' memory is also wrong. This is traced to an integer overflow: it's computed with (inactive pages + active pages) * page_size; page counts are in uint32_t, but we need to do the computation in uint64_t at least.
Comment 2 Henry Hu 2025-01-08 05:58:57 UTC
Preparing fixes in https://invent.kde.org/henryhu/ksystemstats/-/commits/freebsd_mem
The problem is that the code tried to convert a uint64_t to QVariant and sent it through dbus; however, uint64_t maps to Qt type 'ulong', which is not mapped for Qt DBus type system (https://doc.qt.io/qt-6/qdbustypesystem.html).
On the other hand, we can use  'unsigned long long', which maps to Qt type 'qulonglong', which maps to DBus type 'uint64', which is what we want.
Comment 3 David Redondo 2025-01-08 12:24:31 UTC
I wrote that code (in a vm) and your analysis makes sense. Sadly I can't remember why I chose uint64_t for some sensors and uint32_t for some others and can't think of a rason why for example should have a shorter size type.
Comment 4 Bug Janitor Service 2025-01-08 18:28:32 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/ksystemstats/-/merge_requests/102
Comment 5 Arjen Hiemstra 2025-01-09 11:35:10 UTC
Git commit 6bd39bbe1ce2b0e9bdb7e499bd54f3b212c7669e by Arjen Hiemstra, on behalf of Henry Hu.
Committed on 09/01/2025 at 11:28.
Pushed by ahiemstra into branch 'master'.

Fix buffer memory reporting

We can't use 'uint64_t' here, because it's mapped to 'ulong' Qt type,
which is not registered in Qt DBus type system. On the other hand,
'unsigned long long' is okay, because it maps to 'qulonglong', which
maps to DBus type 'uint64', which is what we want.
See https://doc.qt.io/qt-6/qdbustypesystem.html for details.

M  +2    -1    plugins/memory/freebsdbackend.cpp

https://invent.kde.org/plasma/ksystemstats/-/commit/6bd39bbe1ce2b0e9bdb7e499bd54f3b212c7669e