Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash on windows 64, force sigar_set_pointer use 64bit pointer #142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cnstar9988
Copy link

@cnstar9988 cnstar9988 commented Nov 20, 2020

fix #141, #138, #136

@cnstar9988 cnstar9988 changed the title force sigar_set_pointer use 64bit pointer fix crash on windows, force sigar_set_pointer use 64bit pointer Nov 20, 2020
@cnstar9988 cnstar9988 changed the title fix crash on windows, force sigar_set_pointer use 64bit pointer fix crash on windows 64, force sigar_set_pointer use 64bit pointer Nov 21, 2020
@aldrato
Copy link

aldrato commented Nov 21, 2020

Hello @cnstar9988
Can you guide how to rebuild the dll?

@cnstar9988
Copy link
Author

I can rebuild sigar 1.6.4, vs2015+Perl 5.8 + JDK 1.8 + ant 1.9.7

  1. run into vs2015 x64 command prompt environment.
  2. change dir into sigar-1.6.4\bindings\java.
  3. run ant.
    sigar-amd64-winnt.dll will be in sigar-1.6.4\bindings\java\sigar-bin\lib

@nddipiazza
Copy link

nddipiazza commented Dec 4, 2020

@cnstar9988 what Windows OS version and Windows SDK version are you using?

I did:

Download visual studio community installer
Install Win10SDK_10.0.18362
Install ant 1.9.7 and add to PATH
Download and install http://strawberryperl.com/download/5.8.9/strawberry-perl-5.8.9.5.msi
Run "Developer Command Prompt for VS 2019"

Then Run

git clone https://github.com/cnstar9988/sigar
cd sigar\bindings\java
ant

Result:

C:\sigar\bindings\java>ant
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
Buildfile: C:\sigar\bindings\java\build.xml

jni-init:
     [echo] jni.src=win32, jni.jdk.os=win32, 64-bit
    [javac] C:\sigar\bindings\java\hyperic_jni\jni-build.xml:165: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
  [libarch] amd64-winnt
     [echo] java.home=C:\Program Files\AdoptOpenJDK\jdk-8.0.275.1-hotspot

sigar-version:
     [echo] SIGAR git revision 9e5dba8

version-file:
     [echo] cp ./src/org/hyperic/sigar/Version.java.in -> C:\sigar\bindings\java\build/./src/org/hyperic/sigar/Version.java
     [copy] Copying 1 file to C:\sigar\bindings\java\build\src\org\hyperic\sigar

version-file:
     [echo] cp ../../src/sigar_version.c.in -> C:\sigar\bindings\java\build/src/sigar_version.c
     [copy] Copying 1 file to C:\sigar\bindings\java\build\src

version-file:
     [echo] cp ../../src/os/darwin/Info.plist.in -> C:\sigar\bindings\java\build/src/Info.plist
     [copy] Copying 1 file to C:\sigar\bindings\java\build\src

version-file:
     [echo] cp ../../src/os/win32/sigar.rc.in -> C:\sigar\bindings\java\build/src/sigar.rc
     [copy] Copying 1 file to C:\sigar\bindings\java\build\src

sigar.rc:
     [exec] Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
     [exec] Copyright (C) Microsoft Corporation.  All rights reserved.
     [exec]

prepare-src:
     [exec] javasigar_generated.c needs update
     [exec] generating javasigar_generated.c
     [exec] generating javasigar_generated.h
     [exec] generating org/hyperic/sigar/SysInfo.java
     [exec] generating org/hyperic/sigar/FileSystemUsage.java
     [exec] generating org/hyperic/sigar/ProcCred.java
     [exec] generating org/hyperic/sigar/NfsClientV2.java
     [exec] generating org/hyperic/sigar/ProcExe.java
     [exec] generating org/hyperic/sigar/ProcCumulativeDiskIO.java
     [exec] generating org/hyperic/sigar/NetConnection.java
     [exec] generating org/hyperic/sigar/ProcCpu.java
     [exec] skipping org/hyperic/sigar/CpuPerc.java
     [exec] generating org/hyperic/sigar/NetInfo.java
     [exec] generating org/hyperic/sigar/Mem.java
     [exec] generating org/hyperic/sigar/NfsServerV3.java
     [exec] generating org/hyperic/sigar/DirStat.java
     [exec] generating org/hyperic/sigar/ProcTime.java
     [exec] generating org/hyperic/sigar/ProcStat.java
     [exec] generating org/hyperic/sigar/ThreadCpu.java
     [exec] generating org/hyperic/sigar/ProcFd.java
     [exec] generating org/hyperic/sigar/CpuInfo.java
     [exec] generating org/hyperic/sigar/Arp.java
     [exec] generating org/hyperic/sigar/NetRoute.java
     [exec] generating org/hyperic/sigar/FileSystem.java
     [exec] generating org/hyperic/sigar/NetInterfaceStat.java
     [exec] generating org/hyperic/sigar/ProcDiskIO.java
     [exec] generating org/hyperic/sigar/NetInterfaceConfig.java
     [exec] generating org/hyperic/sigar/Uptime.java
     [exec] generating org/hyperic/sigar/DumpPidCache.java
     [exec] generating org/hyperic/sigar/Tcp.java
     [exec] generating org/hyperic/sigar/Cpu.java
     [exec] generating org/hyperic/sigar/Swap.java
     [exec] generating org/hyperic/sigar/ProcCredName.java
     [exec] generating org/hyperic/sigar/NfsClientV3.java
     [exec] generating org/hyperic/sigar/DiskUsage.java
     [exec] generating org/hyperic/sigar/FileAttrs.java
     [exec] generating org/hyperic/sigar/Who.java
     [exec] generating org/hyperic/sigar/DirUsage.java
     [exec] skipping org/hyperic/sigar/NetStat.java
     [exec] generating org/hyperic/sigar/NfsServerV2.java
     [exec] generating org/hyperic/sigar/ProcState.java
     [exec] generating org/hyperic/sigar/ProcMem.java
     [exec] generating org/hyperic/sigar/ResourceLimit.java

