Пример #1
0
status_t
init_hardware(void)
{
	// Return B_OK if a device supported by this driver is found; otherwise,
	// return B_ERROR so the driver will be unloaded.

	if (get_module(B_PCI_MODULE_NAME, (module_info**)&gPCI) != B_OK)
		return B_ERROR;		// unable to access PCI bus

	// Check pci devices for a device supported by this driver.

	uint32 pciIndex = 0;
	pci_info pciInfo;
	const ChipInfo* pDevice = GetNextSupportedDevice(pciIndex, pciInfo);

	TRACE("init_hardware() - %s\n",
		pDevice == NULL ? "no supported devices" : "device supported");

	put_module(B_PCI_MODULE_NAME);		// put away the module manager

	return (pDevice == NULL ? B_ERROR : B_OK);
}
Пример #2
0
status_t
init_driver(void)
{
	sOpenCount = 0;

	status_t status = get_module(B_ACPI_MODULE_NAME, (module_info**)&sAcpi);
	if (status < B_OK)
		return status;

	acpi_hpet *hpetTable;
	status = sAcpi->get_table(ACPI_HPET_SIGNATURE, 0,
		(void**)&hpetTable);
	
	if (status != B_OK) {
		put_module(B_ACPI_MODULE_NAME);
		return status;
	}

	sHPETArea = map_physical_memory("HPET registries",
					hpetTable->hpet_address.address,
					B_PAGE_SIZE,
					B_ANY_KERNEL_ADDRESS,
					B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA,
					(void**)&sHPETRegs);

	if (sHPETArea < 0) {
		put_module(B_ACPI_MODULE_NAME);	
		return sHPETArea;
	}

	status = hpet_init();
	if (status != B_OK) {
		delete_area(sHPETArea);
		put_module(B_ACPI_MODULE_NAME);
	}

	return status;
}
Пример #3
0
extern "C" status_t
init_driver(void)
{
	char path[B_PATH_NAME_LENGTH];
	pci_info info;
	long i;

	if (get_module(B_PCI_MODULE_NAME, (module_info**)&gPci) != B_OK)
		return ENODEV;

	gNumCards = 0;

	for (i = 0; gPci->get_nth_pci_info(i, &info) == B_OK
			&& gNumCards < MAX_CARDS; i++) {
		if ((info.vendor_id == AMD_VENDOR_ID
			&& info.device_id == AMD_CS5536_AUDIO_DEVICE_ID)
			|| (info.vendor_id == NS_VENDOR_ID
				&& info.device_id == NS_CS5535_AUDIO_DEVICE_ID)) {
			memset(&gCards[gNumCards], 0, sizeof(geode_controller));
			gCards[gNumCards].pci_info = info;
			gCards[gNumCards].opened = 0;
			sprintf(path, DEVFS_PATH_FORMAT, gNumCards);
			gCards[gNumCards++].devfs_path = strdup(path);

			dprintf("geode: detected controller @ PCI:%d:%d:%d, IRQ:%d, type %04x/%04x\n",
				info.bus, info.device, info.function,
				info.u.h0.interrupt_line,
				info.vendor_id, info.device_id);
		}
	}

	if (gNumCards == 0) {
		put_module(B_PCI_MODULE_NAME);
		return ENODEV;
	}

	return B_OK;
}
Пример #4
0
int
main(int argc, char *argv[])
{
	if (argc < 2)
		return (-1);

	const char *mod = argv[1];	
	int fd = -1;

	init_modules();
	polysome *p = get_module(mod);
	if (p == NULL) {
		printf("%s invalid\n", mod);
	} else {
		printf("%s valid\n", p->name);
		ovvar_t ov;
		memset(&ov, 0, sizeof(ov));

		init_ov(&ov);
		printf("path %s\n", ov.path);
		
		p->ss(&ov);
		printf("path %s be read\n", ov.fpath);
		printf("ov.a: %d, ov.b: %d\n", ov.a, ov.b);
		p->gs(&ov);

		for (rci_t i = 0; i < (ov.a + ov.b); i ++)
			printf("%ld ", ov.signature[i]);

		printf("\n");

		free_ov(&ov);
	}

	free_modules();

	return (0);
}
Пример #5
0
static void
scan_modules(const char* path)
{
	void* cookie = open_module_list(path);
	if (cookie == NULL)
		return;

	while (true) {
		char name[B_FILE_NAME_LENGTH];
		size_t length = sizeof(name);
		if (read_next_module_name(cookie, name, &length) != B_OK)
			break;

		TRACE(("scan %s\n", name));

		module_info* module;
		if (get_module(name, &module) == B_OK) {
			// we don't need the module right now, but we give it a chance
			// to register itself
			put_module(name);
		}
	}
}
Пример #6
0
void init_ext_module(void)
{
    /* initial state */
    int i;
    connected_module=0;
    for(i=0;i<NB_EXT_MODULES;i++)
        actions_array[i]=NULL;
        
    if( 1 
#ifdef HAVE_FM_REMOTE   
    && !FM_is_connected()
#endif
     && !kFWIsConnected()
    )
    {
        connected_module=get_module();        
    }
    else
        connected_module=AV_MODULE_NONE;

        
    printk("[init] external module (connected: %s)\n",module_name[connected_module]); 
}
Пример #7
0
status_t init_driver(void) {
    /* get a handle for the pci bus */
    if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci_bus) != B_OK)
        return B_ERROR;

    /* driver private data */
    pd = (DeviceData *)calloc(1, sizeof(DeviceData));
    if (!pd) {
        put_module(B_PCI_MODULE_NAME);
        return B_ERROR;
    }
    /* initialize the benaphore */
    INIT_BEN(pd->kernel);

    /* find all of our supported devices */
    et6000ProbeDevices();

#if DEBUG > 0
    add_debugger_command("et6000dump", et6000dump, "dump ET6000 kernel driver persistant data");
