Пример #1
0
void screen_shutdown(void) {
  if (screen) {
    if (screen->video) {
      releaseMem(screen->video);
    }
    releaseMem(screen);
    screen = NULL;
  }
}
Пример #2
0
void ShaMessageDigest_finalize(JNIEnv *env, w_instance This){
  w_sha sha =  getWotsitField(This, F_ShaMessageDigest_wotsit);

  if(sha != NULL){
    releaseMem(sha);
  }
}
Пример #3
0
w_long RMIConnection_getStringHash(JNIEnv *env, w_instance ThisClass, w_instance TheString) {
  w_long suid = 0;
  w_thread thread = JNIEnv2w_thread(env);

  if(TheString == NULL){
    throwException(thread,clazzNullPointerException,NULL);
  }
  else {
    w_word length;
    w_byte * utf8 = string2UTF8(String2string(TheString), &length);

    woempa(10, "'%w' with length %i (=?= %d)\n",String2string(TheString),length,(w_int)*(utf8+1));

    if(utf8) {
      w_sha sha = allocSha();
      processSha(sha, utf8, length);
      finishSha(sha);
      releaseMem(utf8);

      suid = sha->signature.B[4];
      suid <<= 8;  suid |= sha->signature.B[5];
      suid <<= 8;  suid |= sha->signature.B[6];
      suid <<= 8;  suid |= sha->signature.B[7];
      suid <<= 8;  suid |= sha->signature.B[0];
      suid <<= 8;  suid |= sha->signature.B[1];
      suid <<= 8;  suid |= sha->signature.B[2];
      suid <<= 8;  suid |= sha->signature.B[3];
    }
  }
  return suid;

}
Пример #4
0
static x_boolean release_block(t_mchecker mc, t_block b, x_boolean stop, x_boolean discard) {

  x_boolean result;

  result = check_block(b, stop);
  
  x_mutex_lock(test_mutex, x_eternal);

  x_list_remove(b);
  decrement_count(b, b->size);

  if (discard) {
    total_discarded += 1;
    if (total_discarded % 1000 == 0) {
      oempa("Discarding Wonka Chunk %d...\n", total_discarded);
    }
    discardMem(b);
  }
  else {
    releaseMem(b);
  }

  x_mutex_unlock(test_mutex);

  return result;
  
}
Пример #5
0
int reduceFifo(w_fifo f) {
  FifoLeaf *current = f->putFifoLeaf;
  FifoLeaf *next = current->next;
  int released = 0;

#ifdef THREAD_SAFE_FIFOS
  if (f->mutex) {
    x_mutex_lock(f->mutex, x_eternal);
  }
#endif
  woempa(7, "Fifo %p has putFifoLeaf %p, getFifoLeaf %p\n", f, f->putFifoLeaf, f->getFifoLeaf);

  if (f->getFifoLeaf != next) {
    CRITICAL_ENTER
    woempa(7, "current is %p, next is %p\n", current, next);
    woempa(7, "making current->next point to next->next (%p)\n", next->next);
    current->next = next->next;
    CRITICAL_EXIT
    releaseMem(next);
    released = sizeof(FifoLeaf) + (sizeof(void *) * (f->elementsPerLeaf));
    woempa(7, "releasing %p, freed %d bytes\n", next, released);
  }

  return released;

}
Пример #6
0
int contractFifo(w_fifo f) {
  FifoLeaf *current;
  FifoLeaf *next;
  int released = 0;

  CRITICAL_ENTER
  current = f->putFifoLeaf;
  next = current->next;
  woempa(7, "Fifo %p has putFifoLeaf %p, getFifoLeaf %p\n", f, f->putFifoLeaf, f->getFifoLeaf);

  while (f->getFifoLeaf != next) {
    woempa(7, "current is %p, next is %p\n", current, next);
    woempa(7, "making current->next point to next->next (%p)\n", next->next);
    current->next = next->next;
    CRITICAL_EXIT // releaseMem will acquire memory lock
    releaseMem(next);
    released += sizeof(FifoLeaf) + (sizeof(void *) * (f->elementsPerLeaf));
    woempa(7, "releasing %p, freed %d bytes so far\n", next, released);
    CRITICAL_ENTER
    current = current->next;
    next = current->next;
  }
  CRITICAL_EXIT

  return released;

}
Пример #7
0
void ShaMessageDigest_engineReset(JNIEnv *env, w_instance This){
  w_sha sha =  getWotsitField(This, F_ShaMessageDigest_wotsit);

  if(sha != NULL){
    releaseMem(sha);
  }

  sha = allocSha();

  setWotsitField(This, F_ShaMessageDigest_wotsit, sha);

}
Пример #8
0
static void jdwp_vm_classes(jdwp_command_packet cmd) {
  w_int length;
  w_ubyte *sig;
  w_string sig_string;
  w_fifo fifo_of_fifos;
  w_fifo clazz_fifo;
  w_fifo one_fifo;
  w_clazz clazz;

  woempa(7, "Searching all class loaders for all loaded classes\n");
  fifo_of_fifos = forEachClassLoader(getAllLoadedClasses);
  if (fifo_of_fifos) {
    woempa(7, "Found %d class loaders\n", occupancyOfFifo(fifo_of_fifos));
    clazz_fifo = allocFifo(254);
    while ((one_fifo = getFifo(fifo_of_fifos))) {
      woempa(7, "Reading fifo %p\n", one_fifo);
      while ((clazz = getFifo(one_fifo))) {
        if (!clazzIsPrimitive(clazz)) {
          woempa(1, "  %K -> clazz_fifo\n", clazz);
          putFifo(clazz, clazz_fifo);
        }
        else {
          woempa(7, "  %K is primitive class, ignoring\n", clazz);
        }
      }
      woempa(7, "Releasing fifo %p\n", one_fifo);
      releaseFifo(one_fifo);
    }
    woempa(7, "Found %d classes\n", occupancyOfFifo(clazz_fifo));

    jdwp_put_u4(&reply_grobag, occupancyOfFifo(clazz_fifo));
    woempa(7, "Reading clazz_fifo\n");
    while ((clazz = getFifo(clazz_fifo))) {
      jdwp_put_tagged_type(&reply_grobag, clazz);
      sig_string = clazz2desc(clazz);
      woempa(1, "  %K descriptor %w\n", clazz, sig_string);
      sig = jdwp_string2UTF8(sig_string, &length);
      jdwp_put_bytes(&reply_grobag, sig, length + 4);
      deregisterString(sig_string);
      releaseMem(sig);
      jdwp_put_u4(&reply_grobag, clazz2status(clazz));
    }
    woempa(7, "Releasing clazz_fifo\n");
    releaseFifo(clazz_fifo);
  }
  else {
    jdwp_put_u4(&reply_grobag, 0);
  }

  jdwp_send_reply(cmd->id, &reply_grobag, jdwp_err_none);
}
Пример #9
0
static void jdwp_vm_classes_by_sig(jdwp_command_packet cmd) {
  w_int length;
  w_ubyte *sig;
  w_string sig_string;
  w_fifo fifo_of_fifos;
  w_fifo clazz_fifo;
  w_fifo one_fifo;
  w_clazz clazz;

  sig = jdwp_UTF82cstring((w_ubyte*)cmd->data, &length);
  sig_string = cstring2String((char*)sig, (w_word)length);
  classname = undescriptifyClassName(sig_string);
  if (isSet(verbose_flags, VERBOSE_FLAG_JDWP)) {
    w_printf("JDWP: signature = %w -> classname = %w\n", sig_string, classname);
  }
  releaseMem(sig);
  deregisterString(sig_string);

  woempa(7, "Searching all class loaders for classes with signature %w\n", classname);
  fifo_of_fifos = forEachClassLoader(getMatchingClasses);
  if (fifo_of_fifos) {
    woempa(7, "Found %d class loaders\n", occupancyOfFifo(fifo_of_fifos));
    deregisterString(classname);
    clazz_fifo = allocFifo(254);
    while ((one_fifo = getFifo(fifo_of_fifos))) {
      woempa(7, "Reading fifo %p\n", one_fifo);
      while ((clazz = getFifo(one_fifo))) {
          woempa(1, "  %K -> clazz_fifo\n", clazz);
          putFifo(clazz, clazz_fifo);
      }
      woempa(7, "Releasing fifo %p\n", one_fifo);
      releaseFifo(one_fifo);
    }
    woempa(7, "Found %d classes\n", occupancyOfFifo(clazz_fifo));
    jdwp_put_u4(&reply_grobag, occupancyOfFifo(clazz_fifo));

    while ((clazz = getFifo(clazz_fifo))) {
      woempa(1, "  %K\n", clazz);
      jdwp_put_tagged_type(&reply_grobag, clazz);
      jdwp_put_u4(&reply_grobag, clazz2status(clazz));
    }
    releaseFifo(clazz_fifo);
  }
  else {
    jdwp_put_u4(&reply_grobag, 0);
  }

  jdwp_send_reply(cmd->id, &reply_grobag, jdwp_err_none);
}
Пример #10
0
static void jdwp_vm_classpaths(jdwp_command_packet cmd) {
  char *finger = (char*)system_vm_args->classpath;
  char *next;
  char **array;
  int fsrootlen = strlen(fsroot);
  int i;
  int l;
  int n;

  woempa(7, "Base dir = %s\n", jdwp_base_directory);
  // baseDir
  jdwp_put_cstring(&reply_grobag, jdwp_base_directory, strlen(jdwp_base_directory));

  if (fsroot[fsrootlen - 1] == '/') {
    --fsrootlen;
  }
  woempa(7, "fsroot = %s\n", fsroot);
  woempa(7, "Classpath = %s\n", system_vm_args->classpath);
  n = 0;
  while (finger) {
    n++;
    finger = strstr(++finger, ":");
  }
  woempa(7, "Classpath has %d components\n", n);
  array = allocMem(n * sizeof(char*));
  finger = (char*)system_vm_args->classpath;
  i = 0;
  while (finger) {
    next = strstr(finger, ":");
    l = next ? next - finger : (int)strlen(finger);
    if (l >= 3 && finger[0] == '{' && finger[1] == '}' && finger[2] == '/') {
      array[i] = allocMem(l + fsrootlen);
      strcpy(array[i], fsroot);
      memcpy(array[i] + fsrootlen, finger + 2, l);
      array[i][fsrootlen + l - 2] = 0;
    }
    else {
      array[i] = allocMem(l + 1);
      strcpy(array[i], finger);
    }
    woempa(7, "  %s\n", array[i]);
    ++i;
    finger = next ? next + 1 : NULL;
  }
  // classpaths
  jdwp_put_u4(&reply_grobag, n);
  for (i = 0; i < n; ++i) {
    woempa(7, "  %s\n", array[i]);
    jdwp_put_cstring(&reply_grobag, array[i], strlen(array[i]));
    releaseMem(array[i]);
  }
  
  finger = bootclasspath;

  woempa(7, "Bootclasspath = %s\n", bootclasspath);
  n = 0;
  while (finger) {
    n++;
    finger = strstr(++finger, ":");
  }
  woempa(7, "Bootclasspath has %d components\n", n);
  array = reallocMem(array, n * sizeof(char*));
  finger = bootclasspath;
  i = 0;
  while (finger) {
    next = strstr(finger, ":");
    l = next ? next - finger : (int)strlen(finger);
    if (l >= 3 && finger[0] == '{' && finger[1] == '}' && finger[2] == '/') {
      array[i] = allocMem(l + fsrootlen);
      strcpy(array[i], fsroot);
      memcpy(array[i] + fsrootlen, finger + 2, l);
      array[i][fsrootlen + l - 2] = 0;
    }
    else {
      array[i] = allocMem(l + 1);
      strcpy(array[i], finger);
    }
    woempa(7, "  %s\n", array[i]);
    ++i;
    finger = next ? next + 1 : NULL;
  }
  // bootclasspaths
  jdwp_put_u4(&reply_grobag, n);
  for (i = 0; i < n; ++i) {
    woempa(7, "  %s\n", array[i]);
    jdwp_put_cstring(&reply_grobag, array[i], strlen(array[i]));
    releaseMem(array[i]);
  }
  
  releaseMem(array);

  jdwp_send_reply(cmd->id, &reply_grobag, jdwp_err_none);
}
Пример #11
0
CJHTreeNode::~CJHTreeNode()
{
    releaseMem(keyBuf, expandedSize);
}
Пример #12
0
void ShaMessageDigest_nativeDigest(JNIEnv *env, w_instance This, w_instance Bytes, w_int off){
  w_thread thread = JNIEnv2w_thread(env);
  w_int length;
  w_ubyte * bytes;
  w_sha sha;
  w_word word;

  if(Bytes == NULL){
    throwException(thread,clazzNullPointerException,NULL);
  }

  length = instance2Array_length(Bytes);

  if(off < 0 || off > length - 20){
    throwException(thread,clazzArrayIndexOutOfBoundsException,NULL);
  }

  sha = getWotsitField(This, F_ShaMessageDigest_wotsit);

  if(sha == NULL){
    sha = allocSha();
    setWotsitField(This, F_ShaMessageDigest_wotsit, sha);
    if(sha == NULL){
      return;
    }
  }

  bytes = ((w_ubyte*)instance2Array_byte(Bytes)) + off;

  finishSha(sha);

  /** TODO make sure this still works on a BIG ENDIAN platform */
  word = sha->signature.W[0];
  *bytes++ = (w_ubyte)(word>>24);
  *bytes++ = (w_ubyte)(word>>16);
  *bytes++ = (w_ubyte)(word>>8);
  *bytes++ = (w_ubyte) word;
  word = sha->signature.W[1];
  *bytes++ = (w_ubyte)(word>>24);
  *bytes++ = (w_ubyte)(word>>16);
  *bytes++ = (w_ubyte)(word>>8);
  *bytes++ = (w_ubyte) word;
  word = sha->signature.W[2];
  *bytes++ = (w_ubyte)(word>>24);
  *bytes++ = (w_ubyte)(word>>16);
  *bytes++ = (w_ubyte)(word>>8);
  *bytes++ = (w_ubyte) word;
  word = sha->signature.W[3];
  *bytes++ = (w_ubyte)(word>>24);
  *bytes++ = (w_ubyte)(word>>16);
  *bytes++ = (w_ubyte)(word>>8);
  *bytes++ = (w_ubyte) word;
  word = sha->signature.W[4];
  *bytes++ = (w_ubyte)(word>>24);
  *bytes++ = (w_ubyte)(word>>16);
  *bytes++ = (w_ubyte)(word>>8);
  *bytes++ = (w_ubyte) word;


  releaseMem(sha);

  clearWotsitField(This, F_ShaMessageDigest_wotsit);
}
Пример #13
0
//
// destructor
//
frame::~frame() {
    releaseMem();
}
Пример #14
0
void destroyPackage(w_package p) {
  deregisterString(p->name);
  releaseMem(p);
}
Пример #15
0
w_int RandomAccessFile_createFromString (JNIEnv *env, w_instance thisRAF, w_instance path, int mode) {
  w_thread thread = JNIEnv2w_thread(env);
  w_string pathname_string;
  char *pathname;
  const char  *fmode = "r+";
  int         openmode;
  int         fdesc;
  vfs_FILE    *file;
  w_instance  fd_obj;
  struct vfs_STAT statbuf;
  int rc;

  if (mustBeInitialized(clazzFileDescriptor) == CLASS_LOADING_FAILED) {
    return 0;
  }

  pathname_string = String2string(path);
  pathname = (char*)string2UTF8(pathname_string, NULL) + 2;	  
  switch(mode) {
    case 0:
      openmode = VFS_O_RDONLY;
      fmode = "r";
      break;
    case 1:
      openmode = VFS_O_RDWR | VFS_O_CREAT;
      break;
    case 2:
      openmode = VFS_O_RDWR | VFS_O_CREAT | VFS_O_DIRECT;
      break;
    case 3:
      openmode = VFS_O_RDWR | VFS_O_CREAT | VFS_O_SYNC;
      break;
    default:
     openmode = 0;
  }

  rc = vfs_stat(pathname, &statbuf);

  switch(mode) {
    case 0:
      if (rc != 0 || !VFS_S_ISREG(statbuf.st_mode) || (((statbuf.st_mode & VFS_S_IRWXU) & VFS_S_IRUSR) != VFS_S_IRUSR)) {
        return 1;
      }
      break;

    default:
      if (rc == 0 && (!VFS_S_ISREG(statbuf.st_mode) || (((statbuf.st_mode & VFS_S_IRWXU) & VFS_S_IWUSR) != VFS_S_IWUSR))) {
        return 1;
      }
  }

  fdesc = vfs_open(pathname, openmode, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

  releaseMem(pathname - 2);

  if(fdesc == -1) {
    return 1;
  } 

  file = vfs_fdopen(fdesc, fmode);

  if (file == NULL) {
    return 1;
  } else {
    enterUnsafeRegion(thread);
    fd_obj = allocInstance(thread, clazzFileDescriptor);
    enterSafeRegion(thread);
    if(fd_obj != NULL) {
      setReferenceField(thisRAF, fd_obj, F_RandomAccessFile_fd);
      setBooleanField(fd_obj, F_FileDescriptor_validFD, 1);
      setWotsitField(fd_obj, F_FileDescriptor_fd, file);
      setReferenceField(fd_obj, path, F_FileDescriptor_fileName);
    }
  }
  return 0;
}