TALx86: A Realistic Typed Assembly Language
-
Upload
illiana-avila -
Category
Documents
-
view
33 -
download
3
description
Transcript of TALx86: A Realistic Typed Assembly Language
![Page 1: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/1.jpg)
TALx86: A Realistic Typed Assembly TALx86: A Realistic Typed Assembly LanguageLanguage
Dan Grossman, Fred SmithCornell University
Joint work with: Greg Morrisett, Karl Crary (CMU), Neal Glew, Richard Samuels, Dave Walker, Stephanie Weirich, Steve
Zdancewic
![Page 2: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/2.jpg)
1 May 1999www.cs.cornell.edu/talc
2
Everyone wants extensibility:Everyone wants extensibility:
• Web browser• applets, plug-ins
• OS Kernel• packet filters, device drivers
• “Active” networks• service routines
• Databases• extensible ADTs
![Page 3: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/3.jpg)
1 May 1999www.cs.cornell.edu/talc
3
The Language ApproachThe Language Approach
Extension is written in a “safe” language:• Java, Modula-3, ML, Scheme
•Key point: language provides abstractions• ADTs, closures, objects, modules, etc. • Can be used to build fine-grained capabilities
Host ensures code respects abstractions:•Static checking (verification)
• Inserting dynamic checks (code-rewriting)
![Page 4: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/4.jpg)
1 May 1999www.cs.cornell.edu/talc
4
Example: Your Web BrowserExample: Your Web Browser
Java Source
javac
JVM bytecode
JVM verifier
System Interface
Binary
Optimizer
Low-Level IL
SystemBinary
Browser
![Page 5: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/5.jpg)
1 May 1999www.cs.cornell.edu/talc
5
JVM Pros & ConsJVM Pros & Cons
Pros:• Portability• Hype: $, tools, libraries, books, training
Cons:• Performance
• unsatisfying, even with off-line compilation
• Only really suitable for Java (or slight variants):• relatively high-level instructions tailored to Java• type system is Java specific
• and...
![Page 6: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/6.jpg)
1 May 1999www.cs.cornell.edu/talc
6
Large Trusted Computing Large Trusted Computing BaseBase
JVM verifier System Interface
Binary
Optimizer
Low-Level IL
SystemBinary
Browser
No complete formal model
Good code big optimizer bugs in optimizer
Must insert right checks
Lots of “native” methods(i.e., not-safe code)
![Page 7: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/7.jpg)
1 May 1999www.cs.cornell.edu/talc
7
Ideally:Ideally:
Your favoritelanguage
Low-Level IL
optimizer
machine code
verifier SystemInterface
SystemBinary
trusted computing base
![Page 8: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/8.jpg)
1 May 1999www.cs.cornell.edu/talc
8
The Types WayThe Types Way
Your safelanguage
TypedLow-Level IL
Typedoptimizer
TAL
verifier SystemInterface
SystemBinary
trusted computing base
• Verifier is a type-checker
• Type system flexible and expressive
• A useful instantiation of the “proof
carrying code” framework
![Page 9: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/9.jpg)
1 May 1999www.cs.cornell.edu/talc
9
TALx86 in a NutshellTALx86 in a Nutshell
• Most of the IA32 80x86 flat model assembly language
• Memory management primitives
• Sound type system
• Types for code, stacks, structs
• Other advanced features
• Future work (what we can’t do yet)
![Page 10: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/10.jpg)
1 May 1999www.cs.cornell.edu/talc
10
TALx86 Basics:TALx86 Basics:
Primitive types: (e.g., int)
Code types: {r1:1,…,rn:n}
•“I’m code that requires register ri to have type i before you can jump to me.”
•Code blocks are annotated with their types• Think pre-condition • Verify block assuming pre-condition
![Page 11: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/11.jpg)
1 May 1999www.cs.cornell.edu/talc
11
Sample LoopSample Loop
C:
int sum(int n){ int s=0; while(!n) { s+=n; --n; } return n;}
TAL sketch:
<n and retn addr as input>
sum: <type> <initialize s>loop: <type> <add to s, decrement
n>test: <type> <return if n is 0>
![Page 12: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/12.jpg)
1 May 1999www.cs.cornell.edu/talc
12
VerificationVerificationsum: {ecx:int, ebx:{edx:int}}
mov eax,0jmp test
loop:{ecx:int, ebx:{edx:int}, eax:int} add eax,ecx dec ecx
test:{ecx:int, ebx:{edx:int}, eax:int}
cmp ecx,0jne loop
mov edx,eaxjmp ebx
{ecx:int, ebx:{edx:int}, eax:int}
{ecx:int, ebx:{edx:int}, eax:int}
{ecx:int, ebx:{edx:int}, eax:int}
{ecx:int, ebx:{edx:int}, eax:int}
OK: sub-type of {edx:int} -- type of ebx
OK: sub-type of type labeling test
{ecx:int, ebx:{edx:int}, eax:int, edx:int}
OK: sub-type of type labeling next block
OK: sub-type of type labeling loop
![Page 13: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/13.jpg)
1 May 1999www.cs.cornell.edu/talc
13
Stacks & ProceduresStacks & Procedures
Stack Types (lists): ::= nil | :: |
where is a stack type variable.
Examples using C calling convention:
int square(int); int mult(int,int);
{esp: 1::int::} {esp: 2::int::int::}
where where 1={eax: int, esp: int::} 2={eax: int, esp:
int::int::}
![Page 14: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/14.jpg)
1 May 1999www.cs.cornell.edu/talc
14
square: {esp: 1::int::}
where 1={eax: int, esp: int::}
push [esp+4]
push [esp+8]
call mult[with 2 = 1::int::]
add esp,8
retn
mult: {esp: 2::int::int::}
where 2={eax: int, esp: int::int::}
Stacks & VerificationStacks & Verification
int
int
int
aft
aft={eax:int, esp: int::int::1::int::}
{esp: 2::int::int::1::int::1} where 2={eax: int, esp: int::int::1::int::1}
![Page 15: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/15.jpg)
1 May 1999www.cs.cornell.edu/talc
15
Important PropertiesImportant Properties
• Abstraction
“Because the type of the rest of the stack is abstract the callee cannot read/write this portion of the stack”
• Flexibility
Can encode and enforce many calling conventions(stack shape on return, callee-save, tail calls, etc.)
![Page 16: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/16.jpg)
1 May 1999www.cs.cornell.edu/talc
16
Callee-Save ExampleCallee-Save Example
mult: {ebp: esp: 2::int::int::}
where 2={ebp: eax: int, esp: int::int::}
![Page 17: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/17.jpg)
1 May 1999www.cs.cornell.edu/talc
17
StructsStructs
• Goals:
•Prevent reading uninitialized fields
•Permit flexible scheduling of initialization
• MALLOC “instruction”
returns uninitialized record
• Type of struct tracks initialization of fields
• Example: {ecx: int}
MALLOC eax,8 [int,int] ; eax : ^*[intu, intu]
mov [eax+0], ecx ; eax : ^*[intrw,intu]
mov ecx, [eax+4] ; type error!
![Page 18: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/18.jpg)
1 May 1999www.cs.cornell.edu/talc
18
Much, much moreMuch, much more
• Arrays (see next slide)
• Tagged Unions
• Displays, Exceptions [TIC’98]
• Static Data
• Modules and Interfaces [POPL’99]
• Run-time code generation [PEPM’99 Jim, Hornof]
![Page 19: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/19.jpg)
1 May 1999www.cs.cornell.edu/talc
19
Mis-featuresMis-features
• MALLOC and garbage collection in trusted computing base [POPL’99]
• No way to express aliasing
• No array bounds check elimination [Walker]
• Object/class support too primitive [Glew]
![Page 20: TALx86: A Realistic Typed Assembly Language](https://reader036.fdocuments.net/reader036/viewer/2022082405/56812de8550346895d93434d/html5/thumbnails/20.jpg)
1 May 1999www.cs.cornell.edu/talc
20
Summary and ConclusionsSummary and Conclusions
•We can type real machine codePotential for performance + flexibility + safety
•Challenge: Finding generally useful abstractions
•Lots of work remains
http://www.cs.cornell.edu/talc