jni-compile:

jni-cc:
    [mkdir] Created dir: C:\sigar\bindings\java\build\obj\amd64-winnt\lib
     [echo] jni libname=sigar-amd64-winnt
       [cc] 22 total files to be compiled.
       [cc] eventlog.c
       [cc] C:\sigar\bindings\java\src\jni\win32\eventlog.c(133): error C2198: 'wcstok': too few arguments for call
       [cc] C:\sigar\bindings\java\src\jni\win32\eventlog.c(153): error C2198: 'wcstok': too few arguments for call
       [cc] sigar_fileinfo.c
       [cc] C:\sigar\src\sigar_fileinfo.c(419): warning C4293: '<<': shift count negative or too big, undefined behavior
       [cc] javavmware.c
       [cc] win32_sigar.c
       [cc] C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(1933): warning C4005: 'snprintf': macro redefinition
       [cc] C:\sigar\src\os\win32\sigar_os.h(28): note: see previous definition of 'snprintf'
       [cc] C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(1935): fatal error C1189: #error:  Macro definition of snprintf conflicts with Standard Library function declaration
       [cc] sigar_signal.c
       [cc] sigar.c
       [cc] sigar_ptql.c
       [cc] C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(1933): warning C4005: 'snprintf': macro redefinition
       [cc] C:\sigar\src\os\win32\sigar_os.h(28): note: see previous definition of 'snprintf'
       [cc] C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(1935): fatal error C1189: #error:  Macro definition of snprintf conflicts with Standard Library function declaration
       [cc] Generating Code...
       [cc] Compiling...
       [cc] nls.cpp
       [cc] Generating Code...
       [cc] Compiling...
       [cc] sigar_cache.c
       [cc] sigar_util.c
       [cc] javasigar.c
       [cc] sigar_getline.c
       [cc] sigar_format.c
       [cc] C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(1933): warning C4005: 'snprintf': macro redefinition
       [cc] C:\sigar\src\os\win32\sigar_os.h(28): note: see previous definition of 'snprintf'
       [cc] C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(1935): fatal error C1189: #error:  Macro definition of snprintf conflicts with Standard Library function declaration
       [cc] peb.c
       [cc] C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(1933): warning C4005: 'snprintf': macro redefinition
       [cc] C:\sigar\src\os\win32\sigar_os.h(28): note: see previous definition of 'snprintf'
       [cc] C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(1935): fatal error C1189: #error:  Macro definition of snprintf conflicts with Standard Library function declaration
       [cc] sigar_version.c
       [cc] pdh.c
       [cc] Generating Code...
       [cc] Compiling...
       [cc] service.cpp
       [cc] registrykey.cpp
       [cc] Generating Code...
       [cc] Compiling...
       [cc] util.c
       [cc] vmcontrol_wrapper.c
       [cc] Generating Code...
       [cc] Compiling...
       [cc] metabase.cpp
       [cc] wmi.cpp
       [cc] Generating Code...

BUILD FAILED
C:\sigar\bindings\java\hyperic_jni\jni-build.xml:224: The following error occurred while executing this line:
C:\sigar\bindings\java\hyperic_jni\jni-build.xml:270: cl failed with return code 2

i'm probably using too new of stuff.

@cnstar9988
Copy link
Author

cnstar9988 commented Dec 9, 2020

I use VS2010, both test ok.

when buid sigar-amd64-winnt dll, I use "Visual Studio x64 Win64 Command Prompt (2010)"
it works ok.

@cnstar9988
Copy link
Author

you can build sigar with vs2010.
or modify some code in eventlog.c because wcstok changed (just for build OK, win32 event log call faild in win32_set_pointer)

WCHAR *rowstate;
ptr = wcstok(msgdll, FILESEP, &rowstate);

https://docs.microsoft.com/en-us/cpp/porting/visual-cpp-change-history-2003-2015?view=msvc-160

orignal filename sigar-amd64-winnt.dll
md5: ADEEB56EB62E4929440B9A7F52EFDFE4 
sha1: B0A070DC77D6F4751C39DF13CF1A9FC4775B8933
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sigar crashes JDK 1.8 jvm after latest Windows Patches
5 participants