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

18 Коммитов

Автор SHA1 Сообщение Дата
Peter Zhu a84c99468f Fix crash in Time on 32-bit systems
[Bug #19575]

struct vtm is packed causing it to have a size that is not aligned on
32-bit systems. When allocating it on the stack, it will have unaligned
addresses which means that the fields won't be marked by the GC when
scanning the stack (since the GC only marks aligned addresses). This can
cause crashes when the fields are heap allocated objects like Bignums.

This commit moves the flags in struct time_object into struct vtm for
space efficiency and removes the need for packing.

This is an example of a crash:

    ruby(rb_print_backtrace+0xd) [0x56848945] ../src/vm_dump.c:785
    ruby(rb_vm_bugreport) ../src/vm_dump.c:1101
    ruby(rb_assert_failure+0x7a) [0x56671857] ../src/error.c:878
    ruby(vm_search_cc+0x0) [0x56666e47] ../src/vm_method.c:1366
    ruby(rb_vm_search_method_slowpath) ../src/vm_insnhelper.c:2090
    ruby(callable_method_entry+0x5) [0x568232d3] ../src/vm_method.c:1406
    ruby(rb_callable_method_entry) ../src/vm_method.c:1413
    ruby(gccct_method_search_slowpath) ../src/vm_eval.c:427
    ruby(gccct_method_search+0x20f) [0x568237ef] ../src/vm_eval.c:476
    ruby(opt_equality_by_mid_slowpath+0x2c) [0x5682388c] ../src/vm_insnhelper.c:2338
    ruby(rb_equal+0x37) [0x566fe577] ../src/object.c:133
    ruby(rb_big_eq+0x34) [0x56876ee4] ../src/bignum.c:5554
    ruby(rb_int_equal+0x14) [0x566f3ed4] ../src/numeric.c:4640
    ruby(rb_int_equal) ../src/numeric.c:4634
    ruby(vm_call0_cfunc_with_frame+0x6d) [0x568303c2] ../src/vm_eval.c:148
    ruby(vm_call0_cfunc) ../src/vm_eval.c:162
    ruby(vm_call0_body) ../src/vm_eval.c:208
    ruby(rb_funcallv_scope+0xd1) [0x56833971] ../src/vm_eval.c:85
    ruby(RB_TEST+0x0) [0x567e8488] ../src/time.c:78
    ruby(eq) ../src/time.c:78
    ruby(small_vtm_sub) ../src/time.c:1523
    ruby(timelocalw+0x23b) [0x567f3e9b] ../src/time.c:1593
    ruby(time_s_alloc+0x0) [0x567f536b] ../src/time.c:3698
    ruby(time_new_timew) ../src/time.c:2694
    ruby(time_s_mktime) ../src/time.c:3698
2023-04-04 11:12:07 -04:00
Nobuyoshi Nakada a56d959ed5
Replace `PACKED_STRUCT` and `PACKED_STRUCT_UNALIGNED` 2023-02-08 12:35:27 +09: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
nobu c84bdda47a timev.h: dummy definition for TAGS
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 12:43:31 +00:00
kazu 25c1fd3b90 Reverting all commits from r67479 to r67496 because of CI failures
Because hard to specify commits related to r67479 only.
So please commit again.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 09:15:21 +00:00
nobu e86bf9a4d7 timev.h: dummy definition for TAGS
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67491 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 01:34:44 +00:00
nobu ee58c638b8 Timezone support by Time [Feature #14850]
* strftime.c (rb_strftime): support timezone object by `%z`.

* time.c (time_init_1, time_new_timew, time_getlocaltime): accept
  timezone object as `off`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-08 02:35:31 +00:00
svn 7ef91e62e2 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25 13:42:05 +00:00
nobu d7278b5b32 Moved `struct vtm` stuff from internal.h to timev.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25 13:42:02 +00:00
akr 277cedb84c Store String as zone in struct vtm.
This removes zone_table and use fstring instead.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-08 10:00:43 +00:00
normal 56524df980 timev.h: just use "unsigned int" for bitfields
There's no point in having separate types depending on C dialect
when using bitfields, "unsigned int" bitfields are bitfields
anywhere.

Note: we also have test_memsize in test_time.rb in case
users of other platforms want to enable size assertions
if they don't trust their compiler.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-16 06:36:05 +00:00
shyouhei db5d556f9b bit-fields other than int is a C99ism
To be precise C90 says "A bit-field may have type int, unsigned
int, or signed int". It is clear that char or enum are NG.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02 06:41:50 +00:00
nobu df9199d468 configure.in, win32/Makefile.sub: PACKED_STRUCT with VC
* configure.in (PACKED_STRUCT): check VC pragma too, and make
  function-style macro.

* win32/Makefile.sub (PACKED_STRUCT): enable with VC.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-25 07:00:10 +00:00
normal 131e4bec04 time: only use packed struct on x86*
* configure.in: define PACKED_STRUCT_UNALIGNED for x86*
* timev.h (struct vtm): use PACKED_STRUCT_UNALIGNED
* time.c (struct time_object): ditto
  [Bug #9558] non-x86 cannot safely access unaligned addresses

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-24 11:10:11 +00:00
normal b2f3063cae time: rearrange+pack vtm and time_object structs
struct time_object shrinks from 88 to 46 bytes on my 64-bit system.

* configure.in: use -Wno-packed-bitfield-compat for GCC 4.4+
  use __attribute__((packed)) if available
* timev.h: shrink and pack struct vtm
* time.c: pack struct time_object and adjust/introduce helpers
  [ruby-core:60794]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-24 03:38:14 +00:00
nobu 77ff241fa0 timev.h: move time_t stuffs
* timev.h (TYPEOF_TIMEVAL_TV_SEC, unsigned_time_t): move from time.c.

* thread.c: use definitions in timev.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-30 21:08:36 +00:00
akr 8b32a1de29 * timev.h (TIME_SCALE): defined as 1000000000.
(struct vtm): subsec is replaced by subsecx.
  subsec * TIME_SCALE == subsecx.

* time.c: avoid rational in most cases.
  (struct time_object): timev is replaced by timexv.
  timev * TIME_SCALE == timexv.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-08-29 19:06:29 +00:00
akr 3bc16f62c1 * time.c: remove time_t restriction from Time class.
* timev.h: new file to define struct vtm.

* strftime.c: format struct vtm instead of struct tm.

* ext/syck/rubyext.c (mktime_do): don't use time_t;

[ruby-dev:38191]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-04-21 14:56:59 +00:00