~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (1.1.13 upstream)
  • mto: (3.3.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: james.westby@ubuntu.com-20090215164252-dxpjjuq108nz4noa
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3280
3280
}
3281
3281
 
3282
3282
 
3283
 
static GenOp*
3284
 
gen_func_info_mi(LoaderState* stp, GenOpArg mod,
3285
 
                 GenOpArg arity, GenOpArg label)
3286
 
{
3287
 
    GenOp* fi;
3288
 
    GenOp* op;
3289
 
 
3290
 
    NEW_GENOP(stp, fi);
3291
 
    fi->op = genop_i_func_info_4;
3292
 
    fi->arity = 4;
3293
 
    fi->a[0].type = TAG_u;      /* untagged Zero */
3294
 
    fi->a[0].val = 0;
3295
 
    fi->a[1] = mod;
3296
 
    fi->a[2].type = TAG_a;
3297
 
    fi->a[2].val = am_module_info;
3298
 
    fi->a[3] = arity;
3299
 
 
3300
 
    NEW_GENOP(stp, op);
3301
 
    op->op = genop_label_1;
3302
 
    op->arity = 1;
3303
 
    op->a[0] = label;
3304
 
    
3305
 
    fi->next = op;
3306
 
    op->next = NULL;
3307
 
 
3308
 
    NEW_GENOP(stp, op->next);
3309
 
    op = op->next;
3310
 
    op->op = arity.val == 0 ? genop_i_module_info_0_0 :
3311
 
        genop_i_module_info_1_0;
3312
 
    op->arity = 1;
3313
 
    op->a[0] = mod;
3314
 
    op->next = NULL;
3315
 
    return fi;
3316
 
}
3317
 
 
3318
 
 
3319
3283
 
3320
3284
static GenOp*
3321
3285
gen_make_fun2(LoaderState* stp, GenOpArg idx)
3976
3940
            instr->a[ap].type = i;
3977
3941
            instr->a[ap].val = 0;
3978
3942
            break;
 
3943
        case TOP_store_val:
 
3944
            i = *pc++;
 
3945
            instr->a[ap].val = i;
 
3946
            break;
3979
3947
        case TOP_store_var:
3980
3948
            i = *pc++;
3981
3949
            ASSERT(i < TE_MAX_VARS);
4981
4949
    int code_size;
4982
4950
    int rval;
4983
4951
    int i;
 
4952
    ErlDrvBinary* bin = NULL;
4984
4953
    byte* temp_alloc = NULL;
4985
4954
    byte* bytes;
 
4955
    Uint size;
4986
4956
 
4987
4957
    /*
4988
4958
     * Must initialize state.lambdas here because the error handling code
5006
4976
    if ((n = list_length(Funcs)) < 0) {
5007
4977
        goto error;
5008
4978
    }
 
4979
#ifdef HIPE     /* XXX: temporary fix for R12B-5, will go away before R13 */
5009
4980
    n += 2;                     /* module_info/0 and module_info/1 */
 
4981
#endif
5010
4982
    if ((bytes = erts_get_aligned_binary_bytes(Beam, &temp_alloc)) == NULL) {
5011
4983
        goto error;
5012
4984
    }
 
4985
    size = binary_size(Beam);
5013
4986
 
5014
4987
    /*
 
4988
     * Uncompressed if needed.
 
4989
     */
 
4990
    if (!(size >= 4 && bytes[0] == 'F' && bytes[1] == 'O' &&
 
4991
          bytes[2] == 'R' && bytes[3] == '1')) {
 
4992
        bin = (ErlDrvBinary *) erts_gzinflate_buffer((char*)bytes, size);
 
4993
        if (bin == NULL) {
 
4994
            goto error;
 
4995
        }
 
4996
        bytes = (byte*)bin->orig_bytes;
 
4997
        size = bin->orig_size;
 
4998
    }
 
4999
    
 
5000
    /*
5015
5001
     * Scan the Beam binary and read the interesting sections.
5016
5002
     */
5017
5003
 
5018
5004
    state.file_name = "IFF header for Beam file";
5019
5005
    state.file_p = bytes;
5020
 
    state.file_left = binary_size(Beam);
 
5006
    state.file_left = size;
5021
5007
    state.module = Mod;
5022
5008
    state.group_leader = p->group_leader;
5023
5009
    state.num_functions = n;
5125
5111
        fp = make_stub(fp, Mod, func, arity, (Uint)native_address, op);
5126
5112
    }
5127
5113
 
 
5114
#ifdef HIPE     /* XXX: temporary fix for R12B-5, will go away before R13 */
5128
5115
    /*
5129
5116
     * Add the module_info/0,1 functions.
5130
5117
     */
5131
5118
 
5132
5119
    ptrs[i++] = (Eterm) fp;
5133
 
    fp = make_stub(fp, Mod, am_module_info, 0, 0, (Eterm) BeamOp(op_i_module_info_0));
 
5120
    fp = make_stub(fp, Mod, am_module_info, 0, 0, (Eterm) BeamOp(op_hipe_module_info_0));
5134
5121
    ptrs[i++] = (Eterm) fp;
5135
 
    fp = make_stub(fp, Mod, am_module_info, 1, 0, (Eterm) BeamOp(op_i_module_info_1));
 
5122
    fp = make_stub(fp, Mod, am_module_info, 1, 0, (Eterm) BeamOp(op_hipe_module_info_1));
 
5123
#endif
5136
5124
 
5137
5125
    /*
5138
5126
     * Insert the last pointer and the int_code_end instruction.
5182
5170
        if (state.lambdas != state.def_lambdas) {
5183
5171
            erts_free(ERTS_ALC_T_LOADER_TMP, (void *) state.lambdas);
5184
5172
        }
 
5173
        if (bin != NULL) {
 
5174
            driver_free_binary(bin);
 
5175
        }
5185
5176
        return Mod;
5186
5177
    }
5187
5178
 
5193
5184
    if (state.lambdas != state.def_lambdas) {
5194
5185
        erts_free(ERTS_ALC_T_LOADER_TMP, (void *) state.lambdas);
5195
5186
    }
 
5187
    if (bin != NULL) {
 
5188
        driver_free_binary(bin);
 
5189
    }
 
5190
 
 
5191
        
5196
5192
    BIF_ERROR(p, BADARG);
5197
5193
}
5198
5194