Ver Fonte

- remove packed directive from jwapsapi.pas, partly resolves #20525
+ test from bug report
- remove $A+ from jedi include header: $A+ makes no sense for api headers, the records should be layouted with $packrecords c, second part to resolve #20525

git-svn-id: trunk@19533 -

florian há 14 anos atrás
pai
commit
85b52cf8c3

+ 1 - 0
.gitattributes

@@ -6766,6 +6766,7 @@ packages/winunits-jedi/src/jwawsrm.pas svneol=native#text/plain
 packages/winunits-jedi/src/jwawsvns.pas svneol=native#text/plain
 packages/winunits-jedi/src/jwawtsapi32.pas svneol=native#text/plain
 packages/winunits-jedi/src/jwazmouse.pas svneol=native#text/plain
+packages/winunits-jedi/tests/tjwapsapi1.pp svneol=native#text/pascal
 packages/x11/Makefile svneol=native#text/plain
 packages/x11/Makefile.fpc svneol=native#text/plain
 packages/x11/fpmake.pp svneol=native#text/plain

+ 2 - 2
packages/winunits-jedi/src/jediapilib.inc

@@ -35,7 +35,7 @@
 { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
 {                                                                              }
 {******************************************************************************}
-{$A+,Z4}
+{$Z4}
 
 // This file is intended for C header conversions.
 // It defines several mutually exclusive IFDEFs which determine
@@ -329,4 +329,4 @@ Standalone compiling would be useless!
  {$DEFINE HTMLHELP11_UP}
 {$ENDIF HTMLHELP11}
 
-{$ENDIF ~JEDIAPILIB_INC}
+{$ENDIF ~JEDIAPILIB_INC}

+ 3 - 3
packages/winunits-jedi/src/jwapsapi.pas

@@ -92,7 +92,7 @@ function GetModuleFileNameEx(hProcess: HANDLE; hModule: HMODULE; lpFilename: LPT
 type
   LPMODULEINFO = ^MODULEINFO;
   {$EXTERNALSYM LPMODULEINFO}
-  _MODULEINFO = packed record
+  _MODULEINFO = record
     lpBaseOfDll: LPVOID;
     SizeOfImage: DWORD;
     EntryPoint: LPVOID;
@@ -119,7 +119,7 @@ function InitializeProcessForWsWatch(hProcess: HANDLE): BOOL; stdcall;
 type
   PPSAPI_WS_WATCH_INFORMATION = ^PSAPI_WS_WATCH_INFORMATION;
   {$EXTERNALSYM PPSAPI_WS_WATCH_INFORMATION}
-  _PSAPI_WS_WATCH_INFORMATION = packed record
+  _PSAPI_WS_WATCH_INFORMATION = record
     FaultingPc: LPVOID;
     FaultingVa: LPVOID;
   end;
@@ -171,7 +171,7 @@ function GetDeviceDriverFileName(ImageBase: LPVOID; lpFilename: LPTSTR;
 type
   PPROCESS_MEMORY_COUNTERS = ^PROCESS_MEMORY_COUNTERS;
   {$EXTERNALSYM PPROCESS_MEMORY_COUNTERS}
-  _PROCESS_MEMORY_COUNTERS = packed record
+  _PROCESS_MEMORY_COUNTERS = record
     cb: DWORD;
     PageFaultCount: DWORD;
     PeakWorkingSetSize: SIZE_T;

+ 80 - 0
packages/winunits-jedi/tests/tjwapsapi1.pp

@@ -0,0 +1,80 @@
+program winmoduleinfo_test;
+
+{$mode objfpc}{$H+}
+
+uses
+  SysUtils,
+  Classes,
+  windows,
+  jwapsapi;
+
+  function GetModuleName(
+    const pHandle : HANDLE;
+    const mHandle : HMODULE)
+    : string;
+  var
+    name : array [0..1023] of char;
+  begin
+    result := 'ERROR';
+    if GetModuleFileNameEx(pHandle,mHandle,LPTSTR(@name[0]),sizeof(name)) > 0 then begin
+      result := name;
+    end;
+  end;
+
+  procedure WriteModuleInfo(
+    const pHandle : HANDLE;
+    const mHandle : HANDLE);
+  var
+    moduleHandle : HANDLE;
+    modInfo: MODULEINFO;
+    moduleName : string;
+    tmpBeginning : ptruint;
+    tmpEnding : ptruint;
+    success : boolean;
+    lastError : DWORD;
+  begin
+    moduleHandle := mHandle;
+
+    success := (GetModuleInformation(pHandle,moduleHandle,modInfo,sizeof(MODULEINFO)) = WINBOOL(true));
+    if success then begin
+      lastError := 0;
+    end else begin
+      lastError := GetLastError();
+      modInfo.lpBaseOfDll := nil;
+      modInfo.SizeOfImage := 0;
+    end;
+
+    tmpBeginning := ptruint(modInfo.lpBaseOfDll);
+    tmpEnding := tmpBeginning + modInfo.SizeOfImage;
+    moduleName := GetModuleName(pHandle,mHandle);
+    writeln(ExtractFileName(moduleName), ' error=', lastError,
+            '; from 0x', IntToHex(tmpBeginning, sizeof(tmpBeginning)*2),
+            ' to 0x', IntToHex(tmpBeginning, sizeof(tmpEnding)*2));
+    if lastError<>0 then
+      halt(1);
+  end;
+
+var
+  pHandle : HANDLE;
+  mHandles : array [0..1023] of HMODULE;
+  cbNeeded : DWORD;
+  n : integer;
+  i : integer;
+begin
+  pHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
+                         WINBOOL(false),
+                         GetCurrentProcessID);
+  if pHandle <> 0 then begin
+    try
+      if EnumProcessModules(pHandle,@mHandles[0],sizeof(mHandles),cbNeeded) = WINBOOL(true) then begin
+        n := cbNeeded div sizeof(HMODULE);
+        for i := 0 to n-1 do begin
+          WriteModuleInfo(pHandle, mHandles[i]);
+        end;
+      end;
+    finally
+      CloseHandle(pHandle);
+    end;
+  end;
+  writeln('ok');
+end.