Apollo 10.0
自动驾驶开放平台
routine_context.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19namespace apollo {
20namespace cyber {
21namespace croutine {
22
23// The stack layout looks as follows:
24//
25// +------------------+
26// | Reserved |
27// +------------------+
28// | Return Address | f1
29// +------------------+
30// | RDI | arg
31// +------------------+
32// | R12 |
33// +------------------+
34// | R13 |
35// +------------------+
36// | ... |
37// +------------------+
38// ctx->sp => | RBP |
39// +------------------+
40void MakeContext(const func &f1, const void *arg, RoutineContext *ctx) {
41 ctx->sp = ctx->stack + STACK_SIZE - 2 * sizeof(void *) - REGISTERS_SIZE;
42 std::memset(ctx->sp, 0, REGISTERS_SIZE);
43#ifdef __aarch64__
44 char *sp = ctx->stack + STACK_SIZE - sizeof(void *);
45#else
46 char *sp = ctx->stack + STACK_SIZE - 2 * sizeof(void *);
47#endif
48 *reinterpret_cast<void **>(sp) = reinterpret_cast<void *>(f1);
49 sp -= sizeof(void *);
50 *reinterpret_cast<void **>(sp) = const_cast<void *>(arg);
51}
52
53} // namespace croutine
54} // namespace cyber
55} // namespace apollo
constexpr size_t REGISTERS_SIZE
constexpr size_t STACK_SIZE
void MakeContext(const func &f1, const void *arg, RoutineContext *ctx)
class register implement
Definition arena_queue.h:37