Skip to content

Commit

Permalink
Merge pull request #52 from owent/dev
Browse files Browse the repository at this point in the history
Prepare v2.2.0
  • Loading branch information
owent authored Apr 12, 2023
2 parents d381279 + d2ec5f2 commit 18ce873
Show file tree
Hide file tree
Showing 35 changed files with 1,877 additions and 688 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# CHANGELOG

## 2.2.0

1. Merge boost.fcontext 1.81.0
2. Add `LIBCOPP_MACRO_TLS_STACK_PROTECTOR` to work with `-fstack-protector`
3. Optimize `-pthread` flag detection.
4. Support `-fno-rtti` now.
5. Optimize timestamp of generated file to reduce regeneration.

## 2.1.4

1. Fixes timer reset when initialization.(#46 )
2. Update CI environment of GCC 4.8.
3. Add more strict warnings.
4. Optimize spin lock, add `valid()` for `task_promise`(C++ 20 coroutine).
5. Fix consistent of variant detection.

## 2.1.2

+ Update cmake-toolset
+ Implement `unhandled_exception` when without exception.

## 2.1.1

+ Add helper function to pick task id and private data from C++20 coroutine task
+ Fix trivial test
+ Fix `Valgrind_ROOT`
+ Fix compatibility of GCC SFINAE
+ [CI] Add CodeQL job
+ [CI] Add auto stale job
+ [CI] Update linux image to ubuntu 22.04

## 2.1.0

1. Allow custom `promise_error_transform` for C++20 coroutine.
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enable_testing()

project(
libcopp
VERSION "2.1.4"
VERSION "2.2.0"
DESCRIPTION "Cross-platform coroutine library in C++ ."
HOMEPAGE_URL "https://libcopp.atframe.work"
LANGUAGES C CXX ASM)
Expand Down Expand Up @@ -70,6 +70,10 @@ cmake_dependent_option(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR "Enable C++11 std:
"COMPILER_OPTIONS_TEST_STD_EXCEPTION_PTR" OFF)
cmake_dependent_option(LIBCOPP_MACRO_ENABLE_RTTI "Enable C++11 std::exception_ptr support for libcopp" ON
"COMPILER_OPTIONS_TEST_RTTI" OFF)
option(
LIBCOPP_MACRO_TLS_STACK_PROTECTOR
"Users need set LIBCOPP_MACRO_TLS_STACK_PROTECTOR=ON when compiling with -fstack-protector, because it changes the default context switching logic."
OFF)

check_cxx_source_compiles(
"
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2022 OWenT
Copyright (c) 2023 OWenT

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ Options can be cmake options. such as set compile toolchains, source directory o
+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| LIBCOPP_FCONTEXT_USE_TSX=YES|NO | [default=YES] Enable `Intel Transactional Synchronisation Extensions (TSX) <https://software.intel.com/en-us/node/695149>`_. |
+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| LIBCOPP_MACRO_TLS_STACK_PROTECTOR=YES|NO | [default=NO] Users need set LIBCOPP_MACRO_TLS_STACK_PROTECTOR=ON when compiling with ``-fstack-protector``. |
| | Because it changes the default context switching logic. |
+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| GTEST_ROOT=[path] | set gtest library install prefix path |
+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| BOOST_ROOT=[path] | set Boost.Test library install prefix path |
Expand Down
3 changes: 3 additions & 0 deletions src/libcopp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ source_group_by_dir(COPP_SRC_LIST)
if(LIBCOPP_FCONTEXT_USE_TSX)
add_compiler_define(LIBCOPP_FCONTEXT_USE_TSX=1)
endif()
if(LIBCOPP_MACRO_TLS_STACK_PROTECTOR)
add_compiler_define(LIBCOPP_FCONTEXT_TLS_STACK_PROTECTOR=1)
endif()

if(BUILD_SHARED_LIBS OR LIBCOPP_USE_DYNAMIC_LIBRARY)
add_library(${PROJECT_LIBCOPP_LIB_LINK} SHARED ${COPP_SRC_LIST} ${COPP_OBJ_LIST})
Expand Down
133 changes: 133 additions & 0 deletions src/libcopp/fcontext/asm/jump_arm64_aapcs_pe_armasm.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
; Copyright Edward Nevill + Oliver Kowalke 2015
; Distributed under the Boost Software License, Version 1.0.
; (See accompanying file LICENSE_1_0.txt or copy at
; http://www.boost.org/LICENSE_1_0.txt)

;*******************************************************
;* *
;* ------------------------------------------------- *
;* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
;* ------------------------------------------------- *
;* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
;* ------------------------------------------------- *
;* | d8 | d9 | d10 | d11 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
;* ------------------------------------------------- *
;* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
;* ------------------------------------------------- *
;* | d12 | d13 | d14 | d15 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
;* ------------------------------------------------- *
;* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
;* ------------------------------------------------- *
;* | x19 | x20 | x21 | x22 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
;* ------------------------------------------------- *
;* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
;* ------------------------------------------------- *
;* | x23 | x24 | x25 | x26 | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
;* ------------------------------------------------- *
;* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
;* ------------------------------------------------- *
;* | x27 | x28 | FP | LR | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
;* ------------------------------------------------- *
;* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| *
;* ------------------------------------------------- *
;* | fiber data| base | limit | dealloc | *
;* ------------------------------------------------- *
;* ------------------------------------------------- *
;* | 48 | 49 | 50 | 51 | | | *
;* ------------------------------------------------- *
;* | 0xc0| 0xc4| 0xc8| 0xcc| | | *
;* ------------------------------------------------- *
;* | PC | align | | | *
;* ------------------------------------------------- *
;* *
;*******************************************************

AREA |.text|, CODE, READONLY, ALIGN=4, CODEALIGN
EXPORT copp_jump_fcontext_v2

copp_jump_fcontext_v2 proc
; prepare stack for GP + FPU
sub sp, sp, #0xd0

; save d8 - d15
stp d8, d9, [sp, #0x00]
stp d10, d11, [sp, #0x10]
stp d12, d13, [sp, #0x20]
stp d14, d15, [sp, #0x30]

; save x19-x30
stp x19, x20, [sp, #0x40]
stp x21, x22, [sp, #0x50]
stp x23, x24, [sp, #0x60]
stp x25, x26, [sp, #0x70]
stp x27, x28, [sp, #0x80]
stp x29, x30, [sp, #0x90]

; save LR as PC
str x30, [sp, #0xc0]

; save current stack base and limit
ldp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h
stp x5, x6, [sp, #0xa0]
; save current fiber data and deallocation stack
ldr x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h
ldr x6, [x18, #0x20] ; TeFiberData at ksarm64.h
stp x5, x6, [sp, #0xb0]

; store RSP (pointing to context-data) in X0
mov x4, sp

; restore RSP (pointing to context-data) from X1
mov sp, x0

; restore stack base and limit
ldp x5, x6, [sp, #0xa0]
stp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h
; restore fiber data and deallocation stack
ldp x5, x6, [sp, #0xb0]
str x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h
str x6, [x18, #0x20] ; TeFiberData at ksarm64.h

; load d8 - d15
ldp d8, d9, [sp, #0x00]
ldp d10, d11, [sp, #0x10]
ldp d12, d13, [sp, #0x20]
ldp d14, d15, [sp, #0x30]

; load x19-x30
ldp x19, x20, [sp, #0x40]
ldp x21, x22, [sp, #0x50]
ldp x23, x24, [sp, #0x60]
ldp x25, x26, [sp, #0x70]
ldp x27, x28, [sp, #0x80]
ldp x29, x30, [sp, #0x90]

; return transfer_t from jump
; pass transfer_t as first arg in context function
; X0 == FCTX, X1 == DATA
mov x0, x4

; load pc
ldr x4, [sp, #0xc0]

; restore stack from GP + FPU
add sp, sp, #0xd0

ret x4
ENDP
END
4 changes: 2 additions & 2 deletions src/libcopp/fcontext/asm/jump_arm_aapcs_macho_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ _copp_jump_fcontext_v2:
bic v2, v2, #3

@ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key]
ldr v1, [v2, #8]
ldr v1, [v2, #72]
@ save SjLj handler
push {v1}

Expand All @@ -79,7 +79,7 @@ _copp_jump_fcontext_v2:
@ r#estore SjLj handler
pop {v1}
@ store SjLj handler in TLS
str v1, [v2, #8]
str v1, [v2, #72]

@ restore hidden,V1-V8,LR
pop {a4,v1-v8,lr}
Expand Down
44 changes: 27 additions & 17 deletions src/libcopp/fcontext/asm/jump_i386_sysv_elf_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | hidden | *
* | fc_mxcsr|fc_x87_cw| guard | EDI | ESI | EBX | EBP | EIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | | *
* | 0x20 | 0x24 | 0x28 | | *
* ---------------------------------------------------------------------------------- *
* | to | data | | *
* | hidden | to | data | | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
Expand All @@ -30,50 +30,60 @@
.align 2
.type copp_jump_fcontext_v2,@function
copp_jump_fcontext_v2:
leal -0x18(%esp), %esp /* prepare stack */
leal -0x1c(%esp), %esp /* prepare stack */

#if !defined(LIBCOPP_FCONTEXT_USE_TSX)
stmxcsr (%esp) /* save MMX control- and status-word */
fnstcw 0x4(%esp) /* save x87 control-word */
#endif

movl %edi, 0x8(%esp) /* save EDI */
movl %esi, 0xc(%esp) /* save ESI */
movl %ebx, 0x10(%esp) /* save EBX */
movl %ebp, 0x14(%esp) /* save EBP */
#if defined(LIBCOPP_FCONTEXT_TLS_STACK_PROTECTOR)
movl %gs:0x14, %ecx /* read stack guard from TLS record */
movl %ecx, 0x8(%esp) /* save stack guard */
#endif

movl %edi, 0xc(%esp) /* save EDI */
movl %esi, 0x10(%esp) /* save ESI */
movl %ebx, 0x14(%esp) /* save EBX */
movl %ebp, 0x18(%esp) /* save EBP */

/* store ESP (pointing to context-data) in ECX */
movl %esp, %ecx

/* first arg of copp_jump_fcontext_v2() == fcontext to jump to */
movl 0x20(%esp), %eax
movl 0x24(%esp), %eax

/* second arg of copp_jump_fcontext_v2() == data to be transferred */
movl 0x24(%esp), %edx
movl 0x28(%esp), %edx

/* restore ESP (pointing to context-data) from EAX */
movl %eax, %esp

/* address of returned transport_t */
movl 0x1c(%esp), %eax
movl 0x20(%esp), %eax
/* return parent fcontext_t */
movl %ecx, (%eax)
/* return data */
movl %edx, 0x4(%eax)

movl 0x18(%esp), %ecx /* restore EIP */
movl 0x1c(%esp), %ecx /* restore EIP */

#if !defined(LIBCOPP_FCONTEXT_USE_TSX)
ldmxcsr (%esp) /* restore MMX control- and status-word */
fldcw 0x4(%esp) /* restore x87 control-word */
#endif

movl 0x8(%esp), %edi /* restore EDI */
movl 0xc(%esp), %esi /* restore ESI */
movl 0x10(%esp), %ebx /* restore EBX */
movl 0x14(%esp), %ebp /* restore EBP */
#if defined(LIBCOPP_FCONTEXT_TLS_STACK_PROTECTOR)
movl 0x8(%esp), %edx /* load stack guard */
movl %edx, %gs:0x14 /* restore stack guard to TLS record */
#endif

movl 0xc(%esp), %edi /* restore EDI */
movl 0x10(%esp), %esi /* restore ESI */
movl 0x14(%esp), %ebx /* restore EBX */
movl 0x18(%esp), %ebp /* restore EBP */

leal 0x20(%esp), %esp /* prepare stack */
leal 0x24(%esp), %esp /* prepare stack */

/* jump to context */
jmp *%ecx
Expand Down
Loading

0 comments on commit 18ce873

Please sign in to comment.