~clint-fewbar/ubuntu/precise/erlang/merge-15b

« back to all changes in this revision

Viewing changes to erts/emulator/beam/beam_load.c

  • Committer: Elliot Murphy
  • Date: 2009-12-22 02:56:21 UTC
  • mfrom: (3.3.5 sid)
  • Revision ID: elliot@elliotmurphy.com-20091222025621-qv3rja8gbpiabkbe
Tags: 1:13.b.3-dfsg-2ubuntu1
* Merge with Debian testing; remaining Ubuntu changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to. (LP #438365)
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
* Fixed dialyzer(1) manpage which was placed into section 3 and conflicted
  with dialyzer(3erl).
* New upstream release (it adds a new binary package erlang-erl-docgen).
* Refreshed patches, removed most of emacs.patch which is applied upstream.
* Linked run_test binary from erlang-common-test package to /usr/bin.
* Fixed VCS headers in debian/control.
* Moved from prebuilt manpages to generated from sources. This adds
  erlang-manpages binary package and xsltproc build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
283
283
    Uint catches;               /* Linked list of catch_yf instructions. */
284
284
    unsigned loaded_size;       /* Final size of code when loaded. */
285
285
    byte mod_md5[16];           /* MD5 for module code. */
 
286
    int may_load_nif;           /* true if NIFs may later be loaded for this module */  
 
287
    int on_load;                /* Index in the code for the on_load function
 
288
                                 * (or 0 if there is no on_load function)
 
289
                                 */
286
290
 
287
291
    /*
288
292
     * Atom table.
700
704
    state.code = NULL;          /* Prevent code from being freed. */
701
705
    *modp = state.module;
702
706
 
 
707
    /*
 
708
     * If there is an on_load function, signal an error to
 
709
     * indicate that the on_load function must be run.
 
710
     */
 
711
    if (state.on_load) {
 
712
        rval = -5;
 
713
    }
 
714
 
703
715
 load_error:
704
716
    if (state.code != 0) {
705
717
        erts_free(ERTS_ALC_T_CODE, state.code);
773
785
    stp->literal_patches = 0;
774
786
    stp->string_patches = 0;
775
787
    stp->new_float_instructions = 0;
 
788
    stp->may_load_nif = 0;
 
789
    stp->on_load = 0;
776
790
}
777
791
 
778
792
static int
1071
1085
        if ((e = erts_find_export_entry(mod, func, arity)) != NULL) {
1072
1086
            if (e->code[3] == (Uint) em_apply_bif) {
1073
1087
                stp->import[i].bf = (BifFunction) e->code[4];
 
1088
                if (func == am_load_nif && mod == am_erlang && arity == 2) {
 
1089
                    stp->may_load_nif = 1;
 
1090
                }
1074
1091
            }
1075
1092
        }
1076
1093
    }
1366
1383
    int i;
1367
1384
    int tmp;
1368
1385
    int ci;
 
1386
    int last_func_start = 0;
1369
1387
    char* sign;
1370
1388
    int arg;                    /* Number of current argument. */
1371
1389
    int num_specific;           /* Number of specific ops for current. */
2005
2023
        case op_i_func_info_IaaI:
2006
2024
            {
2007
2025
                Uint offset;
 
2026
                enum { FINFO_SZ = 5 };
2008
2027
 
2009
2028
                if (function_number >= stp->num_functions) {
2010
2029
                    LoadError1(stp, "too many functions in module (header said %d)",
2011
2030
                               stp->num_functions); 
2012
2031
                }
2013
2032
 
 
2033
                if (stp->may_load_nif) {
 
2034
                    const int finfo_ix = ci - FINFO_SZ;             
 
2035
                    enum { MIN_FUNC_SZ = 3 };               
 
2036
                    if (finfo_ix - last_func_start < MIN_FUNC_SZ && last_func_start) {             
 
2037
                        /* Must make room for call_nif op */
 
2038
                        int pad = MIN_FUNC_SZ - (finfo_ix - last_func_start);
 
2039
                        ASSERT(pad > 0 && pad < MIN_FUNC_SZ);
 
2040
                        Need(pad);
 
2041
                        sys_memmove(&code[finfo_ix+pad], &code[finfo_ix], FINFO_SZ*sizeof(Eterm));
 
2042
                        sys_memset(&code[finfo_ix], 0, pad*sizeof(Eterm));
 
2043
                        ci += pad;
 
2044
                        stp->labels[last_label].value += pad;
 
2045
                    }
 
2046
                }
 
2047
                last_func_start = ci;
2014
2048
                /*
2015
2049
                 * Save context for error messages.
2016
2050
                 */
2017
2051
                stp->function = code[ci-2];
2018
2052
                stp->arity = code[ci-1];
 
2053
                ASSERT(stp->labels[last_label].value == ci - FINFO_SZ);
2019
2054
                offset = MI_FUNCTIONS + function_number;
2020
2055
                code[offset] = stp->labels[last_label].patches;
2021
2056
                stp->labels[last_label].patches = offset;
2031
2066
#endif
2032
2067
            }
2033
2068
            break;
 
2069
        case op_on_load:
 
2070
            ci--;               /* Get rid of the instruction */
 
2071
 
 
2072
            /* Remember offset for the on_load function. */
 
2073
            stp->on_load = ci;
 
2074
            break;
2034
2075
        case op_put_string_IId:
2035
2076
            {
2036
2077
                /*
3376
3417
 
3377
3418
    code[MI_FUNCTIONS+stp->num_functions] = (Eterm) (code + stp->ci - 1);
3378
3419
 
 
3420
    /*
 
3421
     * Store the pointer to the on_load function.
 
3422
     */
 
3423
 
 
3424
    if (stp->on_load) {
 
3425
        code[MI_ON_LOAD_FUNCTION_PTR] = (Eterm) (code + stp->on_load);
 
3426
    } else {
 
3427
        code[MI_ON_LOAD_FUNCTION_PTR] = 0;
 
3428
    }
3379
3429
 
3380
3430
    /*
3381
3431
     * Place the literal heap directly after the code and fix up all
3571
3621
final_touch(LoaderState* stp)
3572
3622
{
3573
3623
    int i;
 
3624
    int on_load = stp->on_load;
3574
3625
 
3575
3626
    /*
3576
3627
     * Export functions.
3579
3630
    for (i = 0; i < stp->num_exps; i++) {
3580
3631
        Export* ep = erts_export_put(stp->module, stp->export[i].function,
3581
3632
                                     stp->export[i].arity);
3582
 
        ep->address = stp->export[i].address;
 
3633
        if (!on_load) {
 
3634
            ep->address = stp->export[i].address;
 
3635
        } else {
 
3636
            /*
 
3637
             * Don't make any of the exported functions
 
3638
             * callable yet.
 
3639
             */
 
3640
            ep->address = ep->code+3;
 
3641
            ep->code[4] = (Eterm) stp->export[i].address;
 
3642
        }
3583
3643
    }
3584
3644
 
3585
3645
    /*
4253
4313
    return stp->num_literals++;
4254
4314
}
4255
4315
 
4256
 
 
4257
4316
Eterm
4258
4317
erts_module_info_0(Process* p, Eterm module)
4259
4318
{