#endif

    return B_OK;
}
status_t
init_driver(void)
{
	status_t err = ENOMEM;
	FENTRY();

	err = get_module(OSS_CORE_MODULE_NAME, (module_info **)&gOSSCore);
	if (err < B_OK)
		goto err1;
	err = gOSSCore->init_osscore();
	dprintf("oss:init_osscore: 0x%08lx\n", err);
	if (err < B_OK)
		goto err2;
	err = gOSSCore->oss_load_drivers();
	err = B_OK;
	FEXITR(err);
	return err;
	
err2:
	put_module(OSS_CORE_MODULE_NAME);
err1:
	FEXITR(err);
	return err;
}
Пример #9
0
status_t
init_hardware()
{
    TRACE_ALWAYS("SiS19X:init_hardware()\n");
    status_t result = get_module(B_PCI_MODULE_NAME, (module_info**)&gPCIModule);
    if (result < B_OK) {
        return ENOSYS;
    }

    pci_info info = {0};
    for (long i = 0; B_OK == (*gPCIModule->get_nth_pci_info)(i, &info); i++) {
        for (size_t idx = 0; idx < _countof(cardInfos); idx++) {
            if (CARDID(info.vendor_id, info.device_id) == cardInfos[idx].Id()) {
                TRACE_ALWAYS("Found:%s %#010x\n",
                             cardInfos[idx].Description(), cardInfos[idx].Id());
                put_module(B_PCI_MODULE_NAME);
                return B_OK;
            }
        }
    }

    put_module(B_PCI_MODULE_NAME);
    return ENODEV;
}
Пример #10
0
void cacheex_push_out(struct s_client *cl, ECM_REQUEST *er) {
	int32_t res = 0, stats = -1;
	struct s_reader *reader = cl->reader;
	struct s_module *module = get_module(cl);
	// cc-nodeid-list-check
	if(reader)
	{
		if(reader->ph.c_cache_push_chk && !reader->ph.c_cache_push_chk(cl, er))
			return;
		res = reader->ph.c_cache_push(cl, er);
		stats = cacheex_add_stats(cl, er->caid, er->srvid, er->prid, 0);
	}
	else
	{
		if(module->c_cache_push_chk && !module->c_cache_push_chk(cl, er))
			return;
		res = module->c_cache_push(cl, er);
	}
	debug_ecm(D_CACHEEX, "pushed ECM %s to %s res %d stats %d", buf, username(cl), res, stats);
	cl->cwcacheexpush++;
	if(cl->account)
		{ cl->account->cwcacheexpush++; }
	first_client->cwcacheexpush++;
}
Пример #11
0
status_t
init_hardware(void)
{
	int ix = 0;
	pci_info info;

	memset(cards, 0, sizeof(ice1712) * NUM_CARDS);
	TRACE("@@init_hardware()\n");

	if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci))
		return ENOSYS;

	while ((*pci->get_nth_pci_info)(ix, &info) == B_OK) {
		if ((info.vendor_id == ICE1712_VENDOR_ID) &&
			(info.device_id == ICE1712_DEVICE_ID)) {
			TRACE("Found at least 1 card\n");
			put_module(B_PCI_MODULE_NAME);
			return B_OK;
		}
		ix++;
	}
	put_module(B_PCI_MODULE_NAME);
	return ENODEV;
}
Пример #12
0
status_t
init_hardware()
{
	dprintf("sis7018:init_hardware:ver:%s\n", kVersion);
	status_t result = get_module(B_PCI_MODULE_NAME, (module_info **)&gPCI);
	if (result < B_OK) {
		return ENOSYS;
	}

	pci_info info = {0};
	for (long i = 0; B_OK == (*gPCI->get_nth_pci_info)(i, &info); i++) {
		for (size_t idx = 0; idx < _countof(cardInfos); idx++) {
			if (info.vendor_id == cardInfos[idx].VendorId() &&
				info.device_id == cardInfos[idx].DeviceId())
			{
				put_module(B_PCI_MODULE_NAME);
				return B_OK;
			}
		}
	}

	put_module(B_PCI_MODULE_NAME);
	return ENODEV;
}
Пример #13
0
char * sprint_window (char *buffer, size_t max_ln, HWND hwnd, const char *msg)
{
    char sClassName[200]; sClassName[0] = 0;
    GetClassName(hwnd, sClassName, sizeof sClassName);

    char sFileName[200]; sFileName[0] = 0;
    get_module(hwnd, sFileName, sizeof sFileName);

    char caption[128]; caption[0] = 0;
    GetWindowText(hwnd, caption, sizeof caption);

    sprintf_s(buffer, max_ln,

#ifdef BBLEANSKIN_ENG32
        "%s window/32 with title \"%s\"\r\n\t%s:%s"
#else
        "%s window with title \"%s\"\r\n\t%s:%s"
#endif
        //" - %08x %08x"
        , msg, caption, sFileName, sClassName
        //, GetWindowLongPtr(hwnd, GWL_STYLE), GetWindowLongPtr(hwnd, GWL_EXSTYLE),
        );
    return buffer;
}
Пример #14
0
static void
event_nick(irc_session_t *session, const char *event, const char *old_nick,
		const char **params, unsigned int count) {
	const char *new_nick = params[0];
	if (count < 1) {
		return;
	}
	irc_t *irc = get_module(session);
	if (irc->current_nick && strcmp(irc->current_nick, old_nick)) {
		printf("(nick) %s -> %s\n", old_nick, new_nick);
	} else {
		if (irc->current_nick) {
			free(irc->current_nick);
		}
		irc->current_nick = strdup(new_nick);
		irc->module.name = irc->current_nick;
		if (debug) {
			printf("Nick changed: %s\n", new_nick);
		}
		if (irc_cmd_nick(session, irc->nick)) {
			fprintf(stderr, "irc: %s\n", irc_strerror(irc_errno(irc->session)));
		}
	}
}
Пример #15
0
void PROTOCOL_Load(int no_dlg)
{
    (void)no_dlg;
#ifdef MODULAR
    if(! PROTOCOL_HasModule(Model.protocol)) {
        *loaded_protocol = 0;
        return;
    }
    if(*loaded_protocol == Model.protocol)
        return;
    char file[25];
    strcpy(file, "protocol/");
    #define PROTODEF(proto, module, map, cmd, name) case proto: strcat(file,name); break;
    switch(Model.protocol) {
        #include "protocol.h"
        default: *loaded_protocol = 0; return;
    }
    #undef PROTODEF
    file[17] = '\0'; //truncate filename to 8 characters
    strcat(file, ".mod");
    FILE *fh;
    //We close the current font because on the dveo8 we reuse
    //the font filehandle to read the protocol.
    //Thatis necessary because we need to be able to load the
    //protocol while an ini file is open, and we don't want to
    //waste the RAM for an extra filehandle
    u8 old_font = LCD_SetFont(0);
    finit(&FontFAT, ""); //In case no fonts are loaded yet
    fh = fopen2(&FontFAT, file, "r");
    //printf("Loading %s: %08lx\n", file, fh);
    if(! fh) {
        if(! no_dlg) {
            sprintf(tempstring, "Misisng protocol:\n%s", file);
            PAGE_ShowWarning(NULL, tempstring);
        }
        LCD_SetFont(old_font);
        return;
    }
    setbuf(fh, 0);
    int size = 0;
    unsigned char buf[256];
    int len;
    char *ptr = (char *)loaded_protocol;
    while(size < 4096) {
        len = fread(buf, 1, 256, fh);
        if(len) {
            memcpy(ptr, buf, len);
            ptr += len;
        }
        size += len;
        if (len != 256)
            break;
    }
    fclose(fh);
    LCD_SetFont(old_font);
    if ((unsigned long)&_data_loadaddr != *loaded_protocol) {
        if(! no_dlg) {
            sprintf(tempstring, "Protocol Mismatch:\n%08x\n%08x", (unsigned long)&_data_loadaddr, *loaded_protocol);
            PAGE_ShowWarning(NULL, tempstring);
        }
        *loaded_protocol = 0;
        return;
    }
    //printf("Updated %d (%d) bytes: Data: %08lx %08lx %08lx\n", size, len, *loaded_protocol, *(loaded_protocol+1), *(loaded_protocol+2));
    //We use the same file for multiple protocols, so we need to manually set this here
    *loaded_protocol = Model.protocol;
#else
    if(! PROTOCOL_HasModule(Model.protocol)) {
        PROTO_Cmds = NULL;
        printf("Module is not defined!\n");
        return;
    }
    #define PROTODEF(proto, module, map, cmd, name) case proto: PROTO_Cmds = cmd; break;
    switch(Model.protocol) {
        #include "protocol.h"
        default: PROTO_Cmds = NULL;
    }
    #undef PROTODEF
#endif
    PROTOCOL_SetSwitch(get_module(Model.protocol));
}
Пример #16
0
void PROTOCOL_InitModules()
{
#if HAS_MULTIMOD_SUPPORT
    int error = 0;
    const char * missing[TX_MODULE_LAST];
    memset(missing, 0, sizeof(missing));

    if (PROTOCOL_SetSwitch(TX_MODULE_LAST) == 0) {
        //No Switch found
/*
        missing[MULTIMOD] = MODULE_NAME[MULTIMOD];
        for(int i = 0; i < MULTIMOD; i++) {
            if(Transmitter.module_enable[i].port == SWITCH_ADDRESS) {
                error = 1;
                printf("Disabling %s because switch wasn't found\n", MODULE_NAME[i]);
                missing[i] = MODULE_NAME[i];
                Transmitter.module_enable[i].port = 0;
            }
        }
*/
    }
    int orig_proto = Model.protocol;
    for(int i = 0; i < MULTIMOD; i++) {
        if(Transmitter.module_enable[i].port) {
            for(int j = 1; j < PROTOCOL_COUNT; j++) {
                if (get_module(j) == i) {
                    //Try this module
                    Model.protocol = j;
                    PROTOCOL_Load(1);
                    if (! PROTOCOL_LOADED)
                        continue;
                    int res = (long)PROTO_Cmds(PROTOCMD_RESET);
                    if (res == 0)
                        continue;
                    if (res < 0) {
                        error = 1;
                        missing[i] = MODULE_NAME[i];
                        if (! (Transmitter.extra_hardware & FORCE_MODULES))
                            Transmitter.module_enable[i].port = 0;
                    }
                    break;
                }
            } 
        }
    }
    //Put this last because the switch will not respond until after it has been initialized
    if (Transmitter.module_enable[MULTIMOD].port && PROTOCOL_SetSwitch(TX_MODULE_LAST) == 0) {
        //No Switch found
	error = 1;
        missing[MULTIMOD] = MODULE_NAME[MULTIMOD];
    }
    Model.protocol = orig_proto;
    if(error) {
        proto_state |= PROTO_MODULEDLG;
        PAGE_ShowModuleDialog(missing);
    } else
#endif //HAS_MULTIMOD_SUPPORT
    {
        PROTOCOL_Init(0);
    }
}
Пример #17
0
/* {{{ php_load_extension
 */
