Sysinternals / ProcDump-for-Linux

A Linux version of the ProcDump Sysinternals tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support build on riscv64?

yuzibo opened this issue · comments

Expected behavior

Built on riscv64

Actual behavior

Fail to build riscv64

Steps to reproduce the behavior

If you look at this, you will find many changes happened on the new version procdump. It fails to build many archs which can be built in the past.

System information (e.g., distro, kernel version, etc.)

OS: Debian
arch: riscv64
kernel: 6.5.8-1

In fact, I made a patch to support build riscv64 and it can be built on Debian riscv64. But I am not sure how to ensure the patch is ok. So the next step to support is...?:)

I have real riscv64 hardware by hand.

cat debian/patches/support-riscv.patch
--- a/profiler/inc/pal.h
+++ b/profiler/inc/pal.h
@@ -94,6 +94,8 @@
 #define _M_ARM 7
 #elif defined(__aarch64__) && !defined(_M_ARM64)
 #define _M_ARM64 1
+#elif defined(__riscv_xlen) && __riscv_xlen == 64 && !defined(_M_RISCV64)
+#define _M_RISCV64 1
 #elif defined(__s390x__) && !defined(_M_S390X)
 #define _M_S390X 1
 #endif
@@ -106,6 +108,8 @@
 #define HOST_ARM
 #elif defined(_M_ARM64) && !defined(HOST_ARM64)
 #define HOST_ARM64
+#elif defined(_M_RISCV64) && !defined(HOST_RISCV64)
+#define HOST_RISCV64
 #elif defined(_M_S390X) && !defined(HOST_S390X)
 #define HOST_S390X
 #endif
@@ -2202,6 +2206,147 @@

 } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;

+#elif defined(HOST_RISCV64)
+
+// There is no context for riscv64 defined in winnt.h,
+#define CONTEXT_RISCV64   0x4000000
+
+#define CONTEXT_CONTROL (CONTEXT_RISCV64 | 0x1L)
+#define CONTEXT_INTEGER (CONTEXT_RISCV64 | 0x2L)
+#define CONTEXT_FLOATING_POINT  (CONTEXT_RISCV64 | 0x4L)
+
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
+
+#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
+
+#define CONTEXT_EXCEPTION_ACTIVE 0x8000000
+#define CONTEXT_SERVICE_ACTIVE 0x10000000
+#define CONTEXT_EXCEPTION_REQUEST 0x40000000
+#define CONTEXT_EXCEPTION_REPORTING 0x80000000
+
+typedef struct DECLSPEC_ALIGN(8) _CONTEXT {
+
+    //
+    // Control flags.
+    //
+
+    DWORD ContextFlags;
+
+    //
+    // Integer registers.
+    //
+
+    union {
+        DWORD64 Gpr[32];
+        struct {
+            DWORD64 X0;
+            DWORD64 X1;
+            DWORD64 X2;
+            DWORD64 X3;
+            DWORD64 X4;
+            DWORD64 X5;
+            DWORD64 X6;
+            DWORD64 X7;
+            DWORD64 X8;
+            DWORD64 X9;
+            DWORD64 X10;
+            DWORD64 X11;
+            DWORD64 X12;
+            DWORD64 X13;
+            DWORD64 X14;
+            DWORD64 X15;
+            DWORD64 X16;
+            DWORD64 X17;
+            DWORD64 X18;
+            DWORD64 X19;
+            DWORD64 X20;
+            DWORD64 X21;
+            DWORD64 X22;
+            DWORD64 X23;
+            DWORD64 X24;
+            DWORD64 X25;
+            DWORD64 X26;
+            DWORD64 X27;
+            DWORD64 X28;
+            DWORD64 X29;
+            DWORD64 X30;
+            DWORD64 X31;
+        };
+    };
+
+    //
+    // Floating-point registers.
+    //
+
+    union {
+        DWORD64 Fpr[32];
+        struct {
+            DWORD64 F0;
+            DWORD64 F1;
+            DWORD64 F2;
+            DWORD64 F3;
+            DWORD64 F4;
+            DWORD64 F5;
+            DWORD64 F6;
+            DWORD64 F7;
+            DWORD64 F8;
+            DWORD64 F9;
+            DWORD64 F10;
+            DWORD64 F11;
+            DWORD64 F12;
+            DWORD64 F13;
+            DWORD64 F14;
+            DWORD64 F15;
+            DWORD64 F16;
+            DWORD64 F17;
+            DWORD64 F18;
+            DWORD64 F19;
+            DWORD64 F20;
+            DWORD64 F21;
+            DWORD64 F22;
+            DWORD64 F23;
+            DWORD64 F24;
+            DWORD64 F25;
+            DWORD64 F26;
+            DWORD64 F27;
+            DWORD64 F28;
+            DWORD64 F29;
+            DWORD64 F30;
+            DWORD64 F31;
+        };
+    };
+
+    //
+    // Control registers.
+    //
+
+    DWORD64 Ra;
+    DWORD64 Sp;
+    DWORD64 Gp;
+    DWORD64 Tp;
+    DWORD64 Pc;
+    DWORD64 Fp;
+
+} CONTEXT, *PCONTEXT, *LPCONTEXT;
+
+//
+// Nonvolatile context pointer record.
+//
+
+typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
+    PDWORD64 R6;
+    PDWORD64 R7;
+    PDWORD64 R8;
+    PDWORD64 R9;
+    PDWORD64 R10;
+    PDWORD64 R11;
+    PDWORD64 R12;
+    PDWORD64 R13;
+    PDWORD64 R14;
+    PDWORD64 R15;
+
+} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
+
 #elif defined(HOST_S390X)

 // There is no context for s390x defined in winnt.h,
