# HG changeset patch # User hgs # Date 1287412270 -3600 # Node ID 206a6eaaeb712b02fe3c110761a2d7421c127941 # Parent 55a0a1279a7ed9c6817d507daab30027f218c797 201041_05 diff -r 55a0a1279a7e -r 206a6eaaeb71 bsptemplate/asspandvariant/template_assp/iic/iic_slave.cpp --- a/bsptemplate/asspandvariant/template_assp/iic/iic_slave.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/bsptemplate/asspandvariant/template_assp/iic/iic_slave.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -602,7 +602,7 @@ // while(AsspRegister::Read32(iChannelBase + KFifoLevelOffset) <= (KFifoMaxLevel - iWordSize) && // iTxData != iTxDataEnd) // For the template port, will just use a dummy variable (dummyFifoLvlChk )in place of the register read - TInt dummyFifoLvlChk = 0; + TInt dummyFifoLvlChk = 1; while((dummyFifoLvlChk) && // Replace this dummy variable with a read of the hardware (iTxData != iTxDataEnd)) { diff -r 55a0a1279a7e -r 206a6eaaeb71 halservices/hal/inc/hal_data.h --- a/halservices/hal/inc/hal_data.h Wed Oct 13 13:34:03 2010 +0100 +++ b/halservices/hal/inc/hal_data.h Mon Oct 18 15:31:10 2010 +0100 @@ -1025,7 +1025,7 @@ /** Maximum Number of Pointers supported by hardware/driver - Returns the maximum number of pointers for a multi-touch configuration (or KErrNotSupported or 0 or 1 for single-touch legacy configuration) + Returns the maximum number of pointers for a multipletouch configuration (or KErrNotSupported or 0 or 1 for single-touch legacy configuration) */ EPointerMaxPointers, diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/ARM EABI LICENCE.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kernel/eka/compsupp/ARM EABI LICENCE.txt Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,130 @@ +The Specimen Implementations of the Exception Handling Components of the ABI for the ARM(R) Architecture consists of copyright owned by ARM Limited and copyright owned by Nokia Corporation. Each is licensed to you separately by the respective copyright owner, on the terms set out in this file. + +1. LICENSE TO ARM COPYRIGHT + +IMPORTANT: THIS IS A LEGAL AGREEMENT ("LICENCE") BETWEEN YOU (AN INDIVIDUAL OR +SINGLE ENTITY WHO IS RECEIVING THIS SOURCE CODE DIRECTLY FROM ARM LIMITED) +("LICENSEE") AND ARM LIMITED ("ARM") FOR THE VERSION OF THE SOURCE CODE SUPPLIED +WITH THIS LICENCE ("SOURCE CODE"). THE SOURCE CODE IS A SPECIMEN IMPLEMENTATION OF +EXCEPTION HANDLING COMPONENTS COMPLYING WITH THE SPECIFICATION DEFINED IMMEDIATELY +BELOW. BY DOWNLOADING OR OTHERWISE USING THE SOURCE CODE, YOU AGREE TO BE BOUND BY +ALL OF THE TERMS OF THIS LICENCE. IF YOU DO NOT AGREE TO THIS, DO NOT DOWNLOAD OR +USE THE SOURCE CODE. + +“Specification” means, and is limited to, version 2 of the specification for the +Applications Binary Interface for the ARM Architecture published by ARM. +Notwithstanding the foregoing, Specification” shall not include (i) the +implementation of other published specifications referenced in this Specification; +(ii) any enabling technologies that may be necessary to make or use any product or +portion thereof that complies with this Specification, but are not themselves +expressly set forth in this Specification (e.g. compiler front ends, code +generators, back ends, libraries or other compiler, assembler or linker +technologies; validation or debug software or hardware; applications, operating +system or driver software; RISC architecture; processor microarchitecture); +(iii) maskworks and physical layouts of integrated circuit designs; or (iv) RTL or +other high level representations of integrated circuit designs. + +Use, copying or disclosure by the US Government is subject to the restrictions set +out in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software +clause at DFARS 252.227-7013 or subparagraphs (c)(1) and (2) of the Commercial +Computer Software - Restricted Rights at 48 C.F.R. 52.227-19, as applicable. + +The Source Code is owned by ARM or its licensors and is protected by copyright laws +and international copyright treaties as well as other intellectual property laws and +treaties. The Source Code is licensed not sold. + +1. Subject to the provisions of Clauses 2 and 3, ARM hereby grants to LICENSEE, +under any intellectual property that is (i) owned or freely licensable by ARM +without payment to unaffiliated third parties and (ii) either embodied in the Source +Code, or Necessary to copy or implement an applications binary interface compliant +with the Specification, a perpetual, non-exclusive, non-transferable, fully paid, +worldwide limited licence to use, copy, modify and sublicense this Source Code (in +source or object code form) solely for the purpose of developing, having developed, +manufacturing, having manufactured, offering to sell, selling, supplying or +otherwise distributing products which comply with the Specification, provided that +LICENSEE preserves all copyright notices included in the Source Code. All other +rights are reserved to ARM or its licensors. + +2. THIS SOURCE CODE IS PROVIDED "AS IS" WITH NO WARRANTIES EXPRESS, IMPLIED OR +STATUTORY, INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF SATISFACTORY QUALITY, +MERCHANTABILITY, NONINFRINGEMENT OR FITNESS FOR A PARTICULAR PURPOSE. THE SOURCE +CODE MAY INCLUDE ERRORS. ARM RESERVES THE RIGHT TO INCORPORATE MODIFICATIONS TO THE +SOURCE CODE IN LATER REVISIONS OF IT, AND TO MAKE IMPROVEMENTS OR CHANGES IN THE +SPECIFICATION OR THE PRODUCTS OR TECHNOLOGIES DESCRIBED THEREIN AT ANY TIME. + +3. This Licence shall immediately terminate and shall be unavailable to LICENSEE if +LICENSEE or any party affiliated to LICENSEE asserts any patents against ARM, ARM +affiliates, third parties who have a valid licence from ARM for the Specification or +the Source Code, or any customers or distributors of any of them based upon a claim +that a LICENSEE (or LICENSEE affiliate) patent is Necessary to implement the +Specification. In this Licence; (i) "affiliate" means any entity controlling, +controlled by or under common control with a party (in fact or in law, via voting +securities, management control or otherwise) and "affiliated" shall be construed +accordingly; (ii) "assert" means to allege infringement in legal or administrative +proceedings, or proceedings before any other competent trade, arbitral or +international authority; (iii) “Necessary” means with respect to any claims of any +patent, those claims which, without the appropriate permission of the patent owner, +will be infringed when implementing the Specification because no alternative, +commercially reasonable, non-infringing way of implementing the Specification is +known; and (iv) English law and the jurisdiction of the English courts shall apply +to all aspects of this Licence, its interpretation and enforcement. The total +liability of ARM and any of its suppliers and licensors under or in relation to this +Licence shall be limited to the greater of the amount actually paid by LICENSEE for +the Specification or US$10.00. The limitations, exclusions and disclaimers in this +Licence shall apply to the maximum extent allowed by applicable law. + + +ARM contract reference number LEC-ELA-00080-V2.0. + + +2. LICENSE TO NOKIA COPYRIGHT + +IMPORTANT: THIS IS A LEGAL AGREEMENT ("LICENCE") BETWEEN YOU (AN INDIVIDUAL OR +SINGLE ENTITY WHO IS RECEIVING THIS SOURCE CODE FROM NOKIA CORPORATION) +("LICENSEE") AND NOKIA CORPORATION ("NOKIA") FOR THE VERSION OF THE SOURCE CODE SUPPLIED WITH THIS LICENCE ("SOURCE CODE"). THE SOURCE CODE IS A SPECIMEN IMPLEMENTATION OF EXCEPTION HANDLING COMPONENTS COMPLYING WITH THE SPECIFICATION DEFINED IMMEDIATELY BELOW. BY DOWNLOADING OR OTHERWISE USING THE SOURCE CODE, YOU AGREE TO BE BOUND BY ALL OF THE TERMS OF THIS LICENCE. IF YOU DO NOT AGREE TO THIS, DO NOT DOWNLOAD OR USE THE SOURCE CODE. + +“Specification” means, and is limited to, version 2 of the specification for the +Applications Binary Interface for the ARM Architecture published by ARM LIMITED. +Notwithstanding the foregoing, Specification” shall not include (i) the +implementation of other published specifications referenced in this Specification; +(ii) any enabling technologies that may be necessary to make or use any product or +portion thereof that complies with this Specification, but are not themselves +expressly set forth in this Specification (e.g. compiler front ends, code +generators, back ends, libraries or other compiler, assembler or linker +technologies; validation or debug software or hardware; applications, operating +system or driver software; RISC architecture; processor microarchitecture); +(iii) maskworks and physical layouts of integrated circuit designs; or (iv) RTL or +other high level representations of integrated circuit designs. + +Use, copying or disclosure by the US Government is subject to the restrictions set +out in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software +clause at DFARS 252.227-7013 or subparagraphs (c)(1) and (2) of the Commercial +Computer Software - Restricted Rights at 48 C.F.R. 52.227-19, as applicable. + +The Source Code is owned by Nokia or its licensors and is protected by copyright laws +and international copyright treaties as well as other intellectual property laws and +treaties. The Source Code is licensed not sold. + +1. Subject to the provisions of Clauses 2 and 3, Nokia hereby grants to LICENSEE, +under any intellectual property that is (i) owned or freely licensable by Nokia +without payment to unaffiliated third parties and (ii) either embodied in the Source +Code, or Necessary to copy or implement an applications binary interface compliant +with the Specification, a perpetual, non-exclusive, non-transferable, fully paid, +worldwide limited licence to use, copy, modify and sublicense this Source Code (in +source or object code form) solely for the purpose of developing, having developed, +manufacturing, having manufactured, offering to sell, selling, supplying or +otherwise distributing products which comply with the Specification, provided that +LICENSEE preserves all copyright notices included in the Source Code. All other +rights are reserved to Nokia or its licensors. + +2. THIS SOURCE CODE IS PROVIDED "AS IS" WITH NO WARRANTIES EXPRESS, IMPLIED OR +STATUTORY, INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF SATISFACTORY QUALITY, +MERCHANTABILITY, NONINFRINGEMENT OR FITNESS FOR A PARTICULAR PURPOSE. THE SOURCE +CODE MAY INCLUDE ERRORS. ARM RESERVES THE RIGHT TO INCORPORATE MODIFICATIONS TO THE +SOURCE CODE IN LATER REVISIONS OF IT, AND TO MAKE IMPROVEMENTS OR CHANGES IN THE +SPECIFICATION OR THE PRODUCTS OR TECHNOLOGIES DESCRIBED THEREIN AT ANY TIME. + +3. English law and the jurisdiction of the English courts shall apply +to all aspects of this Licence, its interpretation and enforcement. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL NOKIA, ITS EMPLOYEES OR LICENSORS OR AFFILIATES BE LIABLE FOR ANY LOST PROFITS, REVENUE, SALES, DATA, OR COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, PROPERTY DAMAGE, PERSONAL INJURY, INTERRUPTION OF BUSINESS, LOSS OF BUSINESS INFORMATION, OR FOR ANY SPECIAL, DIRECT, INDIRECT, INCIDENTAL, ECONOMIC, COVER, PUNITIVE, OR CONSEQUENTIAL DAMAGES, HOWEVER CAUSED AND WHETHER ARISING UNDER CONTRACT, TORT, NEGLIGENCE, OR OTHER THEORY OF LIABILITY ARISING OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF NOKIA OR ITS LICENSORS OR AFFILIATES ARE ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME COUNTRIES/STATES/JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF LIABILITY, BUT MAY ALLOW LIABILITY TO BE LIMITED, IN SUCH CASES, NOKIA, ITS EMPLOYEES OR LICENSORS OR AFFILIATES' LIABILITY SHALL BE LIMITED TO U.S. $50. Nothing contained in this Agreement shall prejudice the statutory rights of any party dealing as a consumer. Nothing contained in this Agreement limits Nokia's liability to You in the event of death or personal injury resulting from Nokia's negligence. Nokia is acting on behalf of its employees and licensors or affiliates for the purpose of disclaiming, excluding, and/or restricting obligations, warranties, and liability as provided in this clause 9, but in no other respects and for no other purpose. + + diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/bld.inf --- a/kernel/eka/compsupp/bld.inf Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/compsupp/bld.inf Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "ARM EABI LICENCE.txt" @@ -13,66 +13,66 @@ // Description: // Compiler runtime support. // -// PRJ_PLATFORMS -ARMV4 ARMV5 ARMV5SMP ARMV7 - +ARMV4 ARMV5 ARMV5SMP ARMV6 ARMV7 PRJ_EXPORTS -rvct.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(rvct/) -gcce/gcce.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(gcce/) +rvct.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(rvct/) +gcce/gcce.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(gcce/) +symcpp/symcpp.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(symcpp.h) -symcpp/symcpp.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(symcpp.h) - -compsupp.iby /epoc32/rom/include/ - +compsupp.iby /epoc32/rom/include/ PRJ_MMPFILES -#if !defined GCCXML && !defined GCCE +#if !defined(GCCXML) && !defined(GCCE) symcpp/scppnwdl.mmp rvct/dfprvct-thunk.mmp rvct/usrt.mmp + rvct/usrt_nx.mmp rvct/ksrt.mmp - #ifndef SMP // Only static libraries build for SMP. - - rvct/drtaeabi.mmp - - rvct/dfpaeabi.mmp - rvct/dfpaeabi_vfpv2.mmp + #ifndef SMP + rvct/drtaeabi.mmp + rvct/dfpaeabi.mmp + rvct/dfpaeabi_vfpv2.mmp - #if defined(ARMCC_2_2) || defined(ARMCC_3_1) - - rvct/drtrvct.mmp - rvct/drtrvct_vfpv2.mmp - - rvct/dfprvct.mmp - rvct/dfprvct_vfpv2.mmp - #endif - + // As of RVCT 4.0 we no longer export compiler-internal functions. + #if defined(ARMCC_2_2) || defined(ARMCC_3_1) + rvct/drtrvct.mmp + rvct/drtrvct_vfpv2.mmp + rvct/dfprvct.mmp + rvct/dfprvct_vfpv2.mmp + #endif #endif PRJ_EXTENSIONS -// Unzip RVCT3.1 runtime if being built with RVCT2.2 or RVCT4.0 - -start extension tools/compsupp + #ifndef ARMCC_2_2 + start extension tools/compsupp + option FILE $(EXTENSION_ROOT)/rt_2_2.zip + option TODIR $(EPOCROOT)epoc32/release + end + #endif -#if defined(ARMCC_2_2) || defined(ARMCC_4_0) -option FILE $(EXTENSION_ROOT)/rt_3_1.zip -#elif defined(ARMCC_3_1) -option FILE $(EXTENSION_ROOT)/rt_2_2.zip + #ifndef ARMCC_3_1 + start extension tools/compsupp + option FILE $(EXTENSION_ROOT)/rt_3_1.zip + option TODIR $(EPOCROOT)epoc32/release + end + #endif + + #ifndef ARMCC_4_0 + start extension tools/compsupp + option FILE $(EXTENSION_ROOT)/rt_4_0.zip + option TODIR $(EPOCROOT)epoc32/release + end + #endif + #endif -option TODIR $(EPOCROOT)epoc32/release -end - -#endif // #if !defined GCCXML && !defined GCCE - - diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/compsupp.iby --- a/kernel/eka/compsupp/compsupp.iby Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/compsupp/compsupp.iby Mon Oct 18 15:31:10 2010 +0100 @@ -25,9 +25,9 @@ # error "RVCT 2.1 is not supported." #endif -// Set a default run-time version. In the future, 3.1 or 4.X should be the default. +// Set RVCT4.0 as the default run-time version for TB10.1 #if !( defined(RVCT2_2) || defined(RVCT3_1) || defined(RVCT4_0) ) -# define RVCT2_2 +# define RVCT4_0 #endif #if defined(VFPHELPERS) && !defined(NOVFPHELPERS) diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/eabi/drtaeabiu.def --- a/kernel/eka/compsupp/eabi/drtaeabiu.def Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/compsupp/eabi/drtaeabiu.def Mon Oct 18 15:31:10 2010 +0100 @@ -224,4 +224,6 @@ __aeabi_uidiv @ 223 NONAME __ARM_get_typeid @ 224 NONAME __cxa_get_exception_ptr @ 225 NONAME + _ZN23TCppRTExceptionsGlobals22Init2ndEmergencyBufferEv @ 226 NONAME + _ZN23TCppRTExceptionsGlobals22Kill2ndEmergencyBufferEv @ 227 NONAME diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/rt_2_2.zip Binary file kernel/eka/compsupp/rt_2_2.zip has changed diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/rt_3_1.zip Binary file kernel/eka/compsupp/rt_3_1.zip has changed diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/rt_4_0.zip Binary file kernel/eka/compsupp/rt_4_0.zip has changed diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/rvct/usrt.mmp --- a/kernel/eka/compsupp/rvct/usrt.mmp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/compsupp/rvct/usrt.mmp Mon Oct 18 15:31:10 2010 +0100 @@ -22,8 +22,6 @@ target usrt3_1.lib #elif defined(ARMCC_4_0) target usrt4_0.lib -#else -target error #endif SMPSAFE diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/rvct/usrt_nx.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kernel/eka/compsupp/rvct/usrt_nx.mmp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,49 @@ +// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "ARM EABI LICENCE.txt" +// which accompanies this distribution, and is available +// in kernel/eka/compsupp. +// +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// +// + +#if defined(ARMCC_2_2) +target usrt_nx_2_2.lib +#elif defined(ARMCC_3_1) +target usrt_nx_3_1.lib +#elif defined(ARMCC_4_0) +target usrt_nx_4_0.lib +#endif + +SMPSAFE +targettype lib + +macro ENABLE_2ND_EMERGENCY_BUFFER + +always_build_as_arm + +source ucppfini.cpp +source ucppinit.cpp +source dllexp.cpp +source ../symaehabi/callfirstprocessfn.cpp + +#if defined(ARMCC_2_2) || defined(ARMCC_3_1) +sourcepath call_via_rx +source r0.cpp r1.cpp r2.cpp r3.cpp +source r4.cpp r5.cpp r6.cpp r7.cpp +#endif + +OS_LAYER_SYSTEMINCLUDE_SYMBIAN + +start armcc + arminc +end + diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/symaehabi/callfirstprocessfn.cpp --- a/kernel/eka/compsupp/symaehabi/callfirstprocessfn.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/compsupp/symaehabi/callfirstprocessfn.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "ARM EABI LICENCE.txt" @@ -39,14 +39,18 @@ { TCppRTExceptionsGlobals aExceptionGlobals; + #if ENABLE_2ND_EMERGENCY_BUFFER + aExceptionGlobals.Init2ndEmergencyBuffer(); + #endif + if (!aNotFirst) { // Init statics for implicitly linked DLLs User::InitProcess(); - // Init statics for EXE //pick up export table if we're an exexp __DLL_Export_Table__(); + // Init statics for EXE __cpp_initialize__aeabi_(); } #ifdef __LEAVE_EQUALS_THROW__ @@ -54,9 +58,15 @@ try { r = aNotFirst ? (*aFn)(aPtr) : E32Main(); + #if ENABLE_2ND_EMERGENCY_BUFFER + aExceptionGlobals.Kill2ndEmergencyBuffer(); + #endif } catch (XLeaveException&) { + #if ENABLE_2ND_EMERGENCY_BUFFER + aExceptionGlobals.Kill2ndEmergencyBuffer(); + #endif User::Panic(KLitUser, EUserLeaveWithoutTrap); } diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/symaehabi/cppsemantics.cpp --- a/kernel/eka/compsupp/symaehabi/cppsemantics.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/compsupp/symaehabi/cppsemantics.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -6,7 +6,7 @@ * text file LICENCE.txt (ARM contract number LEC-ELA-00080 v1.0). */ -/* Portions copyright Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). */ +/* Portions copyright Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). */ /* * RCS $Revision: 92950 $ @@ -354,9 +354,26 @@ void *__ARM_exceptions_buffer_allocate(void *buffer, size_t size) { emergency_buffer *b = (emergency_buffer *)buffer; + + #ifndef __EPOC32__ if (size > sizeof(emergency_eco) || b == NULL || b->inuse) return NULL; b->inuse = true; return &b->eco; + #else + ASSERT(b); + + if (size > sizeof(emergency_eco) || b->inuse) { + // The first buffer isn't usable; try the second one instead, if it exists. + if (b->em_buf2_p) + return b->em_buf2_p->Alloc(size); + else + return NULL; + } + else { + b->inuse = true; + return &b->eco; + } + #endif } // Deallocator: Must return non-NULL if and only if it recognises @@ -364,9 +381,26 @@ void *__ARM_exceptions_buffer_free(void *buffer, void *addr) { emergency_buffer *b = (emergency_buffer *)buffer; + + #ifndef __EPOC32__ if (b == NULL || addr != &b->eco) return NULL; b->inuse = false; return b; + #else + ASSERT(b); + + if (addr != &b->eco) { + // The object wasn't from the first buffer; see if it is from the second one. + if (b->em_buf2_p) + return b->em_buf2_p->Free(addr); + else + return NULL; + } + else { + b->inuse = false; + return b; + } + #endif } # if 0 diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/symaehabi/emergency_buffer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kernel/eka/compsupp/symaehabi/emergency_buffer.h Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,75 @@ +// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "ARM EABI LICENCE.txt" +// which accompanies this distribution, and is available +// in kernel/eka/compsupp. +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// +// + +template class TEmergencyBuffer + { +public: + void Init(); +public: + void* Alloc(unsigned); + void* Free(void*); +private: + bool iIsOccupied[N]; + T iSlots[N]; +private: + TEmergencyBuffer(); + }; + +template inline void TEmergencyBuffer::Init() + { + for (int i=0; i < N; i++) + { + iIsOccupied[i] = 0; + } + } + +template void* TEmergencyBuffer::Alloc(unsigned n) + { + if ( n <= sizeof(T) ) + { + for (int i=0; i < N; i++) + { + bool& isOccupied = iIsOccupied[i]; + + if ( ! isOccupied ) + { + isOccupied = 1; + return &iSlots[i]; + } + } + } + + return NULL; + } + +template void* TEmergencyBuffer::Free(void* p) + { + for (int i=0; i < N; i++) + { + const void* bp = &iSlots[i]; + bool& isOccupied = iIsOccupied[i]; + + if ( bp == p && isOccupied ) + { + isOccupied = 0; + return p; + } + } + + return NULL; + } + + diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/symaehabi/symbian_support.cpp --- a/kernel/eka/compsupp/symaehabi/symbian_support.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/compsupp/symaehabi/symbian_support.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "ARM EABI LICENCE.txt" @@ -12,7 +12,7 @@ // // Description: // e32/compsupp/symaehabi/symbian_support.cpp -// +// // /* Environment: */ @@ -40,6 +40,7 @@ EXPORT_C TCppRTExceptionsGlobals::TCppRTExceptionsGlobals() { buffer.inuse = false; + buffer.em_buf2_p = NULL; thread_globals.uncaughtExceptions = 0; thread_globals.unexpectedHandler = NAMES::default_unexpected_handler; thread_globals.terminateHandler = __default_terminate_handler; @@ -50,8 +51,27 @@ thread_globals.emergency_buffer = &buffer; Dll::SetTls(this); } + +EXPORT_C void TCppRTExceptionsGlobals::Init2ndEmergencyBuffer() + { + ASSERT(buffer.em_buf2_p == NULL); + + TEmergencyBuffer2* p = (TEmergencyBuffer2*) User::Alloc( sizeof(TEmergencyBuffer2) ); + if (!p) + abort(); + p->Init(); + buffer.em_buf2_p = p; + } + +EXPORT_C void TCppRTExceptionsGlobals::Kill2ndEmergencyBuffer() + { + ASSERT(buffer.em_buf2_p); + + User::Free(buffer.em_buf2_p); + } + #if __ARMCC_VERSION < 220000 -extern "C" +extern "C" { /* we have to dummy up the following for 2.1. The names changed in the def file @@ -78,7 +98,7 @@ } } -#else +#else // This is the key function that forces the class impedimenta to be get exported in RVCT 2.2 and later. EXPORT_C void XLeaveException::ForceKeyFunction(){} #endif @@ -224,9 +244,9 @@ // look in extension ROM if there is one TUint main_start = UserSvr::RomHeaderAddress(); TUint main_end = main_start + ((TRomHeader*)main_start)->iUncompressedSize; - + TUint rda = UserSvr::RomRootDirectoryAddress(); - + // Assume rom starts on multiple of 4k if (rda > main_end) { @@ -237,7 +257,7 @@ // 3. the extension ROM is mapped starting at a megabyte boundary // Thus the address of the extension ROM header may be obtained by rounding the root directory // address down to the next megabyte boundary. - + TUint ext_start = rda &~ 0x000fffffu; TRomExceptionSearchTable* extrom_exctab = (TRomExceptionSearchTable*)(((TExtensionRomHeader*)ext_start)->iRomExceptionSearchTable); if (extrom_exctab && addr >= extrom_exctab->iEntries[0] && addr < GET_EST_FENCEPOST(extrom_exctab)) @@ -315,7 +335,7 @@ public: virtual void Overflow(TDes8& /*aDes*/) {} }; - + #endif void DebugPrintf(const char * aFmt, ...) @@ -333,7 +353,7 @@ RDebug::RawPrint(buf2); #else (void)aFmt; -#endif +#endif } } // extern "C" diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/compsupp/symaehabi/symbian_support.h --- a/kernel/eka/compsupp/symaehabi/symbian_support.h Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/compsupp/symaehabi/symbian_support.h Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "ARM EABI LICENCE.txt" @@ -69,8 +69,25 @@ XLeaveException aUserLeaveException; }; + + +#include "emergency_buffer.h" + +struct emergency_eco2 : emergency_eco { + // The secondary emergency buffer might as well support slightly bigger objects. + int spacer[6]; +}; + +typedef TEmergencyBuffer TEmergencyBuffer2; + + struct emergency_buffer { bool inuse; + + TEmergencyBuffer2* em_buf2_p; // offset = 4, size = 4. + + // This field has always been forced to an 8-byte alignment, so the fact that + // em_buf2_p has been added shouldn't break compatibility with existing binaries. struct emergency_eco eco; }; @@ -79,6 +96,9 @@ { public: IMPORT_C TCppRTExceptionsGlobals(); +public: + IMPORT_C void Init2ndEmergencyBuffer(); + IMPORT_C void Kill2ndEmergencyBuffer(); private: __cxa_eh_globals thread_globals; emergency_buffer buffer; diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/drivers/hcr/hcr_pil.cpp --- a/kernel/eka/drivers/hcr/hcr_pil.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/drivers/hcr/hcr_pil.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "Eclipse Public License v1.0" @@ -93,7 +93,7 @@ // -- WINS Specific ---------------------------------------------------------- -#ifdef __WINS__ +#if defined(__WINS__) || defined(HCRTEST_AVOID_BSP_HCR_DAT) // Set to ensure Rom Hdr dependency does not break compilation in // LocateCoreImgRepository() at the end of this file. @@ -104,6 +104,7 @@ #endif + // -- FUNCTIONS --------------------------------------------------------------- /** @@ -2955,10 +2956,14 @@ // Use this testing more on Emulator platform // and on hardware when ROM Header is not to be used or not implemented +#ifdef HCRTEST_AVOID_BSP_HCR_DAT + const TText8* hcrfile = (const TText8*) "test_hcr.dat"; +#else const TText8* hcrfile = (const TText8*) "hcr.dat"; +#endif TInt retVal = SearchCoreImgRepository(aRepos, hcrfile); if (retVal != KErrNone) - return retVal; + HCR_TRACE_RETURN(retVal); #else @@ -2980,10 +2985,10 @@ aRepos = HCR::TRepositoryFile::New(reinterpret_cast(romHeader.iHcrFileAddress)); NKern::ThreadLeaveCS(); if (aRepos == 0) - return KErrNoMemory; + HCR_TRACE_RETURN(KErrNoMemory); } else - return KErrNotFound; + HCR_TRACE_RETURN(KErrNotFound); #endif // HCRTEST_COREIMG_DONTUSE_ROMHDR diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/drivers/iic/iic_channel.cpp --- a/kernel/eka/drivers/iic/iic_channel.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/drivers/iic/iic_channel.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -443,6 +443,8 @@ if(r == KErrNone) { + // Use placement new to re-initialise the iClientTimeoutDfc callback object (don't re-allocate the memory) + new (iClientTimeoutDfc) TDfc(SlaveStaticCB,(TAny*)this, 7); // Highest Dfc priority iClient->Open(); aCallback->iChannel=this; iNotif = aCallback; @@ -456,7 +458,6 @@ } else r=DoRequest(ESyncConfigPwrUp); - if(r == KErrNone) { if(!aAsynch) // For asynchronous version there is nothing more to do until the callback is invoked @@ -477,6 +478,7 @@ return r; } + TInt DIicBusChannelSlave::ReleaseChannel() { __KTRACE_OPT(KIIC, Kern::Printf("DIicBusChannelSlave::ReleaseChannel\n")); @@ -494,6 +496,10 @@ r=DoRequest(EPowerDown); if(r == KErrNone) { + if(iClientTimeoutDfc != NULL) + { + iClientTimeoutDfc->~TDfc(); // call destructor directly, ie don't free the memory + } TInt intState=__SPIN_LOCK_IRQSAVE(iSpinLock); iClient=NULL; iChannelInUse=0; // Channel now available for capture by other clients @@ -802,7 +808,7 @@ DIicBusChannelSlave::DIicBusChannelSlave(TBusType aBusType, TChannelDuplex aChanDuplex, TInt16 aChannelId) : DIicBusChannel(DIicBusChannel::ESlave, aBusType, aChanDuplex), - iChannelId(aChannelId), iTimerState(EInactive), + iChannelId(aChannelId), iClientTimeoutDfc(NULL), iTimerState(EInactive), iMasterWaitTime(KSlaveDefMWaitTime), iClientWaitTime(KSlaveDefCWaitTime), iSpinLock(TSpinLock::EOrderGenericIrqLow2) // Semi-arbitrary, low priority value { @@ -813,7 +819,12 @@ DIicBusChannelSlave::~DIicBusChannelSlave() { - delete iClientTimeoutDfc; + if(iClientTimeoutDfc != NULL) + { + delete iClientTimeoutDfc; + iClientTimeoutDfc = NULL; + } + return; } void DIicBusChannelSlave::SlaveStaticCB(TAny* aPtr) @@ -1139,9 +1150,7 @@ TInt DIicBusChannelMasterSlave::ReleaseChannel() { - iMasterChannel->Lock(); TInt r=iSlaveChannel->ReleaseChannel(); - iMasterChannel->Unlock(); return r; }; diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/drivers/pbus/mmc/sdcard/sdcard3c/sdcard.cpp --- a/kernel/eka/drivers/pbus/mmc/sdcard/sdcard3c/sdcard.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/drivers/pbus/mmc/sdcard/sdcard3c/sdcard.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -636,6 +636,7 @@ __KTRACE_OPT(KPBUS1, Kern::Printf("R7 not supported.")); OstTrace0( TRACE_INTERNALS, DSDSTACK_INITIALISEMEMORYCARDSM3, "R7 not supported" ); Command().iSpec.iResponseType = ERespTypeR1; + Command().iFlags |= KMMCCmdFlagIgnoreStatus; } diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/drivers/pbus/mmc/stack.cpp --- a/kernel/eka/drivers/pbus/mmc/stack.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/drivers/pbus/mmc/stack.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -5712,10 +5712,15 @@ else { // If commands returns card status and there we no command errors - // (or the status contains errors) then save the status info. - if ( (cmd.iFlags & KMMCCmdFlagStatusReceived) || - ((exitCode==KMMCErrNone || (exitCode & KMMCErrStatus)) && - (cmd.iSpec.iResponseType==ERespTypeR1 || cmd.iSpec.iResponseType==ERespTypeR1B)) ) + // (or the status contains errors) and the status is not to be ignored, + // then save the status info. + if ( !(cmd.iFlags & KMMCCmdFlagIgnoreStatus) && + ((cmd.iFlags & KMMCCmdFlagStatusReceived) || + ((exitCode==KMMCErrNone || (exitCode & KMMCErrStatus))) && + (cmd.iSpec.iResponseType==ERespTypeR1 || cmd.iSpec.iResponseType==ERespTypeR1B)) ) + + + { TMMCStatus status=s.ResponseP(); s.iLastStatus=status; diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/drivers/resmanus/d_resmanus.cpp --- a/kernel/eka/drivers/resmanus/d_resmanus.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/drivers/resmanus/d_resmanus.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -77,32 +77,45 @@ __ASSERT_ALWAYS(0,RESMANUS_FAULT()); \ } \ } + /*************************************************************************************** class TTrackGetStateBuf ***************************************************************************************/ -TTrackGetStateBuf::TTrackGetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, +TTrackGetStateBuf::TTrackGetStateBuf(TPowerResourceCbFn aFn, TAny* /*aPtr*/, TDfcQue* aQue, TInt aPriority) - : iCtrlBlock(aFn, aPtr, aQue, aPriority) + : iCtrlBlock(aFn, this, aQue, aPriority) { iRequest = NULL; } +TTrackGetStateBuf::~TTrackGetStateBuf() + { + if(iRequest) + Kern::DestroyClientRequest(iRequest); + } + /*************************************************************************************** class TTrackSetStateBuf ***************************************************************************************/ -TTrackSetStateBuf::TTrackSetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, +TTrackSetStateBuf::TTrackSetStateBuf(TPowerResourceCbFn aFn, TAny* /*aPtr*/, TDfcQue* aQue, TInt aPriority) - : iCtrlBlock(aFn, aPtr, aQue, aPriority) + : iCtrlBlock(aFn, this, aQue, aPriority) { iRequest = NULL; } +TTrackSetStateBuf::~TTrackSetStateBuf() + { + if(iRequest) + Kern::DestroyClientRequest(iRequest); + } + /*************************************************************************************** class TTrackNotifyBuf ***************************************************************************************/ -TTrackNotifyBuf::TTrackNotifyBuf(TPowerResourceCbFn aFn, TAny* aPtr, +TTrackNotifyBuf::TTrackNotifyBuf(TPowerResourceCbFn aFn, TAny* /*aPtr*/, TDfcQue* aQue, TInt aPriority) - : iNotifyBlock(aFn, aPtr, aQue, aPriority) + : iNotifyBlock(aFn, this, aQue, aPriority) { iRequest = NULL; } @@ -113,17 +126,6 @@ Kern::DestroyClientRequest(iRequest); } -TTrackSetStateBuf::~TTrackSetStateBuf() - { - if(iRequest) - Kern::DestroyClientRequest(iRequest); - } - -TTrackGetStateBuf::~TTrackGetStateBuf() - { - if(iRequest) - Kern::DestroyClientRequest(iRequest); - } /*************************************************************************************** class DDeviceResManUs @@ -505,7 +507,6 @@ if( r != KErrNone) return r; callBack = &(((TTrackSetStateBuf*)trackBuf)->iCtrlBlock); - new (callBack) TPowerResourceCb(&AsyncCallBackFn, (TAny*)trackBuf, iDfcQ, KResManCallBackPriority); parms[0] = (TUint)m.Ptr2(); parms[1] = (TUint)callBack; m.iArg[2] = &(parms[0]); @@ -532,7 +533,6 @@ if(r != KErrNone) return r; prn = &(((TTrackNotifyBuf*)trackBuf)->iNotifyBlock); - new (prn) DPowerResourceNotification(&AsyncCallBackFn, (TAny*)trackBuf, iDfcQ, KResManCallBackPriority); m.iArg[2] = (TAny*)prn; break; } @@ -546,7 +546,6 @@ if(r != KErrNone) return r; prn = &(((TTrackNotifyBuf*)trackBuf)->iNotifyBlock); - new (prn) DPowerResourceNotification(&AsyncCallBackFn, (TAny*)trackBuf, iDfcQ, KResManCallBackPriority); parms[2] = (TUint)prn; break; } @@ -2020,9 +2019,7 @@ TTrackGetStateBuf* stateBuf = (TTrackGetStateBuf*)aBuffer; stateBuf->iRequest->SetDestPtr1(aState); stateBuf->iRequest->SetDestPtr2(aLevelOwnerPtr); - // Use placement new to update the content of the TPowerResourceCb aCb = &(stateBuf->iCtrlBlock); - new (aCb) TPowerResourceCb(&AsyncCallBackFn,(TAny*)aBuffer,iDfcQ,KResManCallBackPriority); } return r; } @@ -2052,18 +2049,30 @@ } Kern::Printf("iOwningChannel at 0x%x\n",aTracker->iOwningChannel); Kern::Printf("iFreeQue at 0x%x\n",aTracker->iFreeQue); + SDblQueLink* buf; if(aTracker->iFreeQue!=NULL) { - buf=aTracker->iFreeQue->First(); - while(buf!=aTracker->iFreeQue->Last()) + SDblQueLink* anchor = &(aTracker->iFreeQue->iA); + buf = anchor->iNext; + while(anchor != buf ) { - Kern::Printf("iFreeQue first buffer at 0x%x\n",buf); + Kern::Printf("iFreeQue buffer at 0x%x\n",buf); TAny* intermediatePtr = (TAny*)buf; - if((aTracker->iType == EGetState)||(aTracker->iType == ESetState)) + if(aTracker->iType == EGetState) + { + TTrackGetStateBuf* tempBuf =(TTrackGetStateBuf*)intermediatePtr; + Kern::Printf("TTrackGetStateBuf buffer control block at 0x%x\n",&(tempBuf->iCtrlBlock)); + } + else if(aTracker->iType == ESetState) { TTrackSetStateBuf* tempBuf =(TTrackSetStateBuf*)intermediatePtr; - Kern::Printf("buffer control block at 0x%x\n",(TInt)&tempBuf->iCtrlBlock); + Kern::Printf("TTrackSetStateBuf buffer control block at 0x%x\n",&(tempBuf->iCtrlBlock)); + } + else if(aTracker->iType == ENotify) + { + TTrackNotifyBuf* tempBuf =(TTrackNotifyBuf*)intermediatePtr; + Kern::Printf("TTrackNotifyBuf buffer notify block at 0x%x\n",&(tempBuf->iNotifyBlock)); } buf = buf->iNext; }; @@ -2071,15 +2080,26 @@ Kern::Printf("iBusyQue at 0x%x\n",aTracker->iBusyQue); if(aTracker->iBusyQue!=NULL) { - buf=aTracker->iBusyQue->First(); - while(buf!=aTracker->iBusyQue->Last()) + SDblQueLink* anchor = &(aTracker->iBusyQue->iA); + buf = anchor->iNext; + while(anchor != buf ) { Kern::Printf("iBusyQue buffer at 0x%x\n",buf); TAny* intermediatePtr = (TAny*)buf; - if((aTracker->iType == EGetState)||(aTracker->iType == ESetState)) + if(aTracker->iType == EGetState) + { + TTrackGetStateBuf* tempBuf =(TTrackGetStateBuf*)intermediatePtr; + Kern::Printf("TTrackGetStateBuf buffer control block at 0x%x\n",&(tempBuf->iCtrlBlock)); + } + else if(aTracker->iType == ESetState) { TTrackSetStateBuf* tempBuf =(TTrackSetStateBuf*)intermediatePtr; - Kern::Printf("buffer control block at 0x%x\n", (TInt)&tempBuf->iCtrlBlock); + Kern::Printf("TTrackSetStateBuf buffer control block at 0x%x\n",&(tempBuf->iCtrlBlock)); + } + else if(aTracker->iType == ENotify) + { + TTrackNotifyBuf* tempBuf =(TTrackNotifyBuf*)intermediatePtr; + Kern::Printf("TTrackNotifyBuf buffer notify block at 0x%x\n",&(tempBuf->iNotifyBlock)); } buf= buf->iNext; }; @@ -2157,12 +2177,14 @@ if(r!=KErrNone) { SDblQueLink* ptr = (aTracker->iFreeQue)->First(); + TTrackingBuffer *buf = NULL; do { SDblQueLink* next = NULL; if(ptr !=NULL) next = ptr->iNext; - delete ptr; + buf = (TTrackingBuffer *)ptr; + DELETE_TRACKING_BUFFER(aTracker,buf) ptr = next; } while ((ptr!=NULL)&&(ptr!=(aTracker->iFreeQue)->Last())); delete aTracker->iFreeQue; diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/euser/epoc/up_dll_tls.cpp --- a/kernel/eka/euser/epoc/up_dll_tls.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/euser/epoc/up_dll_tls.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -26,6 +26,11 @@ /** Sets the value of the Thread Local Storage (TLS) variable. +Note that the TLS value for a given DLL may be preserved even if the DLL has +been unloaded from the current process and loaded again since it was set. The +value is not guaranteed to be preserved. The DLL must take steps to ensure that +Dll::FreeTls is called for all relevant threads if this must be avoided. + @param aPtr The value to be assigned to the Thread Local Storage variable. In practice, this is almost always a pointer to memory that has previously been allocated, but does not necessarily @@ -49,6 +54,11 @@ /** Gets the value of the Thread Local Storage (TLS) variable. +Note that the TLS value for a given DLL may be preserved even if the DLL has +been unloaded from the current process and loaded again since it was set. The +value is not guaranteed to be preserved. The DLL must take steps to ensure that +Dll::FreeTls is called for all relevant threads if this must be avoided. + @return The value of the Thread Local Storage variable as set by a previous call to Dll::SetTls(). If no value has previously been set, then the returned value is NULL. diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/euser/us_time.cpp --- a/kernel/eka/euser/us_time.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/euser/us_time.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -380,7 +380,10 @@ YYYYMMDD:HHMMSS.MMMMMM -If omitted, the first component is set to January 1st 0 AD nominal Gregorian. +If omitted, the first component defaults to 1 January, year 0 (nominal Gregorian). +This is the base date for TTime, so the result of this method will be the number +of microseconds in the time specified by the second and third components. + If either the second or third components are omitted, they are set to zero. Notes: @@ -1472,7 +1475,7 @@ EXPORT_C TDay TTime::DayNoInWeek() const // -// 1st January 0AD was a Monday +// 1st January year 0 was a Monday // /** Gets the day number within the current week. @@ -2480,8 +2483,8 @@ EXPORT_C TBool Time::IsLeapYear(TInt aYear) // -// up to and including 1600 leap years were every 4 years,since then leap years are every 4 years unless -// the year falls on a century which is not divisible by 4 (ie 1900 wasnt,2000 will be) +// up to and including 1600 leap years were every 4 years; since then leap years are every 4 years unless +// the year falls on a century which is not divisible by 4 (i.e. 1900 wasn't, 2000 will be) // for simplicity define year 0 as a leap year // /** @@ -2500,16 +2503,24 @@ EXPORT_C TInt Time::LeapYearsUpTo(TInt aYear) // -// from 0AD to present year according to the rule above +// from year 0 to specified year according to the rule above // /** -Gets the number of leap years between 0 AD nominal Gregorian and the specified -year - inclusive. +Gets the number of leap years between year 0 (nominal Gregorian) and the specified +year, inclusive. + +The calendar used is nominal Gregorian with astronomical numbering (where +year 2000 = 2000 AD, year 1600 = 1600 AD, year 1 = 1 AD, and so year 0 = +1 BC, year -100 = 101 BC). No days are removed from September 1752 or any +other month. Leap year calculation before 1600 uses the Julian method of +every four years, even for years which are exactly divisible by 100 but not +by 400. Thus leap years include: 1200, 1300, 1400, 1500, 1600 and 2000; +non-leap years include: 1601, 1700, 1800, 1900 and 2100. @param aYear The final year in the range to search. If negative, the function will return a negative number of leap years. -@return The number of leap years between 0 AD nominal Gregorian and aYear. +@return The number of leap years between year 0 (nominal Gregorian) and aYear. */ { @@ -2523,4 +2534,3 @@ num+=(aYear/4-century+century/4); return(num); } - diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/include/drivers/mmc.h --- a/kernel/eka/include/drivers/mmc.h Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/include/drivers/mmc.h Mon Oct 18 15:31:10 2010 +0100 @@ -2286,6 +2286,7 @@ const TUint32 KMMCCmdFlagReliableWrite= KBit9; // Current command is Reliable Write const TUint32 KMMCCmdFlagDeleteNotify= KBit10; // Current command is Delete Notify const TUint32 KMMCCmdFlagRpmbIO= KBit11; // Current command is of RPMB type +const TUint32 KMMCCmdFlagIgnoreStatus= KBit12; // Ignore card status from response const TUint32 KMMCCmdFlagASSPFlags= KMMCCmdFlagBytesValid | KMMCCmdFlagTransStopped | diff -r 55a0a1279a7e -r 206a6eaaeb71 kernel/eka/include/e32hal.h --- a/kernel/eka/include/e32hal.h Wed Oct 13 13:34:03 2010 +0100 +++ b/kernel/eka/include/e32hal.h Mon Oct 18 15:31:10 2010 +0100 @@ -216,7 +216,7 @@ TInt iProximityStep; /** #include "kernel/kern_ext.mmh" diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/hcr/d_hcrext_own.mmp --- a/kerneltest/e32test/hcr/d_hcrext_own.mmp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/hcr/d_hcrext_own.mmp Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "Eclipse Public License v1.0" @@ -15,6 +15,7 @@ // macro HCRTEST_USERSIDE_INTERFACE +macro HCRTEST_AVOID_BSP_HCR_DAT #include #include "kernel/kern_ext.mmh" diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/hcr/d_hcrsim.cpp --- a/kerneltest/e32test/hcr/d_hcrsim.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/hcr/d_hcrsim.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "Eclipse Public License v1.0" @@ -154,9 +154,12 @@ } \ } +// Invoke some non-fatal calls on the real HCR.dll in the BSP to show +// a kernel extension can use the HCR API early in boot. void KextInitTests() { TInt r; + // Get last Setting in Reference Compiled Repository TUint32 value1; TSettingId setting1(0xFFFFFFFF, 0xFFFFFFFF); @@ -164,88 +167,8 @@ KEXT_TESTKERRNONE(r); KEXT_TEST(value1==0x4C415354); // 'L', 'A', 'S', 'T' - // Determine what test repositories the HCR has loaded - // Make sure we have the file repository - const TRomHeader& romheader = Epoc::RomHeader(); - KEXT_TEST(romheader.iHcrFileAddress != NULL); // Assuming this is the test repository (hcr.dat) - // Find the nand repository - TBool smr; - TBool smrrep; - SSettingC* repos = NULL; - TInt nosettings = 0; - HasRepositoryInSmr(smr, smrrep); - if (smrrep) - { - repos = SettingsList6; // File+Nand - nosettings = sizeof(SettingsList6) / sizeof(SSettingC); - } - else if (!smr) - { - repos = SettingsList7; // File Only - nosettings = sizeof(SettingsList7) / sizeof(SSettingC); - } - else - { - // SMR partitions found but no HCR repository - KEXT_TEST(0); - return; - } - - // Simple word setting Get - for (SSettingC* setting = repos; setting < repos + nosettings; setting++) - { -// Note: these macros are irrelevant here, it is just so the two test kernel -// extensions do something different -#ifdef HCRTEST_CLIENT_THREAD - if (setting->iName.iType == ETypeInt32) - { - TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey); - TInt32 val; - r = GetInt(id, val); - KEXT_TESTKERRNONE(r); - KEXT_TEST(setting->iValue.iLit.iInt32 == val); - } -#else // !HCRTEST_CLIENT_THREAD - if (setting->iName.iType == ETypeUInt32) - { - TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey); - TUint32 val; - r = GetUInt(id, val); - KEXT_TESTKERRNONE(r); - KEXT_TEST(setting->iValue.iLit.iUInt32 == val); - } -#endif // !HCRTEST_CLIENT_THREAD - } - - // Large setting Get - for (SSettingC* setting = repos; setting < repos + nosettings; setting++) - { -// Note: these macros are irrelevant here, it is just so the two test kernel -// extensions do something different -#ifdef HCRTEST_CLIENT_THREAD - if (setting->iName.iType == ETypeBinData) - { - TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey); - TBuf8 val; - TPtrC8 aval(setting->iValue.iPtr.iData, setting->iName.iLen); - r = GetData(id, val); - KEXT_TESTKERRNONE(r); - KEXT_TEST(0 == val.Compare(aval)); - } -#else // !HCRTEST_CLIENT_THREAD - if (setting->iName.iType == ETypeText8) - { - TSettingId id(setting->iName.iId.iCat, setting->iName.iId.iKey); - TBuf8 val; - TPtrC8 aval(setting->iValue.iPtr.iString8, setting->iName.iLen); - r = GetString(id, val); - KEXT_TESTKERRNONE(r); - KEXT_TEST(0 == val.Compare(aval)); - } -#endif // !HCRTEST_CLIENT_THREAD - } - - // Some other API calls + // Check number of settings in some test categories. + // Most likely these categories are not used in the real HCR.dll TUint i; for (i = 0; i < sizeof(KTestCategories) / sizeof(TCategoryUid); i++) { @@ -296,6 +219,9 @@ r = Kern::DynamicDfcQCreate(iDfcQ, KHcrSimTestThreadPriority, KHcrSimTestThread); if (r != KErrNone) return r; + // Allow this test DFCQ thread to take page faults should it happen rather + // than let the Kernel panic it with 2,61 KERN-EXEC. + iDfcQ->SetRealtimeState(ERealtimeStateOff); #ifdef HCRTEST_USERSIDE_INTERFACE r = SetName(&KTestHcrRealOwn); #else diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/hcr/d_hcrsim_client.mmp --- a/kerneltest/e32test/hcr/d_hcrsim_client.mmp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/hcr/d_hcrsim_client.mmp Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "Eclipse Public License v1.0" @@ -14,8 +14,19 @@ // Hardware Configuration Respoitory Tests // +// Defined when the HCR API must not be exported e.g. when compiled +// into a test driver. macro HCRTEST_NO_EXPORT -macro HCRTEST_CLIENT_THREAD + +// No DFCQ thread when this is defined, test cases execute in user-side +// test application thread context +macro HCRTEST_CLIENT_THREAD + +// Defined to ensure PIL does not make use of production HCR.DAT in core +// image when under test. +macro HCRTEST_AVOID_BSP_HCR_DAT + +// Define this to increase amount of trace output from HCR code. //macro HCR_TRACE #define HCRTEST_TEST_MMP diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/hcr/d_hcrsim_own.mmp --- a/kerneltest/e32test/hcr/d_hcrsim_own.mmp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/hcr/d_hcrsim_own.mmp Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "Eclipse Public License v1.0" @@ -14,7 +14,19 @@ // Hardware Configuration Respoitory Tests // +// Defined when the HCR API must not be exported e.g. when compiled +// into a test driver. macro HCRTEST_NO_EXPORT + +// No DFCQ thread when this is defined, test cases execute in user-side +// test application thread context +//macro HCRTEST_CLIENT_THREAD + +// Defined to ensure PIL does not make use of production HCR.DAT in core +// image when under test. +macro HCRTEST_AVOID_BSP_HCR_DAT + +// Define this to increase amount of trace output from HCR code. //macro HCR_TRACE #define HCRTEST_TEST_MMP diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/hcr/d_hcrsim_testdata.h --- a/kerneltest/e32test/hcr/d_hcrsim_testdata.h Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/hcr/d_hcrsim_testdata.h Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "Eclipse Public License v1.0" @@ -258,7 +258,7 @@ {{{ KTestCategories[0], 1}, ETypeInt32, 0x0000, 0 }, {{ 0 }}}, {{{ KTestCategories[0], 2}, ETypeInt32, 0x0000, 0 }, {{ 0 }}}, }; -#if !defined(__KERNEL_MODE__) || defined(HCRTEST_USERSIDE_INTERFACE) +#if !defined(__KERNEL_MODE__) const TUint32 KTestInvalidCategory = 0; const TUint32 KTestInvalidSettingId = 5678; @@ -670,5 +670,5 @@ {{{ KTestCategories[5], 0x00d0}, ETypeUInt64, 0x0000, sizeof(TUint64) }, {{ reinterpret_cast(&KTestU64Three) }}}, {{{ KTestCategories[5], 0xffffffff}, ETypeInt8, 0x0000, 0 }, {{ 1 }}}, }; -#endif // !defined(__KERNEL_MODE__) || defined(HCRTEST_USERSIDE_INTERFACE) +#endif // !defined(__KERNEL_MODE__) #endif // !D_HCRSIM_TESTDATA_H diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/hcr/d_hcrut.cpp --- a/kerneltest/e32test/hcr/d_hcrut.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/hcr/d_hcrut.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "Eclipse Public License v1.0" @@ -535,11 +535,13 @@ case RHcrTest::ECtrlSwitchFileRepository: { TInt r; - TAny* args[2]; + TAny* args[2]; // args[1] length includes null terminating char TEST_MEMGET(a1, args, sizeof(args)); - const TText* fileRepName = (TText*) args[0]; - r = gObserver.SwitchRepository(fileRepName, HCR::HCRInternal::ECoreRepos); + TBuf8 fileName; + TEST_MEMGET(args[0], (TAny*)fileName.Ptr(), ((TInt)args[1])); + + r = gObserver.SwitchRepository(fileName.Ptr(), HCR::HCRInternal::ECoreRepos); if (r != KErrNone) { HCR_TRACE_RETURN(r); diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/hcr/d_hcrut.h --- a/kerneltest/e32test/hcr/d_hcrut.h Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/hcr/d_hcrut.h Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "Eclipse Public License v1.0" @@ -25,6 +25,8 @@ #include #endif +#define MAX_FILENAME_LEN 64 + /** Interface to the fast-trace memory buffer. @@ -77,10 +79,14 @@ return DoControl(ECtrlFileFindSettingsInCategory, (TAny*)args); } - inline TUint Test_SwitchFileRepository(const TText* aRepName) + // aNameLen includes the null terminator + inline TUint Test_SwitchFileRepository(const TText8* aRepName, TInt aNameLen) { - TAny* args[1]; + __ASSERT_ALWAYS((aNameLeniHcrFileAddress); - test(romheader->iHcrFileAddress); - if (romheader->iPageableRomStart) + test.Printf(_L("HCR Core Image DAT File Address: %08x\n"), romheader->iHcrFileAddress); + if (romheader->iHcrFileAddress && romheader->iPageableRomStart) { // If this is a paged ROM, HCR file must be in the unpaged area test_Compare(romheader->iRomBase + romheader->iPageableRomStart, >, romheader->iHcrFileAddress); @@ -2337,8 +2336,9 @@ void HcrRealSettingDiscovery() { - test.Next(_L("Setting Discovery")); + test.Next(_L("BSP HCR.dll Test Setting Discovery")); TInt r; + TBool anyFound = EFalse; TCategoryUid cat; test.Printf(_L("Category Element Type Len Value\n")); test.Printf(_L("--------------------------------------------------\n")); @@ -2349,6 +2349,7 @@ test_Compare(0, <=, nosettings); if (nosettings > 0) { + anyFound = ETrue; TElementId* elids; TSettingType* types; TUint16* lens; @@ -2551,6 +2552,11 @@ User::Free(lens); } } + if (anyFound == EFalse) + { + test.Printf(_L("No TEST settings found in BSP HCR.dll\n")); + } + test.Printf(_L("--------------------------------------------------\n")); } void HcrRealRetrieveKernelExtensionTestResults() { @@ -2598,33 +2604,14 @@ test_KErrNone(r); r = HcrSimTest.Open(aDriver); test_KErrNone(r); - // + + // Check the BSP specific HCR-using test kernel extensions were + // able to retrieve HCR settings during kernel initialisation. HcrRealRetrieveKernelExtensionTestResults(); + // Discovery of settings, may not print any if repositories for BSP + // do not contain any test settings. HcrRealSettingDiscovery(); - // Initialize static variable with the right HCR client type - if(aDriver.Compare(KTestHcrRealOwn) == 0) - gHcrThread = KSimOwnThread; - else if(aDriver.Compare(KTestHcrRealClient) == 0) - gHcrThread = KSimClientThread; - else - test(EFalse); - // - TBool smr; - TBool smrrep; - r = HcrSimTest.HasRepositoryInSmr(smr, smrrep); - test_KErrNone(r); - if (smrrep) - { - // File + NAND - HcrSimTestApiTests(SettingsList6, sizeof(SettingsList6) / sizeof(SSettingC)); - } - else - { - // File - HcrSimTestApiTests(SettingsList7, sizeof(SettingsList7) / sizeof(SSettingC)); - } - // test.Next(_L("Close LDD")); HcrSimTest.Close(); r = User::FreeLogicalDevice(aDriver); @@ -2635,9 +2622,6 @@ void HcrCatRecodsExampleTest(const TDesC& aDriver) { - using namespace HCR; - - test.Start(_L("HCR Record Structured Category Test")); test.Next(_L("Load HCR Test driver")); diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/hcr/t_hcrut.cpp --- a/kerneltest/e32test/hcr/t_hcrut.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/hcr/t_hcrut.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of the License "Eclipse Public License v1.0" @@ -56,8 +56,9 @@ test_Equal((lastEl - firstEl + 1), NumInTestCat); // Load file repository data for the boundary test condition - const TText * fileBc0 = (const TText *)"filerepos_bc0.dat"; - test_KErrNone(HcrTest.Test_SwitchFileRepository(fileBc0)); + const TText8 * fileBc0 = (const TText8 *)"filerepos_bc0.dat"; + TInt len0 = sizeof("filerepos_bc0.dat"); + test_KErrNone(HcrTest.Test_SwitchFileRepository(fileBc0, len0)); // Test the low end boundary conditions in the file repository. // First element in the category is also the first element in the @@ -82,8 +83,9 @@ //Load relevant coreImg repository - const TText * fileBc1 = (const TText *)"filerepos_bc1.dat"; - test_KErrNone(HcrTest.Test_SwitchFileRepository(fileBc1)); + const TText8 * fileBc1 = (const TText8 *)"filerepos_bc1.dat"; + TInt len1 = sizeof("filerepos_bc1.dat"); + test_KErrNone(HcrTest.Test_SwitchFileRepository(fileBc1, len1)); //Test the low end boundary condition when first element of the diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/mmu/d_shadow.cpp --- a/kerneltest/e32test/mmu/d_shadow.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/mmu/d_shadow.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -36,6 +36,10 @@ const TUint KMaxNumberOfPageDirectories = 256; #endif +// A buffer used to test shadowing of unpaged ROM. It is two pages in size so that it will always +// contain at least one memory page. +const TUint8 UnpagedMemory[8192] = { 1 }; + class DShadow; class DShadowFactory : public DLogicalDevice @@ -395,7 +399,10 @@ break; } - + + case RShadow::EControlGetUnpagedPage: + return _ALIGN_UP((TLinAddr)UnpagedMemory, pageSize); + default: r=KErrNotSupported; break; diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/mmu/d_shadow.h --- a/kerneltest/e32test/mmu/d_shadow.h Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/mmu/d_shadow.h Mon Oct 18 15:31:10 2010 +0100 @@ -71,7 +71,8 @@ EControlClaimPhys, EControlGetMemoryArchitecture, EControlGetMemModelInfo, - EControlGetPdInfo + EControlGetPdInfo, + EControlGetUnpagedPage, }; public: @@ -94,6 +95,7 @@ inline void GetMemoryArchitecture(TCpu &aCpu, TUint &aCR); inline TMemModel GetMemModelInfo(TUint &aPageTable, TUint &aNumPds); inline TInt GetPdInfo(TUint aPdNo, TUint &aPdSize, TUint &aPdBase, TUint &aOffset); + inline TLinAddr GetUnpagedPage(); }; @@ -161,7 +163,10 @@ aOffset = ret & KPageOffsetMask; return (ret & KErrNoPageTable)?KErrNotFound:KErrNone; } - + +inline TLinAddr RShadow::GetUnpagedPage() + { return DoControl(EControlGetUnpagedPage, NULL, NULL); } + #endif #endif diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/mmu/t_shadow.cpp --- a/kerneltest/e32test/mmu/t_shadow.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/mmu/t_shadow.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -78,7 +78,11 @@ TUint8* PageBuffer2 = NULL; TUint8* PageBuffer3 = NULL; -void TestShadowPage(TLinAddr aPageAddr, TPaged aPageType) +// A buffer used to test shadowing of paged ROM. It is two pages in size so that it will always +// contain at least one memory page. +const TUint8 RomToShadow[8192] = { 1 }; + +void TestShadowPage(TLinAddr aPageAddr, TPaged aPageType, TBool aCanModify) { test.Start(_L("Test shadowing a page")); test.Printf(_L(" addr == 0x%08x, type == %d\n"), aPageAddr, aPageType); @@ -130,16 +134,19 @@ test.Next(_L("Check page following shadow page is unaltered")); test_Equal(0, Mem::Compare((TUint8*)(secondPage),PageSize,PageBuffer3,PageSize)); - test.Next(_L("Write data into shadow page")); - for(TInt i=0; i>8)^(i2>>16)); + test.Next(_L("Write data into shadow page")); + for(TInt i=0; i>8)^(i2>>16)); + } + test_KErrNone(Shadow.Write(aPageAddr,PageBuffer2)); + + test.Next(_L("Check data written into shadow page")); + test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer2,PageSize)); } - test_KErrNone(Shadow.Write(aPageAddr,PageBuffer2)); - - test.Next(_L("Check data written into shadow page")); - test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer2,PageSize)); test.Next(_L("Check page following shadow page is unaltered")); test_Equal(0, Mem::Compare((TUint8*)(secondPage),PageSize,PageBuffer3,PageSize)); @@ -460,6 +467,18 @@ User::Free(PageBuffer3); } +static TLinAddr PageToShadow(TBool aPaged) + { + if (aPaged) + { + test(RomPagingSupported); + test(sizeof(RomToShadow) >= ((TUint)(2 * PageSize))); + return _ALIGN_UP((TLinAddr)RomToShadow, PageSize); + } + else + return Shadow.GetUnpagedPage(); + } + GLDEF_C TInt E32Main() // // Test ROM shadowing @@ -484,22 +503,28 @@ test.Start(_L("Testing ROM shadowing")); Initialise(); - TestRomIsSectionMapped(); + TestRomIsSectionMapped(); - TestShadowPage(RomUnpagedStart, EUnpaged); - TestShadowPage(RomUnpagedStart + PageSize, EUnpaged); - TestShadowPage(RomUnpagedEnd - PageSize, EUnpaged); - TestNoFreeRAM(RomUnpagedStart); - TestShadowPageOOM(RomUnpagedStart); + TLinAddr unpagedPage = PageToShadow(EFalse); + + TestShadowPage(unpagedPage, EUnpaged, ETrue); + TestShadowPage(RomUnpagedStart, EUnpaged, EFalse); + TestShadowPage(RomUnpagedEnd - PageSize, EUnpaged, EFalse); + + TestNoFreeRAM(unpagedPage); + TestShadowPageOOM(unpagedPage); if (RomPagingSupported) { - TestShadowPage(RomPagedStart, EPaged); - TestShadowPage(RomPagedStart + PageSize, EPaged); - TestShadowPage(RomPagedEnd - PageSize, EPaged); - TestNoFreeRAM(RomPagedEnd - PageSize); - TestShadowPageOOM(RomPagedStart); - TestInteractionWithPinning(RomPagedStart); + TLinAddr pagedPage = PageToShadow(ETrue); + + TestShadowPage(pagedPage, EPaged, ETrue); + TestShadowPage(RomPagedStart, EPaged, EFalse); + TestShadowPage(RomPagedEnd - PageSize, EPaged, EFalse); + + TestNoFreeRAM(pagedPage); + TestShadowPageOOM(pagedPage); + TestInteractionWithPinning(pagedPage); } // todo: add test when reforming section mappings is implemented diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/resmanus/resourcecontrol.mmp --- a/kerneltest/e32test/resmanus/resourcecontrol.mmp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/resmanus/resourcecontrol.mmp Mon Oct 18 15:31:10 2010 +0100 @@ -30,7 +30,7 @@ #endif macro RESOURCE_MANAGER_SIMULATED_PSL -macro _DUMP_TRACKERS +//macro _DUMP_TRACKERS macro BTRACE_RESMANUS macro PRM_US_INSTRUMENTATION_MACRO diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/resmanus/resourcecontrollerextended.mmp --- a/kerneltest/e32test/resmanus/resourcecontrollerextended.mmp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/resmanus/resourcecontrollerextended.mmp Mon Oct 18 15:31:10 2010 +0100 @@ -31,7 +31,7 @@ macro RESOURCE_MANAGER_SIMULATED_PSL macro BTRACE_RESMANUS -macro _DUMP_TRACKERS +//macro _DUMP_TRACKERS macro PRM_US_INSTRUMENTATION_MACRO macro PRM_ENABLE_EXTENDED_VERSION diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32test/usbho/t_usbdi/t_usbhost_usbman_src/t_usbhost_usbman.cpp --- a/kerneltest/e32test/usbho/t_usbdi/t_usbhost_usbman_src/t_usbhost_usbman.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/e32test/usbho/t_usbdi/t_usbhost_usbman_src/t_usbhost_usbman.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -17,7 +17,7 @@ #include #include #include -#include "..\..\t_usbdi\inc\testdebug.h" +#include "../../t_usbdi/inc/testdebug.h" #include "OstTraceDefinitions.h" #ifdef OST_TRACE_COMPILER_IN_USE #include "t_usbhost_usbmanTraces.h" diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/include/cephes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/include/cephes.h Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,27 @@ +/* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#ifndef _CEPHES_H_ +#define _CEPHES_H_ + +double cephes_igamc(double a, double x); +double cephes_igam(double a, double x); +double cephes_lgam(double x); +double cephes_p1evl(double x, double *coef, int N); +double cephes_polevl(double x, double *coef, int N); +double cephes_erf(double x); +double cephes_erfc(double x); +double cephes_normal(double x); + +#endif /* _CEPHES_H_ */ diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/include/config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/include/config.h Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,65 @@ +/* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#if defined(__cplusplus) +extern "C" { +#endif + +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +//#define WINDOWS32 +//#define PROTOTYPES +//#define LITTLE_ENDIAN +//#define LOWHI + +/* + * AUTO DEFINES (DON'T TOUCH!) + */ + +#ifndef CSTRTD +typedef char *CSTRTD; +#endif +#ifndef BSTRTD +typedef unsigned char *BSTRTD; +#endif + +#ifndef BYTE +typedef unsigned char BYTE; +#endif +#ifndef UINT +typedef unsigned int UINT; +#endif +#ifndef USHORT +typedef unsigned short USHORT; +#endif +#ifndef ULONG +typedef unsigned long ULONG; +#endif +#ifndef DIGIT +typedef USHORT DIGIT; /* 16-bit word */ +#endif +#ifndef DBLWORD +typedef ULONG DBLWORD; /* 32-bit word */ +#endif + +#ifndef WORD64 +typedef ULONG WORD64[2]; /* 64-bit word */ +#endif + +#endif /* _CONFIG_H_ */ + +#if defined(__cplusplus) +} +#endif diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/include/decls.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/include/decls.h Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,52 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#ifndef _DECLS_H_ +#define _DECLS_H_ + +#include "../include/defs.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + G L O B A L D A T A S T R U C T U R E S + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +BitSequence *epsilon; // BIT STREAM +TP tp; // TEST PARAMETER STRUCTURE +FILE *stats[NUMOFTESTS+1]; // FILE OUTPUT STREAM +FILE *results[NUMOFTESTS+1]; // FILE OUTPUT STREAM +FILE *freqfp; // FILE OUTPUT STREAM +FILE *summary; // FILE OUTPUT STREAM +int testVector[NUMOFTESTS+1]; + +char generatorDir[NUMOFGENERATORS][20] = { "AlgorithmTesting", "LCG", "QCG1", "QCG2","CCG", "XOR", + "MODEXP", "BBS", "MS", "G-SHA1", "HASH_DRBG" }; + +char testNames[NUMOFTESTS+1][32] = { " ", "Frequency", "BlockFrequency", "CumulativeSums", "Runs", "LongestRun", "Rank", + "FFT", "NonOverlappingTemplate", "OverlappingTemplate", "Universal", "ApproximateEntropy", "RandomExcursions", + "RandomExcursionsVariant", "Serial", "LinearComplexity" }; + +#endif // _DECLS_H_ + diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/include/defs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/include/defs.h Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,92 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + D E B U G G I N G A I D E S + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#ifndef _DEFS_H_ +#define _DEFS_H_ + +#include "config.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + M A C R O S + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#define MAX(x,y) ((x) < (y) ? (y) : (x)) +#define MIN(x,y) ((x) > (y) ? (y) : (x)) +#define isNonPositive(x) ((x) <= 0.e0 ? 1 : 0) +#define isPositive(x) ((x) > 0.e0 ? 1 : 0) +#define isNegative(x) ((x) < 0.e0 ? 1 : 0) +#define isGreaterThanOne(x) ((x) > 1.e0 ? 1 : 0) +#define isZero(x) ((x) == 0.e0 ? 1 : 0) +#define isOne(x) ((x) == 1.e0 ? 1 : 0) + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + G L O B A L C O N S T A N T S + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#define ALPHA 0.01 /* SIGNIFICANCE LEVEL */ +#define MAXNUMOFTEMPLATES 148 /* APERIODIC TEMPLATES: 148=>temp_length=9 */ +#define NUMOFTESTS 15 /* MAX TESTS DEFINED */ +#define NUMOFGENERATORS 11 /* MAX PRNGs */ +#define MAXFILESPERMITTEDFORPARTITION 148 +#define TEST_FREQUENCY 1 +#define TEST_BLOCK_FREQUENCY 2 +#define TEST_CUSUM 3 +#define TEST_RUNS 4 +#define TEST_LONGEST_RUN 5 +#define TEST_RANK 6 +#define TEST_FFT 7 +#define TEST_NONPERIODIC 8 +#define TEST_OVERLAPPING 9 +#define TEST_UNIVERSAL 10 +#define TEST_APEN 11 +#define TEST_RND_EXCURSION 12 +#define TEST_RND_EXCURSION_VAR 13 +#define TEST_SERIAL 14 +#define TEST_LINEARCOMPLEXITY 15 + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + G L O B A L D A T A S T R U C T U R E S + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +typedef unsigned char BitSequence; + +typedef struct _testParameters { + int n; + int blockFrequencyBlockLength; + int nonOverlappingTemplateBlockLength; + int overlappingTemplateBlockLength; + int serialBlockLength; + int linearComplexitySequenceLength; + int approximateEntropyBlockLength; + int numOfBitStreams; +} TP; + +#endif // _DEFS_H_ + diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/include/externs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/include/externs.h Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,48 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#ifndef _EXTERNS_H_ +#define _EXTERNS_H_ + +#include "../include/defs.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + G L O B A L D A T A S T R U C T U R E S + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +extern BitSequence *epsilon; // BIT STREAM +extern TP tp; // TEST PARAMETER STRUCTURE +extern FILE *stats[NUMOFTESTS+1]; // FILE OUTPUT STREAM +extern FILE *results[NUMOFTESTS+1]; // FILE OUTPUT STREAM +extern FILE *freqfp; // FILE OUTPUT STREAM +extern FILE *summary; // FILE OUTPUT STREAM +extern int testVector[NUMOFTESTS+1]; + +extern char generatorDir[NUMOFGENERATORS][20]; +extern char testNames[NUMOFTESTS+1][32]; + +#endif // _EXTERNS_H_ + diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/include/generators.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/include/generators.h Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,116 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#ifndef _GENERATORS_H_ +#define _GENERATORS_H_ +//#include "../include/sha.h" + +void lcg(); +double lcg_rand(int, double, double*, int); +void quadRes1(); +void quadRes2(); +void cubicRes(); +void exclusiveOR(); +void modExp(); +void bbs(); +void micali_schnorr(); +void SHA1(); +void HASH_DRBG(); + +/* The circular shifts. */ +#define CS1(x) ((((ULONG)x)<<1)|(((ULONG)x)>>31)) +#define CS5(x) ((((ULONG)x)<<5)|(((ULONG)x)>>27)) +#define CS30(x) ((((ULONG)x)<<30)|(((ULONG)x)>>2)) + +/* K constants */ + +#define K0 0x5a827999L +#define K1 0x6ed9eba1L +#define K2 0x8f1bbcdcL +#define K3 0xca62c1d6L + +#define f1(x,y,z) ( (x & (y ^ z)) ^ z ) + +#define f3(x,y,z) ( (x & ( y ^ z )) ^ (z & y) ) + +#define f2(x,y,z) ( x ^ y ^ z ) /* Rounds 20-39 */ + +#define expand(x) Wbuff[x%16] = CS1(Wbuff[(x - 3)%16 ] ^ Wbuff[(x - 8)%16 ] ^ Wbuff[(x - 14)%16] ^ Wbuff[x%16]) + +#define sub1Round1(count) { \ + temp = CS5(A) + f1(B, C, D) + E + Wbuff[count] + K0; \ + E = D; \ + D = C; \ + C = CS30( B ); \ + B = A; \ + A = temp; \ + } \ + +#define sub2Round1(count) \ + { \ + expand(count); \ + temp = CS5(A) + f1(B, C, D) + E + Wbuff[count%16] + K0; \ + E = D; \ + D = C; \ + C = CS30( B ); \ + B = A; \ + A = temp; \ + } \ + +#define Round2(count) \ + { \ + expand(count); \ + temp = CS5( A ) + f2( B, C, D ) + E + Wbuff[count%16] + K1; \ + E = D; \ + D = C; \ + C = CS30( B ); \ + B = A; \ + A = temp; \ + } \ + +#define Round3(count) \ + { \ + expand(count); \ + temp = CS5( A ) + f3( B, C, D ) + E + Wbuff[count%16] + K2; \ + E = D; \ + D = C; \ + C = CS30( B ); \ + B = A; \ + A = temp; \ + } + +#define Round4(count) \ + { \ + expand(count); \ + temp = CS5( A ) + f2( B, C, D ) + E + Wbuff[count%16] + K3; \ + E = D; \ + D = C; \ + C = CS30( B ); \ + B = A; \ + A = temp; \ + } + +#endif diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/include/genutils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/include/genutils.h Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,71 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#ifndef _GENUTILS_H_ +#define _GENUTILS_H_ + +#include "openc.h" +#include "config.h" + +typedef struct _MP_struct { + int size; /* in bytes */ + int bitlen; /* in bits, duh */ + BYTE *val; + } MP; + +#define FREE(A) if ( (A) ) { free((A)); (A) = NULL; } +#define ASCII2BIN(ch) ( (((ch) >= '0') && ((ch) <= '9')) ? ((ch) - '0') : (((ch) >= 'A') && ((ch) <= 'F')) ? ((ch) - 'A' + 10) : ((ch) - 'a' + 10) ) + +#ifndef EXPWD +#define EXPWD ((DBLWORD)1< gLogFilePath; + +extern TInt gTemplateIndex; + +const TInt KMaxBit = 32; + + + +// inline functions +inline void ResetTemplateIndex() + { + gTemplateIndex = 1; + } + + +#endif // _UTILITIES_H_ + diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/approximateEntropy.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/approximateEntropy.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,111 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#include "openc.h" +#include "../include/externs.h" +#include "../include/utilities.h" +#include "../include/cephes.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + A P P R O X I M A T E E N T R O P Y T E S T + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +void +ApproximateEntropy(int m, int n) +{ + int i, j, k, r, blockSize, seqLength, powLen, index; + double sum, numOfBlocks, ApEn[2], apen, chi_squared, p_value; + unsigned int *P; + + fprintf(stats[TEST_APEN], "\t\t\tAPPROXIMATE ENTROPY TEST\n"); + fprintf(stats[TEST_APEN], "\t\t--------------------------------------------\n"); + fprintf(stats[TEST_APEN], "\t\tCOMPUTATIONAL INFORMATION:\n"); + fprintf(stats[TEST_APEN], "\t\t--------------------------------------------\n"); + fprintf(stats[TEST_APEN], "\t\t(a) m (block length) = %d\n", m); + + seqLength = n; + r = 0; + + for ( blockSize=m; blockSize<=m+1; blockSize++ ) { + if ( blockSize == 0 ) { + ApEn[0] = 0.00; + r++; + } + else { + numOfBlocks = (double)seqLength; + powLen = (int)pow(2, blockSize+1)-1; + if ( (P = (unsigned int*)calloc(powLen,sizeof(unsigned int)))== NULL ) { + fprintf(stats[TEST_APEN], "ApEn: Insufficient memory available.\n"); + return; + } + for ( i=1; i 0 ) + sum += P[index]*log(P[index]/numOfBlocks); + index++; + } + sum /= numOfBlocks; + ApEn[r] = sum; + r++; + free(P); + } + } + apen = ApEn[0] - ApEn[1]; + + chi_squared = 2.0*seqLength*(log(2) - apen); + p_value = cephes_igamc(pow(2, m-1), chi_squared/2.0); + + fprintf(stats[TEST_APEN], "\t\t(b) n (sequence length) = %d\n", seqLength); + fprintf(stats[TEST_APEN], "\t\t(c) Chi^2 = %f\n", chi_squared); + fprintf(stats[TEST_APEN], "\t\t(d) Phi(m) = %f\n", ApEn[0]); + fprintf(stats[TEST_APEN], "\t\t(e) Phi(m+1) = %f\n", ApEn[1]); + fprintf(stats[TEST_APEN], "\t\t(f) ApEn = %f\n", apen); + fprintf(stats[TEST_APEN], "\t\t(g) Log(2) = %f\n", log(2.0)); + fprintf(stats[TEST_APEN], "\t\t--------------------------------------------\n"); + + if ( m > (int)(log(seqLength)/log(2)-5) ) { + fprintf(stats[TEST_APEN], "\t\tNote: The blockSize = %d exceeds recommended value of %d\n", m, + MAX(1, (int)(log(seqLength)/log(2)-5))); + fprintf(stats[TEST_APEN], "\t\tResults are inaccurate!\n"); + fprintf(stats[TEST_APEN], "\t\t--------------------------------------------\n"); + } + + fprintf(stats[TEST_APEN], "%s\t\tp_value = %f\n\n", p_value < ALPHA ? "FAILURE" : "SUCCESS", p_value); + fprintf(results[TEST_APEN], "%f\n", p_value); +} diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/assess.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/assess.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,419 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +*/ + + +/* -------------------------------------------------------------------------- + Title : The NIST Statistical Test Suite + + Date : December 1999 + + Programmer : Juan Soto + + Summary : For use in the evaluation of the randomness of bitstreams + produced by cryptographic random number generators. + + Package : Version 1.0 + + Copyright : (c) 1999 by the National Institute Of Standards & Technology + + History : Version 1.0 by J. Soto, October 1999 + Revised by J. Soto, November 1999 + Revised by Larry Bassham, March 2008 + + Keywords : Pseudorandom Number Generator (PRNG), Randomness, Statistical + Tests, Complementary Error functions, Incomplete Gamma + Function, Random Walks, Rank, Fast Fourier Transform, + Template, Cryptographically Secure PRNG (CSPRNG), + Approximate Entropy (ApEn), Secure Hash Algorithm (SHA-1), + Blum-Blum-Shub (BBS) CSPRNG, Micali-Schnorr (MS) CSPRNG, + + Source : David Banks, Elaine Barker, James Dray, Allen Heckert, + Stefan Leigh, Mark Levenson, James Nechvatal, Andrew Rukhin, + Miles Smid, Juan Soto, Mark Vangel, and San Vo. + + Technical + Assistance : Larry Bassham, Ron Boisvert, James Filliben, Daniel Lozier, + and Bert Rust. + + Warning : Portability Issues. + + Limitation : Amount of memory allocated for workspace. + + Restrictions: Permission to use, copy, and modify this software without + fee is hereby granted, provided that this entire notice is + included in all copies of any software which is or includes + a copy or modification of this software and in all copies + of the supporting documentation for such software. + -------------------------------------------------------------------------- */ +//system include +#include +#include +#include + +// user include +#include "openc.h" +#include "../include/decls.h" +#include "../include/cephes.h" +#include "../include/utilities.h" +#include "../include/generators.h" + +typedef int (*CompareFnType)(const void*, const void*); + +void partitionResultFile(int numOfFiles, int numOfSequences, int option, int testNameID); +void postProcessResults(int option); +int cmp(const double *a, const double *b); +int computeMetrics(char *s, int test); + +int +StartNISTTest() +{ + int i; + int option = 10; /* TEMPLATE LENGTH/STREAM LENGTH/GENERATOR*/ + char *streamFile = NULL; /* STREAM FILENAME */ + + + tp.n = 1000000; // length of the individual bit stream(s) to be processed + tp.blockFrequencyBlockLength = 128; + tp.nonOverlappingTemplateBlockLength = 9; + tp.overlappingTemplateBlockLength = 9; + tp.approximateEntropyBlockLength = 10; + tp.serialBlockLength = 16; + tp.linearComplexitySequenceLength = 500; + tp.numOfBitStreams = 100; + chooseTests(); + fixParameters(); + openOutputStreams(option); + invokeTestSuite(option, streamFile); + fclose(freqfp); + for( i=1; i<=NUMOFTESTS; i++ ) { + if ( stats[i] != NULL ) + fclose(stats[i]); + if ( results[i] != NULL ) + fclose(results[i]); + } + if ( (testVector[0] == 1) || (testVector[TEST_CUSUM] == 1) ) + partitionResultFile(2, tp.numOfBitStreams, option, TEST_CUSUM); + if ( (testVector[0] == 1) || (testVector[TEST_NONPERIODIC] == 1) ) + partitionResultFile(MAXNUMOFTEMPLATES, tp.numOfBitStreams, option, TEST_NONPERIODIC); + if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION] == 1) ) + partitionResultFile(8, tp.numOfBitStreams, option, TEST_RND_EXCURSION); + if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION_VAR] == 1) ) + partitionResultFile(18, tp.numOfBitStreams, option, TEST_RND_EXCURSION_VAR); + if ( (testVector[0] == 1) || (testVector[TEST_SERIAL] == 1) ) + partitionResultFile(2, tp.numOfBitStreams, option, TEST_SERIAL); + fprintf(summary, "------------------------------------------------------------------------------\n"); + fprintf(summary, "RESULTS FOR THE UNIFORMITY OF P-VALUES AND THE PROPORTION OF PASSING SEQUENCES\n"); + fprintf(summary, "------------------------------------------------------------------------------\n"); + fprintf(summary, " C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 P-VALUE PROPORTION STATISTICAL TEST\n"); + fprintf(summary, "------------------------------------------------------------------------------\n"); + postProcessResults(option); + fclose(summary); + + return 1; + } + +void +partitionResultFile(int numOfFiles, int numOfSequences, int option, int testNameID) +{ + int i, k, m, j, start, end, num, numread; + float c; + FILE **fp = (FILE **)calloc(numOfFiles+1, sizeof(FILE *)); + int *results = (int *)calloc(numOfFiles, sizeof(int *)); + char *s[MAXFILESPERMITTEDFORPARTITION]; + char resultsDir[200]; + + for ( i=0; i 0.000000 ) + T[count++] = c; + } + + if ( (A = (double *)calloc(count, sizeof(double))) == NULL ) { + printf("Final Analysis Report aborted due to insufficient workspace\n"); + // Perform cleanup before returning + fclose(fp); + free(T); + return 0; + } + + for ( j=0; j big ) { + pkm2 *= biginv; + pkm1 *= biginv; + qkm2 *= biginv; + qkm1 *= biginv; + } + } while ( t > MACHEP ); + + return ans*ax; +} + +double +cephes_igam(double a, double x) +{ + double ans, ax, c, r; + + if ( (x <= 0) || ( a <= 0) ) + return 0.0; + + if ( (x > 1.0) && (x > a ) ) + return 1.e0 - cephes_igamc(a,x); + + /* Compute x**a * exp(-x) / gamma(a) */ + ax = a * log(x) - x - cephes_lgam(a); + if ( ax < -MAXLOG ) { + printf("igam: UNDERFLOW\n"); + return 0.0; + } + ax = exp(ax); + + /* power series */ + r = a; + c = 1.0; + ans = 1.0; + + do { + r += 1.0; + c *= x/r; + ans += c; + } while ( c/ans > MACHEP ); + + return ans * ax/a; +} + + +/* A[]: Stirling's formula expansion of log gamma + * B[], C[]: log gamma function between 2 and 3 + */ +static unsigned short A[] = { + 0x6661,0x2733,0x9850,0x3f4a, + 0xe943,0xb580,0x7fbd,0xbf43, + 0x5ebb,0x20dc,0x019f,0x3f4a, + 0xa5a1,0x16b0,0xc16c,0xbf66, + 0x554b,0x5555,0x5555,0x3fb5 +}; +static unsigned short B[] = { + 0x6761,0x8ff3,0x8901,0xc095, + 0xb93e,0x355b,0xf234,0xc0e2, + 0x89e5,0xf890,0x3d73,0xc114, + 0xdb51,0xf994,0xbc82,0xc131, + 0xf20b,0x0219,0x4589,0xc13a, + 0x055e,0x5418,0x0c67,0xc12a +}; +static unsigned short C[] = { + /*0x0000,0x0000,0x0000,0x3ff0,*/ + 0x12b2,0x1cf3,0xfd0d,0xc075, + 0xd757,0x7b89,0xaa0d,0xc0d0, + 0x4c9b,0xb974,0xeb84,0xc10a, + 0x0043,0x7195,0x6286,0xc131, + 0xf34c,0x892f,0x5255,0xc143, + 0xe14a,0x6a11,0xce4b,0xc13e +}; + +#define MAXLGM 2.556348e305 + + +/* Logarithm of gamma function */ +double +cephes_lgam(double x) +{ + double p, q, u, w, z; + int i; + + sgngam = 1; + + if ( x < -34.0 ) { + q = -x; + w = cephes_lgam(q); /* note this modifies sgngam! */ + p = floor(q); + if ( p == q ) { +lgsing: + goto loverf; + } + i = (int)p; + if ( (i & 1) == 0 ) + sgngam = -1; + else + sgngam = 1; + z = q - p; + if ( z > 0.5 ) { + p += 1.0; + z = p - q; + } + z = q * sin( PI * z ); + if ( z == 0.0 ) + goto lgsing; + /* z = log(PI) - log( z ) - w;*/ + z = log(PI) - log( z ) - w; + return z; + } + + if ( x < 13.0 ) { + z = 1.0; + p = 0.0; + u = x; + while ( u >= 3.0 ) { + p -= 1.0; + u = x + p; + z *= u; + } + while ( u < 2.0 ) { + if ( u == 0.0 ) + goto lgsing; + z /= u; + p += 1.0; + u = x + p; + } + if ( z < 0.0 ) { + sgngam = -1; + z = -z; + } + else + sgngam = 1; + if ( u == 2.0 ) + return( log(z) ); + p -= 2.0; + x = x + p; + p = x * cephes_polevl( x, (double *)B, 5 ) / cephes_p1evl( x, (double *)C, 6); + + return log(z) + p; + } + + if ( x > MAXLGM ) { +loverf: + printf("lgam: OVERFLOW\n"); + + return sgngam * MAXNUM; + } + + q = ( x - 0.5 ) * log(x) - x + log( sqrt( 2*PI ) ); + if ( x > 1.0e8 ) + return q; + + p = 1.0/(x*x); + if ( x >= 1000.0 ) + q += (( 7.9365079365079365079365e-4 * p + - 2.7777777777777777777778e-3) *p + + 0.0833333333333333333333) / x; + else + q += cephes_polevl( p, (double *)A, 4 ) / x; + + return q; +} + +double +cephes_polevl(double x, double *coef, int N) +{ + double ans; + int i; + double *p; + + p = coef; + ans = *p++; + i = N; + + do + ans = ans * x + *p++; + while ( --i ); + + return ans; +} + +double +cephes_p1evl(double x, double *coef, int N) +{ + double ans; + double *p; + int i; + + p = coef; + ans = x + *p++; + i = N-1; + + do + ans = ans * x + *p++; + while ( --i ); + + return ans; +} + +double +cephes_erf(double x) +{ + static const double two_sqrtpi = 1.128379167095512574; + double sum = x, term = x, xsqr = x * x; + int j = 1; + + if ( fabs(x) > 2.2 ) + return 1.0 - cephes_erfc(x); + + do { + term *= xsqr/j; + sum -= term/(2*j+1); + j++; + term *= xsqr/j; + sum += term/(2*j+1); + j++; + } while ( fabs(term)/sum > rel_error ); + + return two_sqrtpi*sum; +} + +double +cephes_erfc(double x) +{ + static const double one_sqrtpi = 0.564189583547756287; + double a = 1, b = x, c = x, d = x*x + 0.5; + double q1, q2 = b/d, n = 1.0, t; + + if ( fabs(x) < 2.2 ) + return 1.0 - cephes_erf(x); + if ( x < 0 ) + return 2.0 - cephes_erfc(-x); + + do { + t = a*n + b*x; + a = b; + b = t; + t = c*n + d*x; + c = d; + d = t; + n += 0.5; + q1 = q2; + q2 = b/d; + } while ( fabs(q1-q2)/q2 > rel_error ); + + return one_sqrtpi*exp(-x*x)*q2; +} + + +double +cephes_normal(double x) +{ + double arg, result, sqrt2=1.414213562373095048801688724209698078569672; + + if (x > 0) { + arg = x/sqrt2; + result = 0.5 * ( 1 + erf(arg) ); + } + else { + arg = -x/sqrt2; + result = 0.5 * ( 1 - erf(arg) ); + } + + return( result); +} diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/cusum.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/cusum.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,109 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#include "openc.h" +#include "../include/externs.h" +#include "../include/cephes.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + C U M U L A T I V E S U M S T E S T + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +void +CumulativeSums(int n) +{ + int S, sup, inf; + int z = 0; + int zrev = 0; + int k; + double sum1, sum2, p_value; + + S = 0; + sup = 0; + inf = 0; + for ( k=0; k sup ) + sup++; + if ( S < inf ) + inf--; + z = (sup > -inf) ? sup : -inf; + zrev = (sup-S > S-inf) ? sup-S : S-inf; + } + + // forward + sum1 = 0.0; + for ( k=(-n/z+1)/4; k<=(n/z-1)/4; k++ ) { + sum1 += cephes_normal(((4*k+1)*z)/sqrt(n)); + sum1 -= cephes_normal(((4*k-1)*z)/sqrt(n)); + } + sum2 = 0.0; + for ( k=(-n/z-3)/4; k<=(n/z-1)/4; k++ ) { + sum2 += cephes_normal(((4*k+3)*z)/sqrt(n)); + sum2 -= cephes_normal(((4*k+1)*z)/sqrt(n)); + } + + p_value = 1.0 - sum1 + sum2; + + fprintf(stats[TEST_CUSUM], "\t\t CUMULATIVE SUMS (FORWARD) TEST\n"); + fprintf(stats[TEST_CUSUM], "\t\t-------------------------------------------\n"); + fprintf(stats[TEST_CUSUM], "\t\tCOMPUTATIONAL INFORMATION:\n"); + fprintf(stats[TEST_CUSUM], "\t\t-------------------------------------------\n"); + fprintf(stats[TEST_CUSUM], "\t\t(a) The maximum partial sum = %d\n", z); + fprintf(stats[TEST_CUSUM], "\t\t-------------------------------------------\n"); + + if ( isNegative(p_value) || isGreaterThanOne(p_value) ) + fprintf(stats[TEST_CUSUM], "\t\tWARNING: P_VALUE IS OUT OF RANGE\n"); + + fprintf(stats[TEST_CUSUM], "%s\t\tp_value = %f\n\n", p_value < ALPHA ? "FAILURE" : "SUCCESS", p_value); + fprintf(results[TEST_CUSUM], "%f\n", p_value); + + // backwards + sum1 = 0.0; + for ( k=(-n/zrev+1)/4; k<=(n/zrev-1)/4; k++ ) { + sum1 += cephes_normal(((4*k+1)*zrev)/sqrt(n)); + sum1 -= cephes_normal(((4*k-1)*zrev)/sqrt(n)); + } + sum2 = 0.0; + for ( k=(-n/zrev-3)/4; k<=(n/zrev-1)/4; k++ ) { + sum2 += cephes_normal(((4*k+3)*zrev)/sqrt(n)); + sum2 -= cephes_normal(((4*k+1)*zrev)/sqrt(n)); + } + p_value = 1.0 - sum1 + sum2; + + fprintf(stats[TEST_CUSUM], "\t\t CUMULATIVE SUMS (REVERSE) TEST\n"); + fprintf(stats[TEST_CUSUM], "\t\t-------------------------------------------\n"); + fprintf(stats[TEST_CUSUM], "\t\tCOMPUTATIONAL INFORMATION:\n"); + fprintf(stats[TEST_CUSUM], "\t\t-------------------------------------------\n"); + fprintf(stats[TEST_CUSUM], "\t\t(a) The maximum partial sum = %d\n", zrev); + fprintf(stats[TEST_CUSUM], "\t\t-------------------------------------------\n"); + + if ( isNegative(p_value) || isGreaterThanOne(p_value) ) + fprintf(stats[TEST_CUSUM], "\t\tWARNING: P_VALUE IS OUT OF RANGE\n"); + + fprintf(stats[TEST_CUSUM], "%s\t\tp_value = %f\n\n", p_value < ALPHA ? "FAILURE" : "SUCCESS", p_value); + fprintf(results[TEST_CUSUM], "%f\n", p_value); +} diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/dfft.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/dfft.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,1399 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original of this file was released into the public domain, see below for details +*/ + + +/* Notes from RFB: + + Looks like the user-level routines are: + + Real FFT + + void __ogg_fdrffti(int n, double *wsave, int *ifac) + void __ogg_fdrfftf(int n,double *r,double *wsave,int *ifac) + void __ogg_fdrfftb(int n, double *r, double *wsave, int *ifac) + + __ogg_fdrffti == initialization + __ogg_fdrfftf == forward transform + __ogg_fdrfftb == backward transform + + Parameters are + n == length of sequence + r == sequence to be transformed (input) + == transformed sequence (output) + wsave == work array of length 2n (allocated by caller) + ifac == work array of length 15 (allocated by caller) + + Cosine quarter-wave FFT + + void __ogg_fdcosqi(int n, double *wsave, int *ifac) + void __ogg_fdcosqf(int n,double *x,double *wsave,int *ifac) + void __ogg_fdcosqb(int n,double *x,double *wsave,int *ifac) +*/ + +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggSQUISH SOFTWARE CODEC SOURCE CODE. * + * * + ******************************************************************** + + file: fft.c + function: Fast discrete Fourier and cosine transforms and inverses + author: Monty + modifications by: Monty + last modification date: Jul 1 1996 + + ********************************************************************/ + +/* These Fourier routines were originally based on the Fourier + routines of the same names from the NETLIB bihar and fftpack + fortran libraries developed by Paul N. Swarztrauber at the National + Center for Atmospheric Research in Boulder, CO USA. They have been + reimplemented in C and optimized in a few ways for OggSquish. */ + +/* As the original fortran libraries are public domain, the C Fourier + routines in this file are hereby released to the public domain as + well. The C routines here produce output exactly equivalent to the + original fortran routines. Of particular interest are the facts + that (like the original fortran), these routines can work on + arbitrary length vectors that need not be powers of two in + length. */ + +#include "openc.h" +#define STIN static + +static void drfti1(int n, double *wa, int *ifac){ + static int ntryh[4] = { 4,2,3,5 }; + static double tpi = 6.28318530717958647692528676655900577; + double arg,argh,argld,fi; + int ntry=0,i,j=-1; + int k1, l1, l2, ib; + int ld, ii, ip, is, nq, nr; + int ido, ipm, nfm1; + int nl=n; + int nf=0; + + L101: + j++; + if (j < 4) + ntry=ntryh[j]; + else + ntry+=2; + + L104: + nq=nl/ntry; + nr=nl-ntry*nq; + if (nr!=0) goto L101; + + nf++; + ifac[nf+1]=ntry; + nl=nq; + if(ntry!=2)goto L107; + if(nf==1)goto L107; + + for (i=1;i>1; + ipp2=ip; + idp2=ido; + nbd=(ido-1)>>1; + t0=l1*ido; + t10=ip*ido; + + if(ido==1)goto L119; + for(ik=0;ikl1){ + for(j=1;j>1; + np2=n; + + kc=np2; + for(k=1;k>1; + ipp2=ip; + ipph=(ip+1)>>1; + if(idol1)goto L139; + + is= -ido-1; + t1=0; + for(j=1;j>1; + np2=n; + + for(i=2;i NDIM ) + N = NDIM; + for ( i=1; i<=N; i++ ) { + DZ = floor(DZ); + DZ1 = DZ*DA1; + DZ2 = DZ*DA2; + DOVER1 = floor(DZ1/DTWO31); + DOVER2 = floor(DZ2/DTWO31); + DZ1 = DZ1-DOVER1*DTWO31; + DZ2 = DZ2-DOVER2*DTWO31; + DZ = DZ1+DZ2+DOVER1+DOVER2; + DOVER = floor(DZ/DMDLS); + DZ = DZ-DOVER*DMDLS; + DUNIF[i-1] = DZ/DMDLS; + SEED = DZ; + } + + return SEED; +} + +void +lcg() +{ + double* DUNIF = NULL; + double SEED; + int i; + unsigned bit; + int num_0s, num_1s, v, bitsRead; + + SEED = 23482349.0; + if ( ((epsilon = (BitSequence *) calloc(tp.n, sizeof(BitSequence))) == NULL) || + ((DUNIF = (double*)calloc(tp.n, sizeof(double))) == NULL) ) { + printf("Insufficient memory available.\n"); + exit(1); + } + + for ( v=0; v randBuffer(KRandomByteCount); + + for (int i = 0; i < tp.numOfBitStreams; ++i) + { + gConsole->Printf(_L("Starting test %d\n"), i+1); + num_0s = 0; + num_1s = 0; + bitsRead = 0; + done = 0; + do + { + Math::Random(randBuffer); + done = convertToBits(randBuffer.Ptr() , KRandomByteCount*8, tp.n, &num_0s, &num_1s, &bitsRead); + } while ( !done ); + fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); + + nist_test_suite(); + } + free(epsilon); + } + diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/genutils.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/genutils.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,693 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +/* + * file: mp.c + * + * DESCRIPTION + * + * These functions comprise a multi-precision integer arithmetic + * and discrete function package. + */ + +#include "../include/genutils.h" + +#define MAXPLEN 384 + + +/***************************************** +** greater - Test if x > y * +** * +** Returns TRUE (1) if x greater than y, * +** otherwise FALSE (0). * +** * +** Parameters: * +** * +** x Address of array x * +** y Address of array y * +** l Length both x and y in bytes * +** * +******************************************/ +int greater(BYTE *x, BYTE *y, int l) +{ + int i; + + for ( i=0; i y[i] ) + return 1; + + return 0; +} + + +/***************************************** +** less - Test if x < y * +** * +** Returns TRUE (1) if x less than y, * +** otherwise FALSE (0). * +** * +** Parameters: * +** * +** x Address of array x * +** y Address of array y * +** l Length both x and y in bytes * +** * +******************************************/ +int less(BYTE *x, BYTE *y, int l) +{ + int i; + + for ( i=0; i>= 1; /* shift the word right once (ms bit = 0) */ + if ( c1 ) + *p |= 0x80; + c1 = c2; + c2 = 0; + p++; + } + + *p >>= 1; /* shift the word right once (ms bit = 0) */ + if ( c1 ) + *p |= 0x80; +} + + +/***************************************** +** Mult - Multiply two integers * +** * +** A = B * C * +** * +** Parameters: * +** * +** A Address of the result * +** B Address of the multiplier * +** C Address of the multiplicand * +** LB Length of B in bytes * +** LC Length of C in bytes * +** * +** NOTE: A MUST be LB+LC in length * +** * +******************************************/ +int Mult(BYTE *A, BYTE *B, int LB, BYTE *C, int LC) +{ + int i, j; + int k = 0; + DIGIT result; + + + for ( i=LB-1; i>=0; i-- ) { + result = 0; + for ( j=LC-1; j>=0; j-- ) { + k = i+j+1; + result = (DIGIT)((DIGIT)A[k] + ((DIGIT)(B[i] * C[j])) + (result >> 8)); + A[k] = (BYTE)result; + } + A[--k] = (BYTE)(result >> 8); + } + + return 0; +} + + +void ModSqr(BYTE *A, BYTE *B, int LB, BYTE *M, int LM) +{ + + Square(A, B, LB); + Mod(A, 2*LB, M, LM); +} + +void ModMult(BYTE *A, BYTE *B, int LB, BYTE *C, int LC, BYTE *M, int LM) +{ + Mult(A, B, LB, C, LC); + Mod(A, (LB+LC), M, LM); +} + + +/***************************************** +** smult - Multiply array by a scalar. * +** * +** A = b * C * +** * +** Parameters: * +** * +** A Address of the result * +** b Scalar (1 BYTE) * +** C Address of the multiplicand * +** L Length of C in bytes * +** * +** NOTE: A MUST be L+1 in length * +** * +******************************************/ +void smult(BYTE *A, BYTE b, BYTE *C, int L) +{ + int i; + DIGIT result; + + result = 0; + for ( i=L-1; i>0; i-- ) { + result = (DIGIT)(A[i] + ((DIGIT)b * C[i]) + (result >> 8)); + A[i] = (BYTE)(result & 0xff); + A[i-1] = (BYTE)(result >> 8); + } +} + +/***************************************** +** Square() - Square an integer * +** * +** A = B^2 * +** * +** Parameters: * +** * +** A Address of the result * +** B Address of the operand * +** L Length of B in bytes * +** * +** NOTE: A MUST be 2*L in length * +** * +******************************************/ +void Square(BYTE *A, BYTE *B, int L) +{ + Mult(A, B, L, B, L); +} + +/***************************************** +** ModExp - Modular Exponentiation * +** * +** A = B ** C (MOD M) * +** * +** Parameters: * +** * +** A Address of result * +** B Address of mantissa * +** C Address of exponent * +** M Address of modulus * +** LB Length of B in bytes * +** LC Length of C in bytes * +** LM Length of M in bytes * +** * +** NOTE: The integer B must be less * +** than the modulus M. * +** NOTE: A must be at least 3*LM * +** bytes long. However, the * +** result stored in A will be * +** only LM bytes long. * +******************************************/ +void ModExp(BYTE *A, BYTE *B, int LB, BYTE *C, int LC, BYTE *M, int LM) +{ + BYTE wmask; + int bits; + + bits = LC*8; + wmask = 0x80; + + A[LM-1] = 1; + + while ( !sniff_bit(C,wmask) ) { + wmask >>= 1; + bits--; + if ( !wmask ) { + wmask = 0x80; + C++; + } + } + + while ( bits-- ) { + memset(A+LM, 0x00, LM*2); + + /* temp = A*A (MOD M) */ + ModSqr(A+LM, A,LM, M,LM); + + /* A = lower L bytes of temp */ + memcpy(A, A+LM*2, LM); + memset(A+LM, 0x00, 2*LM); + + if ( sniff_bit(C,wmask) ) { + memset(A+LM, 0x00, (LM+LB)); + ModMult(A+LM, B,LB, A,LM, M,LM); /* temp = B * A (MOD M) */ + memcpy(A, A+LM+(LM+LB)-LM, LM); /* A = lower LM bytes of temp */ + memset(A+LM, 0x00, 2*LM); + } + + wmask >>= 1; + if ( !wmask ) { + wmask = 0x80; + C++; + } + } +} + + +/* DivMod: + * + * computes: + * quot = x / n + * rem = x % n + * returns: + * length of "quot" + * + * len of rem is lenx+1 + */ +int DivMod(BYTE *x, int lenx, BYTE *n, int lenn, BYTE *quot, BYTE *rem) +{ + BYTE *tx, *tn, *ttx, *ts, bmult[1]; + int i, shift, lgth_x, lgth_n, t_len, lenq; + DIGIT tMSn, mult; + ULONG tMSx; + int underflow; + + tx = x; + tn = n; + + /* point to the MSD of n */ + for ( i=0, lgth_n=lenn; i n, WATCH OUT if lgth_x == lgth_n */ + while ( (lgth_x > lgth_n) || ((lgth_x == lgth_n) && !less(tx, tn, lgth_n)) ) { + shift = 1; + if ( lgth_n == 1 ) { + if ( *tx < *tn ) { + tMSx = (DIGIT) (((*tx) << 8) | *(tx+1)); + tMSn = *tn; + shift = 0; + } + else { + tMSx = *tx; + tMSn = *tn; + } + } + else if ( lgth_n > 1 ) { + tMSx = (DIGIT) (((*tx) << 8) | *(tx+1)); + tMSn = (DIGIT) (((*tn) << 8) | *(tn+1)); + if ( (tMSx < tMSn) || ((tMSx == tMSn) && less(tx, tn, lgth_n)) ) { + tMSx = (tMSx << 8) | *(tx+2); + shift = 0; + } + } + else { + tMSx = (DIGIT) (((*tx) << 8) | *(tx+1)); + tMSn = *tn; + shift = 0; + } + + mult = (DIGIT) (tMSx / tMSn); + if ( mult > 0xff ) + mult = 0xff; + bmult[0] = (BYTE)(mult & 0xff); + + ts = rem; + do { + memset(ts, 0x00, lgth_x+1); + Mult(ts, tn, lgth_n, bmult, 1); + + underflow = 0; + if ( shift ) { + if ( ts[0] != 0 ) + underflow = 1; + else { + for ( i=0; i= 0) ) { + accum = (DIGIT)(accum + A[tL]); + A[tL--] = (BYTE)(accum & 0xff); + accum = (DIGIT)(accum >> 8); + } + + return accum; +} + + +/* + * add() + * + * A = A + B + * + * LB must be <= LA + * + */ +BYTE add(BYTE *A, int LA, BYTE *B, int LB) +{ + int i, indexA, indexB; + DIGIT accum; + + indexA = LA - 1; /* LSD of result */ + indexB = LB - 1; /* LSD of B */ + + accum = 0; + for ( i = 0; i < LB; i++ ) { + accum = (DIGIT)(accum + A[indexA]); + accum = (DIGIT)(accum + B[indexB--]); + A[indexA--] = (BYTE)(accum & 0xff); + accum = (DIGIT)(accum >> 8); + } + + if ( LA > LB ) + while ( accum && (indexA >= 0) ) { + accum = (DIGIT)(accum + A[indexA]); + A[indexA--] = (BYTE)(accum & 0xff); + accum = (DIGIT)(accum >> 8); + } + + return (BYTE)accum; +} + + +void prettyprintBstr(char *S, BYTE *A, int L) +{ + int i, extra, ctrb, ctrl; + + if ( L == 0 ) + printf("%s ", S); + else + printf("%s\n\t", S); + extra = L % 24; + if ( extra ) { + ctrb = 0; + for ( i=0; i<24-extra; i++ ) { + printf(" "); + if ( ++ctrb == 4) { + printf(" "); + ctrb = 0; + } + } + + for ( i=0; i> 16 ); + buffer[ count ] = ( ( value & 0xFF00FF00L ) >> 8 ) | ( ( value & 0x00FF00FFL ) << 8 ); + } +} + +void +ahtopb (char *ascii_hex, BYTE *p_binary, int bin_len) +{ + BYTE nibble; + int i; + + for ( i=0; i 'F' ) + nibble -= 0x20; + if ( nibble > '9' ) + nibble -= 7; + nibble -= '0'; + p_binary[i] = (BYTE)(nibble << 4); + + nibble = ascii_hex[i * 2 + 1]; + if ( nibble > 'F' ) + nibble -= 0x20; + if ( nibble > '9' ) + nibble -= 7; + nibble -= '0'; + p_binary[i] = (BYTE)(p_binary[i] + nibble); + } +} diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/linearComplexity.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/linearComplexity.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,153 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#include "openc.h" +#include "../include/externs.h" +#include "../include/cephes.h" + +void +LinearComplexity(int M, int n) +{ + int i, ii, j, d, N, L, m, N_, sign, K = 6; + double p_value, T_, mean, nu[7], chi2; + double pi[7] = { 0.01047, 0.03125, 0.12500, 0.50000, 0.25000, 0.06250, 0.020833 }; + BitSequence* T = NULL; + BitSequence* P = NULL; + BitSequence* B_ = NULL; + BitSequence* C = NULL; + + N = (int)floor(n/M); + if ( ((B_ = (BitSequence *) calloc(M, sizeof(BitSequence))) == NULL) || + ((C = (BitSequence *) calloc(M, sizeof(BitSequence))) == NULL) || + ((P = (BitSequence *) calloc(M, sizeof(BitSequence))) == NULL) || + ((T = (BitSequence *) calloc(M, sizeof(BitSequence))) == NULL) ) { + printf("Insufficient Memory for Work Space:: Linear Complexity Test\n"); + if ( B_!= NULL ) + free(B_); + if ( C != NULL ) + free(C); + if ( P != NULL ) + free(P); + if ( T != NULL ) + free(T); + return; + } + + + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "\tL I N E A R C O M P L E X I T Y\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "\tM (substring length) = %d\n", M); + fprintf(stats[TEST_LINEARCOMPLEXITY], "\tN (number of substrings) = %d\n", N); + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], " F R E Q U E N C Y \n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], " C0 C1 C2 C3 C4 C5 C6 CHI2 P-value\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "-----------------------------------------------------\n"); + fprintf(stats[TEST_LINEARCOMPLEXITY], "\tNote: %d bits were discarded!\n", n%M); + + for ( i=0; i -2.5 && T_ <= -1.5 ) + nu[1]++; + else if ( T_ > -1.5 && T_ <= -0.5 ) + nu[2]++; + else if ( T_ > -0.5 && T_ <= 0.5 ) + nu[3]++; + else if ( T_ > 0.5 && T_ <= 1.5 ) + nu[4]++; + else if ( T_ > 1.5 && T_ <= 2.5 ) + nu[5]++; + else + nu[6]++; + } + chi2 = 0.00; + for ( i=0; i v_n_obs ) + v_n_obs = run; + } + else + run = 0; + } + if ( v_n_obs < V[0] ) + nu[0]++; + for ( j=0; j<=K; j++ ) { + if ( v_n_obs == V[j] ) + nu[j]++; + } + if ( v_n_obs > V[K] ) + nu[K]++; + } + + chi2 = 0.0; + for ( i=0; i<=K; i++ ) + chi2 += ((nu[i] - N * pi[i]) * (nu[i] - N * pi[i])) / (N * pi[i]); + + pval = cephes_igamc((double)(K/2.0), chi2 / 2.0); + + fprintf(stats[TEST_LONGEST_RUN], "\t\t\t LONGEST RUNS OF ONES TEST\n"); + fprintf(stats[TEST_LONGEST_RUN], "\t\t---------------------------------------------\n"); + fprintf(stats[TEST_LONGEST_RUN], "\t\tCOMPUTATIONAL INFORMATION:\n"); + fprintf(stats[TEST_LONGEST_RUN], "\t\t---------------------------------------------\n"); + fprintf(stats[TEST_LONGEST_RUN], "\t\t(a) N (# of substrings) = %d\n", N); + fprintf(stats[TEST_LONGEST_RUN], "\t\t(b) M (Substring Length) = %d\n", M); + fprintf(stats[TEST_LONGEST_RUN], "\t\t(c) Chi^2 = %f\n", chi2); + fprintf(stats[TEST_LONGEST_RUN], "\t\t---------------------------------------------\n"); + fprintf(stats[TEST_LONGEST_RUN], "\t\t F R E Q U E N C Y\n"); + fprintf(stats[TEST_LONGEST_RUN], "\t\t---------------------------------------------\n"); + + if ( K == 3 ) { + fprintf(stats[TEST_LONGEST_RUN], "\t\t <=1 2 3 >=4 P-value Assignment"); + fprintf(stats[TEST_LONGEST_RUN], "\n\t\t %3d %3d %3d %3d ", nu[0], nu[1], nu[2], nu[3]); + } + else if ( K == 5 ) { + fprintf(stats[TEST_LONGEST_RUN], "\t\t<=4 5 6 7 8 >=9 P-value Assignment"); + fprintf(stats[TEST_LONGEST_RUN], "\n\t\t %3d %3d %3d %3d %3d %3d ", nu[0], nu[1], nu[2], + nu[3], nu[4], nu[5]); + } + else { + fprintf(stats[TEST_LONGEST_RUN],"\t\t<=10 11 12 13 14 15 >=16 P-value Assignment"); + fprintf(stats[TEST_LONGEST_RUN],"\n\t\t %3d %3d %3d %3d %3d %3d %3d ", nu[0], nu[1], nu[2], + nu[3], nu[4], nu[5], nu[6]); + } + if ( isNegative(pval) || isGreaterThanOne(pval) ) + fprintf(stats[TEST_LONGEST_RUN], "WARNING: P_VALUE IS OUT OF RANGE.\n"); + + fprintf(stats[TEST_LONGEST_RUN], "%s\t\tp_value = %f\n\n", pval < ALPHA ? "FAILURE" : "SUCCESS", pval); + fprintf(results[TEST_LONGEST_RUN], "%f\n", pval); +} diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/matrix.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/matrix.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,189 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#include "openc.h" +#include "../include/externs.h" +#include "../include/matrix.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +R A N K A L G O R I T H M R O U T I N E S +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#define MATRIX_FORWARD_ELIMINATION 0 +#define MATRIX_BACKWARD_ELIMINATION 1 + +int +computeRank(int M, int Q, BitSequence **matrix) +{ + int i, rank, m=MIN(M,Q); + + /* FORWARD APPLICATION OF ELEMENTARY ROW OPERATIONS */ + for ( i=0; i0; i-- ) { + if ( matrix[i][i] == 1 ) + perform_elementary_row_operations(MATRIX_BACKWARD_ELIMINATION, i, M, Q, matrix); + else { /* matrix[i][i] = 0 */ + if ( find_unit_element_and_swap(MATRIX_BACKWARD_ELIMINATION, i, M, Q, matrix) == 1 ) + perform_elementary_row_operations(MATRIX_BACKWARD_ELIMINATION, i, M, Q, matrix); + } + } + + rank = determine_rank(m, M, Q, matrix); + + return rank; +} + +void +perform_elementary_row_operations(int flag, int i, int M, int Q, BitSequence **A) +{ + int j, k; + + if ( flag == MATRIX_FORWARD_ELIMINATION ) { + for ( j=i+1; j=0; j-- ) + if ( A[j][i] == 1 ) + for ( k=0; k= 0) && (A[index][i] == 0) ) + index--; + if ( index >= 0 ) + row_op = swap_rows(i, index, Q, A); + } + + return row_op; +} + +int +swap_rows(int i, int index, int Q, BitSequence **A) +{ + int p; + BitSequence temp; + + for ( p=0; p 1 ) + { + for(int index = 0; index < (SKIP-1)*2*m; ++index) + { + GetNextTemplateItem(templateSequence); + } + } + fprintf(results[TEST_NONPERIODIC], "%f\n", p_value); + } + } + + fprintf(stats[TEST_NONPERIODIC], "\n"); + free(Wj); +} diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/overlappingTemplateMatchings.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/overlappingTemplateMatchings.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,132 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#include "openc.h" +#include "../include/externs.h" +#include "../include/utilities.h" +#include "../include/cephes.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + O V E R L A P P I N G T E M P L A T E T E S T + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +double Pr(int u, double eta); + +void +OverlappingTemplateMatchings(int m, int n) +{ + int i, k, match; + double W_obs, eta, sum, chi2, p_value, lambda; + int M, N, j, K = 5; + unsigned int nu[6] = { 0, 0, 0, 0, 0, 0 }; + double pi[6] = { 0.143783, 0.139430, 0.137319, 0.124314, 0.106209, 0.348945 }; + BitSequence *sequence; + + M = 1032; + N = n/M; + + if ( (sequence = (BitSequence *) calloc(m, sizeof(BitSequence))) == NULL ) { + fprintf(stats[TEST_OVERLAPPING], "\t\t OVERLAPPING TEMPLATE OF ALL ONES TEST\n"); + fprintf(stats[TEST_OVERLAPPING], "\t\t---------------------------------------------\n"); + fprintf(stats[TEST_OVERLAPPING], "\t\tTEMPLATE DEFINITION: Insufficient memory, Overlapping Template Matchings test aborted!\n"); + } + else + for ( i=0; i=5 Chi^2 P-value Assignment\n"); + fprintf(stats[TEST_OVERLAPPING], "\t\t-----------------------------------------------\n"); + fprintf(stats[TEST_OVERLAPPING], "\t\t%3d %3d %3d %3d %3d %3d %f ", + nu[0], nu[1], nu[2], nu[3], nu[4], nu[5], chi2); + + if ( isNegative(p_value) || isGreaterThanOne(p_value) ) + fprintf(stats[TEST_OVERLAPPING], "WARNING: P_VALUE IS OUT OF RANGE.\n"); + + free(sequence); + fprintf(stats[TEST_OVERLAPPING], "%f %s\n\n", p_value, p_value < ALPHA ? "FAILURE" : "SUCCESS"); + fprintf(results[TEST_OVERLAPPING], "%f\n", p_value); +} + +double +Pr(int u, double eta) +{ + int l; + double sum, p; + + if ( u == 0 ) + p = exp(-eta); + else { + sum = 0.0; + for ( l=1; l<=u; l++ ) + sum += exp(-eta-u*log(2)+l*log(eta)-cephes_lgam(l+1)+cephes_lgam(u)-cephes_lgam(l)-cephes_lgam(u-l+1)); + p = sum; + } + return p; +} diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/randomExcursions.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/randomExcursions.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,145 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#include "openc.h" +#include "../include/externs.h" +#include "../include/cephes.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + R A N D O M E X C U R S I O N S T E S T + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +void +RandomExcursions(int n) +{ + int b, i, j, k, J, x; + int cycleStart, cycleStop, *cycle = NULL, *S_k = NULL; + int stateX[8] = { -4, -3, -2, -1, 1, 2, 3, 4 }; + int counter[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + double p_value, sum, constraint, nu[6][8]; + double pi[5][6] = { {0.0000000000, 0.00000000000, 0.00000000000, 0.00000000000, 0.00000000000, 0.0000000000}, + {0.5000000000, 0.25000000000, 0.12500000000, 0.06250000000, 0.03125000000, 0.0312500000}, + {0.7500000000, 0.06250000000, 0.04687500000, 0.03515625000, 0.02636718750, 0.0791015625}, + {0.8333333333, 0.02777777778, 0.02314814815, 0.01929012346, 0.01607510288, 0.0803755143}, + {0.8750000000, 0.01562500000, 0.01367187500, 0.01196289063, 0.01046752930, 0.0732727051} }; + + if ( ((S_k = (int *)calloc(n, sizeof(int))) == NULL) || + ((cycle = (int *)calloc(MAX(1000, n/100), sizeof(int))) == NULL) ) { + printf("Random Excursions Test: Insufficent Work Space Allocated.\n"); + if ( S_k != NULL ) + free(S_k); + if ( cycle != NULL ) + free(cycle); + return; + } + + J = 0; /* DETERMINE CYCLES */ + S_k[0] = 2*(int)epsilon[0] - 1; + for( i=1; i MAX(1000, n/100) ) { + printf("ERROR IN FUNCTION randomExcursions: EXCEEDING THE MAX NUMBER OF CYCLES EXPECTED\n."); + free(S_k); + free(cycle); + return; + } + cycle[J] = i; + } + } + if ( S_k[n-1] != 0 ) + J++; + cycle[J] = n; + + fprintf(stats[TEST_RND_EXCURSION], "\t\t\t RANDOM EXCURSIONS TEST\n"); + fprintf(stats[TEST_RND_EXCURSION], "\t\t--------------------------------------------\n"); + fprintf(stats[TEST_RND_EXCURSION], "\t\tCOMPUTATIONAL INFORMATION:\n"); + fprintf(stats[TEST_RND_EXCURSION], "\t\t--------------------------------------------\n"); + fprintf(stats[TEST_RND_EXCURSION], "\t\t(a) Number Of Cycles (J) = %04d\n", J); + fprintf(stats[TEST_RND_EXCURSION], "\t\t(b) Sequence Length (n) = %d\n", n); + + constraint = MAX(0.005*pow(n, 0.5), 500); + if (J < constraint) { + fprintf(stats[TEST_RND_EXCURSION], "\t\t---------------------------------------------\n"); + fprintf(stats[TEST_RND_EXCURSION], "\t\tWARNING: TEST NOT APPLICABLE. THERE ARE AN\n"); + fprintf(stats[TEST_RND_EXCURSION], "\t\t\t INSUFFICIENT NUMBER OF CYCLES.\n"); + fprintf(stats[TEST_RND_EXCURSION], "\t\t---------------------------------------------\n"); + for(i = 0; i < 8; i++) + fprintf(results[TEST_RND_EXCURSION], "%f\n", 0.0); + } + else { + fprintf(stats[TEST_RND_EXCURSION], "\t\t(c) Rejection Constraint = %f\n", constraint); + fprintf(stats[TEST_RND_EXCURSION], "\t\t-------------------------------------------\n"); + + cycleStart = 0; + cycleStop = cycle[1]; + for ( k=0; k<6; k++ ) + for ( i=0; i<8; i++ ) + nu[k][i] = 0.; + for ( j=1; j<=J; j++ ) { /* FOR EACH CYCLE */ + for ( i=0; i<8; i++ ) + counter[i] = 0; + for ( i=cycleStart; i= 1 && S_k[i] <= 4) || (S_k[i] >= -4 && S_k[i] <= -1) ) { + if ( S_k[i] < 0 ) + b = 4; + else + b = 3; + counter[S_k[i]+b]++; + } + } + cycleStart = cycle[j]+1; + if ( j < J ) + cycleStop = cycle[j+1]; + + for ( i=0; i<8; i++ ) { + if ( (counter[i] >= 0) && (counter[i] <= 4) ) + nu[counter[i]][i]++; + else if ( counter[i] >= 5 ) + nu[5][i]++; + } + } + + for ( i=0; i<8; i++ ) { + x = stateX[i]; + sum = 0.; + for ( k=0; k<6; k++ ) + sum += pow(nu[k][i] - J*pi[(int)fabs(x)][k], 2) / (J*pi[(int)fabs(x)][k]); + p_value = cephes_igamc(2.5, sum/2.0); + + if ( isNegative(p_value) || isGreaterThanOne(p_value) ) + fprintf(stats[TEST_RND_EXCURSION], "WARNING: P_VALUE IS OUT OF RANGE.\n"); + + fprintf(stats[TEST_RND_EXCURSION], "%s\t\tx = %2d chi^2 = %9.6f p_value = %f\n", + p_value < ALPHA ? "FAILURE" : "SUCCESS", x, sum, p_value); + fprintf(results[TEST_RND_EXCURSION], "%f\n", p_value); + } + } + fprintf(stats[TEST_RND_EXCURSION], "\n"); + free(S_k); + free(cycle); +} diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/src/randomExcursionsVariant.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/e32utils/nistsecurerng/src/randomExcursionsVariant.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -0,0 +1,90 @@ +/* +* Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The original NIST Statistical Test Suite code is placed in public domain. +* (http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) +* +* This software was developed at the National Institute of Standards and Technology by +* employees of the Federal Government in the course of their official duties. Pursuant +* to title 17 Section 105 of the United States Code this software is not subject to +* copyright protection and is in the public domain. The NIST Statistical Test Suite is +* an experimental system. NIST assumes no responsibility whatsoever for its use by other +* parties, and makes no guarantees, expressed or implied, about its quality, reliability, +* or any other characteristic. We would appreciate acknowledgment if the software is used. +*/ + +#include "openc.h" +#include "../include/externs.h" +#include "../include/cephes.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + R A N D O M E X C U R S I O N S V A R I A N T T E S T + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +void +RandomExcursionsVariant(int n) +{ + int i, p, J, x, constraint, count, *S_k; + int stateX[18] = { -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + double p_value; + + if ( (S_k = (int *)calloc(n, sizeof(int))) == NULL ) { + fprintf(stats[TEST_RND_EXCURSION_VAR], "\t\tRANDOM EXCURSIONS VARIANT: Insufficent memory allocated.\n"); + return; + } + J = 0; + S_k[0] = 2*(int)epsilon[0] - 1; + for ( i=1; i (2.0 / sqrt(n)) ) { + fprintf(stats[TEST_RUNS], "\t\t\t\tRUNS TEST\n"); + fprintf(stats[TEST_RUNS], "\t\t------------------------------------------\n"); + fprintf(stats[TEST_RUNS], "\t\tPI ESTIMATOR CRITERIA NOT MET! PI = %f\n", pi); + p_value = 0.0; + } + else { + + V = 1; + for ( k=1; k= 1010*2^L*L * + * NOT BE MET, FOR THE BLOCK LENGTH L. * + * * * * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + L = 5; + if ( n >= 387840 ) L = 6; + if ( n >= 904960 ) L = 7; + if ( n >= 2068480 ) L = 8; + if ( n >= 4654080 ) L = 9; + if ( n >= 10342400 ) L = 10; + if ( n >= 22753280 ) L = 11; + if ( n >= 49643520 ) L = 12; + if ( n >= 107560960 ) L = 13; + if ( n >= 231669760 ) L = 14; + if ( n >= 496435200 ) L = 15; + if ( n >= 1059061760 ) L = 16; + + Q = 10*(int)pow(2, L); + K = (int) (floor(n/L) - (double)Q); /* BLOCKS TO TEST */ + + p = (int)pow(2, L); + if ( (L < 6) || (L > 16) || ((double)Q < 10*pow(2, L)) || + ((T = (long *)calloc(p, sizeof(long))) == NULL) ) { + fprintf(stats[TEST_UNIVERSAL], "\t\tUNIVERSAL STATISTICAL TEST\n"); + fprintf(stats[TEST_UNIVERSAL], "\t\t---------------------------------------------\n"); + fprintf(stats[TEST_UNIVERSAL], "\t\tERROR: L IS OUT OF RANGE.\n"); + fprintf(stats[TEST_UNIVERSAL], "\t\t-OR- : Q IS LESS THAN %f.\n", 10*pow(2, L)); + fprintf(stats[TEST_UNIVERSAL], "\t\t-OR- : Unable to allocate T.\n"); + return; + } + + /* COMPUTE THE EXPECTED: Formula 16, in Marsaglia's Paper */ + c = 0.7 - 0.8/(double)L + (4 + 32/(double)L)*pow(K, -3/(double)L)/15; + sigma = c * sqrt(variance[L]/(double)K); + sqrt2 = sqrt(2); + sum = 0.0; + for ( i=0; i gLogFilePath; +TInt gTemplateIndex = 1; + +bool ConvertToAperiodicBits(BitSequence aSequence[32], long value); + + +int +displayGeneratorOptions() +{ + int option = 0; + + printf(" G E N E R A T O R S E L E C T I O N \n"); + printf(" ______________________________________\n\n"); + printf(" [0] Input File [1] Linear Congruential\n"); + printf(" [2] Quadratic Congruential I [3] Quadratic Congruential II\n"); + printf(" [4] Cubic Congruential [5] XOR\n"); + printf(" [6] Modular Exponentiation [7] Blum-Blum-Shub\n"); + printf(" [8] Micali-Schnorr [9] G Using SHA-1\n\n"); + printf(" Enter Choice: "); + scanf("%d", &option); + printf("\n\n"); + + return option; +} + + +int +generatorOptions(char** streamFile) +{ + char file[200]; + int option = NUMOFGENERATORS+1; + + while ( (option < 0) || (option > NUMOFGENERATORS) ) { + option = displayGeneratorOptions(); + switch( option ) { + case 0: + printf("\t\tUser Prescribed Input File: "); + scanf("%s", file); + *streamFile = (char*)calloc(200, sizeof(char)); + sprintf(*streamFile, "%s", file); + printf("\n"); + break; + case 1: + *streamFile = "Linear-Congruential"; + break; + case 2: + *streamFile = "Quadratic-Congruential-1"; + break; + case 3: + *streamFile = "Quadratic-Congruential-2"; + break; + case 4: + *streamFile = "Cubic-Congruential"; + break; + case 5: + *streamFile = "XOR"; + break; + case 6: + *streamFile = "Modular-Exponentiation"; + break; + case 7: + *streamFile = "Blum-Blum-Shub"; + break; + case 8: + *streamFile = "Micali-Schnorr"; + break; + case 9: + *streamFile = "G using SHA-1"; + break; + + /* INTRODUCE NEW PRNG NAMES HERE */ + /* + case 10: *streamFile = "myNewPRNG"; + break; + */ + default: + printf("Error: Out of range - Try again!\n"); + break; + } + } + return option; +} + + +void +chooseTests() +{ + int i; + + printf(" S T A T I S T I C A L T E S T S\n"); + printf(" _________________________________\n\n"); + printf(" [01] Frequency [02] Block Frequency\n"); + printf(" [03] Cumulative Sums [04] Runs\n"); + printf(" [05] Longest Run of Ones [06] Rank\n"); + printf(" [07] Discrete Fourier Transform [08] Nonperiodic Template Matchings\n"); + printf(" [09] Overlapping Template Matchings [10] Universal Statistical\n"); + printf(" [11] Approximate Entropy [12] Random Excursions\n"); + printf(" [13] Random Excursions Variant [14] Serial\n"); + printf(" [15] Linear Complexity\n\n"); + printf(" INSTRUCTIONS\n"); + printf(" Enter 0 if you DO NOT want to apply all of the\n"); + printf(" statistical tests to each sequence and 1 if you DO.\n\n"); + printf(" Enter Choice: "); + scanf("%d", &testVector[0]); + printf("\n"); + if ( testVector[0] == 1 ) + { + for( i=1; i<=NUMOFTESTS; i++ ) + testVector[i] = 1; + + // Disable Fast Fourier Transform Test. + // NIST has discovered a problem with the Fast Fourier Transform test. + // At this time NIST advises disregarding the results of this test until + // a further update is posted. + // Link: http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html + // + // When the FFT test is fixed remove the following 5 lines. + printf(" Please Note: \n"); + printf(" NIST has discovered a problem with the DFT test and hence the DFT results are invalid currently.\n"); + printf(" DFT test will be disabled at the momemt in the NIST test suite run \n \n"); + testVector[TEST_FFT] = 0; + testVector[0] = 0; + } + else { + printf(" INSTRUCTIONS\n"); + printf(" Enter a 0 or 1 to indicate whether or not the numbered statistical\n"); + printf(" test should be applied to each sequence.\n\n"); + printf(" 123456789111111\n"); + printf(" 012345\n"); + printf(" "); + for ( i=1; i<=NUMOFTESTS; i++ ) + scanf("%1d", &testVector[i]); + printf("\n\n"); + } +} + + +void +fixParameters() +{ + int counter, testid; + + // Check to see if any parameterized tests are selected + if ( (testVector[TEST_BLOCK_FREQUENCY] != 1) && (testVector[TEST_NONPERIODIC] != 1) && + (testVector[TEST_OVERLAPPING] != 1) && (testVector[TEST_APEN] != 1) && + (testVector[TEST_SERIAL] != 1) && (testVector[TEST_LINEARCOMPLEXITY] != 1) ) + return; + + do { + counter = 1; + printf(" P a r a m e t e r A d j u s t m e n t s\n"); + printf(" -----------------------------------------\n"); + if ( testVector[TEST_BLOCK_FREQUENCY] == 1 ) + printf(" [%d] Block Frequency Test - block length(M): %d\n", counter++, tp.blockFrequencyBlockLength); + if ( testVector[TEST_NONPERIODIC] == 1 ) + printf(" [%d] NonOverlapping Template Test - block length(m): %d\n", counter++, tp.nonOverlappingTemplateBlockLength); + if ( testVector[TEST_OVERLAPPING] == 1 ) + printf(" [%d] Overlapping Template Test - block length(m): %d\n", counter++, tp.overlappingTemplateBlockLength); + if ( testVector[TEST_APEN] == 1 ) + printf(" [%d] Approximate Entropy Test - block length(m): %d\n", counter++, tp.approximateEntropyBlockLength); + if ( testVector[TEST_SERIAL] == 1 ) + printf(" [%d] Serial Test - block length(m): %d\n", counter++, tp.serialBlockLength); + if ( testVector[TEST_LINEARCOMPLEXITY] == 1 ) + printf(" [%d] Linear Complexity Test - block length(M): %d\n", counter++, tp.linearComplexitySequenceLength); + printf("\n"); + printf(" Select Test (0 to continue): "); + scanf("%1d", &testid); + printf("\n"); + + counter = 0; + if ( testVector[TEST_BLOCK_FREQUENCY] == 1 ) { + counter++; + if ( counter == testid ) { + printf(" Enter Block Frequency Test block length: "); + scanf("%d", &tp.blockFrequencyBlockLength); + printf("\n"); + continue; + } + } + if ( testVector[TEST_NONPERIODIC] == 1 ) { + counter++; + if ( counter == testid ) { + printf(" Enter NonOverlapping Template Test block Length: "); + scanf("%d", &tp.nonOverlappingTemplateBlockLength); + printf("\n"); + continue; + } + } + if ( testVector[TEST_OVERLAPPING] == 1 ) { + counter++; + if ( counter == testid ) { + printf(" Enter Overlapping Template Test block Length: "); + scanf("%d", &tp.overlappingTemplateBlockLength); + printf("\n"); + continue; + } + } + if ( testVector[TEST_APEN] == 1 ) { + counter++; + if ( counter == testid ) { + printf(" Enter Approximate Entropy Test block Length: "); + scanf("%d", &tp.approximateEntropyBlockLength); + printf("\n"); + continue; + } + } + if ( testVector[TEST_SERIAL] == 1 ) { + counter++; + if ( counter == testid ) { + printf(" Enter Serial Test block Length: "); + scanf("%d", &tp.serialBlockLength); + printf("\n"); + continue; + } + } + if ( testVector[TEST_LINEARCOMPLEXITY] == 1 ) { + counter++; + if ( counter == testid ) { + printf(" Enter Linear Complexity Test block Length: "); + scanf("%d", &tp.linearComplexitySequenceLength); + printf("\n"); + continue; + } + } + } while ( testid != 0 ); +} + + +void +fileBasedBitStreams(char *streamFile) +{ + FILE *fp; + int mode; + + printf(" Input File Format:\n"); + printf(" [0] ASCII - A sequence of ASCII 0's and 1's\n"); + printf(" [1] Binary - Each byte in data file contains 8 bits of data\n\n"); + printf(" Select input mode: "); + scanf("%1d", &mode); + printf("\n"); + if ( mode == 0 ) { + if ( (fp = fopen(streamFile, "r")) == NULL ) { + printf("ERROR IN FUNCTION fileBasedBitStreams: file %s could not be opened.\n", streamFile); + exit(-1); + } + readBinaryDigitsInASCIIFormat(fp, streamFile); + fclose(fp); + } + else if ( mode == 1 ) { + if ( (fp = fopen(streamFile, "rb")) == NULL ) { + printf("ERROR IN FUNCTION fileBasedBitStreams: file %s could not be opened.\n", streamFile); + exit(-1); + } + readHexDigitsInBinaryFormat(fp); + fclose(fp); + } +} + + +void +readBinaryDigitsInASCIIFormat(FILE *fp, char *streamFile) +{ + int i, j, num_0s, num_1s, bitsRead, bit; + + if ( (epsilon = (BitSequence *) calloc(tp.n, sizeof(BitSequence))) == NULL ) { + printf("BITSTREAM DEFINITION: Insufficient memory available.\n"); + printf("Statistical Testing Aborted!\n"); + return; + } + printf(" Statistical Testing In Progress.........\n\n"); + for ( i=0; i>= 1; + epsilon[*bitsRead] = (BitSequence)bit; + (*bitsRead)++; + if ( *bitsRead == bitsNeeded ) + return 1; + if ( ++count == xBitLength ) + return 0; + } + } + + return 0; +} + + +void +openOutputStreams(int option) +{ + int i, numOfBitStreams, numOfOpenFiles = 0; + char freqfn[200], statsDir[200], resultsDir[200]; + TBuf16<200> logFilePath; + logFilePath.Copy(_L("c:\\nist")); + + printf(" Directory for logs : "); + gConsole->Printf(logFilePath); + ReadStringFromConsole(logFilePath); + gConsole->Printf(_L("\r\n")); + gLogFilePath.Copy(logFilePath); + + TBuf8<100> tempName; + TBuf<100> directoryName; + + for(i = 1; i <= NUMOFTESTS; ++i) + { + tempName.Format(_L8("%s\\experiments\\%s\\%s\\"), gLogFilePath.PtrZ(), generatorDir[option], testNames[i]); + directoryName.Copy(tempName); + gFileSession.MkDirAll(directoryName); + } + + sprintf(freqfn, "%s\\experiments\\%s\\freq", gLogFilePath.PtrZ(), generatorDir[option]); + if ( (freqfp = fopen(freqfn, "w")) == NULL ) { + printf("\t\tMAIN: Could not open freq file: experiments/%s/freq", generatorDir[option]); + exit(-1); + } + + TBuf8<512> finalAnalysisReport; + finalAnalysisReport.Format(_L8("%s\\finalAnalysisReport"), gLogFilePath.PtrZ()); + + if ( (summary = fopen((const char *)finalAnalysisReport.PtrZ(), "w")) == NULL ) { + printf("\t\tMAIN: Could not open stats file: %s\\experiments\\%s\\finalAnalysisReport",gLogFilePath.PtrZ(), generatorDir[option]); + exit(-1); + } + + for( i=1; i<=NUMOFTESTS; i++ ) { + if ( testVector[i] == 1 ) { + sprintf(statsDir, "%s\\experiments\\%s\\%s\\stats", gLogFilePath.PtrZ(), generatorDir[option], testNames[i]); + sprintf(resultsDir, "%s\\experiments\\%s\\%s\\results", gLogFilePath.PtrZ(), generatorDir[option], testNames[i]); + if ( (stats[i] = fopen(statsDir, "w")) == NULL ) { /* STATISTICS LOG */ + printf("ERROR: LOG FILES COULD NOT BE OPENED.\n"); + printf(" MAX # OF OPENED FILES HAS BEEN REACHED = %d\n", numOfOpenFiles); + printf("-OR- THE OUTPUT DIRECTORY DOES NOT EXIST.\n"); + exit(-1); + } + else + numOfOpenFiles++; + if ( (results[i] = fopen(resultsDir, "w")) == NULL ) { /* P_VALUES LOG */ + printf("ERROR: LOG FILES COULD NOT BE OPENED.\n"); + printf(" MAX # OF OPENED FILES HAS BEEN REACHED = %d\n", numOfOpenFiles); + printf("-OR- THE OUTPUT DIRECTORY DOES NOT EXIST.\n"); + exit(-1); + } + else + numOfOpenFiles++; + } + } + printf(" How many bitstreams? "); + scanf("%d", &numOfBitStreams); + tp.numOfBitStreams = numOfBitStreams; + printf("\n"); +} + + +void +invokeTestSuite(int option, char *streamFile) +{ + fprintf(freqfp, "________________________________________________________________________________\n\n"); + fprintf(freqfp, "\t\tALPHA = %6.4f\n", ALPHA); + fprintf(freqfp, "________________________________________________________________________________\n\n"); + if ( option != 0 ) + printf(" Statistical Testing In Progress.........\n\n"); + switch( option ) { + case 0: + fileBasedBitStreams(streamFile); + break; + case 1: + lcg(); + break; + case 2: + quadRes1(); + break; + case 3: + quadRes2(); + break; + case 4: + cubicRes(); + break; + case 5: + exclusiveOR(); + break; + case 6: + modExp(); + break; + case 7: + bbs(); + break; + case 8: + micali_schnorr(); + break; + case 9: + SHA1(); + break; + case 10: + HASH_DRBG(); + break; + + /* INTRODUCE NEW PSEUDO RANDOM NUMBER GENERATORS HERE */ + + default: + printf("Error in invokeTestSuite!\n"); + break; + } + printf(" Statistical Testing Complete!!!!!!!!!!!!\n\n"); +} + + +void +nist_test_suite() +{ + if ( (testVector[0] == 1) || (testVector[TEST_FREQUENCY] == 1) ) + Frequency(tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_BLOCK_FREQUENCY] == 1) ) + BlockFrequency(tp.blockFrequencyBlockLength, tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_CUSUM] == 1) ) + CumulativeSums(tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_RUNS] == 1) ) + Runs(tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_LONGEST_RUN] == 1) ) + LongestRunOfOnes(tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_RANK] == 1) ) + Rank(tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_FFT] == 1) ) + { + // Disable Fast Fourier Transform Test. + // NIST has discovered a problem with the Fast Fourier Transform test. + // At this time NIST advises disregarding the results of this test until + // a further update is posted. + // Link: http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html + // + // When the FFT test is fixed remove the following 3 printf lines and uncomment the 4th line. + printf(" Please Note: NIST has discovered a problem with the DFT test and hence\n"); + printf(" the DFT results are invalid currently.\n"); + printf(" So all tests except DFT will run until futher notification from NIST \n \n"); + //DiscreteFourierTransform(tp.n); + } + + if ( (testVector[0] == 1) || (testVector[TEST_NONPERIODIC] == 1) ) + NonOverlappingTemplateMatchings(tp.nonOverlappingTemplateBlockLength, tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_OVERLAPPING] == 1) ) + OverlappingTemplateMatchings(tp.overlappingTemplateBlockLength, tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_UNIVERSAL] == 1) ) + Universal(tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_APEN] == 1) ) + ApproximateEntropy(tp.approximateEntropyBlockLength, tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION] == 1) ) + RandomExcursions(tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION_VAR] == 1) ) + RandomExcursionsVariant(tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_SERIAL] == 1) ) + Serial(tp.serialBlockLength,tp.n); + + if ( (testVector[0] == 1) || (testVector[TEST_LINEARCOMPLEXITY] == 1) ) + LinearComplexity(tp.linearComplexitySequenceLength, tp.n); +} + +void GetNextTemplateItem(BitSequence aBitSequence[]) + { + int count = (TInt)pow(2, tp.overlappingTemplateBlockLength); + + for(bool isSuccess = false; (!isSuccess) && (gTemplateIndex < count); ++gTemplateIndex) + { + isSuccess = ConvertToAperiodicBits(aBitSequence, gTemplateIndex); + } + } + + +bool ConvertToAperiodicBits(BitSequence aSequence[32], long value) + { + int bitMask = int(1U << (KMaxBit-1)); + + long count = tp.overlappingTemplateBlockLength; + + for(int c = 0; c < KMaxBit; c++) + { + if (value & bitMask) + aSequence[c] = 1; + else + aSequence[c] = 0; + value <<= 1; + } + + bool match = false; + + for(int i = 1; i < count; i++) + { + match = false; + if ((aSequence[KMaxBit-count]!= aSequence[KMaxBit-1]) && ((aSequence[KMaxBit-count]!= aSequence[KMaxBit-2])||(aSequence[KMaxBit-count+1] != aSequence[KMaxBit-1]))) + { + for(int c = KMaxBit-count; c <= (KMaxBit-1)-i; c++) + { + if (aSequence[c] != aSequence[c+i]) + { + match = true; + break; + } + } + } + + if (!match) + { + break; + } + } + + return match; + } + diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/e32utils/nistsecurerng/testdata/testdata.zip Binary file kerneltest/e32utils/nistsecurerng/testdata/testdata.zip has changed diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/f32test/loader/dlltree.txt --- a/kerneltest/f32test/loader/dlltree.txt Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/f32test/loader/dlltree.txt Mon Oct 18 15:31:10 2010 +0100 @@ -212,8 +212,8 @@ # just add some data paged executables so loading gets OOM tested -DataPagedExe1 X PD T -DataPagedExe2 X PD D T +DataPagedExe1 X B PD I T +DataPagedExe2 X B PD D I T !TESTCASES diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/f32test/server/t_falsespace.cpp --- a/kerneltest/f32test/server/t_falsespace.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/f32test/server/t_falsespace.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -30,6 +30,9 @@ const TInt KNumberThreads=2; const TInt KHeapSize=0x2000; +//-- this is taken from the file server. Hardcoded constant that specifies session limits on reserving the drive space +const TInt KMaxSessionDriveReserved =0x10000; + static TInt RsrvSpaceThread(TAny* aArg); static TInt SessCloseThread(TAny* aArg); static void GetFreeDiskSpace(TInt64 &aFree); @@ -80,6 +83,24 @@ User::WaitForRequest(s); } +//----------------------------------------------------------------------------- +/** + Get a cluster size for the currently mounted FS (if it supports clusters). + @return 0 if there was an error (e.g. cluster size query is not supported), otherwise a cluster size +*/ +static TUint32 FsClusterSize() +{ + TVolumeIOParamInfo volIop; + TInt nRes = TheFs.VolumeIOParam(gTestDrive, volIop); + + if(nRes != KErrNone || volIop.iClusterSize < 512 || !IsPowerOf2(volIop.iClusterSize)) + { + test.Printf(_L("FsClusterSize() The FS hasn't reported a cluster size\n")); + return 0; + } + + return volIop.iClusterSize; +} static TInt CreateFileX(const TDesC& aBaseName,TInt aX, TInt aFileSize) // @@ -147,8 +168,7 @@ // Test that a full disk is ok // { - - test.Start(_L("Fill disk to capacity")); + test.Next(_L("Fill disk to capacity\n")); TInt r=TheFs.MkDirAll(KBasePath); test_Value(r, r == KErrNone || r==KErrAlreadyExists); gCount=0; @@ -211,8 +231,6 @@ while (freespaceBeforeScanDrive != freespaceAfterScanDrive ); gCount--; - - test.End(); } static void GetFreeDiskSpace(TInt64 &aFree) @@ -233,7 +251,7 @@ // Test the API fundamentaly works for one session // { - test.Next(_L("Test Disk Space reserve APIs")); + test.Next(_L("Test Disk Space reserve APIs\n")); TInt r=0; FormatDrive(); @@ -303,7 +321,7 @@ // { - test.Next(_L("Test Session and total reserve limits")); + test.Next(_L("Test Session and total reserve limits\n")); FormatDrive(); @@ -319,7 +337,7 @@ test_KErrNone(r); } - test.Next(_L("Test breaching sesson reserve limit")); + test.Next(_L("Test breaching sesson reserve limit\n")); r=sessions[0].ReserveDriveSpace(gTestDrive,0x10001); test_Value(r, r == KErrArgument); @@ -328,7 +346,7 @@ if(v.iFree > 0x100000) { - test.Next(_L("Test breaching drive reserve limit")); + test.Next(_L("Test breaching drive reserve limit\n")); for (i=0; i<16; i++) { @@ -343,7 +361,7 @@ else { test.Printf(_L("Drive too small: breaching drive reserve limit test skipped\n")); - test.Next(_L("Testing exhausting available drive free space instead")); + test.Next(_L("Testing exhausting available drive free space instead\n")); for(i=0; (v.iFree -= 0x10000) >= 0; i++) { @@ -368,7 +386,7 @@ // Test session cleanup // { - test.Next(_L("Test session close and clean up of resrved space")); + test.Next(_L("Test session close and clean up of resrved space\n")); FormatDrive(); @@ -439,16 +457,26 @@ // reserve an area etc // { - test.Next(_L("Test Filling disk and using APIs")); + test.Next(_L("Test Filling disk and using APIs\n")); if(IsTestingLFFS()) { - //-- This test is not valid for LFFS, because free space on this FS can change itself because of some - //-- internal FS activities + //-- This test is not valid for LFFS, because free space on this FS can change itself because of some internal FS activities test.Printf(_L("This test is inconsistent on LFFS\n")); return; } + + const TInt KThreshold = 0x10000; + + //-- check that the cluster size doesn't exceed the max. limit + const TInt KClusterSz = FsClusterSize(); + if(KClusterSz > KThreshold) + { + test.Printf(_L("The cluster size(%d) is bigger than threshold to test (%d)! Skipping the test!\n"), KClusterSz, KThreshold); + return; + } + FormatDrive(); RFs fs; @@ -473,7 +501,7 @@ file.Close(); - r=fs.ReserveDriveSpace(gTestDrive,0x10000); //reserve some disk space + r=fs.ReserveDriveSpace(gTestDrive,KThreshold); //reserve some disk space test_KErrNone(r); FillUpDisk(); //fill up the disk @@ -493,7 +521,7 @@ r=fs.ReleaseReserveAccess(gTestDrive); //release reserve space test_KErrNone(r); - test(freeA == (freeB - 0x10000)); //test difference in space is equal to the amount reserved + test(freeA == (freeB - KThreshold)); //test difference in space is equal to the amount reserved r=fs.Volume(v,gTestDrive); //get disk space test_KErrNone(r); @@ -611,7 +639,7 @@ // // { - test.Next(_L("Test Session limits")); + test.Next(_L("Test Session limits\n")); if(IsTestingLFFS()) { @@ -731,7 +759,7 @@ // { - test.Next(_L("Test sharable session")); + test.Next(_L("Test sharable session\n")); RFs fsess; TInt r=KErrNone; @@ -787,6 +815,8 @@ // Tests notifier events for sessions with and without reserved access // { + test.Next(_L("Test reserved access notification\n")); + if(IsTestingLFFS()) { // This test is not valid for LFFS... @@ -794,11 +824,26 @@ return; } - - test.Next(_L("Test reserved access notification")); - FormatDrive(); + //-- find out the cluster size + const TInt KClusterSz = FsClusterSize(); + if(!IsPowerOf2(KClusterSz)) + { + test.Printf(_L("The FS hasn't reported a cluster size. The test is inconsistent, skipping\n")); + return; + } + + //-- check that the cluster size doesn't exceed the max. limit + if(KClusterSz > KMaxSessionDriveReserved) + { + test.Printf(_L("The cluster size(%d) is bigger than reserve limit (%d)! Skipping the test!\n"), KClusterSz, KMaxSessionDriveReserved); + return; + } + + + const TInt resSpace = Max(0x1000, KClusterSz); + RFs theNrm; RFs theRes; @@ -823,25 +868,6 @@ err = theTestSession.Connect(); test_KErrNone(err); - // determine the cluster size - RFile theFile; - err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite); - test_KErrNone(err); - - // Neither notifier should be triggered here - err = theFile.SetSize(1); - test(KErrNone == err); - theFile.Close(); - - TInt64 newFreeSpace; - GetFreeDiskSpace(newFreeSpace); - TInt clusterSize = TInt(freeSpace - newFreeSpace); - theTestSession.Delete(fileName); - GetFreeDiskSpace(newFreeSpace); - test (newFreeSpace == freeSpace); - - TInt resSpace = Max(0x1000, clusterSize); - TVolumeInfo volInfo; theNrm.Volume(volInfo, gTestDrive); test(volInfo.iFree == freeSpace); @@ -858,6 +884,8 @@ test(volInfo.iFree == freeSpace - resSpace); + RFile theFile; + // // Register the notifiers and verify that the only the "Normal" // and not the "Reserved" session is triggered. @@ -918,7 +946,7 @@ LOCAL_C void TestForDEF142554() { - test.Next(_L("Test for DEF142554: test RFile::Modified and RFile::Att when disk full")); + test.Next(_L("Test for DEF142554: test RFile::Modified and RFile::Att when disk full\n")); Format(gTestDrive); @@ -990,7 +1018,7 @@ { const TInt64 K4Gig = 4*(TInt64)K1GigaByte; - test.Next(_L("Test files crossing 4G boundary on FAT")); + test.Next(_L("Test files crossing 4G boundary on FAT\n")); if(!Is_Fat32(TheFs, gTestDrive)) { @@ -1056,7 +1084,7 @@ void TestRAMDriveNotification() { - test.Next(_L("Verifying RFs::ReserveDriveSpace() triggers RFs::NotifyDiskSpace() events")); + test.Next(_L("Verifying RFs::ReserveDriveSpace() triggers RFs::NotifyDiskSpace() events\n")); TInt64 freeSpace; GetFreeDiskSpace(freeSpace); @@ -1065,19 +1093,19 @@ // set a notification on half the amount we plan to reserve TInt reserve = 4096; TInt64 trigger = freeSpace - 2048; - test.Printf(_L("setting notification for space to fall below: 0x%Lx bytes ... "), trigger); + test.Printf(_L("setting notification for space to fall below: 0x%Lx bytes ... \n"), trigger); TRequestStatus stat; TheFs.NotifyDiskSpace(trigger, gTestDrive, stat); test_Value(stat.Int(), stat == KRequestPending); test.Printf(_L("ok\n")); // reserve the space and validate that this triggers the notification - test.Printf(_L("reserving 0x%x bytes ..."), reserve); + test.Printf(_L("reserving 0x%x bytes ...\n"), reserve); TInt r = TheFs.ReserveDriveSpace(gTestDrive, reserve); test_KErrNone(r); test.Printf(_L("ok\n")); - test.Printf(_L("validating that the disk space notification triggered ... ")); + test.Printf(_L("validating that the disk space notification triggered ...\n")); User::After(2000000); // 2 seconds should be enough to cause the trigger test_Value(stat.Int(), stat == KErrNone); test.Printf(_L("ok\n")); @@ -1090,10 +1118,9 @@ */ void Test0() { - test.Next(_L("test ReserveDriveSpace threshold")); + test.Next(_L("test ReserveDriveSpace threshold\n")); TInt nRes; - TVolumeIOParamInfo volIop; TInt64 freespace=0; //-- 1. format the volume @@ -1102,15 +1129,21 @@ GetFreeDiskSpace(freespace); const TInt64 freeSpace1 = freespace; //-- initial amount of free space on the volume - nRes = TheFs.VolumeIOParam(gTestDrive, volIop); - test_KErrNone(nRes); - const TInt KClusterSz = volIop.iClusterSize; + const TInt KClusterSz = FsClusterSize(); if(!IsPowerOf2(KClusterSz)) { - test.Next(_L("The FS hasn't reported a cluster size. The test is inconsistent, skipping")); + test.Printf(_L("The FS hasn't reported a cluster size. The test is inconsistent, skipping\n")); return; } + //-- check that the cluster size doesn't exceed the max. limit + if(KClusterSz > KMaxSessionDriveReserved) + { + test.Printf(_L("The cluster size(%d) is bigger than reserve limit (%d)! Skipping the test!\n"), KClusterSz, KMaxSessionDriveReserved); + return; + } + + //-- reserve exactly 1 cluster worth drive space. nRes = TheFs.ReserveDriveSpace(gTestDrive, KClusterSz); test_KErrNone(nRes); @@ -1162,7 +1195,7 @@ // If TESTFAST mode (for automated test builds) is set, don't run LFFS tests. if ((UserSvr::DebugMask(2) & 0x00000002) && IsTestingLFFS()) { - test.Printf(_L("TEST NOT RUN FOR LFFS DRIVE")); + test.Printf(_L("TEST NOT RUN FOR LFFS DRIVE\n")); return; } diff -r 55a0a1279a7e -r 206a6eaaeb71 kerneltest/f32test/server/t_fsys.cpp --- a/kerneltest/f32test/server/t_fsys.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/kerneltest/f32test/server/t_fsys.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -697,7 +697,7 @@ test(remounts == KMaxMountFailures); // simulate a media change to reset failure count - r = TheFs.RemountDrive(aDrive, NULL, 0); + r = TheFs.RemountDrive(aDrive, NULL, RFs::KForceMediaChangeReOpenAllMediaDrivers); // now try mounting again & verify the the file server attempts to mount the drive again for (entryAttempts=0; entryAttempts < KEntryAttempts; entryAttempts++) @@ -1335,14 +1335,13 @@ nRes = TheFs.DismountFileSystem(fsName, drvNumber); test_Value(nRes, nRes == KErrInUse); - // Flag from locmedia.h to simulate ejecting and re-inserting the media. - const TUint KMediaRemountForceMediaChange = 0x00000001; + TRequestStatus changeStatus; TheFs.NotifyChange(ENotifyAll, changeStatus); - //-- 3. forcedly remount the drive - nRes = TheFs.RemountDrive(drvNumber, NULL, KMediaRemountForceMediaChange); + //-- 3. forcedly remount the drive to simulate ejecting and re-inserting the media. + nRes = TheFs.RemountDrive(drvNumber, NULL, RFs::KMediaRemountForceMediaChange); if(nRes == KErrNotSupported) {//-- this feature is not supported and the test is inconsistent. diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/etshell/ts_com.cpp --- a/userlibandfileserver/fileserver/etshell/ts_com.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/etshell/ts_com.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -338,7 +338,7 @@ if (nRes != KErrNone) { - CShell::TheConsole->Printf(_L("Wrong drive specified!\n")); + CShell::Printf(_L("Wrong drive specified!\n")); return nRes; } @@ -348,7 +348,7 @@ nRes=TheShell->TheFs.ScanDrive(aPath); if(nRes == KErrNone) { - CShell::TheConsole->Printf(_L("No errors.\n")); + CShell::Printf(_L("No errors.\n")); } } else if(bFinaliseDrv) @@ -357,7 +357,7 @@ if(nRes != KErrNone) return nRes; - CShell::TheConsole->Printf(_L("Drive %c: is finalised RW\n"), 'A'+drive); + CShell::Printf(_L("Drive %c: is finalised RW\n"), 'A'+drive); } else if(bUnFinaliseDrv) {//-- Unfinalise the drive @@ -365,7 +365,7 @@ if(nRes != KErrNone) return nRes; - CShell::TheConsole->Printf(_L("Drive %c: is Unfinalised\n"), 'A'+drive); + CShell::Printf(_L("Drive %c: is Unfinalised\n"), 'A'+drive); } else {//-- run CheckDisk on the specified drive @@ -377,22 +377,22 @@ switch(nRes) { case 0: - CShell::TheConsole->Printf(_L("Completed - no errors found\n")); + CShell::Printf(_L("Completed - no errors found\n")); break; case 1: - CShell::TheConsole->Printf(_L("Error - File cluster chain contains a bad value (<2 or >maxCluster)\n")); + CShell::Printf(_L("Error - File cluster chain contains a bad value (<2 or >maxCluster)\n")); break; case 2: - CShell::TheConsole->Printf(_L("Error - Two files are linked to the same cluster\n")); + CShell::Printf(_L("Error - Two files are linked to the same cluster\n")); break; case 3: - CShell::TheConsole->Printf(_L("Error - Unallocated cluster contains a value != 0\n")); + CShell::Printf(_L("Error - Unallocated cluster contains a value != 0\n")); break; case 4: - CShell::TheConsole->Printf(_L("Error - Size of file != number of clusters in chain\n")); + CShell::Printf(_L("Error - Size of file != number of clusters in chain\n")); break; default: - CShell::TheConsole->Printf(_L("Undefined Error value\n")); + CShell::Printf(_L("Undefined Error value\n")); } } return nRes; @@ -1494,12 +1494,12 @@ nRes = aFs.DismountFileSystem(fsName, aDrvNum); if(nRes != KErrNone) { - CShell::TheConsole->Printf(_L("Can't dismount FS!\n")); + CShell::Printf(_L("Can't dismount FS!\n")); return nRes; } else { - CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum); + CShell::Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum); return KErrNone; } } @@ -1509,7 +1509,7 @@ aFs.NotifyDismount(aDrvNum, rqStat, EFsDismountForceDismount); User::WaitForRequest(rqStat); - CShell::TheConsole->Printf(_L("'%S' filesystem Forcedly dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum); + CShell::Printf(_L("'%S' filesystem Forcedly dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum); return rqStat.Int(); } @@ -1551,7 +1551,7 @@ nRes = aFs.ExtensionName(extName, aDrvNum, 1); if(nRes == KErrNone) { - CShell::TheConsole->Printf(_L("Non-primary extensions are not supported!\n")); + CShell::Printf(_L("Non-primary extensions are not supported!\n")); return KErrNotSupported; } } @@ -1579,7 +1579,7 @@ if(nRes == KErrNone) { - CShell::TheConsole->Printf(_L("mounted filesystem:%S\n"), &fsName); + CShell::Printf(_L("mounted filesystem:%S\n"), &fsName); } return nRes; @@ -1630,7 +1630,7 @@ nRes = DoExtractDriveLetter(token); if(nRes < 0) { - CShell::TheConsole->Printf(KErrInvalidDrive); + CShell::Printf(KErrInvalidDrive); return KErrArgument; } @@ -1651,7 +1651,7 @@ if(nRes == KErrNotFound) {//-- nothing to dismount - CShell::TheConsole->Printf(_L("specified drive doesn't have FS mounted\n")); + CShell::Printf(_L("specified drive doesn't have FS mounted\n")); return KErrNone; } @@ -1673,8 +1673,8 @@ nRes = fs.FileSystemName(fsName, drvNum); if(nRes == KErrNone) { - CShell::TheConsole->Printf(_L("specified drive already has '%S' file system mounted.\n"), &fsName); - CShell::TheConsole->Printf(_L("Dismount it first using '/U' switch or use '/F' switch.\n")); + CShell::Printf(_L("specified drive already has '%S' file system mounted.\n"), &fsName); + CShell::Printf(_L("Dismount it first using '/U' switch or use '/F' switch.\n")); return KErrNone; } @@ -1692,13 +1692,13 @@ if(!DoFindToken(aArgs, KFSY_Param, ptrFSYName)) {//-- FSY plugin name, like "elocal.fsy" - CShell::TheConsole->Printf(_L("'%S' parameter is required!\n"), &KFSY_Param); + CShell::Printf(_L("'%S' parameter is required!\n"), &KFSY_Param); return KErrNone; } if(!DoFindToken(aArgs, KFsName_Param, ptrFSName)) {//-- file system name, like "FAT" - CShell::TheConsole->Printf(_L("'%S' parameter is required!\n"), &KFsName_Param); + CShell::Printf(_L("'%S' parameter is required!\n"), &KFsName_Param); return KErrNone; } @@ -1714,7 +1714,7 @@ nRes = fs.AddFileSystem(ptrFSYName); if(nRes != KErrNone && nRes != KErrAlreadyExists) { - CShell::TheConsole->Printf(_L("Can't load '%S' file system plugin!\n"), &ptrFSYName); + CShell::Printf(_L("Can't load '%S' file system plugin!\n"), &ptrFSYName); return nRes; } @@ -1723,7 +1723,7 @@ nRes = fs.AddExtension(ptrPExtName); if(nRes != KErrNone && nRes != KErrAlreadyExists) { - CShell::TheConsole->Printf(_L("Can't load '%S' FS extension plugin!\n"), &ptrPExtName); + CShell::Printf(_L("Can't load '%S' FS extension plugin!\n"), &ptrPExtName); return nRes; } } @@ -1738,11 +1738,11 @@ nRes = fs.MountFileSystem(ptrFSName, drvNum, bDrvSynch); } - CShell::TheConsole->Printf(_L("Mounting new file system...\n")); + CShell::Printf(_L("Mounting new file system...\n")); if(nRes != KErrNone && nRes != KErrCorrupt) {//-- KErrCorrupt might mean that the FS mounted OK onto the drive, but ve volume itself needs formatting - CShell::TheConsole->Printf(_L("Error mounting the filesystem! (%d)\n"), nRes); + CShell::Printf(_L("Error mounting the filesystem! (%d)\n"), nRes); return nRes; } @@ -1810,7 +1810,7 @@ const TInt nDrv = DoExtractDriveLetter(ptrPath); if(nDrv < 0 ) { - CShell::TheConsole->Printf(_L("type \"format /?\" for help.\n")); + CShell::Printf(_L("type \"format /?\" for help.\n")); return KErrNone; } @@ -1908,7 +1908,7 @@ } else { - CShell::TheConsole->Printf(_L("Invalid SectorsPerCluster value!\n")); + CShell::Printf(_L("Invalid SectorsPerCluster value!\n")); return KErrNone; } } @@ -1925,7 +1925,7 @@ } else { - CShell::TheConsole->Printf(_L("Invalid Reserved Sectors value!\n")); + CShell::Printf(_L("Invalid Reserved Sectors value!\n")); return KErrNone; } } @@ -1942,7 +1942,7 @@ } else { - CShell::TheConsole->Printf(_L("Invalid FAT tables number value!\n")); + CShell::Printf(_L("Invalid FAT tables number value!\n")); return KErrNone; } } @@ -1967,7 +1967,7 @@ } else { - CShell::TheConsole->Printf(_L("Invalid SectorsPerCluster value!\n")); + CShell::Printf(_L("Invalid SectorsPerCluster value!\n")); return KErrNone; } } @@ -1984,7 +1984,7 @@ } else { - CShell::TheConsole->Printf(_L("Invalid FAT tables number value!\n")); + CShell::Printf(_L("Invalid FAT tables number value!\n")); return KErrNone; } } @@ -1999,7 +1999,7 @@ } else { - CShell::TheConsole->Printf(_L("The new file system is:%S\n"), &fsName); + CShell::Printf(_L("The new file system is:%S\n"), &fsName); nRes = format.Open(TheShell->TheFs, ptrPath, fmtMode, fmtCnt, volFmtParamBuf); } @@ -2028,28 +2028,28 @@ //-- format errors processing if(nRes != KErrNone) { - CShell::TheConsole->Printf(_L("Format failed.\n")); + CShell::Printf(_L("Format failed.\n")); } switch(nRes) { case KErrNone: - CShell::TheConsole->Printf(_L("Format complete.\n")); + CShell::Printf(_L("Format complete.\n")); break; case KErrArgument: //-- FORMAT has rejected specified parameters - CShell::TheConsole->Printf(_L("Possible reason: Invalid combination of formatting parameters.\n")); + CShell::Printf(_L("Possible reason: Invalid combination of formatting parameters.\n")); nRes = KErrNone; break; case KErrNotSupported: //-- trying to format SD card with parameters or not supported FS name specified - CShell::TheConsole->Printf(_L("Possible reasons: media does not support special formatting or specified file system is not supported\n")); + CShell::Printf(_L("Possible reasons: media does not support special formatting or specified file system is not supported\n")); nRes = KErrNone; break; case KErrNotFound: //-- possible reason: unrecognisable media and automounter FS + formatting without specifying the FS name - CShell::TheConsole->Printf(_L("Possible reason: Unable to chose appropriate file system (not specified)\n")); + CShell::Printf(_L("Possible reason: Unable to chose appropriate file system (not specified)\n")); nRes = KErrNone; break; @@ -2146,7 +2146,7 @@ TInt fileNameLen=aPath.LocateReverse(' '); if (fileNameLen==KErrNotFound) // No spaces implies no filelength specified { - CShell::TheConsole->Printf(_L("Please specify a file name and a file length\n")); + CShell::Printf(_L("Please specify a file name and a file length\n")); return (KErrNone); } @@ -2164,7 +2164,7 @@ TInt r=size.Val(fileSize,radix); if (r!=KErrNone || ! size.Eos()) { - CShell::TheConsole->Printf(_L("Please specify a file length\n")); + CShell::Printf(_L("Please specify a file length\n")); return (KErrNone); } @@ -2211,7 +2211,7 @@ //-- this can make write faster on rugged fat. if(aSwitches&TShellCommand::EESwitch) {//-- /e switch is specified, create an empty file without writing data - CShell::TheConsole->Printf(_L("Creating an empty file, size:%LD bytes\n"), fileSize); + CShell::Printf(_L("Creating an empty file, size:%LD bytes\n"), fileSize); } r=file.SetSize(fileSize); @@ -2249,8 +2249,8 @@ endTime.SecondsFrom(startTime, timeTaken); - CShell::TheConsole->Printf(_L("Total bytes written:%LD\n"), cntBytes); - CShell::TheConsole->Printf(_L("Time taken:%d Sec.\n"), timeTaken.Int()); + CShell::Printf(_L("Total bytes written:%LD\n"), cntBytes); + CShell::Printf(_L("Time taken:%d Sec.\n"), timeTaken.Int()); return r; @@ -2261,7 +2261,7 @@ if(r!= KErrAlreadyExists) //this is to ensure that an existing file does not get deleted CShell::TheFs.Delete(fileName.FullName()); - CShell::TheConsole->Printf(_L("Error - could not create file, code:%d\n"), r); + CShell::Printf(_L("Error - could not create file, code:%d\n"), r); return r; } @@ -3033,7 +3033,7 @@ r=directory.Open(TheShell->TheFs,dirPath.FullName(),KEntryAttMatchExclusive|KEntryAttDir); if (r!=KErrNone) { - CShell::TheConsole->Printf(_L("Directory %S was not found\n"),&dirPath.FullName()); + CShell::Printf(_L("Directory %S was not found\n"),&dirPath.FullName()); return (KErrNone); } directory.Close(); @@ -3041,10 +3041,10 @@ TInt ret=TheShell->TheFs.RmDir(dirPath.FullName()); if (ret==KErrNone) - CShell::TheConsole->Printf(_L("Directory %S was removed\n"),&dirPath.FullName()); + CShell::Printf(_L("Directory %S was removed\n"),&dirPath.FullName()); else if(ret==KErrInUse) { - CShell::TheConsole->Printf(_L("Directory %S is in use and cannot be deleted\n"),&dirPath.FullName()); + CShell::Printf(_L("Directory %S is in use and cannot be deleted\n"),&dirPath.FullName()); return KErrNone; } @@ -3069,11 +3069,14 @@ TInt ShellFunction::Time(TDes&,TUint /*aSwitches*/) { - TTime time; + + TTime time; time.HomeTime(); TDateTime dateTime(time.DateTime()); - CShell::TheConsole->Printf(_L(" %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); - return(KErrNone); + + CShell::Printf(_L(" %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+03d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); + + return KErrNone; } TInt ShellFunction::Trace(TDes& aState,TUint aSwitches) @@ -3359,6 +3362,7 @@ aPath.Insert(0,pathParse.FullName()); } +/* TBool ShellFunction::Certain() { CShell::TheConsole->Printf(_L("Are you sure? Y/N...")); @@ -3372,6 +3376,7 @@ CShell::TheConsole->Printf(_L("%c\n"),r); return(r=='Y'); } +*/ TInt ShellFunction::GetFullPath(TDes& aPath,TParse& aParse) // diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/etshell/ts_edshl.cpp --- a/userlibandfileserver/fileserver/etshell/ts_edshl.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/etshell/ts_edshl.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -1059,7 +1059,9 @@ readBuf.SetLength(r); readBuf.Trim(); - TheFs.SessionPath(currentPath); + r = TheFs.SessionPath(currentPath); + if(r!=KErrNone) + break; TheConsole->Printf(currentPath); TheConsole->Printf(_L(">%S\n"),&readBuf); @@ -1093,7 +1095,7 @@ file.Close(); - return KErrNone; + return r; } diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/fs_utils/bit_vector.cpp --- a/userlibandfileserver/fileserver/fs_utils/bit_vector.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/fs_utils/bit_vector.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -327,11 +327,11 @@ return FindNearest(aStartPos, aBitVal, EFalse); default: - Panic(EWrondFindDirection); - return EFalse; + break; + }; - }; - + Panic(EWrondFindDirection); + return EFalse; } //----------------------------------------------------------------------------- @@ -670,11 +670,9 @@ { if(aIdx == 0) return ETrue; - else - { - aIdx--; - return EFalse; - } + + aIdx--; + return EFalse; } //----------------------------------------------------------------------------- @@ -692,8 +690,8 @@ aIdx++; return EFalse; } - else - return ETrue; + + return ETrue; } //----------------------------------------------------------------------------- diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/group/release.txt --- a/userlibandfileserver/fileserver/group/release.txt Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/group/release.txt Mon Oct 18 15:31:10 2010 +0100 @@ -1,3 +1,17 @@ +Version 2.00.4006 +================= +(Made by fadhliM 13/10/2010) + +1. dlyokhin + 1. ou1cimx1#582827 RFormat causes all logical drives (associated with a primary removable media device) to be deleted and recreated + 2. ou1cimx1#603919 TDrive::ForceDismount() shouldn't finalise drive in RO mode + 3. ou1cimx1#602572 SD stack should correctly support SD cards larger than 32GB + +2. michcox + 1. ou1cimx1#512321 coverity defects - Fileserver - cases 125100, 126171, 130137 + 2. ou1cimx1#565164 Fix Change - coverity defects - Fileserver + + Version 2.00.4005 ================= (Made by fadhliM 04/10/2010) diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/inc/f32file.h --- a/userlibandfileserver/fileserver/inc/f32file.h Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/inc/f32file.h Mon Oct 18 15:31:10 2010 +0100 @@ -2106,7 +2106,7 @@ IMPORT_C TInt RemoveProxyDrive(const TDesC& aDriveName); template inline TInt MountProxyDrive(const TUint aDrive, const TDesC& aName, T0 a0, T1 a1) - { return(DoMountProxyDrive(TIpcArgs(aDrive, &aName, a0, a1))); }; + { return(DoMountProxyDrive(TIpcArgs(aDrive, &aName, a0, a1))); } IMPORT_C TInt DismountProxyDrive(const TUint aDrive); TInt Unclamp(const RFileClamp& aHandle); @@ -2152,6 +2152,33 @@ EFSRV_IMPORT_C TInt SupportedFileSystemName(TDes& aName, TInt aDrive, TInt aFsEnumerator) const; + + + /** + A set of special flags passed directly to the media driver via RFs::RemountDrive() API. + They are used to specify how exactly the drive should be remounted. For more information see RLocalDrive::ForceMediaChange() + @see RFs::RemountDrive() + */ + enum TForceMediaChangeFlags + { + /** + Passing this flag to RFs::RemountDrive() API results in all media drivers associated with the primary media being closed and reopened. + All pending requests on all logical drives associated with the primary media will be cancelled. + */ + KForceMediaChangeReOpenAllMediaDrivers = 0, + + /** + This flag is used to simulate ejecting and re-inserting the media. + All pending requests on all logical drives associated with the primary media will be cancelled. + */ + KMediaRemountForceMediaChange = 0x00000001, + + /** This flag is used to force the media driver for the specified logical drive to be closed and reopened. + It should not affect any pending requests on other logical drives associated with the primary media. + */ + KForceMediaChangeReOpenMediaDriver = 0x80000000 + }; + protected: TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs) const; diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/inc/f32ver.h --- a/userlibandfileserver/fileserver/inc/f32ver.h Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/inc/f32ver.h Mon Oct 18 15:31:10 2010 +0100 @@ -58,6 +58,6 @@ @see TVersion */ -const TInt KF32BuildVersionNumber=4005; +const TInt KF32BuildVersionNumber=4006; // #endif diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/runtests/runtests.cpp --- a/userlibandfileserver/fileserver/runtests/runtests.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/runtests/runtests.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -722,7 +722,7 @@ r=listfile.Open(TheFs,listfilename,EFileRead|EFileShareAny); if (r!=KErrNone) __PANIC(r); - TInt listfilesize; + TInt listfilesize = 0; r=listfile.Size(listfilesize); if (r!=KErrNone) __PANIC(r); diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/fat_table32.cpp --- a/userlibandfileserver/fileserver/sfat32/fat_table32.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/fat_table32.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -649,10 +649,11 @@ return aFatIndex<<2; //-- 4 bytes per FAT entry default: - ASSERT(0); - return 0;//-- get rid of warning + break; }; + ASSERT(0); + return 0;//-- get rid of warning } //----------------------------------------------------------------------------- diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_bpb32.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_bpb32.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_bpb32.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -274,9 +274,9 @@ return EFat12; else if(clusterCnt < 65525) return EFat16; - else - return EFat32; + + return EFat32; } diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_fatmisc32.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_fatmisc32.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_fatmisc32.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -107,15 +107,12 @@ ASSERT(iReservedSectors >= (bFat32 ? KDefFat32ResvdSec : KDefFatResvdSec)); if ((FirstDataSector() & (aEraseBlockSizeInSectors-1)) == 0) - { return KErrNone; - } - else - { - iReservedSectors = reservedSectorsSaved; - iSectorsPerFat = sectorsPerFatSaved; - return KErrGeneral; - } + + + iReservedSectors = reservedSectorsSaved; + iSectorsPerFat = sectorsPerFatSaved; + return KErrGeneral; } @@ -283,10 +280,17 @@ } } - // ReMount since MBR may have been rewritten and partition may have moved / changed size - TInt ret = LocalDrive()->ForceRemount(0); - if (ret != KErrNone && ret != KErrNotSupported) - User::Leave(ret); + + {//-- ReMount whole driver stack since MBR may have been rewritten and partition may have moved / changed size. + + //-- this is mostly applicable to SD cards formatting, since SD stack takes care of creating partition table. + //-- use KForceMediaChangeReOpenAllMediaDrivers flag that will cause remounting media + //-- drivers associatied with the current partition only and not affecting other ones. + const TInt ret = LocalDrive()->ForceRemount((TUint)RFs::KForceMediaChangeReOpenMediaDriver); + if(ret != KErrNone && ret != KErrNotSupported) + User::Leave(ret); + } + // MBR may have changed, so need to re-read iHiddenSectors etc.before BPB is written InitializeFormatDataL(); diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_file.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_file.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_file.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -877,8 +877,9 @@ aStartPos = iCurrentPos.iPos; if ((I64LOW(aStartPos) == FCB_FileSize()) || ( I64LOW(aStartPos) == (myStartPos + length))) return KErrCompletion; - else - return KErrNone; + + + return KErrNone; } @@ -898,8 +899,10 @@ return FatMount().LocalDrive()->GetLocalDrive((TBusLocalDrive*&) aInterface); default: - return CFileCB::GetInterface(aInterfaceId,aInterface,aInput); + break; } + + return CFileCB::GetInterface(aInterfaceId,aInterface,aInput); } diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_fmt.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_fmt.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_fmt.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -137,8 +137,8 @@ return EFat12; else if(clusterCnt < 65525) return EFat16; - else - return EFat32; + + return EFat32; } //------------------------------------------------------------------------------------------------------------------- diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_fsy.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_fsy.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_fsy.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -145,6 +145,8 @@ return KErrNone; default: - return(CFileSystem::GetInterface(aInterfaceId, aInterface, aInput)); + break; } + + return(CFileSystem::GetInterface(aInterfaceId, aInterface, aInput)); } diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_leafdir_cache.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_leafdir_cache.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_leafdir_cache.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -893,10 +893,8 @@ CLeafDirTreeNode* dummy = NULL; return (iTree->Search(path, dummy, aLeafDirData)); } - else - { - return KErrBadName; - } + + return KErrBadName; } /* diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_mnt.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_mnt.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_mnt.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -1634,15 +1634,20 @@ MoveToDosEntryL(dirEntryPos,dirEntry); if (dirEntry.IsParentDirectory() || dirEntry.IsCurrentDirectory()) goto LoopEnd; + if (dirEntry.IsEndOfDirectory()) return ETrue; + if (IsRootDir(dirEntryPos)&&(dirEntryPos.iPos+StartOfRootDirInBytes()==RootDirEnd())) return ETrue; // Root Directory has no end of directory marker + if (!dirEntry.IsErased()) - return EFalse; + break; //-- found a valid dir. entry LoopEnd: MoveToNextEntryL(dirEntryPos); } + + return EFalse; } //----------------------------------------------------------------------------------------- @@ -1810,7 +1815,7 @@ if (offset=length) - return; + break; } } @@ -1884,7 +1889,7 @@ __ASSERT_ALWAYS(FAT().GetNextClusterL(aPos.iCluster),User::Leave(KErrCorrupt)); } if (offset>=aLength) - return; + break; } } @@ -3513,7 +3518,8 @@ TLeafDirData leafDir; pos.iCluster=FindLeafDirL(aShortName.Left(namePos), leafDir); - FOREVER + + for(;;) { TFatDirEntry startEntry; User::LeaveIfError(GetDirEntry(pos,entry,startEntry,aLongName)); @@ -3529,13 +3535,14 @@ LocaleUtils::ConvertToUnicodeL(entryName, entryName8); if (shortNameWithoutPathDelimiter.MatchF(entryName)!=KErrNotFound) { - if (entryIsVFat==EFalse) + if(!entryIsVFat) aLongName=shortNameWithoutPathDelimiter; - return; + + break; } } MoveToNextEntryL(pos); - } + }//for(;;) } @@ -3815,8 +3822,12 @@ r=local->ErasePassword(); if(r==KErrNone) { - // ...media change to ensure a fresh remount the drive - r = local->ForceRemount(0); + //-- ReMount whole driver stack since MBR may have been rewritten and partition may have moved / changed size. + //-- this is mostly applicable to SD cards formatting, since SD stack takes care of creating partition table. + //-- use KForceMediaChangeReOpenAllMediaDrivers flag that will cause remounting media + //-- drivers associatied with the current partition only and not affecting other ones. + r = LocalDrive()->ForceRemount((TUint)RFs::KForceMediaChangeReOpenMediaDriver); + local->Status() = KErrNotReady; WritePasswordData(); } @@ -4366,13 +4377,10 @@ TTimeIntervalSeconds CFatMountCB::TimeOffset() const { if((Drive().Att() & KDriveAttRemovable) && FatFileSystem().GetUseLocalTime() ) - { return User::UTCOffset(); - } - else - { - return TTimeIntervalSeconds(0); - } + + + return TTimeIntervalSeconds(0); } @@ -4431,10 +4439,11 @@ return EOF_12Bit-7; //-- 0xff8 default: - ASSERT(aFatType == EInvalid); - return 0; + break; } + ASSERT(aFatType == EInvalid); + return 0; } //----------------------------------------------------------------------------------------- diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_mnt32.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_mnt32.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_mnt32.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -335,8 +335,7 @@ User::LeaveIfError(drive.ReadNonCritical(StartOfFatInBytes()+KFatEntrySize, KFatEntrySize, ptrFatEntry)); //read FAT32[1] entry return (fatEntry & KFat32CleanShutDownMask); } - else - if(Is16BitFat()) + else if(Is16BitFat()) {//-- Fat16 TFat16Entry fatEntry; const TInt KFatEntrySize=sizeof(fatEntry); //-- FAT entry size in bytes @@ -659,7 +658,7 @@ if(aName.MaxLength() < 5) return KErrArgument; - switch (FatType()) + switch(FatType()) { case EFat12: { @@ -676,11 +675,14 @@ aName = KFSSubType_FAT32; return KErrNone; } + default: - // case EInvalidFatType - return KErrNotReady; + break; + } - } + + return KErrNotReady; + } //------------------------------------------------------------------------------------------------------------------- @@ -1006,8 +1008,10 @@ return KErrNone; default: - return(CMountCB::GetInterface(aInterfaceId, aInterface, aInput)); + break; } + + return(CMountCB::GetInterface(aInterfaceId, aInterface, aInput)); } //----------------------------------------------------------------------------------------- diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_scan32.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_scan32.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_scan32.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -234,11 +234,10 @@ */ CScanDrive::TGenericError CScanDrive::ProblemsDiscovered() const { - if(IsDirError()) return EScanDriveDirError; - else - return iGenericError; + + return iGenericError; } /** diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfat32/sl_vfat.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_vfat.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfat32/sl_vfat.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -548,16 +548,11 @@ User::Leave(KErrAlreadyExists); if((i == -1) && IsLegalDosName(aName,EFalse,EFalse,EFalse,EFalse,ETrue)) - { - // Original file name is a legal 8.3 name - return(ETrue); - } - else - { - return(EFalse); + {// Original file name is a legal 8.3 name + return ETrue; } - + return EFalse; } diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfile/sf_drv.cpp --- a/userlibandfileserver/fileserver/sfile/sf_drv.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfile/sf_drv.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -2201,8 +2201,7 @@ /** Gracefully dismounts the current mount. This is method is called from outside, so do some finalisation work on mount. -After calling this function there is no current mount on the drive. - + After calling this function there is no current mount on the drive. */ EXPORT_C void TDrive::Dismount() { @@ -2216,8 +2215,8 @@ TRAP_IGNORE(FlushCachedFileInfoL()); //-- try our best to finalise the mount (the mount can decide to do some job during finalisation, e.g. write some data) - //-- finalise the mount in RO mode, we are dismounting the FS anyway - TRAP_IGNORE(iCurrentMount->FinaliseMountL(RFs::EFinal_RO)); + //-- finalise the mount in RW mode + TRAP_IGNORE(iCurrentMount->FinaliseMountL(RFs::EFinal_RW)); DoDismount(); } @@ -2240,8 +2239,9 @@ TRAP_IGNORE(FlushCachedFileInfoL()); //-- try our best to finalise the mount (the mount can decide to do some job during finalisation, e.g. write some data) - //-- finalise the mount in RO mode, we are dismounting the FS anyway - TRAP_IGNORE(iCurrentMount->FinaliseMountL(RFs::EFinal_RO)); + //-- finalise the mount in RW mode. It is possible that the mount is being forcedly dismounted with some files opened on it. + //-- in this case further attempt to access may will result in successful remountng and re-attaching mount and its files to the media. + TRAP_IGNORE(iCurrentMount->FinaliseMountL(RFs::EFinal_RW)); //-- mark the mount as 'Dismounted'; this invalidates all object handles until the mount is successfully "remounted". //-- if there are still some objects opened on this mount, CMountCB::Close() won't destroy it until all objects are closed. @@ -2541,10 +2541,8 @@ TInt TDrive::ClearDeferredDismount() // debug-only function for testing { - Lock(); FsNotify::HandleDismount(EFsDismountRegisterClient, DriveNumber(), ETrue, KErrNone); SetDismountDeferred(EFalse); - UnLock(); return KErrNone; } #endif diff -r 55a0a1279a7e -r 206a6eaaeb71 userlibandfileserver/fileserver/sfsrv/cl_cli.cpp --- a/userlibandfileserver/fileserver/sfsrv/cl_cli.cpp Wed Oct 13 13:34:03 2010 +0100 +++ b/userlibandfileserver/fileserver/sfsrv/cl_cli.cpp Mon Oct 18 15:31:10 2010 +0100 @@ -832,7 +832,6 @@ -EFSRV_EXPORT_C TInt RFs::RemountDrive(TInt aDrive,const TDesC8* aMountInfo,TUint aFlags) /** Forces a remount of the specified drive. @@ -840,14 +839,13 @@ @param aMountInfo Information passed down to the media driver. The meaning of this information depends on the media driver, for example, keys for secure areas. -@param aFlags When the flag is set to - 0x00000001 - Used to simulate ejecting and re-inserting the media. - 0x80000000 - used to force the media driver for the specified logical - drive to be closed and reopened. - -@return KErrNone if successful, otherwise one of - the other system wide error codes. + +@param aFlags one of the flags specified in RFs::TForceMediaChangeFlags and describing the way + drive is going to be remounted. + +@return KErrNone if successful, otherwise one of the other system wide error codes. */ +EFSRV_EXPORT_C TInt RFs::RemountDrive(TInt aDrive,const TDesC8* aMountInfo,TUint aFlags) { OstTraceExt4(TRACE_BORDER, EFSRV_EFSREMOUNTDRIVE, "sess %x aDrive %d aMountInfo %x aFlags %x", (TUint) Handle(), aDrive, (TUint) aMountInfo, (TUint) aFlags); TInt r = SendReceive(EFsRemountDrive,TIpcArgs(aDrive,aMountInfo,aFlags));