ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
September 2012
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
17 participants
236 discussions
Start a n
N
ew thread
[tkreuzer] 57439: [SPEC2DEF] Implement support for int128. CORE-6630 #resolve
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sat Sep 29 22:58:06 2012 New Revision: 57439 URL:
http://svn.reactos.org/svn/reactos?rev=57439&view=rev
Log: [SPEC2DEF] Implement support for int128. CORE-6630 #resolve Modified: trunk/reactos/tools/spec2def/spec2def.c Modified: trunk/reactos/tools/spec2def/spec2def.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/spec2def/spec2def.c?…
============================================================================== --- trunk/reactos/tools/spec2def/spec2def.c [iso-8859-1] (original) +++ trunk/reactos/tools/spec2def/spec2def.c [iso-8859-1] Sat Sep 29 22:58:06 2012 @@ -67,6 +67,7 @@ ARG_WSTR, ARG_DBL, ARG_INT64, + ARG_INT128, ARG_FLOAT }; @@ -191,7 +192,9 @@ case ARG_PTR: fprintf(file, "void*"); break; case ARG_STR: fprintf(file, "char*"); break; case ARG_WSTR: fprintf(file, "wchar_t*"); break; - case ARG_DBL: case ARG_INT64 : fprintf(file, "__int64"); break; + case ARG_DBL: + case ARG_INT64 : fprintf(file, "__int64"); break; + case ARG_INT128 : fprintf(file, "__int128"); break; case ARG_FLOAT: fprintf(file, "float"); break; } fprintf(file, " a%d", i); @@ -210,6 +213,7 @@ case ARG_WSTR: fprintf(file, "'%%ws'"); break; case ARG_DBL: fprintf(file, "%%f"); break; case ARG_INT64: fprintf(file, "%%\"PRix64\""); break; + case ARG_INT128: fprintf(file, "%%\"PRix128\""); break; case ARG_FLOAT: fprintf(file, "%%f"); break; } } @@ -226,6 +230,7 @@ case ARG_WSTR: fprintf(file, "(wchar_t*)a%d", i); break; case ARG_DBL: fprintf(file, "(double)a%d", i); break; case ARG_INT64: fprintf(file, "(__int64)a%d", i); break; + case ARG_INT128: fprintf(file, "(__int128)a%d", i); break; case ARG_FLOAT: fprintf(file, "(float)a%d", i); break; } } @@ -600,6 +605,11 @@ exp.nStackBytes += 8; exp.anArgs[exp.nArgCount] = ARG_INT64; } + else if (CompareToken(pc, "int128")) + { + exp.nStackBytes += 16; + exp.anArgs[exp.nArgCount] = ARG_INT128; + } else if (CompareToken(pc, "float")) { exp.nStackBytes += 4;
12 years, 2 months
1
0
0
0
[ekohl] 57438: [LSASRV] - Fix a typo: LsarEnmuerateAccountRights --> LsarEnumerateAccountRights. - Implement LsarEnumeratePrivileges.
by ekohl@svn.reactos.org
Author: ekohl Date: Sat Sep 29 22:52:30 2012 New Revision: 57438 URL:
http://svn.reactos.org/svn/reactos?rev=57438&view=rev
Log: [LSASRV] - Fix a typo: LsarEnmuerateAccountRights --> LsarEnumerateAccountRights. - Implement LsarEnumeratePrivileges. Modified: trunk/reactos/dll/win32/advapi32/sec/lsa.c trunk/reactos/dll/win32/lsasrv/lsarpc.c trunk/reactos/dll/win32/lsasrv/lsasrv.h trunk/reactos/dll/win32/lsasrv/privileges.c trunk/reactos/include/reactos/idl/lsa.idl Modified: trunk/reactos/dll/win32/advapi32/sec/lsa.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/sec/lsa…
============================================================================== --- trunk/reactos/dll/win32/advapi32/sec/lsa.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/sec/lsa.c [iso-8859-1] Sat Sep 29 22:52:30 2012 @@ -417,7 +417,7 @@ RpcTryExcept { - Status = LsarEnmuerateAccountRights((LSAPR_HANDLE)PolicyHandle, + Status = LsarEnumerateAccountRights((LSAPR_HANDLE)PolicyHandle, AccountSid, &UserRightsSet); Modified: trunk/reactos/dll/win32/lsasrv/lsarpc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/lsasrv/lsarpc.c?…
============================================================================== --- trunk/reactos/dll/win32/lsasrv/lsarpc.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/lsasrv/lsarpc.c [iso-8859-1] Sat Sep 29 22:52:30 2012 @@ -109,8 +109,26 @@ PLSAPR_PRIVILEGE_ENUM_BUFFER EnumerationBuffer, DWORD PreferedMaximumLength) { - UNIMPLEMENTED; - return STATUS_NOT_IMPLEMENTED; + PLSA_DB_OBJECT PolicyObject; + NTSTATUS Status; + + TRACE("LsarEnumeratePrivileges(%p %p %p %lu)\n", + PolicyHandle, EnumerationContext, EnumerationBuffer, + PreferedMaximumLength); + + Status = LsapValidateDbObject(PolicyHandle, + LsaDbPolicyObject, + POLICY_VIEW_LOCAL_INFORMATION, + &PolicyObject); + if (!NT_SUCCESS(Status)) + return Status; + + if (EnumerationContext == NULL) + return STATUS_INVALID_PARAMETER; + + return LsarpEnumeratePrivileges(EnumerationContext, + EnumerationBuffer, + PreferedMaximumLength); } @@ -1658,7 +1676,7 @@ /* Function 36 */ -NTSTATUS WINAPI LsarEnmuerateAccountRights( +NTSTATUS WINAPI LsarEnumerateAccountRights( LSAPR_HANDLE PolicyHandle, PRPC_SID AccountSid, PLSAPR_USER_RIGHT_SET UserRights) @@ -1666,7 +1684,8 @@ PLSA_DB_OBJECT PolicyObject; NTSTATUS Status; - FIXME("(%p,%p,%p) stub\n", PolicyHandle, AccountSid, UserRights); + TRACE("LsarEnumerateAccountRights(%p %p %p)\n", + PolicyHandle, AccountSid, UserRights); Status = LsapValidateDbObject(PolicyHandle, LsaDbPolicyObject, Modified: trunk/reactos/dll/win32/lsasrv/lsasrv.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/lsasrv/lsasrv.h?…
============================================================================== --- trunk/reactos/dll/win32/lsasrv/lsasrv.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/lsasrv/lsasrv.h [iso-8859-1] Sat Sep 29 22:52:30 2012 @@ -182,6 +182,11 @@ LsarpLookupPrivilegeValue(PUNICODE_STRING Name, PLUID Value); +NTSTATUS +LsarpEnumeratePrivileges(DWORD *EnumerationContext, + PLSAPR_PRIVILEGE_ENUM_BUFFER EnumerationBuffer, + DWORD PreferedMaximumLength); + /* sids.h */ NTSTATUS LsapInitSids(VOID); Modified: trunk/reactos/dll/win32/lsasrv/privileges.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/lsasrv/privilege…
============================================================================== --- trunk/reactos/dll/win32/lsasrv/privileges.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/lsasrv/privileges.c [iso-8859-1] Sat Sep 29 22:52:30 2012 @@ -9,6 +9,8 @@ #include "lsasrv.h" +WINE_DEFAULT_DEBUG_CHANNEL(lsasrv); + typedef struct { @@ -16,6 +18,8 @@ LPCWSTR Name; } PRIVILEGE_DATA; + +/* GLOBALS *****************************************************************/ static const PRIVILEGE_DATA WellKnownPrivileges[] = { @@ -111,8 +115,6 @@ { if (_wcsicmp(Name->Buffer, WellKnownPrivileges[Priv].Name) == 0) { -// Value->LowPart = WellKnownPrivileges[Priv].Luid.LowPart; -// Value->HighPart = WellKnownPrivileges[Priv].Luid.HighPart; *Value = WellKnownPrivileges[Priv].Luid; return STATUS_SUCCESS; } @@ -120,3 +122,100 @@ return STATUS_NO_SUCH_PRIVILEGE; } + + +NTSTATUS +LsarpEnumeratePrivileges(DWORD *EnumerationContext, + PLSAPR_PRIVILEGE_ENUM_BUFFER EnumerationBuffer, + DWORD PreferedMaximumLength) +{ + PLSAPR_POLICY_PRIVILEGE_DEF Privileges = NULL; + ULONG EnumIndex; + ULONG EnumCount = 0; + ULONG RequiredLength = 0; + ULONG i; + BOOLEAN MoreEntries = FALSE; + NTSTATUS Status = STATUS_SUCCESS; + + EnumIndex = *EnumerationContext; + + for (; EnumIndex < sizeof(WellKnownPrivileges) / sizeof(WellKnownPrivileges[0]); EnumIndex++) + { + TRACE("EnumIndex: %lu\n", EnumIndex); + TRACE("Privilege Name: %S\n", WellKnownPrivileges[EnumIndex].Name); + TRACE("Name Length: %lu\n", wcslen(WellKnownPrivileges[EnumIndex].Name)); + + if ((RequiredLength + + wcslen(WellKnownPrivileges[EnumIndex].Name) * sizeof(WCHAR) + + sizeof(UNICODE_NULL) + + sizeof(LSAPR_POLICY_PRIVILEGE_DEF)) > PreferedMaximumLength) + { + MoreEntries = TRUE; + break; + } + + RequiredLength += (wcslen(WellKnownPrivileges[EnumIndex].Name) * sizeof(WCHAR) + + sizeof(UNICODE_NULL) + sizeof(LSAPR_POLICY_PRIVILEGE_DEF)); + EnumCount++; + } + + TRACE("EnumCount: %lu\n", EnumCount); + TRACE("RequiredLength: %lu\n", RequiredLength); + + if (EnumCount == 0) + goto done; + + Privileges = MIDL_user_allocate(EnumCount * sizeof(LSAPR_POLICY_PRIVILEGE_DEF)); + if (Privileges == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + goto done; + } + + EnumIndex = *EnumerationContext; + + for (i = 0; i < EnumCount; i++, EnumIndex++) + { + Privileges[i].LocalValue = WellKnownPrivileges[EnumIndex].Luid; + + Privileges[i].Name.Length = (USHORT)wcslen(WellKnownPrivileges[EnumIndex].Name) * sizeof(WCHAR); + Privileges[i].Name.MaximumLength = (USHORT)Privileges[i].Name.Length + sizeof(UNICODE_NULL); + + Privileges[i].Name.Buffer = MIDL_user_allocate(Privileges[i].Name.MaximumLength); + if (Privileges[i].Name.Buffer == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + goto done; + } + + memcpy(Privileges[i].Name.Buffer, + WellKnownPrivileges[EnumIndex].Name, + Privileges[i].Name.Length); + } + +done: + if (NT_SUCCESS(Status)) + { + EnumerationBuffer->Entries = EnumCount; + EnumerationBuffer->Privileges = Privileges; + *EnumerationContext += EnumCount; + } + else + { + if (Privileges != NULL) + { + for (i = 0; i < EnumCount; i++) + { + if (Privileges[i].Name.Buffer != NULL) + MIDL_user_free(Privileges[i].Name.Buffer); + } + + MIDL_user_free(Privileges); + } + } + + if ((Status == STATUS_SUCCESS) && (MoreEntries == TRUE)) + Status = STATUS_MORE_ENTRIES; + + return Status; +} Modified: trunk/reactos/include/reactos/idl/lsa.idl URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/idl/lsa.id…
============================================================================== --- trunk/reactos/include/reactos/idl/lsa.idl [iso-8859-1] (original) +++ trunk/reactos/include/reactos/idl/lsa.idl [iso-8859-1] Sat Sep 29 22:52:30 2012 @@ -821,7 +821,7 @@ [out] PLSAPR_ACCOUNT_ENUM_BUFFER EnumerationBuffer); /* Function 36 */ - NTSTATUS __stdcall LsarEnmuerateAccountRights( + NTSTATUS __stdcall LsarEnumerateAccountRights( [in] LSAPR_HANDLE PolicyHandle, [in] PRPC_SID AccountSid, [out] PLSAPR_USER_RIGHT_SET UserRights);
12 years, 2 months
1
0
0
0
[tkreuzer] 57437: [CLASSPNP] - Make srb volatile, since it's assigned inside SEH and referenced in finally [NTOSKRNL] - FsRtlTeardownPerStreamContexts: make IsMutexLocked volatile (SEH) - IoCreateF...
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sat Sep 29 22:44:48 2012 New Revision: 57437 URL:
http://svn.reactos.org/svn/reactos?rev=57437&view=rev
Log: [CLASSPNP] - Make srb volatile, since it's assigned inside SEH and referenced in finally [NTOSKRNL] - FsRtlTeardownPerStreamContexts: make IsMutexLocked volatile (SEH) - IoCreateFile: Make SystemEaBuffer volatile (SEH), save status and information in the caller's IoStatusBlock, cleanup and fail when IoCheckEaBufferValidity failed with PreviousMode == KernelMode, too. - NtLockFile: Move ExAllocatePoolWithTag out of the SEH block. ExAllocatePoolWithTag does not raise an exception by default (unlike ExAllocatePoolWithQuotaTag). Get rid of this SEH block completely and check the return value instead. - NtQueryDirectoryFile: make AuxBuffer volatile (SEH), again move ExAllocatePoolWithTag out of the SEH block and check return value instead. IopCaptureUnicodeString: Make Name volatile (SEH) Modified: trunk/reactos/drivers/storage/classpnp/create.c trunk/reactos/ntoskrnl/fsrtl/filtrctx.c trunk/reactos/ntoskrnl/io/iomgr/file.c trunk/reactos/ntoskrnl/io/iomgr/iofunc.c trunk/reactos/ntoskrnl/io/pnpmgr/plugplay.c Modified: trunk/reactos/drivers/storage/classpnp/create.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/storage/classpnp/c…
============================================================================== --- trunk/reactos/drivers/storage/classpnp/create.c [iso-8859-1] (original) +++ trunk/reactos/drivers/storage/classpnp/create.c [iso-8859-1] Sat Sep 29 22:44:48 2012 @@ -444,8 +444,8 @@ #if 1 /* - * BUGBUG REMOVE this old function implementation as soon as the - * boottime pagefile problems with the new one (below) + * BUGBUG REMOVE this old function implementation as soon as the + * boottime pagefile problems with the new one (below) * are resolved. */ NTSTATUS @@ -460,10 +460,10 @@ PFUNCTIONAL_DEVICE_EXTENSION FdoExtension = Fdo->DeviceExtension; PCOMMON_DEVICE_EXTENSION commonExtension = (PCOMMON_DEVICE_EXTENSION) FdoExtension; - + PFILE_OBJECT_EXTENSION fsContext = NULL; NTSTATUS status; - PSCSI_REQUEST_BLOCK srb = NULL; + volatile PSCSI_REQUEST_BLOCK srb = NULL; BOOLEAN countChanged = FALSE; PAGED_CODE(); @@ -508,7 +508,7 @@ // if(LockType == SecureMediaLock) { - + PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp); PFILE_OBJECT fileObject = irpStack->FileObject; @@ -563,7 +563,7 @@ break; } } - + } else { // @@ -621,25 +621,25 @@ srb->CdbLength = 6; cdb->MEDIA_REMOVAL.OperationCode = SCSIOP_MEDIUM_REMOVAL; - + // // TRUE - prevent media removal. // FALSE - allow media removal. // - + cdb->MEDIA_REMOVAL.Prevent = Lock; - + // // Set timeout value. // - + srb->TimeOutValue = FdoExtension->TimeOutValue; - + // // The actual lock operation on the device isn't so important // as the internal lock counts. Ignore failures. // - + status = ClassSendSrbSynchronous(FdoExtension->DeviceObject, srb, NULL, @@ -653,7 +653,7 @@ DebugPrint((2, "ClasspEjectionControl: FAILED status %x -- " "reverting lock counts\n", status)); - + if (countChanged) { // @@ -662,7 +662,7 @@ // if(Lock) { - + switch(LockType) { case SimpleMediaLock: { @@ -755,9 +755,9 @@ BOOLEAN fileHandleOk = TRUE; BOOLEAN countChanged = FALSE; NTSTATUS status; - + PAGED_CODE(); - + status = KeWaitForSingleObject( &fdoExt->EjectSynchronizationEvent, UserRequest, @@ -803,7 +803,7 @@ fdoExt->LockCount++; countChanged = TRUE; break; - case SecureMediaLock: + case SecureMediaLock: fsContext->LockCount++; fdoExt->ProtectedLockCount++; countChanged = TRUE; @@ -813,14 +813,14 @@ countChanged = TRUE; break; } - } + } else { /* * This is an unlock command. If it's a secured one then make sure * the caller has a lock outstanding or return an error. */ switch (LockType){ - case SimpleMediaLock: + case SimpleMediaLock: if (fdoExt->LockCount > 0){ fdoExt->LockCount--; countChanged = TRUE; @@ -859,7 +859,7 @@ (fdoExt->ProtectedLockCount || fdoExt->InternalLockCount || fdoExt->LockCount)){ - + /* * The lock count is still positive, so don't unlock yet. */ @@ -873,14 +873,14 @@ } else { TRANSFER_PACKET *pkt; - + pkt = DequeueFreeTransferPacket(Fdo, TRUE); if (pkt){ KEVENT event; - + /* * Store the number of packets servicing the irp (one) - * inside the original IRP. It will be used to counted down + * inside the original IRP. It will be used to counted down * to zero when the packet completes. * Initialize the original IRP's status to success. * If the packet fails, we will set it to the error status. @@ -893,10 +893,10 @@ * and wait for the packet to complete. The result * status will be written to the original irp. */ - KeInitializeEvent(&event, SynchronizationEvent, FALSE); + KeInitializeEvent(&event, SynchronizationEvent, FALSE); SetupEjectionTransferPacket(pkt, Lock, &event, Irp); SubmitTransferPacket(pkt); - KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL); + KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL); status = Irp->IoStatus.Status; } else { @@ -961,7 +961,7 @@ } - + KeSetEvent(&fdoExt->EjectSynchronizationEvent, IO_NO_INCREMENT, FALSE); return status; Modified: trunk/reactos/ntoskrnl/fsrtl/filtrctx.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/fsrtl/filtrctx.c?…
============================================================================== --- trunk/reactos/ntoskrnl/fsrtl/filtrctx.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/fsrtl/filtrctx.c [iso-8859-1] Sat Sep 29 22:44:48 2012 @@ -368,7 +368,7 @@ FsRtlTeardownPerStreamContexts(IN PFSRTL_ADVANCED_FCB_HEADER AdvFcbHeader) { PLIST_ENTRY NextEntry; - BOOLEAN IsMutexLocked = FALSE; + volatile BOOLEAN IsMutexLocked = FALSE; PFSRTL_PER_STREAM_CONTEXT PerStreamContext; _SEH2_TRY Modified: trunk/reactos/ntoskrnl/io/iomgr/file.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/file.c?r…
============================================================================== --- trunk/reactos/ntoskrnl/io/iomgr/file.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/io/iomgr/file.c [iso-8859-1] Sat Sep 29 22:44:48 2012 @@ -1700,8 +1700,8 @@ KPROCESSOR_MODE AccessMode; HANDLE LocalHandle = 0; LARGE_INTEGER SafeAllocationSize; - PVOID SystemEaBuffer = NULL; - NTSTATUS Status; + volatile PVOID SystemEaBuffer = NULL; + NTSTATUS Status = STATUS_SUCCESS; OPEN_PACKET OpenPacket; ULONG EaErrorOffset; @@ -1738,9 +1738,7 @@ if ((EaBuffer) && (EaLength)) { - ProbeForRead(EaBuffer, - EaLength, - sizeof(ULONG)); + ProbeForRead(EaBuffer, EaLength, sizeof(ULONG)); /* marshal EaBuffer */ SystemEaBuffer = ExAllocatePoolWithTag(NonPagedPool, @@ -1757,24 +1755,14 @@ Status = IoCheckEaBufferValidity(SystemEaBuffer, EaLength, &EaErrorOffset); - if (!NT_SUCCESS(Status)) - { - DPRINT1("FIXME: IoCheckEaBufferValidity() failed with " - "Status: %lx\n",Status); - - /* Free EA Buffer and return the error */ - ExFreePoolWithTag(SystemEaBuffer, TAG_EA); - _SEH2_YIELD(return Status); - } + IoStatusBlock->Status = Status; + IoStatusBlock->Information = EaErrorOffset; } } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - /* Free SystemEaBuffer if needed */ - if (SystemEaBuffer) ExFreePoolWithTag(SystemEaBuffer, TAG_EA); - /* Return the exception code */ - _SEH2_YIELD(return _SEH2_GetExceptionCode()); + Status = _SEH2_GetExceptionCode(); } _SEH2_END; } @@ -1816,12 +1804,19 @@ Status = IoCheckEaBufferValidity(SystemEaBuffer, EaLength, &EaErrorOffset); - if (!NT_SUCCESS(Status)) - { - DPRINT1("FIXME: IoCheckEaBufferValidity() failed with " - "Status: %lx\n",Status); - } - } + IoStatusBlock->Status = Status; + IoStatusBlock->Information = EaErrorOffset; + } + } + + if (!NT_SUCCESS(Status)) + { + DPRINT1("FIXME: IoCheckEaBufferValidity() failed with Status: %lx\n", + Status); + + /* Free SystemEaBuffer if needed and return the error */ + if (SystemEaBuffer) ExFreePoolWithTag(SystemEaBuffer, TAG_EA); + return Status; } /* Setup the Open Packet */ Modified: trunk/reactos/ntoskrnl/io/iomgr/iofunc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/iofunc.c…
============================================================================== --- trunk/reactos/ntoskrnl/io/iomgr/iofunc.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/io/iomgr/iofunc.c [iso-8859-1] Sat Sep 29 22:44:48 2012 @@ -1330,29 +1330,21 @@ StackPtr->MinorFunction = IRP_MN_LOCK; StackPtr->FileObject = FileObject; - /* Enter SEH */ - _SEH2_TRY - { - /* Allocate local buffer */ - LocalLength = ExAllocatePoolWithTag(NonPagedPool, - sizeof(LARGE_INTEGER), - TAG_LOCK); - - /* Set the length */ - *LocalLength = CapturedLength; - Irp->Tail.Overlay.AuxiliaryBuffer = (PVOID)LocalLength; - StackPtr->Parameters.LockControl.Length = LocalLength; - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - /* Allocating failed, clean up and return the exception code */ + /* Allocate local buffer */ + LocalLength = ExAllocatePoolWithTag(NonPagedPool, + sizeof(LARGE_INTEGER), + TAG_LOCK); + if (!LocalLength) + { + /* Allocating failed, clean up and return failure */ IopCleanupAfterException(FileObject, Irp, Event, NULL); - if (LocalLength) ExFreePoolWithTag(LocalLength, TAG_LOCK); - - /* Return the exception code */ - _SEH2_YIELD(return _SEH2_GetExceptionCode()); - } - _SEH2_END; + return STATUS_INSUFFICIENT_RESOURCES; + } + + /* Set the length */ + *LocalLength = CapturedLength; + Irp->Tail.Overlay.AuxiliaryBuffer = (PVOID)LocalLength; + StackPtr->Parameters.LockControl.Length = LocalLength; /* Set Parameters */ StackPtr->Parameters.LockControl.ByteOffset = CapturedByteOffset; @@ -1397,7 +1389,7 @@ NTSTATUS Status; BOOLEAN LockedForSynch = FALSE; PKEVENT Event = NULL; - PVOID AuxBuffer = NULL; + volatile PVOID AuxBuffer = NULL; PMDL Mdl; UNICODE_STRING CapturedFileName; PUNICODE_STRING SearchPattern; @@ -1526,25 +1518,19 @@ /* Check if this is buffered I/O */ if (DeviceObject->Flags & DO_BUFFERED_IO) { - /* Enter SEH */ - _SEH2_TRY - { - /* Allocate a buffer */ - Irp->AssociatedIrp.SystemBuffer = - ExAllocatePoolWithTag(NonPagedPool, - Length, - TAG_SYSB); - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + /* Allocate a buffer */ + Irp->AssociatedIrp.SystemBuffer = ExAllocatePoolWithTag(NonPagedPool, + Length, + TAG_SYSB); + if (!Irp->AssociatedIrp.SystemBuffer) { /* Allocating failed, clean up and return the exception code */ IopCleanupAfterException(FileObject, Irp, Event, NULL); if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB); /* Return the exception code */ - _SEH2_YIELD(return _SEH2_GetExceptionCode()); - } - _SEH2_END; + return STATUS_INSUFFICIENT_RESOURCES; + } /* Set the buffer and flags */ Irp->UserBuffer = FileInformation; Modified: trunk/reactos/ntoskrnl/io/pnpmgr/plugplay.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/plugpla…
============================================================================== --- trunk/reactos/ntoskrnl/io/pnpmgr/plugplay.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/io/pnpmgr/plugplay.c [iso-8859-1] Sat Sep 29 22:44:48 2012 @@ -167,7 +167,7 @@ IopCaptureUnicodeString(PUNICODE_STRING DstName, PUNICODE_STRING SrcName) { NTSTATUS Status = STATUS_SUCCESS; - UNICODE_STRING Name; + volatile UNICODE_STRING Name; Name.Buffer = NULL; _SEH2_TRY
12 years, 2 months
1
0
0
0
[akhaldi] 57436: [BROWSEUI_WINETEST]: Sync to Wine 1.5.13. CORE-6415
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Sep 29 17:50:50 2012 New Revision: 57436 URL:
http://svn.reactos.org/svn/reactos?rev=57436&view=rev
Log: [BROWSEUI_WINETEST]: Sync to Wine 1.5.13. CORE-6415 Modified: trunk/rostests/winetests/browseui/CMakeLists.txt trunk/rostests/winetests/browseui/progressdlg.c Modified: trunk/rostests/winetests/browseui/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/browseui/CMakeL…
============================================================================== --- trunk/rostests/winetests/browseui/CMakeLists.txt [iso-8859-1] (original) +++ trunk/rostests/winetests/browseui/CMakeLists.txt [iso-8859-1] Sat Sep 29 17:50:50 2012 @@ -1,7 +1,5 @@ -add_definitions( - -D__ROS_LONG64__ - -D_DLL -D__USE_CRTIMP) +add_definitions(-D__ROS_LONG64__) add_executable(browseui_winetest autocomplete.c Modified: trunk/rostests/winetests/browseui/progressdlg.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/browseui/progre…
============================================================================== --- trunk/rostests/winetests/browseui/progressdlg.c [iso-8859-1] (original) +++ trunk/rostests/winetests/browseui/progressdlg.c [iso-8859-1] Sat Sep 29 17:50:50 2012 @@ -39,19 +39,19 @@ return; } - hr = IUnknown_QueryInterface(dlg, &IID_IUnknown, NULL); + hr = IProgressDialog_QueryInterface(dlg, &IID_IUnknown, NULL); ok(hr == E_POINTER, "got 0x%x (expected E_POINTER)\n", hr); - hr = IUnknown_QueryInterface(dlg, &IID_IUnknown, (void**)&unk); + hr = IProgressDialog_QueryInterface(dlg, &IID_IUnknown, (void**)&unk); ok(hr == S_OK, "QueryInterface (IUnknown) returned 0x%x\n", hr); if (SUCCEEDED(hr)) { IUnknown_Release(unk); } - hr = IUnknown_QueryInterface(dlg, &IID_IOleWindow, (void**)&olewindow); + hr = IProgressDialog_QueryInterface(dlg, &IID_IOleWindow, (void**)&olewindow); ok(hr == S_OK, "QueryInterface (IOleWindow) returned 0x%x\n", hr); if (SUCCEEDED(hr)) { - hr = IUnknown_QueryInterface(olewindow, &IID_IProgressDialog, (void**)&dlg2); + hr = IOleWindow_QueryInterface(olewindow, &IID_IProgressDialog, (void**)&dlg2); ok(hr == S_OK, "QueryInterface (IProgressDialog) returned 0x%x\n", hr); if (SUCCEEDED(hr)) { IProgressDialog_Release(dlg2);
12 years, 2 months
1
0
0
0
[tkreuzer] 57434: [LAN] Improve formatting, move function comments out of the function body and convert them to javadoc / doxygen style
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sat Sep 29 16:19:30 2012 New Revision: 57434 URL:
http://svn.reactos.org/svn/reactos?rev=57434&view=rev
Log: [LAN] Improve formatting, move function comments out of the function body and convert them to javadoc / doxygen style Modified: trunk/reactos/drivers/network/lan/lan/lan.c Modified: trunk/reactos/drivers/network/lan/lan/lan.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/lan/lan/la…
============================================================================== --- trunk/reactos/drivers/network/lan/lan/lan.c [iso-8859-1] (original) +++ trunk/reactos/drivers/network/lan/lan/lan.c [iso-8859-1] Sat Sep 29 16:19:30 2012 @@ -14,46 +14,54 @@ ULONG DebugTraceLevel = 0x7ffffff; PDEVICE_OBJECT LanDeviceObject = NULL; -NDIS_STATUS NDISCall( +/*! + * @brief Send a request to NDIS + * + * @param Adapter = Pointer to a LAN_ADAPTER structure + * @param Type = Type of request (Set or Query) + * @param OID = Value to be set/queried for + * @param Buffer = Pointer to a buffer to use + * @param Length = Number of bytes in Buffer + * + * @return Status of operation + */ +NDIS_STATUS +NDISCall( PLAN_ADAPTER Adapter, NDIS_REQUEST_TYPE Type, NDIS_OID OID, PVOID Buffer, UINT Length) -/* - * FUNCTION: Send a request to NDIS - * ARGUMENTS: - * Adapter = Pointer to a LAN_ADAPTER structure - * Type = Type of request (Set or Query) - * OID = Value to be set/queried for - * Buffer = Pointer to a buffer to use - * Length = Number of bytes in Buffer - * RETURNS: - * Status of operation - */ { NDIS_REQUEST Request; NDIS_STATUS NdisStatus; Request.RequestType = Type; - if (Type == NdisRequestSetInformation) { - Request.DATA.SET_INFORMATION.Oid = OID; - Request.DATA.SET_INFORMATION.InformationBuffer = Buffer; + if (Type == NdisRequestSetInformation) + { + Request.DATA.SET_INFORMATION.Oid = OID; + Request.DATA.SET_INFORMATION.InformationBuffer = Buffer; Request.DATA.SET_INFORMATION.InformationBufferLength = Length; - } else { - Request.DATA.QUERY_INFORMATION.Oid = OID; - Request.DATA.QUERY_INFORMATION.InformationBuffer = Buffer; + } + else + { + Request.DATA.QUERY_INFORMATION.Oid = OID; + Request.DATA.QUERY_INFORMATION.InformationBuffer = Buffer; Request.DATA.QUERY_INFORMATION.InformationBufferLength = Length; } - if (Adapter->State != LAN_STATE_RESETTING) { + if (Adapter->State != LAN_STATE_RESETTING) + { NdisRequest(&NdisStatus, Adapter->NdisHandle, &Request); - } else { + } + else + { NdisStatus = NDIS_STATUS_NOT_ACCEPTED; } /* Wait for NDIS to complete the request */ - if (NdisStatus == NDIS_STATUS_PENDING) { + if (NdisStatus == NDIS_STATUS_PENDING) + { KeWaitForSingleObject(&Adapter->Event, UserRequest, KernelMode, @@ -66,29 +74,32 @@ } -VOID FreeAdapter( +/*! + * @brief Frees memory for a LAN_ADAPTER structure + * + * @param Adapter = Pointer to LAN_ADAPTER structure to free + */ +VOID +FreeAdapter( PLAN_ADAPTER Adapter) -/* - * FUNCTION: Frees memory for a LAN_ADAPTER structure - * ARGUMENTS: - * Adapter = Pointer to LAN_ADAPTER structure to free - */ { exFreePool(Adapter); } -VOID NTAPI ProtocolOpenAdapterComplete( +/*! + * @brief Called by NDIS to complete opening of an adapter + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + * @param Status = Status of the operation + * @param OpenErrorStatus = Additional status information + */ +VOID +NTAPI +ProtocolOpenAdapterComplete( NDIS_HANDLE BindingContext, NDIS_STATUS Status, NDIS_STATUS OpenErrorStatus) -/* - * FUNCTION: Called by NDIS to complete opening of an adapter - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - * Status = Status of the operation - * OpenErrorStatus = Additional status information - */ { PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext; @@ -98,15 +109,17 @@ } -VOID NTAPI ProtocolCloseAdapterComplete( +/*! + * @brief Called by NDIS to complete closing an adapter + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + * @param Status = Status of the operation + */ +VOID +NTAPI +ProtocolCloseAdapterComplete( NDIS_HANDLE BindingContext, NDIS_STATUS Status) -/* - * FUNCTION: Called by NDIS to complete closing an adapter - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - * Status = Status of the operation - */ { PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext; @@ -118,31 +131,35 @@ } -VOID NTAPI ProtocolResetComplete( +/*! + * @brief Called by NDIS to complete resetting an adapter + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + * @param Status = Status of the operation + */ +VOID +NTAPI +ProtocolResetComplete( NDIS_HANDLE BindingContext, NDIS_STATUS Status) -/* - * FUNCTION: Called by NDIS to complete resetting an adapter - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - * Status = Status of the operation - */ { LA_DbgPrint(MID_TRACE, ("Called.\n")); } -VOID NTAPI ProtocolRequestComplete( +/*! + * @brief Called by NDIS to complete a request + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + * @param NdisRequest = Pointer to an object describing the request + * @param Status = Status of the operation + */ +VOID +NTAPI +ProtocolRequestComplete( NDIS_HANDLE BindingContext, PNDIS_REQUEST NdisRequest, NDIS_STATUS Status) -/* - * FUNCTION: Called by NDIS to complete a request - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - * NdisRequest = Pointer to an object describing the request - * Status = Status of the operation - */ { PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext; @@ -155,17 +172,19 @@ } -VOID NTAPI ProtocolSendComplete( +/*! + * @brief Called by NDIS to complete sending process + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + * @param Packet = Pointer to a packet descriptor + * @param Status = Status of the operation + */ +VOID +NTAPI +ProtocolSendComplete( NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status) -/* - * FUNCTION: Called by NDIS to complete sending process - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - * Packet = Pointer to a packet descriptor - * Status = Status of the operation - */ { /*PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;*/ @@ -175,22 +194,24 @@ } -VOID NTAPI ProtocolTransferDataComplete( +/*! + * @brief Called by NDIS to complete reception of data + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + * @param Packet = Pointer to a packet descriptor + * @param Status = Status of the operation + * @param BytesTransferred = Number of bytes transferred + * + * @note If the packet was successfully received, determine the protocol + * type and pass it to the correct receive handler + */ +VOID +NTAPI +ProtocolTransferDataComplete( NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status, UINT BytesTransferred) -/* - * FUNCTION: Called by NDIS to complete reception of data - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - * Packet = Pointer to a packet descriptor - * Status = Status of the operation - * BytesTransferred = Number of bytes transferred - * NOTES: - * If the packet was successfully received, determine the protocol - * type and pass it to the correct receive handler - */ { PLIST_ENTRY ListEntry, ReadListEntry; PLAN_PROTOCOL Proto; @@ -206,9 +227,10 @@ LA_DbgPrint(DEBUG_DATALINK, ("Called.\n")); - KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql ); - - if (Status == NDIS_STATUS_SUCCESS) { + KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql); + + if (Status == NDIS_STATUS_SUCCESS) + { PNDIS_BUFFER NdisBuffer; NdisGetFirstBufferFromPacket(Packet, @@ -217,93 +239,119 @@ &ContigSize, &LPPacket.TotalSize); - LPPacket.TotalSize = BytesTransferred; + LPPacket.TotalSize = BytesTransferred; /* Determine which upper layer protocol that should receive this packet and pass it to the correct receive handler */ - /*OskitDumpBuffer( IPPacket.Header, BytesTransferred );*/ + /*OskitDumpBuffer(IPPacket.Header, BytesTransferred);*/ PacketType = LPPacket.EthHeader->EType; - LA_DbgPrint - (DEBUG_DATALINK, - ("Ether Type = %x Total = %d Packet %x Payload %x\n", - PacketType, LPPacket.TotalSize, LPPacket.EthHeader, - LPPacket.EthHeader + 1)); - - NdisBuffer->Next = NULL; - - for( ListEntry = DeviceExt->ProtocolListHead.Flink; - ListEntry != &DeviceExt->ProtocolListHead; - ListEntry = ListEntry->Flink ) { - Proto = CONTAINING_RECORD(ListEntry, LAN_PROTOCOL, ListEntry); - LA_DbgPrint(MID_TRACE,("Examining protocol %x\n", Proto)); - for( i = 0; i < Proto->NumEtherTypes; i++ ) { - LA_DbgPrint(MID_TRACE,(".Accepts proto %x\n", - Proto->EtherType[i])); - if( Proto->EtherType[i] == PacketType && - !IsListEmpty( &Proto->ReadIrpListHead ) ) { - ReadListEntry = RemoveHeadList( &Proto->ReadIrpListHead ); - ReadIrp = CONTAINING_RECORD(ReadListEntry, IRP, - Tail.Overlay.ListEntry ); - LA_DbgPrint(MID_TRACE,("..Irp %x\n", ReadIrp)); - _SEH2_TRY { - Header = ReadIrp->AssociatedIrp.SystemBuffer; - LA_DbgPrint - (MID_TRACE, - ("Writing packet at %x\n", Header)); - Header->Fixed.Adapter = Adapter->Index; - Header->Fixed.AddressType = Adapter->Media; - Header->Fixed.AddressLen = IEEE_802_ADDR_LENGTH; - Header->Fixed.PacketType = PacketType; - RtlCopyMemory( Header->Address, - LPPacket.EthHeader->SrcAddr, - IEEE_802_ADDR_LENGTH ); - if( Proto->Buffered ) { - LA_DbgPrint(MID_TRACE,("Buffered copy\n")); - RtlCopyMemory - ( Header->Address + - IEEE_802_ADDR_LENGTH, - LPPacket.EthHeader + 1, - LPPacket.TotalSize - - sizeof(*LPPacket.EthHeader) ); - Header->Fixed.Mdl = NULL; - } else - Header->Fixed.Mdl = NdisBuffer; - - ReadIrp->IoStatus.Status = 0; - ReadIrp->IoStatus.Information = - (Header->Address + IEEE_802_ADDR_LENGTH + - LPPacket.TotalSize - - sizeof(*LPPacket.EthHeader)) - - (PCHAR)Header; - - LA_DbgPrint(MID_TRACE,("Bytes returned %d\n", - ReadIrp->IoStatus.Information)); - - IoCompleteRequest( ReadIrp, IO_NETWORK_INCREMENT ); - } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - LA_DbgPrint - (MIN_TRACE, - ("Failed write to packet in client\n")); - ReadIrp->IoStatus.Status = STATUS_ACCESS_VIOLATION; - ReadIrp->IoStatus.Information = 0; - IoCompleteRequest( ReadIrp, IO_NETWORK_INCREMENT ); - } _SEH2_END; - break; - } - } - } - } - - KeReleaseSpinLock( &DeviceExt->Lock, OldIrql ); - - FreeNdisPacket( Packet ); -} - - -NDIS_STATUS NTAPI ProtocolReceive( + LA_DbgPrint(DEBUG_DATALINK, + ("Ether Type = %x Total = %d Packet %x Payload %x\n", + PacketType, LPPacket.TotalSize, LPPacket.EthHeader, + LPPacket.EthHeader + 1)); + + NdisBuffer->Next = NULL; + + for (ListEntry = DeviceExt->ProtocolListHead.Flink; + ListEntry != &DeviceExt->ProtocolListHead; + ListEntry = ListEntry->Flink) + { + Proto = CONTAINING_RECORD(ListEntry, LAN_PROTOCOL, ListEntry); + LA_DbgPrint(MID_TRACE,("Examining protocol %x\n", Proto)); + + for (i = 0; i < Proto->NumEtherTypes; i++) + { + LA_DbgPrint(MID_TRACE,(".Accepts proto %x\n", + Proto->EtherType[i])); + + if (Proto->EtherType[i] == PacketType && + !IsListEmpty(&Proto->ReadIrpListHead)) + { + ReadListEntry = RemoveHeadList(&Proto->ReadIrpListHead); + ReadIrp = CONTAINING_RECORD(ReadListEntry, + IRP, + Tail.Overlay.ListEntry); + LA_DbgPrint(MID_TRACE,("..Irp %x\n", ReadIrp)); + + _SEH2_TRY + { + Header = ReadIrp->AssociatedIrp.SystemBuffer; + LA_DbgPrint(MID_TRACE, + ("Writing packet at %x\n", Header)); + + Header->Fixed.Adapter = Adapter->Index; + Header->Fixed.AddressType = Adapter->Media; + Header->Fixed.AddressLen = IEEE_802_ADDR_LENGTH; + Header->Fixed.PacketType = PacketType; + + RtlCopyMemory(Header->Address, + LPPacket.EthHeader->SrcAddr, + IEEE_802_ADDR_LENGTH); + + if (Proto->Buffered) + { + LA_DbgPrint(MID_TRACE,("Buffered copy\n")); + RtlCopyMemory(Header->Address + IEEE_802_ADDR_LENGTH, + LPPacket.EthHeader + 1, + LPPacket.TotalSize - + sizeof(*LPPacket.EthHeader) ); + Header->Fixed.Mdl = NULL; + } + else + Header->Fixed.Mdl = NdisBuffer; + + ReadIrp->IoStatus.Status = 0; + ReadIrp->IoStatus.Information = + (Header->Address + IEEE_802_ADDR_LENGTH + + LPPacket.TotalSize - + sizeof(*LPPacket.EthHeader)) - + (PCHAR)Header; + + LA_DbgPrint(MID_TRACE,("Bytes returned %d\n", + ReadIrp->IoStatus.Information)); + + IoCompleteRequest(ReadIrp, IO_NETWORK_INCREMENT); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + LA_DbgPrint(MIN_TRACE, + ("Failed write to packet in client\n")); + ReadIrp->IoStatus.Status = STATUS_ACCESS_VIOLATION; + ReadIrp->IoStatus.Information = 0; + IoCompleteRequest(ReadIrp, IO_NETWORK_INCREMENT); + } + _SEH2_END; + break; + } + } + } + } + + KeReleaseSpinLock(&DeviceExt->Lock, OldIrql); + + FreeNdisPacket(Packet); +} + + +/*! + * @brief Called by NDIS when a packet has been received on the physical link + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + * @param MacReceiveContext = Handle used by underlying NIC driver + * @param HeaderBuffer = Pointer to a buffer containing the packet header + * @param HeaderBufferSize = Number of bytes in HeaderBuffer + * @param LookaheadBuffer = Pointer to a buffer containing buffered packet data + * @param LookaheadBufferSize = Size of LookaheadBuffer. May be less than asked for + * @param PacketSize = Overall size of the packet (not including header) + * + * @return Status of operation + */ +NDIS_STATUS +NTAPI +ProtocolReceive( NDIS_HANDLE BindingContext, NDIS_HANDLE MacReceiveContext, PVOID HeaderBuffer, @@ -311,19 +359,6 @@ PVOID LookaheadBuffer, UINT LookaheadBufferSize, UINT PacketSize) -/* - * FUNCTION: Called by NDIS when a packet has been received on the physical link - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - * MacReceiveContext = Handle used by underlying NIC driver - * HeaderBuffer = Pointer to a buffer containing the packet header - * HeaderBufferSize = Number of bytes in HeaderBuffer - * LookaheadBuffer = Pointer to a buffer containing buffered packet data - * LookaheadBufferSize = Size of LookaheadBuffer. May be less than asked for - * PacketSize = Overall size of the packet (not including header) - * RETURNS: - * Status of operation - */ { USHORT EType; UINT PacketType, BytesTransferred; @@ -334,12 +369,14 @@ LA_DbgPrint(DEBUG_DATALINK, ("Called. (packetsize %d)\n",PacketSize)); - if (Adapter->State != LAN_STATE_STARTED) { + if (Adapter->State != LAN_STATE_STARTED) + { LA_DbgPrint(DEBUG_DATALINK, ("Adapter is stopped.\n")); return NDIS_STATUS_NOT_ACCEPTED; } - if (HeaderBufferSize < Adapter->HeaderSize) { + if (HeaderBufferSize < Adapter->HeaderSize) + { LA_DbgPrint(DEBUG_DATALINK, ("Runt frame received.\n")); return NDIS_STATUS_NOT_ACCEPTED; } @@ -348,35 +385,45 @@ /* Get a transfer data packet */ KeAcquireSpinLockAtDpcLevel(&Adapter->Lock); - NdisStatus = AllocatePacketWithBuffer( &NdisPacket, NULL, Adapter->MTU ); - if( NdisStatus != NDIS_STATUS_SUCCESS ) { + NdisStatus = AllocatePacketWithBuffer(&NdisPacket, NULL, Adapter->MTU); + if (NdisStatus != NDIS_STATUS_SUCCESS) + { KeReleaseSpinLockFromDpcLevel(&Adapter->Lock); return NDIS_STATUS_NOT_ACCEPTED; } - LA_DbgPrint(DEBUG_DATALINK, ("pretransfer LookaheadBufferSize %d packsize %d\n",LookaheadBufferSize,PacketSize)); - { - UINT temp; - temp = PacketSize; - GetDataPtr( NdisPacket, 0, &BufferData, &temp ); - } - - LA_DbgPrint(DEBUG_DATALINK, ("pretransfer LookaheadBufferSize %d HeaderBufferSize %d packsize %d\n",LookaheadBufferSize,HeaderBufferSize,PacketSize)); + + LA_DbgPrint(DEBUG_DATALINK, + ("pretransfer LookaheadBufferSize %d packsize %d\n", + LookaheadBufferSize,PacketSize)); + + { + UINT temp; + temp = PacketSize; + GetDataPtr(NdisPacket, 0, &BufferData, &temp); + } + + LA_DbgPrint(DEBUG_DATALINK, + ("pretransfer LookaheadBufferSize %d HeaderBufferSize %d packsize %d\n", + LookaheadBufferSize,HeaderBufferSize,PacketSize)); + /* Get the data */ NdisTransferData(&NdisStatus, - Adapter->NdisHandle, - MacReceiveContext, - 0, - PacketSize + HeaderBufferSize, - NdisPacket, - &BytesTransferred); + Adapter->NdisHandle, + MacReceiveContext, + 0, + PacketSize + HeaderBufferSize, + NdisPacket, + &BytesTransferred); LA_DbgPrint(DEBUG_DATALINK, ("Calling complete\n")); if (NdisStatus != NDIS_STATUS_PENDING) - ProtocolTransferDataComplete(BindingContext, - NdisPacket, - NdisStatus, - PacketSize + HeaderBufferSize); + { + ProtocolTransferDataComplete(BindingContext, + NdisPacket, + NdisStatus, + PacketSize + HeaderBufferSize); + } /* Release the packet descriptor */ KeReleaseSpinLockFromDpcLevel(&Adapter->Lock); @@ -386,63 +433,72 @@ } -VOID NTAPI ProtocolReceiveComplete( +/*! + * @brief Called by NDIS when we're done receiving data + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + */ +VOID +NTAPI +ProtocolReceiveComplete( NDIS_HANDLE BindingContext) -/* - * FUNCTION: Called by NDIS when we're done receiving data - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - */ { LA_DbgPrint(DEBUG_DATALINK, ("Called.\n")); } -VOID NTAPI ProtocolStatus( +/*! + * @brief Called by NDIS when the underlying driver has changed state + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + * @param GenerelStatus = A generel status code + * @param StatusBuffer = Pointer to a buffer with medium-specific data + * @param StatusBufferSize = Number of bytes in StatusBuffer + */ +VOID +NTAPI +ProtocolStatus( NDIS_HANDLE BindingContext, NDIS_STATUS GenerelStatus, PVOID StatusBuffer, UINT StatusBufferSize) -/* - * FUNCTION: Called by NDIS when the underlying driver has changed state - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - * GenerelStatus = A generel status code - * StatusBuffer = Pointer to a buffer with medium-specific data - * StatusBufferSize = Number of bytes in StatusBuffer - */ { LA_DbgPrint(DEBUG_DATALINK, ("Called.\n")); } -VOID NTAPI ProtocolStatusComplete( +/*! + * @brief Called by NDIS when a status-change has occurred + * + * @param BindingContext = Pointer to a device context (LAN_ADAPTER) + */ +VOID +NTAPI +ProtocolStatusComplete( NDIS_HANDLE NdisBindingContext) -/* - * FUNCTION: Called by NDIS when a status-change has occurred - * ARGUMENTS: - * BindingContext = Pointer to a device context (LAN_ADAPTER) - */ { LA_DbgPrint(DEBUG_DATALINK, ("Called.\n")); } -VOID NTAPI ProtocolBindAdapter( +/*! + * @brief Called by NDIS during NdisRegisterProtocol to set up initial + * bindings, and periodically thereafer as new adapters come online + * + * @param Status - Return value to NDIS + * @param BindContext - Handle provided by NDIS to track pending binding operations + * @param DeviceName - Name of the miniport device to bind to + * @param SystemSpecific1 - Pointer to a registry path with protocol-specific + * configuration information + * @param SystemSpecific2 - Unused & must not be touched + */ +VOID +NTAPI +ProtocolBindAdapter( OUT PNDIS_STATUS Status, IN NDIS_HANDLE BindContext, IN PNDIS_STRING DeviceName, IN PVOID SystemSpecific1, IN PVOID SystemSpecific2) -/* - * FUNCTION: Called by NDIS during NdisRegisterProtocol to set up initial - * bindings, and periodically thereafer as new adapters come online - * ARGUMENTS: - * Status: Return value to NDIS - * BindContext: Handle provided by NDIS to track pending binding operations - * DeviceName: Name of the miniport device to bind to - * SystemSpecific1: Pointer to a registry path with protocol-specific configuration information - * SystemSpecific2: Unused & must not be touched - */ { /* XXX confirm that this is still true, or re-word the following comment */ /* we get to ignore BindContext because we will never pend an operation with NDIS */ @@ -451,35 +507,41 @@ } -VOID LANTransmit( +/*! + * @brief Transmits a packet + * ARGUMENTS: + * @param Context = Pointer to context information (LAN_ADAPTER) + * @param NdisPacket = Pointer to NDIS packet to send + * @param LinkAddress = Pointer to link address of destination (NULL = broadcast) + * @param Type = LAN protocol type (LAN_PROTO_*) + */ +VOID +LANTransmit( PLAN_ADAPTER Adapter, PNDIS_PACKET NdisPacket, PVOID LinkAddress, USHORT Type) -/* - * FUNCTION: Transmits a packet - * ARGUMENTS: - * Context = Pointer to context information (LAN_ADAPTER) - * NdisPacket = Pointer to NDIS packet to send - * LinkAddress = Pointer to link address of destination (NULL = broadcast) - * Type = LAN protocol type (LAN_PROTO_*) - */ { NDIS_STATUS NdisStatus; LA_DbgPrint(DEBUG_DATALINK, ("Called.\n")); - if (Adapter->State == LAN_STATE_STARTED) { + if (Adapter->State == LAN_STATE_STARTED) + { NdisSend(&NdisStatus, Adapter->NdisHandle, NdisPacket); if (NdisStatus != NDIS_STATUS_PENDING) ProtocolSendComplete((NDIS_HANDLE)Adapter, NdisPacket, NdisStatus); - } else { + } + else + { ProtocolSendComplete((NDIS_HANDLE)Adapter, NdisPacket, NDIS_STATUS_CLOSED); } } /* For use internally */ -UINT LANTransmitInternal(PLAN_PACKET_HEADER ToWrite, UINT OverallLength) { +UINT +LANTransmitInternal(PLAN_PACKET_HEADER ToWrite, UINT OverallLength) +{ NDIS_STATUS NdisStatus; PLAN_DEVICE_EXT DeviceExt = LanDeviceObject->DeviceExtension; PLAN_ADAPTER Adapter; @@ -487,61 +549,71 @@ KIRQL OldIrql; PNDIS_PACKET NdisPacket; UINT Size, PayloadSize = OverallLength - - ((ToWrite->Address + ToWrite->Fixed.AddressLen) - (PCHAR)ToWrite); - - NdisStatus = AllocatePacketWithBuffer( &NdisPacket, NULL, - PayloadSize + sizeof(ETH_HEADER) ); - - KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql ); - - if( !NT_SUCCESS(NdisStatus) ) goto end; - - Adapter = FindAdapterByIndex( DeviceExt, ToWrite->Fixed.Adapter ); - - if( !Adapter ) goto end; - - GetDataPtr( NdisPacket, 0, (PCHAR *)&EthHeader, &Size ); - if( !EthHeader ) goto end; + ((ToWrite->Address + ToWrite->Fixed.AddressLen) - (PCHAR)ToWrite); + + NdisStatus = AllocatePacketWithBuffer(&NdisPacket, NULL, + PayloadSize + sizeof(ETH_HEADER)); + + KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql); + + if (!NT_SUCCESS(NdisStatus)) goto end; + + Adapter = FindAdapterByIndex(DeviceExt, ToWrite->Fixed.Adapter); + + if (!Adapter) goto end; + + GetDataPtr(NdisPacket, 0, (PCHAR *)&EthHeader, &Size); + if (!EthHeader) goto end; LA_DbgPrint(MID_TRACE,("Writing %d bytes of Dst\n", - ToWrite->Fixed.AddressLen)); + ToWrite->Fixed.AddressLen)); /* Handle broadcast for other media types here */ - if( ToWrite->Fixed.AddressLen ) - RtlCopyMemory( EthHeader->DstAddr, - ToWrite->Address, - ToWrite->Fixed.AddressLen ); + if (ToWrite->Fixed.AddressLen) + { + RtlCopyMemory(EthHeader->DstAddr, + ToWrite->Address, + ToWrite->Fixed.AddressLen); + } else - memset( EthHeader->DstAddr, -1, sizeof(EthHeader->DstAddr) ); - - LA_DbgPrint(MID_TRACE,("Writing %d bytes of Src\n", Adapter->HWAddressLength)); - RtlCopyMemory( EthHeader->SrcAddr, - Adapter->HWAddress, - Adapter->HWAddressLength ); - LA_DbgPrint(MID_TRACE,("Writing %d bytes of payload\n", PayloadSize)); + memset(EthHeader->DstAddr, -1, sizeof(EthHeader->DstAddr)); + + LA_DbgPrint(MID_TRACE, + ("Writing %d bytes of Src\n", Adapter->HWAddressLength)); + + RtlCopyMemory(EthHeader->SrcAddr, + Adapter->HWAddress, + Adapter->HWAddressLength); + + LA_DbgPrint(MID_TRACE, + ("Writing %d bytes of payload\n", PayloadSize)); + EthHeader->EType = ToWrite->Fixed.PacketType; - RtlCopyMemory( EthHeader + 1, - ToWrite->Address + ToWrite->Fixed.AddressLen, - PayloadSize ); - - LANTransmit( Adapter, NdisPacket, ToWrite->Address, - ToWrite->Fixed.PacketType ); + RtlCopyMemory(EthHeader + 1, + ToWrite->Address + ToWrite->Fixed.AddressLen, + PayloadSize); + + LANTransmit(Adapter, + NdisPacket, + ToWrite->Address, + ToWrite->Fixed.PacketType); end: - KeReleaseSpinLock( &DeviceExt->Lock, OldIrql ); + KeReleaseSpinLock(&DeviceExt->Lock, OldIrql); return OverallLength; } -VOID BindAdapter(PLAN_ADAPTER Adapter, PNDIS_STRING RegistryPath) -/* - * FUNCTION: Binds a LAN adapter to IP layer - * ARGUMENTS: - * Adapter = Pointer to LAN_ADAPTER structure - * NOTES: - * We set the lookahead buffer size, set the packet filter and - * bind the adapter to IP layer - */ +/*! + * @brief Binds a LAN adapter to IP layer + * + * @param Adapter = Pointer to LAN_ADAPTER structure + * + * @note We set the lookahead buffer size, set the packet filter and + * bind the adapter to IP layer + */ +VOID +BindAdapter(PLAN_ADAPTER Adapter, PNDIS_STRING RegistryPath) { /*NDIS_STATUS NdisStatus;*/ /*ULONG Lookahead = LOOKAHEAD_SIZE;*/ @@ -552,16 +624,18 @@ } -NDIS_STATUS LANRegisterAdapter( PNDIS_STRING AdapterName, - PNDIS_STRING RegistryPath) -/* - * FUNCTION: Registers protocol with an NDIS adapter - * ARGUMENTS: - * AdapterName = Pointer to string with name of adapter to register - * Adapter = Address of pointer to a LAN_ADAPTER structure - * RETURNS: - * Status of operation - */ +/*! + * @brief Registers protocol with an NDIS adapter + * + * @param AdapterName = Pointer to string with name of adapter to register + * @param Adapter = Address of pointer to a LAN_ADAPTER structure + * + * @return Status of operation + */ +NDIS_STATUS +LANRegisterAdapter( + PNDIS_STRING AdapterName, + PNDIS_STRING RegistryPath) { PLAN_ADAPTER Adapter; NDIS_MEDIUM MediaArray[MAX_MEDIA]; @@ -575,7 +649,8 @@ LA_DbgPrint(DEBUG_DATALINK, ("Called.\n")); Adapter = exAllocatePool(NonPagedPool, sizeof(LAN_ADAPTER)); - if (!Adapter) { + if (!Adapter) + { LA_DbgPrint(MIN_TRACE, ("Insufficient resources.\n")); return NDIS_STATUS_RESOURCES; } @@ -586,8 +661,8 @@ Adapter->State = LAN_STATE_STOPPED; Adapter->Index = DeviceExt->AdapterId++; - InitializeListHead( &Adapter->AddressList ); - InitializeListHead( &Adapter->ForeignList ); + InitializeListHead(&Adapter->AddressList); + InitializeListHead(&Adapter->ForeignList); /* Initialize protecting spin lock */ KeInitializeSpinLock(&Adapter->Lock); @@ -598,6 +673,7 @@ MediaArray[MEDIA_ETH] = NdisMedium802_3; LA_DbgPrint(DEBUG_DATALINK,("opening adapter %wZ\n", AdapterName)); + /* Open the adapter. */ NdisOpenAdapter(&NdisStatus, &OpenStatus, @@ -614,15 +690,17 @@ /* Wait until the adapter is opened */ if (NdisStatus == NDIS_STATUS_PENDING) KeWaitForSingleObject(&Adapter->Event, UserRequest, KernelMode, FALSE, NULL); - else if (NdisStatus != NDIS_STATUS_SUCCESS) { - exFreePool(Adapter); + else if (NdisStatus != NDIS_STATUS_SUCCESS) + { + exFreePool(Adapter); return NdisStatus; } Adapter->Media = MediaArray[MediaIndex]; /* Fill LAN_ADAPTER structure with some adapter specific information */ - switch (Adapter->Media) { + switch (Adapter->Media) + { case NdisMedium802_3: Adapter->HWAddressLength = IEEE_802_ADDR_LENGTH; Adapter->BCastMask = BCAST_ETH_MASK; @@ -650,7 +728,8 @@ OID_GEN_MAXIMUM_FRAME_SIZE, &Adapter->MTU, sizeof(UINT)); - if (NdisStatus != NDIS_STATUS_SUCCESS) { + if (NdisStatus != NDIS_STATUS_SUCCESS) + { exFreePool(Adapter); return NdisStatus; } @@ -661,7 +740,8 @@ OID_GEN_MAXIMUM_TOTAL_SIZE, &Adapter->MaxPacketSize, sizeof(UINT)); - if (NdisStatus != NDIS_STATUS_SUCCESS) { + if (NdisStatus != NDIS_STATUS_SUCCESS) + { LA_DbgPrint(MIN_TRACE, ("Query for maximum packet size failed.\n")); exFreePool(Adapter); return NdisStatus; @@ -674,9 +754,11 @@ &Adapter->MaxSendPackets, sizeof(UINT)); if (NdisStatus != NDIS_STATUS_SUCCESS) + { /* Legacy NIC drivers may not support this query, if it fails we assume it can send at least one packet per call to NdisSend(Packets) */ Adapter->MaxSendPackets = 1; + } /* Get current hardware address */ NdisStatus = NDISCall(Adapter, @@ -684,7 +766,8 @@ AddressOID, Adapter->HWAddress, Adapter->HWAddressLength); - if (NdisStatus != NDIS_STATUS_SUCCESS) { + if (NdisStatus != NDIS_STATUS_SUCCESS) + { LA_DbgPrint(MIN_TRACE, ("Query for current hardware address failed.\n")); exFreePool(Adapter); return NdisStatus; @@ -696,7 +779,8 @@ OID_GEN_LINK_SPEED, &Speed, sizeof(UINT)); - if (NdisStatus != NDIS_STATUS_SUCCESS) { + if (NdisStatus != NDIS_STATUS_SUCCESS) + { LA_DbgPrint(MIN_TRACE, ("Query for maximum link speed failed.\n")); exFreePool(Adapter); return NdisStatus; @@ -711,22 +795,22 @@ &DeviceExt->Lock); Adapter->RegistryPath.Buffer = - ExAllocatePool( NonPagedPool, RegistryPath->MaximumLength ); - if( !Adapter->RegistryPath.Buffer ) - return NDIS_STATUS_RESOURCES; - - RtlCopyUnicodeString( &Adapter->RegistryPath, - RegistryPath ); + ExAllocatePool(NonPagedPool, RegistryPath->MaximumLength); + if (!Adapter->RegistryPath.Buffer) + return NDIS_STATUS_RESOURCES; + + RtlCopyUnicodeString(&Adapter->RegistryPath, RegistryPath); NdisStatus = NDISCall(Adapter, NdisRequestSetInformation, OID_GEN_CURRENT_LOOKAHEAD, &Adapter->Lookahead, sizeof(ULONG)); - if (NdisStatus != NDIS_STATUS_SUCCESS) { + if (NdisStatus != NDIS_STATUS_SUCCESS) + { LA_DbgPrint(MID_TRACE, - ("Could not set lookahead buffer size (0x%X).\n", - NdisStatus)); + ("Could not set lookahead buffer size (0x%X).\n", + NdisStatus)); return NdisStatus; } @@ -736,9 +820,10 @@ OID_GEN_CURRENT_PACKET_FILTER, &Adapter->PacketFilter, sizeof(UINT)); - if (NdisStatus != NDIS_STATUS_SUCCESS) { + if (NdisStatus != NDIS_STATUS_SUCCESS) + { LA_DbgPrint(MID_TRACE, ("Could not set packet filter (0x%X).\n", - NdisStatus)); + NdisStatus)); return NdisStatus; } @@ -750,15 +835,16 @@ } -NDIS_STATUS LANUnregisterAdapter( +/*! + * @brief Unregisters protocol with NDIS adapter + * + * @param Adapter = Pointer to a LAN_ADAPTER structure + * + * @return Status of operation + */ +NDIS_STATUS +LANUnregisterAdapter( PLAN_ADAPTER Adapter) -/* - * FUNCTION: Unregisters protocol with NDIS adapter - * ARGUMENTS: - * Adapter = Pointer to a LAN_ADAPTER structure - * RETURNS: - * Status of operation - */ { KIRQL OldIrql; NDIS_HANDLE NdisHandle; @@ -771,12 +857,14 @@ KeAcquireSpinLock(&Adapter->Lock, &OldIrql); NdisHandle = Adapter->NdisHandle; - if (NdisHandle) { + if (NdisHandle) + { Adapter->NdisHandle = NULL; KeReleaseSpinLock(&Adapter->Lock, OldIrql); NdisCloseAdapter(&NdisStatus, NdisHandle); - if (NdisStatus == NDIS_STATUS_PENDING) { + if (NdisStatus == NDIS_STATUS_PENDING) + { KeWaitForSingleObject(&Adapter->Event, UserRequest, KernelMode, @@ -784,7 +872,8 @@ NULL); NdisStatus = Adapter->NdisStatus; } - } else + } + else KeReleaseSpinLock(&Adapter->Lock, OldIrql); FreeAdapter(Adapter); @@ -792,14 +881,15 @@ return NDIS_STATUS_SUCCESS; } -NTSTATUS LANRegisterProtocol(PNDIS_STRING Name) -/* - * FUNCTION: Registers this protocol driver with NDIS - * ARGUMENTS: - * Name = Name of this protocol driver - * RETURNS: - * Status of operation - */ +/*! + * @brief Registers this protocol driver with NDIS + * + * @param Name = Name of this protocol driver + * + * @return Status of operation + */ +NTSTATUS +LANRegisterProtocol(PNDIS_STRING Name) { NDIS_STATUS NdisStatus; NDIS_PROTOCOL_CHARACTERISTICS ProtChars; @@ -836,7 +926,7 @@ sizeof(NDIS_PROTOCOL_CHARACTERISTICS)); if (NdisStatus != NDIS_STATUS_SUCCESS) { - LA_DbgPrint(MID_TRACE, ("NdisRegisterProtocol failed, status 0x%x\n", NdisStatus)); + LA_DbgPrint(MID_TRACE, ("NdisRegisterProtocol failed, status 0x%x\n", NdisStatus)); return (NTSTATUS)NdisStatus; } @@ -844,11 +934,12 @@ } -VOID LANUnregisterProtocol(VOID) -/* - * FUNCTION: Unregisters this protocol driver with NDIS - * NOTES: Does not care wether we are already registered - */ +/*! + * @brief Unregisters this protocol driver with NDIS + * @note Does not care wether we are already registered + */ +VOID +LANUnregisterProtocol(VOID) { PLAN_DEVICE_EXT DeviceExt = LanDeviceObject->DeviceExtension; @@ -864,40 +955,45 @@ /* Search the list and remove every adapter we find */ CurrentEntry = DeviceExt->AdapterListHead.Flink; - while (CurrentEntry != &DeviceExt->AdapterListHead) { - NextEntry = CurrentEntry->Flink; - Current = CONTAINING_RECORD(CurrentEntry, LAN_ADAPTER, ListEntry); - /* Unregister it */ - LANUnregisterAdapter(Current); - CurrentEntry = NextEntry; + while (CurrentEntry != &DeviceExt->AdapterListHead) + { + NextEntry = CurrentEntry->Flink; + Current = CONTAINING_RECORD(CurrentEntry, LAN_ADAPTER, ListEntry); + /* Unregister it */ + LANUnregisterAdapter(Current); + CurrentEntry = NextEntry; } NdisDeregisterProtocol(&NdisStatus, DeviceExt->NdisProtocolHandle); } -NTSTATUS NTAPI -LanCreateProtocol( PDEVICE_OBJECT DeviceObject, PIRP Irp, - PIO_STACK_LOCATION IrpSp ) { +NTSTATUS +NTAPI +LanCreateProtocol( + PDEVICE_OBJECT DeviceObject, + PIRP Irp, + PIO_STACK_LOCATION IrpSp) +{ PLAN_PROTOCOL Proto; PFILE_FULL_EA_INFORMATION EaInfo; - PLAN_DEVICE_EXT DeviceExt = - (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; + PLAN_DEVICE_EXT DeviceExt = (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; PFILE_OBJECT FileObject = IrpSp->FileObject; PCHAR ProtoNumbersToMatch; - UINT Size = sizeof( *Proto ); + UINT Size = sizeof(*Proto); NTSTATUS Status = STATUS_SUCCESS; EaInfo = Irp->AssociatedIrp.SystemBuffer; Size += EaInfo->EaValueLength; - Proto = ExAllocatePool( NonPagedPool, Size ); - - if( !Proto ) { - Status = Irp->IoStatus.Status = STATUS_NO_MEMORY; - IoCompleteRequest( Irp, IO_NETWORK_INCREMENT ); - return Status; - } - - RtlZeroMemory( Proto, Size ); + Proto = ExAllocatePool(NonPagedPool, Size); + + if (!Proto) + { + Status = Irp->IoStatus.Status = STATUS_NO_MEMORY; + IoCompleteRequest(Irp, IO_NETWORK_INCREMENT); + return Status; + } + + RtlZeroMemory(Proto, Size); Proto->Id = DeviceExt->ProtoId++; Proto->NumEtherTypes = EaInfo->EaValueLength / sizeof(USHORT); @@ -905,34 +1001,37 @@ LA_DbgPrint(MID_TRACE,("NumEtherTypes: %d\n", Proto->NumEtherTypes)); - RtlCopyMemory( Proto->EtherType, - ProtoNumbersToMatch, - sizeof(USHORT) * Proto->NumEtherTypes ); - - InitializeListHead( &Proto->ReadIrpListHead ); + RtlCopyMemory(Proto->EtherType, + ProtoNumbersToMatch, + sizeof(USHORT) * Proto->NumEtherTypes); + + InitializeListHead(&Proto->ReadIrpListHead); FileObject->FsContext = Proto; LA_DbgPrint(MID_TRACE,("DeviceExt: %x, Proto %x\n", DeviceExt, Proto)); - ExInterlockedInsertTailList( &DeviceExt->ProtocolListHead, - &Proto->ListEntry, - &DeviceExt->Lock ); + ExInterlockedInsertTailList(&DeviceExt->ProtocolListHead, + &Proto->ListEntry, + &DeviceExt->Lock); Irp->IoStatus.Information = 0; Irp->IoStatus.Status = STATUS_SUCCESS; LA_DbgPrint(MID_TRACE,("Status %x\n", Irp->IoStatus.Status)); - IoCompleteRequest( Irp, IO_NO_INCREMENT ); + IoCompleteRequest(Irp, IO_NO_INCREMENT); return STATUS_SUCCESS; } -NTSTATUS NTAPI -LanCloseProtocol( PDEVICE_OBJECT DeviceObject, PIRP Irp, - PIO_STACK_LOCATION IrpSp ) { - PLAN_DEVICE_EXT DeviceExt = - (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; +NTSTATUS +NTAPI +LanCloseProtocol( + PDEVICE_OBJECT DeviceObject, + PIRP Irp, + PIO_STACK_LOCATION IrpSp) +{ + PLAN_DEVICE_EXT DeviceExt = (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; PFILE_OBJECT FileObject = IrpSp->FileObject; PLAN_PROTOCOL Proto = FileObject->FsContext; KIRQL OldIrql; @@ -942,43 +1041,51 @@ LA_DbgPrint(MID_TRACE,("Called\n")); - KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql ); - - while( !IsListEmpty( &Proto->ReadIrpListHead ) ) { - ReadIrpListEntry = RemoveHeadList( &Proto->ReadIrpListHead ); - - ReadIrp = CONTAINING_RECORD( ReadIrpListEntry, IRP, - Tail.Overlay.ListEntry ); - ReadIrp->IoStatus.Information = 0; - ReadIrp->IoStatus.Status = STATUS_UNSUCCESSFUL; - IoCompleteRequest( ReadIrp, IO_NO_INCREMENT ); - } - - RemoveEntryList( &Proto->ListEntry ); - - KeReleaseSpinLock( &DeviceExt->Lock, OldIrql ); + KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql); + + while (!IsListEmpty(&Proto->ReadIrpListHead)) + { + ReadIrpListEntry = RemoveHeadList(&Proto->ReadIrpListHead); + + ReadIrp = CONTAINING_RECORD(ReadIrpListEntry, + IRP, + Tail.Overlay.ListEntry); + ReadIrp->IoStatus.Information = 0; + ReadIrp->IoStatus.Status = STATUS_UNSUCCESSFUL; + IoCompleteRequest(ReadIrp, IO_NO_INCREMENT); + } + + RemoveEntryList(&Proto->ListEntry); + + KeReleaseSpinLock(&DeviceExt->Lock, OldIrql); LA_DbgPrint(MID_TRACE,("Deleting %x\n")); - ExFreePool( Proto ); + ExFreePool(Proto); Status = Irp->IoStatus.Status = STATUS_SUCCESS; - IoCompleteRequest( Irp, IO_NO_INCREMENT ); + IoCompleteRequest(Irp, IO_NO_INCREMENT); return Status; } -PLAN_ADAPTER FindAdapterByIndex( PLAN_DEVICE_EXT DeviceExt, UINT Index ) { +PLAN_ADAPTER +FindAdapterByIndex( + PLAN_DEVICE_EXT DeviceExt, + UINT Index) +{ PLIST_ENTRY ListEntry; PLAN_ADAPTER Current, Target = NULL; - for( ListEntry = DeviceExt->AdapterListHead.Flink; - ListEntry != &DeviceExt->AdapterListHead; - ListEntry = ListEntry->Flink ) { - Current = CONTAINING_RECORD(ListEntry, LAN_ADAPTER, ListEntry); - if( Current->Index == Index ) { - Target = Current; - break; - } + for (ListEntry = DeviceExt->AdapterListHead.Flink; + ListEntry != &DeviceExt->AdapterListHead; + ListEntry = ListEntry->Flink) + { + Current = CONTAINING_RECORD(ListEntry, LAN_ADAPTER, ListEntry); + if (Current->Index == Index) + { + Target = Current; + break; + } } return Target; @@ -988,50 +1095,61 @@ * |<- 16 >| |<-- variable ... -->| * [indx] [addrtype] [addrlen ] [ptype] [packet-data ...] */ -NTSTATUS NTAPI -LanWriteData( PDEVICE_OBJECT DeviceObject, PIRP Irp, - PIO_STACK_LOCATION IrpSp ) { +NTSTATUS +NTAPI +LanWriteData( + PDEVICE_OBJECT DeviceObject, + PIRP Irp, + PIO_STACK_LOCATION IrpSp) +{ PLAN_PACKET_HEADER ToWrite = Irp->AssociatedIrp.SystemBuffer; NTSTATUS Status = STATUS_SUCCESS; LA_DbgPrint(MID_TRACE,("Called\n")); Irp->IoStatus.Information = - LANTransmitInternal( ToWrite, IrpSp->Parameters.Write.Length ); + LANTransmitInternal(ToWrite, IrpSp->Parameters.Write.Length); Irp->IoStatus.Status = Status; - IoCompleteRequest( Irp, IO_NETWORK_INCREMENT ); + IoCompleteRequest(Irp, IO_NETWORK_INCREMENT); return Status; } -NTSTATUS NTAPI -LanReadData( PDEVICE_OBJECT DeviceObject, PIRP Irp, - PIO_STACK_LOCATION IrpSp ) { +NTSTATUS +NTAPI +LanReadData( + PDEVICE_OBJECT DeviceObject, + PIRP Irp, + PIO_STACK_LOCATION IrpSp) +{ PLAN_DEVICE_EXT DeviceExt = - (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; + (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; PFILE_OBJECT FileObject = IrpSp->FileObject; PLAN_PROTOCOL Proto = FileObject->FsContext; LA_DbgPrint(MID_TRACE,("Called on %x (%x)\n", Proto, Irp)); - ExInterlockedInsertTailList( &Proto->ReadIrpListHead, - &Irp->Tail.Overlay.ListEntry, - &DeviceExt->Lock ); + ExInterlockedInsertTailList(&Proto->ReadIrpListHead, + &Irp->Tail.Overlay.ListEntry, + &DeviceExt->Lock); LA_DbgPrint(MID_TRACE,("List: %x %x\n", - Proto->ReadIrpListHead.Flink, - Irp->Tail.Overlay.ListEntry.Flink)); - - IoMarkIrpPending( Irp ); + Proto->ReadIrpListHead.Flink, + Irp->Tail.Overlay.ListEntry.Flink)); + + IoMarkIrpPending(Irp); return STATUS_PENDING; } -NTSTATUS NTAPI -LanEnumAdapters( PDEVICE_OBJECT DeviceObject, PIRP Irp, - PIO_STACK_LOCATION IrpSp ) { +NTSTATUS +NTAPI +LanEnumAdapters( + PDEVICE_OBJECT DeviceObject, + PIRP Irp, + PIO_STACK_LOCATION IrpSp) +{ PLIST_ENTRY ListEntry; - PLAN_DEVICE_EXT DeviceExt = - (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; + PLAN_DEVICE_EXT DeviceExt = (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; NTSTATUS Status = STATUS_SUCCESS; PLAN_ADAPTER Adapter; UINT AdapterCount = 0; @@ -1040,45 +1158,56 @@ LA_DbgPrint(MID_TRACE,("Called\n")); - KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql ); - - for( ListEntry = DeviceExt->AdapterListHead.Flink; - ListEntry != &DeviceExt->AdapterListHead; - ListEntry = ListEntry->Flink ) AdapterCount++; - - if( IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= - AdapterCount * sizeof(UINT) ) { - for( ListEntry = DeviceExt->AdapterListHead.Flink; - ListEntry != &DeviceExt->AdapterListHead; - ListEntry = ListEntry->Flink ) { - Adapter = CONTAINING_RECORD(ListEntry, LAN_ADAPTER, ListEntry); - *Output++ = Adapter->Index; - } - } else Status = STATUS_BUFFER_TOO_SMALL; - - KeReleaseSpinLock( &DeviceExt->Lock, OldIrql ); + KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql); + + for (ListEntry = DeviceExt->AdapterListHead.Flink; + ListEntry != &DeviceExt->AdapterListHead; + ListEntry = ListEntry->Flink) + { + AdapterCount++; + } + + if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= + AdapterCount * sizeof(UINT)) + { + for (ListEntry = DeviceExt->AdapterListHead.Flink; + ListEntry != &DeviceExt->AdapterListHead; + ListEntry = ListEntry->Flink) + { + Adapter = CONTAINING_RECORD(ListEntry, LAN_ADAPTER, ListEntry); + *Output++ = Adapter->Index; + } + } + else + Status = STATUS_BUFFER_TOO_SMALL; + + KeReleaseSpinLock(&DeviceExt->Lock, OldIrql); LA_DbgPrint(MID_TRACE,("Ending\n")); Irp->IoStatus.Status = Status; Irp->IoStatus.Information = (PCHAR)Output - - (PCHAR)Irp->AssociatedIrp.SystemBuffer; - - IoCompleteRequest( Irp, IO_NO_INCREMENT ); + (PCHAR)Irp->AssociatedIrp.SystemBuffer; + + IoCompleteRequest(Irp, IO_NO_INCREMENT); return Status; } -NTSTATUS NTAPI -LanAdapterInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp, - PIO_STACK_LOCATION IrpSp ) { +NTSTATUS +NTAPI +LanAdapterInfo( + PDEVICE_OBJECT DeviceObject, + PIRP Irp, + PIO_STACK_LOCATION IrpSp) +{ PLAN_DEVICE_EXT DeviceExt = - (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; + (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; PLAN_ADAPTER Adapter; PLAN_ADDRESS_C Address; PUINT AdapterIndexPtr = Irp->AssociatedIrp.SystemBuffer; PLIST_ENTRY ListEntry; - UINT BytesNeeded = sizeof( LAN_ADAPTER_INFO ), AddrSize; + UINT BytesNeeded = sizeof(LAN_ADAPTER_INFO), AddrSize; NTSTATUS Status = STATUS_SUCCESS; PCHAR Writing = Irp->AssociatedIrp.SystemBuffer; PLAN_ADAPTER_INFO_S Info; @@ -1086,99 +1215,111 @@ LA_DbgPrint(MID_TRACE,("Called\n")); - KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql ); - - if( IrpSp->Parameters.DeviceIoControl.InputBufferLength < - sizeof(*AdapterIndexPtr) ) - Adapter = NULL; + KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql); + + if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < + sizeof(*AdapterIndexPtr)) + Adapter = NULL; else - Adapter = FindAdapterByIndex( DeviceExt, *AdapterIndexPtr ); - - if( Adapter ) { - /* Local Addresses */ - for( ListEntry = Adapter->AddressList.Flink; - ListEntry != &Adapter->AddressList; - ListEntry = ListEntry->Flink ) { - Address = CONTAINING_RECORD(ListEntry, LAN_ADDRESS_C, ListEntry); - BytesNeeded += LAN_ADDR_SIZE(Address->ClientPart.AddressLen, - Address->ClientPart.HWAddressLen); - } - - /* Foreign Addresses */ - for( ListEntry = Adapter->ForeignList.Flink; - ListEntry != &Adapter->ForeignList; - ListEntry = ListEntry->Flink ) { - Address = CONTAINING_RECORD(ListEntry, LAN_ADDRESS_C, ListEntry); - BytesNeeded += LAN_ADDR_SIZE(Address->ClientPart.AddressLen, - Address->ClientPart.HWAddressLen); - } - BytesNeeded += Adapter->RegistryPath.Length; - - if( IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= - BytesNeeded ) { - /* Write common info */ - Info = (PLAN_ADAPTER_INFO_S)Writing; - Info->Index = Adapter->Index; - Info->Media = Adapter->Media; - Info->Speed = Adapter->Speed; - /* Ethernet specific XXX */ - Info->AddressLen = IEEE_802_ADDR_LENGTH; - Info->Overhead = Adapter->HeaderSize; - Info->MTU = Adapter->MTU; - Info->RegKeySize = Adapter->RegistryPath.Length; - - /* Copy the name */ - Writing += sizeof(*Info); - RtlCopyMemory( Adapter->RegistryPath.Buffer, - Writing, - Adapter->RegistryPath.Length ); - - /* Write the address info */ - Writing += Adapter->RegistryPath.Length; - - for( ListEntry = Adapter->AddressList.Flink; - ListEntry != &Adapter->AddressList; - ListEntry = ListEntry->Flink ) { - Address = CONTAINING_RECORD(ListEntry, LAN_ADDRESS_C, - ListEntry); - AddrSize = LAN_ADDR_SIZE(Address->ClientPart.AddressLen, - Address->ClientPart.HWAddressLen); - RtlCopyMemory( Writing, &Address->ClientPart, AddrSize ); - Writing += AddrSize; - } - - for( ListEntry = Adapter->ForeignList.Flink; - ListEntry != &Adapter->ForeignList; - ListEntry = ListEntry->Flink ) { - Address = CONTAINING_RECORD(ListEntry, LAN_ADDRESS_C, - ListEntry); - AddrSize = LAN_ADDR_SIZE(Address->ClientPart.AddressLen, - Address->ClientPart.HWAddressLen); - RtlCopyMemory( Writing, &Address->ClientPart, AddrSize ); - Writing += AddrSize; - } - - ASSERT( BytesNeeded == Writing - Irp->AssociatedIrp.SystemBuffer ); - } else Status = STATUS_BUFFER_TOO_SMALL; - } else Status = STATUS_NO_SUCH_DEVICE; - - KeReleaseSpinLock( &DeviceExt->Lock, OldIrql ); + Adapter = FindAdapterByIndex(DeviceExt, *AdapterIndexPtr); + + if (Adapter) + { + /* Local Addresses */ + for (ListEntry = Adapter->AddressList.Flink; + ListEntry != &Adapter->AddressList; + ListEntry = ListEntry->Flink) + { + Address = CONTAINING_RECORD(ListEntry, LAN_ADDRESS_C, ListEntry); + BytesNeeded += LAN_ADDR_SIZE(Address->ClientPart.AddressLen, + Address->ClientPart.HWAddressLen); + } + + /* Foreign Addresses */ + for (ListEntry = Adapter->ForeignList.Flink; + ListEntry != &Adapter->ForeignList; + ListEntry = ListEntry->Flink) + { + Address = CONTAINING_RECORD(ListEntry, LAN_ADDRESS_C, ListEntry); + BytesNeeded += LAN_ADDR_SIZE(Address->ClientPart.AddressLen, + Address->ClientPart.HWAddressLen); + } + BytesNeeded += Adapter->RegistryPath.Length; + + if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= + BytesNeeded) + { + /* Write common info */ + Info = (PLAN_ADAPTER_INFO_S)Writing; + Info->Index = Adapter->Index; + Info->Media = Adapter->Media; + Info->Speed = Adapter->Speed; + /* Ethernet specific XXX */ + Info->AddressLen = IEEE_802_ADDR_LENGTH; + Info->Overhead = Adapter->HeaderSize; + Info->MTU = Adapter->MTU; + Info->RegKeySize = Adapter->RegistryPath.Length; + + /* Copy the name */ + Writing += sizeof(*Info); + RtlCopyMemory(Adapter->RegistryPath.Buffer, + Writing, + Adapter->RegistryPath.Length); + + /* Write the address info */ + Writing += Adapter->RegistryPath.Length; + + for (ListEntry = Adapter->AddressList.Flink; + ListEntry != &Adapter->AddressList; + ListEntry = ListEntry->Flink) + { + Address = CONTAINING_RECORD(ListEntry, LAN_ADDRESS_C, + ListEntry); + AddrSize = LAN_ADDR_SIZE(Address->ClientPart.AddressLen, + Address->ClientPart.HWAddressLen); + RtlCopyMemory(Writing, &Address->ClientPart, AddrSize); + Writing += AddrSize; + } + + for (ListEntry = Adapter->ForeignList.Flink; + ListEntry != &Adapter->ForeignList; + ListEntry = ListEntry->Flink) + { + Address = CONTAINING_RECORD(ListEntry, + LAN_ADDRESS_C, + ListEntry); + AddrSize = LAN_ADDR_SIZE(Address->ClientPart.AddressLen, + Address->ClientPart.HWAddressLen); + RtlCopyMemory(Writing, &Address->ClientPart, AddrSize); + Writing += AddrSize; + } + + ASSERT(BytesNeeded == Writing - Irp->AssociatedIrp.SystemBuffer); + } + else Status = STATUS_BUFFER_TOO_SMALL; + } + else Status = STATUS_NO_SUCH_DEVICE; + + KeReleaseSpinLock(&DeviceExt->Lock, OldIrql); LA_DbgPrint(MID_TRACE,("Ending (%d bytes)\n", BytesNeeded)); Irp->IoStatus.Status = Status; Irp->IoStatus.Information = BytesNeeded; - IoCompleteRequest( Irp, IO_NO_INCREMENT ); + IoCompleteRequest(Irp, IO_NO_INCREMENT); return Status; } -NTSTATUS NTAPI -LanSetBufferedMode( PDEVICE_OBJECT DeviceObject, PIRP Irp, - PIO_STACK_LOCATION IrpSp ) { - PLAN_DEVICE_EXT DeviceExt = - (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; +NTSTATUS +NTAPI +LanSetBufferedMode( + PDEVICE_OBJECT DeviceObject, + PIRP Irp, + PIO_STACK_LOCATION IrpSp) +{ + PLAN_DEVICE_EXT DeviceExt = (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension; PFILE_OBJECT FileObject = IrpSp->FileObject; PLAN_PROTOCOL Proto = FileObject->FsContext; NTSTATUS Status = STATUS_SUCCESS; @@ -1186,93 +1327,97 @@ LA_DbgPrint(MID_TRACE,("Called %x\n", Proto)); - KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql ); - - if( IrpSp->Parameters.DeviceIoControl.InputBufferLength >= - sizeof(Proto->Buffered) ) - RtlCopyMemory( &Proto->Buffered, Irp->AssociatedIrp.SystemBuffer, - sizeof(Proto->Buffered) ); + KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql); + + if (IrpSp->Parameters.DeviceIoControl.InputBufferLength >= + sizeof(Proto->Buffered)) + RtlCopyMemory(&Proto->Buffered, + Irp->AssociatedIrp.SystemBuffer, + sizeof(Proto->Buffered)); else - Status = STATUS_INVALID_PARAMETER; - - KeReleaseSpinLock( &DeviceExt->Lock, OldIrql ); + Status = STATUS_INVALID_PARAMETER; + + KeReleaseSpinLock(&DeviceExt->Lock, OldIrql); LA_DbgPrint(MID_TRACE,("Set buffered for %x to %d\n", Proto->Buffered)); Status = Irp->IoStatus.Status = Status; Irp->IoStatus.Information = 0; - IoCompleteRequest( Irp, IO_NETWORK_INCREMENT ); + IoCompleteRequest(Irp, IO_NETWORK_INCREMENT); return Status; } -NTSTATUS NTAPI -LanDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp) +NTSTATUS +NTAPI +LanDispatch( + PDEVICE_OBJECT DeviceObject, + PIRP Irp) { PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp); NTSTATUS Status = STATUS_SUCCESS; LA_DbgPrint(MID_TRACE,("LanDispatch: %d\n", IrpSp->MajorFunction)); - if( IrpSp->MajorFunction != IRP_MJ_CREATE) { - LA_DbgPrint(MID_TRACE,("FO %x, IrpSp->FO %x\n", - FileObject, IrpSp->FileObject)); - ASSERT(FileObject == IrpSp->FileObject); - } - - switch(IrpSp->MajorFunction) - { - /* opening and closing handles to the device */ + if (IrpSp->MajorFunction != IRP_MJ_CREATE) + { + LA_DbgPrint(MID_TRACE,("FO %x, IrpSp->FO %x\n", + FileObject, IrpSp->FileObject)); + ASSERT(FileObject == IrpSp->FileObject); + } + + switch (IrpSp->MajorFunction) + { + /* opening and closing handles to the device */ case IRP_MJ_CREATE: - /* Mostly borrowed from the named pipe file system */ - return LanCreateProtocol(DeviceObject, Irp, IrpSp); + /* Mostly borrowed from the named pipe file system */ + return LanCreateProtocol(DeviceObject, Irp, IrpSp); case IRP_MJ_CLOSE: - /* Ditto the borrowing */ - return LanCloseProtocol(DeviceObject, Irp, IrpSp); - - /* write data */ + /* Ditto the borrowing */ + return LanCloseProtocol(DeviceObject, Irp, IrpSp); + + /* write data */ case IRP_MJ_WRITE: - return LanWriteData( DeviceObject, Irp, IrpSp ); - - /* read data */ + return LanWriteData(DeviceObject, Irp, IrpSp); + + /* read data */ case IRP_MJ_READ: - return LanReadData( DeviceObject, Irp, IrpSp ); + return LanReadData(DeviceObject, Irp, IrpSp); case IRP_MJ_DEVICE_CONTROL: { - LA_DbgPrint(MID_TRACE,("DeviceIoControl: %x\n", - IrpSp->Parameters.DeviceIoControl. - IoControlCode)); - switch( IrpSp->Parameters.DeviceIoControl.IoControlCode ) { - case IOCTL_IF_ENUM_ADAPTERS: - return LanEnumAdapters( DeviceObject, Irp, IrpSp ); - - case IOCTL_IF_BUFFERED_MODE: - return LanSetBufferedMode( DeviceObject, Irp, IrpSp ); - - case IOCTL_IF_ADAPTER_INFO: - return LanAdapterInfo( DeviceObject, Irp, IrpSp ); - - default: - Status = STATUS_NOT_IMPLEMENTED; - Irp->IoStatus.Information = 0; - LA_DbgPrint(MIN_TRACE, ("Unknown IOCTL (0x%x)\n", - IrpSp->Parameters.DeviceIoControl. - IoControlCode)); - break; - } - break; + LA_DbgPrint(MID_TRACE,("DeviceIoControl: %x\n", + IrpSp->Parameters.DeviceIoControl. + IoControlCode)); + switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) + { + case IOCTL_IF_ENUM_ADAPTERS: + return LanEnumAdapters(DeviceObject, Irp, IrpSp); + + case IOCTL_IF_BUFFERED_MODE: + return LanSetBufferedMode(DeviceObject, Irp, IrpSp); + + case IOCTL_IF_ADAPTER_INFO: + return LanAdapterInfo(DeviceObject, Irp, IrpSp); + + default: + Status = STATUS_NOT_IMPLEMENTED; + Irp->IoStatus.Information = 0; + LA_DbgPrint(MIN_TRACE, ("Unknown IOCTL (0x%x)\n", + IrpSp->Parameters.DeviceIoControl. + IoControlCode)); + break; + } + break; } /* unsupported operations */ default: - { - Status = STATUS_NOT_IMPLEMENTED; - LA_DbgPrint(MIN_TRACE, - ("Irp: Unknown Major code was %x\n", - IrpSp->MajorFunction)); - break; - } + Status = STATUS_NOT_IMPLEMENTED; + LA_DbgPrint(MIN_TRACE, + ("Irp: Unknown Major code was %x\n", + IrpSp->MajorFunction)); + break; } LA_DbgPrint(MID_TRACE, ("Returning %x\n", Status)); @@ -1283,13 +1428,21 @@ } /* Do i need a global here? I think i need to do this a different way XXX */ -VOID NTAPI LanUnload(PDRIVER_OBJECT DriverObject) { +VOID +NTAPI +LanUnload( + PDRIVER_OBJECT DriverObject) +{ LANUnregisterProtocol(); CloseNdisPools(); } -NTSTATUS NTAPI DriverEntry( PDRIVER_OBJECT DriverObject, - PUNICODE_STRING RegsitryPath ) { +NTSTATUS +NTAPI +DriverEntry( + PDRIVER_OBJECT DriverObject, + PUNICODE_STRING RegsitryPath) +{ PDEVICE_OBJECT DeviceObject; PLAN_DEVICE_EXT DeviceExt; UNICODE_STRING wstrDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Lan"); @@ -1307,34 +1460,33 @@ DriverObject->DriverUnload = LanUnload; /* create lan device */ - Status = IoCreateDevice - ( DriverObject, - sizeof(LAN_DEVICE_EXT), - &wstrDeviceName, - FILE_DEVICE_NAMED_PIPE, - 0, - FALSE, - &DeviceObject ); + Status = IoCreateDevice(DriverObject, + sizeof(LAN_DEVICE_EXT), + &wstrDeviceName, + FILE_DEVICE_NAMED_PIPE, + 0, + FALSE, + &DeviceObject); /* failure */ - if(!NT_SUCCESS(Status)) - { - return (Status); + if (!NT_SUCCESS(Status)) + { + return (Status); } LanDeviceObject = DeviceObject; DeviceExt = DeviceObject->DeviceExtension; - RtlZeroMemory( DeviceExt, sizeof(*DeviceExt) ); - InitializeListHead( &DeviceExt->AdapterListHead ); - InitializeListHead( &DeviceExt->ProtocolListHead ); - KeInitializeSpinLock( &DeviceExt->Lock ); - - LANRegisterProtocol( &LanString ); + RtlZeroMemory(DeviceExt, sizeof(*DeviceExt)); + InitializeListHead(&DeviceExt->AdapterListHead); + InitializeListHead(&DeviceExt->ProtocolListHead); + KeInitializeSpinLock(&DeviceExt->Lock); + + LANRegisterProtocol(&LanString); DeviceObject->Flags |= DO_BUFFERED_IO; LA_DbgPrint(MID_TRACE,("Device created: object %x ext %x\n", - DeviceObject, DeviceExt)); + DeviceObject, DeviceExt)); return (Status); }
12 years, 2 months
1
0
0
0
[tkreuzer] 57433: [RSYM_CMAKE] Improve the code a bit. No functional change.
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sat Sep 29 15:28:46 2012 New Revision: 57433 URL:
http://svn.reactos.org/svn/reactos?rev=57433&view=rev
Log: [RSYM_CMAKE] Improve the code a bit. No functional change. Modified: trunk/reactos/tools/pecoff.h trunk/reactos/tools/rsym/rsym.cmake.c Modified: trunk/reactos/tools/pecoff.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/pecoff.h?rev=57433&r…
============================================================================== --- trunk/reactos/tools/pecoff.h [iso-8859-1] (original) +++ trunk/reactos/tools/pecoff.h [iso-8859-1] Sat Sep 29 15:28:46 2012 @@ -186,6 +186,28 @@ typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER; #endif +typedef struct _IMAGE_NT_HEADERS32 +{ + DWORD Signature; + IMAGE_FILE_HEADER FileHeader; + IMAGE_OPTIONAL_HEADER32 OptionalHeader; +} IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32; + +typedef struct _IMAGE_NT_HEADERS64 +{ + DWORD Signature; + IMAGE_FILE_HEADER FileHeader; + IMAGE_OPTIONAL_HEADER32 OptionalHeader; +} IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64; + +#ifdef _TARGET_PE64 +typedef IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS; +typedef PIMAGE_NT_HEADERS64 PIMAGE_NT_HEADERS; +#else +typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS; +typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS; +#endif + typedef struct _IMAGE_SECTION_HEADER { BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; union { Modified: trunk/reactos/tools/rsym/rsym.cmake.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rsym/rsym.cmake.c?re…
============================================================================== --- trunk/reactos/tools/rsym/rsym.cmake.c [iso-8859-1] (original) +++ trunk/reactos/tools/rsym/rsym.cmake.c [iso-8859-1] Sat Sep 29 15:28:46 2012 @@ -27,14 +27,22 @@ #include "rsym.h" +int +IsDebugSection(PIMAGE_SECTION_HEADER Section) +{ + /* This is a hack, but works for us */ + return (Section->Name[0] == '/'); +} + int main(int argc, char* argv[]) { - int i; + unsigned int i; PSYMBOLFILE_HEADER SymbolFileHeader; - PIMAGE_DOS_HEADER PEDosHeader; - PIMAGE_FILE_HEADER PEFileHeader; - PIMAGE_OPTIONAL_HEADER PEOptHeader; - PIMAGE_SECTION_HEADER PESectionHeaders; + PIMAGE_NT_HEADERS NtHeaders; + PIMAGE_DOS_HEADER DosHeader; + PIMAGE_FILE_HEADER FileHeader; + PIMAGE_OPTIONAL_HEADER OptionalHeader; + PIMAGE_SECTION_HEADER SectionHeaders, LastSection; char* path1; char* path2; FILE* out; @@ -42,7 +50,7 @@ void *FileData; char elfhdr[] = { '\377', 'E', 'L', 'F' }; - if (3 != argc) + if (argc != 3) { fprintf(stderr, "Usage: rsym <exefile> <symfile>\n"); exit(1); @@ -51,56 +59,66 @@ path1 = convert_path(argv[1]); path2 = convert_path(argv[2]); - FileData = load_file(path1, &FileSize ); + /* Load the input file into memory */ + FileData = load_file( path1, &FileSize); if ( !FileData ) { - fprintf ( stderr, "An error occured loading '%s'\n", path1 ); + fprintf(stderr, "An error occured loading '%s'\n", path1); exit(1); } /* Check if MZ header exists */ - PEDosHeader = (PIMAGE_DOS_HEADER)FileData; - if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC || PEDosHeader->e_lfanew == 0L) + DosHeader = (PIMAGE_DOS_HEADER) FileData; + if (DosHeader->e_magic != IMAGE_DOS_MAGIC || DosHeader->e_lfanew == 0L) { /* Ignore elf */ - if (!memcmp(PEDosHeader, elfhdr, sizeof(elfhdr))) + if (!memcmp(DosHeader, elfhdr, sizeof(elfhdr))) exit(0); perror("Input file is not a PE image.\n"); free(FileData); exit(1); } - /* Locate PE file header */ - /* sizeof(ULONG) = sizeof(MAGIC) */ - PEFileHeader = (PIMAGE_FILE_HEADER)((char *) FileData + PEDosHeader->e_lfanew + sizeof(ULONG)); - - /* Locate optional header */ - assert(sizeof(ULONG) == 4); - PEOptHeader = (PIMAGE_OPTIONAL_HEADER)(PEFileHeader + 1); + /* Locate the headers */ + NtHeaders = (PIMAGE_NT_HEADERS)((char*)FileData + DosHeader->e_lfanew); + FileHeader = &NtHeaders->FileHeader; + OptionalHeader = &NtHeaders->OptionalHeader; /* Locate PE section headers */ - PESectionHeaders = (PIMAGE_SECTION_HEADER)((char *) PEOptHeader + PEFileHeader->SizeOfOptionalHeader); + SectionHeaders = (PIMAGE_SECTION_HEADER)((char*)OptionalHeader + + FileHeader->SizeOfOptionalHeader); - for (i = 0; i < PEFileHeader->NumberOfSections; i++) + /* Loop all sections */ + for (i = 0; i < FileHeader->NumberOfSections; i++) { - if (PESectionHeaders[i].Name[0] == '/') + /* Check if this is a debug section */ + if (IsDebugSection(&SectionHeaders[i])) { - PESectionHeaders[i].Characteristics |= IMAGE_SCN_CNT_INITIALIZED_DATA; - PESectionHeaders[i].Characteristics &= ~(IMAGE_SCN_MEM_PURGEABLE | IMAGE_SCN_MEM_DISCARDABLE); + /* Make sure we have the correct characteristics */ + SectionHeaders[i].Characteristics |= IMAGE_SCN_CNT_INITIALIZED_DATA; + SectionHeaders[i].Characteristics &= ~(IMAGE_SCN_MEM_PURGEABLE | IMAGE_SCN_MEM_DISCARDABLE); } } - PESectionHeaders[PEFileHeader->NumberOfSections-1].SizeOfRawData = - FileSize - PESectionHeaders[PEFileHeader->NumberOfSections-1].PointerToRawData; - if (PESectionHeaders[PEFileHeader->NumberOfSections-1].SizeOfRawData > - PESectionHeaders[PEFileHeader->NumberOfSections-1].Misc.VirtualSize) + /* Get a pointer to the last section header */ + LastSection = &SectionHeaders[FileHeader->NumberOfSections - 1]; + + /* Set the size of the last section to cover the rest of the PE */ + LastSection->SizeOfRawData = FileSize - LastSection->PointerToRawData; + + /* Check if the virtual section size is smaller than the raw data */ + if (LastSection->Misc.VirtualSize < LastSection->SizeOfRawData) { - PESectionHeaders[PEFileHeader->NumberOfSections-1].Misc.VirtualSize = - ROUND_UP(PESectionHeaders[PEFileHeader->NumberOfSections-1].SizeOfRawData, - PEOptHeader->SectionAlignment); - PEOptHeader->SizeOfImage = PESectionHeaders[PEFileHeader->NumberOfSections-1].VirtualAddress + PESectionHeaders[PEFileHeader->NumberOfSections-1].Misc.VirtualSize; + /* Make sure the virtual size of the section cover the raw data */ + LastSection->Misc.VirtualSize = ROUND_UP(LastSection->SizeOfRawData, + OptionalHeader->SectionAlignment); + + /* Fix up image size */ + OptionalHeader->SizeOfImage = LastSection->VirtualAddress + + LastSection->Misc.VirtualSize; } + /* Open the output file */ out = fopen(path2, "wb"); if (out == NULL) { @@ -109,6 +127,7 @@ exit(1); } + /* Write the output file */ fwrite(FileData, 1, FileSize, out); fclose(out); free(FileData);
12 years, 2 months
1
0
0
0
[akhaldi] 57432: [MSVCRT_WINETEST]: Sync to Wine 1.5.13. CORE-6415
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Sep 29 14:28:48 2012 New Revision: 57432 URL:
http://svn.reactos.org/svn/reactos?rev=57432&view=rev
Log: [MSVCRT_WINETEST]: Sync to Wine 1.5.13. CORE-6415 Modified: trunk/rostests/winetests/msvcrt/cpp.c trunk/rostests/winetests/msvcrt/file.c trunk/rostests/winetests/msvcrt/locale.c trunk/rostests/winetests/msvcrt/misc.c trunk/rostests/winetests/msvcrt/printf.c trunk/rostests/winetests/msvcrt/scanf.c trunk/rostests/winetests/msvcrt/string.c trunk/rostests/winetests/msvcrt/time.c Modified: trunk/rostests/winetests/msvcrt/cpp.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/msvcrt/cpp.c?re…
============================================================================== --- trunk/rostests/winetests/msvcrt/cpp.c [iso-8859-1] (original) +++ trunk/rostests/winetests/msvcrt/cpp.c [iso-8859-1] Sat Sep 29 14:28:48 2012 @@ -15,42 +15,33 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - * - * NOTES - * This tests is only valid for ix86 platforms, on others it's a no-op. - * Some tests cannot be checked with ok(), for example the dtors. We simply - * call them to ensure we don't crash ;-) - * - * If we build this test with VC++ in debug mode, we will fail in _chkstk() - * or at program exit malloc() checking if these methods haven't been - * implemented correctly (they have). - * - * Tested with a range of native msvcrt's from v4 -> v7. */ #include "wine/test.h" #include "winbase.h" #include "winnt.h" -#ifndef __i386__ -/* Skip these tests for non x86 platforms */ -START_TEST(cpp) -{ -} -#else +typedef void (*vtable_ptr)(void); typedef struct __exception { - void *vtable; + vtable_ptr *vtable; char *name; int do_free; } exception; typedef struct __type_info { - void *vtable; + vtable_ptr *vtable; char *name; char mangled[16]; } type_info; + +#undef __thiscall +#ifdef __i386__ +#define __thiscall __stdcall +#else +#define __thiscall __cdecl +#endif /* Function pointers. We need to use these to call these funcs as __thiscall */ static HMODULE hMsvcrt; @@ -61,56 +52,56 @@ static void (__cdecl *pfree)(void*); /* exception */ -static void (WINAPI *pexception_ctor)(exception*,LPCSTR*); -static void (WINAPI *pexception_copy_ctor)(exception*,exception*); -static void (WINAPI *pexception_default_ctor)(exception*); -static void (WINAPI *pexception_dtor)(exception*); -static exception* (WINAPI *pexception_opequals)(exception*,exception*); -static char* (WINAPI *pexception_what)(exception*); -static void* (WINAPI *pexception_vtable)(exception*); -static void (WINAPI *pexception_vector_dtor)(exception*,unsigned int); -static void (WINAPI *pexception_scalar_dtor)(exception*,unsigned int); +static void (__thiscall *pexception_ctor)(exception*,LPCSTR*); +static void (__thiscall *pexception_copy_ctor)(exception*,exception*); +static void (__thiscall *pexception_default_ctor)(exception*); +static void (__thiscall *pexception_dtor)(exception*); +static exception* (__thiscall *pexception_opequals)(exception*,exception*); +static char* (__thiscall *pexception_what)(exception*); +static vtable_ptr *pexception_vtable; +static void (__thiscall *pexception_vector_dtor)(exception*,unsigned int); +static void (__thiscall *pexception_scalar_dtor)(exception*,unsigned int); /* bad_typeid */ -static void (WINAPI *pbad_typeid_ctor)(exception*,LPCSTR); -static void (WINAPI *pbad_typeid_ctor_closure)(exception*); -static void (WINAPI *pbad_typeid_copy_ctor)(exception*,exception*); -static void (WINAPI *pbad_typeid_dtor)(exception*); -static exception* (WINAPI *pbad_typeid_opequals)(exception*,exception*); -static char* (WINAPI *pbad_typeid_what)(exception*); -static void* (WINAPI *pbad_typeid_vtable)(exception*); -static void (WINAPI *pbad_typeid_vector_dtor)(exception*,unsigned int); -static void (WINAPI *pbad_typeid_scalar_dtor)(exception*,unsigned int); +static void (__thiscall *pbad_typeid_ctor)(exception*,LPCSTR); +static void (__thiscall *pbad_typeid_ctor_closure)(exception*); +static void (__thiscall *pbad_typeid_copy_ctor)(exception*,exception*); +static void (__thiscall *pbad_typeid_dtor)(exception*); +static exception* (__thiscall *pbad_typeid_opequals)(exception*,exception*); +static char* (__thiscall *pbad_typeid_what)(exception*); +static vtable_ptr *pbad_typeid_vtable; +static void (__thiscall *pbad_typeid_vector_dtor)(exception*,unsigned int); +static void (__thiscall *pbad_typeid_scalar_dtor)(exception*,unsigned int); /* bad_cast */ -static void (WINAPI *pbad_cast_ctor)(exception*,LPCSTR*); -static void (WINAPI *pbad_cast_ctor2)(exception*,LPCSTR); -static void (WINAPI *pbad_cast_ctor_closure)(exception*); -static void (WINAPI *pbad_cast_copy_ctor)(exception*,exception*); -static void (WINAPI *pbad_cast_dtor)(exception*); -static exception* (WINAPI *pbad_cast_opequals)(exception*,exception*); -static char* (WINAPI *pbad_cast_what)(exception*); -static void* (WINAPI *pbad_cast_vtable)(exception*); -static void (WINAPI *pbad_cast_vector_dtor)(exception*,unsigned int); -static void (WINAPI *pbad_cast_scalar_dtor)(exception*,unsigned int); +static void (__thiscall *pbad_cast_ctor)(exception*,LPCSTR*); +static void (__thiscall *pbad_cast_ctor2)(exception*,LPCSTR); +static void (__thiscall *pbad_cast_ctor_closure)(exception*); +static void (__thiscall *pbad_cast_copy_ctor)(exception*,exception*); +static void (__thiscall *pbad_cast_dtor)(exception*); +static exception* (__thiscall *pbad_cast_opequals)(exception*,exception*); +static char* (__thiscall *pbad_cast_what)(exception*); +static vtable_ptr *pbad_cast_vtable; +static void (__thiscall *pbad_cast_vector_dtor)(exception*,unsigned int); +static void (__thiscall *pbad_cast_scalar_dtor)(exception*,unsigned int); /* __non_rtti_object */ -static void (WINAPI *p__non_rtti_object_ctor)(exception*,LPCSTR); -static void (WINAPI *p__non_rtti_object_copy_ctor)(exception*,exception*); -static void (WINAPI *p__non_rtti_object_dtor)(exception*); -static exception* (WINAPI *p__non_rtti_object_opequals)(exception*,exception*); -static char* (WINAPI *p__non_rtti_object_what)(exception*); -static void* (WINAPI *p__non_rtti_object_vtable)(exception*); -static void (WINAPI *p__non_rtti_object_vector_dtor)(exception*,unsigned int); -static void (WINAPI *p__non_rtti_object_scalar_dtor)(exception*,unsigned int); +static void (__thiscall *p__non_rtti_object_ctor)(exception*,LPCSTR); +static void (__thiscall *p__non_rtti_object_copy_ctor)(exception*,exception*); +static void (__thiscall *p__non_rtti_object_dtor)(exception*); +static exception* (__thiscall *p__non_rtti_object_opequals)(exception*,exception*); +static char* (__thiscall *p__non_rtti_object_what)(exception*); +static vtable_ptr *p__non_rtti_object_vtable; +static void (__thiscall *p__non_rtti_object_vector_dtor)(exception*,unsigned int); +static void (__thiscall *p__non_rtti_object_scalar_dtor)(exception*,unsigned int); /* type_info */ -static void (WINAPI *ptype_info_dtor)(type_info*); -static char* (WINAPI *ptype_info_raw_name)(type_info*); -static char* (WINAPI *ptype_info_name)(type_info*); -static int (WINAPI *ptype_info_before)(type_info*,type_info*); -static int (WINAPI *ptype_info_opequals_equals)(type_info*,type_info*); -static int (WINAPI *ptype_info_opnot_equals)(type_info*,type_info*); +static void (__thiscall *ptype_info_dtor)(type_info*); +static char* (__thiscall *ptype_info_raw_name)(type_info*); +static char* (__thiscall *ptype_info_name)(type_info*); +static int (__thiscall *ptype_info_before)(type_info*,type_info*); +static int (__thiscall *ptype_info_opequals_equals)(type_info*,type_info*); +static int (__thiscall *ptype_info_opnot_equals)(type_info*,type_info*); /* RTTI */ static type_info* (__cdecl *p__RTtypeid)(void*); @@ -125,147 +116,184 @@ static void* bAncientVersion; /* Emulate a __thiscall */ -#ifdef _MSC_VER -static inline void* do_call_func1(void *func, void *_this) -{ - volatile void* retval = 0; - __asm - { - push ecx - mov ecx, _this - call func - mov retval, eax - pop ecx - } - return (void*)retval; -} - -static inline void* do_call_func2(void *func, void *_this, const void* arg) -{ - volatile void* retval = 0; - __asm - { - push ecx - push arg - mov ecx, _this - call func - mov retval, eax - pop ecx - } - return (void*)retval; -} +#ifdef __i386__ + +#include "pshpack1.h" +struct thiscall_thunk +{ + BYTE pop_eax; /* popl %eax (ret addr) */ + BYTE pop_edx; /* popl %edx (func) */ + BYTE pop_ecx; /* popl %ecx (this) */ + BYTE push_eax; /* pushl %eax */ + WORD jmp_edx; /* jmp *%edx */ +}; +#include "poppack.h" + +static void * (WINAPI *call_thiscall_func1)( void *func, void *this ); +static void * (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a ); + +static void init_thiscall_thunk(void) +{ + struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk), + MEM_COMMIT, PAGE_EXECUTE_READWRITE ); + thunk->pop_eax = 0x58; /* popl %eax */ + thunk->pop_edx = 0x5a; /* popl %edx */ + thunk->pop_ecx = 0x59; /* popl %ecx */ + thunk->push_eax = 0x50; /* pushl %eax */ + thunk->jmp_edx = 0xe2ff; /* jmp *%edx */ + call_thiscall_func1 = (void *)thunk; + call_thiscall_func2 = (void *)thunk; +} + +#define call_func1(func,_this) call_thiscall_func1(func,_this) +#define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)a) + #else -static void* do_call_func1(void *func, void *_this) -{ - void *ret, *dummy; - __asm__ __volatile__ ("call *%2" - : "=a" (ret), "=c" (dummy) - : "g" (func), "1" (_this) - : "edx", "memory" ); - return ret; -} -static void* do_call_func2(void *func, void *_this, const void* arg) -{ - void *ret, *dummy; - __asm__ __volatile__ ("pushl %3\n\tcall *%2" - : "=a" (ret), "=c" (dummy) - : "r" (func), "r" (arg), "1" (_this) - : "edx", "memory" ); - return ret; -} -#endif - -#define call_func1(x,y) do_call_func1((void*)x,(void*)y) -#define call_func2(x,y,z) do_call_func2((void*)x,(void*)y,(const void*)z) + +#define init_thiscall_thunk() do { } while(0) +#define call_func1(func,_this) func(_this) +#define call_func2(func,_this,a) func(_this,a) + +#endif /* __i386__ */ /* Some exports are only available in later versions */ #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y) #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0) -static void InitFunctionPtrs(void) -{ - hMsvcrt = GetModuleHandleA("msvcrt.dll"); - if (!hMsvcrt) - hMsvcrt = GetModuleHandleA("msvcrtd.dll"); - ok(hMsvcrt != 0, "GetModuleHandleA failed\n"); - if (hMsvcrt) - { - if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */ +static BOOL InitFunctionPtrs(void) +{ + hMsvcrt = GetModuleHandleA("msvcrt.dll"); + if (!hMsvcrt) + hMsvcrt = GetModuleHandleA("msvcrtd.dll"); + ok(hMsvcrt != 0, "GetModuleHandleA failed\n"); + if (!hMsvcrt) + { + win_skip("Could not load msvcrt.dll\n"); + return FALSE; + } + + SET(pmalloc, "malloc"); + SET(pfree, "free"); + + SET(pexception_vtable, "??_7exception@@6B@"); + SET(pbad_typeid_vtable, "??_7bad_typeid@@6B@"); + SET(pbad_cast_vtable, "??_7bad_cast@@6B@"); + SET(p__non_rtti_object_vtable, "??_7__non_rtti_object@@6B@"); + + SET(p__RTtypeid, "__RTtypeid"); + SET(p__RTCastToVoid, "__RTCastToVoid"); + SET(p__RTDynamicCast, "__RTDynamicCast"); + + SET(p__unDName,"__unDName"); + + /* Extremely early versions export logic_error, and crash in RTTI */ + SETNOFAIL(bAncientVersion, "??0logic_error@@QAE@ABQBD@Z"); + if (sizeof(void *) > sizeof(int)) /* 64-bit initialization */ { SETNOFAIL(poperator_new, "??_U@YAPEAX_K@Z"); SETNOFAIL(poperator_delete, "??_V@YAXPEAX@Z"); + + SET(pexception_ctor, "??0exception@@QEAA@AEBQEBD@Z"); + SET(pexception_copy_ctor, "??0exception@@QEAA@AEBV0@@Z"); + SET(pexception_default_ctor, "??0exception@@QEAA@XZ"); + SET(pexception_dtor, "??1exception@@UEAA@XZ"); + SET(pexception_opequals, "??4exception@@QEAAAEAV0@AEBV0@@Z"); + SET(pexception_what, "?what@exception@@UEBAPEBDXZ"); + pexception_vector_dtor = (void*)pexception_vtable[0]; + pexception_scalar_dtor = (void*)pexception_vtable[0]; + + SET(pbad_typeid_ctor, "??0bad_typeid@@QEAA@PEBD@Z"); + SETNOFAIL(pbad_typeid_ctor_closure, "??_Fbad_typeid@@QEAAXXZ"); + SET(pbad_typeid_copy_ctor, "??0bad_typeid@@QEAA@AEBV0@@Z"); + SET(pbad_typeid_dtor, "??1bad_typeid@@UEAA@XZ"); + SET(pbad_typeid_opequals, "??4bad_typeid@@QEAAAEAV0@AEBV0@@Z"); + SET(pbad_typeid_what, "?what@exception@@UEBAPEBDXZ"); + pbad_typeid_vector_dtor = (void*)pbad_typeid_vtable[0]; + pbad_typeid_scalar_dtor = (void*)pbad_typeid_vtable[0]; + + SET(pbad_cast_ctor, "??0bad_cast@@QEAA@AEBQEBD@Z"); + SET(pbad_cast_ctor2, "??0bad_cast@@QEAA@PEBD@Z"); + SET(pbad_cast_ctor_closure, "??_Fbad_cast@@QEAAXXZ"); + SET(pbad_cast_copy_ctor, "??0bad_cast@@QEAA@AEBV0@@Z"); + SET(pbad_cast_dtor, "??1bad_cast@@UEAA@XZ"); + SET(pbad_cast_opequals, "??4bad_cast@@QEAAAEAV0@AEBV0@@Z"); + SET(pbad_cast_what, "?what@exception@@UEBAPEBDXZ"); + pbad_cast_vector_dtor = (void*)pbad_cast_vtable[0]; + pbad_cast_scalar_dtor = (void*)pbad_cast_vtable[0]; + + SET(p__non_rtti_object_ctor, "??0__non_rtti_object@@QEAA@PEBD@Z"); + SET(p__non_rtti_object_copy_ctor, "??0__non_rtti_object@@QEAA@AEBV0@@Z"); + SET(p__non_rtti_object_dtor, "??1__non_rtti_object@@UEAA@XZ"); + SET(p__non_rtti_object_opequals, "??4__non_rtti_object@@QEAAAEAV0@AEBV0@@Z"); + SET(p__non_rtti_object_what, "?what@exception@@UEBAPEBDXZ"); + p__non_rtti_object_vector_dtor = (void*)p__non_rtti_object_vtable[0]; + p__non_rtti_object_scalar_dtor = (void*)p__non_rtti_object_vtable[0]; + + SET(ptype_info_dtor, "??1type_info@@UEAA@XZ"); + SET(ptype_info_raw_name, "?raw_name@type_info@@QEBAPEBDXZ"); + SET(ptype_info_name, "?name@type_info@@QEBAPEBDXZ"); + SET(ptype_info_before, "?before@type_info@@QEBAHAEBV1@@Z"); + SET(ptype_info_opequals_equals, "??8type_info@@QEBAHAEBV0@@Z"); + SET(ptype_info_opnot_equals, "??9type_info@@QEBAHAEBV0@@Z"); } else { SETNOFAIL(poperator_new, "??_U@YAPAXI@Z"); SETNOFAIL(poperator_delete, "??_V@YAXPAX@Z"); + + SET(pexception_ctor, "??0exception@@QAE@ABQBD@Z"); + SET(pexception_copy_ctor, "??0exception@@QAE@ABV0@@Z"); + SET(pexception_default_ctor, "??0exception@@QAE@XZ"); + SET(pexception_dtor, "??1exception@@UAE@XZ"); + SET(pexception_opequals, "??4exception@@QAEAAV0@ABV0@@Z"); + SET(pexception_what, "?what@exception@@UBEPBDXZ"); + SET(pexception_vector_dtor, "??_Eexception@@UAEPAXI@Z"); + SET(pexception_scalar_dtor, "??_Gexception@@UAEPAXI@Z"); + + SET(pbad_typeid_ctor, "??0bad_typeid@@QAE@PBD@Z"); + SETNOFAIL(pbad_typeid_ctor_closure, "??_Fbad_typeid@@QAEXXZ"); + SET(pbad_typeid_copy_ctor, "??0bad_typeid@@QAE@ABV0@@Z"); + SET(pbad_typeid_dtor, "??1bad_typeid@@UAE@XZ"); + SET(pbad_typeid_opequals, "??4bad_typeid@@QAEAAV0@ABV0@@Z"); + SET(pbad_typeid_what, "?what@exception@@UBEPBDXZ"); + SET(pbad_typeid_vector_dtor, "??_Ebad_typeid@@UAEPAXI@Z"); + SET(pbad_typeid_scalar_dtor, "??_Gbad_typeid@@UAEPAXI@Z"); + + SETNOFAIL(pbad_cast_ctor, "??0bad_cast@@QAE@ABQBD@Z"); + if (!pbad_cast_ctor) + SET(pbad_cast_ctor, "??0bad_cast@@AAE@PBQBD@Z"); + SETNOFAIL(pbad_cast_ctor2, "??0bad_cast@@QAE@PBD@Z"); + SETNOFAIL(pbad_cast_ctor_closure, "??_Fbad_cast@@QAEXXZ"); + SET(pbad_cast_copy_ctor, "??0bad_cast@@QAE@ABV0@@Z"); + SET(pbad_cast_dtor, "??1bad_cast@@UAE@XZ"); + SET(pbad_cast_opequals, "??4bad_cast@@QAEAAV0@ABV0@@Z"); + SET(pbad_cast_what, "?what@exception@@UBEPBDXZ"); + SET(pbad_cast_vector_dtor, "??_Ebad_cast@@UAEPAXI@Z"); + SET(pbad_cast_scalar_dtor, "??_Gbad_cast@@UAEPAXI@Z"); + + SET(p__non_rtti_object_ctor, "??0__non_rtti_object@@QAE@PBD@Z"); + SET(p__non_rtti_object_copy_ctor, "??0__non_rtti_object@@QAE@ABV0@@Z"); + SET(p__non_rtti_object_dtor, "??1__non_rtti_object@@UAE@XZ"); + SET(p__non_rtti_object_opequals, "??4__non_rtti_object@@QAEAAV0@ABV0@@Z"); + SET(p__non_rtti_object_what, "?what@exception@@UBEPBDXZ"); + SET(p__non_rtti_object_vector_dtor, "??_E__non_rtti_object@@UAEPAXI@Z"); + SET(p__non_rtti_object_scalar_dtor, "??_G__non_rtti_object@@UAEPAXI@Z"); + + SET(ptype_info_dtor, "??1type_info@@UAE@XZ"); + SET(ptype_info_raw_name, "?raw_name@type_info@@QBEPBDXZ"); + SET(ptype_info_name, "?name@type_info@@QBEPBDXZ"); + SET(ptype_info_before, "?before@type_info@@QBEHABV1@@Z"); + SET(ptype_info_opequals_equals, "??8type_info@@QBEHABV0@@Z"); + SET(ptype_info_opnot_equals, "??9type_info@@QBEHABV0@@Z"); } - SET(pmalloc, "malloc"); - SET(pfree, "free"); if (!poperator_new) - poperator_new = pmalloc; + poperator_new = pmalloc; if (!poperator_delete) - poperator_delete = pfree; - - SET(pexception_ctor, "??0exception@@QAE@ABQBD@Z"); - SET(pexception_copy_ctor, "??0exception@@QAE@ABV0@@Z"); - SET(pexception_default_ctor, "??0exception@@QAE@XZ"); - SET(pexception_dtor, "??1exception@@UAE@XZ"); - SET(pexception_opequals, "??4exception@@QAEAAV0@ABV0@@Z"); - SET(pexception_what, "?what@exception@@UBEPBDXZ"); - SET(pexception_vtable, "??_7exception@@6B@"); - SET(pexception_vector_dtor, "??_Eexception@@UAEPAXI@Z"); - SET(pexception_scalar_dtor, "??_Gexception@@UAEPAXI@Z"); - - SET(pbad_typeid_ctor, "??0bad_typeid@@QAE@PBD@Z"); - SETNOFAIL(pbad_typeid_ctor_closure, "??_Fbad_typeid@@QAEXXZ"); - SET(pbad_typeid_copy_ctor, "??0bad_typeid@@QAE@ABV0@@Z"); - SET(pbad_typeid_dtor, "??1bad_typeid@@UAE@XZ"); - SET(pbad_typeid_opequals, "??4bad_typeid@@QAEAAV0@ABV0@@Z"); - SET(pbad_typeid_what, "?what@exception@@UBEPBDXZ"); - SET(pbad_typeid_vtable, "??_7bad_typeid@@6B@"); - SET(pbad_typeid_vector_dtor, "??_Ebad_typeid@@UAEPAXI@Z"); - SET(pbad_typeid_scalar_dtor, "??_Gbad_typeid@@UAEPAXI@Z"); - - SETNOFAIL(pbad_cast_ctor, "??0bad_cast@@QAE@ABQBD@Z"); - if (!pbad_cast_ctor) - SET(pbad_cast_ctor, "??0bad_cast@@AAE@PBQBD@Z"); - SETNOFAIL(pbad_cast_ctor2, "??0bad_cast@@QAE@PBD@Z"); - SETNOFAIL(pbad_cast_ctor_closure, "??_Fbad_cast@@QAEXXZ"); - SET(pbad_cast_copy_ctor, "??0bad_cast@@QAE@ABV0@@Z"); - SET(pbad_cast_dtor, "??1bad_cast@@UAE@XZ"); - SET(pbad_cast_opequals, "??4bad_cast@@QAEAAV0@ABV0@@Z"); - SET(pbad_cast_what, "?what@exception@@UBEPBDXZ"); - SET(pbad_cast_vtable, "??_7bad_cast@@6B@"); - SET(pbad_cast_vector_dtor, "??_Ebad_cast@@UAEPAXI@Z"); - SET(pbad_cast_scalar_dtor, "??_Gbad_cast@@UAEPAXI@Z"); - - SET(p__non_rtti_object_ctor, "??0__non_rtti_object@@QAE@PBD@Z"); - SET(p__non_rtti_object_copy_ctor, "??0__non_rtti_object@@QAE@ABV0@@Z"); - SET(p__non_rtti_object_dtor, "??1__non_rtti_object@@UAE@XZ"); - SET(p__non_rtti_object_opequals, "??4__non_rtti_object@@QAEAAV0@ABV0@@Z"); - SET(p__non_rtti_object_what, "?what@exception@@UBEPBDXZ"); - SET(p__non_rtti_object_vtable, "??_7__non_rtti_object@@6B@"); - SET(p__non_rtti_object_vector_dtor, "??_E__non_rtti_object@@UAEPAXI@Z"); - SET(p__non_rtti_object_scalar_dtor, "??_G__non_rtti_object@@UAEPAXI@Z"); - - SET(ptype_info_dtor, "??1type_info@@UAE@XZ"); - SET(ptype_info_raw_name, "?raw_name@type_info@@QBEPBDXZ"); - SET(ptype_info_name, "?name@type_info@@QBEPBDXZ"); - SET(ptype_info_before, "?before@type_info@@QBEHABV1@@Z"); - SET(ptype_info_opequals_equals, "??8type_info@@QBEHABV0@@Z"); - SET(ptype_info_opnot_equals, "??9type_info@@QBEHABV0@@Z"); - - SET(p__RTtypeid, "__RTtypeid"); - SET(p__RTCastToVoid, "__RTCastToVoid"); - SET(p__RTDynamicCast, "__RTDynamicCast"); - - SET(p__unDName,"__unDName"); - - /* Extremely early versions export logic_error, and crash in RTTI */ - SETNOFAIL(bAncientVersion, "??0logic_error@@QAE@ABQBD@Z"); - } + poperator_delete = pfree; + + init_thiscall_thunk(); + return TRUE; } static void test_exception(void) @@ -346,14 +374,14 @@ call_func2(pexception_vector_dtor, pe, 1); /* Should delete pe as single element*/ } - pe = poperator_new(sizeof(exception) * 4 + sizeof(int)); + pe = poperator_new(sizeof(exception) * 4 + sizeof(size_t)); ok(pe != NULL, "new() failed\n"); if (pe) { /* vector dtor, multiple elements */ char name[] = "a constant"; - *((int*)pe) = 3; - pe = (exception*)((int*)pe + 1); + *((size_t*)pe) = 3; + pe = (exception*)((size_t*)pe + 1); call_func2(pexception_ctor, &pe[0], &e_name); call_func2(pexception_ctor, &pe[1], &e_name); call_func2(pexception_ctor, &pe[2], &e_name); @@ -471,13 +499,13 @@ call_func2(pbad_typeid_vector_dtor, pe, 1); /* Should delete pe as single element*/ } - pe = poperator_new(sizeof(exception) * 4 + sizeof(int)); + pe = poperator_new(sizeof(exception) * 4 + sizeof(size_t)); ok(pe != NULL, "new() failed\n"); if (pe) { /* vector dtor, multiple elements */ - *((int*)pe) = 3; - pe = (exception*)((int*)pe + 1); + *((size_t*)pe) = 3; + pe = (exception*)((size_t*)pe + 1); call_func2(pbad_typeid_ctor, &pe[0], e_name); call_func2(pbad_typeid_ctor, &pe[1], e_name); call_func2(pbad_typeid_ctor, &pe[2], e_name); @@ -599,13 +627,13 @@ call_func2(pbad_cast_vector_dtor, pe, 1); /* Should delete pe as single element*/ } - pe = poperator_new(sizeof(exception) * 4 + sizeof(int)); + pe = poperator_new(sizeof(exception) * 4 + sizeof(size_t)); ok(pe != NULL, "new() failed\n"); if (pe) { /* vector dtor, multiple elements */ - *((int*)pe) = 3; - pe = (exception*)((int*)pe + 1); + *((size_t*)pe) = 3; + pe = (exception*)((size_t*)pe + 1); call_func2(pbad_cast_ctor, &pe[0], &e_name); call_func2(pbad_cast_ctor, &pe[1], &e_name); call_func2(pbad_cast_ctor, &pe[2], &e_name); @@ -701,13 +729,13 @@ call_func2(p__non_rtti_object_vector_dtor, pe, 1); /* Should delete pe as single element*/ } - pe = poperator_new(sizeof(exception) * 4 + sizeof(int)); + pe = poperator_new(sizeof(exception) * 4 + sizeof(size_t)); ok(pe != NULL, "new() failed\n"); if (pe) { /* vector dtor, multiple elements */ - *((int*)pe) = 3; - pe = (exception*)((int*)pe + 1); + *((size_t*)pe) = 3; + pe = (exception*)((size_t*)pe + 1); call_func2(p__non_rtti_object_ctor, &pe[0], e_name); call_func2(p__non_rtti_object_ctor, &pe[1], e_name); call_func2(p__non_rtti_object_ctor, &pe[2], e_name); @@ -732,7 +760,6 @@ } call_func2(p__non_rtti_object_vector_dtor, &e, 0); /* Should delete e.name, but not e */ } - static void test_type_info(void) { @@ -801,13 +828,99 @@ ok(res == 1, "expected 1, got %d\n", res); } +static inline vtable_ptr *get_vtable( void *obj ) +{ + return *(vtable_ptr **)obj; +} + +static inline void/*rtti_object_locator*/ *get_obj_locator( void *cppobj ) +{ + const vtable_ptr *vtable = get_vtable( cppobj ); + return (void *)vtable[-1]; +} + +#ifndef __x86_64__ +#define DEFINE_RTTI_REF(type, name) type *name +#define RTTI_REF(instance, name) &instance.name +#define RTTI_REF_SIG0(instance, name, base) RTTI_REF(instance, name) +#else +#define DEFINE_RTTI_REF(type, name) unsigned name +#define RTTI_REF(instance, name) FIELD_OFFSET(struct rtti_data, name) +#define RTTI_REF_SIG0(instance, name, base) ((char*)&instance.name-base) +#endif /* Test RTTI functions */ static void test_rtti(void) { + struct _object_locator + { + unsigned int signature; + int base_class_offset; + unsigned int flags; + DEFINE_RTTI_REF(type_info, type_descriptor); + DEFINE_RTTI_REF(struct _rtti_object_hierarchy, type_hierarchy); + DEFINE_RTTI_REF(void, object_locator); + } *obj_locator; + + struct rtti_data + { + type_info type_info[4]; + + struct _rtti_base_descriptor + { + DEFINE_RTTI_REF(type_info, type_descriptor); + int num_base_classes; + struct { + int this_offset; + int vbase_descr; + int vbase_offset; + } this_ptr_offsets; + unsigned int attributes; + } base_descriptor[4]; + + struct _rtti_base_array { + DEFINE_RTTI_REF(struct _rtti_base_descriptor, bases[4]); + } base_array; + + struct _rtti_object_hierarchy { + unsigned int signature; + unsigned int attributes; + int array_len; + DEFINE_RTTI_REF(struct _rtti_base_array, base_classes); + } object_hierarchy; + + struct _object_locator object_locator; + } simple_class_rtti = { + { {NULL, NULL, "simple_class"} }, + { {RTTI_REF(simple_class_rtti, type_info[0]), 0, {0, 0, 0}, 0} }, + { {RTTI_REF(simple_class_rtti, base_descriptor[0])} }, + {0, 0, 1, RTTI_REF(simple_class_rtti, base_array)}, + {1, 0, 0, RTTI_REF(simple_class_rtti, type_info[0]), RTTI_REF(simple_class_rtti, object_hierarchy), RTTI_REF(simple_class_rtti, object_locator)} + }, child_class_rtti = { + { {NULL, NULL, "simple_class"}, {NULL, NULL, "child_class"} }, + { {RTTI_REF(child_class_rtti, type_info[1]), 0, {4, -1, 0}, 0}, {RTTI_REF(child_class_rtti, type_info[0]), 0, {8, -1, 0}, 0} }, + { {RTTI_REF(child_class_rtti, base_descriptor[0]), RTTI_REF(child_class_rtti, base_descriptor[1])} }, + {0, 0, 2, RTTI_REF(child_class_rtti, base_array)}, + {1, 0, 0, RTTI_REF(child_class_rtti, type_info[1]), RTTI_REF(child_class_rtti, object_hierarchy), RTTI_REF(child_class_rtti, object_locator)} + }; + static struct rtti_data simple_class_sig0_rtti, child_class_sig0_rtti; + + void *simple_class_vtbl[2] = {&simple_class_rtti.object_locator}; + void *simple_class = &simple_class_vtbl[1]; + void *child_class_vtbl[2] = {&child_class_rtti.object_locator}; + void *child_class = &child_class_vtbl[1]; + void *simple_class_sig0_vtbl[2] = {&simple_class_sig0_rtti.object_locator}; + void *simple_class_sig0 = &simple_class_sig0_vtbl[1]; + void *child_class_sig0_vtbl[2] = {&child_class_sig0_rtti.object_locator}; + void *child_class_sig0 = &child_class_sig0_vtbl[1]; + static const char* e_name = "name"; type_info *ti,*bti; exception e,b; void *casted; + BOOL old_signature; +#ifdef __x86_64__ + char *base = (char*)GetModuleHandleW(NULL); +#endif if (bAncientVersion || !p__RTCastToVoid || !p__RTtypeid || !pexception_ctor || !pbad_typeid_ctor @@ -817,6 +930,12 @@ call_func2(pexception_ctor, &e, &e_name); call_func2(pbad_typeid_ctor, &b, e_name); + obj_locator = get_obj_locator(&e); + if(obj_locator->signature!=1 && sizeof(void*)>sizeof(int)) + old_signature = TRUE; + else + old_signature = FALSE; + /* dynamic_cast to void* */ casted = p__RTCastToVoid(&e); ok (casted == (void*)&e, "failed cast to void\n"); @@ -838,6 +957,75 @@ call_func1(pexception_dtor, &e); call_func1(pbad_typeid_dtor, &b); + + memcpy(&simple_class_sig0_rtti, &simple_class_rtti, sizeof(struct rtti_data)); + simple_class_sig0_rtti.object_locator.signature = 0; + simple_class_sig0_rtti.base_descriptor[0].type_descriptor = RTTI_REF_SIG0(simple_class_sig0_rtti, type_info[0], base); + simple_class_sig0_rtti.base_array.bases[0] = RTTI_REF_SIG0(simple_class_sig0_rtti, base_descriptor[0], base); + simple_class_sig0_rtti.object_hierarchy.base_classes = RTTI_REF_SIG0(simple_class_sig0_rtti, base_array, base); + simple_class_sig0_rtti.object_locator.type_descriptor = RTTI_REF_SIG0(simple_class_sig0_rtti, type_info[0], base); + simple_class_sig0_rtti.object_locator.type_hierarchy = RTTI_REF_SIG0(simple_class_sig0_rtti, object_hierarchy, base); + + memcpy(&child_class_sig0_rtti, &child_class_rtti, sizeof(struct rtti_data)); + child_class_sig0_rtti.object_locator.signature = 0; + child_class_sig0_rtti.base_descriptor[0].type_descriptor = RTTI_REF_SIG0(child_class_sig0_rtti, type_info[1], base); + child_class_sig0_rtti.base_descriptor[1].type_descriptor = RTTI_REF_SIG0(child_class_sig0_rtti, type_info[0], base); + child_class_sig0_rtti.base_array.bases[0] = RTTI_REF_SIG0(child_class_sig0_rtti, base_descriptor[0], base); + child_class_sig0_rtti.base_array.bases[1] = RTTI_REF_SIG0(child_class_sig0_rtti, base_descriptor[1], base); + child_class_sig0_rtti.object_hierarchy.base_classes = RTTI_REF_SIG0(child_class_sig0_rtti, base_array, base); + child_class_sig0_rtti.object_locator.type_descriptor = RTTI_REF_SIG0(child_class_sig0_rtti, type_info[1], base); + child_class_sig0_rtti.object_locator.type_hierarchy = RTTI_REF_SIG0(child_class_sig0_rtti, object_hierarchy, base); + + ti = p__RTtypeid(&simple_class_sig0); + ok (ti && ti->mangled && !strcmp(ti->mangled, "simple_class"), + "incorrect rtti data\n"); + + casted = p__RTCastToVoid(&simple_class_sig0); + ok (casted == (void*)&simple_class_sig0, "failed cast to void\n"); + + ti = p__RTtypeid(&child_class_sig0); + ok (ti && ti->mangled && !strcmp(ti->mangled, "child_class"), + "incorrect rtti data\n"); + + casted = p__RTCastToVoid(&child_class_sig0); + ok (casted == (void*)&child_class_sig0, "failed cast to void\n"); + + casted = p__RTDynamicCast(&child_class_sig0, 0, NULL, simple_class_sig0_rtti.type_info, 0); + if(casted) + { + ok (casted == (char*)&child_class_sig0+8, "failed cast to simple_class (%p %p)\n", casted, &child_class_sig0); + } + + casted = p__RTDynamicCast(&child_class_sig0, 0, &child_class_sig0_rtti.type_info[0], &child_class_sig0_rtti.type_info[1], 0); + ok(casted == (char*)&child_class_sig0+4, "failed cast to child class (%p %p)\n", casted, &child_class_sig0); + + if(old_signature) { + skip("signature==1 is not supported\n"); + return; + } + + ti = p__RTtypeid(&simple_class); + ok (ti && ti->mangled && !strcmp(ti->mangled, "simple_class"), + "incorrect rtti data\n"); + + casted = p__RTCastToVoid(&simple_class); + ok (casted == (void*)&simple_class, "failed cast to void\n"); + + ti = p__RTtypeid(&child_class); + ok (ti && ti->mangled && !strcmp(ti->mangled, "child_class"), + "incorrect rtti data\n"); + + casted = p__RTCastToVoid(&child_class); + ok (casted == (void*)&child_class, "failed cast to void\n"); + + casted = p__RTDynamicCast(&child_class, 0, NULL, simple_class_rtti.type_info, 0); + if(casted) + { + ok (casted == (char*)&child_class+8, "failed cast to simple_class (%p %p)\n", casted, &child_class); + } + + casted = p__RTDynamicCast(&child_class, 0, &child_class_rtti.type_info[0], &child_class_rtti.type_info[1], 0); + ok(casted == (char*)&child_class+4, "failed cast to child class (%p %p)\n", casted, &child_class); } struct _demangle { @@ -1081,7 +1269,8 @@ START_TEST(cpp) { - InitFunctionPtrs(); + if (!InitFunctionPtrs()) + return; test_exception(); test_bad_typeid(); @@ -1092,4 +1281,3 @@ test_demangle_datatype(); test_demangle(); } -#endif /* __i386__ */ Modified: trunk/rostests/winetests/msvcrt/file.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/msvcrt/file.c?r…
============================================================================== --- trunk/rostests/winetests/msvcrt/file.c [iso-8859-1] (original) +++ trunk/rostests/winetests/msvcrt/file.c [iso-8859-1] Sat Sep 29 14:28:48 2012 @@ -434,6 +434,37 @@ unlink("ascii2.tst"); } +static void test_filemodeT(void) +{ + char DATA [] = {26, 't', 'e', 's' ,'t'}; + char DATA2 [100]; + char temppath[MAX_PATH]; + char tempfile[MAX_PATH]; + FILE* f; + size_t bytesWritten; + size_t bytesRead; + WIN32_FIND_DATA findData; + HANDLE h; + + GetTempPath (MAX_PATH, temppath); + GetTempFileName (temppath, "", 0, tempfile); + + f = fopen(tempfile, "w+bDT"); + bytesWritten = fwrite(DATA, 1, sizeof(DATA), f); + rewind(f); + bytesRead = fread(DATA2, 1, sizeof(DATA2), f); + fclose(f); + + ok (bytesRead == bytesWritten && bytesRead == sizeof(DATA), + "fopen file mode 'T' wrongly interpreted as 't'\n" ); + + h = FindFirstFile(tempfile, &findData); + + ok (h == INVALID_HANDLE_VALUE, "file wasn't deleted when closed.\n" ); + + if (h != INVALID_HANDLE_VALUE) FindClose(h); +} + static WCHAR* AtoW( const char* p ) { WCHAR* buffer; @@ -544,10 +575,21 @@ bufmodes[bufmode], 0, ret); ret = _flsbuf(0xff,tempfh); ok(0xff == ret, "_flsbuf(0xff,tempfh) with bufmode %x expected %x got %x\n", - bufmodes[bufmode], 0, ret); + bufmodes[bufmode], 0xff, ret); ret = _flsbuf(0xffffffff,tempfh); ok(0xff == ret, "_flsbuf(0xffffffff,tempfh) with bufmode %x expected %x got %x\n", - bufmodes[bufmode], 0, ret); + bufmodes[bufmode], 0xff, ret); + if(tempfh->_base) { + fputc('x', tempfh); + tempfh->_cnt = -1; + tempfh->_base[1] = 'a'; + ret = _flsbuf(0xab,tempfh); + ok(ret == 0xab, "_flsbuf(0xab,tempfh) with bufmode %x expected 0xab got %x\n", + bufmodes[bufmode], ret); + ok(tempfh->_base[1] == 'a', "tempfh->_base[1] should not be changed (%d)\n", + tempfh->_base[1]); + } + fclose(tempfh); } @@ -574,6 +616,58 @@ ok(c == 'Q', "first byte should be 'Q'\n"); c = fgetc(tempfh); ok(c == EOF, "there should only be one byte\n"); + fclose(tempfh); + + unlink(tempf); + free(tempf); +} + +static void test_fflush( void ) +{ + static const char obuf[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + char buf1[16], buf2[24]; + char *tempf; + FILE *tempfh; + int ret; + + tempf=_tempnam(".","wne"); + + /* Prepare the file. */ + tempfh = fopen(tempf,"wb"); + ok(tempfh != NULL, "Can't open test file.\n"); + fwrite(obuf, 1, sizeof(obuf), tempfh); + fclose(tempfh); + + /* Open the file for input. */ + tempfh = fopen(tempf,"rb"); + ok(tempfh != NULL, "Can't open test file.\n"); + fread(buf1, 1, sizeof(buf1), tempfh); + + /* Using fflush() on input stream is undefined in ANSI. + * But MSDN says that it clears input buffer. */ + _lseek(_fileno(tempfh), 0, SEEK_SET); + ret = fflush(tempfh); + ok(ret == 0, "expected 0, got %d\n", ret); + memset(buf2, '?', sizeof(buf2)); + fread(buf2, 1, sizeof(buf2), tempfh); + ok(memcmp(buf1, buf2, sizeof(buf1)) == 0, "Got unexpected data (%c)\n", buf2[0]); + + /* fflush(NULL) doesn't clear input buffer. */ + _lseek(_fileno(tempfh), 0, SEEK_SET); + ret = fflush(NULL); + ok(ret == 0, "expected 0, got %d\n", ret); + memset(buf2, '?', sizeof(buf2)); + fread(buf2, 1, sizeof(buf2), tempfh); + ok(memcmp(buf1, buf2, sizeof(buf1)) != 0, "Got unexpected data (%c)\n", buf2[0]); + + /* _flushall() clears input buffer. */ + _lseek(_fileno(tempfh), 0, SEEK_SET); + ret = _flushall(); + ok(ret >= 0, "unexpected ret %d\n", ret); + memset(buf2, '?', sizeof(buf2)); + fread(buf2, 1, sizeof(buf2), tempfh); + ok(memcmp(buf1, buf2, sizeof(buf1)) == 0, "Got unexpected data (%c)\n", buf2[0]); + fclose(tempfh); unlink(tempf); @@ -1565,12 +1659,14 @@ test_fileops(); test_asciimode(); test_asciimode2(); + test_filemodeT(); test_readmode(FALSE); /* binary mode */ test_readmode(TRUE); /* ascii mode */ test_readboundary(); test_fgetc(); test_fputc(); test_flsbuf(); + test_fflush(); test_fgetwc(); test_ctrlz(); test_file_put_get(); Modified: trunk/rostests/winetests/msvcrt/locale.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/msvcrt/locale.c…
============================================================================== --- trunk/rostests/winetests/msvcrt/locale.c [iso-8859-1] (original) +++ trunk/rostests/winetests/msvcrt/locale.c [iso-8859-1] Sat Sep 29 14:28:48 2012 @@ -25,6 +25,7 @@ static BOOL (__cdecl *p__crtGetStringTypeW)(DWORD, DWORD, const wchar_t*, int, WORD*); static int (__cdecl *pmemcpy_s)(void *, size_t, void*, size_t); +void* __cdecl _Gettnames(void); static void init(void) { @@ -471,10 +472,11 @@ if(ret) ok(!strcmp(ret, "Polish_Poland.1250"), "ret = %s\n", ret); - ret = setlocale(LC_ALL, "portugese"); - ok(ret != NULL || broken (ret == NULL), "ret == NULL\n"); - if(ret) - ok(!strcmp(ret, "Portuguese_Brazil.1252"), "ret = %s\n", ret); + ret = setlocale(LC_ALL, "portuguese"); + ok(ret != NULL || broken (ret == NULL), "ret == NULL\n"); + if(ret) + ok(!strcmp(ret, "Portuguese_Brazil.1252") + || broken(!strcmp(ret, "Portuguese_Portugal.1252")) /* NT4 */, "ret = %s\n", ret); ret = setlocale(LC_ALL, "portuguese-brazil"); ok(ret != NULL || broken (ret == NULL), "ret == NULL\n"); @@ -616,10 +618,131 @@ ok(!ret, "ret == TRUE\n"); } +static void test__Gettnames(void) +{ + struct { + char *str[43]; + LCID lcid; + int unk[2]; + wchar_t *wstr[43]; + char data[1]; + } *ret; + int size; + + if(!setlocale(LC_ALL, "english")) + return; + + ret = _Gettnames(); + size = ret->data-(char*)ret; + /* Newer version of the structure stores both ascii and unicode strings. + * Unicode strings are only initialized on Windows 7 + */ + if(sizeof(void*) == 8) + ok(size==0x2c0 || broken(size==0x170), "strucure size: %x\n", size); + else + ok(size==0x164 || broken(size==0xb8), "strucure size: %x\n", size); + + ok(!strcmp(ret->str[0], "Sun"), "ret->str[0] = %s\n", ret->str[0]); + ok(!strcmp(ret->str[1], "Mon"), "ret->str[1] = %s\n", ret->str[1]); + ok(!strcmp(ret->str[2], "Tue"), "ret->str[2] = %s\n", ret->str[2]); + ok(!strcmp(ret->str[3], "Wed"), "ret->str[3] = %s\n", ret->str[3]); + ok(!strcmp(ret->str[4], "Thu"), "ret->str[4] = %s\n", ret->str[4]); + ok(!strcmp(ret->str[5], "Fri"), "ret->str[5] = %s\n", ret->str[5]); + ok(!strcmp(ret->str[6], "Sat"), "ret->str[6] = %s\n", ret->str[6]); + ok(!strcmp(ret->str[7], "Sunday"), "ret->str[7] = %s\n", ret->str[7]); + ok(!strcmp(ret->str[8], "Monday"), "ret->str[8] = %s\n", ret->str[8]); + ok(!strcmp(ret->str[9], "Tuesday"), "ret->str[9] = %s\n", ret->str[9]); + ok(!strcmp(ret->str[10], "Wednesday"), "ret->str[10] = %s\n", ret->str[10]); + ok(!strcmp(ret->str[11], "Thursday"), "ret->str[11] = %s\n", ret->str[11]); + ok(!strcmp(ret->str[12], "Friday"), "ret->str[12] = %s\n", ret->str[12]); + ok(!strcmp(ret->str[13], "Saturday"), "ret->str[13] = %s\n", ret->str[13]); + ok(!strcmp(ret->str[14], "Jan"), "ret->str[14] = %s\n", ret->str[14]); + ok(!strcmp(ret->str[15], "Feb"), "ret->str[15] = %s\n", ret->str[15]); + ok(!strcmp(ret->str[16], "Mar"), "ret->str[16] = %s\n", ret->str[16]); + ok(!strcmp(ret->str[17], "Apr"), "ret->str[17] = %s\n", ret->str[17]); + ok(!strcmp(ret->str[18], "May"), "ret->str[18] = %s\n", ret->str[18]); + ok(!strcmp(ret->str[19], "Jun"), "ret->str[19] = %s\n", ret->str[19]); + ok(!strcmp(ret->str[20], "Jul"), "ret->str[20] = %s\n", ret->str[20]); + ok(!strcmp(ret->str[21], "Aug"), "ret->str[21] = %s\n", ret->str[21]); + ok(!strcmp(ret->str[22], "Sep"), "ret->str[22] = %s\n", ret->str[22]); + ok(!strcmp(ret->str[23], "Oct"), "ret->str[23] = %s\n", ret->str[23]); + ok(!strcmp(ret->str[24], "Nov"), "ret->str[24] = %s\n", ret->str[24]); + ok(!strcmp(ret->str[25], "Dec"), "ret->str[25] = %s\n", ret->str[25]); + ok(!strcmp(ret->str[26], "January"), "ret->str[26] = %s\n", ret->str[26]); + ok(!strcmp(ret->str[27], "February"), "ret->str[27] = %s\n", ret->str[27]); + ok(!strcmp(ret->str[28], "March"), "ret->str[28] = %s\n", ret->str[28]); + ok(!strcmp(ret->str[29], "April"), "ret->str[29] = %s\n", ret->str[29]); + ok(!strcmp(ret->str[30], "May"), "ret->str[30] = %s\n", ret->str[30]); + ok(!strcmp(ret->str[31], "June"), "ret->str[31] = %s\n", ret->str[31]); + ok(!strcmp(ret->str[32], "July"), "ret->str[32] = %s\n", ret->str[32]); + ok(!strcmp(ret->str[33], "August"), "ret->str[33] = %s\n", ret->str[33]); + ok(!strcmp(ret->str[34], "September"), "ret->str[34] = %s\n", ret->str[34]); + ok(!strcmp(ret->str[35], "October"), "ret->str[35] = %s\n", ret->str[35]); + ok(!strcmp(ret->str[36], "November"), "ret->str[36] = %s\n", ret->str[36]); + ok(!strcmp(ret->str[37], "December"), "ret->str[37] = %s\n", ret->str[37]); + ok(!strcmp(ret->str[38], "AM"), "ret->str[38] = %s\n", ret->str[38]); + ok(!strcmp(ret->str[39], "PM"), "ret->str[39] = %s\n", ret->str[39]); + ok(!strcmp(ret->str[40], "M/d/yyyy") || broken(!strcmp(ret->str[40], "M/d/yy"))/*NT*/, + "ret->str[40] = %s\n", ret->str[40]); + ok(!strcmp(ret->str[41], "dddd, MMMM dd, yyyy"), "ret->str[41] = %s\n", ret->str[41]); + free(ret); + + if(!setlocale(LC_TIME, "german")) + return; + + ret = _Gettnames(); + ok(!strcmp(ret->str[0], "So"), "ret->str[0] = %s\n", ret->str[0]); + ok(!strcmp(ret->str[1], "Mo"), "ret->str[1] = %s\n", ret->str[1]); + ok(!strcmp(ret->str[2], "Di"), "ret->str[2] = %s\n", ret->str[2]); + ok(!strcmp(ret->str[3], "Mi"), "ret->str[3] = %s\n", ret->str[3]); + ok(!strcmp(ret->str[4], "Do"), "ret->str[4] = %s\n", ret->str[4]); + ok(!strcmp(ret->str[5], "Fr"), "ret->str[5] = %s\n", ret->str[5]); + ok(!strcmp(ret->str[6], "Sa"), "ret->str[6] = %s\n", ret->str[6]); + ok(!strcmp(ret->str[7], "Sonntag"), "ret->str[7] = %s\n", ret->str[7]); + ok(!strcmp(ret->str[8], "Montag"), "ret->str[8] = %s\n", ret->str[8]); + ok(!strcmp(ret->str[9], "Dienstag"), "ret->str[9] = %s\n", ret->str[9]); + ok(!strcmp(ret->str[10], "Mittwoch"), "ret->str[10] = %s\n", ret->str[10]); + ok(!strcmp(ret->str[11], "Donnerstag"), "ret->str[11] = %s\n", ret->str[11]); + ok(!strcmp(ret->str[12], "Freitag"), "ret->str[12] = %s\n", ret->str[12]); + ok(!strcmp(ret->str[13], "Samstag"), "ret->str[13] = %s\n", ret->str[13]); + ok(!strcmp(ret->str[14], "Jan"), "ret->str[14] = %s\n", ret->str[14]); + ok(!strcmp(ret->str[15], "Feb"), "ret->str[15] = %s\n", ret->str[15]); + ok(!strcmp(ret->str[16], "Mrz"), "ret->str[16] = %s\n", ret->str[16]); + ok(!strcmp(ret->str[17], "Apr"), "ret->str[17] = %s\n", ret->str[17]); + ok(!strcmp(ret->str[18], "Mai"), "ret->str[18] = %s\n", ret->str[18]); + ok(!strcmp(ret->str[19], "Jun"), "ret->str[19] = %s\n", ret->str[19]); + ok(!strcmp(ret->str[20], "Jul"), "ret->str[20] = %s\n", ret->str[20]); + ok(!strcmp(ret->str[21], "Aug"), "ret->str[21] = %s\n", ret->str[21]); + ok(!strcmp(ret->str[22], "Sep"), "ret->str[22] = %s\n", ret->str[22]); + ok(!strcmp(ret->str[23], "Okt"), "ret->str[23] = %s\n", ret->str[23]); + ok(!strcmp(ret->str[24], "Nov"), "ret->str[24] = %s\n", ret->str[24]); + ok(!strcmp(ret->str[25], "Dez"), "ret->str[25] = %s\n", ret->str[25]); + ok(!strcmp(ret->str[26], "Januar"), "ret->str[26] = %s\n", ret->str[26]); + ok(!strcmp(ret->str[27], "Februar"), "ret->str[27] = %s\n", ret->str[27]); + ok(!strcmp(ret->str[29], "April"), "ret->str[29] = %s\n", ret->str[29]); + ok(!strcmp(ret->str[30], "Mai"), "ret->str[30] = %s\n", ret->str[30]); + ok(!strcmp(ret->str[31], "Juni"), "ret->str[31] = %s\n", ret->str[31]); + ok(!strcmp(ret->str[32], "Juli"), "ret->str[32] = %s\n", ret->str[32]); + ok(!strcmp(ret->str[33], "August"), "ret->str[33] = %s\n", ret->str[33]); + ok(!strcmp(ret->str[34], "September"), "ret->str[34] = %s\n", ret->str[34]); + ok(!strcmp(ret->str[35], "Oktober"), "ret->str[35] = %s\n", ret->str[35]); + ok(!strcmp(ret->str[36], "November"), "ret->str[36] = %s\n", ret->str[36]); + ok(!strcmp(ret->str[37], "Dezember"), "ret->str[37] = %s\n", ret->str[37]); + ok(!strcmp(ret->str[38], ""), "ret->str[38] = %s\n", ret->str[38]); + ok(!strcmp(ret->str[39], ""), "ret->str[39] = %s\n", ret->str[39]); + ok(!strcmp(ret->str[40], "dd.MM.yyyy") || broken(!strcmp(ret->str[40], "dd.MM.yy"))/*NT*/, + "ret->str[40] = %s\n", ret->str[40]); + ok(!strcmp(ret->str[41], "dddd, d. MMMM yyyy"), "ret->str[41] = %s\n", ret->str[41]); + free(ret); + + setlocale(LC_ALL, "C"); +} + START_TEST(locale) { init(); test_crtGetStringTypeW(); test_setlocale(); + test__Gettnames(); } Modified: trunk/rostests/winetests/msvcrt/misc.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/msvcrt/misc.c?r…
============================================================================== --- trunk/rostests/winetests/msvcrt/misc.c [iso-8859-1] (original) +++ trunk/rostests/winetests/msvcrt/misc.c [iso-8859-1] Sat Sep 29 14:28:48 2012 @@ -23,7 +23,6 @@ #include "msvcrt.h" static int (__cdecl *prand_s)(unsigned int *); -static int (__cdecl *pmemcpy_s)(void *, MSVCRT_size_t, void*, MSVCRT_size_t); static int (__cdecl *pI10_OUTPUT)(long double, int, int, void*); static int (__cdecl *pstrerror_s)(char *, MSVCRT_size_t, int); static int (__cdecl *p_get_doserrno)(int *); @@ -36,7 +35,6 @@ HMODULE hmod = GetModuleHandleA("msvcrt.dll"); prand_s = (void *)GetProcAddress(hmod, "rand_s"); - pmemcpy_s = (void*)GetProcAddress(hmod, "memcpy_s"); pI10_OUTPUT = (void*)GetProcAddress(hmod, "$I10_OUTPUT"); pstrerror_s = (void *)GetProcAddress(hmod, "strerror_s"); p_get_doserrno = (void *)GetProcAddress(hmod, "_get_doserrno"); @@ -63,57 +61,6 @@ ret = prand_s(&rand); ok(ret == 0, "Expected rand_s to return 0, got %d\n", ret); -} - -static void test_memcpy_s(void) -{ - static char data[] = "data\0to\0be\0copied"; - static char dest[32]; - int ret; - - if(!pmemcpy_s) - { - win_skip("memcpy_s is not available\n"); - return; - } - - errno = 0xdeadbeef; - ret = pmemcpy_s(NULL, 0, NULL, 0); - ok(ret == 0, "ret = %x\n", ret); - ok(errno == 0xdeadbeef, "errno = %x\n", errno); - - errno = 0xdeadbeef; - dest[0] = 'x'; - ret = pmemcpy_s(dest, 10, NULL, 0); - ok(ret == 0, "ret = %x\n", ret); - ok(errno == 0xdeadbeef, "errno = %x\n", errno); - ok(dest[0] == 'x', "dest[0] != \'x\'\n"); - - errno = 0xdeadbeef; - ret = pmemcpy_s(NULL, 10, data, 10); - ok(ret == EINVAL, "ret = %x\n", ret); - ok(errno == EINVAL, "errno = %x\n", errno); - - errno = 0xdeadbeef; - dest[7] = 'x'; - ret = pmemcpy_s(dest, 10, data, 5); - ok(ret == 0, "ret = %x\n", ret); - ok(errno == 0xdeadbeef, "errno = %x\n", errno); - ok(memcmp(dest, data, 10), "All data copied\n"); - ok(!memcmp(dest, data, 5), "First five bytes are different\n"); - - errno = 0xdeadbeef; - ret = pmemcpy_s(data, 10, data, 10); - ok(ret == 0, "ret = %x\n", ret); - ok(errno == 0xdeadbeef, "errno = %x\n", errno); - ok(!memcmp(dest, data, 5), "data was destroyed during overwriting\n"); - - errno = 0xdeadbeef; - dest[0] = 'x'; - ret = pmemcpy_s(dest, 5, data, 10); - ok(ret == ERANGE, "ret = %x\n", ret); - ok(errno == ERANGE, "errno = %x\n", errno); - ok(dest[0] == '\0', "dest[0] != \'\\0\'\n"); } typedef struct _I10_OUTPUT_data { @@ -367,7 +314,6 @@ init(); test_rand_s(); - test_memcpy_s(); test_I10_OUTPUT(); test_strerror_s(); test__get_doserrno(); Modified: trunk/rostests/winetests/msvcrt/printf.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/msvcrt/printf.c…
============================================================================== --- trunk/rostests/winetests/msvcrt/printf.c [iso-8859-1] (original) +++ trunk/rostests/winetests/msvcrt/printf.c [iso-8859-1] Sat Sep 29 14:28:48 2012 @@ -323,6 +323,22 @@ ok(!strcmp(buffer,"1 "),"Character zero-padded and/or not left-adjusted \"%s\"\n",buffer); ok( r==4, "return count wrong\n"); + format = "%#012x"; + r = sprintf(buffer,format,1); + ok(!strcmp(buffer,"0x0000000001"),"Hexadecimal zero-padded \"%s\"\n",buffer); + + format = "%#04.8x"; + r = sprintf(buffer,format,1); + ok(!strcmp(buffer,"0x00000001"), "Hexadecimal zero-padded precision \"%s\"\n",buffer); + + format = "%#-08.2x"; + r = sprintf(buffer,format,1); + ok(!strcmp(buffer,"0x01 "), "Hexadecimal zero-padded not left-adjusted \"%s\"\n",buffer); + + format = "%#08o"; + r = sprintf(buffer,format,1); + ok(!strcmp(buffer,"00000001"), "Octal zero-padded \"%s\"\n",buffer); + if (sizeof(void *) == 8) { format = "%p"; @@ -591,6 +607,16 @@ r = sprintf(buffer, format); ok(!strcmp(buffer,"%0"), "failed: \"%s\"\n", buffer); ok( r==2, "return count wrong\n"); + + format = "%hx"; + r = sprintf(buffer, format, 0x12345); + ok(!strcmp(buffer,"2345"), "failed \"%s\"\n", buffer); + + format = "%hhx"; + r = sprintf(buffer, format, 0x123); + ok(!strcmp(buffer,"123"), "failed: \"%s\"\n", buffer); + r = sprintf(buffer, format, 0x12345); + ok(!strcmp(buffer,"2345"), "failed \"%s\"\n", buffer); } static void test_swprintf( void ) Modified: trunk/rostests/winetests/msvcrt/scanf.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/msvcrt/scanf.c?…
============================================================================== --- trunk/rostests/winetests/msvcrt/scanf.c [iso-8859-1] (original) +++ trunk/rostests/winetests/msvcrt/scanf.c [iso-8859-1] Sat Sep 29 14:28:48 2012 @@ -27,6 +27,7 @@ char buffer[100], buffer1[100]; char format[20]; int result, ret; + LONGLONG result64; char c; void *ptr; float res1= -82.6267f, res2= 27.76f, res11, res12; @@ -125,6 +126,25 @@ ok(ret == 0 , "problem with format arg \"%%*c%%n\"\n"); ok(number_so_far == 1,"Read wrong arg for \"%%n\" %d instead of 2\n",number_so_far); + result = 0xdeadbeef; + strcpy(buffer,"12345678"); + ret = sscanf(buffer, "%hd", &result); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ok(result == 0xdead614e, "Wrong number read (%x)\n", result); + + result = 0xdeadbeef; + ret = sscanf(buffer, "%hhd", &result); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ok(result == 0xbc614e, "Wrong number read (%x)\n", result); + + strcpy(buffer,"12345678901234"); + ret = sscanf(buffer, "%lld", &result64); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ret = sprintf(buffer1, "%lld", result64); + ok(ret==14 || broken(ret==10), "sprintf retuned %d\n", ret); + if(ret == 14) + ok(!strcmp(buffer, buffer1), "got %s, expected %s\n", buffer1, buffer); + /* Check %i according to bug 1878 */ strcpy(buffer,"123"); ret = sscanf(buffer, "%i", &result); @@ -243,8 +263,25 @@ ok(i==123, "i = %d\n", i); } +static void test_swscanf( void ) +{ + wchar_t buffer[100]; + int result, ret; + static const WCHAR formatd[] = {'%','d',0}; + + /* check WEOF */ + /* WEOF is an unsigned short -1 but swscanf returns int + so it should be sign-extended */ + buffer[0] = 0; + ret = swscanf(buffer, formatd, &result); + /* msvcrt returns 0 but should return -1 (later versions do) */ + ok( ret == (short)WEOF || broken(ret == 0), + "swscanf returns %x instead of %x\n", ret, WEOF ); +} + START_TEST(scanf) { test_sscanf(); test_sscanf_s(); -} + test_swscanf(); +} Modified: trunk/rostests/winetests/msvcrt/string.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/msvcrt/string.c…
============================================================================== --- trunk/rostests/winetests/msvcrt/string.c [iso-8859-1] (original) +++ trunk/rostests/winetests/msvcrt/string.c [iso-8859-1] Sat Sep 29 14:28:48 2012 @@ -58,6 +58,8 @@ #define expect_bin(buf, value, len) { ok(memcmp((buf), value, len) == 0, "Binary buffer mismatch - expected %s, got %s\n", buf_to_string((unsigned char *)value, len, 1), buf_to_string((buf), len, 0)); } static void* (__cdecl *pmemcpy)(void *, const void *, size_t n); +static int (__cdecl *p_memcpy_s)(void *, size_t, const void *, size_t); +static int (__cdecl *p_memmove_s)(void *, size_t, const void *, size_t); static int* (__cdecl *pmemcmp)(void *, const void *, size_t n); static int (__cdecl *pstrcpy_s)(char *dst, size_t len, const char *src); static int (__cdecl *pstrcat_s)(char *dst, size_t len, const char *src); @@ -500,6 +502,148 @@ ok(ret == EINVAL, "Copying a big string a NULL dest returned %d, expected EINVAL\n", ret); } +#define NUMELMS(array) (sizeof(array)/sizeof((array)[0])) + +#define okchars(dst, b0, b1, b2, b3, b4, b5, b6, b7) \ + ok(dst[0] == b0 && dst[1] == b1 && dst[2] == b2 && dst[3] == b3 && \ + dst[4] == b4 && dst[5] == b5 && dst[6] == b6 && dst[7] == b7, \ + "Bad result: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",\ + dst[0], dst[1], dst[2], dst[3], dst[4], dst[5], dst[6], dst[7]) + +static void test_memcpy_s(void) +{ + static char dest[8]; + static const char tiny[] = {'T',0,'I','N','Y',0}; + static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0}; + int ret; + if (!p_memcpy_s) { + skip("memcpy_s not found\n"); + return; + } + + if (p_set_invalid_parameter_handler) + ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL, + "Invalid parameter handler was already set\n"); + + /* Normal */ + memset(dest, 'X', sizeof(dest)); + ret = p_memcpy_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny)); + ok(ret == 0, "Copying a buffer into a big enough destination returned %d, expected 0\n", ret); + okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X'); + + /* Vary source size */ + errno = 0xdeadbeef; + memset(dest, 'X', sizeof(dest)); + ret = p_memcpy_s(dest, NUMELMS(dest), big, NUMELMS(big)); + ok(ret == ERANGE, "Copying a big buffer to a small destination returned %d, expected ERANGE\n", ret); + ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno); + okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0); + + /* Replace source with NULL */ + errno = 0xdeadbeef; + memset(dest, 'X', sizeof(dest)); + ret = p_memcpy_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny)); + ok(ret == EINVAL, "Copying a NULL source buffer returned %d, expected EINVAL\n", ret); + ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno); + okchars(dest, 0, 0, 0, 0, 0, 0, 0, 0); + + /* Vary dest size */ + errno = 0xdeadbeef; + memset(dest, 'X', sizeof(dest)); + ret = p_memcpy_s(dest, 0, tiny, NUMELMS(tiny)); + ok(ret == ERANGE, "Copying into a destination of size 0 returned %d, expected ERANGE\n", ret); + ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno); + okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'); + + /* Replace dest with NULL */ + errno = 0xdeadbeef; + ret = p_memcpy_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny)); + ok(ret == EINVAL, "Copying a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret); + ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno); + + /* Combinations */ + errno = 0xdeadbeef; + memset(dest, 'X', sizeof(dest)); + ret = p_memcpy_s(dest, 0, NULL, NUMELMS(tiny)); + ok(ret == EINVAL, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret); + ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno); + okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'); + + if (p_set_invalid_parameter_handler) + ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler, + "Cannot reset invalid parameter handler\n"); +} + +static void test_memmove_s(void) +{ + static char dest[8]; + static const char tiny[] = {'T',0,'I','N','Y',0}; + static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0}; + int ret; + if (!p_memmove_s) { + skip("memmove_s not found\n"); + return; + } + + if (p_set_invalid_parameter_handler) + ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL, + "Invalid parameter handler was already set\n"); + + /* Normal */ + memset(dest, 'X', sizeof(dest)); + ret = p_memmove_s(dest, NUMELMS(dest), tiny, NUMELMS(tiny)); + ok(ret == 0, "Moving a buffer into a big enough destination returned %d, expected 0\n", ret); + okchars(dest, tiny[0], tiny[1], tiny[2], tiny[3], tiny[4], tiny[5], 'X', 'X'); + + /* Overlapping */ + memcpy(dest, big, sizeof(dest)); + ret = p_memmove_s(dest+1, NUMELMS(dest)-1, dest, NUMELMS(dest)-1); + ok(ret == 0, "Moving a buffer up one char returned %d, expected 0\n", ret); + okchars(dest, big[0], big[0], big[1], big[2], big[3], big[4], big[5], big[6]); + + /* Vary source size */ + errno = 0xdeadbeef; + memset(dest, 'X', sizeof(dest)); + ret = p_memmove_s(dest, NUMELMS(dest), big, NUMELMS(big)); + ok(ret == ERANGE, "Moving a big buffer to a small destination returned %d, expected ERANGE\n", ret); + ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno); + okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'); + + /* Replace source with NULL */ + errno = 0xdeadbeef; + memset(dest, 'X', sizeof(dest)); + ret = p_memmove_s(dest, NUMELMS(dest), NULL, NUMELMS(tiny)); + ok(ret == EINVAL, "Moving a NULL source buffer returned %d, expected EINVAL\n", ret); + ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno); + okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'); + + /* Vary dest size */ + errno = 0xdeadbeef; + memset(dest, 'X', sizeof(dest)); + ret = p_memmove_s(dest, 0, tiny, NUMELMS(tiny)); + ok(ret == ERANGE, "Moving into a destination of size 0 returned %d, expected ERANGE\n", ret); + ok(errno == ERANGE, "errno is %d, expected ERANGE\n", errno); + okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'); + + /* Replace dest with NULL */ + errno = 0xdeadbeef; + ret = p_memmove_s(NULL, NUMELMS(dest), tiny, NUMELMS(tiny)); + ok(ret == EINVAL, "Moving a tiny buffer to a big NULL destination returned %d, expected EINVAL\n", ret); + ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno); + + /* Combinations */ + errno = 0xdeadbeef; + memset(dest, 'X', sizeof(dest)); + ret = p_memmove_s(dest, 0, NULL, NUMELMS(tiny)); + ok(ret == EINVAL, "Moving a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret); + ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno); + okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'); + + if (p_set_invalid_parameter_handler) + ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler, + "Cannot reset invalid parameter handler\n"); +} + static void test_strcat_s(void) { char dest[8]; @@ -685,6 +829,22 @@ ret = p_wcsncpy_s(szDestShort, 8, szLongText, sizeof(szLongText)/sizeof(WCHAR)); ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret); ok(szDestShort[0] == 0, "szDestShort[0] not 0\n"); + + szDest[0] = 'A'; + ret = p_wcsncpy_s(szDest, 5, szLongText, -1); + ok(ret == STRUNCATE, "expected STRUNCATE got %d\n", ret); + ok(szDest[4] == 0, "szDest[4] not 0\n"); + ok(!memcmp(szDest, szLongText, 4*sizeof(WCHAR)), "szDest = %s\n", wine_dbgstr_w(szDest)); + + ret = p_wcsncpy_s(NULL, 0, (void*)0xdeadbeef, 0); + ok(ret == 0, "ret = %d\n", ret); + + szDestShort[0] = '1'; + szDestShort[1] = 0; + ret = p_wcsncpy_s(szDestShort+1, 4, szDestShort, -1); + ok(ret == STRUNCATE, "expected ERROR_SUCCESS got %d\n", ret); + ok(szDestShort[0]=='1' && szDestShort[1]=='1' && szDestShort[2]=='1' && szDestShort[3]=='1', + "szDestShort = %s\n", wine_dbgstr_w(szDestShort)); } static void test__wcsupr_s(void) @@ -866,21 +1026,79 @@ /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */ unsigned int jisjms[][2] = { {0x2020, 0}, {0x2021, 0}, {0x2120, 0}, {0x2121, 0x8140}, {0x7f7f, 0}, {0x7f7e, 0}, {0x7e7f, 0}, {0x7e7e, 0xeffc}, + {0x255f, 0x837e}, {0x2560, 0x8380}, {0x2561, 0x8381}, {0x2121FFFF, 0}, {0x2223, 0x81a1}, {0x237e, 0x829e}, {0, 0}}; - unsigned int ret, exp, i; - - i = 0; - do + int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS }; + unsigned int i, j; + int prev_cp = _getmbcp(); + + for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++) { - ret = _mbcjistojms(jisjms[i][0]); - - if(_getmbcp() == 932) /* Japanese codepage? */ - exp = jisjms[i][1]; - else - exp = jisjms[i][0]; /* If not, no conversion */ - - ok(ret == exp, "Expected 0x%x, got 0x%x\n", exp, ret); - } while(jisjms[i++][0] != 0); + _setmbcp(cp[i]); + for (j = 0; jisjms[j][0] != 0; j++) + { + unsigned int ret, exp; + ret = _mbcjistojms(jisjms[j][0]); + exp = (cp[i] == 932) ? jisjms[j][1] : jisjms[j][0]; + ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n", + exp, ret, jisjms[j][0], cp[i]); + } + } + _setmbcp(prev_cp); +} + +static void test_mbcjmsjis(void) +{ + /* List of value-pairs to test. The test assumes the last pair to be {0, ..} */ + unsigned int jmsjis[][2] = { {0x80fc, 0}, {0x813f, 0}, {0x8140, 0x2121}, + {0x817e, 0x215f}, {0x817f, 0}, {0x8180, 0x2160}, + {0x819e, 0x217e}, {0x819f, 0x2221}, {0x81fc, 0x227e}, + {0x81fd, 0}, {0x9ffc, 0x5e7e}, {0x9ffd, 0}, + {0xa040, 0}, {0xdffc, 0}, {0xe040, 0x5f21}, + {0xeffc, 0x7e7e}, {0xf040, 0}, {0x21, 0}, {0, 0}}; + int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS }; + unsigned int i, j; + int prev_cp = _getmbcp(); + + for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++) + { + _setmbcp(cp[i]); + for (j = 0; jmsjis[j][0] != 0; j++) + { + unsigned int ret, exp; + ret = _mbcjmstojis(jmsjis[j][0]); + exp = (cp[i] == 932) ? jmsjis[j][1] : jmsjis[j][0]; + ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage=%d)\n", + exp, ret, jmsjis[j][0], cp[i]); + } + } + _setmbcp(prev_cp); +} + +static void test_mbbtombc(void) +{ + static const unsigned int mbbmbc[][2] = { + {0x1f, 0x1f}, {0x20, 0x8140}, {0x39, 0x8258}, {0x40, 0x8197}, + {0x41, 0x8260}, {0x5e, 0x814f}, {0x7e, 0x8150}, {0x7f, 0x7f}, + {0x80, 0x80}, {0x81, 0x81}, {0xa0, 0xa0}, {0xa7, 0x8340}, + {0xb0, 0x815b}, {0xd1, 0x8380}, {0xff, 0xff}, {0,0}}; + int cp[] = { 932, 936, 939, 950, 1361, _MB_CP_SBCS }; + int i, j; + int prev_cp = _getmbcp(); + + for (i = 0; i < sizeof(cp)/sizeof(cp[0]); i++) + { + _setmbcp(cp[i]); + for (j = 0; mbbmbc[j][0] != 0; j++) + { + unsigned int exp, ret; + ret = _mbbtombc(mbbmbc[j][0]); + exp = (cp[i] == 932) ? mbbmbc[j][1] : mbbmbc[j][0]; + ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n", + exp, ret, mbbmbc[j][0], cp[i]); + } + } + _setmbcp(prev_cp); } static void test_mbctombb(void) @@ -1586,7 +1804,7 @@ ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")), - "Expected the output buffer to be \"gorrIsTeR\"\n"); + "Expected the output buffer to be \"\\0oRrIsTeR\"\n"); strcpy(buffer, "GoRrIsTeR"); errno = EBADF; @@ -1594,7 +1812,7 @@ ok(ret == EINVAL, "Expected _strlwr_s to return EINVAL, got %d\n", ret); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); ok(!memcmp(buffer, "\0oRrIsTeR", sizeof("\0oRrIsTeR")), - "Expected the output buffer to be \"gorrIsTeR\"\n"); + "Expected the output buffer to be \"\\0oRrIsTeR\"\n"); strcpy(buffer, "GoRrIsTeR"); ret = p_strlwr_s(buffer, sizeof("GoRrIsTeR")); @@ -2005,6 +2223,9 @@ ret = p_wctob(0x81); ok(ret == (int)(char)0x81, "ret = %x\n", ret); + ret = p_wctob(0x9f); + ok(ret == (int)(char)0x9f, "ret = %x\n", ret); + ret = p_wctob(0xe0); ok(ret == (int)(char)0xe0, "ret = %x\n", ret); } @@ -2055,6 +2276,8 @@ hMsvcrt = GetModuleHandleA("msvcrtd.dll"); ok(hMsvcrt != 0, "GetModuleHandleA failed\n"); SET(pmemcpy,"memcpy"); + p_memcpy_s = (void*)GetProcAddress( hMsvcrt, "memcpy_s" ); + p_memmove_s = (void*)GetProcAddress( hMsvcrt, "memmove_s" ); SET(pmemcmp,"memcmp"); SET(p_mbctype,"_mbctype"); SET(p__mb_cur_max,"__mb_cur_max"); @@ -2102,9 +2325,13 @@ /* test _strdup */ test_strdup(); test_strcpy_s(); + test_memcpy_s(); + test_memmove_s(); test_strcat_s(); test__mbsnbcpy_s(); test_mbcjisjms(); + test_mbcjmsjis(); + test_mbbtombc(); test_mbctombb(); test_ismbclegal(); test_strtok(); Modified: trunk/rostests/winetests/msvcrt/time.c URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/winetests/msvcrt/time.c?r…
============================================================================== --- trunk/rostests/winetests/msvcrt/time.c [iso-8859-1] (original) +++ trunk/rostests/winetests/msvcrt/time.c [iso-8859-1] Sat Sep 29 14:28:48 2012 @@ -25,6 +25,7 @@ #include <stdlib.h> /*setenv*/ #include <stdio.h> /*printf*/ +#include <locale.h> #include <errno.h> #define _MAX__TIME64_T (((__time64_t)0x00000007 << 32) | 0x93406FFF) @@ -37,6 +38,7 @@ static __time32_t (__cdecl *p_mkgmtime32)(struct tm*); static struct tm* (__cdecl *p_gmtime32)(__time32_t*); +static struct tm* (__cdecl *p_gmtime)(time_t*); static errno_t (__cdecl *p_gmtime32_s)(struct tm*, __time32_t*); static errno_t (__cdecl *p_strtime_s)(char*,size_t); static errno_t (__cdecl *p_strdate_s)(char*,size_t); @@ -44,12 +46,16 @@ static errno_t (__cdecl *p_localtime64_s)(struct tm*, __time64_t*); static int* (__cdecl *p__daylight)(void); static int* (__cdecl *p___p__daylight)(void); +static size_t (__cdecl *p_strftime)(char *, size_t, const char *, const struct tm *); +static size_t (__cdecl *p_wcsftime)(wchar_t *, size_t, const wchar_t *, const struct tm *); +static char* (__cdecl *p_asctime)(const struct tm *); static void init(void) { - HMODULE hmod = GetModuleHandleA("msvcrt.dll"); + HMODULE hmod = LoadLibrary("msvcrt.dll"); p_gmtime32 = (void*)GetProcAddress(hmod, "_gmtime32"); + p_gmtime = (void*)GetProcAddress(hmod, "gmtime"); p_gmtime32_s = (void*)GetProcAddress(hmod, "_gmtime32_s"); p_mkgmtime32 = (void*)GetProcAddress(hmod, "_mkgmtime32"); p_strtime_s = (void*)GetProcAddress(hmod, "_strtime_s"); @@ -58,6 +64,9 @@ p_localtime64_s = (void*)GetProcAddress(hmod, "_localtime64_s"); p__daylight = (void*)GetProcAddress(hmod, "__daylight"); p___p__daylight = (void*)GetProcAddress(hmod, "__p__daylight"); + p_strftime = (void*)GetProcAddress(hmod, "strftime"); + p_wcsftime = (void*)GetProcAddress(hmod, "wcsftime"); + p_asctime = (void*)GetProcAddress(hmod, "asctime"); } static int get_test_year(time_t *start) @@ -568,10 +577,238 @@ ok(ret1 && ret1 == ret2, "got %p\n", ret1); } +static void test_strftime(void) +{ + static const wchar_t cW[] = { '%','c',0 }; + static const char expected[] = "01/01/70 00:00:00"; + time_t gmt; + struct tm* gmt_tm; + char buf[256], bufA[256]; + WCHAR bufW[256]; + long retA, retW; + + if (!p_strftime || !p_wcsftime || !p_gmtime) + { + win_skip("strftime, wcsftime or gmtime is not available\n"); + return; + } + + setlocale(LC_TIME, "C"); + + gmt = 0; + gmt_tm = p_gmtime(&gmt); + ok(gmt_tm != NULL, "gmtime failed\n"); + + errno = 0xdeadbeef; + retA = strftime(NULL, 0, "copy", gmt_tm); + ok(retA == 0, "expected 0, got %ld\n", retA); + ok(errno==EINVAL || broken(errno==0xdeadbeef), "errno = %d\n", errno); + + retA = strftime(bufA, 256, "copy", NULL); + ok(retA == 4, "expected 4, got %ld\n", retA); + ok(!strcmp(bufA, "copy"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "copy it", gmt_tm); + ok(retA == 7, "expected 7, got %ld\n", retA); + ok(!strcmp(bufA, "copy it"), "got %s\n", bufA); + + errno = 0xdeadbeef; + retA = strftime(bufA, 2, "copy", gmt_tm); + ok(retA == 0, "expected 0, got %ld\n", retA); + ok(!strcmp(bufA, "") || broken(!strcmp(bufA, "copy it")), "got %s\n", bufA); + ok(errno==ERANGE || errno==0xdeadbeef, "errno = %d\n", errno); + + errno = 0xdeadbeef; + retA = strftime(bufA, 256, "a%e", gmt_tm); + ok(retA==0 || broken(retA==1), "expected 0, got %ld\n", retA); + ok(!strcmp(bufA, "") || broken(!strcmp(bufA, "a")), "got %s\n", bufA); + ok(errno==EINVAL || broken(errno==0xdeadbeef), "errno = %d\n", errno); + + if(0) { /* crashes on Win2k */ + errno = 0xdeadbeef; + retA = strftime(bufA, 256, "%c", NULL); + ok(retA == 0, "expected 0, got %ld\n", retA); + ok(!strcmp(bufA, ""), "got %s\n", bufA); + ok(errno == EINVAL, "errno = %d\n", errno); + } + + retA = strftime(bufA, 256, "e%#%e", gmt_tm); + ok(retA == 3, "expected 3, got %ld\n", retA); + ok(!strcmp(bufA, "e%e"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%c", gmt_tm); + ok(retA == 17, "expected 17, got %ld\n", retA); + ok(strcmp(bufA, expected) == 0, "expected %s, got %s\n", expected, bufA); + + retW = wcsftime(bufW, 256, cW, gmt_tm); + ok(retW == 17, "expected 17, got %ld\n", retW); + ok(retA == retW, "expected %ld, got %ld\n", retA, retW); + buf[0] = 0; + retA = WideCharToMultiByte(CP_ACP, 0, bufW, retW, buf, 256, NULL, NULL); + buf[retA] = 0; + ok(strcmp(bufA, buf) == 0, "expected %s, got %s\n", bufA, buf); + + retA = strftime(bufA, 256, "%x", gmt_tm); + ok(retA == 8, "expected 8, got %ld\n", retA); + ok(!strcmp(bufA, "01/01/70"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%X", gmt_tm); + ok(retA == 8, "expected 8, got %ld\n", retA); + ok(!strcmp(bufA, "00:00:00"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%a", gmt_tm); + ok(retA == 3, "expected 3, got %ld\n", retA); + ok(!strcmp(bufA, "Thu"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%A", gmt_tm); + ok(retA == 8, "expected 8, got %ld\n", retA); + ok(!strcmp(bufA, "Thursday"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%b", gmt_tm); + ok(retA == 3, "expected 3, got %ld\n", retA); + ok(!strcmp(bufA, "Jan"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%B", gmt_tm); + ok(retA == 7, "expected 7, got %ld\n", retA); + ok(!strcmp(bufA, "January"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%d", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "01"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%#d", gmt_tm); + ok(retA == 1, "expected 1, got %ld\n", retA); + ok(!strcmp(bufA, "1"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%H", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "00"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%I", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "12"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%j", gmt_tm); + ok(retA == 3, "expected 3, got %ld\n", retA); + ok(!strcmp(bufA, "001"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%m", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "01"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%#M", gmt_tm); + ok(retA == 1, "expected 1, got %ld\n", retA); + ok(!strcmp(bufA, "0"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%p", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "AM"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%U", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "00"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%W", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "00"), "got %s\n", bufA); + + gmt_tm->tm_wday = 0; + retA = strftime(bufA, 256, "%U", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "01"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%W", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "00"), "got %s\n", bufA); + + gmt_tm->tm_yday = 365; + retA = strftime(bufA, 256, "%U", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "53"), "got %s\n", bufA); + + retA = strftime(bufA, 256, "%W", gmt_tm); + ok(retA == 2, "expected 2, got %ld\n", retA); + ok(!strcmp(bufA, "52"), "got %s\n", bufA); + + gmt_tm->tm_mon = 1; + gmt_tm->tm_mday = 30; + retA = strftime(bufA, 256, "%c", gmt_tm); + todo_wine { + ok(retA == 17, "expected 17, got %ld\n", retA); + ok(!strcmp(bufA, "02/30/70 00:00:00"), "got %s\n", bufA); + } +} + +static void test_asctime(void) +{ + struct tm* gmt_tm; + time_t gmt; + char *ret; + + if(!p_asctime || !p_gmtime) + { + win_skip("asctime or gmtime is not available\n"); + return; + } + + gmt = 0; + gmt_tm = p_gmtime(&gmt); + ret = p_asctime(gmt_tm); + ok(!strcmp(ret, "Thu Jan 01 00:00:00 1970\n"), "asctime retunred %s\n", ret); + + gmt = 312433121; + gmt_tm = p_gmtime(&gmt); + ret = p_asctime(gmt_tm); + ok(!strcmp(ret, "Mon Nov 26 02:58:41 1979\n"), "asctime retunred %s\n", ret); + + /* Week day is only checked if it's in 0..6 range */ + gmt_tm->tm_wday = 3; + ret = p_asctime(gmt_tm); + ok(!strcmp(ret, "Wed Nov 26 02:58:41 1979\n"), "asctime returned %s\n", ret); + + errno = 0xdeadbeef; + gmt_tm->tm_wday = 7; + ret = p_asctime(gmt_tm); + ok(!ret || broken(!ret[0]), "asctime returned %s\n", ret); + ok(errno==EINVAL || broken(errno==0xdeadbeef), "errno = %d\n", errno); + + /* Year day is ignored */ + gmt_tm->tm_wday = 3; + gmt_tm->tm_yday = 1300; + ret = p_asctime(gmt_tm); + ok(!strcmp(ret, "Wed Nov 26 02:58:41 1979\n"), "asctime returned %s\n", ret); + + /* Dates that can't be displayed using 26 characters are broken */ + gmt_tm->tm_mday = 28; + gmt_tm->tm_year = 8100; + ret = p_asctime(gmt_tm); + ok(!strcmp(ret, "Wed Nov 28 02:58:41 :000\n"), "asctime returned %s\n", ret); + + gmt_tm->tm_year = 264100; + ret = p_asctime(gmt_tm); + ok(!strcmp(ret, "Wed Nov 28 02:58:41 :000\n"), "asctime returned %s\n", ret); + + /* asctime works from year 1900 */ + errno = 0xdeadbeef; + gmt_tm->tm_year = -1; + ret = p_asctime(gmt_tm); + ok(!ret || broken(!strcmp(ret, "Wed Nov 28 02:58:41 190/\n")), "asctime returned %s\n", ret); + ok(errno==EINVAL || broken(errno == 0xdeadbeef), "errno = %d\n", errno); + + errno = 0xdeadbeef; + gmt_tm->tm_mon = 1; + gmt_tm->tm_mday = 30; + gmt_tm->tm_year = 79; + ret = p_asctime(gmt_tm); + ok(!ret || broken(!strcmp(ret, "Wed Feb 30 02:58:41 1979\n")), "asctime returned %s\n", ret); + ok(errno==EINVAL || broken(errno==0xdeadbeef), "errno = %d\n", errno); +} + START_TEST(time) { init(); + test_strftime(); test_ctime(); test_gmtime(); test_mktime(); @@ -583,4 +820,5 @@ test_localtime32_s(); test_localtime64_s(); test_daylight(); -} + test_asctime(); +}
12 years, 2 months
1
0
0
0
[tkreuzer] 57431: [RSYM_CMAKE] Improve formatting, no code change
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sat Sep 29 14:13:16 2012 New Revision: 57431 URL:
http://svn.reactos.org/svn/reactos?rev=57431&view=rev
Log: [RSYM_CMAKE] Improve formatting, no code change Modified: trunk/reactos/tools/rsym/rsym.cmake.c Modified: trunk/reactos/tools/rsym/rsym.cmake.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rsym/rsym.cmake.c?re…
============================================================================== --- trunk/reactos/tools/rsym/rsym.cmake.c [iso-8859-1] (original) +++ trunk/reactos/tools/rsym/rsym.cmake.c [iso-8859-1] Sat Sep 29 14:13:16 2012 @@ -29,88 +29,91 @@ int main(int argc, char* argv[]) { - int i; - PSYMBOLFILE_HEADER SymbolFileHeader; - PIMAGE_DOS_HEADER PEDosHeader; - PIMAGE_FILE_HEADER PEFileHeader; - PIMAGE_OPTIONAL_HEADER PEOptHeader; - PIMAGE_SECTION_HEADER PESectionHeaders; - char* path1; - char* path2; - FILE* out; - size_t FileSize; - void *FileData; - char elfhdr[] = { '\377', 'E', 'L', 'F' }; + int i; + PSYMBOLFILE_HEADER SymbolFileHeader; + PIMAGE_DOS_HEADER PEDosHeader; + PIMAGE_FILE_HEADER PEFileHeader; + PIMAGE_OPTIONAL_HEADER PEOptHeader; + PIMAGE_SECTION_HEADER PESectionHeaders; + char* path1; + char* path2; + FILE* out; + size_t FileSize; + void *FileData; + char elfhdr[] = { '\377', 'E', 'L', 'F' }; - if (3 != argc) + if (3 != argc) { - fprintf(stderr, "Usage: rsym <exefile> <symfile>\n"); - exit(1); + fprintf(stderr, "Usage: rsym <exefile> <symfile>\n"); + exit(1); } - path1 = convert_path(argv[1]); - path2 = convert_path(argv[2]); + path1 = convert_path(argv[1]); + path2 = convert_path(argv[2]); - FileData = load_file ( path1, &FileSize ); - if ( !FileData ) - { - fprintf ( stderr, "An error occured loading '%s'\n", path1 ); - exit(1); - } - - /* Check if MZ header exists */ - PEDosHeader = (PIMAGE_DOS_HEADER) FileData; - if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC || PEDosHeader->e_lfanew == 0L) + FileData = load_file(path1, &FileSize ); + if ( !FileData ) { - /* Ignore elf */ - if (!memcmp(PEDosHeader, elfhdr, sizeof(elfhdr))) - exit(0); - perror("Input file is not a PE image.\n"); - free(FileData); - exit(1); + fprintf ( stderr, "An error occured loading '%s'\n", path1 ); + exit(1); } - /* Locate PE file header */ - /* sizeof(ULONG) = sizeof(MAGIC) */ - PEFileHeader = (PIMAGE_FILE_HEADER)((char *) FileData + PEDosHeader->e_lfanew + sizeof(ULONG)); - - /* Locate optional header */ - assert(sizeof(ULONG) == 4); - PEOptHeader = (PIMAGE_OPTIONAL_HEADER)(PEFileHeader + 1); - - /* Locate PE section headers */ - PESectionHeaders = (PIMAGE_SECTION_HEADER)((char *) PEOptHeader + PEFileHeader->SizeOfOptionalHeader); - - for (i = 0; i < PEFileHeader->NumberOfSections; i++) { - if (PESectionHeaders[i].Name[0] == '/') { - PESectionHeaders[i].Characteristics |= IMAGE_SCN_CNT_INITIALIZED_DATA; - PESectionHeaders[i].Characteristics &= ~(IMAGE_SCN_MEM_PURGEABLE | IMAGE_SCN_MEM_DISCARDABLE); - } - } - - PESectionHeaders[PEFileHeader->NumberOfSections-1].SizeOfRawData = - FileSize - PESectionHeaders[PEFileHeader->NumberOfSections-1].PointerToRawData; - if (PESectionHeaders[PEFileHeader->NumberOfSections-1].SizeOfRawData > - PESectionHeaders[PEFileHeader->NumberOfSections-1].Misc.VirtualSize) { - PESectionHeaders[PEFileHeader->NumberOfSections-1].Misc.VirtualSize = - ROUND_UP(PESectionHeaders[PEFileHeader->NumberOfSections-1].SizeOfRawData, - PEOptHeader->SectionAlignment); - PEOptHeader->SizeOfImage = PESectionHeaders[PEFileHeader->NumberOfSections-1].VirtualAddress + PESectionHeaders[PEFileHeader->NumberOfSections-1].Misc.VirtualSize; - } - - out = fopen(path2, "wb"); - if (out == NULL) + /* Check if MZ header exists */ + PEDosHeader = (PIMAGE_DOS_HEADER)FileData; + if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC || PEDosHeader->e_lfanew == 0L) { - perror("Cannot open output file"); - free(FileData); - exit(1); + /* Ignore elf */ + if (!memcmp(PEDosHeader, elfhdr, sizeof(elfhdr))) + exit(0); + perror("Input file is not a PE image.\n"); + free(FileData); + exit(1); } - fwrite(FileData, 1, FileSize, out); - fclose(out); - free(FileData); + /* Locate PE file header */ + /* sizeof(ULONG) = sizeof(MAGIC) */ + PEFileHeader = (PIMAGE_FILE_HEADER)((char *) FileData + PEDosHeader->e_lfanew + sizeof(ULONG)); - return 0; + /* Locate optional header */ + assert(sizeof(ULONG) == 4); + PEOptHeader = (PIMAGE_OPTIONAL_HEADER)(PEFileHeader + 1); + + /* Locate PE section headers */ + PESectionHeaders = (PIMAGE_SECTION_HEADER)((char *) PEOptHeader + PEFileHeader->SizeOfOptionalHeader); + + for (i = 0; i < PEFileHeader->NumberOfSections; i++) + { + if (PESectionHeaders[i].Name[0] == '/') + { + PESectionHeaders[i].Characteristics |= IMAGE_SCN_CNT_INITIALIZED_DATA; + PESectionHeaders[i].Characteristics &= ~(IMAGE_SCN_MEM_PURGEABLE | IMAGE_SCN_MEM_DISCARDABLE); + } + } + + PESectionHeaders[PEFileHeader->NumberOfSections-1].SizeOfRawData = + FileSize - PESectionHeaders[PEFileHeader->NumberOfSections-1].PointerToRawData; + if (PESectionHeaders[PEFileHeader->NumberOfSections-1].SizeOfRawData > + PESectionHeaders[PEFileHeader->NumberOfSections-1].Misc.VirtualSize) + { + PESectionHeaders[PEFileHeader->NumberOfSections-1].Misc.VirtualSize = + ROUND_UP(PESectionHeaders[PEFileHeader->NumberOfSections-1].SizeOfRawData, + PEOptHeader->SectionAlignment); + PEOptHeader->SizeOfImage = PESectionHeaders[PEFileHeader->NumberOfSections-1].VirtualAddress + PESectionHeaders[PEFileHeader->NumberOfSections-1].Misc.VirtualSize; + } + + out = fopen(path2, "wb"); + if (out == NULL) + { + perror("Cannot open output file"); + free(FileData); + exit(1); + } + + fwrite(FileData, 1, FileSize, out); + fclose(out); + free(FileData); + + return 0; } /* EOF */
12 years, 2 months
1
0
0
0
[akhaldi] 57430: * Shell32 (a forked module) was jealous because of shlwapi getting synced.
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Sep 29 13:27:13 2012 New Revision: 57430 URL:
http://svn.reactos.org/svn/reactos?rev=57430&view=rev
Log: * Shell32 (a forked module) was jealous because of shlwapi getting synced. Modified: trunk/reactos/dll/win32/shell32/undocshell.h Modified: trunk/reactos/dll/win32/shell32/undocshell.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/undocshe…
============================================================================== --- trunk/reactos/dll/win32/shell32/undocshell.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/shell32/undocshell.h [iso-8859-1] Sat Sep 29 13:27:13 2012 @@ -135,6 +135,30 @@ DWORD dwType); /**************************************************************************** + * Memory Routines + */ + +/* The Platform SDK's shlobj.h header defines similar functions with a + * leading underscore. However those are unusable because of the leading + * underscore, because they have an incorrect calling convention, and + * because these functions are not exported by name anyway. + */ +HANDLE WINAPI SHAllocShared( + LPVOID pv, + ULONG cb, + DWORD pid); + +BOOL WINAPI SHFreeShared( + HANDLE hMem, + DWORD pid); + +LPVOID WINAPI SHLockShared( + HANDLE hMem, + DWORD pid); + +BOOL WINAPI SHUnlockShared(LPVOID pv); + +/**************************************************************************** * Cabinet Window Messages */
12 years, 2 months
1
0
0
0
[tkreuzer] 57429: [NTOSKRNL] - Allocate a capture buffer outside of SEH in NtAddAtom and NtRaiseHardError - Call ExpGetCurrentUserUILanguage outside of SEH in NtQueryDefaultUILanguage and return th...
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sat Sep 29 13:22:31 2012 New Revision: 57429 URL:
http://svn.reactos.org/svn/reactos?rev=57429&view=rev
Log: [NTOSKRNL] - Allocate a capture buffer outside of SEH in NtAddAtom and NtRaiseHardError - Call ExpGetCurrentUserUILanguage outside of SEH in NtQueryDefaultUILanguage and return the actual result instead of returning PsInstallUILanguageId in case of success. - Don't allocate a unicode string inside SEH in NtQuerySystemEnvironmentValue, instead use RtlAnsiStringToUnicodeString directly on the callers buffer. CORE-6624 Modified: trunk/reactos/ntoskrnl/ex/atom.c trunk/reactos/ntoskrnl/ex/harderr.c trunk/reactos/ntoskrnl/ex/locale.c trunk/reactos/ntoskrnl/ex/sysinfo.c Modified: trunk/reactos/ntoskrnl/ex/atom.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/atom.c?rev=574…
============================================================================== --- trunk/reactos/ntoskrnl/ex/atom.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ex/atom.c [iso-8859-1] Sat Sep 29 13:22:31 2012 @@ -107,50 +107,56 @@ DPRINT1("Atom name too long\n"); return STATUS_INVALID_PARAMETER; } - - /* Re-use the given name if kernel mode or no atom name */ - CapturedName = AtomName; - - /* Check if we're called from user-mode*/ - if (PreviousMode != KernelMode) - { - /* Enter SEH */ - _SEH2_TRY - { - /* Check if we have a name */ - if (AtomName) + + /* Check if we're called from user-mode or kernel-mode */ + if (PreviousMode == KernelMode) + { + /* Re-use the given name if kernel mode */ + CapturedName = AtomName; + } + else + { + /* Check if we have a name */ + if (AtomName) + { + /* Allocate an aligned buffer + the null char */ + CapturedSize = ((AtomNameLength + sizeof(WCHAR)) & + ~(sizeof(WCHAR) -1)); + CapturedName = ExAllocatePoolWithTag(PagedPool, + CapturedSize, + TAG_ATOM); + + if (!CapturedName) + { + /* Fail the call */ + return STATUS_INSUFFICIENT_RESOURCES; + } + + /* Enter SEH */ + _SEH2_TRY { /* Probe the atom */ ProbeForRead(AtomName, AtomNameLength, sizeof(WCHAR)); - /* Allocate an aligned buffer + the null char */ - CapturedSize = ((AtomNameLength + sizeof(WCHAR)) &~ - (sizeof(WCHAR) -1)); - CapturedName = ExAllocatePoolWithTag(PagedPool, - CapturedSize, - TAG_ATOM); - if (!CapturedName) - { - /* Fail the call */ - Status = STATUS_INSUFFICIENT_RESOURCES; - } - else - { - /* Copy the name and null-terminate it */ - RtlCopyMemory(CapturedName, AtomName, AtomNameLength); - CapturedName[AtomNameLength / sizeof(WCHAR)] = UNICODE_NULL; - } + /* Copy the name and null-terminate it */ + RtlCopyMemory(CapturedName, AtomName, AtomNameLength); + CapturedName[AtomNameLength / sizeof(WCHAR)] = UNICODE_NULL; /* Probe the atom too */ if (Atom) ProbeForWriteUshort(Atom); } - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - /* Return the exception code */ - _SEH2_YIELD(return _SEH2_GetExceptionCode()); - } - _SEH2_END; + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + /* Return the exception code */ + _SEH2_YIELD(return _SEH2_GetExceptionCode()); + } + _SEH2_END; + } + else + { + /* No name */ + CapturedName = NULL; + } } /* Call the runtime function */ @@ -172,7 +178,7 @@ } /* If we captured anything, free it */ - if ((CapturedName) && (CapturedName != AtomName)) + if ((CapturedName != NULL) && (CapturedName != AtomName)) ExFreePoolWithTag(CapturedName, TAG_ATOM); /* Return to caller */ @@ -258,7 +264,7 @@ DPRINT1("Atom name too long\n"); return STATUS_INVALID_PARAMETER; } - + /* Re-use the given name if kernel mode or no atom name */ CapturedName = AtomName; Modified: trunk/reactos/ntoskrnl/ex/harderr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/harderr.c?rev=…
============================================================================== --- trunk/reactos/ntoskrnl/ex/harderr.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ex/harderr.c [iso-8859-1] Sat Sep 29 13:22:31 2012 @@ -523,7 +523,7 @@ ULONG SafeResponse; UNICODE_STRING SafeString; ULONG i; - ULONG ParamSize; + ULONG ParamSize = 0; KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); /* Validate parameter count */ @@ -534,7 +534,7 @@ } /* Make sure we have some at least */ - if ((Parameters) && !(NumberOfParameters)) + if ((Parameters != NULL) && (NumberOfParameters == 0)) { /* Fail */ return STATUS_INVALID_PARAMETER_2; @@ -561,6 +561,20 @@ return STATUS_INVALID_PARAMETER_4; } + /* Check if we have parameters */ + if (Parameters) + { + /* Calculate size of the parameters */ + ParamSize = sizeof(ULONG_PTR) * NumberOfParameters; + + /* Allocate a safe buffer */ + SafeParams = ExAllocatePoolWithTag(PagedPool, ParamSize, TAG_ERR); + if (!SafeParams) + { + return STATUS_INSUFFICIENT_RESOURCES; + } + } + /* Enter SEH Block */ _SEH2_TRY { @@ -571,13 +585,7 @@ if (Parameters) { /* Validate the parameter pointers */ - ParamSize = sizeof(ULONG_PTR) * NumberOfParameters; ProbeForRead(Parameters, ParamSize, sizeof(ULONG_PTR)); - - /* Allocate a safe buffer */ - SafeParams = ExAllocatePoolWithTag(PagedPool, - ParamSize, - TAG_ERR); /* Copy them */ RtlCopyMemory(SafeParams, Parameters, ParamSize); Modified: trunk/reactos/ntoskrnl/ex/locale.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/locale.c?rev=5…
============================================================================== --- trunk/reactos/ntoskrnl/ex/locale.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ex/locale.c [iso-8859-1] Sat Sep 29 13:22:31 2012 @@ -349,8 +349,12 @@ NTAPI NtQueryDefaultUILanguage(OUT LANGID* LanguageId) { - NTSTATUS Status = STATUS_SUCCESS; - PAGED_CODE(); + NTSTATUS Status; + LANGID SafeLanguageId; + PAGED_CODE(); + + /* Call the executive helper routine */ + Status = ExpGetCurrentUserUILanguage(L"MultiUILanguageId", &SafeLanguageId); /* Enter SEH for probing */ _SEH2_TRY @@ -362,11 +366,14 @@ ProbeForWriteLangid(LanguageId); } - /* Call the executive helper routine */ - Status = ExpGetCurrentUserUILanguage(L"MultiUILanguageId", LanguageId); if (NT_SUCCESS(Status)) { /* Success, return the language */ + *LanguageId = SafeLanguageId; + } + else + { + /* Failed, use fallback value */ *LanguageId = PsInstallUILanguageId; } } Modified: trunk/reactos/ntoskrnl/ex/sysinfo.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/sysinfo.c?rev=…
============================================================================== --- trunk/reactos/ntoskrnl/ex/sysinfo.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ex/sysinfo.c [iso-8859-1] Sat Sep 29 13:22:31 2012 @@ -211,27 +211,22 @@ ANSI_STRING AName; UNICODE_STRING WName; ARC_STATUS Result; - PCH Value; + PCH AnsiValueBuffer; ANSI_STRING AValue; UNICODE_STRING WValue; KPROCESSOR_MODE PreviousMode; NTSTATUS Status; PAGED_CODE(); + /* Check if the call came from user mode */ PreviousMode = ExGetPreviousMode(); - if (PreviousMode != KernelMode) { _SEH2_TRY { - ProbeForRead(VariableName, - sizeof(UNICODE_STRING), - sizeof(ULONG)); - - ProbeForWrite(ValueBuffer, - ValueBufferLength, - sizeof(WCHAR)); - + /* Probe the input and output buffers */ + ProbeForRead(VariableName, sizeof(UNICODE_STRING), sizeof(ULONG)); + ProbeForWrite(ValueBuffer, ValueBufferLength, sizeof(WCHAR)); if (ReturnLength != NULL) ProbeForWriteUlong(ReturnLength); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) @@ -240,102 +235,79 @@ _SEH2_YIELD(return _SEH2_GetExceptionCode()); } _SEH2_END; + + } + + /* Allocate a buffer for the value */ + AnsiValueBuffer = ExAllocatePoolWithTag(NonPagedPool, ValueBufferLength, 'pmeT'); + if (AnsiValueBuffer == NULL) + { + return STATUS_INSUFFICIENT_RESOURCES; } /* * Copy the name to kernel space if necessary and convert it to ANSI. */ - Status = ProbeAndCaptureUnicodeString(&WName, - PreviousMode, - VariableName); - if (NT_SUCCESS(Status)) - { - /* - * according to ntinternals the SeSystemEnvironmentName privilege is required! - */ - if (!SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege, - PreviousMode)) - { - ReleaseCapturedUnicodeString(&WName, PreviousMode); - DPRINT1("NtQuerySystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n"); - return STATUS_PRIVILEGE_NOT_HELD; - } - - /* - * convert the value name to ansi - */ - Status = RtlUnicodeStringToAnsiString(&AName, &WName, TRUE); + Status = ProbeAndCaptureUnicodeString(&WName, PreviousMode, VariableName); + if (!NT_SUCCESS(Status)) + { + return Status; + } + + /* + * according to ntinternals the SeSystemEnvironmentName privilege is required! + */ + if (!SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege, PreviousMode)) + { ReleaseCapturedUnicodeString(&WName, PreviousMode); - - if (!NT_SUCCESS(Status)) return Status; - - /* - * Create a temporary buffer for the value - */ - Value = ExAllocatePool(NonPagedPool, ValueBufferLength); - if (Value == NULL) - { - RtlFreeAnsiString(&AName); - return STATUS_INSUFFICIENT_RESOURCES; - } - - /* - * Get the environment variable - */ - Result = HalGetEnvironmentVariable(AName.Buffer, - (USHORT)ValueBufferLength, - Value); - if (!Result) - { - RtlFreeAnsiString(&AName); - ExFreePool(Value); - return STATUS_UNSUCCESSFUL; - } - - /* - * Convert the result to UNICODE, protect with SEH in case the value buffer - * isn't NULL-terminated! - */ + DPRINT1("NtQuerySystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n"); + return STATUS_PRIVILEGE_NOT_HELD; + } + + /* Convert the value name to ansi and release the captured unicode string */ + Status = RtlUnicodeStringToAnsiString(&AName, &WName, TRUE); + ReleaseCapturedUnicodeString(&WName, PreviousMode); + if (!NT_SUCCESS(Status)) return Status; + + /* Get the environment variable */ + Result = HalGetEnvironmentVariable(AName.Buffer, + (USHORT)ValueBufferLength, + AnsiValueBuffer); + + /* Check if we had success */ + if (Result == ESUCCESS) + { + /* Copy the result back to the caller. */ _SEH2_TRY { - RtlInitAnsiString(&AValue, Value); - Status = RtlAnsiStringToUnicodeString(&WValue, &AValue, TRUE); + /* Initialize ansi string from the result */ + RtlInitAnsiString(&AValue, AnsiValueBuffer); + + /* Initialize a unicode string from the callers buffer */ + RtlInitEmptyUnicodeString(&WValue, ValueBuffer, ValueBufferLength); + + /* Convert the result to unicode */ + Status = RtlAnsiStringToUnicodeString(&WValue, &AValue, FALSE); + + if (ReturnLength != NULL) + { + *ReturnLength = WValue.Length; + } } _SEH2_EXCEPT(ExSystemExceptionFilter()) { Status = _SEH2_GetExceptionCode(); } _SEH2_END; - - if (NT_SUCCESS(Status)) - { - /* - * Copy the result back to the caller. - */ - _SEH2_TRY - { - RtlCopyMemory(ValueBuffer, WValue.Buffer, WValue.Length); - ValueBuffer[WValue.Length / sizeof(WCHAR)] = L'\0'; - if (ReturnLength != NULL) - { - *ReturnLength = WValue.Length + sizeof(WCHAR); - } - - Status = STATUS_SUCCESS; - } - _SEH2_EXCEPT(ExSystemExceptionFilter()) - { - Status = _SEH2_GetExceptionCode(); - } - _SEH2_END; - } - - /* - * Cleanup allocated resources. - */ - RtlFreeAnsiString(&AName); - ExFreePool(Value); - } + } + else + { + Status = STATUS_UNSUCCESSFUL; + } + + /* Cleanup allocated resources. */ + RtlFreeAnsiString(&AName); + ExFreePoolWithTag(AnsiValueBuffer, 'pmeT'); return Status; } @@ -466,7 +438,7 @@ OUT PULONG NonPagedPoolAllocs, OUT PULONG NonPagedPoolFrees, OUT PULONG NonPagedPoolLookasideHits); - + /* Class 0 - Basic Information */ QSI_DEF(SystemBasicInformation) { @@ -741,7 +713,7 @@ do { SpiCurrent = (PSYSTEM_PROCESS_INFORMATION) Current; - + if ((Process->ProcessExiting) && (Process->Pcb.Header.SignalState) && !(Process->ActiveThreads) && @@ -1801,9 +1773,9 @@ ULONG SessionId; KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(); NTSTATUS Status; - + if (Size != sizeof(ULONG)) return STATUS_INFO_LENGTH_MISMATCH; - + if (PreviousMode != KernelMode) { if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, PreviousMode)) @@ -1811,7 +1783,7 @@ return STATUS_PRIVILEGE_NOT_HELD; } } - + Status = MmSessionCreate(&SessionId); if (NT_SUCCESS(Status)) *(PULONG)Buffer = SessionId; @@ -1824,9 +1796,9 @@ { ULONG SessionId; KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(); - + if (Size != sizeof(ULONG)) return STATUS_INFO_LENGTH_MISMATCH; - + if (PreviousMode != KernelMode) { if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, PreviousMode)) @@ -1834,9 +1806,9 @@ return STATUS_PRIVILEGE_NOT_HELD; } } - + SessionId = *(PULONG)Buffer; - + return MmSessionDelete(SessionId); }
12 years, 2 months
1
0
0
0
← Newer
1
2
3
4
5
...
24
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Results per page:
10
25
50
100
200