Exemple #1
0
MODULE create_child_thread (THREAD *thread)
{
    THREAD
        *child = NULL;
    TCB
        *child_tcb = NULL;
    struct_smtsmtp_message
        *event = NULL;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

  START_BODY
    get_smtsmtp_message (thread-> event-> body, &event);

    child = thread_create (AGENT_NAME, "");
    RAISE_EXC_IF (child == NULL, undefined_event);
    
    child_tcb = child-> tcb;
    clear_context (child_tcb);
    
    init_child_context (child_tcb, event, 
                        thread-> event-> sender,
                        thread-> event-> event_number);
    CHECK_EXC;
    event = NULL;

  END_BODY

    if (event)
        free_smtsmtp_message (&event);
}
AmfParser::~AmfParser() {
	// TODO Auto-generated destructor stub
	clear_context(&mContext);

	if( mpParseBuffer != NULL ) {
		delete[] mpParseBuffer;
		mpParseBuffer = NULL;
	}
}
bool PrologLoader :: load (char * file_name) {
	old_caption_id = root -> captionId ();
	old_auto_atoms = root -> autoAtoms ();
	root -> setCaptions (0, false);
	bool ret = LOAD (file_name);
	clear_context ();
	root -> setCaptions (old_caption_id, old_auto_atoms);
	return ret;
}
Exemple #4
0
av_cold void swr_free(SwrContext **ss){
    SwrContext *s= *ss;
    if(s){
        clear_context(s);
        if (s->resampler)
            s->resampler->free(&s->resample);
    }

    av_freep(ss);
}
Exemple #5
0
/*
 * Push the current context onto the context stack; the current context
 * is disabled, but not closed.
 */
void PushContext( void )
/**********************/
{
    if( stackItems == MAX_INDIRECTIONS ) {
        FatalError( "Too many levels of context indirection." );
    }
    memcpy( &stack[stackItems], &curContext, sizeof(struct Context) );
    stackItems++;
    clear_context( &curContext );
    curContextInitialized = 0;
}
Exemple #6
0
int smtsmtp_init (void)
{
    AGENT  *agent;                      /*  Handle for our agent             */
    THREAD *thread;
#   include "smtsmtp.i"                /*  Include dialog interpreter       */

    /*  Change any of the agent properties that you need to                  */
    agent-> router      = FALSE;        /*  FALSE = default                  */
    agent-> max_threads = 0;            /*  0 = default                      */

    /*                      Method name     Event value      Priority        */
    /*  Shutdown event comes from Kernel                                     */
    declare_smtlib_shutdown   (shutdown_event,    SMT_PRIORITY_MAX);

    /*  Public methods supported by this agent                               */
    declare_smtsmtp_send_message   (send_mail_event,   0);
    declare_smtsmtp_open_message   (open_mail_event,   0);
    declare_smtsmtp_message_chunk  (mail_chunk_event,  0);
    declare_smtsmtp_close_message  (close_mail_event,  0);

    /*  Reply events from socket agent                                       */
    declare_smtsock_connect_ok   (sock_connect_ok_event,  SMT_PRIORITY_HIGH);
    declare_smtsock_read_ok      (sock_read_ok_event,     SMT_PRIORITY_HIGH);
    declare_smtsock_closed       (sock_closed_event,      SMT_PRIORITY_HIGH);
    declare_smtsock_read_closed  (sock_read_closed_event, SMT_PRIORITY_HIGH);
    declare_smtsock_timeout      (sock_timeout_event,     SMT_PRIORITY_HIGH);
    declare_smtsock_error        (sock_error_event,       SMT_PRIORITY_HIGH);
    declare_smtsock_read_timeout (sock_timeout_event,     SMT_PRIORITY_HIGH);
    declare_smtsock_ok           (sock_ok_event,          SMT_PRIORITY_HIGH);

    /*  Ensure that socket i/o agent is running, else start it up            */
    if (agent_lookup (SMT_SOCKET) == NULL)
        smtsock_init ();
    if ((thread = thread_lookup (SMT_SOCKET, "")) != NULL)
        sockq = thread-> queue-> qid;
    else
        return (-1);

    /*  Create master thread */
    if ((thread = thread_create (AGENT_NAME, "master")) != NULL)
      {
        tcb = thread-> tcb;
        clear_context (tcb);
        tcb-> thread_type = master_event;
      }
    else
        return (-1);

    /*  We need random number to generate message boundaries                 */
    randomize ();

    /*  Signal okay to caller that we initialised okay                       */
    return (0);
}
Exemple #7
0
/*
 * Open a new file context.
 */
