/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CO2_INT_H #define CO2_INT_H #include #include #ifdef __cplusplus extern "C" { #endif #if defined(__aarch64__) #define REG_NR 22 #define REG_LR 11 #define REG_SP 13 #elif defined(__arm__) #define REG_NR 64 #define REG_LR 1 #define REG_SP 0 #elif defined(__x86_64__) #define REG_NR 8 #define REG_LR 7 #define REG_SP 6 #else #error "Unsupported architecture" #endif struct co2_context { uintptr_t regs[REG_NR]; }; int co2_save_context(struct co2_context* ctx); void co2_restore_context(struct co2_context* ctx); static inline void co2_switch_context(struct co2_context* from, struct co2_context* to) { if (co2_save_context(from) == 0) { co2_restore_context(to); } } int co2_init_context(struct co2_context* ctx, void (*func)(void*), void* arg, void* stack, size_t stack_size); #ifdef __cplusplus } #endif #endif /* CO2_INT_H */