PHPAPI int php_load_extension(char *filename, int type, int start_now)
{
	void *handle;
	char *libpath;
	zend_module_entry *module_entry;
	zend_module_entry *(*get_module)(void);
	int error_type;
	char *extension_dir;

	if (type == MODULE_PERSISTENT) {
		extension_dir = INI_STR("extension_dir");
	} else {
		extension_dir = PG(extension_dir);
	}

	if (type == MODULE_TEMPORARY) {
		error_type = E_WARNING;
	} else {
		error_type = E_CORE_WARNING;
	}

	/* Check if passed filename contains directory separators */
	if (strchr(filename, '/') != NULL || strchr(filename, DEFAULT_SLASH) != NULL) {
		/* Passing modules with full path is not supported for dynamically loaded extensions */
		if (type == MODULE_TEMPORARY) {
			php_error_docref(NULL, E_WARNING, "Temporary module name should contain only filename");
			return FAILURE;
		}
		libpath = estrdup(filename);
	} else if (extension_dir && extension_dir[0]) {
		int extension_dir_len = (int)strlen(extension_dir);

		if (IS_SLASH(extension_dir[extension_dir_len-1])) {
			spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */
		} else {
			spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */
		}
	} else {
		return FAILURE; /* Not full path given or extension_dir is not set */
	}

	/* load dynamic symbol */
	handle = DL_LOAD(libpath);
	if (!handle) {
#if PHP_WIN32
		char *err = GET_DL_ERROR();
		if (err && (*err != '\0')) {
			php_error_docref(NULL, error_type, "Unable to load dynamic library '%s' - %s", libpath, err);
			LocalFree(err);
		} else {
			php_error_docref(NULL, error_type, "Unable to load dynamic library '%s' - %s", libpath, "Unknown reason");
		}
#else
		php_error_docref(NULL, error_type, "Unable to load dynamic library '%s' - %s", libpath, GET_DL_ERROR());
		GET_DL_ERROR(); /* free the buffer storing the error */
#endif
		efree(libpath);
		return FAILURE;
	}
	efree(libpath);

	get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "get_module");

	/* Some OS prepend _ to symbol names while their dynamic linker
	 * does not do that automatically. Thus we check manually for
	 * _get_module. */

	if (!get_module) {
		get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "_get_module");
	}

	if (!get_module) {
		if (DL_FETCH_SYMBOL(handle, "zend_extension_entry") || DL_FETCH_SYMBOL(handle, "_zend_extension_entry")) {
			DL_UNLOAD(handle);
			php_error_docref(NULL, error_type, "Invalid library (appears to be a Zend Extension, try loading using zend_extension=%s from php.ini)", filename);
			return FAILURE;
		}
		DL_UNLOAD(handle);
		php_error_docref(NULL, error_type, "Invalid library (maybe not a PHP library) '%s'", filename);
		return FAILURE;
	}
	module_entry = get_module();
	if (module_entry->zend_api != ZEND_MODULE_API_NO) {
			php_error_docref(NULL, error_type,
					"%s: Unable to initialize module\n"
					"Module compiled with module API=%d\n"
					"PHP    compiled with module API=%d\n"
					"These options need to match\n",
					module_entry->name, module_entry->zend_api, ZEND_MODULE_API_NO);
			DL_UNLOAD(handle);
			return FAILURE;
	}
	if(strcmp(module_entry->build_id, ZEND_MODULE_BUILD_ID)) {
		php_error_docref(NULL, error_type,
				"%s: Unable to initialize module\n"
				"Module compiled with build ID=%s\n"
				"PHP    compiled with build ID=%s\n"
				"These options need to match\n",
				module_entry->name, module_entry->build_id, ZEND_MODULE_BUILD_ID);
		DL_UNLOAD(handle);
		return FAILURE;
	}
	module_entry->type = type;
	module_entry->module_number = zend_next_free_module();
	module_entry->handle = handle;

	if ((module_entry = zend_register_module_ex(module_entry)) == NULL) {
		DL_UNLOAD(handle);
		return FAILURE;
	}

	if ((type == MODULE_TEMPORARY || start_now) && zend_startup_module_ex(module_entry) == FAILURE) {
		DL_UNLOAD(handle);
		return FAILURE;
	}

	if ((type == MODULE_TEMPORARY || start_now) && module_entry->request_startup_func) {
		if (module_entry->request_startup_func(type, module_entry->module_number) == FAILURE) {
			php_error_docref(NULL, error_type, "Unable to initialize module '%s'", module_entry->name);
			DL_UNLOAD(handle);
			return FAILURE;
		}
	}
	return SUCCESS;
}
Пример #18
0
/**********************************************************************
 *          LoadResource     (KERNEL.61)
 */