int OpenFileContext( const char *filename )
/*****************************************/
{
    if( curContextInitialized )  Zoinks();
    clear_context( &curContext );

    curContext.fp = fopen( filename, "rt" );
    if( curContext.fp == NULL )  return( 1 );

    curContextInitialized = 1;
    curContext.type = COMMAND_FILE_CONTEXT;
    return( 0 );
}
int
heim_digest_parse_challenge(heim_digest_t context, const char *challenge)
{
    struct md5_value *val = NULL;
    int ret, type;
    
    challenge = check_prefix(context, challenge);

    ret = parse_values(challenge, &val);
    if (ret)
	goto out;

    ret = 1;

    context->serverNonce = values_find(&val, "nonce");
    if (context->serverNonce == NULL) goto out;

    context->serverRealm = values_find(&val, "realm");
    if (context->serverRealm == NULL) goto out;

    /* check alg */

    context->serverAlgorithm = values_find(&val, "algorithm");
    if (context->serverAlgorithm == NULL || strcasecmp(context->serverAlgorithm, "md5") == 0) {
	type = HEIM_DIGEST_TYPE_RFC2617_MD5;
    } else if (strcasecmp(context->serverAlgorithm, "md5-sess") == 0) {
	type = HEIM_DIGEST_TYPE_RFC2617_OR_RFC2831;
    } else {
	goto out;
    }

    context->serverQOP = values_find(&val, "qop");
    if (context->serverQOP == NULL)
	type = HEIM_DIGEST_TYPE_RFC2069;
    
    context->serverOpaque = values_find(&val, "opaque");

    if (context->type != HEIM_DIGEST_TYPE_AUTO && (context->type & type) == 0)
	goto out;
    else if (context->type == HEIM_DIGEST_TYPE_AUTO)
	context->type = type;

    ret = 0;
 out:
    free_values(val);
    if (ret)
	clear_context(context);
    return ret;
}
Exemple #9
0
void servicelet::clear_outstanding_tasks()
{
    std::lock_guard<std::mutex> l(_outstanding_tasks_lock);
    for (auto it = _outstanding_tasks.begin(); it != _outstanding_tasks.end(); it++)
    {
        it->second->cancel(true);

        auto sc = dynamic_cast<service_context_manager*>(it->second);
        if (nullptr != sc)
        {
            sc->clear_context();
        }
    }
    _outstanding_tasks.clear();
}
Exemple #10
0
/*
 * Open a new environment variable context.
 */
int OpenEnvironContext( const char *envVar )
/******************************************/
{
    if( curContextInitialized )  Zoinks();
    clear_context( &curContext );

    curContext.data = getenv( envVar );
    curContext.dataStart = curContext.data;
    if( curContext.data == NULL )  return( 1 );
    curContext.dataLen = strlen( curContext.dataStart );

    curContextInitialized = 1;
    curContext.type = ENVIRON_VAR_CONTEXT;
    return( 0 );
}
Exemple #11
0
int
heim_digest_parse_challenge(heim_digest_t context, const char *challenge)
{
    struct md5_value *val = NULL;
    int ret, type;

    ret = parse_values(challenge, &val);
    if (ret)
	goto out;

    ret = 1;

    context->serverNonce = values_find(&val, "nonce");
    if (context->serverNonce == NULL) goto out;

    context->serverRealm = values_find(&val, "realm");
    if (context->serverRealm == NULL) goto out;

    context->serverQOP = values_find(&val, "qop");
    if (context->serverQOP == NULL)
	context->serverQOP = strdup("auth");
    if (context->serverQOP == NULL) goto out;

    /* check alg */

    context->serverAlgorithm = values_find(&val, "algorithm");
    if (context->serverAlgorithm == NULL || strcasecmp(context->serverAlgorithm, "md5") == 0) {
	type = HEIM_DIGEST_TYPE_RFC2069;
    } else if (strcasecmp(context->serverAlgorithm, "md5-sess") == 0) {
	type = HEIM_DIGEST_TYPE_MD5_SESS;
    } else {
	goto out;
    }

    if (context->type != HEIM_DIGEST_TYPE_AUTO && context->type != type)
	goto out;
    else
	context->type = type;



    ret = 0;
 out:
    free_values(val);
    if (ret)
	clear_context(context);
    return ret;
}
Exemple #12
0
void
shutdown_agent(void) {

    /* probably some of this can be called as shutdown callback */
    shutdown_tree();
    clear_context();
    netsnmp_clear_callback_list();
    netsnmp_clear_tdomain_list();
    netsnmp_clear_handler_list();
    netsnmp_container_free_list();
    clear_sec_mod();
    clear_snmp_enum();
    clear_callback();
    clear_user_list();

    done_init_agent = 0;
}
Exemple #13
0
/*
 * Open a new command line context.
 */
int OpenCmdLineContext( void )
/****************************/
{
    int                 len;

    if( curContextInitialized )  Zoinks();
    clear_context( &curContext );

    /*** Make a copy of the command line ***/
    len = _bgetcmd( NULL, 0 ) + 1;
    curContext.dataStart = AllocMem( len );
    getcmd( curContext.dataStart );

    curContext.data = curContext.dataStart;
    curContext.dataLen = strlen( curContext.dataStart );
    curContextInitialized = 1;
    curContext.type = COMMAND_LINE_CONTEXT;
    return( 0 );
}
Exemple #14
0
/*
 * Close the current context.
 */
