Browse Source

--- Merging r25168 into '.':
U packages/winunits-jedi/src/jwawindows.pas
--- Merging r25226 into '.':
U packages/sdl/src/sdl_net.pas
--- Merging r25230 into '.':
U utils/instantfpc/instantfptools.pas
U utils/instantfpc/instantfpc.pas
U utils/instantfpc/instantfpc.lpi
--- Merging r25341 into '.':
U packages/fcl-net/src/ssockets.pp
--- Merging r25574 into '.':
U rtl/win/wininc/base.inc
--- Merging r25639 into '.':
U rtl/win/wininc/messages.inc
--- Merging r25708 into '.':
U packages/openssl/src/openssl.pas
--- Merging r25709 into '.':
A packages/openssl/examples/genkeypair.lpr
U packages/openssl/examples/Makefile
A packages/openssl/examples/genkeypair.lpi

# revisions: 25168,25226,25230,25341,25574,25639,25708,25709
r25168 | marco | 2013-07-24 16:24:36 +0200 (Wed, 24 Jul 2013) | 4 lines
Changed paths:
M /trunk/packages/winunits-jedi/src/jwawindows.pas

* workaround for Lazarus include file browsing bug (Mantis #24778).
Committed because it is very unintrusive and actually improves the style
of the unit, though in essence it is a lazarus problem.
r25226 | marco | 2013-08-07 17:36:12 +0200 (Wed, 07 Aug 2013) | 2 lines
Changed paths:
M /trunk/packages/sdl/src/sdl_net.pas

* fix for Mantis #24834 sockets field in SDLNET_SOCKETSET is double pointer.
r25230 | mattias | 2013-08-09 14:02:15 +0200 (Fri, 09 Aug 2013) | 1 line
Changed paths:
M /trunk/utils/instantfpc/instantfpc.lpi
M /trunk/utils/instantfpc/instantfpc.pas
M /trunk/utils/instantfpc/instantfptools.pas

instantfpc: version 1.3: compile into temporary directory to avoid clashes in parallel compilations
r25341 | michael | 2013-08-23 16:27:23 +0200 (Fri, 23 Aug 2013) | 1 line
Changed paths:
M /trunk/packages/fcl-net/src/ssockets.pp

* Handle EINTR for read/Write operations
r25574 | paul | 2013-09-26 05:51:06 +0200 (Thu, 26 Sep 2013) | 1 line
Changed paths:
M /trunk/rtl/win/wininc/base.inc

rtl: add/change some token related types
r25639 | marco | 2013-10-04 20:24:16 +0200 (Fri, 04 Oct 2013) | 1 line
Changed paths:
M /trunk/rtl/win/wininc/messages.inc

* fix for mantis #24920 try to properly update messages unit for win64.
r25708 | michael | 2013-10-07 09:27:12 +0200 (Mon, 07 Oct 2013) | 1 line
Changed paths:
M /trunk/packages/openssl/src/openssl.pas

* Added some constants and encoding functions.
r25709 | michael | 2013-10-07 09:51:53 +0200 (Mon, 07 Oct 2013) | 1 line
Changed paths:
M /trunk/packages/openssl/examples/Makefile
A /trunk/packages/openssl/examples/genkeypair.lpi
A /trunk/packages/openssl/examples/genkeypair.lpr

* Example how to create public/private RSA key

git-svn-id: branches/fixes_2_6@25763 -

marco 12 years ago
parent
commit
c32a051939

+ 2 - 0
.gitattributes

@@ -5466,6 +5466,8 @@ packages/opengles/src/gles20.pas svneol=native#text/pascal
 packages/openssl/Makefile svneol=native#text/plain
 packages/openssl/Makefile.fpc svneol=native#text/plain
 packages/openssl/examples/Makefile svneol=native#text/plain
+packages/openssl/examples/genkeypair.lpi svneol=native#text/plain
+packages/openssl/examples/genkeypair.lpr svneol=native#text/plain
 packages/openssl/examples/test1.pas svneol=native#text/plain
 packages/openssl/fpmake.pp svneol=native#text/plain
 packages/openssl/src/openssl.pas svneol=native#text/plain

+ 23 - 11
packages/fcl-net/src/ssockets.pp

@@ -116,6 +116,7 @@ type
     Procedure StopAccepting(DoAbort : Boolean = False);
     Procedure SetNonBlocking;
     Property Bound : Boolean Read FBound;
+    // Maximium number of connections in total. *Not* the simultaneous connection count. -1 keeps accepting.
     Property MaxConnections : longint Read FMaxConnections Write FMaxConnections;
     Property QueueSize : Longint Read FQueueSize Write FQueueSize default 5;
     Property OnConnect : TConnectEvent Read FOnConnect Write FOnConnect;
@@ -279,11 +280,17 @@ Var
 
 begin
   Flags:=FReadFlags;
-  Result:=fprecv(handle,@Buffer,count,flags);
-  If Result<0 then
-    FLastError:=SocketError
-  else
-    FLastError:=0;
+{$ifdef unix}
+  Repeat
+{$endif}
+    Result:=fprecv(handle,@Buffer,count,flags);
+    If Result<0 then
+      FLastError:=SocketError
+    else
+      FLastError:=0;
+{$ifdef unix}
+  Until (FlastError<>ESysEINTR);
+{$ENDIF}
 end;
 
 Function TSocketStream.Write (Const Buffer; Count : Longint) :Longint;
@@ -293,11 +300,17 @@ Var
 
 begin
   Flags:=FWriteFlags;
-  Result:=fpsend(handle,@Buffer,count,flags);
-  If Result<0 then
-    FLastError:=SocketError
-  else
-    FlastError:=0;
+{$ifdef unix}
+  Repeat
+{$endif}
+    Result:=fpsend(handle,@Buffer,count,flags);
+    If Result<0 then
+      FLastError:=SocketError
+    else
+      FlastError:=0;
+{$ifdef unix}
+  Until (FlastError<>ESysEINTR);
+{$ENDIF}
 end;
 
 function TSocketStream.GetLocalAddress: TSockAddr;
@@ -387,7 +400,6 @@ Function TSocketServer.GetConnection : TSocketStream;
 
 var
   NewSocket : longint;
-  r,w,e : pfdset;
 
 begin
   Result:=Nil;

+ 2 - 1
packages/openssl/examples/Makefile

@@ -3,7 +3,8 @@ ARGS=-O2 -XX -Xs
 DELP=delp
 
 all:
-	$(PP) $(ARGS) test1.pas
+	$(PP) $(ARGS) -Fu../src test1.pas
+	$(PP) $(ARGS) -Fu../src genkeypair.lpr
 
 clean:
 	$(DELP) .

+ 69 - 0
packages/openssl/examples/genkeypair.lpi

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="9"/>
+    <General>
+      <Flags>
+        <MainUnitHasCreateFormStatements Value="False"/>
+        <MainUnitHasTitleStatement Value="False"/>
+      </Flags>
+      <SessionStorage Value="InProjectDir"/>
+      <MainUnit Value="0"/>
+      <Title Value="genkeypair"/>
+      <UseAppBundle Value="False"/>
+      <ResourceType Value="res"/>
+    </General>
+    <i18n>
+      <EnableI18N LFM="False"/>
+    </i18n>
+    <VersionInfo>
+      <StringTable ProductVersion=""/>
+    </VersionInfo>
+    <BuildModes Count="1">
+      <Item1 Name="Default" Default="True"/>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+    </PublishOptions>
+    <RunParams>
+      <local>
+        <FormatVersion Value="1"/>
+      </local>
+    </RunParams>
+    <Units Count="1">
+      <Unit0>
+        <Filename Value="genkeypair.lpr"/>
+        <IsPartOfProject Value="True"/>
+        <UnitName Value="genkeypair"/>
+      </Unit0>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <OtherUnitFiles Value="../src"/>
+    </SearchPaths>
+    <Parsing>
+      <SyntaxOptions>
+        <UseAnsiStrings Value="False"/>
+      </SyntaxOptions>
+    </Parsing>
+    <Other>
+      <CompilerPath Value="$(CompPath)"/>
+    </Other>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions Count="3">
+      <Item1>
+        <Name Value="EAbort"/>
+      </Item1>
+      <Item2>
+        <Name Value="ECodetoolError"/>
+      </Item2>
+      <Item3>
+        <Name Value="EFOpenError"/>
+      </Item3>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 107 - 0
packages/openssl/examples/genkeypair.lpr

@@ -0,0 +1,107 @@
+{$mode objfpc}
+{$h+}
+program genkeypair;
+
+uses sysutils, openssl;
+
+// This is normally only used when you specify a cipher for encoding the private key.
+
+function PasswordCallback(buf:PAnsiChar; size:Integer; rwflag:Integer; userdata: Pointer):Integer; cdecl;
+
+begin
+  Result:=0;
+  Buf^:=#0;
+end;
+
+procedure DoKey(Const FNPrivate, FNPublic : String; AKeySize : Integer = 1024);
+
+  Procedure RaiseErr(Const Msg : String);
+
+  Var
+    Err : String;
+
+  begin
+    SetLength(Err,1024);
+    ErrErrorString(ErrGetError,Err,1024);
+    Raise Exception.Create(Msg+' : '+Err);
+  end;
+
+  Function GetKey(K : pBIO) : String;
+
+  Var
+    L : Integer;
+    p : pchar;
+
+  begin
+    l:=BIO_ctrl(K,BIO_CTRL_INFO,0,PChar(@P));
+    setlength(Result,l);
+    move(P^,Result[1],l);
+  end;
+
+  Procedure WriteKey(Const FN,Key : String);
+
+  Var
+    F : Text;
+
+  begin
+    Assign(F,FN);
+    Rewrite(F);
+    try
+      Write(F,Key);
+    finally
+      Close(F);
+    end;
+  end;
+
+
+Var
+  rsa: PRSA;
+  PK :PEVP_PKEY;
+  PrivKey, PubKey: pBIO;
+  Key : string;
+
+begin
+  InitLibeaInterface(true);
+  InitSSLEAInterface(true);
+  InitSSLInterface(true);
+  ERR_load_crypto_strings;
+  OpenSSL_add_all_ciphers;
+  pk := EvpPkeynew;
+  if (pk=Nil) then
+    Raise exception.Create('Could not create key structure.');
+  rsa:=RsaGenerateKey(AKeySize,$10001,Nil,Nil);
+  if rsa=nil then
+    Raise exception.Create('Could not create RSA key.');
+  if EvpPkeyAssign(pk, EVP_PKEY_RSA, rsa)=0 then
+    Raise exception.Create('Could not assign created RSA key to key structure.');
+  // Generate private key
+  PrivKey:=BIOnew(BIOsmem);
+  if PrivKey=Nil then
+    Raise exception.Create('Could not allocate BIO structure for private key.');
+  try
+    if PEM_write_bio_PrivateKey(PrivKey, PK, nil, nil, 0, @PasswordCallBack, Nil)=0 then
+      RaiseErr('Could not write private key');
+    Key:=GetKey(PrivKey);
+    WriteKey(FNPrivate,Key);
+  finally
+    BioFreeAll(PrivKey);
+  end;
+  // Get public key
+  PubKey:= BIOnew(BIOsmem);
+  if PubKey=Nil then
+    Raise exception.Create('Could not allocate BIO structure for public key.');
+  try
+    if PEM_write_bio_PubKey(PubKey,PK)=0 then
+      RaiseErr('Could not write public key');
+    Key:=GetKey(PubKey);
+    WriteKey(FNPublic,Key);
+  finally
+    BioFreeAll(PubKey);
+  end;
+end;
+
+begin
+  writeln('Writing private/public key of length 1024 to id_rsa/id_rsa.pub');
+  DoKey('id_rsa','id_rsa.pub',1024);
+end.
+

+ 233 - 0
packages/openssl/src/openssl.pas

@@ -604,6 +604,51 @@ const
   BIO_C_SET_EX_ARG		= 153;
   BIO_C_GET_EX_ARG		= 154;
 
+  BIO_CTRL_RESET  =    1  ; { opt - rewind/zero etc }
+  BIO_CTRL_EOF    =    2  ; { opt - are we at the eof }
+  BIO_CTRL_INFO   =     3  ; { opt - extra tit-bits }
+  BIO_CTRL_SET    =     4  ; { man - set the 'IO' type }
+  BIO_CTRL_GET    =     5  ; { man - get the 'IO' type }
+  BIO_CTRL_PUSH   =     6  ; { opt - internal, used to signify change }
+  BIO_CTRL_POP    =     7  ; { opt - internal, used to signify change }
+  BIO_CTRL_GET_CLOSE =  8  ; { man - set the 'close' on free }
+  BIO_CTRL_SET_CLOSE =  9  ; { man - set the 'close' on free }
+  BIO_CTRL_PENDING   =  10  ; { opt - is their more data buffered }
+  BIO_CTRL_FLUSH     =  11  ; { opt - 'flush' buffered output }
+  BIO_CTRL_DUP       =  12  ; { man - extra stuff for 'duped' BIO }
+  BIO_CTRL_WPENDING  =  13  ; { opt - number of bytes still to write }
+  BIO_CTRL_SET_CALLBACK   = 14  ; { opt - set callback function }
+  BIO_CTRL_GET_CALLBACK   = 15  ; { opt - set callback function }
+  BIO_CTRL_SET_FILENAME   = 30  ; { BIO_s_file special }
+  BIO_CTRL_DGRAM_CONNECT  = 31  ; { BIO dgram special }
+  BIO_CTRL_DGRAM_SET_CONNECTED      = 32  ; { allow for an externally }
+  BIO_CTRL_DGRAM_SET_RECV_TIMEOUT   = 33 ; { setsockopt, essentially }
+  BIO_CTRL_DGRAM_GET_RECV_TIMEOUT   = 34 ; { getsockopt, essentially }
+  BIO_CTRL_DGRAM_SET_SEND_TIMEOUT   = 35 ; { setsockopt, essentially }
+  BIO_CTRL_DGRAM_GET_SEND_TIMEOUT   = 36 ; { getsockopt, essentially }
+  BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP = 37 ; { flag whether the last }
+  BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP = 38 ; { I/O operation tiemd out }
+  BIO_CTRL_DGRAM_MTU_DISCOVER       = 39 ; { set DF bit on egress packets }
+  BIO_CTRL_DGRAM_QUERY_MTU          = 40 ; { as kernel for current MTU }
+  BIO_CTRL_DGRAM_GET_FALLBACK_MTU   = 47 ;
+  BIO_CTRL_DGRAM_GET_MTU            = 41 ; { get cached value for MTU }
+  BIO_CTRL_DGRAM_SET_MTU            = 42 ; { set cached value for }
+  BIO_CTRL_DGRAM_MTU_EXCEEDED       = 43 ; { check whether the MTU }
+  BIO_CTRL_DGRAM_GET_PEER           = 46 ;
+  BIO_CTRL_DGRAM_SET_PEER           = 44 ; { Destination for the data }
+  BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT   = 45 ; { Next DTLS handshake timeout to }
+  BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE = 50;
+  BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY     = 51;
+  BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY    = 52;
+  BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD    = 53;
+  BIO_CTRL_DGRAM_SCTP_GET_SNDINFO      = 60;
+  BIO_CTRL_DGRAM_SCTP_SET_SNDINFO      = 61;
+  BIO_CTRL_DGRAM_SCTP_GET_RCVINFO      = 62;
+  BIO_CTRL_DGRAM_SCTP_SET_RCVINFO      = 63;
+  BIO_CTRL_DGRAM_SCTP_GET_PRINFO       = 64;
+  BIO_CTRL_DGRAM_SCTP_SET_PRINFO       = 65;
+  BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN    = 70;
+
 //DES modes
   DES_ENCRYPT = 1;
   DES_DECRYPT = 0;
@@ -779,6 +824,23 @@ var
   function SSLeay_version(t: cint): PChar;
 
   // EVP Functions - evp.h
+  function EVP_des_ede3_cbc : PEVP_CIPHER;
+  Function EVP_enc_null : PEVP_CIPHER;
+  Function EVP_rc2_cbc : PEVP_CIPHER;
+  Function EVP_rc2_40_cbc : PEVP_CIPHER;
+  Function EVP_rc2_64_cbc : PEVP_CIPHER;
+  Function EVP_rc4 : PEVP_CIPHER;
+  Function EVP_rc4_40 : PEVP_CIPHER;
+  Function EVP_des_cbc : PEVP_CIPHER;
+  Function EVP_aes_128_cbc : PEVP_CIPHER;
+  Function EVP_aes_192_cbc : PEVP_CIPHER;
+  Function EVP_aes_256_cbc : PEVP_CIPHER;
+  Function EVP_aes_128_cfb8 : PEVP_CIPHER;
+  Function EVP_aes_192_cfb8 : PEVP_CIPHER;
+  Function EVP_aes_256_cfb8 : PEVP_CIPHER;
+  Function EVP_camellia_128_cbc : PEVP_CIPHER;
+  Function EVP_camellia_192_cbc : PEVP_CIPHER;
+  Function EVP_camellia_256_cbc : PEVP_CIPHER;
 
   procedure OpenSSL_add_all_algorithms;
   procedure OpenSSL_add_all_ciphers;
@@ -1022,6 +1084,7 @@ type
   TEVP_VerifyFinal = function(ctx: pEVP_MD_CTX; sigbuf: pointer;
     siglen: cardinal; pkey: pEVP_PKEY): integer;  cdecl;
   //
+  TEVP_CIPHERFunction = function() : PEVP_CIPHER; cdecl;
   TEVP_get_cipherbyname = function(const name: PChar): PEVP_CIPHER; cdecl;
   TEVP_get_digestbyname = function(const name: PChar): PEVP_MD; cdecl;
   //
@@ -1149,6 +1212,23 @@ var
   _Asn1UtctimeFree: TAsn1UtctimeFree = nil;
   _i2dX509bio: Ti2dX509bio = nil;
   _i2dPrivateKeyBio: Ti2dPrivateKeyBio = nil;
+  _EVP_enc_null : TEVP_CIPHERFunction = nil;
+  _EVP_rc2_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_rc2_40_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_rc2_64_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_rc4 : TEVP_CIPHERFunction = nil;
+  _EVP_rc4_40 : TEVP_CIPHERFunction = nil;
+  _EVP_des_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_des_ede3_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_aes_128_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_aes_192_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_aes_256_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_aes_128_cfb8 : TEVP_CIPHERFunction = nil;
+  _EVP_aes_192_cfb8 : TEVP_CIPHERFunction = nil;
+  _EVP_aes_256_cfb8 : TEVP_CIPHERFunction = nil;
+  _EVP_camellia_128_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_camellia_192_cbc : TEVP_CIPHERFunction = nil;
+  _EVP_camellia_256_cbc : TEVP_CIPHERFunction = nil;
 
   // 3DES functions
   _DESsetoddparity: TDESsetoddparity = nil;
@@ -2259,6 +2339,142 @@ end;
 
 // EVP Functions
 
+function EVP_des_ede3_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_des_ede3_cbc) then
+    Result := _EVP_des_ede3_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_enc_null: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_enc_null) then
+    Result := _EVP_enc_null()
+  else
+    Result := Nil;
+end;
+
+function EVP_rc2_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_rc2_cbc) then
+    Result := _EVP_rc2_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_rc2_40_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_rc2_40_cbc) then
+    Result := _EVP_rc2_40_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_rc2_64_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_rc2_64_cbc) then
+    Result := _EVP_rc2_64_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_rc4: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_rc4) then
+    Result := _EVP_rc4()
+  else
+    Result := Nil;
+end;
+
+function EVP_rc4_40: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_rc4_40) then
+    Result := _EVP_rc4_40()
+  else
+    Result := Nil;
+end;
+
+function EVP_des_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_des_cbc) then
+    Result := _EVP_des_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_aes_128_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_aes_128_cbc) then
+    Result := _EVP_aes_128_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_aes_192_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_aes_192_cbc) then
+    Result := _EVP_aes_192_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_aes_256_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_aes_256_cbc) then
+    Result := _EVP_aes_256_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_aes_128_cfb8: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_aes_128_cfb8) then
+    Result := _EVP_aes_128_cfb8()
+  else
+    Result := Nil;
+end;
+
+function EVP_aes_192_cfb8: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_aes_192_cfb8) then
+    Result := _EVP_aes_192_cfb8()
+  else
+    Result := Nil;
+end;
+
+function EVP_aes_256_cfb8: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_aes_256_cfb8) then
+    Result := _EVP_aes_256_cfb8()
+  else
+    Result := Nil;
+end;
+
+function EVP_camellia_128_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_camellia_128_cbc) then
+    Result := _EVP_camellia_128_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_camellia_192_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_camellia_192_cbc) then
+    Result := _EVP_camellia_192_cbc()
+  else
+    Result := Nil;
+end;
+
+function EVP_camellia_256_cbc: PEVP_CIPHER;
+begin
+  if InitlibeaInterface and Assigned(_EVP_camellia_256_cbc) then
+    Result := _EVP_camellia_256_cbc()
+  else
+    Result := Nil;
+end;
+
 procedure OpenSSL_add_all_algorithms;
 begin
   if InitlibeaInterface and Assigned(_OpenSSL_add_all_algorithms) then
