Example #1
0
static void initInternal() {
  SanitizerToolName = "Scudo";
  CHECK(!ScudoInitIsRunning && "Scudo init calls itself!");
  ScudoInitIsRunning = true;

  initFlags();

  AllocatorOptions Options;
  Options.setFrom(getFlags(), common_flags());
  initAllocator(Options);

  ScudoInitIsRunning = false;
}
Example #2
0
static jint initAgent(JavaVM *vm, char *options)
{
	jint                rc;
	jvmtiError          err;
	jvmtiCapabilities   capabilities;
	jvmtiEventCallbacks callbacks;
	jvmtiEnv           *jvmti;

	if (JNI_FALSE == __sync_lock_test_and_set(&gdata->vmStarted, JNI_TRUE))
	{
		/* Get JVMTI environment */
		jvmti = NULL;
		rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION);
		if (rc != JNI_OK)
		{
			fatal_error("ERROR: Unable to create jvmtiEnv, error=%d\n", rc);
			return 1;
		}
		if ( jvmti == NULL )
		{
			fatal_error("ERROR: No jvmtiEnv* returned from GetEnv\n");
		}

		initAllocator(gdata->self_check);
		initClassesToCheck();
		gdata->jvmti = jvmti;
		gdata->vm = vm;
		gdata->vmDeathCalled = JNI_FALSE;

		/* Get/Add JVMTI capabilities */
		memset(&capabilities, 0, sizeof(capabilities));
		capabilities.can_tag_objects = 1;
		capabilities.can_get_source_file_name  = 1;
		capabilities.can_get_line_numbers  = 1;
		err = (*jvmti)->AddCapabilities(jvmti, &capabilities);
		check_jvmti_error(jvmti, err, "add capabilities");

		/* Create the raw monitor */
		err = (*jvmti)->CreateRawMonitor(jvmti, "agent lock", &(gdata->lock));
		check_jvmti_error(jvmti, err, "create raw monitor");

		/* Set callbacks and enable event notifications */
		memset(&callbacks, 0, sizeof(callbacks));
		callbacks.VMDeath                 = &vmDeath;
		callbacks.VMInit           = &vmInit;

		err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
		check_jvmti_error(jvmti, err, "set event callbacks");
		err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
				JVMTI_EVENT_VM_DEATH, NULL);
		check_jvmti_error(jvmti, err, "set event notifications");
		err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
				JVMTI_EVENT_VM_INIT, NULL);
		check_jvmti_error(jvmti, err, "Cannot set event notification");
	}
    
    if (!parse_agent_options(options))
    {
    	return 1;
    }

    return 0;
}