예제 #1
0
파일: thread.c 프로젝트: amir9/longene
/*
 * user_thread_startup
 * prepare for jumping to userspace to execute after new thread waken
 */
VOID
STDCALL
user_thread_startup(PKSTART_ROUTINE StartRoutine,
		PVOID StartContext)
{
	struct ethread  *thread;
	PKAPC   thread_apc;
	void * start_stack;

	ktrace("pid %x, tgid %x\n",current->pid, current->tgid);

	if (!(thread = get_current_ethread())) {
		return;
	}

	/* create dummy file */
	create_dummy_file(thread->threads_process->win32process);

	if (!(thread_apc = kmalloc(sizeof(struct kapc),GFP_KERNEL))) {
		return;
	}

	start_stack = (void *)thread->tcb.stack_base; /* user stack base */

	if (thread->threads_process->fork_in_progress) {
		apc_init(thread_apc,
				&thread->tcb,
				OriginalApcEnvironment,
				thread_special_apc,
				NULL,
				(PKNORMAL_ROUTINE)get_ntdll_entry(),
				UserMode,
				start_stack);
		insert_queue_apc(thread_apc, 
				(void *)get_interp_entry(), 
				thread->threads_process->spare0[0], 
				IO_NO_INCREMENT);

		thread->threads_process->fork_in_progress = NULL;
	} else {
		apc_init(thread_apc,
				&thread->tcb,
				OriginalApcEnvironment,
				thread_special_apc,
				NULL,
				(PKNORMAL_ROUTINE)get_thread_entry(),
				UserMode,
				start_stack);
		insert_queue_apc(thread_apc, NULL,NULL, IO_NO_INCREMENT);
	}
	thread->tcb.apc_state.uapc_pending = 1;
	set_tsk_thread_flag(current, TIF_APC);

	try_module_get(THIS_MODULE);

	return;
} /* end user_thread_startup */
예제 #2
0
int main(int argc, const char *const * argv)
{
    apr_pool_t *pool;
    apr_file_t *fd;
    apr_xml_parser *parser;
    apr_xml_doc *doc;
    apr_status_t rv;
    char errbuf[2000];
    char errbufXML[2000];

    (void) apr_initialize();
    apr_pool_create(&pool, NULL);
    progname = argv[0];
    if (argc == 1) {
        rv = create_dummy_file(pool, &fd);
        if (rv != APR_SUCCESS) {
            oops("cannot create dummy file", "oops", rv);
        }
    }
    else {
        if (argc == 2) {
            rv = apr_file_open(&fd, argv[1], APR_READ, APR_OS_DEFAULT, pool);
            if (rv != APR_SUCCESS) {
                oops("cannot open: %s", argv[1], rv);
            }
        }
        else {
            oops("usage: %s", usage, 0);
        }
    }
    rv = apr_xml_parse_file(pool, &parser, &doc, fd, 2000);
    if (rv != APR_SUCCESS) {
        fprintf(stderr, "APR Error %s\nXML Error: %s\n",
                apr_strerror(rv, errbuf, sizeof(errbuf)),
             apr_xml_parser_geterror(parser, errbufXML, sizeof(errbufXML)));
        return rv;
    }
    dump_xml(doc->root, 0);
    apr_file_close(fd);
    if (argc == 1) {
        rv = create_dummy_file_error(pool, &fd);
        if (rv != APR_SUCCESS) {
            oops("cannot create error dummy file", "oops", rv);
        }
        rv = apr_xml_parse_file(pool, &parser, &doc, fd, 2000);
        if (rv != APR_SUCCESS) {
            fprintf(stdout, "APR Error %s\nXML Error: %s "
                            "(EXPECTED) This is good.\n",
                    apr_strerror(rv, errbuf, sizeof(errbuf)),
             apr_xml_parser_geterror(parser, errbufXML, sizeof(errbufXML)));
             rv = APR_SUCCESS; /* reset the return code, as the test is supposed to get this error */
        }
        else {
            fprintf(stderr, "Expected an error, but didn't get one ;( ");
            return APR_EGENERAL;
        }
    }
    apr_pool_destroy(pool);
    apr_terminate();
    return rv;
}