Source/Packages

Runtime.NativeDescriptor

packages/execution/src/Runtime/NativeDescriptor.alpha

80 lines3 declarations3.4 KiBSHA-256 ac2abacc0cb3

Complete file · line 56

NativeDescriptor.alpha

Definition view
1module Runtime.NativeDescriptor
2
3import Compiler.MachineX86Native
4import Compiler.MachineX86NativeAssembly
5import Runtime.NativePhysicalNative
6import Runtime.NativePhysicalProgram
7import Runtime.NativeLaunchRecipeLoad
8import Std.Natural
9
10-- Admit a Linux descriptor-returning syscall result: [0, INT_MAX] succeeds;
11-- negative kernel errors survive unchanged, oversized positive words fail.
12-- This does not test whether an arbitrary integer names an open descriptor.
13def nativeDescriptorStatusAssembly =
14  (nativePhysicalNativeEmit
15    (nativePhysicalNativeMove
16      (constructor X86NativeRegister64 X86NativeRDI)
17      (constructor X86NativeRegister64 X86NativeRAX))
18    (nativePhysicalNativeEmit
19      (nativePhysicalNativeTest
20        (constructor X86NativeRegister64 X86NativeRAX)
21        (constructor X86NativeRegister64 X86NativeRAX))
22      (nativePhysicalNativeJumpCondition
23        (constructor X86NativeCondition X86NativeConditionSign)
24        b"descriptor-return"
25        (nativePhysicalNativeEmit
26          (nativePhysicalNativeCompareImmediate
27            (constructor X86NativeRegister64 X86NativeRAX)
28            (x86NativeImmediate32FromNatural 2147483647))
29          (nativePhysicalNativeJumpCondition
30            (constructor X86NativeCondition X86NativeConditionAbove)
31            b"descriptor-invalid"
32            (nativePhysicalNativeEmit
33              (constructor
34                X86NativeInstruction
35                X86NativeClear32
36                (constructor X86NativeRegister64 X86NativeRAX))
37              (nativePhysicalNativeJump
38                b"descriptor-return"
39                (nativePhysicalNativeLabel
40                  b"descriptor-invalid"
41                  (nativePhysicalNativeEmit
42                    (constructor
43                      X86NativeInstruction
44                      X86NativeClear32
45                      (constructor X86NativeRegister64 X86NativeRAX))
46                    (nativePhysicalNativeEmit
47                      (nativePhysicalNativeAddImmediate
48                        (constructor X86NativeRegister64 X86NativeRAX)
49                        (x86NativeImmediate32FromNatural (naturalSaturatingSubtract 4294967296 22)))
50                      (nativePhysicalNativeLabel
51                        b"descriptor-return"
52                        (nativePhysicalNativeEmit
53                          nativePhysicalNativeReturnInstruction
54                          (constructor X86NativeAssembly X86NativeAssemblyEnd)))))))))))))
55
56def nativeDescriptorStatusCode =
57  (compiler-native-encode (family X86NativeAssembly) nativeDescriptorStatusAssembly)
58
59def nativeDescriptorRequire =
60  (lambda unrestricted descriptor : (family NativePhysicalOperand) .
61    (lambda unrestricted slot : Nat .
62      (lambda unrestricted error : Bytes .
63        (lambda unrestricted tail : (family NativePhysicalCommands) .
64          (nativeLaunchRecipeCommand
65            (constructor
66              NativePhysicalOperation
67              NativePhysicalMachineRoutine
68              nativeDescriptorStatusCode
69              (nativeLaunchRecipeArguments
70                descriptor
71                (nativeLaunchRecipeImmediate 0)
72                (nativeLaunchRecipeImmediate 0)
73                (nativeLaunchRecipeImmediate 0))
74              (nativeLaunchRecipeStore slot))
75            error
76            (nativeLaunchRecipeAssertEqual
77              (nativeLaunchRecipeSlotValue slot)
78              (nativeLaunchRecipeImmediate 0)
79              error
80              tail))))))

The compiler supplied declaration spans and resolved links from this source snapshot. This page does not assert that this file belongs to a checked closure.