void CloseContext( void )
/***********************/
{
    if( curContextInitialized ) {
        switch( curContext.type ) {
          case COMMAND_LINE_CONTEXT:
            free( curContext.dataStart );
          case ENVIRON_VAR_CONTEXT:
            break;
          case COMMAND_FILE_CONTEXT:
            fclose( curContext.fp );
            break;
          default:
            Zoinks();
        }
    }

    curContextInitialized = 0;
    clear_context( &curContext );
}
Exemple #15
0
void
shutdown_agent(void) {

    /* probably some of this can be called as shutdown callback */
    shutdown_tree();
    clear_context();
    netsnmp_clear_callback_list();
    netsnmp_clear_tdomain_list();
    netsnmp_clear_handler_list();
    shutdown_agent_sysORTable();
    netsnmp_container_free_list();
    clear_sec_mod();
    clear_snmp_enum();
    clear_callback();
    shutdown_secmod();
    netsnmp_addrcache_destroy();
#ifdef NETSNMP_CAN_USE_NLIST
    free_kmem();
#endif

    done_init_agent = 0;
}
void
heim_digest_release(heim_digest_t context)
{
    clear_context(context);
    free(context);
}
Exemple #17
0
kern_return_t
kxld_link_file(
               KXLDContext       * context,
               u_char            * file,
               u_long              size,
               const char        * name,
               void              * callback_data,
               KXLDDependency    * dependencies,
               u_int               ndependencies,
               u_char           ** linked_object_out,
               kxld_addr_t       * kmod_info_kern)
{
    kern_return_t       rval                    = KERN_FAILURE;
    kxld_addr_t         vmaddr                  = 0;
    u_long              vmsize                  = 0;
    u_char            * linked_object           = NULL;
    u_char            * linked_object_alloc     = NULL;
    
    kaslr_offsets_count = 0;
    kaslr_offsets_index = 0;
    kaslr_offsets = NULL;

    kxld_set_logging_callback_data(name, callback_data);
    
    kxld_log(kKxldLogLinking, kKxldLogBasic, "Linking kext %s", name);
    
    require_action(context, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(dependencies, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(ndependencies, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(file, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(size, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(linked_object_out, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(kmod_info_kern, finish, rval=KERN_INVALID_ARGUMENT);
    
    isSplitKext = FALSE;
    isOldInterface = TRUE;

    rval = init_context(context, ndependencies);
    require_noerr(rval, finish);
    
    rval = init_kext_objects(context, file, size, name,
                             dependencies, ndependencies);
    require_noerr(rval, finish);
    
    linked_object = allocate_kext(context, callback_data,
                                  &vmaddr, &vmsize, &linked_object_alloc);
    require_action(linked_object, finish, rval=KERN_RESOURCE_SHORTAGE);
    
    
    rval = kxld_kext_relocate(context->kext,
                              vmaddr,
                              &context->vtables_by_name,
                              &context->defined_symbols_by_name,
                              &context->obsolete_symbols_by_name,
                              &context->defined_cxx_symbols_by_value);
    require_noerr(rval, finish);
    
    rval = kxld_kext_export_linked_object(context->kext,
                                          (void *) linked_object,
                                          kmod_info_kern);
    require_noerr(rval, finish);
    *linked_object_out = linked_object;
    
    linked_object_alloc = NULL;
    
    rval = KERN_SUCCESS;
finish:
    if (linked_object_alloc) {
        kxld_page_free_untracked(linked_object_alloc, vmsize);
    }
    
    clear_context(context);
    kxld_set_logging_callback_data(NULL, NULL);
    
    return rval;
}
Exemple #18
0
void hb_buffer_add(hb_buffer_t * buffer, hb_codepoint_t codepoint,
		   unsigned int cluster)
{
	add(buffer, codepoint, cluster);
	clear_context(buffer, 1);
}
Exemple #19
0
av_cold void swr_close(SwrContext *s){
    clear_context(s);
}
bool PrologLoader :: LOAD (char * file_name) {
	bool ret;
	AREA command;
	ri = NULL;
	fi = NULL;
	drop_instructions ();
	if (root -> resource_loader != NULL) ri = root -> resource_loader -> load (file_name);
	if (ri == NULL) {
		fi = fopen (file_name, "rb");
		PrologString * root_directory = root -> search_directories;
		while (root_directory != NULL && fi == NULL) {
			sprintf (command, "%s%s", root_directory -> text, file_name);
			fi = fopen (command, "rb");
			root_directory = root_directory -> next;
		}
		if (fi == NULL) {
			ri = load_plugin_module (file_name);
			if (ri == 0) {message_v ("File not found: ", file_name); return false;}
		}
	}
	get_symbol ();
	PrologDirectory * import;
	clear_context ();
//	if (root != NULL) search_context = root -> root;
	PrologDirectory * user_directory = NULL;
	if (root != NULL) user_directory = root -> root;
	while (symbol_control == 11 && strcmp (root -> import_caption, symbol) == 0) {
		get_symbol ();
		switch (symbol_control) {
		case 8: if (root -> searchDirectoryNotFound (symbol)) root -> addSearchDirectory (symbol); break;
		case 11:
			import = root -> searchDirectory (symbol);
			if (import == NULL) {
				PrologLoader * loader = new PrologLoader (root);
				area_cat (command, 0, symbol);
				area_cat (command, ".prc");
				ret = loader -> load (command);
				delete loader;
				if (! ret) {message_v ("Module not loaded: ", command); close (); return false;}
				import = root -> searchDirectory (symbol);
			}
			if (import != NULL) search_context = import -> duplicate (search_context);
			break;
		default: message ("Syntax error: import module or search path expected."); close (); return false;
		}
		get_symbol ();
	}
	while (symbol_control == 31) {
		if (strcmp (symbol, "uap32") == 0) root -> set_uap32_captions ();
		if (strcmp (symbol, "standard") == 0) root -> set_standard_captions ();
		if (strcmp (symbol, "edinburg") == 0) root -> set_edinburg_captions ();
		if (strcmp (symbol, "marseille") == 0) root -> set_marseille_captions ();
		if (strcmp (symbol, "functional") == 0) root -> set_functional_captions ();
		get_symbol ();
	}
	if (symbol_control != 11 || strcmp (root -> program_caption, symbol) != 0) {message ("Syntax error: program header expected."); close (); return false;}
	get_symbol ();
	if (symbol_control != 11) {message ("Syntax error: program name expected."); close (); return false;}
	PROLOG_STRING program_name;
	prolog_string_copy (program_name, symbol);
	PrologServiceClass * service_class = NULL;
	if (reload) root -> drop (program_name);
	else if (root -> searchDirectory (program_name) != NULL) {close (); return true;}
	get_symbol ();
	PrologDirectory * directory;
	if (symbol_control == 11 && strcmp (root -> machine_caption, symbol) == 0) {
		get_symbol ();
		if (symbol_control != 11 || strcmp (root -> if_atom_caption, symbol) != 0) {
			message ("Syntax error: machine assignment expected in program header.");
			close ();
			return false;
		}
		get_symbol ();
		if (symbol_control != 8) {message ("Syntax error: service class name expected."); close (); return false;}
		service_class = root -> loadServiceClass (symbol);
		if (service_class == NULL) {message_v ("Service class crashed or not found: ", symbol); close (); return false;}
		get_symbol ();
		directory = root -> createDirectory (program_name, service_class);
	} else directory = root -> createDirectory (program_name);
	root -> auto_atoms = false;
	switch (symbol_control) {
	case 11:
		if (strcmp (root -> auto_atoms_caption, symbol) != 0) {
			message ("Syntax error: auto expected.");
			root -> drop ();
			close ();
			return false;
		}
		root -> auto_atoms = true;
		get_symbol ();
		break;
	case 6: get_symbol (); break;
	case 1:
		get_symbol ();
		while (symbol_control != 2) {
			switch (symbol_control) {
			case 11: root -> createAtom (symbol); break;
			case 21: root -> createAtom (symbol); break;
			default:
				message ("Syntax error: atom expected.");
				root -> drop ();
				close ();
				return false;
				break;
			}
			get_symbol ();
			if (strlen (root -> separator_caption) > 0) {
				if (symbol_control != 23 && symbol_control != 2) {
					message ("Syntax error: separator missing.");
					root -> drop ();
					close ();
					return false;
				}
				if (symbol_control == 23) get_symbol ();
			}
		}
		get_symbol ();
		break;
	default: message ("Syntax error: atome list expected."); root -> drop (); close (); return false;
	}
	//
	if (service_class != 0) service_class -> init (root, directory);
	if (directory != NULL) search_context = directory -> duplicate (search_context);
	PrologDirectory * dt = search_context;
	if (dt != NULL) {
		while (dt -> next != NULL) dt = dt -> next;
		dt -> next = user_directory;
	}
//	message (file_name);
//	dt = search_context;
//	while (dt != NULL) {message (dt -> directoryName); dt = dt -> next;}
//	message ("===");
//	dt = root -> root;
//	while (dt != NULL) {message (dt -> directoryName); dt = dt -> next;}
//	message ("");
	//
	PrologElement * clause = NULL;
	PrologAtom * atom = NULL;
	PrologNativeCode * native_code = NULL;
	PrologResolution * resolution = NULL;
	PrologAtom * preprocessor = NULL;
	PrologDirectory * preprocessor_directory;
	while (true) {
		switch (symbol_control) {
		case 11:
			if (strcmp (root -> machine_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control != 11) {
					message ("Syntax error: atom expected.");
					root -> drop ();
					close ();
					return false;
				}
				atom = searchAtomC (symbol); //root -> search (symbol);
				if (atom == NULL) {
					message_v ("Unknown atom: ", symbol);
					root -> drop ();
					close ();
					return false;
				}
				if (atom -> getMachine () != 0) {
					message_v ("Atom has already machine code attached: ", symbol);
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				if (symbol_control != 11 || strcmp (root -> if_atom_caption, symbol) != 0) {
					message ("Syntax error: machine assignment expected.");
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				if (symbol_control != 8) {
					message ("Syntax error: machine name expected.");
					root -> drop ();
					close ();
					return false;
				}
				if (service_class == NULL) {
					message ("Service class missing.");
					root -> drop ();
					close ();
					return false;
				}
				native_code = service_class -> getNativeCode (symbol);
				if (native_code == NULL) {
					message_v ("Unknown native class: ", symbol);
					root -> drop ();
					close ();
					return false;
				}
				atom -> setMachine (native_code);
				get_symbol ();
				break;
			}
//		case 11:
			if (strcmp (root -> end_caption, symbol) == 0) {
				get_symbol ();
				clause = NULL;
				if (symbol_control == 11 && strcmp (root -> if_atom_caption, symbol) == 0) {
					clause = readElement ();
					if (clause == NULL) {
						// suspiciouse drop 1
						root -> drop ();
						close ();
						return false;
					}
					get_symbol ();
				}
				if (symbol_control == 21) {
					if (echo) message ("");
					root -> close ();
					if (clause != 0) instructions = clause;
					close ();
					return true;
				}
				message ("Syntax error: dot expected.");
				root -> drop ();
				close ();
				return false;
			}
			if (strcmp (root -> protect_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control == 6) {get_symbol (); break;}
				if (symbol_control != 1) {
					message ("Syntax error: atome list expected.");
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				while (symbol_control != 2) {
					if (symbol_control != 11) {
						message ("Syntax error: atom expected.");
						root -> drop ();
						close ();
						return false;
					}
					if (! root -> Protect (symbol)) {
						root -> message ("Can not protect unknown atom:", symbol);
						root -> drop ();
						close ();
						return false;
					}
					get_symbol ();
					if (strlen (root -> separator_caption) > 0) {
						if (symbol_control != 23 && symbol_control != 2) {
							message ("Syntax error: separator missing.");
							root -> drop ();
							close ();
							return false;
						}
						if (symbol_control == 23) get_symbol ();
					}
				}
				get_symbol ();
				break;
			}
			if (strcmp (root -> private_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control == 6) {get_symbol (); break;}
				if (symbol_control != 1) {
					message ("Syntax error: atome list expected.");
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				while (symbol_control != 2) {
					if (symbol_control != 11) {
						message ("Syntax error: atom expected.");
						root -> drop ();
						close ();
						return false;
					}
					if (! root -> Private (symbol)) {
						root -> message ("Can not lock unknown atom as private:", symbol);
						root -> drop ();
						close ();
						return false;
					}
					get_symbol ();
					if (strlen (root -> separator_caption) > 0) {
						if (symbol_control != 23 && symbol_control != 2) {
							message ("Syntax error: separator missing.");
							root -> drop ();
							close ();
							return false;
						}
						if (symbol_control == 23) get_symbol ();
					}
				}
				get_symbol ();
				break;
			}
			if (strcmp (root -> preprocessor_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control != 11 && strcmp (root -> if_atom_caption, symbol) != 0) {
					message ("Syntax error: preprocessor assignment expected.");
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				if (symbol_control == 6) {
//					directory -> setPreprocessor (NULL);
					preprocessor = NULL;
					get_symbol ();
					break;
				}
				if (symbol_control != 11) {
					if (symbol_control == 22) {
						get_symbol ();
						if (symbol_control != 11) {
							message ("Syntax error: directory name expected in qualified preprocessor name.");
							root -> drop ();
							close ();
							return false;
						}
						preprocessor_directory = root -> searchDirectory (symbol);
						if (preprocessor_directory == NULL) {
							message_v ("Directory not found in qualified preprocessor name:", symbol);
							root -> drop ();
							close ();
							return false;
						}
						get_symbol ();
						if (symbol_control != 21) {
							message ("Syntax error: dot expected in qualified preprocessor name.");
							root -> drop ();
							close ();
							return false;
						}
						get_symbol ();
						if (symbol_control != 11) {
							message ("Syntax error: qualified preprocessor name expected.");
							root -> drop ();
							close ();
							return false;
						}
						atom = preprocessor_directory -> searchAtom (symbol);
					} else {
						message ("Syntax error: atom expected.");
						root -> drop ();
						close ();
						return false;
					}
				} else {
					atom = searchAtom (symbol); //root -> search (symbol);
				}
				if (atom == NULL) {
					message_v ("Unknown atom: ", symbol);
					root -> drop ();
					close ();
					return false;
				}
//				directory -> setPreprocessor (atom);
				preprocessor = atom;
				get_symbol ();
				break;
			}
			if (strcmp (root -> auto_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control != 11 && strcmp (root -> if_atom_caption, symbol) != 0) {
					message ("Syntax error: auto assignment expected.");
					root -> drop ();
					close ();
					return false;
				}
				clause = readElement ();
				// suspicious drop 2
				if (clause == NULL) {root -> drop (); close (); return false;}
				clause = root -> pair (root -> head (NULL), clause);
				//root -> resolution (clause);
				resolution = new PrologResolution (root);
				resolution -> resolution (clause);
				delete resolution;
				delete clause;
				get_symbol ();
				break;
			}
		case 1:
//			atom = root -> getPreprocessor ();
			if (preprocessor != NULL) {
				clause = readElement ();
				if (clause == NULL) {root -> drop (); close (); return false;}
				clause = readRightSide (clause, false);
				if (clause == NULL) {root -> drop (); close (); return false;}
				get_symbol ();
				clause = root -> pair (root -> var (0), root -> pair (root -> pair (root -> atom (preprocessor), root -> pair (clause, root -> earth ())), root -> earth ()));
				resolution = new PrologResolution (root);
				resolution -> resolution (clause);
				delete resolution;
				delete clause;
				break;
			}
			clause = readClause ();
			get_symbol ();
			// suspicious drop 3
			if (clause == NULL) {root -> drop (); close (); return false;}
			if (root -> attachClause (clause) == 0) break;
			// suspicious drop 4
			root -> drop ();
			close ();
			return false;
		default: message ("Syntax error: at least clause expected."); root -> drop (); close (); return false;
		}
	}
}
Exemple #21
0
kern_return_t
kxld_link_split_file(
    KXLDContext       * context,
    splitKextLinkInfo *link_info,
    const char        * name,
    void              * callback_data,
    KXLDDependency    * dependencies,
    u_int               ndependencies,
    kxld_addr_t       * kmod_info_kern)
{
    kern_return_t       rval                    = KERN_FAILURE;
    KXLDObject *        kext_object             = NULL;
    splitKextLinkInfo * my_link_info            = NULL;

    isSplitKext = (link_info->vmaddr_TEXT_EXEC != 0);
    isOldInterface = FALSE;

    kxld_set_logging_callback_data(name, callback_data);

    kxld_log(kKxldLogLinking, kKxldLogBasic, "Linking kext %s", name);

    kaslr_offsets_count = 0;
    kaslr_offsets_index = 0;
    kaslr_offsets = NULL;

    require_action(context, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(link_info, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(dependencies, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(ndependencies, finish, rval=KERN_INVALID_ARGUMENT);
    require_action(kmod_info_kern, finish, rval=KERN_INVALID_ARGUMENT);
    
    rval = init_context(context, ndependencies);
    require_noerr(rval, finish);
    
    rval = init_kext_objects(context,
                             link_info->kextExecutable,
                             link_info->kextSize,
                             name,
                             dependencies, ndependencies);
    require_noerr(rval, finish);
    
    kext_object = get_object_for_file(context,
                                      link_info->kextExecutable,
                                      link_info->kextSize,
                                      name);
    require_action(kext_object, finish, rval=KERN_FAILURE);
    
    // copy vmaddrs and fileoffsets for split segments into kext_object
    kxld_object_set_link_info(kext_object, link_info);

    my_link_info = kxld_object_get_link_info(kext_object);
    
    rval = allocate_split_kext(context, my_link_info);
    require_noerr(rval, finish);
    
#if SPLIT_KEXTS_DEBUG
    kxld_log(kKxldLogLinking, kKxldLogErr, "Linking kext %s", name);
    kxld_show_split_info(link_info);
#endif // SPLIT_KEXTS_DEBUG
    
    rval = kxld_kext_relocate(context->kext,
                              (kxld_addr_t)my_link_info,
                              &context->vtables_by_name,
                              &context->defined_symbols_by_name,
                              &context->obsolete_symbols_by_name,
                              &context->defined_cxx_symbols_by_value);
    require_noerr(rval, finish);
    
    rval = kxld_kext_export_linked_object(context->kext,
                                          (void *) my_link_info,
                                          kmod_info_kern);
    require_noerr(rval, finish);
    
    // pass back info about linked kext
    link_info->kaslr_offsets_count = kaslr_offsets_count;
    link_info->kaslr_offsets = kaslr_offsets;
    link_info->linkedKext = my_link_info->linkedKext;
    link_info->linkedKextSize = my_link_info->linkedKextSize;

    if (kaslr_offsets_count != kaslr_offsets_index) {
        kxld_log(kKxldLogLinking, kKxldLogErr, "[ERROR] %s: KASLR pointers: count=%d, but only populated %d!", name, kaslr_offsets_count, kaslr_offsets_index);
        rval = KERN_FAILURE;
        goto finish;
    }

    // the values are now the responsibility of the caller
    kaslr_offsets_count = 0;
    kaslr_offsets_index = 0;
    kaslr_offsets = NULL;

    rval = KERN_SUCCESS;
finish:
    clear_context(context);
    kxld_set_logging_callback_data(NULL, NULL);
    
    return rval;
}
Exemple #22
0
av_cold int swr_init(struct SwrContext *s){
    int ret;
    char l1[1024], l2[1024];

    clear_context(s);

    if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
        av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt);
        return AVERROR(EINVAL);
    }
    if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
        av_log(s, AV_LOG_ERROR, "Requested output sample format %d is invalid\n", s->out_sample_fmt);
        return AVERROR(EINVAL);
    }

    s->out.ch_count  = s-> user_out_ch_count;
    s-> in.ch_count  = s->  user_in_ch_count;
    s->used_ch_count = s->user_used_ch_count;

    s-> in_ch_layout = s-> user_in_ch_layout;
    s->out_ch_layout = s->user_out_ch_layout;

    s->int_sample_fmt= s->user_int_sample_fmt;

    if(av_get_channel_layout_nb_channels(s-> in_ch_layout) > SWR_CH_MAX) {
        av_log(s, AV_LOG_WARNING, "Input channel layout 0x%"PRIx64" is invalid or unsupported.\n", s-> in_ch_layout);
        s->in_ch_layout = 0;
    }

    if(av_get_channel_layout_nb_channels(s->out_ch_layout) > SWR_CH_MAX) {
        av_log(s, AV_LOG_WARNING, "Output channel layout 0x%"PRIx64" is invalid or unsupported.\n", s->out_ch_layout);
        s->out_ch_layout = 0;
    }

    switch(s->engine){
#if CONFIG_LIBSOXR
        extern struct Resampler const soxr_resampler;
        case SWR_ENGINE_SOXR: s->resampler = &soxr_resampler; break;
#endif
        case SWR_ENGINE_SWR : s->resampler = &swri_resampler; break;
        default:
            av_log(s, AV_LOG_ERROR, "Requested resampling engine is unavailable\n");
            return AVERROR(EINVAL);
    }

    if(!s->used_ch_count)
        s->used_ch_count= s->in.ch_count;

    if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){
        av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
        s-> in_ch_layout= 0;
    }

    if(!s-> in_ch_layout)
        s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count);
    if(!s->out_ch_layout)
        s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);

    s->rematrix= s->out_ch_layout  !=s->in_ch_layout || s->rematrix_volume!=1.0 ||
                 s->rematrix_custom;

    if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){
        if(av_get_planar_sample_fmt(s->in_sample_fmt) <= AV_SAMPLE_FMT_S16P){
            s->int_sample_fmt= AV_SAMPLE_FMT_S16P;
        }else if(   av_get_planar_sample_fmt(s-> in_sample_fmt) == AV_SAMPLE_FMT_S32P
                 && av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P
                 && !s->rematrix
                 && s->engine != SWR_ENGINE_SOXR){
            s->int_sample_fmt= AV_SAMPLE_FMT_S32P;
        }else if(av_get_planar_sample_fmt(s->in_sample_fmt) <= AV_SAMPLE_FMT_FLTP){
            s->int_sample_fmt= AV_SAMPLE_FMT_FLTP;
        }else{
            av_log(s, AV_LOG_DEBUG, "Using double precision mode\n");
            s->int_sample_fmt= AV_SAMPLE_FMT_DBLP;
        }
    }

    if(   s->int_sample_fmt != AV_SAMPLE_FMT_S16P
        &&s->int_sample_fmt != AV_SAMPLE_FMT_S32P
        &&s->int_sample_fmt != AV_SAMPLE_FMT_FLTP
        &&s->int_sample_fmt != AV_SAMPLE_FMT_DBLP){
        av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, S16/S32/FLT/DBL is supported\n", av_get_sample_fmt_name(s->int_sample_fmt));
        return AVERROR(EINVAL);
    }

    set_audiodata_fmt(&s-> in, s-> in_sample_fmt);
    set_audiodata_fmt(&s->out, s->out_sample_fmt);

    if (s->firstpts_in_samples != AV_NOPTS_VALUE) {
        if (!s->async && s->min_compensation >= FLT_MAX/2)
            s->async = 1;
        s->firstpts =
        s->outpts   = s->firstpts_in_samples * s->out_sample_rate;
    } else
        s->firstpts = AV_NOPTS_VALUE;

    if (s->async) {
        if (s->min_compensation >= FLT_MAX/2)
            s->min_compensation = 0.001;
        if (s->async > 1.0001) {
            s->max_soft_compensation = s->async / (double) s->in_sample_rate;
        }
    }

    if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){
        s->resample = s->resampler->init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_size, s->phase_shift, s->linear_interp, s->cutoff, s->int_sample_fmt, s->filter_type, s->kaiser_beta, s->precision, s->cheby);
        if (!s->resample) {
            av_log(s, AV_LOG_ERROR, "Failed to initilaize resampler\n");
            return AVERROR(ENOMEM);
        }
    }else
        s->resampler->free(&s->resample);
    if(    s->int_sample_fmt != AV_SAMPLE_FMT_S16P
        && s->int_sample_fmt != AV_SAMPLE_FMT_S32P
        && s->int_sample_fmt != AV_SAMPLE_FMT_FLTP
        && s->int_sample_fmt != AV_SAMPLE_FMT_DBLP
        && s->resample){
        av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16/s32/flt/dbl\n");
        ret = AVERROR(EINVAL);
        goto fail;
    }

#define RSC 1 //FIXME finetune
    if(!s-> in.ch_count)
        s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
    if(!s->used_ch_count)
        s->used_ch_count= s->in.ch_count;
    if(!s->out.ch_count)
        s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout);

    if(!s-> in.ch_count){
        av_assert0(!s->in_ch_layout);
        av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n");
        ret = AVERROR(EINVAL);
        goto fail;
    }

    av_get_channel_layout_string(l1, sizeof(l1), s-> in.ch_count, s-> in_ch_layout);
    av_get_channel_layout_string(l2, sizeof(l2), s->out.ch_count, s->out_ch_layout);
    if (s->out_ch_layout && s->out.ch_count != av_get_channel_layout_nb_channels(s->out_ch_layout)) {
        av_log(s, AV_LOG_ERROR, "Output channel layout %s mismatches specified channel count %d\n", l2, s->out.ch_count);
        ret = AVERROR(EINVAL);
        goto fail;
    }
    if (s->in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s->in_ch_layout)) {
        av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->used_ch_count);
        ret = AVERROR(EINVAL);
        goto fail;
    }

    if ((!s->out_ch_layout || !s->in_ch_layout) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) {
        av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s "
               "but there is not enough information to do it\n", l1, l2);
        ret = AVERROR(EINVAL);
        goto fail;
    }

av_assert0(s->used_ch_count);
av_assert0(s->out.ch_count);
    s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0;

    s->in_buffer= s->in;
    s->silence  = s->in;
    s->drop_temp= s->out;

    if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){
        s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt,
                                                   s-> in_sample_fmt, s-> in.ch_count, NULL, 0);
        return 0;
    }

    s->in_convert = swri_audio_convert_alloc(s->int_sample_fmt,
                                             s-> in_sample_fmt, s->used_ch_count, s->channel_map, 0);
    s->out_convert= swri_audio_convert_alloc(s->out_sample_fmt,
                                             s->int_sample_fmt, s->out.ch_count, NULL, 0);

    if (!s->in_convert || !s->out_convert) {
        ret = AVERROR(ENOMEM);
        goto fail;
    }

    s->postin= s->in;
    s->preout= s->out;
    s->midbuf= s->in;

    if(s->channel_map){
        s->postin.ch_count=
        s->midbuf.ch_count= s->used_ch_count;
        if(s->resample)
            s->in_buffer.ch_count= s->used_ch_count;
    }
    if(!s->resample_first){
        s->midbuf.ch_count= s->out.ch_count;
        if(s->resample)
            s->in_buffer.ch_count = s->out.ch_count;
    }

    set_audiodata_fmt(&s->postin, s->int_sample_fmt);
    set_audiodata_fmt(&s->midbuf, s->int_sample_fmt);
    set_audiodata_fmt(&s->preout, s->int_sample_fmt);

    if(s->resample){
        set_audiodata_fmt(&s->in_buffer, s->int_sample_fmt);
    }

    if ((ret = swri_dither_init(s, s->out_sample_fmt, s->int_sample_fmt)) < 0)
        goto fail;

    if(s->rematrix || s->dither.method) {
        ret = swri_rematrix_init(s);
        if (ret < 0)
            goto fail;
    }

    return 0;
