3030
3131import  static  java .lang .foreign .ValueLayout .ADDRESS ;
3232import  static  java .lang .foreign .ValueLayout .JAVA_LONG ;
33+ import  static  org .elasticsearch .entitlement .qa .test .EntitlementTest .ExpectedAccess .PLUGINS ;
34+ import  static  org .elasticsearch .entitlement .qa .test .EntitlementTest .ExpectedAccess .SERVER_ONLY ;
3335
34- class  VersionSpecificNativeChecks  {
36+ class  NativeActions  {
3537
38+     @ EntitlementTest (expectedAccess  = SERVER_ONLY )
3639    static  void  enableNativeAccess () throws  Exception  {
3740        ModuleLayer  parent  = ModuleLayer .boot ();
3841
@@ -49,16 +52,19 @@ static void enableNativeAccess() throws Exception {
4952        controller .enableNativeAccess (targetModule .get ());
5053    }
5154
55+     @ EntitlementTest (expectedAccess  = PLUGINS )
5256    static  void  addressLayoutWithTargetLayout () {
5357        AddressLayout  addressLayout  = ADDRESS .withoutTargetLayout ();
5458        addressLayout .withTargetLayout (MemoryLayout .sequenceLayout (Long .MAX_VALUE , ValueLayout .JAVA_BYTE ));
5559    }
5660
61+     @ EntitlementTest (expectedAccess  = PLUGINS )
5762    static  void  linkerDowncallHandle () {
5863        Linker  linker  = Linker .nativeLinker ();
5964        linker .downcallHandle (FunctionDescriptor .of (JAVA_LONG , ADDRESS ));
6065    }
6166
67+     @ EntitlementTest (expectedAccess  = PLUGINS )
6268    static  void  linkerDowncallHandleWithAddress () {
6369        Linker  linker  = Linker .nativeLinker ();
6470        linker .downcallHandle (linker .defaultLookup ().find ("strlen" ).get (), FunctionDescriptor .of (JAVA_LONG , ADDRESS ));
@@ -68,12 +74,13 @@ static int callback() {
6874        return  0 ;
6975    }
7076
77+     @ EntitlementTest (expectedAccess  = PLUGINS )
7178    static  void  linkerUpcallStub () throws  NoSuchMethodException  {
7279        Linker  linker  = Linker .nativeLinker ();
7380
7481        MethodHandle  mh  = null ;
7582        try  {
76-             mh  = MethodHandles .lookup ().findStatic (VersionSpecificNativeChecks .class , "callback" , MethodType .methodType (int .class ));
83+             mh  = MethodHandles .lookup ().findStatic (NativeActions .class , "callback" , MethodType .methodType (int .class ));
7784        } catch  (IllegalAccessException  e ) {
7885            assert  false ;
7986        }
@@ -82,24 +89,28 @@ static void linkerUpcallStub() throws NoSuchMethodException {
8289        linker .upcallStub (mh , callbackDescriptor , Arena .ofAuto ());
8390    }
8491
92+     @ EntitlementTest (expectedAccess  = PLUGINS )
8593    static  void  memorySegmentReinterpret () {
8694        Arena  arena  = Arena .ofAuto ();
8795        MemorySegment  segment  = arena .allocate (100 );
8896        segment .reinterpret (50 );
8997    }
9098
99+     @ EntitlementTest (expectedAccess  = PLUGINS )
91100    static  void  memorySegmentReinterpretWithCleanup () {
92101        Arena  arena  = Arena .ofAuto ();
93102        MemorySegment  segment  = arena .allocate (100 );
94103        segment .reinterpret (Arena .ofAuto (), s  -> {});
95104    }
96105
106+     @ EntitlementTest (expectedAccess  = PLUGINS )
97107    static  void  memorySegmentReinterpretWithSizeAndCleanup () {
98108        Arena  arena  = Arena .ofAuto ();
99109        MemorySegment  segment  = arena .allocate (100 );
100110        segment .reinterpret (50 , Arena .ofAuto (), s  -> {});
101111    }
102112
113+     @ EntitlementTest (expectedAccess  = PLUGINS )
103114    static  void  symbolLookupWithPath () {
104115        try  {
105116            SymbolLookup .libraryLookup (Path .of ("/foo/bar/libFoo.so" ), Arena .ofAuto ());
@@ -108,6 +119,7 @@ static void symbolLookupWithPath() {
108119        }
109120    }
110121
122+     @ EntitlementTest (expectedAccess  = PLUGINS )
111123    static  void  symbolLookupWithName () {
112124        try  {
113125            SymbolLookup .libraryLookup ("foo" , Arena .ofAuto ());
0 commit comments