@@ -2701,6 +2917,23 @@ begin
         _Asn1UtctimeFree := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_free', AVerboseLoading);
         _i2dX509bio := GetProcAddr(SSLUtilHandle, 'i2d_X509_bio', AVerboseLoading);
         _i2dPrivateKeyBio := GetProcAddr(SSLUtilHandle, 'i2d_PrivateKey_bio', AVerboseLoading);
+        _EVP_enc_null := GetProcAddr(SSLUtilHandle, 'EVP_enc_null', AVerboseLoading);;
+        _EVP_rc2_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_cbc', AVerboseLoading);;
+        _EVP_rc2_40_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_40_cbc', AVerboseLoading);;
+        _EVP_rc2_64_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_64_cbc', AVerboseLoading);;
+        _EVP_rc4 := GetProcAddr(SSLUtilHandle, 'EVP_rc4', AVerboseLoading);;
+        _EVP_rc4_40 := GetProcAddr(SSLUtilHandle, 'EVP_rc4_40', AVerboseLoading);;
+        _EVP_des_cbc := GetProcAddr(SSLUtilHandle, 'EVP_des_cbc', AVerboseLoading);;
+        _EVP_des_ede3_cbc := GetProcAddr(SSLUtilHandle, 'EVP_des_ede3_cbc', AVerboseLoading);;
+        _EVP_aes_128_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_128_cbc', AVerboseLoading);;
+        _EVP_aes_192_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_192_cbc', AVerboseLoading);;
+        _EVP_aes_256_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_256_cbc', AVerboseLoading);;
+        _EVP_aes_128_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_128_cfb8', AVerboseLoading);;
+        _EVP_aes_192_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_192_cfb8', AVerboseLoading);;
+        _EVP_aes_256_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_256_cfb8', AVerboseLoading);;
+        _EVP_camellia_128_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_128_cbc', AVerboseLoading);;
+        _EVP_camellia_192_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_192_cbc', AVerboseLoading);;
+        _EVP_camellia_256_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_256_cbc', AVerboseLoading);;
 
         // 3DES functions
         _DESsetoddparity := GetProcAddr(SSLUtilHandle, 'des_set_odd_parity', AVerboseLoading);