fail:
    swr_close(s);
    return ret;

}
Exemple #23
0
/*to unroll the original c++, could have used a macro
  ASSEMBLY:maybe worth to be unrolled to fine tuned assembly*/
static void hb_buffer_add_utf(hb_buffer_t * buffer, struct utf *utf, void *text,
			      int text_length, unsigned item_offset,
			      int item_length)
{
	void *next;
	void *end;

	assert(buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE ||
	       (!buffer->len
		&& buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID));

	if (hb_atomic_int32_get(&buffer->ref_cnt) == REF_CNT_INVALID_VAL)
		return;

	if (text_length == -1)
		text_length = utf->len(text);

	if (item_length == -1)
		item_length = text_length - item_offset;

	ensure(buffer, buffer->len + item_length * utf->bytes_n / 4);

	/*If buffer is empty and pre-context provided, install it.
	   This check is written this way, to make sure people can
	   provide pre-context in one add_utf() call, then provide
	   text in a follow-up call.  See:

	   https://bugzilla.mozilla.org/show_bug.cgi?id=801410#c13 */
	if (!buffer->len && item_offset > 0) {
		void *prev;
		void *start;

		/*Add pre-context */
		clear_context(buffer, 0);
		prev = utf->ptr_offset(text, item_offset);
		start = text;
		while (start < prev
		       && buffer->context_len[0] < HB_BUFFER_CONTEXT_LENGTH) {
			hb_codepoint_t u;
			prev = utf->prev(prev, start, &u);
			buffer->context[0][buffer->context_len[0]++] = u;
		}
	}

	next = utf->ptr_offset(text, item_offset);
	end = utf->ptr_offset(next, item_length);
	while (next < end) {
		hb_codepoint_t u;
		void *old_next;

		old_next = next;
		next = utf->next(next, end, &u);
		add(buffer, u, utf->diff(old_next, text));
	}

	/*Add post-context */
	clear_context(buffer, 1);
	end = utf->ptr_offset(text, text_length);
	while (next < end && buffer->context_len[1] < HB_BUFFER_CONTEXT_LENGTH) {
		hb_codepoint_t u;

		next = utf->next(next, end, &u);
		buffer->context[1][buffer->context_len[1]++] = u;
	}

	buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE;
}