Changeset 5420 for icGREP


Ignore:
Timestamp:
Apr 23, 2017, 2:10:34 PM (2 years ago)
Author:
nmedfort
Message:

Bug fix for 32-bit VM on 64-bit host

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5419 r5420  
    256256 * @param advice
    257257 *
    258  * Note: intermittent failures are possible. Test if this is more than a simple hint and handle accordingly.
     258 * Note: this funcition can fail if a kernel resource was temporarily unavailable. Test if this is more than a simple hint and handle accordingly.
    259259 *
    260260 *  ADVICE_NORMAL
     
    279279    Value * result = nullptr;
    280280    if (T.isOSLinux() || T.isOSDarwin()) {
    281         DataLayout DL(mMod);
    282         IntegerType * const intTy = getIntPtrTy(DL);
     281        IntegerType * const intTy = getInt32Ty();
    283282        IntegerType * const sizeTy = getSizeTy();
    284283        PointerType * const voidPtrTy = getVoidPtrTy();
     
    347346}
    348347
    349 Value * CBuilder::CreateMUnmap(Value * addr, Value * size) {
     348Value * CBuilder::CreateMUnmap(Value * addr, Value * len) {
    350349    IntegerType * const sizeTy = getSizeTy();
    351350    PointerType * const voidPtrTy = getVoidPtrTy();
    352     Function * fMUnmap = mMod->getFunction("munmap");
    353     if (LLVM_UNLIKELY(fMUnmap == nullptr)) {
    354         DataLayout DL(mMod);
    355         IntegerType * const intTy = getIntPtrTy(DL);
    356         FunctionType * fty = FunctionType::get(intTy, {voidPtrTy, sizeTy}, false);
    357         fMUnmap = Function::Create(fty, Function::ExternalLinkage, "munmap", mMod);
    358     }
     351    Function * munmapFunc = mMod->getFunction("munmap");
     352    if (LLVM_UNLIKELY(munmapFunc == nullptr)) {
     353        FunctionType * const fty = FunctionType::get(sizeTy, {voidPtrTy, sizeTy}, false);
     354        munmapFunc = Function::Create(fty, Function::ExternalLinkage, "munmap", mMod);
     355    }
     356    len = CreateZExtOrTrunc(len, sizeTy);
    359357    if (codegen::EnableAsserts) {
    360         Value * const pageOffset = CreateURem(CreatePtrToInt(addr, sizeTy), getSize(getpagesize()));
     358        CreateAssert(len, "CreateMUnmap: length cannot be 0");
     359        Value * const addrValue = CreatePtrToInt(addr, sizeTy);
     360        Value * const pageOffset = CreateURem(addrValue, getSize(getpagesize()));
    361361        CreateAssert(CreateICmpEQ(pageOffset, getSize(0)), "CreateMUnmap: addr must be a multiple of the page size");
     362        Value * const boundCheck = CreateICmpULT(addrValue, CreateSub(ConstantInt::getAllOnesValue(sizeTy), len));
     363        CreateAssert(boundCheck, "CreateMUnmap: addresses in [addr, addr+len) are outside the valid address space range");
    362364    }
    363365    addr = CreatePointerCast(addr, voidPtrTy);
    364     size = CreateZExtOrTrunc(size, sizeTy);
    365     CallInst * result = CreateCall(fMUnmap, {addr, size});
    366     if (codegen::EnableAsserts) {
    367         CreateAssert(CreateICmpEQ(result, ConstantInt::getNullValue(result->getType())), "CreateMUnmap: failed");
    368     }
    369     return result;
     366    return CreateCall(munmapFunc, {addr, len});
    370367}
    371368
Note: See TracChangeset for help on using the changeset viewer.