+ 2 - 1
packages/sdl/src/sdl_net.pas

@@ -258,11 +258,12 @@ type
 {$ENDIF}
   end;
 
+  PPSDLNet_Socket = ^PSDLNet_Socket;
   PSDLNet_SocketSet = ^TSDLNet_SocketSet;
   TSDLNet_SocketSet = record
     numsockets : integer;
     maxsockets : integer;
-    sockets : PSDLNet_Socket;
+    sockets : PPSDLNet_Socket;
   end;
 
   {* Any network socket can be safely cast to this socket type *}

+ 6 - 6
packages/winunits-jedi/src/jwawindows.pas

@@ -363,9 +363,9 @@ The list has no order!}
 {$I JwaAccCtrl.pas}
 {$I JwaAclApi.pas}
 {$I JwaSddl.pas}
-{$I JwaLmErr}
-{$I JwaLmCons}
-{$I JwaNtSecApi}
+{$I JwaLmErr.pas}
+{$I JwaLmCons.pas}
+{$I JwaNtSecApi.pas}
 {$I JwaWinCred.pas}
 {$I JwaWtsApi32.pas}
 {$I JwaWinIoctl.pas}
@@ -687,9 +687,9 @@ The list has no order!}
 {$I JwaAccCtrl.pas}
 {$I JwaAclApi.pas}
 {$I JwaSddl.pas}
