1befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray/* 2befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * Copyright (C) 2018 The Android Open Source Project 3befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * 4befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * you may not use this file except in compliance with the License. 6befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * You may obtain a copy of the License at 7befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * 8befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * 10befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * See the License for the specific language governing permissions and 14befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray * limitations under the License. 15befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray */ 16befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 17befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffrayimport java.lang.reflect.Field; 18befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffrayimport java.lang.reflect.Method; 19befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 20befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffraypublic class ChildClass { 21befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray // This method being synchronized means the SIGQUIT code in ART will call 22befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray // FindLocksAtDexPc (we check for the presence of try blocks), 23befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray // which triggered a DCHECK of an invariant. 24befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray public static synchronized void runTest() throws Exception { 25befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray Main m = Foo.mainObject; 26befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 27befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray SigQuit.doKill(); 28befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 29befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray // Sleep some time to get the kill while executing this method. 30befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray Thread.sleep(2); 31befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 32befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray // The FindLocksAtDexPc method running with the verifier would fail when 33befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray // resolving this call, as the verifier didn't register Main from the field 34befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray // access above with the current class loader. 35befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray Main.staticMethod(); 36befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray System.out.println("Done"); 37befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray } 38befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 39befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray private final static class SigQuit { 40befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray private final static int sigquit; 41befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray private final static Method kill; 42befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray private final static int pid; 43befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 44befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray static { 45befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray int pidTemp = -1; 46befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray int sigquitTemp = -1; 47befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray Method killTemp = null; 48befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 49befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray try { 50befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray Class<?> osClass = Class.forName("android.system.Os"); 51befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray Method getpid = osClass.getDeclaredMethod("getpid"); 52befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray pidTemp = (Integer)getpid.invoke(null); 53befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 54befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray Class<?> osConstants = Class.forName("android.system.OsConstants"); 55befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray Field sigquitField = osConstants.getDeclaredField("SIGQUIT"); 56befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray sigquitTemp = (Integer)sigquitField.get(null); 57befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 58befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray killTemp = osClass.getDeclaredMethod("kill", int.class, int.class); 59befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray } catch (Exception e) { 60befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray throw new Error(e); 61befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray } 62befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 63befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray pid = pidTemp; 64befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray sigquit = sigquitTemp; 65befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray kill = killTemp; 66befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray } 67befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray 68befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray public static void doKill() throws Exception { 69befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray kill.invoke(null, pid, sigquit); 70befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray } 71befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray } 72befa3091a7a2abb5181970837c5ccee506573130Nicolas Geoffray} 73