Пример #1
0
/** Convert an array of ProtectionDomain's into a w_Wordset of
 ** distinct PermissionCollection's.
 */
w_wordset pdarray2context(w_instance thisAccessControlContext, w_instance arrayOfProtectionDomains) {
  w_wordset context = NULL;
  w_instance *domain = instance2Array_instance(arrayOfProtectionDomains);
  w_int n = instance2Array_length(arrayOfProtectionDomains);
  w_int i;

  if (n) {
    if (!addToWordset(&context, (w_word)getReferenceField((*domain), F_ProtectionDomain_permissions))) {
      wabort(ABORT_WONKA, "Unable to add permission to context\n");
    }
    ++domain;
  }
  for (i = 1; i < n; ++i) {
    w_word permissions = (w_word)getReferenceField((*domain), F_ProtectionDomain_permissions);
    if (!isInWordset(&context,permissions)) {
      if (!addToWordset(&context,permissions)) {
        wabort(ABORT_WONKA, "Unable to add permission to context\n");
      }
    }
    ++domain;
  }
  if (n) {
    sortWordset(&context);
  }
  return context;
}
Пример #2
0
w_clazz createClazzArray(void) {
  w_string string_clone = cstring2String("clone",5);
  w_clazz clazz = allocClazz();
  w_method arrayclone = &Array_clone_method;
  w_size   i;

  for (i = 0; i < clazzObject->numDeclaredMethods; i++) {
    if (clazzObject->own_methods[i].spec.name == string_clone) {
      woempa(7, "Found clone method of clazzObject in slot [%d], using it as basis of array clone\n", i);
      w_memcpy(arrayclone, &clazzObject->own_methods[i], sizeof(w_Method));
      arrayclone->exec.function = (w_function)(w_void_fun)Array_clone;
      unsetFlag(arrayclone->flags, ACC_PROTECTED);
      setFlag(arrayclone->flags, ACC_PUBLIC);
    }
  }

  w_memcpy(clazz, clazzObject, sizeof(w_Clazz));
  clazz->resolution_monitor = allocMem(sizeof(x_Monitor));
  if (!clazz->resolution_monitor) {
    wabort(ABORT_WONKA, "Unable to allocate clazz->resolution_monitor\n");
  }
  x_monitor_create(clazz->resolution_monitor);
  clazz->dotified = cstring2String("array prototype", 15);
  clazz->tags = allocMem(clazzObject->numConstants * sizeof(w_ConstantType));
  if (!clazz->tags) {
    wabort(ABORT_WONKA, "Unable to allocate clazz->tags\n");
  }
  memcpy((char*)clazz->tags, (char*)clazzObject->tags, clazzObject->numConstants * sizeof(w_ConstantType));
  clazz->values = allocMem(clazzObject->numConstants * sizeof(w_word));
  if (!clazz->values) {
    wabort(ABORT_WONKA, "Unable to allocate clazz->values\n");
  }
  memcpy((char*)clazz->values, (char*)clazzObject->values, clazzObject->numConstants * sizeof(w_word));
  clazz->numDeclaredMethods = 1;
  clazz->own_methods = arrayclone;

  clazz->numInterfaces = 2;
  clazz->numDirectInterfaces = 2;
  clazz->interfaces = Array_interfaces;
  clazz->interfaces[0] = clazzCloneable;
  clazz->interfaces[1] = clazzSerializable;
  clazz->numSuperClasses = 1;
  clazz->supers = Array_supers;
  clazz->supers[0] = clazzObject;
  clazz->numConstants = 0;
  F_Array_length = 0; 
  F_Array_data = 1; 

  return clazz;

}
Пример #3
0
static int utypeqw(QW *qw, int c)
{
	W *win;
	W *w = qw->parent;
	int *notify = w->notify;
	int (*func) ();
	void *object = qw->object;

	if (locale_map->type) {
		c = utf8_decode(&qw_sm, c);
		if (c<0)
			return 0;
	}

	win = qw->parent->win;
	func = qw->func;
	vsrm(qw->prompt);
	joe_free(qw);
	w->object = NULL;
	w->notify = NULL;
	wabort(w);
	if (func)
		return func(win->object, c, object, notify);
	return -1;
}
Пример #4
0
void _releaseMem(void * block) {
  w_chunk chunk;
  if (!block) {
    wabort(ABORT_WONKA, "Bah. releaseMem(NULL)?");
  }

  chunk = block2chunk(block);
  pre_dealloc(currentWonkaThread, chunk, x_mem_size(chunk));
  x_mem_free(chunk);
}
Пример #5
0
static int rtnpw(BW *bw)
{
	W *w = bw->parent;
	PW *pw = (PW *) bw->object;
	unsigned char *s;
	W *win;
	int *notify;
	int (*pfunc) ();
	void *object;
	long byte;

	/* Extract entered text from buffer */
	p_goto_eol(bw->cursor);
	byte = bw->cursor->byte;
	p_goto_bol(bw->cursor);
	s = brvs(bw->cursor, (int) (byte - bw->cursor->byte));

	/* Save text into history buffer */
	if (pw->hist) {
		if (bw->b->changed) {
			append_history(pw->hist, sv(s));
		} else {
			promote_history(pw->hist, bw->cursor->line);
		}
	}

	/* Do ~ expansion and set new current directory */
	if (pw->file_prompt&2) {
		set_current_dir(s,1);
	}

	if (pw->file_prompt) {
		s = canonical(s);
	}

	win = w->win;
	pfunc = pw->pfunc;
	object = pw->object;
	bwrm(bw);
	joe_free(pw->prompt);
	joe_free(pw);
	w->object = NULL;
	notify = w->notify;
	w->notify = 0;
	wabort(w);
	dostaupd = 1;

	/* Call callback function */
	if (pfunc) {
		return pfunc(win->object, s, object, notify);
	} else {
		return -1;
	}
}
Пример #6
0
void _heapCheck(const char * function, const int line) {

  static w_int walks = 0;
  w_Wa Wa;
  w_wa wa = &Wa;

  wa->count = 0;
  wa->bytes = 0;
  wa->errors = 0;
  wa->all_count = 0;
  wa->all_bytes = 0;
  wa->function = function;
  wa->line = line;
  previous = NULL;
  x_mem_walk(x_eternal, checkWalk, wa);
  walks += 1;
  woempa(9, "%s %d : %d anon %d tagged, %d MB anon %d MB tagged, %d errors, %d scans.\n", function, line, wa->all_count, wa->count, wa->all_bytes / (1024 * 1024), wa->bytes / (1024 * 1024), wa->errors, walks);
  w_printf("%s %d : %d anon %d tagged, %d MB anon %d MB tagged, %d errors, %d scans.\n", function, line, wa->all_count, wa->count, wa->all_bytes / (1024 * 1024), wa->bytes / (1024 * 1024), wa->errors, walks);
  
  if (wa->errors) {
    wabort(ABORT_WONKA, "x_mem_walk returned %d errors\n", wa->errors);
  }
}
Пример #7
0
static w_chunk checkChunk(void * block, w_int for_realloc, const char * file, const int line) {

  static w_int errors = 0;
  static w_int checks = 0;
  static w_int walks = 0;
  w_chunk chunk;
  w_Wa Wa;
  w_wa wa = &Wa;

  checks += 1;
  
  if (checks % check_limit == 0) {
    x_mem_lock(x_eternal);
    woempa(7, "Performing heap check for alloc/releaseMem at %s:%d, count = %d\n", file, line, checks);
    wa->count = 0;
    wa->bytes = 0;
    wa->errors = 0;
    wa->all_bytes = 0;
    wa->all_count = 0;
    previous = NULL;
    x_mem_walk(x_eternal, checkWalk, wa);
    walks += 1;
    errors += wa->errors;
    x_mem_unlock();
    woempa(9, "%s.%d (alloc/release %p): Walked %d anon %d tagged chunks, %d MB anon %d Mb tagged, %d chunks were in error. Made %d scans.\n", file, line, block2chunk(block), wa->all_count - wa->count, wa->count, (wa->all_bytes - wa->bytes) / (1024 * 1024), wa->bytes / (1024 * 1024), wa->errors, walks);
    if (wa->errors) {
      wabort(ABORT_WONKA, "Found bad chunk. Stopping...\n");
    }
  }

  if (block == NULL) {
    wabort(ABORT_WONKA, "Freeing NULL block at %s:%d.\n", file, line);
  }

  /*
  ** It looks like a valid block, just proceed...
  */

  chunk = block2chunk(block);

  if (chunk->data[chunk->back] == FREED_BYTE) {
    wabort(ABORT_WONKA, "Freeing chunk %p twice (allocated %s %d, released %s %d).\n", chunk, chunk->file, chunk->line, file, line);
    return NULL;
  }

  if (chunk->data[chunk->back] != BACK_BYTE) {
    wabort(ABORT_WONKA, "Back fence overwritten of chunk %p (allocated %s %d, released %s %d).\n", chunk, chunk->file, chunk->line, file, line);
    return NULL;
  }

  if (chunk->front != FRONT_FENCE) {
    wabort(ABORT_WONKA, "Front fence of %p overwritten (allocated %s %d, released %s %d).\n", chunk, chunk->file, chunk->line, file, line);
    return NULL;
  }

  if (chunk->madgic != CHUNK_MADGIC) {
    wabort(ABORT_WONKA, "Wrong madgic of %p (allocated %s %d, released %s %d).\n", chunk, chunk->file, chunk->line, file, line);
    return NULL;
  }

  /*
  ** If this check isn't done for realloc, we overwrite the data area to quickly evoke
  ** errors when freed memory would b re-used. Also the backfence will get a new color.
  */

  if (! for_realloc) {
    memset(chunk->data, FREED_DATA, chunk->size);
    chunk->data[chunk->back] = FREED_BYTE;
  }

  return chunk;
  
}
Пример #8
0
w_int loadSuperClasses(w_clazz clazz, w_thread thread) {
  w_clazz super;
  w_int   i;
  w_int   n;
  w_int   result = CLASS_LOADING_DID_NOTHING;

#ifndef NO_FORMAT_CHECKS
  if (isNotSet(clazz->flags, CLAZZ_IS_TRUSTED) && !clazz->temp.super_index) {
    throwException(thread, clazzVerifyError, "Class %k has no superclass", clazz);

    return CLASS_LOADING_FAILED;
  }
#endif

  clazz->supers = allocMem(MAX_SUPER_CLASSES * sizeof(w_clazz));
  if (!clazz->supers) {
    return CLASS_LOADING_FAILED;
  }
  super = clazz;
  n = MAX_SUPER_CLASSES;
  for (i = 0; i < MAX_SUPER_CLASSES; ++i) {
    if (!super->temp.super_index) {
      woempa(1, "Reached top of hierarchy after %d class(es): %k\n", i, super);
      n = i;
      break;
    }

#ifndef NO_FORMAT_CHECKS
    if (isNotSet(super->flags, CLAZZ_IS_TRUSTED) && !isClassConstant(super, super->temp.super_index)) {
      throwException(thread, clazzClassFormatError, "Superclass of %k is not a class constant (is %02x)", super, super->tags[super->temp.super_index]);

      return CLASS_LOADING_FAILED;

    }
#endif

    super = getClassConstant(super, super->temp.super_index, thread);
    if (!super) {
      throwException(thread, clazzLinkageError, "Cannot resolve superclass of %k", clazz);

      return CLASS_LOADING_FAILED;

    }

    clazz->supers[i] = super;
    woempa(1, "Class %k supers[%d] = %k\n", clazz, i, super);
    if (getClazzState(super) >= CLAZZ_STATE_SUPERS_LOADED) {
      woempa(1, "Class %k is already supersLoaded, has %d superclasses => depth of %k is %d\n", super, super->numSuperClasses, clazz, i + super->numSuperClasses + 1);
      n = i + super->numSuperClasses + 1;
      break;
    }
  }

  if (n == MAX_SUPER_CLASSES) {
      wabort(ABORT_WONKA, "Class %k has too many superclasses", clazz);
  }

  for (i= i + 1; i < n; ++i) {
    woempa(1, "Copying %k (superclass[%d] of %k) as superclass[%d] of %k\n", super->supers[i - n + super->numSuperClasses], i - n + super->numSuperClasses, super, i, clazz);
    clazz->supers[i] = super->supers[i - n + super->numSuperClasses];
  }

  woempa(1, "Class %k has total of %d superclasses\n", clazz, n);
  clazz->supers = reallocMem(clazz->supers, n * sizeof(w_clazz));
  if (!clazz->supers) {
    return CLASS_LOADING_FAILED;
  }
  clazz->numSuperClasses = n;
  super = clazz->supers[0];
#ifndef NO_HIERARCHY_CHECKS
  if (isNotSet(super->flags, CLAZZ_IS_TRUSTED)) {
    if (isSet(clazz->flags, ACC_INTERFACE) && super != clazzObject) {
      throwException(thread, clazzIncompatibleClassChangeError, "Superclass %k of %k is an interface", super, clazz);

      return CLASS_LOADING_FAILED;

    }
    if (isSet(super->flags, ACC_FINAL)) {
      woempa(9, "Violation of J+JVM Constraint 4.1.1, item 2\n");
      throwException(thread, clazzIncompatibleClassChangeError, "Superclass %k of %k is final", super, clazz);

      return CLASS_LOADING_FAILED;

    }
    if (isNotSet(super->flags, ACC_PUBLIC) && !sameRuntimePackage(clazz, super)) {
      woempa(9, "Violation of J+JVM Constraint 4.1.4\n");
      throwException(thread, clazzIncompatibleClassChangeError, "Superclass %k of %k is not accessible", super, clazz);

      return CLASS_LOADING_FAILED;

    }
  }
#endif

  for (i = n - 1; i >= 0; --i) {
    result |= mustBeSupersLoaded(clazz->supers[i]);
    if (result == CLASS_LOADING_FAILED || exceptionThrown(thread)) {

      return CLASS_LOADING_FAILED;

    }
  }

  clazz->flags |= super->flags & CLAZZ_HERITABLE_FLAGS;

  return CLASS_LOADING_SUCCEEDED;
}