-{$I JwaLmErr}
-{$I JwaLmCons}
-{$I JwaNtSecApi}
+{$I JwaLmErr.pas}
+{$I JwaLmCons.pas}
+{$I JwaNtSecApi.pas}
 {$I JwaWinCred.pas}
 {$I JwaWtsApi32.pas}
 {$I JwaWinIoctl.pas}

+ 21 - 5
rtl/win/wininc/base.inc

@@ -333,6 +333,21 @@
 
      _SID_NAME_USE = SID_NAME_USE;
 
+     TOKEN_TYPE = (
+       TokenPrimary = 1,
+       TokenImpersonation
+     );
+     _TOKEN_TYPE = TOKEN_TYPE;
+     TTokenType = TOKEN_TYPE;
+
+     TOKEN_ELEVATION_TYPE = (
+       TokenElevationTypeDefault = 1,
+       TokenElevationTypeFull,
+       TokenElevationTypeLimited
+     );
+     _TOKEN_ELEVATION_TYPE = TOKEN_ELEVATION_TYPE;
+     TTokenElevationType = TOKEN_ELEVATION_TYPE;
+
      TOKEN_INFORMATION_CLASS = (
        TokenUser = 1,
        TokenGroups,
@@ -364,14 +379,15 @@
        TokenLogonSid,
        MaxTokenInfoClass  // MaxTokenInfoClass should always be the last enum
      );
-
      _TOKEN_INFORMATION_CLASS = TOKEN_INFORMATION_CLASS;
      TTokenInformationClass   = TOKEN_INFORMATION_CLASS;
 
