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

Side by Side Diff: src/regexp-macro-assembler-ia32.h

Issue 42441: Made regexp robust against changes to a string's implementation. (Closed)
Patch Set: Removed unused addition to memory.h Created 11 years, 9 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
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 16 matching lines...) Expand all
27 27
28 #ifndef REGEXP_MACRO_ASSEMBLER_IA32_H_ 28 #ifndef REGEXP_MACRO_ASSEMBLER_IA32_H_
29 #define REGEXP_MACRO_ASSEMBLER_IA32_H_ 29 #define REGEXP_MACRO_ASSEMBLER_IA32_H_
30 30
31 namespace v8 { namespace internal { 31 namespace v8 { namespace internal {
32 32
33 class RegExpMacroAssemblerIA32: public RegExpMacroAssembler { 33 class RegExpMacroAssemblerIA32: public RegExpMacroAssembler {
34 public: 34 public:
35 // Type of input string to generate code for. 35 // Type of input string to generate code for.
36 enum Mode { ASCII = 1, UC16 = 2 }; 36 enum Mode { ASCII = 1, UC16 = 2 };
37 enum Result { EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 }; 37 // Result of calling the generated RegExp code:
38 // RETRY: Something significant changed during execution, and the matching
39 // should be retried from scratch.
40 // EXCEPTION: Something failed during execution. If no exception has been
41 // thrown, it's an internal out-of-memory, and the caller should
42 // throw the exception.
43 // FAILURE: Matching failed.
44 // SUCCESS: Matching succeeded, and the output array has been filled with
45 // capture positions.
46 enum Result { RETRY = -2, EXCEPTION = -1, FAILURE = 0, SUCCESS = 1 };
38 47
39 RegExpMacroAssemblerIA32(Mode mode, int registers_to_save); 48 RegExpMacroAssemblerIA32(Mode mode, int registers_to_save);
40 virtual ~RegExpMacroAssemblerIA32(); 49 virtual ~RegExpMacroAssemblerIA32();
41 virtual int stack_limit_slack(); 50 virtual int stack_limit_slack();
42 virtual void AdvanceCurrentPosition(int by); 51 virtual void AdvanceCurrentPosition(int by);
43 virtual void AdvanceRegister(int reg, int by); 52 virtual void AdvanceRegister(int reg, int by);
44 virtual void Backtrack(); 53 virtual void Backtrack();
45 virtual void Bind(Label* label); 54 virtual void Bind(Label* label);
46 virtual void CheckAtStart(Label* on_at_start); 55 virtual void CheckAtStart(Label* on_at_start);
47 virtual void CheckBitmap(uc16 start, Label* bitmap, Label* on_zero); 56 virtual void CheckBitmap(uc16 start, Label* bitmap, Label* on_zero);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 virtual void ClearRegisters(int reg_from, int reg_to); 122 virtual void ClearRegisters(int reg_from, int reg_to);
114 virtual void WriteStackPointerToRegister(int reg); 123 virtual void WriteStackPointerToRegister(int reg);
115 124
116 static Result Match(Handle<Code> regexp, 125 static Result Match(Handle<Code> regexp,
117 Handle<String> subject, 126 Handle<String> subject,
118 int* offsets_vector, 127 int* offsets_vector,
119 int offsets_vector_length, 128 int offsets_vector_length,
120 int previous_index); 129 int previous_index);
121 130
122 static Result Execute(Code* code, 131 static Result Execute(Code* code,
123 Address* input, 132 String* input,
124 int start_offset, 133 int start_offset,
125 int end_offset, 134 const byte* input_start,
135 const byte* input_end,
126 int* output, 136 int* output,
127 bool at_start); 137 bool at_start);
128 138
129 private: 139 private:
130 // Offsets from ebp of function parameters and stored registers. 140 // Offsets from ebp of function parameters and stored registers.
131 static const int kFramePointer = 0; 141 static const int kFramePointer = 0;
132 // Above the frame pointer - function parameters and return address. 142 // Above the frame pointer - function parameters and return address.
133 static const int kReturn_eip = kFramePointer + kPointerSize; 143 static const int kReturn_eip = kFramePointer + kPointerSize;
134 static const int kInputBuffer = kReturn_eip + kPointerSize; 144 static const int kFrameAlign = kReturn_eip + kPointerSize;
135 static const int kInputStartOffset = kInputBuffer + kPointerSize; 145 // Parameters.
136 static const int kInputEndOffset = kInputStartOffset + kPointerSize; 146 static const int kInputString = kFrameAlign;
137 static const int kRegisterOutput = kInputEndOffset + kPointerSize; 147 static const int kStartIndex = kInputString + kPointerSize;
148 static const int kInputStart = kStartIndex + kPointerSize;
149 static const int kInputEnd = kInputStart + kPointerSize;
150 static const int kRegisterOutput = kInputEnd + kPointerSize;
138 static const int kAtStart = kRegisterOutput + kPointerSize; 151 static const int kAtStart = kRegisterOutput + kPointerSize;
139 static const int kStackHighEnd = kAtStart + kPointerSize; 152 static const int kStackHighEnd = kAtStart + kPointerSize;
140 // Below the frame pointer - local stack variables. 153 // Below the frame pointer - local stack variables.
141 // When adding local variables remember to push space for them in 154 // When adding local variables remember to push space for them in
142 // the frame in GetCode. 155 // the frame in GetCode.
143 static const int kBackup_esi = kFramePointer - kPointerSize; 156 static const int kBackup_esi = kFramePointer - kPointerSize;
144 static const int kBackup_edi = kBackup_esi - kPointerSize; 157 static const int kBackup_edi = kBackup_esi - kPointerSize;
145 static const int kBackup_ebx = kBackup_edi - kPointerSize; 158 static const int kBackup_ebx = kBackup_edi - kPointerSize;
146 static const int kInputStartMinusOne = kBackup_ebx - kPointerSize; 159 static const int kInputStartMinusOne = kBackup_ebx - kPointerSize;
147 // First register address. Following registers are below it on the stack. 160 // First register address. Following registers are below it on the stack.
148 static const int kRegisterZero = kInputStartMinusOne - kPointerSize; 161 static const int kRegisterZero = kInputStartMinusOne - kPointerSize;
149 162
150 // Initial size of code buffer. 163 // Initial size of code buffer.
151 static const size_t kRegExpCodeSize = 1024; 164 static const size_t kRegExpCodeSize = 1024;
152 // Initial size of constant buffers allocated during compilation. 165 // Initial size of constant buffers allocated during compilation.
153 static const int kRegExpConstantsSize = 256; 166 static const int kRegExpConstantsSize = 256;
154 167
168 static const byte* StringCharacterPosition(String* subject, int start_index);
169
155 // Compares two-byte strings case insensitively. 170 // Compares two-byte strings case insensitively.
156 // Called from generated RegExp code. 171 // Called from generated RegExp code.
157 static int CaseInsensitiveCompareUC16(uc16** buffer, 172 static int CaseInsensitiveCompareUC16(Address byte_offset1,
158 int byte_offset1, 173 Address byte_offset2,
159 int byte_offset2,
160 size_t byte_length); 174 size_t byte_length);
161 175
162 // Load a number of characters at the given offset from the 176 // Load a number of characters at the given offset from the
163 // current position, into the current-character register. 177 // current position, into the current-character register.
164 void LoadCurrentCharacterUnchecked(int cp_offset, int character_count); 178 void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
165 179
166 // Check whether preemption has been requested. 180 // Check whether preemption has been requested.
167 void CheckPreemption(); 181 void CheckPreemption();
168 182
169 // Check whether we are exceeding the stack limit on the backtrack stack. 183 // Check whether we are exceeding the stack limit on the backtrack stack.
170 void CheckStackLimit(); 184 void CheckStackLimit();
171 185
172 // Called from RegExp if the stack-guard is triggered. 186 // Called from RegExp if the stack-guard is triggered.
173 // If the code object is relocated, the return address is fixed before 187 // If the code object is relocated, the return address is fixed before
174 // returning. 188 // returning.
175 static int CheckStackGuardState(Address* return_address, Code* re_code); 189 static int CheckStackGuardState(Address* return_address,
190 Code* re_code,
191 Address re_frame);
192
193 // Generate a call to CheckStackGuardState.
194 void CallCheckStackGuardState(Register scratch);
176 195
177 // Called from RegExp if the backtrack stack limit is hit. 196 // Called from RegExp if the backtrack stack limit is hit.
178 // Tries to expand the stack. Returns the new stack-pointer if 197 // Tries to expand the stack. Returns the new stack-pointer if
179 // successful, and updates the stack_top address, or returns 0 if unable 198 // successful, and updates the stack_top address, or returns 0 if unable
180 // to grow the stack. 199 // to grow the stack.
181 // This function must not trigger a garbage collection. 200 // This function must not trigger a garbage collection.
182 static Address GrowStack(Address stack_pointer, Address* stack_top); 201 static Address GrowStack(Address stack_pointer, Address* stack_top);
183 202
184 // The ebp-relative location of a regexp register. 203 // The ebp-relative location of a regexp register.
185 Operand register_location(int register_index); 204 Operand register_location(int register_index);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 Label success_label_; 276 Label success_label_;
258 Label backtrack_label_; 277 Label backtrack_label_;
259 Label exit_label_; 278 Label exit_label_;
260 Label check_preempt_label_; 279 Label check_preempt_label_;
261 Label stack_overflow_label_; 280 Label stack_overflow_label_;
262 }; 281 };
263 282
264 }} // namespace v8::internal 283 }} // namespace v8::internal
265 284
266 #endif /* REGEXP_MACRO_ASSEMBLER_IA32_H_ */ 285 #endif /* REGEXP_MACRO_ASSEMBLER_IA32_H_ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698