Skip to content

Commit 18ce873

Browse files
authored
Merge pull request #52 from owent/dev
Prepare v2.2.0
2 parents d381279 + d2ec5f2 commit 18ce873

35 files changed

+1877
-688
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# CHANGELOG
22

3+
## 2.2.0
4+
5+
1. Merge boost.fcontext 1.81.0
6+
2. Add `LIBCOPP_MACRO_TLS_STACK_PROTECTOR` to work with `-fstack-protector`
7+
3. Optimize `-pthread` flag detection.
8+
4. Support `-fno-rtti` now.
9+
5. Optimize timestamp of generated file to reduce regeneration.
10+
11+
## 2.1.4
12+
13+
1. Fixes timer reset when initialization.(#46 )
14+
2. Update CI environment of GCC 4.8.
15+
3. Add more strict warnings.
16+
4. Optimize spin lock, add `valid()` for `task_promise`(C++ 20 coroutine).
17+
5. Fix consistent of variant detection.
18+
19+
## 2.1.2
20+
21+
+ Update cmake-toolset
22+
+ Implement `unhandled_exception` when without exception.
23+
24+
## 2.1.1
25+
26+
+ Add helper function to pick task id and private data from C++20 coroutine task
27+
+ Fix trivial test
28+
+ Fix `Valgrind_ROOT`
29+
+ Fix compatibility of GCC SFINAE
30+
+ [CI] Add CodeQL job
31+
+ [CI] Add auto stale job
32+
+ [CI] Update linux image to ubuntu 22.04
33+
334
## 2.1.0
435

536
1. Allow custom `promise_error_transform` for C++20 coroutine.

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ enable_testing()
2020

2121
project(
2222
libcopp
23-
VERSION "2.1.4"
23+
VERSION "2.2.0"
2424
DESCRIPTION "Cross-platform coroutine library in C++ ."
2525
HOMEPAGE_URL "https://libcopp.atframe.work"
2626
LANGUAGES C CXX ASM)
@@ -70,6 +70,10 @@ cmake_dependent_option(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR "Enable C++11 std:
7070
"COMPILER_OPTIONS_TEST_STD_EXCEPTION_PTR" OFF)
7171
cmake_dependent_option(LIBCOPP_MACRO_ENABLE_RTTI "Enable C++11 std::exception_ptr support for libcopp" ON
7272
"COMPILER_OPTIONS_TEST_RTTI" OFF)
73+
option(
74+
LIBCOPP_MACRO_TLS_STACK_PROTECTOR
75+
"Users need set LIBCOPP_MACRO_TLS_STACK_PROTECTOR=ON when compiling with -fstack-protector, because it changes the default context switching logic."
76+
OFF)
7377

7478
check_cxx_source_compiles(
7579
"

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2022 OWenT
3+
Copyright (c) 2023 OWenT
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ Options can be cmake options. such as set compile toolchains, source directory o
217217
+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
218218
| LIBCOPP_FCONTEXT_USE_TSX=YES|NO | [default=YES] Enable `Intel Transactional Synchronisation Extensions (TSX) <https://software.intel.com/en-us/node/695149>`_. |
219219
+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
220+
| LIBCOPP_MACRO_TLS_STACK_PROTECTOR=YES|NO | [default=NO] Users need set LIBCOPP_MACRO_TLS_STACK_PROTECTOR=ON when compiling with ``-fstack-protector``. |
221+
| | Because it changes the default context switching logic. |
222+
+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
220223
| GTEST_ROOT=[path] | set gtest library install prefix path |
221224
+------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
222225
| BOOST_ROOT=[path] | set Boost.Test library install prefix path |

src/libcopp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ source_group_by_dir(COPP_SRC_LIST)
77
if(LIBCOPP_FCONTEXT_USE_TSX)
88
add_compiler_define(LIBCOPP_FCONTEXT_USE_TSX=1)
99
endif()
10+
if(LIBCOPP_MACRO_TLS_STACK_PROTECTOR)
11+
add_compiler_define(LIBCOPP_FCONTEXT_TLS_STACK_PROTECTOR=1)
12+
endif()
1013

1114
if(BUILD_SHARED_LIBS OR LIBCOPP_USE_DYNAMIC_LIBRARY)
1215
add_library(${PROJECT_LIBCOPP_LIB_LINK} SHARED ${COPP_SRC_LIST} ${COPP_OBJ_LIST})
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
; Copyright Edward Nevill + Oliver Kowalke 2015
2+
; Distributed under the Boost Software License, Version 1.0.
3+
; (See accompanying file LICENSE_1_0.txt or copy at
4+
; http://www.boost.org/LICENSE_1_0.txt)
5+
6+
;*******************************************************
7+
;* *
8+
;* ------------------------------------------------- *
9+
;* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
10+
;* ------------------------------------------------- *
11+
;* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
12+
;* ------------------------------------------------- *
13+
;* | d8 | d9 | d10 | d11 | *
14+
;* ------------------------------------------------- *
15+
;* ------------------------------------------------- *
16+
;* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
17+
;* ------------------------------------------------- *
18+
;* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
19+
;* ------------------------------------------------- *
20+
;* | d12 | d13 | d14 | d15 | *
21+
;* ------------------------------------------------- *
22+
;* ------------------------------------------------- *
23+
;* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
24+
;* ------------------------------------------------- *
25+
;* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
26+
;* ------------------------------------------------- *
27+
;* | x19 | x20 | x21 | x22 | *
28+
;* ------------------------------------------------- *
29+
;* ------------------------------------------------- *
30+
;* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
31+
;* ------------------------------------------------- *
32+
;* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
33+
;* ------------------------------------------------- *
34+
;* | x23 | x24 | x25 | x26 | *
35+
;* ------------------------------------------------- *
36+
;* ------------------------------------------------- *
37+
;* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
38+
;* ------------------------------------------------- *
39+
;* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
40+
;* ------------------------------------------------- *
41+
;* | x27 | x28 | FP | LR | *
42+
;* ------------------------------------------------- *
43+
;* ------------------------------------------------- *
44+
;* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
45+
;* ------------------------------------------------- *
46+
;* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| *
47+
;* ------------------------------------------------- *
48+
;* | fiber data| base | limit | dealloc | *
49+
;* ------------------------------------------------- *
50+
;* ------------------------------------------------- *
51+
;* | 48 | 49 | 50 | 51 | | | *
52+
;* ------------------------------------------------- *
53+
;* | 0xc0| 0xc4| 0xc8| 0xcc| | | *
54+
;* ------------------------------------------------- *
55+
;* | PC | align | | | *
56+
;* ------------------------------------------------- *
57+
;* *
58+
;*******************************************************
59+
60+
AREA |.text|, CODE, READONLY, ALIGN=4, CODEALIGN
61+
EXPORT copp_jump_fcontext_v2
62+
63+
copp_jump_fcontext_v2 proc
64+
; prepare stack for GP + FPU
65+
sub sp, sp, #0xd0
66+
67+
; save d8 - d15
68+
stp d8, d9, [sp, #0x00]
69+
stp d10, d11, [sp, #0x10]
70+
stp d12, d13, [sp, #0x20]
71+
stp d14, d15, [sp, #0x30]
72+
73+
; save x19-x30
74+
stp x19, x20, [sp, #0x40]
75+
stp x21, x22, [sp, #0x50]
76+
stp x23, x24, [sp, #0x60]
77+
stp x25, x26, [sp, #0x70]
78+
stp x27, x28, [sp, #0x80]
79+
stp x29, x30, [sp, #0x90]
80+
81+
; save LR as PC
82+
str x30, [sp, #0xc0]
83+
84+
; save current stack base and limit
85+
ldp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h
86+
stp x5, x6, [sp, #0xa0]
87+
; save current fiber data and deallocation stack
88+
ldr x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h
89+
ldr x6, [x18, #0x20] ; TeFiberData at ksarm64.h
90+
stp x5, x6, [sp, #0xb0]
91+
92+
; store RSP (pointing to context-data) in X0
93+
mov x4, sp
94+
95+
; restore RSP (pointing to context-data) from X1
96+
mov sp, x0
97+
98+
; restore stack base and limit
99+
ldp x5, x6, [sp, #0xa0]
100+
stp x5, x6, [x18, #0x08] ; TeStackBase and TeStackLimit at ksarm64.h
101+
; restore fiber data and deallocation stack
102+
ldp x5, x6, [sp, #0xb0]
103+
str x5, [x18, #0x1478] ; TeDeallocationStack at ksarm64.h
104+
str x6, [x18, #0x20] ; TeFiberData at ksarm64.h
105+
106+
; load d8 - d15
107+
ldp d8, d9, [sp, #0x00]
108+
ldp d10, d11, [sp, #0x10]
109+
ldp d12, d13, [sp, #0x20]
110+
ldp d14, d15, [sp, #0x30]
111+
112+
; load x19-x30
113+
ldp x19, x20, [sp, #0x40]
114+
ldp x21, x22, [sp, #0x50]
115+
ldp x23, x24, [sp, #0x60]
116+
ldp x25, x26, [sp, #0x70]
117+
ldp x27, x28, [sp, #0x80]
118+
ldp x29, x30, [sp, #0x90]
119+
120+
; return transfer_t from jump
121+
; pass transfer_t as first arg in context function
122+
; X0 == FCTX, X1 == DATA
123+
mov x0, x4
124+
125+
; load pc
126+
ldr x4, [sp, #0xc0]
127+
128+
; restore stack from GP + FPU
129+
add sp, sp, #0xd0
130+
131+
ret x4
132+
ENDP
133+
END

src/libcopp/fcontext/asm/jump_arm_aapcs_macho_gas.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ _copp_jump_fcontext_v2:
5252
bic v2, v2, #3
5353

5454
@ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key]
55-
ldr v1, [v2, #8]
55+
ldr v1, [v2, #72]
5656
@ save SjLj handler
5757
push {v1}
5858

@@ -79,7 +79,7 @@ _copp_jump_fcontext_v2:
7979
@ r#estore SjLj handler
8080
pop {v1}
8181
@ store SjLj handler in TLS
82-
str v1, [v2, #8]
82+
str v1, [v2, #72]
8383

8484
@ restore hidden,V1-V8,LR
8585
pop {a4,v1-v8,lr}

src/libcopp/fcontext/asm/jump_i386_sysv_elf_gas.S

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
* ---------------------------------------------------------------------------------- *
1313
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
1414
* ---------------------------------------------------------------------------------- *
15-
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | hidden | *
15+
* | fc_mxcsr|fc_x87_cw| guard | EDI | ESI | EBX | EBP | EIP | *
1616
* ---------------------------------------------------------------------------------- *
1717
* ---------------------------------------------------------------------------------- *
1818
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
1919
* ---------------------------------------------------------------------------------- *
20-
* | 0x20 | 0x24 | | *
20+
* | 0x20 | 0x24 | 0x28 | | *
2121
* ---------------------------------------------------------------------------------- *
22-
* | to | data | | *
22+
* | hidden | to | data | | *
2323
* ---------------------------------------------------------------------------------- *
2424
* *
2525
****************************************************************************************/
@@ -30,50 +30,60 @@
3030
.align 2
3131
.type copp_jump_fcontext_v2,@function
3232
copp_jump_fcontext_v2:
33-
leal -0x18(%esp), %esp /* prepare stack */
33+
leal -0x1c(%esp), %esp /* prepare stack */
3434

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

40-
movl %edi, 0x8(%esp) /* save EDI */
41-
movl %esi, 0xc(%esp) /* save ESI */
42-
movl %ebx, 0x10(%esp) /* save EBX */
43-
movl %ebp, 0x14(%esp) /* save EBP */
40+
#if defined(LIBCOPP_FCONTEXT_TLS_STACK_PROTECTOR)
41+
movl %gs:0x14, %ecx /* read stack guard from TLS record */
42+
movl %ecx, 0x8(%esp) /* save stack guard */
43+
#endif
44+
45+
movl %edi, 0xc(%esp) /* save EDI */
46+
movl %esi, 0x10(%esp) /* save ESI */
47+
movl %ebx, 0x14(%esp) /* save EBX */
48+
movl %ebp, 0x18(%esp) /* save EBP */
4449

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

4853
/* first arg of copp_jump_fcontext_v2() == fcontext to jump to */
49-
movl 0x20(%esp), %eax
54+
movl 0x24(%esp), %eax
5055

5156
/* second arg of copp_jump_fcontext_v2() == data to be transferred */
52-
movl 0x24(%esp), %edx
57+
movl 0x28(%esp), %edx
5358

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

5762
/* address of returned transport_t */
58-
movl 0x1c(%esp), %eax
63+
movl 0x20(%esp), %eax
5964
/* return parent fcontext_t */
6065
movl %ecx, (%eax)
6166
/* return data */
6267
movl %edx, 0x4(%eax)
6368

64-
movl 0x18(%esp), %ecx /* restore EIP */
69+
movl 0x1c(%esp), %ecx /* restore EIP */
6570

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

71-
movl 0x8(%esp), %edi /* restore EDI */
72-
movl 0xc(%esp), %esi /* restore ESI */
73-
movl 0x10(%esp), %ebx /* restore EBX */
74-
movl 0x14(%esp), %ebp /* restore EBP */
76+
#if defined(LIBCOPP_FCONTEXT_TLS_STACK_PROTECTOR)
77+
movl 0x8(%esp), %edx /* load stack guard */
78+
movl %edx, %gs:0x14 /* restore stack guard to TLS record */
79+
#endif
80+
81+
movl 0xc(%esp), %edi /* restore EDI */
82+
movl 0x10(%esp), %esi /* restore ESI */
83+
movl 0x14(%esp), %ebx /* restore EBX */
84+
movl 0x18(%esp), %ebp /* restore EBP */
7585

76-
leal 0x20(%esp), %esp /* prepare stack */
86+
leal 0x24(%esp), %esp /* prepare stack */
7787

7888
/* jump to context */
7989
jmp *%ecx

0 commit comments

Comments
 (0)