-     TOKEN_TYPE = (TokenPrimary := 1,TokenImpersonation
-       );
-
-     tagTOKEN_TYPE = TOKEN_TYPE;
+     _TOKEN_ELEVATION = record
+       TokenIsElevated: DWORD;
+     end;
+     TOKEN_ELEVATION = _TOKEN_ELEVATION;
+     TTokenElevation = _TOKEN_ELEVATION;
+     PTokenElevation = ^TTokenElevation;
 
     _FINDEX_INFO_LEVELS = (FindExInfoStandard,FindExInfoBasic,FindExInfoMaxInfoLevel);
     _FINDEX_SEARCH_OPS  = (FindExSearchNameMatch, FindExSearchLimitToDirectories,

+ 160 - 61
rtl/win/wininc/messages.inc

@@ -1298,15 +1298,9 @@
     TWMCopy             = Windows.TWMCopy;
 {$else}
 
-{$ifdef cpu64}
-     HALFLRESULT = DWORD;
-     HALFPARAM = DWORD;
-     HALFPARAMBOOL = LONGBOOL;
-{$else}
-     HALFLRESULT = WORD;
-     HALFPARAM = WORD;
+     HALFLRESULT   = WORD;     // in win64, these remain 16-bit. the extra room is unused.
+     HALFPARAM     = WORD;
      HALFPARAMBOOL = WORDBOOL;
-{$endif}
 
      MSG = record
           hwnd : HWND;
@@ -1322,10 +1316,19 @@
      TMSG = MSG;
      PMSG = ^MSG;
 
+     // define a type for a field that only takes space if 64-bit.
+     TDWordFiller = record
+                       {$ifdef CPU64}
+                         filler : array[0..3] of byte;
+	               {$endif}
+                    end;
+
 
      PMessage = ^TMessage;
-     TMessage = record       {fields according to ICS}
+     TMessage = record
         msg      : UINT;
+        // Delphi docs say no filler here. Because next field is
+        // already 8 byte aligned in 64-bit?
         case longint of
           0: (
               wParam : WPARAM;
@@ -1334,25 +1337,31 @@
              );
           1: (
               wParamlo,
-              wParamhi : HALFPARAM;  // Is there Windows type for half an wparam?
+              wParamhi : HALFPARAM;  // Is there Windows type for half an w/lparam?
+              wParamFiller : TDwordFiller;
               lParamlo,
               lParamhi : HALFPARAM;
+              lParamFiller : TDwordFiller;
               Resultlo,
               Resulthi : HALFLRESULT;
+              ResultFiller : TDwordFiller;
              );
        end;
 
     TWMSize = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       SizeType : WPARAM;
       Width : HALFPARAM;
       Height : HALFPARAM;
+      LParamfiller : TDWordFiller;
       Result : LRESULT;
     End;
 
     TWMNoParams = record
       Msg : UINT;
-      Unused : array[0..3] of HALFPARAM;
+      Unusedw : WPARAM;
+      Unusedl : LPARAM;
       Result : LRESULT;
     end;
 
@@ -1368,9 +1377,12 @@
 
     TWMUIState = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Action : Word;
       Flags : Word;
-      Unused : HRESULT;
+      WParamFiller : TDwordFiller;
+      Unused  : LParam;
+      unused2 : LResult;
     end;
 
     TWMChangeUIState = TWMUIState;
@@ -1378,9 +1390,12 @@
 
     TWMKey = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       CharCode: Word;
       Unused: Word;
+      WParamFiller : TDwordFiller;
       KeyData: Longint;
+      LParamFiller : TDwordFiller;
       Result: LRESULT;
     end;
 
@@ -1393,8 +1408,10 @@
 
     TWMMenuChar = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       User: Char;
       MenuFlag: Word;
+      WParamFiller : TDwordFiller;
       Menu: HMENU;
       Result: LRESULT;
     end;
@@ -1407,8 +1424,10 @@
 
     TWMScroll = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       ScrollCode : HALFPARAM;
       Pos : HALFPARAM;
+      WparamFiller : TDwordFiller;
       ScrollBar : HWND;
       Result : LRESULT;
     end;
@@ -1418,7 +1437,8 @@
 
     TWMGetText = record
       Msg : UINT;
-      TextMax : LPARAM;
+      MsgFiller : TDwordFiller;
+      TextMax : WPARAM;
       Text : PChar;
       Result : LRESULT;
     end;
@@ -1427,21 +1447,25 @@
 
     TWMKillFocus = record
        Msg : UINT;
+       MsgFiller : TDwordFiller;
        FocusedWnd : HWND;
-       UnUsed : WPARAM;
+       UnUsed : LPARAM;
        Result : LRESULT;
     end;
 
     TWMSetCursor = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       CursorWnd : HWND;
       HitTest : HALFPARAM;
       MouseMsg : HALFPARAM;
+      LParamFiller : TDwordFiller;
       Result : LRESULT;
     end;
 
     TWMSetFocus = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       FocusedWnd : HWND;
       Unused : LPARAM;
       Result : LRESULT;
@@ -1449,22 +1473,27 @@
 
     TWMSetFont = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Font : HFONT;
       Redraw : HALFPARAMBOOL;
       Unused : HALFPARAM;
+      LParamFiller : TDwordFiller;
       Result : LRESULT;
     end;
 
     TWMShowWindow = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Show : HALFPARAMBOOL;
       Unused : HALFPARAM;
-      Status : WPARAM;
+      WParamFiller : TDwordFiller;
+      Status : LPARAM;
       Result : LRESULT;
     end;
 
     TWMEraseBkgnd = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       DC : HDC;
       Unused : LPARAM;
       Result : LRESULT;
@@ -1472,18 +1501,20 @@
 
     TWMNCHitTest = record
       Msg : UINT;
-      Unused : Longint;
+      MsgFiller : TDwordFiller;
+      Unused : WParam;
       case Integer of
         0: (XPos : Smallint;YPos : Smallint);
-        1:  ( Pos : TSmallPoint;Result: LRESULT);
+        1: ( Pos : TSmallPoint;LParamFiller:TDwordFiller;Result: LRESULT);
     end;
 
     TWMMouse = record
       Msg : UINT;
-      Keys : Longint;
+      MsgFiller : TDwordFiller;
+      Keys : WParam;
       case Integer of
         0: (XPos : Smallint;YPos : Smallint);
-        1: (Pos : TSmallPoint;Result : LRESULT);
+        1: (Pos : TSmallPoint;LParamFiller:TDwordFiller;Result : LRESULT);
     end;
 
     TWMLButtonDblClk  = TWMMouse;
@@ -1495,18 +1526,23 @@
 
     TWMMouseWheel = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Keys : SmallInt;
       WheelDelta : SmallInt;
+      WParamFiller : TDwordFiller;
       case Integer of
         0: (XPos : Smallint;YPos : Smallint);
-        1: (Pos : TSmallPoint;Result : LRESULT);
+        1: (Pos : TSmallPoint;LParamFiller:TDwordFiller;Result : LRESULT);
     end;
 
     TWMNCHitMessage = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       HitTest : Longint;
+      WParamFiller : TDwordFiller;
       XCursor : Smallint;
       YCursor : Smallint;
+      LParamFiller : TDwordFiller;
       Result : LRESULT;
     end;
 
@@ -1524,30 +1560,38 @@
 
     TWMPaint = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       DC : HDC;
       Unused : Longint;
+      LParamFiller : TDwordFiller;
       Result : LRESULT;
     end;
 
     TWMCommand = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       ItemID : Word;
       NotifyCode : Word;
+      WParamFiller : TDwordFiller;
       Ctl : HWND;
       Result : LRESULT;
     end;
 
     TWMNotify = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       IDCtrl : Longint;
+      WParamFiller : TDwordFiller;
       NMHdr : PNMHdr;
       Result : LRESULT;
     end;
 
     TWMPrint = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       DC : HDC;
       Flags : Cardinal;
+      LParamFiller : TDwordFiller;
       Result : LRESULT;
     end;
 
@@ -1555,30 +1599,36 @@
 
     TWMWinIniChange = record
       Msg : UINT;
-      Unused : Integer;
+      MsgFiller : TDwordFiller;
+      Unused : WParam;
       Section : PChar;
       Result : LRESULT;
     end;
 
     TWMContextMenu = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       hWnd : HWND;
       case Integer of
         0: (XPos : Smallint;YPos : Smallint);
-        1: (Pos : TSmallPoint;Result : LRESULT);
+        1: (Pos : TSmallPoint; LParamFiller : TDwordFiller;Result : LRESULT);
     end;
 
     TWMNCCalcSize = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       CalcValidRects : BOOL;
+      WParamFiller : TDwordFiller;
       CalcSize_Params : PNCCalcSizeParams;
       Result : LRESULT;
     end;
 
     TWMCharToItem = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Key : Word;
       CaretPos : Word;
+      WParamFiller : TDwordFiller;
       ListBox: HWND;
       Result : LRESULT;
     end;
@@ -1587,33 +1637,37 @@
 
     TWMParentNotify = record
       Msg : UINT;
-      case Event : Word of
-        WM_CREATE, WM_DESTROY: (ChildID : Word;ChildWnd : HWnd);
-        WM_LBUTTONDOWN, WM_MBUTTONDOWN, WM_RBUTTONDOWN: (Value : Word;XPos : Smallint;YPos : Smallint);
-        0: (Value1 : Word;Value2 : Longint;Result : LRESULT);
+      MsgFiller : TDwordFiller;
+      case Word of // moves into union to simply alignment rules.
+        WM_CREATE, WM_DESTROY: (Event : word;ChildID : Word; WParamFiller : TDwordFiller;ChildWnd : HWnd);
+        WM_LBUTTONDOWN, WM_MBUTTONDOWN, WM_RBUTTONDOWN: (dummy:word;Value : Word; WParamFiller2 : TDwordFiller;XPos : Smallint;YPos : Smallint);
+        0: (dummy2:word;Value1 : Word; WParamFiller3 : TDwordFiller;Value2 : Longint; LParamFiller : TDwordFiller;Result : LRESULT);
     end;
 
     TWMSysCommand = record
       Msg : UINT;
-      case CmdType : Longint of
+      MsgFiller : TDwordFiller;
+      case CmdType : WParam of
         SC_HOTKEY: (ActivateWnd : HWND);
         SC_KEYMENU: (Key : Word);
         SC_CLOSE, SC_HSCROLL, SC_MAXIMIZE, SC_MINIMIZE, SC_MOUSEMENU, SC_MOVE,
         SC_NEXTWINDOW, SC_PREVWINDOW, SC_RESTORE, SC_SCREENSAVE, SC_SIZE,
-        SC_TASKLIST, SC_VSCROLL: (XPos : Smallint; YPos : Smallint;Result : LRESULT);
+        SC_TASKLIST, SC_VSCROLL: (XPos : Smallint; YPos : Smallint; LParamFiller : TDwordFiller;Result : LRESULT);
     end;
 
     TWMMove = record
       Msg : UINT;
-      Unused : Integer;
+      MsgFiller : TDwordFiller;
+      Unused : WParam;
       case Integer of
         0: (XPos : Smallint;YPos : Smallint);
-        1: (Pos : TSmallPoint;Result : LRESULT);
+        1: (Pos : TSmallPoint; LParamFiller : TDwordFiller;Result : LRESULT);
     end;
 
     TWMWindowPosMsg = record
       Msg : UINT;
-      Unused : Integer;
+      MsgFiller : TDwordFiller;
+      Unused : WParam;
       WindowPos : PWindowPos;
       Result : LRESULT;
     end;
@@ -1623,6 +1677,7 @@
 
     TWMCompareItem = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Ctl : HWnd;
       CompareItemStruct : PCompareItemStruct;
       Result : LRESULT;
@@ -1630,6 +1685,7 @@
 
     TWMDeleteItem = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Ctl : HWND;
       DeleteItemStruct : PDeleteItemStruct;
       Result : LRESULT;
@@ -1637,6 +1693,7 @@
 
     TWMDrawItem = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Ctl : HWND;
       DrawItemStruct : PDrawItemStruct;
       Result : LRESULT;
@@ -1644,6 +1701,7 @@
 
     TWMMeasureItem = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       IDCtl : HWnd;
       MeasureItemStruct : PMeasureItemStruct;
       Result : LRESULT
@@ -1651,44 +1709,54 @@
 
     TWMNCCreate = record
       Msg : UINT;
-      Unused : Integer;
+      MsgFiller : TDwordFiller;
+      Unused : WParam;
       CreateStruct : PCreateStruct;
       Result : LRESULT;
     end;
 
     TWMInitMenuPopup = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       MenuPopup : HMENU;
       Pos : Smallint;
       SystemMenu : WordBool;
+      LParamFiller : TDwordFiller;
       Result : LRESULT;
     end;
 
     TWMMenuSelect = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       IDItem : Word;
       MenuFlag : Word;
+      WParamFiller : TDwordFiller;
       Menu: HMENU;
       Result : LRESULT;
     end;
 
     TWMActivate = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Active : Word;
       Minimized : WordBool;
+      WParamFiller : TDwordFiller;
       ActiveWindow : HWND;
       Result : LRESULT;
     end;
 
     TWMQueryEndSession = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Source : Longint;
-      Unused : Longint;
+      WParamFiller : TDwordFiller;
+      Unused : LParam;
       Result : LRESULT;
     end;
 
     TWMMDIActivate = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       case Integer of
         0: (ChildWnd : HWND);
         1: (DeactiveWnd : HWND;ActiveWnd : HWND;Result: LRESULT);
@@ -1696,42 +1764,51 @@
 
     TWMNextDlgCtl = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       CtlFocus : Longint;
+      WParamFiller : TDwordFiller;
       Handle : WordBool;
       Unused : Word;
+      LParamFiller : TDwordFiller;
       Result : LRESULT;
     end;
 
     TWMHelp = record
       Msg : UINT;
-      Unused : Integer;
+      MsgFiller : TDwordFiller;
+      Unused : WParam;
       HelpInfo : PHelpInfo;
       Result : LRESULT;
     end;
 
     TWMGetMinMaxInfo = record
       Msg : UINT;
-      Unused : Integer;
+      MsgFiller : TDwordFiller;
+      Unused : WParam;
       MinMaxInfo : PMinMaxInfo;
       Result : LRESULT;
     end;
 
     TWMSettingChange = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Flag : Integer;
+      WParamFiller : TDwordFiller;
       Section : PChar;
       Result : LRESULT;
     end;
 
     TWMCreate = record
       Msg : UINT;
-      Unused : Integer;
+      MsgFiller : TDwordFiller;
+      Unused : WParam;
       CreateStruct : PCreateStruct;
       Result : LRESULT;
     end;
 
     TWMCtlColor = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       ChildDC : HDC;
       ChildWnd : HWND;
       Result : LRESULT;
@@ -1747,27 +1824,32 @@
 
     TWMInitDialog = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       Focus : HWND;
       InitParam : Longint;
+      LParamFiller : TDwordFiller;
       Result : LRESULT;
     end;
 
     TWMNCPaint = record
       Msg : UINT;
+      MsgFiller : TDwordFiller;
       RGN : HRGN;
-      Unused : WPARAM;
+      Unused : LPARAM;
       Result : LRESULT;
     end;
 
     TWMSetText = record
       Msg : UINT;
-      Unused : Longint;
+      MsgFiller : TDwordFiller;
+      Unused : WParam;
       Text : PChar;
       Result : LRESULT;
     end;
 
     TWMSizeClipboard = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       Viewer: HWND;
       RC: THandle;
       Result: LRESULT;
@@ -1775,67 +1857,77 @@
 
     TWMSpoolerStatus = record
       Msg: UINT;
-      JobStatus: LPARAM;
-      JobsLeft: WPARAM;
-      Unused: WPARAM;
+      MsgFiller: TDwordFiller;
+      JobStatus: WPARAM;
+      JobsLeft : word;
+      Unused   : word;
+      LParamFiller : TDwordFiller;
       Result: LRESULT;
     end;
-  
+
     TWMStyleChange = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       StyleType: LPARAM;
       StyleStruct: PStyleStruct;
       Result: LRESULT;
     end;
-  
+
     TWMStyleChanged = TWMStyleChange;
     TWMStyleChanging = TWMStyleChange;
-  
-  
+
+
     TWMSysDeadChar = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       CharCode: WPARAM;
-      Unused: WPARAM;
       KeyData: LPARAM;
       Result: LRESULT;
     end;
-  
+
     TWMSystemError = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       ErrSpec: WPARAM;
       Unused: LPARAM;
       Result: LRESULT;
     end;
-  
+
     TWMTimeChange = TWMNoParams;
-  
+
     TWMTimer = record
       Msg: UINT;
-      TimerID: LPARAM;
+      MsgFiller : TDwordFiller;
+      TimerID: WPARAM;
       TimerProc: TFarProc;
       Result: LRESULT;
     end;
-  
+
     TWMUndo = TWMNoParams;
-  
+
     TWMVScrollClipboard = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       Viewer: HWND;
-      ScollCode: WPARAM;
-      ThumbPos: WPARAM;
+      ScollCode: word;
+      ThumbPos: word;
+      LParamFiller : TDwordFiller;
       Result: LRESULT;
     end;
-  
+
     TWMDisplayChange = record
       Msg: UINT;
-      BitsPerPixel: Integer;
-      Width: WPARAM;
-      Height: WPARAM;
+      MsgFiller : TDwordFiller;
+      BitsPerPixel: WParam;
+      Width: Word;
+      Height: Word;
+      LParamFiller : TDwordFiller;
       Result: LRESULT;
     end;
 
     TWMDropFiles = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       Drop: THANDLE;
       Unused: LPARAM;
       Result: LRESULT;
@@ -1843,34 +1935,41 @@
 
     TWMEnable = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       Enabled: BOOL;
+      WParamFiller : TDwordFiller;
       Unused: LPARAM;
       Result: LRESULT;
     end;
 
     TWMMouseActivate = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       TopLevel: HWND;
       HitTestCode: Word;
       MouseMsg: Word;
+      LParamFiller : TDwordFiller;
       Result: LRESULT;
     end;
 
     TWMEndSession = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       EndSession: BOOL;
+      WParamFiller : TDwordFiller;
       Unused: LPARAM;
       Result: LRESULT;
     end;
-    
+
     TWMActivateApp = record
       Msg: UINT;
+      MsgFiller : TDwordFiller;
       Active: BOOL;
-      ThreadId: WPARAM;
+      WParamFiller : TDwordFiller;
+      ThreadId: LPARAM;
       Result: LRESULT;
     end;
 {$endif messagesunit}
-    
 
 {$endif read_interface}
 

+ 2 - 8
utils/instantfpc/instantfpc.lpi

@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <CONFIG>
   <ProjectOptions>
     <Version Value="9"/>
@@ -46,7 +46,7 @@
     </Units>
   </ProjectOptions>
   <CompilerOptions>
-    <Version Value="10"/>
+    <Version Value="11"/>
     <Target>
       <Filename Value="instantfpc"/>
     </Target>
@@ -54,12 +54,6 @@
       <IncludeFiles Value="$(ProjOutDir)"/>
       <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
-    <Linking>
-      <Debugging>
-        <GenerateDebugInfo Value="True"/>
-        <DebugInfoType Value="dsAuto"/>
-      </Debugging>
-    </Linking>
     <Other>
       <CompilerMessages>
         <UseMsgFile Value="True"/>

+ 3 - 4
utils/instantfpc/instantfpc.pas

@@ -25,7 +25,8 @@ uses
   Classes, SysUtils, InstantFPTools;
 
 const
-  Version = '1.2';
+  Version = '1.3';
+  // 1.3 compile in a separate directory, so that parallel invocations do not overwrite link.res files
 
 
 Procedure Usage;
@@ -92,7 +93,6 @@ var
   CacheDir: String;
   CacheFilename: String;
   OutputFilename: String;
-  ExeExt: String;
   E : String;
   RunIt: boolean = true;
   
@@ -184,8 +184,7 @@ begin
     E:=LowerCase(ExtractFileExt(CacheFileName));
     if (E<>'.pp') and (E<>'.pas') and (E<>'.lpr') then
       CacheFileName:=CacheFileName+'.pas';
-    ExeExt:='';
-    OutputFilename:=CacheDir+ChangeFileExt(ExtractFileName(Filename),ExeExt);
+    OutputFilename:=CacheDir+ChangeFileExt(ExtractFileName(Filename),'');
     if not IsCacheValid(Src,CacheFilename,OutputFilename) then begin
       // save source in cache to find out next time if something changed
       Src.SaveToFile(CacheFilename);

+ 66 - 6
utils/instantfpc/instantfptools.pas

@@ -47,7 +47,7 @@ procedure Compile(const SrcFilename, CacheFilename, OutputFilename: string);
 procedure WriteCompilerOutput(SrcFilename, CacheFilename, CompilerOutput: string);
 function GetCompiler: string;
 procedure SetCompiler(AValue : string);
-function GetCompilerParameters(const SrcFilename, OutputFilename: string): string;
+function GetCompilerParameters(const SrcFilename, OutputDirectory, OutputFilename: string): string;
 procedure Run(const Filename: string);
 
 implementation
@@ -246,6 +246,31 @@ begin
     end;
 end;
 
+procedure DeleteDirectory(Directory: string);
+var
+  FileInfo: TSearchRec;
+  aFilename: String;
+begin
+  Directory:=ExcludeTrailingPathDelimiter(Directory);
+  if not DirectoryExists(Directory) then exit;
+  if FindFirst(Directory+PathDelim+AllFilesMask,faAnyFile,FileInfo)=0 then begin
+    repeat
+      if (FileInfo.Name='.') or (FileInfo.Name='..') then continue;
+      aFilename:=Directory+PathDelim+FileInfo.Name;
+      if (FileInfo.Attr and faDirectory)>0 then
+        DeleteDirectory(aFilename)
+      else if not DeleteFile(aFilename) then begin
+        writeln('unable to delete file "'+aFilename+'"');
+        Halt(1);
+      end;
+    until FindNext(FileInfo)<>0;
+  end;
+  if not RemoveDir(Directory) then begin
+    writeln('unable to delete directory "'+Directory+'"');
+    Halt(1);
+  end;
+end;
+
 procedure Compile(const SrcFilename, CacheFilename, OutputFilename: string);
 var
   Compiler: String;
@@ -254,14 +279,35 @@ var
   Count: Int64;
   ss: TStringStream;
   buf : Array[1..4096] of byte;
+  pid: SizeUInt;
+  BuildDir: String;
+  BuildOutputFilename: String;
 begin
   Compiler:=GetCompiler;
-  CompParams:=GetCompilerParameters(CacheFilename,OutputFilename);
+  pid:=GetProcessID;
+  BuildDir:='';
+  BuildOutputFilename:=OutputFilename;
+  if pid>0 then begin
+    BuildDir:=ExtractFilePath(OutputFilename)+'__tmp'+IntToStr(pid)+PathDelim;
+    BuildOutputFilename:=BuildDir+ExtractFileName(OutputFilename);
+  end;
   //writeln('Compiler=',Compiler,' Params=',CompParams);
   if FileExists(OutputFilename) and not DeleteFile(OutputFilename) then begin
     writeln('unable to delete ',OutputFilename);
     Halt(1);
   end;
+  if BuildDir<>'' then begin
+    if FileExists(BuildOutputFilename) and not DeleteFile(BuildOutputFilename)
+    then begin
+      writeln('unable to delete ',BuildOutputFilename);
+      Halt(1);
+    end;
+    if not DirectoryExists(BuildDir) and not CreateDir(BuildDir) then begin
+      writeln('unable to mkdir ',BuildDir);
+      Halt(1);
+    end;
+  end;
+  CompParams:=GetCompilerParameters(CacheFilename,BuildDir,BuildOutputFilename);
   Proc:=TProcess.Create(nil);
   Proc.CommandLine:=Compiler+' '+CompParams;
 {$WARNING Unconditional use of pipes breaks for targets not supporting them}
@@ -274,6 +320,15 @@ begin
     if Count>0 then
       ss.write(buf,count);
   until Count=0;
+  if BuildDir<>'' then begin
+    // move from build directory to cache
+    if not RenameFile(BuildOutputFilename,OutputFilename) then begin
+      writeln('unable to move "',BuildOutputFilename,'" to "',OutputFilename,'"');
+      Halt(1);
+    end;
+    // delete build directory
+    DeleteDirectory(BuildDir);
+  end;
   if (not Proc.WaitOnExit) or (Proc.ExitStatus<>0) then begin
     WriteCompilerOutput(SrcFilename,CacheFilename,ss.DataString);
     Halt(1);
@@ -282,7 +337,8 @@ begin
   Proc.Free;
 end;
 
-function GetCompilerParameters(const SrcFilename, OutputFilename: string): string;
+function GetCompilerParameters(const SrcFilename, OutputDirectory,
+  OutputFilename: string): string;
 { For example:
     /usr/bin/instantfpc -MObjFpc -Sh ./envvars.pas param1
   The shebang compile parameters: -MObjFpc -Sh
@@ -300,6 +356,8 @@ begin
       AddParam(P,Result);
     inc(I);
     end;
+  if OutputDirectory<>'' then
+    AddParam('-FU'+OutputDirectory,Result);
   AddParam('-o'+OutputFilename {$IFDEF HASEXEEXT} + '.exe' {$ENDIF},Result);
   AddParam(SrcFilename,Result);
 end;
@@ -307,8 +365,10 @@ end;
 procedure Run(const Filename: string);
 var
   p : PPChar;
+  {$IFNDEF UseFpExecV}
   i : integer;
   args : array of string;
+  {$ENDIF}
 begin
   p:=argv;
   inc(p);
@@ -318,7 +378,9 @@ begin
     end;
     inc(p);
   end;
-  {$IFNDEF UseFpExecV}
+  {$IFDEF UseFpExecV}
+    Halt(FpExecV(Filename,p));
+  {$ELSE}
     if paramcount>1 then
       begin
         setlength(args,paramcount-1);
@@ -326,8 +388,6 @@ begin
           args[i-2]:=paramstr(i);
       end;
     Halt(ExecuteProcess(Filename,args));
-  {$ELSE}
-    Halt(FpExecV(Filename,p));
   {$ENDIF}
 end;