HGLOBAL16 WINAPI LoadResource16( HMODULE16 hModule, HRSRC16 hRsrc )
{
    NE_TYPEINFO *pTypeInfo;
    NE_NAMEINFO *pNameInfo = NULL;
    NE_MODULE *pModule = get_module( hModule );
    int d;

    if (!hRsrc || !pModule) return 0;

    if (pModule->module32)
    {
        /* load 32-bit resource and convert it */
        HRSRC hRsrc32 = MapHRsrc16To32( pModule, hRsrc );
        WORD type     = MapHRsrc16ToType( pModule, hRsrc );
        HGLOBAL hMem  = LoadResource( pModule->module32, hRsrc32 );
        DWORD size    = SizeofResource( pModule->module32, hRsrc32 );
        if (!hMem) return 0;
        return NE_LoadPEResource( pModule, type, LockResource( hMem ), size );
    }

    /* first, verify hRsrc (just an offset from pModule to the needed pNameInfo) */

    d = pModule->ne_rsrctab + 2;
    pTypeInfo = (NE_TYPEINFO *)((char *)pModule + d);
    while( hRsrc > d )
    {
        if (pTypeInfo->type_id == 0) break; /* terminal entry */
        d += sizeof(NE_TYPEINFO) + pTypeInfo->count * sizeof(NE_NAMEINFO);
        if (hRsrc < d)
        {
            if( ((d - hRsrc)%sizeof(NE_NAMEINFO)) == 0 )
            {
                pNameInfo = (NE_NAMEINFO *)((char *)pModule + hRsrc);
                break;
            }
            else break; /* NE_NAMEINFO boundary mismatch */
        }
        pTypeInfo = (NE_TYPEINFO *)((char *)pModule + d);
    }

    if (pNameInfo)
    {
        if (pNameInfo->handle && !(GlobalFlags16(pNameInfo->handle) & GMEM_DISCARDED))
        {
            pNameInfo->usage++;
            TRACE("  Already loaded, new count=%d\n", pNameInfo->usage );
        }
        else
        {
            FARPROC16 resloader;
            memcpy_unaligned( &resloader, &pTypeInfo->resloader, sizeof(FARPROC16) );
            if (resloader && resloader != get_default_res_handler())
            {
                WORD args[3];
                DWORD ret;

                args[2] = pNameInfo->handle;
                args[1] = pModule->self;
                args[0] = hRsrc;
                WOWCallback16Ex( (DWORD)resloader, WCB16_PASCAL, sizeof(args), args, &ret );
                pNameInfo->handle = LOWORD(ret);
            }
            else
                pNameInfo->handle = NE_DefResourceHandler( pNameInfo->handle, pModule->self, hRsrc );

            if (pNameInfo->handle)
            {
                pNameInfo->usage++;
                pNameInfo->flags |= NE_SEGFLAGS_LOADED;
            }
        }
        return pNameInfo->handle;
    }
    return 0;
}
Пример #19
0
void *work_thread(void *ptr)
{
	struct job_data *data = (struct job_data *)ptr;
	struct s_client *cl = data->cl;
	struct s_reader *reader = cl->reader;
	struct timeb start, end;  // start time poll, end time poll

	struct job_data tmp_data;
	struct pollfd pfd[1];

	pthread_setspecific(getclient, cl);
	cl->thread = pthread_self();
	cl->thread_active = 1;

	set_work_thread_name(data);

	struct s_module *module = get_module(cl);
	uint16_t bufsize = module->bufsize; //CCCam needs more than 1024bytes!
	if(!bufsize)
		{ bufsize = 1024; }

	uint8_t *mbuf;
	if(!cs_malloc(&mbuf, bufsize))
		{ return NULL; }
	cl->work_mbuf = mbuf; // Track locally allocated data, because some callback may call cs_exit/cs_disconect_client/pthread_exit and then mbuf would be leaked
	int32_t n = 0, rc = 0, i, idx, s;
	uint8_t dcw[16];
	int8_t restart_reader = 0;
	while(cl->thread_active)
	{
		cs_ftime(&start); // register start time
		while(cl->thread_active)
		{
			if(!cl || cl->kill || !is_valid_client(cl))
			{
				pthread_mutex_lock(&cl->thread_lock);
				cl->thread_active = 0;
				pthread_mutex_unlock(&cl->thread_lock);
				cs_debug_mask(D_TRACE, "ending thread (kill)");
				__free_job_data(cl, data);
				cl->work_mbuf = NULL; // Prevent free_client from freeing mbuf (->work_mbuf)
				free_client(cl);
				if(restart_reader)
					{ restart_cardreader(reader, 0); }
				NULLFREE(mbuf);
				pthread_exit(NULL);
				return NULL;
			}

			if(data && data->action != ACTION_READER_CHECK_HEALTH)
				{ cs_debug_mask(D_TRACE, "data from add_job action=%d client %c %s", data->action, cl->typ, username(cl)); }

			if(!data)
			{
				if(!cl->kill && cl->typ != 'r')
					{ client_check_status(cl); } // do not call for physical readers as this might cause an endless job loop
				pthread_mutex_lock(&cl->thread_lock);
				if(cl->joblist && ll_count(cl->joblist) > 0)
				{
					LL_ITER itr = ll_iter_create(cl->joblist);
					data = ll_iter_next_remove(&itr);
					if(data)
						{ set_work_thread_name(data); }
					//cs_debug_mask(D_TRACE, "start next job from list action=%d", data->action);
				}
				pthread_mutex_unlock(&cl->thread_lock);
			}

			if(!data)
			{
				/* for serial client cl->pfd is file descriptor for serial port not socket
				   for example: pfd=open("/dev/ttyUSB0"); */
				if(!cl->pfd || module->listenertype == LIS_SERIAL)
					{ break; }
				pfd[0].fd = cl->pfd;
				pfd[0].events = POLLIN | POLLPRI;

				pthread_mutex_lock(&cl->thread_lock);
				cl->thread_active = 2;
				pthread_mutex_unlock(&cl->thread_lock);
				rc = poll(pfd, 1, 3000);
				pthread_mutex_lock(&cl->thread_lock);
				cl->thread_active = 1;
				pthread_mutex_unlock(&cl->thread_lock);
				if(rc > 0)
				{
					cs_ftime(&end); // register end time
					cs_debug_mask(D_TRACE, "[OSCAM-WORK] new event %d occurred on fd %d after %"PRId64" ms inactivity", pfd[0].revents,
								  pfd[0].fd, comp_timeb(&end, &start));
					data = &tmp_data;
					data->ptr = NULL;
					cs_ftime(&start); // register start time for new poll next run

					if(reader)
						{ data->action = ACTION_READER_REMOTE; }
					else
					{
						if(cl->is_udp)
						{
							data->action = ACTION_CLIENT_UDP;
							data->ptr = mbuf;
							data->len = bufsize;
						}
						else
							{ data->action = ACTION_CLIENT_TCP; }
						if(pfd[0].revents & (POLLHUP | POLLNVAL | POLLERR))
							{ cl->kill = 1; }
					}
				}
			}

			if(!data)
				{ continue; }

			if(!reader && data->action < ACTION_CLIENT_FIRST)
			{
				__free_job_data(cl, data);
				break;
			}

			if(!data->action)
				{ break; }

			struct timeb actualtime;
			cs_ftime(&actualtime);
			int32_t gone = comp_timeb(&actualtime, &data->time);
			if(data != &tmp_data && gone > (int) cfg.ctimeout+1000)
			{
				cs_debug_mask(D_TRACE, "dropping client data for %s time %dms", username(cl), gone);
				__free_job_data(cl, data);
				continue;
			}

			if(data != &tmp_data)
				{ cl->work_job_data = data; } // Track the current job_data
			switch(data->action)
			{
			case ACTION_READER_IDLE:
				reader_do_idle(reader);
				break;
			case ACTION_READER_REMOTE:
				s = check_fd_for_data(cl->pfd);
				if(s == 0)  // no data, another thread already read from fd?
					{ break; }
				if(s < 0)
				{
					if(reader->ph.type == MOD_CONN_TCP)
						{ network_tcp_connection_close(reader, "disconnect"); }
					break;
				}
				rc = reader->ph.recv(cl, mbuf, bufsize);
				if(rc < 0)
				{
					if(reader->ph.type == MOD_CONN_TCP)
						{ network_tcp_connection_close(reader, "disconnect on receive"); }
					break;
				}
				cl->last = time(NULL); // *********************************** TO BE REPLACE BY CS_FTIME() LATER ****************
				idx = reader->ph.c_recv_chk(cl, dcw, &rc, mbuf, rc);
				if(idx < 0) { break; }  // no dcw received
				if(!idx) { idx = cl->last_idx; }
				reader->last_g = time(NULL); // *********************************** TO BE REPLACE BY CS_FTIME() LATER **************** // for reconnect timeout
				for(i = 0, n = 0; i < cfg.max_pending && n == 0; i++)
				{
					if(cl->ecmtask[i].idx == idx)
					{
						cl->pending--;
						casc_check_dcw(reader, i, rc, dcw);
						n++;
					}
				}
				break;
			case ACTION_READER_RESET:
				cardreader_do_reset(reader);
				break;
			case ACTION_READER_ECM_REQUEST:
				reader_get_ecm(reader, data->ptr);
				break;
			case ACTION_READER_EMM:
				reader_do_emm(reader, data->ptr);
				break;
			case ACTION_READER_CARDINFO:
				reader_do_card_info(reader);
				break;
			case ACTION_READER_INIT:
				if(!cl->init_done)
					{ reader_init(reader); }
				break;
			case ACTION_READER_RESTART:
				cl->kill = 1;
				restart_reader = 1;
				break;
			case ACTION_READER_RESET_FAST:
				reader->card_status = CARD_NEED_INIT;
				cardreader_do_reset(reader);
				break;
			case ACTION_READER_CHECK_HEALTH:
				cardreader_do_checkhealth(reader);
				break;
			case ACTION_READER_CAPMT_NOTIFY:
				if(reader->ph.c_capmt) { reader->ph.c_capmt(cl, data->ptr); }
				break;
			case ACTION_CLIENT_UDP:
				n = module->recv(cl, data->ptr, data->len);
				if(n < 0) { break; }
				module->s_handler(cl, data->ptr, n);
				break;
			case ACTION_CLIENT_TCP:
				s = check_fd_for_data(cl->pfd);
				if(s == 0)  // no data, another thread already read from fd?
					{ break; }
				if(s < 0)    // system error or fd wants to be closed
				{
					cl->kill = 1; // kill client on next run
					continue;
				}
				n = module->recv(cl, mbuf, bufsize);
				if(n < 0)
				{
					cl->kill = 1; // kill client on next run
					continue;
				}
				module->s_handler(cl, mbuf, n);
				break;
			case ACTION_CACHEEX_TIMEOUT:
#ifdef CS_CACHEEX
				cacheex_timeout(data->ptr);
#endif
				break;
			case ACTION_FALLBACK_TIMEOUT:
				fallback_timeout(data->ptr);
				break;
			case ACTION_CLIENT_TIMEOUT:
				ecm_timeout(data->ptr);
				break;
			case ACTION_ECM_ANSWER_READER:
				chk_dcw(data->ptr);
				break;
			case ACTION_ECM_ANSWER_CACHE:
				write_ecm_answer_fromcache(data->ptr);
				break;
			case ACTION_CLIENT_INIT:
				if(module->s_init)
					{ module->s_init(cl); }
				cl->is_udp = module->type == MOD_CONN_UDP;
				cl->init_done = 1;
				break;
			case ACTION_CLIENT_IDLE:
				if(module->s_idle)
					{ module->s_idle(cl); }
				else
				{
					cs_log("user %s reached %d sec idle limit.", username(cl), cfg.cmaxidle);
					cl->kill = 1;
				}
				break;
			case ACTION_CACHE_PUSH_OUT:
			{
#ifdef CS_CACHEEX
				ECM_REQUEST *er = data->ptr;
				int32_t res = 0, stats = -1;
				// cc-nodeid-list-check
				if(reader)
				{
					if(reader->ph.c_cache_push_chk && !reader->ph.c_cache_push_chk(cl, er))
						{ break; }
					res = reader->ph.c_cache_push(cl, er);
					stats = cacheex_add_stats(cl, er->caid, er->srvid, er->prid, 0);
				}
				else
				{
					if(module->c_cache_push_chk && !module->c_cache_push_chk(cl, er))
						{ break; }
					res = module->c_cache_push(cl, er);
				}
				debug_ecm(D_CACHEEX, "pushed ECM %s to %s res %d stats %d", buf, username(cl), res, stats);
				cl->cwcacheexpush++;
				if(cl->account)
					{ cl->account->cwcacheexpush++; }
				first_client->cwcacheexpush++;
#endif
				break;
			}
			case ACTION_CLIENT_KILL:
				cl->kill = 1;
				break;
			case ACTION_CLIENT_SEND_MSG:
			{
#ifdef MODULE_CCCAM
				struct s_clientmsg *clientmsg = (struct s_clientmsg *)data->ptr;
				cc_cmd_send(cl, clientmsg->msg, clientmsg->len, clientmsg->cmd);
#endif
				break;
			}
			} // switch

			__free_job_data(cl, data);
		}

		if(thread_pipe[1] && (mbuf[0] != 0x00))
		{
			cs_ddump_mask(D_TRACE, mbuf, 1, "[OSCAM-WORK] Write to pipe:");
			if(write(thread_pipe[1], mbuf, 1) == -1)    // wakeup client check
			{
				cs_debug_mask(D_TRACE, "[OSCAM-WORK] Writing to pipe failed (errno=%d %s)", errno, strerror(errno));
			}
		}

		// Check for some race condition where while we ended, another thread added a job
		pthread_mutex_lock(&cl->thread_lock);
		if(cl->joblist && ll_count(cl->joblist) > 0)
		{
			pthread_mutex_unlock(&cl->thread_lock);
			continue;
		}
		else
		{
			cl->thread_active = 0;
			pthread_mutex_unlock(&cl->thread_lock);
			break;
		}
	}
	cl->thread_active = 0;
	cl->work_mbuf = NULL; // Prevent free_client from freeing mbuf (->work_mbuf)
	NULLFREE(mbuf);
	pthread_exit(NULL);
	return NULL;
}
Пример #20
0
int
imap_driver_init(struct module *module, struct event_base *base)
{
    struct imap_driver *driver = module->priv;
    struct imap_config *config;
    struct imap_handler *handler = handlers;
    struct module *ldap;
    struct sockaddr_in6 sin;
    int socklen = sizeof(sin);

    assert(driver && driver->config && base);
    config = driver->config;

    driver->base = base;
    driver->dnsbase = get_dnsbase();

    if (config->cert) {
        driver->ssl_ctx = new_ssl_ctx(config->cert, config->pkey);
        if (driver->ssl_ctx == NULL) {
            return 1;
        }
    } else {
        /* skip the STARTTLS handler */
        handler += 1;
    }

    for (; handler->command; handler++) {
        /* handle the private handler storage */
        if (avl_insert(&driver->commands, handler, imap_handler_cmp, avl_dup_error)) {
            return 1;
        }
    }

    if (evutil_parse_sockaddr_port(config->listen, (struct sockaddr *)&sin, &socklen)) {
        return 1;
    }

    /* we start in disabled state until the LDAP interface is ready */
    driver->listener = evconnlistener_new_bind(base, listen_cb, (void*)driver,
            LEV_OPT_REUSEABLE|LEV_OPT_DISABLED|LEV_OPT_CLOSE_ON_FREE,
            -1, (struct sockaddr *)&sin, socklen);
    /* could also be wise to set an error callback, but what errors do we face
     * on accept()? */

    if (!driver->listener) {
        skeeter_log(LOG_CRIT, "Could not create a listener!");
        return 1;
    }

    ldap = get_module("ldap");
    if (!ldap || !ldap->register_event) {
        skeeter_log(LOG_CRIT, "LDAP module not available!");
        return 1;
    }

    if (ldap->register_event(ldap, MODULE_ANY | MODULE_PERSIST, trigger_listener, driver->listener)) {
        skeeter_log(LOG_CRIT, "Regitration with LDAP module failed!");
        return 1;
    }

    driver->ldap = ldap;

    return 0;
}
Пример #21
0
const std::string& abstract_group::module_name() const {
  return get_module()->name();
}
Пример #22
0
extern "C" status_t
init_driver(void)
{
	TRACE("%s\n", __func__);

	status_t status = get_module(B_PCI_MODULE_NAME, (module_info**)&gPCI);
	if (status != B_OK) {
		ERROR("%s: ERROR: pci module unavailable\n", __func__);
		return status;
	}

	mutex_init(&gLock, "radeon hd ksync");

	// find devices

	int32 found = 0;

	for (int32 cookie = 0; found < MAX_CARDS;) {
		pci_info* info = (pci_info*)malloc(sizeof(pci_info));
		if (info == NULL)
			break;

		uint32 type;
		status = get_next_radeon_hd(&cookie, *info, type);
		if (status < B_OK) {
			free(info);
			break;
		}

		// create device names & allocate device info structure

		char name[64];
		sprintf(name, "graphics/radeon_hd_%02x%02x%02x",
			info->bus, info->device,
			info->function);

		gDeviceNames[found] = strdup(name);
		if (gDeviceNames[found] == NULL)
			break;

		gDeviceInfo[found] = (radeon_info*)malloc(sizeof(radeon_info));
		if (gDeviceInfo[found] == NULL) {
			free(gDeviceNames[found]);
			break;
		}

		// initialize the structure for later use

		memset(gDeviceInfo[found], 0, sizeof(radeon_info));
		gDeviceInfo[found]->init_status = B_NO_INIT;
		gDeviceInfo[found]->id = found;
		gDeviceInfo[found]->pci = info;
		gDeviceInfo[found]->registers = info->u.h0.base_registers[0];
		gDeviceInfo[found]->pciID = kSupportedDevices[type].pciID;
		gDeviceInfo[found]->deviceName = kSupportedDevices[type].deviceName;
		gDeviceInfo[found]->chipsetID = kSupportedDevices[type].chipsetID;
		gDeviceInfo[found]->dceMajor = kSupportedDevices[type].dceMajor;
		gDeviceInfo[found]->dceMinor = kSupportedDevices[type].dceMinor;
		gDeviceInfo[found]->chipsetFlags = kSupportedDevices[type].chipsetFlags;

		ERROR("%s: GPU(%ld) %s, revision = 0x%x\n", __func__, found,
			kSupportedDevices[type].deviceName, info->revision);

		found++;
	}

	gDeviceNames[found] = NULL;

	if (found == 0) {
		mutex_destroy(&gLock);
		put_module(B_AGP_GART_MODULE_NAME);
		put_module(B_PCI_MODULE_NAME);
		ERROR("%s: no supported devices found\n", __func__);
		return ENODEV;
	}

	return B_OK;
}
Пример #23
0
int set_frequency(struct cli_state *state, int argc, char **argv)
{
    /* Usage: set frequency [<rx|tx>] <frequency in Hz> */
    int rv = CLI_RET_OK;
    int status;
    unsigned int freq;
    bladerf_module module = BLADERF_MODULE_RX;

    if( argc == 4 ) {
        /* Parse module */
        bool ok;
        module = get_module( argv[2], &ok );
        if( !ok ) {
            invalid_module(state, argv[0], argv[2]);
            rv = CLI_RET_INVPARAM;
        }
    } else if( argc != 3 ) {
        /* Assume both RX & TX if not specified */
        rv = CLI_RET_NARGS;
    }

    if( argc > 2 && rv == CLI_RET_OK ) {
        bool ok;
        /* Parse out frequency */
        freq = str2uint_suffix( argv[argc-1],
                                BLADERF_FREQUENCY_MIN, BLADERF_FREQUENCY_MAX,
                                FREQ_SUFFIXES, NUM_FREQ_SUFFIXES, &ok );

        if( !ok ) {
            cli_err(state, argv[0], "Invalid frequency (%s)", argv[argc - 1]);
            rv = CLI_RET_INVPARAM;
        } else {

            printf( "\n" );

            /* Change RX frequency */
            if( argc == 3 || module == BLADERF_MODULE_RX ) {
                int status = bladerf_set_frequency( state->dev,
                                                    BLADERF_MODULE_RX, freq );

                if (status < 0) {
                    state->last_lib_error = status;
                    rv = CLI_RET_LIBBLADERF;
                } else {
                    printf( "  Set RX frequency: %10uHz\n", freq );
                }
            }

            /* Change TX frequency */
            if( argc == 3 || module == BLADERF_MODULE_TX ) {
                status = bladerf_set_frequency( state->dev,
                                                BLADERF_MODULE_TX, freq );

                if (status < 0) {
                    state->last_lib_error = status;
                    rv = CLI_RET_LIBBLADERF;
                } else {
                    printf( "  Set TX frequency: %10uHz\n", freq );
                }
            }

            printf( "\n" );
        }
    }

    return rv;
}
Пример #24
0
/**
 * cacheex modes:
 *
 * cacheex=1 CACHE PULL:
 * Situation: oscam A reader1 has cacheex=1, oscam B account1 has cacheex=1
 *   oscam A gets a ECM request, reader1 send this request to oscam B, oscam B checks his cache
 *   a. not found in cache: return NOK
 *   a. found in cache: return OK+CW
 *   b. not found in cache, but found pending request: wait max cacheexwaittime and check again
 *   oscam B never requests new ECMs
 *
 *   CW-flow: B->A
 *
 * cacheex=2 CACHE PUSH:
 * Situation: oscam A reader1 has cacheex=2, oscam B account1 has cacheex=2
 *   if oscam B gets a CW, its pushed to oscam A
 *   reader has normal functionality and can request ECMs
 *
 *   Problem: oscam B can only push if oscam A is connected
 *   Problem or feature?: oscam A reader can request ecms from oscam B
 *
 *   CW-flow: B->A
 *
 */
