Граф коммитов

85 Коммитов

Автор SHA1 Сообщение Дата
KJ Tsanaktsidis 86c2724e75 Don't emit ELF notes on non-ELF platforms
These apparently break compilation on old MacOS toolchains, because the
MachO section name is capped to 16 chars (although, on my MacOS, at
least, the section name just gets truncated). Nevertheless, these serve
no purpose on non-ELF platforms (they're part of the LSB Linux ABI).

[Bug #20677]
2024-08-22 17:35:43 +10:00
KJ Tsanaktsidis ff0a181852 Fix typo in ELF note generation
This wasn't looking at the right macro name for pac-ret support, so if
Ruby was compiled with pac-ret but NOT BTI, then the ELF note would not
be emitted.
2024-08-22 17:35:43 +10:00
KJ Tsanaktsidis 8ec67052e6 Do not define SHSTK feature for amd64 Context.S
We do not implement CET shadow-stack switching in amd64 Context.S. If
you compile Ruby with `-fcf-protection=full` and run it with
`GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK` exported, it will crash with a
control flow exception.

Configure the appropriate notes at the end of Context.S

[Bug #18061]
2024-07-07 20:14:44 +10:00
KJ Tsanaktsidis b940de83de Revert autoconf macros defining RUBY_AARCH64_{BTI|PAC}_ENABLED
This partially reverts https://github.com/ruby/ruby/pull/10944; now that
we decided to pass CFLAGS to $(CC) when assembling .S files, we don't
need these autoconf macros that capture the state of
__ARM_FEATURE{PAC|BTI}_DEFAULT.

[Bug #20601]
2024-07-07 20:14:44 +10:00
Vít Ondruch d9398ac430
Use `__CET__` macro to enable IBT support. (#11081)
According to the GCC documentation [1], the macro `__CET__` is dfined
when `-fcf-protection` compiler option is used. Therefore use this macro
to enable IBT support instead of special casing for `__OpenBSD__`.

[1]: https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fcf-protection
2024-07-04 08:37:41 +09:00
Jeremy Evans a60831f9b6 Use ENDBR instruction in amd64 coroutine on OpenBSD
When running on newer Intel processors supporting the feature,
OpenBSD enforces indirect branch tracking.  Without this endbr64
instruction, jumps to the coroutine_transfer function result
in SIGILL on OpenBSD/amd64 when using such processors.

The OpenBSD Ruby ports have been using a patch similar to this
for the past two months.

From some research, cet.h has been supported by GCC for about
6 years and LLVM for about 4 years.
2024-06-13 07:28:59 -07:00
KJ Tsanaktsidis 0ccb80d6bf Extract hardening CFLAGS to a special $hardenflags variable
This changes the automatic detection of -fstack-protector,
-D_FORTIFY_SOURCE, and -mbranch-protection to write to $hardenflags
instead of $XCFLAGS. The definition of $cflags is changed to
"$hardenflags $orig_cflags $optflags $debugflags $warnflags" to match.

Furthermore, these flags are _prepended_ to $hardenflags, rather than
appended.

The implications of doing this are as follows:

* If a CRuby builder specifies cflags="-mbranch-protection=foobar" at
  the ./configure script, and the configure script detects that
  -mbranch-protection=pac-ret is accepted, then GCC will be invoked as
  "gcc -mbranch-protection=pac-ret -mbranch-protection=foobar". Since
  the last flags take precedence, that means that user-supplied values
  of these flags in $cflags will take priority.
* Likewise, if a CRuby builder explicitly specifies
  "hardenflags=-mbranch-protection=foobar", because we _prepend_ to
  $hardenflags in our autoconf script, we will still invoke GCC as
  "gcc -mbranch-protection=pac-ret -mbranch-protection=foobar".
* If a CRuby builder specifies CFLAGS="..." at the configure line,
  automatic detection of hardening flags is ignored as before.
* C extensions will _also_ be built with hardening flags now as well
  (this was not the case by default before because the detected flags
  went into $XCFLAGS).

Additionally, as part of this work, I changed how the detection of
PAC/BTI in Context.S works. Rather than appending the autodetected
option to ASFLAGS, we simply compile a set of test programs with the
actual CFLAGS in use to determine what PAC/BTI settings were actually
chosen by the builder. Context.S is made aware of these choices through
some custom macros.

The result of this work is that:

* Ruby will continue to choose some sensible defaults for hardening
  options for the C compiler
* Distributors are able to specify CFLAGS that are consistent with their
  distribution and override these defaults
* Context.S will react to whatever -mbranch-protection is actually in
  use, not what was autodetected
* Extensions get built with hardening flags too.

[Bug #20154]
[Bug #20520]
2024-06-11 20:48:55 +10:00
cui fliter 226a889dc7
[DOC] fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 18:50:47 +09:00
Nobuyoshi Nakada 603392b8d4
Win32: Use prototype 2024-02-11 20:55:26 +09:00
Nobuyoshi Nakada 4f6b827e98
Use `__asm` instead of `asm`
With `--std=c99` option coroutine/arm64/Context.h errs:

```
In file included from cont.c:26:
coroutine/arm64/Context.h:59:5: error: call to undeclared function 'asm'; ISO C99 and later do not support
      implicit function declarations [-Wimplicit-function-declaration]
   59 |     asm ("hint #8;" : "+r"(r17) : "r"(r16));
      |     ^
```

Also move the common function header.
2024-02-06 12:19:56 +09:00
Yuta Saito 0d4de0f4b1 wasm: align fiber stack pointer to 16 bytes
In WebAssembly C ABI, the linear stack pointer must be always aligned
to 16 bytes like other archs.
The misaligned stack pointer causes some weird memory corruption since
compiler assumes the aligned stack pointer.
2024-01-29 23:45:36 +09:00
Yuta Saito fa0f7522c4 coroutine/arm64: Skip saving/restoring x30 twice and use `autiasp`
We don't need to save/restore x30 twice, and we can just use `ret`,
which uses x30 as return address register instead of explicit `ret <reg>`
instruction. This also allows us to use `autiasp` instead of `autia1716`
and we can skip setting SP/LR to x16/x17.

Also the size of register save area is shrunk by 16 bytes due to the
removal of extra x30 save/restore.
2023-12-22 11:30:00 +09:00
Yuta Saito 2d004decde coroutine/arm64/Context.S: Append PAC/BTI note section if needed
Fixes https://bugs.ruby-lang.org/issues/20029
2023-12-22 11:30:00 +09:00
Yuta Saito 35587150e2 coroutine/arm64/Context.S: Insert `bti c` as BTI landing pad 2023-12-22 11:30:00 +09:00
Yuta Saito d9e5564ccd coroutine/arm64: Sign return address if PAC enabled 2023-12-22 11:30:00 +09:00
Nobuyoshi Nakada 368a1cb3c4
Do not use non-ASCII chars in sources
No encodings are guaranteed in C compilers, and other than UTF-8
encodings may be assumed in some platforms, e.g., CP932 on Windows
Japanese edition, and may result in compilation errors.
2023-11-05 02:14:26 +09:00
Samuel Williams 40d774bec6
Avoid memory dependency between instructions. (#8284) 2023-08-25 13:28:33 +12:00
小MAO钓鱼 65ef20d2a7
Add support for LoongArch (#7343)
* vm_dump.c: Dump machine registers on loongarch64 Linux.

* coroutines: Support for native loongarch64 coroutines.

---------

Co-authored-by: zangruochen <zangruochen@loongson.cn>
2023-02-22 13:11:33 +09:00
Sergey Fedorov 567725ed30
Fix and improve coroutines for Darwin (macOS) ppc/ppc64. (#5975) 2022-10-19 23:49:45 +13:00
Samuel Williams 901525b107 Add support for address sanitizer for amd64 and arm64. 2022-05-25 15:24:24 +12:00
Sergey Fedorov 539459abda
Ruby31: add support for Darwin ppc/ppc64 (#5927)
* add coroutines for ppc & ppc64

* fix universal coroutine to include ppc & ppc64

* add powerpc*-darwin to configure.ac

* fix thread_pthread for older systems
2022-05-22 15:02:03 +12:00
Yuta Saito a4b73f1ba8 [wasm] add coroutine/asyncify implementation
set the default coroutine_type as asyncify when wasi
2022-01-19 11:19:06 +09:00
Samuel Williams 1862d961a9 Ignore dead threads in `coroutine_join`. 2021-07-02 12:36:14 +12:00
Samuel Williams 42130a64f0
Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
Benoit Daloze 229cbeba8c Fix -Wundef warnings in coroutine/*/Context.h
* See [Feature #17752]

Co-authored-by: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com>
2021-05-04 14:56:55 +02:00
David CARLIER 68a8f611e0 coroutine: Darwin on ARM64 needs alignment of 2^2 2021-04-01 23:51:06 +13:00
Samuel Williams b507f65d44 Support for native riscv64 coroutines. 2021-03-30 19:23:17 +13:00
David CARLIER 816a1d97fd coroutine mac m1 update.
using proper link register and frame pointer which equal x30/x29.
2021-03-22 23:32:07 +09:00
David Carlier 0ead818d81 Generating note.GNU-stack section for FreeBSD on x86.
Not enabling for ELF in general as not all platform support it
 (e.g. NetBSD, implictly stack never executable).
2021-03-05 14:33:52 +13:00
David Carlier c230ccdba6 coroutine arm64 generating note.GNU-stack section for linux. 2021-03-05 14:26:00 +13:00
Yusuke Endoh 62283f7a7a coroutine/emscripten/: Experimentally support emscripten fiber API 2021-01-23 18:56:06 +09:00
Nobuyoshi Nakada 07b4b1b1cb
Support coroutine on universal binary 2021-01-22 23:41:52 +09:00
Nobuyoshi Nakada f1c36f2e6b
Added include guards to coroutine headers 2021-01-22 23:21:25 +09:00
Samuel Williams 09229c71bc Fix "Ruby is not properly fortified on armv7hl".
See <https://bugs.ruby-lang.org/issues/16762> for more details.
2020-12-08 23:37:42 +13:00
Nobuyoshi Nakada d2b7e1e4b2
Protoized old pre-ANSI K&R style definitions 2020-12-05 14:57:31 +09:00
Samuel Williams 3b5b309b7b Proposed method for dealing with stack locals which have non-local lifetime. 2020-12-05 11:38:56 +13:00
Samuel Williams 15e23312f6 Rework the order of operations to avoid stack smashing. 2020-12-05 11:38:56 +13:00
Nobuyoshi Nakada 41168f69fb
Prefix export symbol prefix to coroutine_transfer 2020-07-05 17:27:12 +09:00
Nobuyoshi Nakada 04c704c5c9
Removed trailing spaces [ci skip] 2020-07-05 17:12:20 +09:00
Paul Jordan 0091fac1d8 Patch assembly so that it aligns properly 2020-04-01 15:49:02 +13:00
卜部昌平 ce4ea956d2 function pointers are not void*
The same as 8427fca49b.
2020-02-06 11:46:51 +09:00
Samuel Williams bf04fe086b
Remove "All Rights Reserved." from Copyright statement. 2019-12-28 12:45:37 +13:00
Samuel Williams f96216df8d
Remove "All Rights Reserved." from Copyright statement. 2019-12-28 12:41:47 +13:00
Jeremy Evans f05416c91f Fix coroutine copy implementation on OpenBSD
OpenBSD is the only platform that uses this support by default,
and it did not work because while OpenBSD supports alloca, it does
not include alloca.h.

This should be backported to Ruby 2.7.

From George Koehler
2019-12-27 15:01:01 -08:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Yusuke Endoh f4d9daf2b6 coroutine/ucontext/Context.c: define __EXTENSIONS__ explicitly
instead of ruby/config.h, per samuel's request.

dbfd4b780e (diff-7fd78c3cc8a19b7e0637502983ec26ff)
2019-12-05 22:24:58 +09:00
Yusuke Endoh dbfd4b780e coroutine/ucontext/Context.c: Include "ruby/config.h" for Solaris
getcontext, makecontext, and swapcontext seem to be available only when
`__EXTENSION__` is defined on Solaris.
2019-12-04 20:59:39 +09:00
Lars Kanis 853d91a04a Fix coroutine support on win32
Ruby master branch currently fails on win32 MINGW at this spec:
https://github.com/ruby/spec/blob/master/core/thread/element_set_spec.rb

MINGW makes use of setjmp3() implemented in MSVCRT.DLL.
This function traverses the SEH list up to a terminating pointer 0xFFFFFFFF.
It therefore currently segfaults on NULL.
The SEH linked list must be terminated by 0xFFFFFFFF instead of NULL.

This fixes the issue mentioned here:
  https://github.com/ruby/ruby/pull/2279#issuecomment-509508810
2019-11-05 15:31:21 +09:00
Samuel Williams e14f5762c5
Add assertions to `coroutine_initialize_main`. 2019-07-19 15:55:34 +12:00
Samuel Williams dd0e33f083
Split assertions to check which one fails. 2019-07-19 15:53:47 +12:00