@@ -2444,6 +2589,8 @@
 #define PAL_CS_NATIVE_DATA_SIZE 76
 #elif defined(__linux__) && defined(__x86_64__)
 #define PAL_CS_NATIVE_DATA_SIZE 96
+#elif defined(__linux__) && defined(HOST_RISCV64)
+#define PAL_CS_NATIVE_DATA_SIZE 116
 #elif defined(__linux__) && defined(HOST_S390X)
 #define PAL_CS_NATIVE_DATA_SIZE 96
 #elif defined(__NetBSD__) && defined(__amd64__)
--- a/profiler/inc/palrt.h
+++ b/profiler/inc/palrt.h
@@ -1215,6 +1215,14 @@
     BOOLEAN ControlPcIsUnwound;
 } DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;

+#elif defined(HOST_RISCV64)
+
+typedef struct _DISPATCHER_CONTEXT {
+    // RISCV64 does not build the VM or JIT at this point,
+    // so we only provide a dummy definition.
+    DWORD Reserved;
+} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
+
 #elif defined(HOST_S390X)

 typedef struct _DISPATCHER_CONTEXT {

Thanks for letting us know about this. The fundamental issue here is that ProcDump has .NET integration in the form of a profiler. The current snapshot of .NET dependencies do not seem to support the architectures that are failing. Unless .NET has explicit support for that architecture, there really doesn't exist an easy workaround. An alternative approach would be to allow disabling building the .NET profiler but that would be a fairly large change and create some user experience inconsistencies.

Thanks for reply.

Here I find .NET has a initial support for riscv64 , but I am not sure this is enough or not. please let me know if I can help here.

I've made some changes to enable some of this here - https://github.com/mariohewardt/ProcDump-for-Linux

When building, specify the HOST like so: make CLRHOST=HOST_RISCV6

A list of supported hosts can be found in the Makefile comments. I haven't been able to cross compile and test this yet but if you want to give it a go that'd be great.

Thanks. It seems it works!

make CLRHOST=HOST_RISCV64
sudo make install

And I just to try one basic usage:

rv@debci-01:~/git/ProcDump-for-Linux$ sudo procdump -n 3 663

ProcDump v2.2 - Sysinternals process dump utility
Copyright (C) 2023 Microsoft Corporation. All rights reserved. Licensed under the MIT license.
Mark Russinovich, Mario Hewardt, John Salem, Javid Habibi
Sysinternals - www.sysinternals.com

Monitors one or more processes and writes a core dump file when the processes exceeds the
specified criteria.

[03:33:05 - INFO]: Press Ctrl-C to end monitoring without terminating the process(es).
Process:                                beam.smp (663)
CPU Threshold:                          n/a
Commit Threshold:                       n/a
Thread Threshold:                       n/a
File Descriptor Threshold:              n/a
Signal:                                 n/a
Exception monitor                       n/a
GC Generation                           n/a
Polling Interval (ms):                  1000
Threshold (s):                          10
Number of Dumps:                        3
Output directory:                       .
[03:33:05 - INFO]: Starting monitor for process beam.smp (663)
[03:33:05 - INFO]: Trigger: Timer:1(s) on process ID: 663
[03:33:51 - INFO]: Core dump 0 generated: ./beam_smp_time_2023-11-03_03:33:05.663
[03:34:01 - INFO]: Trigger: Timer:1(s) on process ID: 663
[03:34:45 - INFO]: Core dump 1 generated: ./beam_smp_time_2023-11-03_03:34:01.663
[03:34:55 - INFO]: Trigger: Timer:1(s) on process ID: 663
[03:35:39 - INFO]: Core dump 2 generated: ./beam_smp_time_2023-11-03_03:34:55.663
[03:35:39 - INFO]: Stopping monitor for process beam.smp (663)

rv@debci-01:~/git/ProcDump-for-Linux$ uname -a
Linux debci-01 6.5.0-3-riscv64 #1 SMP Debian 6.5.8-1 (2023-10-22) riscv64 GNU/Linux

Great to hear. Is it now passing all the builds in the Debian Packaga Autobuilding (link with logs you sent earlier in the thread)?

Sorry, I am not the package maintainer on Debian, so I just built it on riscv64 and another issue is that I am not a DD, so I don't have permission to do this.

I think the best method is let the maintainer of package to build in experimential repo first to see if break something on other archs.

I've merged the fix for this issue. It will detect the architecture so you no longer have to specify it via make CLRHOST (simply run make).