On Oct 9, 2014, at 11:24 AM, Bruce Cran <[email protected]> wrote:
> I noticed that in Library/SynchronizationLib.h the Interlocked
> functions (e.g. InterlockedIncrement) don't specify that the Value is
> volatile, but the InternalSync* functions they call in
> Synchronization.c _are_ specified as taking a volatile integer.
>
A volatile variable in C is not atomic, or thread safe, they are used to
prevent the compiler from changing the order of memory accesses, or skipping
memory accesses.
> Is that due to the limitation imposed by the UEFI spec not having a
> VOLATILE modifier, or should they use the 'volatile' C keyword like
> the definition of SPIN_LOCK?
>
Not sure about the history, but the limitation is going to be accessing Value
outside of the functions. As you can see in my example The check for the while
loop is only made one time, and the code returns or gets stuck in an infinite
loop (JMP LBB0_1). If you add volatile to Value then the loop will check the
value on every iteration. If you just use the return value of the functions to
return the value, you will always get the correct answer.
Since the library functions use volatile C variables or assembler the optimizer
is never going to break them.
~/work/Compiler>cat Inter.c
unsigned int InterlockedIncrement (unsigned int *Value);
void
test (unsigned int *Value)
{
unsigned int Result;
Result = InterlockedIncrement (Value);
while (*Value <= Result);
return;
}
~/work/Compiler>clang -O3 -S -target x86_64-pc-win32-macho Inter.c
~/work/Compiler>cat Inter.S
.section __TEXT,__text,regular,pure_instructions
.globl _test
.align 4, 0x90
_test: ## @test
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp3:
.cfi_def_cfa_offset 16
Ltmp4:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp5:
.cfi_def_cfa_register %rbp
pushq %rsi
subq $40, %rsp
Ltmp6:
.cfi_offset %rsi, -24
movq %rcx, %rsi
## kill: RCX<def> RSI<kill>
callq _InterlockedIncrement
cmpl %eax, (%rsi)
jbe LBB0_1
## BB#2: ## %.split1
addq $40, %rsp
popq %rsi
popq %rbp
retq
.align 4, 0x90
LBB0_1: ## %..split_crit_edge
## =>This Inner Loop Header: Depth=1
jmp LBB0_1
.cfi_endproc
.subsections_via_symbols
Thanks,
Andrew Fish
> --
> Bruce
>
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel