"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "BootMemory.cpp" see the
Fossies "Dox" file reference documentation.
1 /*
2 Derived from source code of TrueCrypt 7.1a, which is
3 Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
4 by the TrueCrypt License 3.0.
5
6 Modifications and additions to the original source code (contained in this file)
7 and all other portions of this file are Copyright (c) 2013-2017 IDRIX
8 and are governed by the Apache License 2.0 the full text of which is
9 contained in the file License.txt included in VeraCrypt binary and source
10 code distribution packages.
11 */
12
13 #include "BootDefs.h"
14 #include "BootMemory.h"
15
16 static uint32 MemoryMapContValue;
17
18 static bool GetMemoryMapEntry (BiosMemoryMapEntry &entry)
19 {
20 static const uint32 function = 0x0000E820UL;
21 static const uint32 magic = 0x534D4150UL;
22 static const uint32 bufferSize = sizeof (BiosMemoryMapEntry);
23
24 bool carry = false;
25 uint32 resultMagic;
26 uint32 resultSize;
27
28 __asm
29 {
30 push es
31
32 lea di, function
33 TC_ASM_MOV_EAX_DI
34 lea di, MemoryMapContValue
35 TC_ASM_MOV_EBX_DI
36 lea di, bufferSize
37 TC_ASM_MOV_ECX_DI
38 lea di, magic
39 TC_ASM_MOV_EDX_DI
40 lea di, MemoryMapContValue
41 TC_ASM_MOV_DI_ECX
42
43 // Use alternative segment to prevent memory corruption caused by buggy BIOSes
44 push TC_BOOT_LOADER_ALT_SEGMENT
45 pop es
46 mov di, 0
47
48 int 0x15
49 jnc no_carry
50 mov carry, true
51 no_carry:
52
53 lea di, resultMagic
54 TC_ASM_MOV_DI_EAX
55 lea di, MemoryMapContValue
56 TC_ASM_MOV_DI_EBX
57 lea di, resultSize
58 TC_ASM_MOV_DI_ECX
59
60 pop es
61 }
62
63 CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, 0, &entry, sizeof (entry));
64
65 // BIOS may set CF at the end of the list
66 if (carry)
67 MemoryMapContValue = 0;
68
69 return resultMagic == magic && resultSize == bufferSize;
70 }
71
72
73 bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
74 {
75 MemoryMapContValue = 0;
76 return GetMemoryMapEntry (entry);
77 }
78
79
80 bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
81 {
82 if (MemoryMapContValue == 0)
83 return false;
84
85 return GetMemoryMapEntry (entry);
86 }