| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008, Google Inc. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * All rights reserved. | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * | 4 * found in the LICENSE file. |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are | |
| 7 * met: | |
| 8 * | |
| 9 * * Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * * Redistributions in binary form must reproduce the above | |
| 12 * copyright notice, this list of conditions and the following disclaimer | |
| 13 * in the documentation and/or other materials provided with the | |
| 14 * distribution. | |
| 15 * * Neither the name of Google Inc. nor the names of its | |
| 16 * contributors may be used to endorse or promote products derived from | |
| 17 * this software without specific prior written permission. | |
| 18 * | |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 30 */ | 5 */ |
| 31 | 6 |
| 32 /* | 7 /* |
| 33 * NaCl Service Runtime, C-level context switch code. | 8 * NaCl Service Runtime, C-level context switch code. |
| 34 */ | 9 */ |
| 35 | 10 |
| 36 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 11 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| 37 #include "native_client/src/trusted/service_runtime/arch/arm/sel_rt.h" | 12 #include "native_client/src/trusted/service_runtime/arch/arm/sel_rt.h" |
| 38 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 13 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
| 39 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | 14 #include "native_client/src/trusted/service_runtime/nacl_globals.h" |
| 40 #include "native_client/src/trusted/service_runtime/nacl_switch_to_app.h" | 15 #include "native_client/src/trusted/service_runtime/nacl_switch_to_app.h" |
| 41 | 16 |
| 42 | 17 |
| 43 NORETURN void NaClStartThreadInApp(struct NaClAppThread *natp, | 18 NORETURN void NaClStartThreadInApp(struct NaClAppThread *natp, |
| 44 uint32_t new_prog_ctr) { | 19 uint32_t new_prog_ctr) { |
| 45 struct NaClApp *nap; | 20 struct NaClApp *nap; |
| 46 struct NaClThreadContext *context; | 21 struct NaClThreadContext *context; |
| 47 | 22 |
| 48 natp->sys.stack_ptr = (NaClGetSp() & ~0xf) + 4; | 23 natp->sys.stack_ptr = (NaClGetSp() & ~0xf) + 4; |
| 49 | 24 |
| 25 nap = natp->nap; |
| 26 context = &natp->user; |
| 27 context->spring_addr = NaClSysToUser(nap, |
| 28 nap->mem_start + nap->springboard_addr); |
| 29 context->new_eip = new_prog_ctr; |
| 30 |
| 31 /* |
| 32 * At startup this is not the return value, but the first argument. |
| 33 * In the initial thread, it gets the pointer to the information |
| 34 * block on the stack. Additional threads do not expect anything in |
| 35 * particular in the first argument register, so we don't bother to |
| 36 * conditionalize this. |
| 37 */ |
| 38 context->sysret = context->stack_ptr; |
| 39 |
| 50 /* | 40 /* |
| 51 * springboard pops 4 words from stack which are the parameters for | 41 * springboard pops 4 words from stack which are the parameters for |
| 52 * syscall. In this case, it is not a syscall so no parameters, but we still | 42 * syscall. In this case, it is not a syscall so no parameters, but we still |
| 53 * need to adjust the stack | 43 * need to adjust the stack |
| 54 */ | 44 */ |
| 55 natp->user.stack_ptr -= 16; | 45 context->stack_ptr -= 16; |
| 56 nap = natp->nap; | |
| 57 context = &natp->user; | |
| 58 context->spring_addr = NaClSysToUser(nap, | |
| 59 nap->mem_start + nap->springboard_addr); | |
| 60 context->new_eip = new_prog_ctr; | |
| 61 context->sysret = 0; /* not used to return */ | |
| 62 | 46 |
| 63 NaClSwitch(context); | 47 NaClSwitch(context); |
| 64 } | 48 } |
| 65 | 49 |
| 66 /* | 50 /* |
| 67 * syscall return | 51 * syscall return |
| 68 */ | 52 */ |
| 69 NORETURN void NaClSwitchToApp(struct NaClAppThread *natp, | 53 NORETURN void NaClSwitchToApp(struct NaClAppThread *natp, |
| 70 uint32_t new_prog_ctr) { | 54 uint32_t new_prog_ctr) { |
| 71 struct NaClApp *nap; | 55 struct NaClApp *nap; |
| 72 struct NaClThreadContext *context; | 56 struct NaClThreadContext *context; |
| 73 | 57 |
| 74 nap = natp->nap; | 58 nap = natp->nap; |
| 75 context = &natp->user; | 59 context = &natp->user; |
| 76 context->spring_addr = NaClSysToUser(nap, | 60 context->spring_addr = NaClSysToUser(nap, |
| 77 nap->mem_start + nap->springboard_addr); | 61 nap->mem_start + nap->springboard_addr); |
| 78 context->new_eip = new_prog_ctr; | 62 context->new_eip = new_prog_ctr; |
| 79 context->sysret = natp->sysret; | 63 context->sysret = natp->sysret; |
| 80 | 64 |
| 81 NaClSwitch(context); | 65 NaClSwitch(context); |
| 82 } | 66 } |
| OLD | NEW |