Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(690)

Side by Side Diff: base/android/jni_generator/jni_generator.py

Issue 2531273002: android: Realign stack pointer on JNI entry. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Extracts native methods from a Java file and generates the JNI bindings. 6 """Extracts native methods from a Java file and generates the JNI bindings.
7 If you change this, please run and update the tests.""" 7 If you change this, please run and update the tests."""
8 8
9 import collections 9 import collections
10 import errno 10 import errno
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 1023
1024 if is_method: 1024 if is_method:
1025 optional_error_return = JavaReturnValueToC(native.return_type) 1025 optional_error_return = JavaReturnValueToC(native.return_type)
1026 if optional_error_return: 1026 if optional_error_return:
1027 optional_error_return = ', ' + optional_error_return 1027 optional_error_return = ', ' + optional_error_return
1028 values.update({ 1028 values.update({
1029 'OPTIONAL_ERROR_RETURN': optional_error_return, 1029 'OPTIONAL_ERROR_RETURN': optional_error_return,
1030 'PARAM0_NAME': native.params[0].name, 1030 'PARAM0_NAME': native.params[0].name,
1031 'P0_TYPE': native.p0_type, 1031 'P0_TYPE': native.p0_type,
1032 }) 1032 })
1033 # Dalvik JIT generated code doesn't guarantee 16-byte stack alignment on
1034 # x86 - use force_align_arg_pointer to realign the stack at the JNI
1035 # boundary. crbug.com/655248
1033 template = Template("""\ 1036 template = Template("""\
1034 extern "C" __attribute__((visibility("default"))) 1037 extern "C" __attribute__((visibility("default")))
1038 #if defined(ARCH_CPU_X86)
1039 __attribute__((force_align_arg_pointer))
1040 #endif
1035 ${RETURN} ${STUB_NAME}(JNIEnv* env, 1041 ${RETURN} ${STUB_NAME}(JNIEnv* env,
1036 ${PARAMS_IN_STUB}) { 1042 ${PARAMS_IN_STUB}) {
1037 ${PROFILING_ENTERED_NATIVE} 1043 ${PROFILING_ENTERED_NATIVE}
1038 ${P0_TYPE}* native = reinterpret_cast<${P0_TYPE}*>(${PARAM0_NAME}); 1044 ${P0_TYPE}* native = reinterpret_cast<${P0_TYPE}*>(${PARAM0_NAME});
1039 CHECK_NATIVE_PTR(env, jcaller, native, "${NAME}"${OPTIONAL_ERROR_RETURN}); 1045 CHECK_NATIVE_PTR(env, jcaller, native, "${NAME}"${OPTIONAL_ERROR_RETURN});
1040 return native->${NAME}(${PARAMS_IN_CALL})${POST_CALL}; 1046 return native->${NAME}(${PARAMS_IN_CALL})${POST_CALL};
1041 } 1047 }
1042 """) 1048 """)
1043 else: 1049 else:
1044 template = Template(""" 1050 template = Template("""
1045 static ${RETURN_DECLARATION} ${NAME}(JNIEnv* env, ${PARAMS}); 1051 static ${RETURN_DECLARATION} ${NAME}(JNIEnv* env, ${PARAMS});
1046 1052
1047 extern "C" __attribute__((visibility("default"))) 1053 extern "C" __attribute__((visibility("default")))
1054 #if defined(ARCH_CPU_X86)
1055 __attribute__((force_align_arg_pointer))
1056 #endif
1048 ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { 1057 ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) {
1049 ${PROFILING_ENTERED_NATIVE} 1058 ${PROFILING_ENTERED_NATIVE}
1050 return ${NAME}(${PARAMS_IN_CALL})${POST_CALL}; 1059 return ${NAME}(${PARAMS_IN_CALL})${POST_CALL};
1051 } 1060 }
1052 """) 1061 """)
1053 1062
1054 return RemoveIndentedEmptyLines(template.substitute(values)) 1063 return RemoveIndentedEmptyLines(template.substitute(values))
1055 1064
1056 def GetArgument(self, param): 1065 def GetArgument(self, param):
1057 if param.datatype == 'int': 1066 if param.datatype == 'int':
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 root_name = os.path.splitext(os.path.basename(input_file))[0] 1405 root_name = os.path.splitext(os.path.basename(input_file))[0]
1397 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' 1406 output_file = os.path.join(options.output_dir, root_name) + '_jni.h'
1398 GenerateJNIHeader(input_file, output_file, options) 1407 GenerateJNIHeader(input_file, output_file, options)
1399 1408
1400 if options.depfile: 1409 if options.depfile:
1401 build_utils.WriteDepfile(options.depfile, output_file) 1410 build_utils.WriteDepfile(options.depfile, output_file)
1402 1411
1403 1412
1404 if __name__ == '__main__': 1413 if __name__ == '__main__':
1405 sys.exit(main(sys.argv)) 1414 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698