From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=ray.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 239BA208EB3F0 for ; Fri, 15 Feb 2019 23:38:12 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Feb 2019 23:38:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,375,1544515200"; d="scan'208";a="143975282" Received: from ray-dev.ccr.corp.intel.com (HELO [10.239.9.31]) ([10.239.9.31]) by fmsmga002.fm.intel.com with ESMTP; 15 Feb 2019 23:38:10 -0800 To: Liu Yu , "afish@apple.com; jordan.l.justen"@intel.com Cc: "edk2-devel@lists.01.org" References: From: "Ni, Ray" Message-ID: <4ed773fe-7a1a-8434-b8b4-bed2b9f24f26@Intel.com> Date: Sat, 16 Feb 2019 15:40:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: Subject: Re: EmulatorPkg Unix Host Segmentation fault. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Feb 2019 07:38:12 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit I also met this issue. I found three solutions: 1. Forcing PeiMain CC flag to "-O0" works. 2. Changing EmulatorPkg/Sec to not produce TemporaryRamSupportPpi also works. 3. Implement the temporary migration routine as below in EmulatorPkg/Sec module. EFI_STATUS EFIAPI SecTemporaryRamSupport ( IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, IN UINTN CopySize ) { VOID *OldHeap; VOID *NewHeap; VOID *OldStack; VOID *NewStack; UINTN StackMigrateOffset; BASE_LIBRARY_JUMP_BUFFER JumpBuffer; DEBUG ((EFI_D_INFO, "TemporaryRamMigration(0x%Lx, 0x%Lx, 0x%Lx)\n", TemporaryMemoryBase, PermanentMemoryBase, (UINT64)CopySize )); // // Assume Host prepare the stack and heap in the temprary ram that stack // is below heap (stack is in smaller address). // Stack/heap migration depends on the stack/heap location information // in the temporary ram. // OldStack = (VOID*)(UINTN)TemporaryMemoryBase; NewStack = (VOID*)((UINTN)PermanentMemoryBase); OldHeap = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1)); NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1)); StackMigrateOffset = (UINTN)NewStack - (UINTN)OldStack; // // Migrate Heap and Stack // CopyMem (NewHeap, OldHeap, CopySize >> 1); CopyMem (NewStack, OldStack, CopySize >> 1); // // Use SetJump()/LongJump() to switch to a new stack. // if (SetJump (&JumpBuffer) == 0) { #if defined (MDE_CPU_IA32) JumpBuffer.Esp = JumpBuffer.Esp + StackMigrateOffset; JumpBuffer.Ebp = JumpBuffer.Ebp + StackMigrateOffset; #endif #if defined (MDE_CPU_X64) JumpBuffer.Rsp = JumpBuffer.Rsp + StackMigrateOffset; JumpBuffer.Rbp = JumpBuffer.Rbp + StackMigrateOffset; #endif LongJump (&JumpBuffer, (UINTN)-1); } ZeroMem ((VOID *)(UINTN) TemporaryMemoryBase, CopySize); return EFI_SUCCESS; } Andrew, I'd like to know why you chose to produce the migration PPI from EmulatorPkg/Sec module. Based on PI spec and current PeiCore implementation, PeiCore can do the migration when PPI is absent. -- Thanks, Ray