summaryrefslogtreecommitdiffhomepage
path: root/src/load.c
AgeCommit message (Collapse)Author
2020-06-05Change arena index from `mrb_int` to `int`.Yukihiro "Matz" Matsumoto
2020-06-05Squashed commit of the following:Yukihiro "Matz" Matsumoto
commit 2d7d545c4c4bfce7fdcbcbe9baaeb437915742f0 Merge: 625a1249 b178914b Author: Yukihiro "Matz" Matsumoto <[email protected]> Date: Fri Jun 5 14:35:13 2020 +0900 Merge branch 'fix-mrb_open-with-nomem' of https://github.com/dearblue/mruby into dearblue-fix-mrb_open-with-nomem commit b178914b111dda79a8f36ec4eb3e9d37b76f982e Author: dearblue <[email protected]> Date: Sat Jan 19 22:22:44 2019 +0900 Fix invalid pointer free inside other heap's block 1. `e = mrb_obj_alloc(...)` 2. `e->stack = mrb->c->stack` (`mrb->c->stack` is anywhere in the range `stbase...stend`) 3. And raised exception by `mrb_malloc()`! 4. `mrb_free(e->stack)` by GC part (wrong free) commit 52e3d5d8585daf86af3ed12db5ab0efefbc9b956 Author: dearblue <[email protected]> Date: Sat Jan 19 21:55:36 2019 +0900 Fix memory leak for temporary symbols when out of memory commit 4c5499b88e47cc6012ad7d7379cb6bc74c6a0b60 Author: dearblue <[email protected]> Date: Sun Jan 20 11:42:07 2019 +0900 Fix uninitialized pointer dereference for debug section commit 8e993167dec62a9709d6faacd517729ddcedf4f9 Author: dearblue <[email protected]> Date: Sun Jan 20 11:41:09 2019 +0900 Fix memory leak for temporary filenames when out of memory commit 8b422577e6eae68a28121b88421d937e8707b487 Author: dearblue <[email protected]> Date: Sun Jan 20 10:57:51 2019 +0900 Fix memory leak for irep when out of memory commit 6b35ebf49a0aa3edb6bbda770ed58681e9c2e6af Author: dearblue <[email protected]> Date: Sun Jan 20 10:55:50 2019 +0900 Fix uninitialized pointer dereference when do not finished initializing irep commit 2531f2631e67e0462749618e2344c733a29238f0 Author: dearblue <[email protected]> Date: Sun Jan 20 10:48:15 2019 +0900 Fix NULL pointer dereference when do not finished initializing irep commit e2d6896ebad13694800af49c2625e106b8440ddf Author: dearblue <[email protected]> Date: Sat Jan 19 12:54:19 2019 +0900 Fix memory leak for irep when out of memory by `mrb_proc_new()` commit b6214ff8a0a1c73bc9554e39053878ac50bb683f Author: dearblue <[email protected]> Date: Sat Jan 19 12:53:07 2019 +0900 Fix memory leak for `khash_t` in `kh_init_size()` when out of memory by `kh_alloc()` commit 19162dd6c11f0093d0011e7cab83b8f9e84c2c07 Author: dearblue <[email protected]> Date: Sun Jan 20 02:15:07 2019 +0900 Fix memory leak for symbol string when out of memory in `kh_put()` commit 15e67297ff54bc14ef359d6d1e745d760a4a255a Author: dearblue <[email protected]> Date: Sun Jan 20 02:12:24 2019 +0900 Fix keep wrong symbol index when out of memory commit 3f8e2b375244f5441e8d62efa13c6e6a9afecb14 Author: dearblue <[email protected]> Date: Sun Jan 20 02:08:13 2019 +0900 Fix keep wrong symbol capacity when out of memory commit a3cfe755ab3e758046c3f4e30938ac8d567ed046 Author: dearblue <[email protected]> Date: Sat Jan 19 10:11:37 2019 +0900 Fix NULL pointer dereference `mrb->c` by `mark_context()` commit d9c7b6be6eb54630b64eea5c35be241e551676e5 Author: dearblue <[email protected]> Date: Sun Jan 20 15:25:09 2019 +0900 Fix protect exception for print error message commit 100642750e4d549f2e8050f8d6cabdf8825d4495 Author: dearblue <[email protected]> Date: Sun Jan 20 11:59:02 2019 +0900 Protect exception for mruby core initialization commit 7a0418304ec70764fa215bef3599f5f735222075 Author: dearblue <[email protected]> Date: Fri Jan 18 20:38:27 2019 +0900 Fix memory leak for string object when out of memory The `mrb_str_pool()` function has a path to call `malloc()` twice. If occurs `NoMemoryError` exception in second `malloc()`, first `malloc()` pointer is not freed. commit fef1c152ce4e52b9e4a34dc23aca5b02907ac639 Author: dearblue <[email protected]> Date: Sat Jan 19 13:05:09 2019 +0900 Fix stack overflow when out of memory As a result of this change, no backtrace information is set for NoMemoryError (`mrb->nomem_err`). Detailes: When generating a backtrace, called `mrb_intern_lit()`, `mrb_str_new_cstr()` and `mrb_obj_iv_set()` function with `exc_debug_info()` function in `src/error.c`. If a `NoMemoryError` exception occurs at this time, the `exc_debug_info()` function will be called again, and in the same way `NoMemoryError` exception raised will result in an infinite loop to occurs stack overflow (and SIGSEGV). commit da7d7f881bbbad9988a3a2b7bad8f2b72ff06bc6 Author: dearblue <[email protected]> Date: Sun Jan 20 12:00:38 2019 +0900 Fix NULL pointer dereference `mrb->nomem_err` when not initialized Add internal functions (not `static`): * `mrb_raise_nomemory()` * `mrb_core_init_abort()`
2020-05-07Remove endian information/flags from compiled binary format.Yukihiro "Matz" Matsumoto
Since `mruby 2.0`, compiled bytecode no longer depends on the endian of the machine.
2020-01-06Refactor `mrb_cstr_to_dbl`; ref #4920Yukihiro "Matz" Matsumoto
2020-01-06Avoid creating temporary objects in `read_irep_record_1`; close #4920Yukihiro "Matz" Matsumoto
The basic idea of this change is from @dearblue. Note: the arguments of `mrb_str_pool()` have changed, but the function is provided for internal use (No `MRB_API`). So basically you don't have to worry about the change.
2019-09-21Rename MRB_USE_ETEXT_EDATA to MRB_USE_LINK_TIME_RO_DATA_P and support lld ↵Fangrui Song
linked programs In lld linked programs, .rodata comes before .text, thus mrb_ro_data_p will return false for strings in .rodata. Change the lower bound from _etext to __ehdr_start to catch these cases. This works for ld.bfd, gold and lld, and it does not have false positives even if .init_array does not exist. Remove the branch that uses _edata: strings in .data can be modified so this is semantically incorrect. Delete the __APPLE__ branch (its manpages say get_etext() and get_edata() are strongly discouraged). .init_array has been adopted by most ELF platforms to supersede .ctors. Neither _etext nor _edata is used, so rename MRB_USE_ETEXT_EDATA to MRB_USE_EHDR_START.
2019-08-18Prohibit changes to iseq in principledearblue
2019-05-22Merge pull request #4403 from dearblue/read-irep-from-bufYukihiro "Matz" Matsumoto
Read irep from buffers
2019-05-19Remove "LINE" section readerdearblue
Because it is not currently output by `mrbc`.
2019-05-03Fix `FLAG_SRC_STATIC` always set in `mrb_read_irep()` with ↵dearblue
`MRB_USE_CUSTOM_RO_DATA_P`
2019-04-24Add mruby binary loader functions from buffer memorydearblue
Add new functions (with `MRB_API`): - `mrb_read_irep_buf()` - `mrb_load_irep_buf()` - `mrb_load_irep_buf_cxt()`
2019-04-24Check mruby binary sizedearblue
2019-04-24Check mruby binary versiondearblue
2019-04-01Avoid keeping pointers from `mrb_sym2name_len()`; fix #4342Yukihiro "Matz" Matsumoto
The addresses for packed inline symbols reference `mrb->symbuf` that could be overridden by the later call of `mrb_sym2name_len`. Since file names in call stack information are kept as symbols, keeping the address in the C structures could cause problems like #4342. This changes small incompatible changes in function prototypes: * `mrb_parser_get_filename`: return value changed to `mrb_sym`. * `mrb_debug_get_filename`: add `mrb_state*` as a first argument. * `mrb_debug_get_line`: ditto. I believe above functions are almost internal, and no third-party mrbgem use them.
2019-01-08Fix dump/load float leteral evaluate to infinityKOBAYASHI Shuji
Example: # example.rb p(2e308) p(-2e308) Good: $ bin/mruby example.rb inf -inf Bad: $ bin/mrbc example.rb $ bin/mruby -b example.mrb 0 -0 Cause: Float infinity representation is `inf` on dump and it is converted by corresponding `String#to_f` on load. Treatment: - Introduce new representations (`i`: +infinity, `I`: -infinity) - Allow old representations (`inf`, `-inf`, `infinity`, `-infinity`) too - Raise error for unknown representations (use corresponding `Kernel#Float`)
2018-11-15Remove `filename`&`lines` from `mrb_irep` struct.Yukihiro "Matz" Matsumoto
This patch slightly reduce memory consumption (2% for my test).
2018-11-02Fix dump and load with endianesstake-cheeze
2018-08-25Reduce integer casting warnings.Yukihiro "Matz" Matsumoto
2018-07-30New bytecode implementation of mruby VM.Yukihiro "Matz" Matsumoto
2018-04-28Fix broken support of `MRB_WITHOUT_FLOAT`; fix #4015Yukihiro "Matz" Matsumoto
2018-04-17Fallback to float when caompiled binary with 64bit compiler.Takeshi Watanabe
closes #3997.
2017-10-11Add MRB_WITHOUT_FLOATYAMAMOTO Masaya
2017-08-29Exclude the top-level closure from `each_object`; fix #3793Yukihiro "Matz" Matsumoto
2017-08-12Reduce integer type mismatch warnings in VC.Yukihiro "Matz" Matsumoto
2016-09-28Removed trailing spacesNobuyoshi Nakada
2016-09-25Remove needless MRB_APIKouhei Sutou
ref #3215 If a function (such as mrb_read_irep_file()) is declared without MRB_API in header file (such as include/mruby/dump.h), implementation of the function in source file (such as src/load.c) should also defined without MRB_API. If MRB_API is mismatch, Visual C++ reports link error with C2375 error code: https://msdn.microsoft.com/en-us/library/5k6kw95a.aspx
2016-09-24Remove unnecessary MRB_API from read_irep related functions; ref #3215Yukihiro "Matz" Matsumoto
2016-01-07replace mrb_toplevel_run() by mrb_top_run()Yukihiro "Matz" Matsumoto
2015-12-29Support backtrace after method callsKouhei Sutou
GitHub: fix #2902, #2917 The current implementation traverses stack to retrieve backtrace. But stack will be changed when some operations are occurred. It means that backtrace may be broken after some operations. This change (1) saves the minimum information to retrieve backtrace when exception is raised and (2) restores backtrace from the minimum information when backtrace is needed. It reduces overhead for creating backtrace Ruby objects. The space for the minimum information is reused by multiple exceptions. So memory allocation isn't occurred for each exception.
2015-11-27include changed from by quotes ("") to by brackets (<>); close #3032Yukihiro "Matz" Matsumoto
2015-11-17DISABLE_STDIO/ENABLE_DEBUG macros to rename; close #3014Yukihiro "Matz" Matsumoto
changes: * rename DISABLE_STDIO -> MRB_DISABLE_STDIO * rename ENABLE_DEBUG -> MRB_ENABLE_DEBUG_HOOK * no more opposite macro definitions (e.g. ENABLE_STDIO, DISABLE_DEBUG). * rewrite above macro references throughout the code. * update documents
2015-09-03remove trailing spaces from bc9c47d5Yukihiro "Matz" Matsumoto
2015-04-30Merge pull request #2778 from cremno/fix-load-size-error-macrosYukihiro "Matz" Matsumoto
src/load.c: fix size error macros
2015-04-29always define SIZE_ERROR_MUL() macrocremno
Previously there wasn't a way to trigger the useful definition, but it is needed and that in every case to check for integer overflow due to multiplication and faulty/modified binary files. Also change existing code to a calloc()-like parameter order.
2015-04-29remove SIZE_ERROR() macrocremno
It's only used once and in that case it isn't necessary anyway, since size_t must be at least 32 bits wide and the max. length of a filename is UINT16_MAX.
2015-04-29add more descriptive error message and fail earliercremno
2015-04-28fix possible unsigned integer underflowcremno
buf_size has to be greater than header_size, otherwise subtracting header_size from buf_size will cause an integer underflow. Being equal to header_size is fine, however useless, so quit early.
2015-04-28unify error handlingcremno
Convert mrb_read_irep_file() to use goto like read_section_lv() and read_section_debug() already do.
2015-02-02allow endian specification of mrb files by `mrbc -e/-E`Yukihiro "Matz" Matsumoto
`mruby -b` now accepts both big/little endian mrb (compiled binary) files. `mrbc` generates mrb files in big endian for .mrb files and in native endian for C files (with -B option specified) by default. If you are cross compiling, you need to specify target endian by -e/-E options if it is different from host endian.
2014-11-25remove unnecessary _WIN32 preprocessor checkcremno
SIZE_MAX < UINT32_MAX is false on Win32 / Win64.
2014-11-04avoid using rewind(3) to load mrb filesYukihiro "Matz" Matsumoto
2014-11-04read whole mrb file at once to calculate correct padding offset; ref #2630Yukihiro "Matz" Matsumoto
2014-11-04Fix misaligned access when reading irep; close #2630Yukihiro "Matz" Matsumoto
Add padding bytes before iseq block that may be used as mrb_code[]. Note that dumped mrb format has changed. Based on a patch from kimu_shu <[email protected]>
2014-10-01load.c to use mrb_ro_data_p()Yukihiro "Matz" Matsumoto
2014-09-05support native byteorder in mrb files; ref 3492beYukihiro "Matz" Matsumoto
2014-09-05condition refactoring in load.cYukihiro "Matz" Matsumoto
2014-09-04fix strict aliasing rule violationcremno
2014-09-04wrong iseq conversion flagYukihiro "Matz" Matsumoto
2014-09-04avoid iseq allocation from static irep binary. it reduces 424KB allocation ↵Yukihiro "Matz" Matsumoto
for mrbtest
2014-08-19Fix error hanldlings in read_irep_record().Tatsuhiko Kubo
read_irep_record_1() and read_irep_record() may return NULL.