PRL-PRG / UFOs

User Fault Objects: making vectors lazy and forgetful.
12 stars 3 forks source link

Too much freedom #14

Closed kondziu closed 4 years ago

kondziu commented 4 years ago

Now that we have automatic shutdown, I found some problems with it.

R example (create any vector and quit):

/opt/R-3.6.0/bin/R
library(ufoseq)
ufo_seq(1,10,1)
quit()
double free or corruption (fasttop)
Aborted (core dumped)
kondziu commented 4 years ago

I tried running it with valgrind (I'm new to valgrind, I hope this makes sense):

/opt/R-3.6.0/bin/R -d "valgrind --track-origins=yes --keep-stacktraces=alloc-and-free --error-limit=no --num-callers=40"
library(ufoseq)
ufo_seq(1,10,1)
--19530-- WARNING: unhandled amd64-linux syscall: 323
--19530-- You may be able to write your own handler.
--19530-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--19530-- Nevertheless we consider this a bug.  Please report
--19530-- it at http://valgrind.org/support/bug_reports.html.
syscall/userfaultfd: Function not implemented
error initializing User-Fault file descriptor: Function not implemented
Error in ufo_seq(1, 10, 1) : Error initializing the UFO framework (-1)
kondziu commented 4 years ago

I ran ufoTest but limited the iterations to 10. I don't get the double free, but I do get the Function not implemented thing from valgrind. This makes me think there might be two separate issues here.


#include <stdio.h>
#include <printf.h>

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>

#include <assert.h>

#include <unistd.h>

#include "userfaultCore.h"
#include "../unstdLib/errors.h"

int testpopulate(uint64_t startValueIdx, uint64_t endValueIdx, ufPopulateCallout callout, ufUserData userData, char* target){
  uint64_t* t = (uint64_t*) target;
  uint64_t* requestCt = (uint64_t*) userData;
  assert(startValueIdx >= 0);
  assert(endValueIdx <= *requestCt);
  for(int i = startValueIdx; i < endValueIdx; i++)
    t[i - startValueIdx] = ~i;

  return 0;
}

#define setBit(i)   ( bitmap[i >> 6] |= 1ull << (i & 0x3f) )
#define clearBit(i) ( bitmap[i >> 6] &= ~(1ull << (i & 0x3f)) )
#define testBit(i)  (0 != (bitmap[i >> 6] & (1ull << (i & 0x3f))) )

int main(int argc, char **argv) {
  int res;

  srand(13);
  int i = 0;

  ufInstance_t ufI = ufMakeInstance();
  tryPerrInt(res, ufInit(ufI), "Err Init", error);

//  uint64_t* bitmap = calloc(1024*1024*1024, 8);
  do{
    uint64_t ct = 1024ull*1024*((rand() & 0xffull) + 1), sz = ct*8 ;

    ufObjectConfig_t config = makeObjectConfig(uint64_t, 64, ct, (rand() & 0xffff) + 1);
    ufSetPopulateFunction(config, testpopulate);
    ufSetUserConfig(config, &ct);

    ufObject_t o;
    tryPerrInt(res, ufCreateObject(ufI, config, &o), "Err init obj", error1);
    uint64_t* h = (uint64_t*) ufGetHeaderPointer(o);
    assert(h[0] == 0x00);
    h[0] = 0x01;
    assert(h[0] == 0x01);

    uint64_t* ptr = (uint64_t*) ufGetValuePointer(o);

    free(config);

    printf("%lu\n", (uint64_t)ct);

    while((random() & 0xfff) != 0){
      uint64_t i = rand() % ct;
      assert(i < ct);
      assert(  (((uint64_t) &ptr[i]) - ((uint64_t)ptr)) < sz );
      uint64_t x = ptr[i];
      assert(~i == x);
    }

    tryPerrInt(res, ufDestroyObject(o), "Err destroying obj", error1);

    i++;
  }while(i<10);

  error1:
  tryPerrInt(res, ufShutdown(ufI, false), "Err Shutdown", error);
  tryPerrInt(res, ufAwaitShutdown(ufI), "Err Await Shutdown", error);
  exit(0);

  error:
  exit(-1);
}
kondziu@elma:~/Workspace/ufo_workspace/UFOs/ufos$ valgrind --track-origins=yes --keep-stacktraces=alloc-and-free --error-limit=no --num-callers=40 ./ufoTest 
==20414== Memcheck, a memory error detector
==20414== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==20414== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==20414== Command: ./ufoTest
==20414== 
--20414-- WARNING: unhandled amd64-linux syscall: 323
--20414-- You may be able to write your own handler.
--20414-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--20414-- Nevertheless we consider this a bug.  Please report
--20414-- it at http://valgrind.org/support/bug_reports.html.
syscall/userfaultfd: Function not implemented
error initializing User-Fault file descriptor: Function not implemented
x.x: Function not implemented
Err Init: Function not implemented
==20414== 
==20414== HEAP SUMMARY:
==20414==     in use at exit: 82,208 bytes in 4 blocks
==20414==   total heap usage: 12 allocs, 8 frees, 88,512 bytes allocated
==20414== 
==20414== LEAK SUMMARY:
==20414==    definitely lost: 0 bytes in 0 blocks
==20414==    indirectly lost: 0 bytes in 0 blocks
==20414==      possibly lost: 0 bytes in 0 blocks
==20414==    still reachable: 82,208 bytes in 4 blocks
==20414==         suppressed: 0 bytes in 0 blocks
==20414== Rerun with --leak-check=full to see details of leaked memory
==20414== 
==20414== For counts of detected and suppressed errors, rerun with: -v
==20414== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
kondziu commented 4 years ago

I'm closing this and splitting it into two issues.