Skip to content

Commit

Permalink
Always define CLOCK_BOOTTIME, CLOCK_BOOTTIME_ALARM and CLOCK_REALTIME…
Browse files Browse the repository at this point in the history
…_ALARM

* Giving a non-existing clock to clock_gettime() raises Errno::EINVAL,
  which seems fairly harmless.
* Fixes oracle#1480
  • Loading branch information
eregon authored and Strech committed May 23, 2022
1 parent 995a7bd commit 1349708
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Compatibility:
* `Process.euid=` should accept String (#2615, @ngtban).
* Fix `instance_variable_get` and `instance_variable_set` for immutable objects (@bjfish).
* `Thread#raise(exc, message)` now calls `exc.exception` in the target thread like CRuby (@eregon).
* Define `Process::{CLOCK_BOOTTIME,CLOCK_BOOTTIME_ALARM,CLOCK_REALTIME_ALARM}` (#1480, @eregon).

Performance:

Expand Down
2 changes: 0 additions & 2 deletions spec/tags/core/process/clock_gettime_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@ public static void load(NativeConfiguration configuration, RubyContext context)
configuration.config("platform.clocks.CLOCK_REALTIME", 0);
configuration.config("platform.clocks.CLOCK_REALTIME_COARSE", 5);
configuration.config("platform.clocks.CLOCK_THREAD_CPUTIME_ID", 3);
configuration.config("platform.clocks.CLOCK_BOOTTIME", 7);
configuration.config("platform.clocks.CLOCK_REALTIME_ALARM", 8);
configuration.config("platform.clocks.CLOCK_BOOTTIME_ALARM", 9);
configuration.config("platform.typedef.int8_t", string(context, "char"));
configuration.config("platform.typedef.int16_t", string(context, "short"));
configuration.config("platform.typedef.int32_t", string(context, "int"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,16 +760,16 @@ public static void load(NativeConfiguration configuration, RubyContext context)
configuration.config("platform.dlopen.RTLD_GLOBAL", 256);
configuration.config("platform.dlopen.RTLD_NEXT", -1);
configuration.config("platform.dlopen.RTLD_DEFAULT", 0);
configuration.config("platform.clocks.CLOCK_BOOTTIME", 7);
configuration.config("platform.clocks.CLOCK_BOOTTIME_ALARM", 9);
configuration.config("platform.clocks.CLOCK_MONOTONIC", 1);
configuration.config("platform.clocks.CLOCK_MONOTONIC_COARSE", 6);
configuration.config("platform.clocks.CLOCK_MONOTONIC_RAW", 4);
configuration.config("platform.clocks.CLOCK_PROCESS_CPUTIME_ID", 2);
configuration.config("platform.clocks.CLOCK_REALTIME", 0);
configuration.config("platform.clocks.CLOCK_REALTIME_ALARM", 8);
configuration.config("platform.clocks.CLOCK_REALTIME_COARSE", 5);
configuration.config("platform.clocks.CLOCK_THREAD_CPUTIME_ID", 3);
configuration.config("platform.clocks.CLOCK_BOOTTIME", 7);
configuration.config("platform.clocks.CLOCK_REALTIME_ALARM", 8);
configuration.config("platform.clocks.CLOCK_BOOTTIME_ALARM", 9);
configuration.config("platform.typedef.int8_t", string(context, "char"));
configuration.config("platform.typedef.int16_t", string(context, "short"));
configuration.config("platform.typedef.int32_t", string(context, "int"));
Expand Down
19 changes: 14 additions & 5 deletions tool/generate-native-config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,13 @@ def initialize(group)
@constants = {}
end

def const(name, default_value = nil, format = '%ld', cast = '(long)')
@constants[name] = Constant.new(name, format, cast, default_value)
end

def consts(names, format = '%ld', cast = '(long)')
names.each do |name|
@constants[name] = Constant.new(name, format, cast, nil)
const(name, nil, format, cast)
end
end

Expand Down Expand Up @@ -774,8 +778,6 @@ def constants(name)
constants 'clocks' do |cg|
cg.include 'time.h'
cg.consts %w[
CLOCK_BOOTTIME
CLOCK_BOOTTIME_ALARM
CLOCK_MONOTONIC
CLOCK_MONOTONIC_COARSE
CLOCK_MONOTONIC_FAST
Expand All @@ -785,7 +787,6 @@ def constants(name)
CLOCK_PROCESS_CPUTIME_ID
CLOCK_PROF
CLOCK_REALTIME
CLOCK_REALTIME_ALARM
CLOCK_REALTIME_COARSE
CLOCK_REALTIME_FAST
CLOCK_REALTIME_PRECISE
Expand All @@ -797,7 +798,15 @@ def constants(name)
CLOCK_UPTIME_RAW
CLOCK_UPTIME_RAW_APPROX
CLOCK_VIRTUAL
]
]

# Give the following clock ids a default so they works on newer Linux built by older Linux:
# https://github.com/oracle/truffleruby/issues/1480
cg.const 'CLOCK_BOOTTIME', (7 if RUBY_PLATFORM =~ /linux/)
# These 2 are not supported on linux-aarch64:
# https://patchwork.kernel.org/project/linux-arm-kernel/patch/20171031183306.81375-1-salyzyn@android.com/#21274245
cg.const 'CLOCK_REALTIME_ALARM', (8 if RUBY_PLATFORM =~ /x86_64-linux/)
cg.const 'CLOCK_BOOTTIME_ALARM', (9 if RUBY_PLATFORM =~ /x86_64-linux/)
end

TypesGenerator.new.generate

0 comments on commit 1349708

Please sign in to comment.