void cacheex_cache_push(ECM_REQUEST *er)
{
    if(er->rc >= E_NOTFOUND) {
        return;
    }

    //cacheex=2 mode: push (server->remote)
    struct s_client *cl;
    cs_readlock(&clientlist_lock);
    for(cl = first_client->next; cl; cl = cl->next)
    {
        if(check_client(cl) && er->cacheex_src != cl)
        {
            if(get_module(cl)->num == R_CSP)    // always send to csp cl
            {
                if(!er->cacheex_src || cfg.csp.allow_reforward) {
                    cacheex_cache_push_to_client(cl, er);    // but not if the origin was cacheex (might loop)
                }
            }
            else if(cl->typ == 'c' && !cl->dup && cl->account && cl->account->cacheex.mode == 2)      //send cache over user
            {
                if(get_module(cl)->c_cache_push  // cache-push able
                        && (!er->grp || (cl->grp & er->grp)) //Group-check
                        /****  OUTGOING FILTER CHECK ***/
                        && (!er->selected_reader || !cacheex_reader(er->selected_reader) || !cfg.block_same_name || strcmp(username(cl), er->selected_reader->label)) //check reader mode-1 loopback by same name
                        && (!er->selected_reader || !cacheex_reader(er->selected_reader) || !cfg.block_same_ip || (check_client(er->selected_reader->client) && !IP_EQUAL(cl->ip, er->selected_reader->client->ip))) //check reader mode-1 loopback by same ip
                        && (!cl->account->cacheex.drop_csp || checkECMD5(er))  //cacheex_drop_csp-check
                        && chk_ctab(er->caid, &cl->ctab)  					 //Caid-check
                        && (!checkECMD5(er) || chk_ident_filter(er->caid, er->prid, &cl->ftab))	 	 //Ident-check (not for csp: prid=0 always!)
                        && chk_srvid(cl, er) //Service-check
                  )
                {
                    cacheex_cache_push_to_client(cl, er);
                }
            }
        }
    }
    cs_readunlock(&clientlist_lock);


    //cacheex=3 mode: reverse push (reader->server)
    cs_readlock(&readerlist_lock);
    cs_readlock(&clientlist_lock);
    struct s_reader *rdr;
    for(rdr = first_active_reader; rdr; rdr = rdr->next)
    {
        cl = rdr->client;
        if(check_client(cl) && er->cacheex_src != cl && rdr->cacheex.mode == 3)    //send cache over reader
        {
            if(rdr->ph.c_cache_push     // cache-push able
                    && (!er->grp || (rdr->grp & er->grp)) //Group-check
                    /****  OUTGOING FILTER CHECK ***/
                    && (!er->selected_reader || !cacheex_reader(er->selected_reader) || !cfg.block_same_name || strcmp(username(cl), er->selected_reader->label)) //check reader mode-1 loopback by same name
                    && (!er->selected_reader || !cacheex_reader(er->selected_reader) || !cfg.block_same_ip || (check_client(er->selected_reader->client) && !IP_EQUAL(cl->ip, er->selected_reader->client->ip))) //check reader mode-1 loopback by same ip
                    && (!rdr->cacheex.drop_csp || checkECMD5(er))  		 //cacheex_drop_csp-check
                    && chk_ctab(er->caid, &rdr->ctab)  					 //Caid-check
                    && (!checkECMD5(er) || chk_ident_filter(er->caid, er->prid, &rdr->ftab))	 	 //Ident-check (not for csp: prid=0 always!)
                    && chk_srvid(cl, er) //Service-check
              )
            {
                cacheex_cache_push_to_client(cl, er);
            }
        }
    }
    cs_readunlock(&clientlist_lock);
    cs_readunlock(&readerlist_lock);
}
Пример #25
0
/* {{{ php_load_extension
 */
