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

Side by Side Diff: src/platform-linux.cc

Issue 10829122: android: refine custom ucontext_t definitions. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup. 900 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup.
901 } 901 }
902 } 902 }
903 903
904 904
905 Semaphore* OS::CreateSemaphore(int count) { 905 Semaphore* OS::CreateSemaphore(int count) {
906 return new LinuxSemaphore(count); 906 return new LinuxSemaphore(count);
907 } 907 }
908 908
909 909
910 #if !defined(__GLIBC__) && (defined(__arm__) || defined(__thumb__)) 910 #if defined(__ANDROID__) && !defined(__BIONIC_HAVE_UCONTEXT_T)
911 // Android runs a fairly new Linux kernel, so signal info is there,
912 // but the C library doesn't have the structs defined.
913 911
914 struct sigcontext { 912 // Not all versions of Android's C library provide ucontext_t.
915 uint32_t trap_no; 913 // Detect this and provide custom but compatible definitions. Note that these
916 uint32_t error_code; 914 // follow the GLibc naming convention to access register values from
917 uint32_t oldmask; 915 // mcontext_t.
918 uint32_t gregs[16]; 916 //
919 uint32_t arm_cpsr; 917 // See http://code.google.com/p/android/issues/detail?id=34784
920 uint32_t fault_address; 918
921 }; 919 #if defined(__arm__)
922 typedef uint32_t __sigset_t; 920
921 // GLibc on ARM defines mcontext_t has a typedef for 'struct sigcontext'.
922 // Old versions of the C library <signal.h> didn't define the type.
923 #if !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT)
924 #include <asm/sigcontext.h>
925 #endif
926
923 typedef struct sigcontext mcontext_t; 927 typedef struct sigcontext mcontext_t;
928
924 typedef struct ucontext { 929 typedef struct ucontext {
925 uint32_t uc_flags; 930 uint32_t uc_flags;
926 struct ucontext* uc_link; 931 struct ucontext* uc_link;
927 stack_t uc_stack; 932 stack_t uc_stack;
928 mcontext_t uc_mcontext; 933 mcontext_t uc_mcontext;
929 __sigset_t uc_sigmask; 934 // Other fields are not used by V8, don't define them here.
930 } ucontext_t; 935 } ucontext_t;
931 enum ArmRegisters {R15 = 15, R13 = 13, R11 = 11};
932 936
933 #elif !defined(__GLIBC__) && defined(__mips__) 937 #elif defined(__mips__)
934 // MIPS version of sigcontext, for Android bionic. 938 // MIPS version of sigcontext, for Android bionic.
935 struct sigcontext { 939 typedef struct {
936 uint32_t regmask; 940 uint32_t regmask;
937 uint32_t status; 941 uint32_t status;
938 uint64_t pc; 942 uint64_t pc;
939 uint64_t gregs[32]; 943 uint64_t gregs[32];
940 uint64_t fpregs[32]; 944 uint64_t fpregs[32];
941 uint32_t acx; 945 uint32_t acx;
942 uint32_t fpc_csr; 946 uint32_t fpc_csr;
943 uint32_t fpc_eir; 947 uint32_t fpc_eir;
944 uint32_t used_math; 948 uint32_t used_math;
945 uint32_t dsp; 949 uint32_t dsp;
946 uint64_t mdhi; 950 uint64_t mdhi;
947 uint64_t mdlo; 951 uint64_t mdlo;
948 uint32_t hi1; 952 uint32_t hi1;
949 uint32_t lo1; 953 uint32_t lo1;
950 uint32_t hi2; 954 uint32_t hi2;
951 uint32_t lo2; 955 uint32_t lo2;
952 uint32_t hi3; 956 uint32_t hi3;
953 uint32_t lo3; 957 uint32_t lo3;
954 }; 958 } mcontext_t;
955 typedef uint32_t __sigset_t; 959
956 typedef struct sigcontext mcontext_t;
957 typedef struct ucontext { 960 typedef struct ucontext {
958 uint32_t uc_flags; 961 uint32_t uc_flags;
959 struct ucontext* uc_link; 962 struct ucontext* uc_link;
960 stack_t uc_stack; 963 stack_t uc_stack;
961 mcontext_t uc_mcontext; 964 mcontext_t uc_mcontext;
962 __sigset_t uc_sigmask; 965 // Other fields are not used by V8, don't define them here.
963 } ucontext_t; 966 } ucontext_t;
964 967
965 #elif !defined(__GLIBC__) && defined(__i386__) 968 #elif defined(__i386__)
966 // x86 version for Android. 969 // x86 version for Android.
967 struct sigcontext { 970 typedef struct {
968 uint32_t gregs[19]; 971 uint32_t gregs[19];
969 void* fpregs; 972 void* fpregs;
970 uint32_t oldmask; 973 uint32_t oldmask;
971 uint32_t cr2; 974 uint32_t cr2;
972 }; 975 } mcontext_t;
973 976
974 typedef uint32_t __sigset_t; 977 typedef uint32_t kernel_sigset_t[2]; // x86 kernel uses 64-bit signal masks
975 typedef struct sigcontext mcontext_t;
976 typedef struct ucontext { 978 typedef struct ucontext {
977 uint32_t uc_flags; 979 uint32_t uc_flags;
978 struct ucontext* uc_link; 980 struct ucontext* uc_link;
979 stack_t uc_stack; 981 stack_t uc_stack;
980 mcontext_t uc_mcontext; 982 mcontext_t uc_mcontext;
981 __sigset_t uc_sigmask; 983 // Other fields are not used by V8, don't define them here.
982 } ucontext_t; 984 } ucontext_t;
983 enum { REG_EBP = 6, REG_ESP = 7, REG_EIP = 14 }; 985 enum { REG_EBP = 6, REG_ESP = 7, REG_EIP = 14 };
984 #endif 986 #endif
985 987
988 #endif // __ANDROID__ && !defined(__BIONIC_HAVE_UCONTEXT_T)
986 989
987 static int GetThreadID() { 990 static int GetThreadID() {
991 #if defined(__ANDROID__)
992 // Android's C library provides gettid(2).
993 return gettid();
994 #else
988 // Glibc doesn't provide a wrapper for gettid(2). 995 // Glibc doesn't provide a wrapper for gettid(2).
989 #if defined(ANDROID)
990 return syscall(__NR_gettid);
991 #else
992 return syscall(SYS_gettid); 996 return syscall(SYS_gettid);
993 #endif 997 #endif
994 } 998 }
995 999
996 1000
997 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { 1001 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
998 USE(info); 1002 USE(info);
999 if (signal != SIGPROF) return; 1003 if (signal != SIGPROF) return;
1000 Isolate* isolate = Isolate::UncheckedCurrent(); 1004 Isolate* isolate = Isolate::UncheckedCurrent();
1001 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { 1005 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) {
(...skipping 18 matching lines...) Expand all
1020 sample->state = isolate->current_vm_state(); 1024 sample->state = isolate->current_vm_state();
1021 #if V8_HOST_ARCH_IA32 1025 #if V8_HOST_ARCH_IA32
1022 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]); 1026 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]);
1023 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]); 1027 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]);
1024 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]); 1028 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]);
1025 #elif V8_HOST_ARCH_X64 1029 #elif V8_HOST_ARCH_X64
1026 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]); 1030 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]);
1027 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_RSP]); 1031 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_RSP]);
1028 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_RBP]); 1032 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_RBP]);
1029 #elif V8_HOST_ARCH_ARM 1033 #elif V8_HOST_ARCH_ARM
1030 // An undefined macro evaluates to 0, so this applies to Android's Bionic also. 1034 #if defined(__GLIBC__) && !defined(__UCLIBC__) && \
1031 #if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3) && \ 1035 (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
1032 !defined(__UCLIBC__)) 1036 // Old GLibc ARM versions used a gregs[] array to access the register
1037 // values from mcontext_t.
1033 sample->pc = reinterpret_cast<Address>(mcontext.gregs[R15]); 1038 sample->pc = reinterpret_cast<Address>(mcontext.gregs[R15]);
1034 sample->sp = reinterpret_cast<Address>(mcontext.gregs[R13]); 1039 sample->sp = reinterpret_cast<Address>(mcontext.gregs[R13]);
1035 sample->fp = reinterpret_cast<Address>(mcontext.gregs[R11]); 1040 sample->fp = reinterpret_cast<Address>(mcontext.gregs[R11]);
1036 #else 1041 #else
1037 sample->pc = reinterpret_cast<Address>(mcontext.arm_pc); 1042 sample->pc = reinterpret_cast<Address>(mcontext.arm_pc);
1038 sample->sp = reinterpret_cast<Address>(mcontext.arm_sp); 1043 sample->sp = reinterpret_cast<Address>(mcontext.arm_sp);
1039 sample->fp = reinterpret_cast<Address>(mcontext.arm_fp); 1044 sample->fp = reinterpret_cast<Address>(mcontext.arm_fp);
1040 #endif // (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3) && 1045 #endif // defined(__GLIBC__) && !defined(__UCLIBC__) && \
1041 // !defined(__UCLIBC__)) 1046 // (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
1042 #elif V8_HOST_ARCH_MIPS 1047 #elif V8_HOST_ARCH_MIPS
1043 sample->pc = reinterpret_cast<Address>(mcontext.pc); 1048 sample->pc = reinterpret_cast<Address>(mcontext.pc);
1044 sample->sp = reinterpret_cast<Address>(mcontext.gregs[29]); 1049 sample->sp = reinterpret_cast<Address>(mcontext.gregs[29]);
1045 sample->fp = reinterpret_cast<Address>(mcontext.gregs[30]); 1050 sample->fp = reinterpret_cast<Address>(mcontext.gregs[30]);
1046 #endif // V8_HOST_ARCH_* 1051 #endif // V8_HOST_ARCH_*
1047 sampler->SampleStack(sample); 1052 sampler->SampleStack(sample);
1048 sampler->Tick(sample); 1053 sampler->Tick(sample);
1049 } 1054 }
1050 1055
1051 1056
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 1289
1285 1290
1286 void Sampler::Stop() { 1291 void Sampler::Stop() {
1287 ASSERT(IsActive()); 1292 ASSERT(IsActive());
1288 SignalSender::RemoveActiveSampler(this); 1293 SignalSender::RemoveActiveSampler(this);
1289 SetActive(false); 1294 SetActive(false);
1290 } 1295 }
1291 1296
1292 1297
1293 } } // namespace v8::internal 1298 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698