| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client 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 | 6 |
| 7 #include "native_client/tests/thread_suspension/suspend_test.h" | 7 #include "native_client/tests/thread_suspension/suspend_test.h" |
| 8 | 8 |
| 9 #include "native_client/src/include/nacl_assert.h" | 9 #include "native_client/src/include/nacl_assert.h" |
| 10 #include "native_client/src/include/portability_io.h" | 10 #include "native_client/src/include/portability_io.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 regs.r8 = 0x12340009; | 332 regs.r8 = 0x12340009; |
| 333 /* | 333 /* |
| 334 * Skip r9 because it is not supposed to be settable or readable by | 334 * Skip r9 because it is not supposed to be settable or readable by |
| 335 * untrusted code. | 335 * untrusted code. |
| 336 */ | 336 */ |
| 337 regs.r10 = 0x1234000a; | 337 regs.r10 = 0x1234000a; |
| 338 regs.r11 = 0x1234000b; | 338 regs.r11 = 0x1234000b; |
| 339 regs.r12 = 0x1234000c; | 339 regs.r12 = 0x1234000c; |
| 340 /* Leave sp (r13) and lr (r14) alone for now. */ | 340 /* Leave sp (r13) and lr (r14) alone for now. */ |
| 341 regs.prog_ctr = test_shm->continue_after_suspension_func; | 341 regs.prog_ctr = test_shm->continue_after_suspension_func; |
| 342 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_mips |
| 343 /* Skip setting zero register because it's read-only. */ |
| 344 regs.at = 0x12340001; |
| 345 regs.v0 = 0x12340002; |
| 346 regs.v1 = 0x12340003; |
| 347 regs.a0 = 0x12340004; |
| 348 regs.a1 = 0x12340005; |
| 349 regs.a2 = 0x12340006; |
| 350 regs.a3 = 0x12340007; |
| 351 regs.t0 = 0x12340008; |
| 352 regs.t1 = 0x12340009; |
| 353 regs.t2 = 0x12340010; |
| 354 regs.t3 = 0x12340011; |
| 355 regs.t4 = 0x12340012; |
| 356 regs.t5 = 0x12340013; |
| 357 /* Skip setting t6 and t7 because those are mask registers. */ |
| 358 regs.s0 = 0x12340014; |
| 359 regs.s1 = 0x12340015; |
| 360 regs.s2 = 0x12340016; |
| 361 regs.s3 = 0x12340017; |
| 362 regs.s4 = 0x12340018; |
| 363 regs.s5 = 0x12340019; |
| 364 regs.s6 = 0x12340020; |
| 365 regs.s7 = 0x12340021; |
| 366 /* Skip setting t8 because it holds thread pointer. */ |
| 367 regs.t9 = 0x12340022; |
| 368 /* Skip setting k0 and k1 registers, they are used by kernel. */ |
| 369 regs.global_ptr = 0x12340023; |
| 370 /* Skip setting sp also. */ |
| 371 regs.frame_ptr = 0x12340025; |
| 372 regs.return_addr = 0x12340026; |
| 373 regs.prog_ctr = test_shm->continue_after_suspension_func; |
| 342 #else | 374 #else |
| 343 # error Unsupported architecture | 375 # error Unsupported architecture |
| 344 #endif | 376 #endif |
| 345 | 377 |
| 346 NaClAppThreadSetSuspendedRegisters(natp, ®s); | 378 NaClAppThreadSetSuspendedRegisters(natp, ®s); |
| 347 test_shm->expected_regs = regs; | 379 test_shm->expected_regs = regs; |
| 348 | 380 |
| 349 /* | 381 /* |
| 350 * Sanity check: After setting registers, getting registers should | 382 * Sanity check: After setting registers, getting registers should |
| 351 * read back what we just set. (We have to be careful to ensure | 383 * read back what we just set. (We have to be careful to ensure |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 456 |
| 425 /* | 457 /* |
| 426 * Only compare prog_ctr if the thread is inside the syscall, | 458 * Only compare prog_ctr if the thread is inside the syscall, |
| 427 * otherwise there is a small set of instructions that untrusted | 459 * otherwise there is a small set of instructions that untrusted |
| 428 * code executes. | 460 * code executes. |
| 429 */ | 461 */ |
| 430 if (!NaClAppThreadIsSuspendedInSyscall(natp)) { | 462 if (!NaClAppThreadIsSuspendedInSyscall(natp)) { |
| 431 regs.prog_ctr = test_shm->expected_regs.prog_ctr; | 463 regs.prog_ctr = test_shm->expected_regs.prog_ctr; |
| 432 RegsUnsetNonCalleeSavedRegisters(®s); | 464 RegsUnsetNonCalleeSavedRegisters(®s); |
| 433 } | 465 } |
| 434 /* | 466 RegsAssertEqual(®s, &test_shm->expected_regs); |
| 435 * TODO(mseaborn): Enable the RegsAssertEqual() check for MIPS | |
| 436 * once NaClGetRegistersForContextSwitch() is implemented for | |
| 437 * MIPS. | |
| 438 */ | |
| 439 if (NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 || | |
| 440 NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm) { | |
| 441 RegsAssertEqual(®s, &test_shm->expected_regs); | |
| 442 } | |
| 443 | 467 |
| 444 NaClUntrustedThreadsResumeAll(nap); | 468 NaClUntrustedThreadsResumeAll(nap); |
| 445 } | 469 } |
| 446 | 470 |
| 447 g_simple_syscall_should_exit = 1; | 471 g_simple_syscall_should_exit = 1; |
| 448 WaitForThreadToExitFully(nap); | 472 WaitForThreadToExitFully(nap); |
| 449 } | 473 } |
| 450 | 474 |
| 451 int main(int argc, char **argv) { | 475 int main(int argc, char **argv) { |
| 452 struct NaClApp app; | 476 struct NaClApp app; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 529 |
| 506 printf("Running TestGettingRegisterSnapshotInSyscallContextSwitch...\n"); | 530 printf("Running TestGettingRegisterSnapshotInSyscallContextSwitch...\n"); |
| 507 TestGettingRegisterSnapshotInSyscallContextSwitch(&app); | 531 TestGettingRegisterSnapshotInSyscallContextSwitch(&app); |
| 508 | 532 |
| 509 /* | 533 /* |
| 510 * Avoid calling exit() because it runs process-global destructors | 534 * Avoid calling exit() because it runs process-global destructors |
| 511 * which might break code that is running in our unjoined threads. | 535 * which might break code that is running in our unjoined threads. |
| 512 */ | 536 */ |
| 513 NaClExit(0); | 537 NaClExit(0); |
| 514 } | 538 } |
| OLD | NEW |