PHPAPI int php_load_extension(char *filename, int type, int start_now)
{
	void *handle;
	char *libpath;
	zend_module_entry *module_entry;
	zend_module_entry *(*get_module)(void);
	int error_type, slash_suffix;
	char *extension_dir;

	if (type == MODULE_PERSISTENT) {
		extension_dir = INI_STR("extension_dir");
	} else {
		extension_dir = PG(extension_dir);
	}

	if (type == MODULE_TEMPORARY) {
		error_type = E_WARNING;
	} else {
		error_type = E_CORE_WARNING;
	}

	/* Check if passed filename contains directory separators */
	if (strchr(filename, '/') != NULL || strchr(filename, DEFAULT_SLASH) != NULL) {
		/* Passing modules with full path is not supported for dynamically loaded extensions */
		if (type == MODULE_TEMPORARY) {
			php_error_docref(NULL, E_WARNING, "Temporary module name should contain only filename");
			return FAILURE;
		}
		libpath = estrdup(filename);
	} else if (extension_dir && extension_dir[0]) {
		int extension_dir_len = (int)strlen(extension_dir);
		char *err1, *err2;
		slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
		/* Try as filename first */
		if (slash_suffix) {
			spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */
		} else {
			spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */
		}

		handle = php_load_shlib(libpath, &err1);
		if (!handle) {
			/* Now, consider 'filename' as extension name and build file name */
			char *orig_libpath = libpath;

			if (slash_suffix) {
				spprintf(&libpath, 0, "%s" PHP_SHLIB_EXT_PREFIX "%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
			} else {
				spprintf(&libpath, 0, "%s%c" PHP_SHLIB_EXT_PREFIX "%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
			}

			handle = php_load_shlib(libpath, &err2);
			if (!handle) {
				php_error_docref(NULL, error_type, "Unable to load dynamic library '%s' (tried: %s (%s), %s (%s))",
					filename, orig_libpath, err1, libpath, err2);
				efree(orig_libpath);
				efree(err1);
				efree(libpath);
				efree(err2);
				return FAILURE;
			}
			efree(orig_libpath);
			efree(err1);
		}
	} else {
		return FAILURE; /* Not full path given or extension_dir is not set */
	}

	efree(libpath);

	get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "get_module");

	/* Some OS prepend _ to symbol names while their dynamic linker
	 * does not do that automatically. Thus we check manually for
	 * _get_module. */

	if (!get_module) {
		get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "_get_module");
	}

	if (!get_module) {
		if (DL_FETCH_SYMBOL(handle, "zend_extension_entry") || DL_FETCH_SYMBOL(handle, "_zend_extension_entry")) {
			DL_UNLOAD(handle);
			php_error_docref(NULL, error_type, "Invalid library (appears to be a Zend Extension, try loading using zend_extension=%s from php.ini)", filename);
			return FAILURE;
		}
		DL_UNLOAD(handle);
		php_error_docref(NULL, error_type, "Invalid library (maybe not a PHP library) '%s'", filename);
		return FAILURE;
	}
	module_entry = get_module();
	if (module_entry->zend_api != ZEND_MODULE_API_NO) {
			php_error_docref(NULL, error_type,
					"%s: Unable to initialize module\n"
					"Module compiled with module API=%d\n"
					"PHP    compiled with module API=%d\n"
					"These options need to match\n",
					module_entry->name, module_entry->zend_api, ZEND_MODULE_API_NO);
			DL_UNLOAD(handle);
			return FAILURE;
	}
	if(strcmp(module_entry->build_id, ZEND_MODULE_BUILD_ID)) {
		php_error_docref(NULL, error_type,
				"%s: Unable to initialize module\n"
				"Module compiled with build ID=%s\n"
				"PHP    compiled with build ID=%s\n"
				"These options need to match\n",
				module_entry->name, module_entry->build_id, ZEND_MODULE_BUILD_ID);
		DL_UNLOAD(handle);
		return FAILURE;
	}
	module_entry->type = type;
	module_entry->module_number = zend_next_free_module();
	module_entry->handle = handle;

	if ((module_entry = zend_register_module_ex(module_entry)) == NULL) {
		DL_UNLOAD(handle);
		return FAILURE;
	}

	if ((type == MODULE_TEMPORARY || start_now) && zend_startup_module_ex(module_entry) == FAILURE) {
		DL_UNLOAD(handle);
		return FAILURE;
	}

	if ((type == MODULE_TEMPORARY || start_now) && module_entry->request_startup_func) {
		if (module_entry->request_startup_func(type, module_entry->module_number) == FAILURE) {
			php_error_docref(NULL, error_type, "Unable to initialize module '%s'", module_entry->name);
			DL_UNLOAD(handle);
			return FAILURE;
		}
	}
	return SUCCESS;
}
Пример #26
0
int
main()
{
	_add_builtin_module((module_info*)&gNetBufferModule);
	get_module(NET_BUFFER_MODULE_NAME, (module_info**)&gBufferModule);
	gQueue.SetInitialSequence(100);

	add(100, 100);
	add(100, 300);
	add(100, 250);
	add(100, 175);
	ASSERT(gQueue.Available() == 300);
	dump("add 4");

	eat(99);
	dump("ate 99");

	eat(1);
	eat(1);
	eat(149);
	eat(50);

	add(10, 100);
	add(0, 400);
	add(1, 399);
	dump("add nothing");

	add(1, 1000);
	dump("add far away");

	add(2, 399);
	dump("add 1");

	add(100, 500);
	add(10, 480);
	add(19, 401);
	add(10, 460);
	add(10, 420);
	add(30, 430);
	add(35, 465);
	dump("added with holes");

	add(50, 425);
	dump("added no new data");

	eat(19);
	eat(1);
	eat(40);
	eat(50);
	dump("ate some");

	add(1, 999);
	dump("add 1");
	add(2, 999);
	add(2, 999);
	dump("add 2");
	add(3, 999);
	dump("add 3");

	add(60, 540);
	dump("added at the end of previous data");
	
	add(998, 1002);
	add(500, 1000);
	dump("added data covered by next");

	put_module(NET_BUFFER_MODULE_NAME);
	return 0;
}
Пример #27
0
int set_bandwidth(struct cli_state *state, int argc, char **argv)
{
    /* Usage: set bandwidth [rx|tx] <bandwidth in Hz> */
    int rv = CLI_RET_OK;
    int status;
    bladerf_module module = BLADERF_MODULE_RX;
    unsigned int bw = 28000000, actual;

    /* Check for extended help */
    if( argc == 2 ) {
        printf( "\n" );
        printf( "Usage: set bandwidth [module] <bandwidth>\n" );
        printf( "\n" );
        printf( "    module         Optional argument to set single module bandwidth\n" );
        printf( "    bandwidth      Bandwidth in Hz - will be rounded up to closest bandwidth\n" );
        printf( "\n" );
    }

    /* Check for optional module */
    else if( argc == 4 ) {
        /* Parse module */
        bool ok;
        module = get_module( argv[2], &ok );
        if( !ok ) {
            invalid_module(state, argv[0], argv[2]);
            rv = CLI_RET_INVPARAM;
        }

        /* Parse bandwidth */
        bw = str2uint_suffix( argv[3],
                              BLADERF_BANDWIDTH_MIN, BLADERF_BANDWIDTH_MAX,
                              FREQ_SUFFIXES, NUM_FREQ_SUFFIXES, &ok );
        if( !ok ) {
            cli_err(state, argv[0], "Invalid bandwidth (%s)", argv[3]);
            rv = CLI_RET_INVPARAM;
        }
    }

    /* No module, just bandwidth */
    else if( argc == 3 ) {
        bool ok;
        bw = str2uint_suffix( argv[2],
                              BLADERF_BANDWIDTH_MIN, BLADERF_BANDWIDTH_MAX,
                              FREQ_SUFFIXES, NUM_FREQ_SUFFIXES, &ok );
        if( !ok ) {
            cli_err(state, argv[0], "Invalid bandwidth (%s)", argv[2]);
            rv = CLI_RET_INVPARAM;
        }
    }

    /* Weird number of arguments */
    else {
        rv = CLI_RET_NARGS;
    }

    /* Problem parsing arguments? */
    if( argc > 2 && rv == CLI_RET_OK ) {

        printf( "\n" );

        /* Lack of option, so set both or RX only */
        if( argc == 3 || module == BLADERF_MODULE_RX ) {
            status = bladerf_set_bandwidth( state->dev, BLADERF_MODULE_RX,
                                            bw, &actual );

            if (status < 0) {
                state->last_lib_error = status;
                rv = CLI_RET_LIBBLADERF;
            } else {
                printf( "  Set RX bandwidth - req:%9uHz actual:%9uHz\n",
                        bw, actual );
            }
        }

        /* Lack of option, so set both or TX only */
        if( argc == 3 || module == BLADERF_MODULE_TX ) {
            status = bladerf_set_bandwidth( state->dev, BLADERF_MODULE_TX,
                                            bw, &actual );

            if (status < 0) {
                state->last_lib_error = status;
                rv = CLI_RET_LIBBLADERF;
            } else {
                printf( "  Set TX bandwidth - req:%9uHz actual:%9uHz\n",
                        bw, actual );
            }
        }

        printf( "\n" );
    }


    return rv;
}
Пример #28
0
static
jint check_system_loader(JNIEnv *env, jobject loader) {
    jvmtiError err = JVMTI_ERROR_NONE;
    jobject module = NULL;
    const char* exp_name = NULL;
    const char* mod_name = NULL;

    // NULL pointer for package name
    err = get_module(env, loader, NULL, &module, &mod_name);
    if (err != JVMTI_ERROR_NULL_POINTER) {
        throw_exc(env, "check #SN1: failed to return JVMTI_ERROR_NULL_POINTER for NULL package");
        return FAILED;
    }

    // NULL pointer for module_ptr
    err = (*jvmti)->GetNamedModule(jvmti, loader, "", NULL);
    if (err != JVMTI_ERROR_NULL_POINTER) {
        throw_exc(env, "check #SN2: failed to return JVMTI_ERROR_NULL_POINTER for NULL module_ptr");
        return FAILED;
    }

    // Unnamed/default package ""
    err = get_module(env, loader, "", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #S1: failed to return JVMTI_ERROR_NONE for default package");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #S2: failed to return NULL-module for default package");
        return FAILED;
    }

    // Test package: MyPackage
    err = get_module(env, loader, "MyPackage", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #S3: failed to return JVMTI_ERROR_NONE for MyPackage");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #S4: failed to return NULL-module for MyPackage");
        return FAILED;
    }

    // Package: com/sun/jdi
    exp_name = "jdk.jdi";
    err = get_module(env, loader, "com/sun/jdi", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #S5: failed to return JVMTI_ERROR_NONE for test package");
        return FAILED;
    }
    if (module == NULL || mod_name == NULL) {
        throw_exc(env, "check #S6: failed to return named module for com/sun/jdi package");
        return FAILED;
    }
    if (strcmp(mod_name, exp_name) != 0) {
        printf("check #S7: failed to return right module, expected: %s, returned: %s\n",
               exp_name, mod_name);
        throw_exc(env, "check #S7: failed to return jdk.jdi module for com/sun/jdi package");
        return FAILED;
    }

    // Non-existing package: "bad/package/name"
    err = get_module(env, loader, "bad/package/name", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #S8: failed to return JVMTI_ERROR_NONE for bad package");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #S9: failed to return NULL-module for bad package");
        return FAILED;
    }
    return PASSED;
}
Пример #29
0
void cs_statistics(struct s_client *client)
{
	if(!cfg.disableuserfile)
	{
		struct tm lt;
		char buf[LOG_BUF_SIZE];

		float cwps;

		time_t walltime = cs_time();
		localtime_r(&walltime, &lt);
		if(client->cwfound + client->cwnot > 0)
		{
			cwps = client->last - client->login;
			cwps /= client->cwfound + client->cwnot;
		}
		else
			{ cwps = 0; }

		char channame[32];
		get_servicename(client, client->last_srvid, client->last_caid, channame);

		int32_t lsec;
		if((client->last_caid == NO_CAID_VALUE) && (client->last_srvid == NO_SRVID_VALUE))
			{ lsec = client->last - client->login; } //client leave calc total duration
		else
			{ lsec = client->last - client->lastswitch; }

		int32_t secs = 0, fullmins = 0, mins = 0, fullhours = 0;

		if((lsec > 0) && (lsec < 1000000))
		{
			secs = lsec % 60;
			if(lsec > 60)
			{
				fullmins = lsec / 60;
				mins = fullmins % 60;
				if(fullmins > 60)
				{
					fullhours = fullmins / 60;
				}
			}
		}

		/* statistics entry start with 's' to filter it out on other end of pipe
		 * so we can use the same Pipe as Log
		 */
		snprintf(buf, sizeof(buf), "s%02d.%02d.%02d %02d:%02d:%02d %3.1f %s %s %d %d %d %d %d %d %d %ld %ld %02d:%02d:%02d %s %04X:%04X %s\n",
				 lt.tm_mday, lt.tm_mon + 1, lt.tm_year % 100,
				 lt.tm_hour, lt.tm_min, lt.tm_sec, cwps,
				 client->account->usr,
				 cs_inet_ntoa(client->ip),
				 client->port,
				 client->cwfound,
				 client->cwcache,
				 client->cwnot,
				 client->cwignored,
				 client->cwtout,
				 client->cwtun,
				 client->login,
				 client->last,
				 fullhours, mins, secs,
				 get_module(client)->desc,
				 client->last_caid,
				 client->last_srvid,
				 channame);

		cs_write_log_int(buf);
	}
}
Пример #30
0
static
jint check_bootstrap_loader(JNIEnv *env, jobject loader) {
    jvmtiError err = JVMTI_ERROR_NONE;
    jobject module = NULL;
    const char* exp_name = NULL;
    const char* mod_name = NULL;

    // NULL pointer for package name
    err = get_module(env, loader, NULL, &module, &mod_name);
    if (err != JVMTI_ERROR_NULL_POINTER) {
        throw_exc(env, "check #BN1: failed to return JVMTI_ERROR_NULL_POINTER for NULL package");
        return FAILED;
    }

    // NULL pointer for module_ptr
    err = (*jvmti)->GetNamedModule(jvmti, loader, "", NULL);
    if (err != JVMTI_ERROR_NULL_POINTER) {
        throw_exc(env, "check #BN2: failed to return JVMTI_ERROR_NULL_POINTER for NULL module_ptr");
        return FAILED;
    }

    // Unnamed/default package ""
    err = get_module(env, loader, "", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #B1: failed to return JVMTI_ERROR_NONE for default package");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #B2: failed to return NULL-module for default package");
        return FAILED;
    }

    // Normal package from java.base module: "java/lang"
    exp_name = "java.base";
    err = get_module(env, loader, "java/lang", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #B3: failed to return JVMTI_ERROR_NONE for java/lang package");
        return FAILED;
    }
    if (module == NULL || mod_name == NULL) {
        throw_exc(env, "check #B4: failed to return named module for java/lang package");
        return FAILED;
    }
    if (strcmp(exp_name, mod_name) != 0) {
        printf("check #B5: failed to return right module, expected: %s, returned: %s\n",
               exp_name, mod_name);
        throw_exc(env, "check #B5: failed to return expected module for java/lang package");
        return FAILED;
    }

    // Non-existing package: "bad/package/name"
    err = get_module(env, loader, "bad/package/name", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #B6: failed to return JVMTI_ERROR_NONE for bad package");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #B7: failed to return NULL-module for bad package");
        return FAILED;
    }
    return PASSED;
}