Skip to content

Disable date object related system calls by default. #929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

LaszloLango
Copy link
Contributor

gettimeofday system call cause problems on multiple platforms, so better to disable by default.

Related issue: #923

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com

@LaszloLango LaszloLango added bug Undesired behaviour critical Raises security concerns ecma builtins Related to ECMA built-in routines labels Mar 2, 2016
@LaszloLango LaszloLango force-pushed the fix-date-regressions-on-arm branch from 25b2f28 to 27cce21 Compare March 2, 2016 16:48
@akosthekiss
Copy link
Member

Issue analysis:

In jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c, we rely on the second argument of gettimeofday(&tv, &tz) to determine the time zone. Unfortunately, Linux manuals state that "The use of the timezone structure is obsolete; the tz argument should normally be specified as NULL." Our bad luck is that qemu takes this seriously, and its gettimeofday syscall implementation simply avoids the second argument: it does not fill anything there, even if the pointer is non-NULL.

(Note: Real Linux kernels still provide valid tz info, that's why we haven't faced this problem until now. Moreover, our main target is a real device and not qemu emulation, of course. However, qemu is our only chance to get ARM tests work on Travis. So we should deal with the issue, IMHO.)

We could work around the trouble. At both places where we use the second argument, we use struct timezone tz;. If we would pre-initialize tz with zeros (= { 0, 0 };), then however we run jerry, we wouldn't find garbage in tz.tz_minuteswest and thus would be on the safe side.

Conclusions:

I wouldn't guard out date syscalls but would go with the initializations.

Notes:

  • Changing ecma_raise_type_error ("gettimeofday failed") to ecma_number_make_nan () seems an unrelated change to me. Why's that?
  • I'd definitely move struct timezone to sys/time.h since it's surely not the responsibility of ecma-builtin-helpers-date.c. (I haven't noticed its introduction in the last buildfix.)
  • The above is kinda hipothetical, it hasn't beed tried out on jerry but on an example test app only.

@LaszloLango
Copy link
Contributor Author

Changing ecma_raise_type_error ("gettimeofday failed") to ecma_number_make_nan () seems an unrelated change to me. Why's that?

The return value is ecma_number_t and ecma_raise_type_error returns ecma_value_t, so this is a bug and should be fixed.

@LaszloLango LaszloLango force-pushed the fix-date-regressions-on-arm branch 2 times, most recently from 0e5d255 to e05176a Compare March 3, 2016 14:19
@LaszloLango
Copy link
Contributor Author

@akiss77, updated the PR. There are still build issues with external compilers. (Ex.: https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2) So I still prefer to disable by default.

* Note:
* Experimental. Works on Ubuntu 14.04.
*/
// #define ECMA_ENABLE_DATE_SYS_CALLS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to enable the calls without editing config.h? If not, we wont be testing it "ever" -- neither with local precommit checks, nor on Travis. Which makes all gettimeofday-related code paths effectively dead. External tool chains are not the primary targets (strictly IMHO). If their users need tweaks, they shoud be the one to do edits to config.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looked like to me that is the common way. (see: CONFIG_VM_RUN_GC_AFTER_EACH_OPCODE) But I agree with you. A build option would be good.

@LaszloLango LaszloLango force-pushed the fix-date-regressions-on-arm branch from e05176a to 7ffaff6 Compare March 7, 2016 12:54
@LaszloLango
Copy link
Contributor Author

@akiss77, updated the patch. You can enable sys calls with DATE_SYS_CALLS=ON make... build option.

@akosthekiss
Copy link
Member

The guards still make me sad, but LGTM (FWIW).

@zherczeg
Copy link
Member

zherczeg commented Mar 8, 2016

LGTM

Use DATE_SYS_CALLS=ON for make target to enable the
date related system calls. Also fix some minor issues.
Related issue: jerryscript-project#923

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
@LaszloLango LaszloLango force-pushed the fix-date-regressions-on-arm branch from 7ffaff6 to 9bf1ecc Compare March 8, 2016 11:14
@LaszloLango LaszloLango merged commit 9bf1ecc into jerryscript-project:master Mar 8, 2016
@LaszloLango LaszloLango deleted the fix-date-regressions-on-arm branch April 1, 2016 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Undesired behaviour critical Raises security concerns ecma builtins Related to ECMA built-in routines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants