Пример #1
0
// Resize an IString buffer (if dynamically allocated)
ZString IString_Resize (
	IStringPtr self,
	u32 buf_len
	)
{
	ESIF_ASSERT(self);
	// Allocate initial buffer if it has never been allocated
	if (self->buf_ptr == 0) {
		self->buf_ptr = esif_ccb_malloc(buf_len);
		if (self->buf_ptr) {
			self->buf_len  = buf_len;
			self->data_len = 1;
			return (ZString)self->buf_ptr;
		}
	}
	// Resize buffer if it is not a static string
	if (self->buf_len > 0) {
		ZString buf_ptr = (ZString)esif_ccb_realloc(self->buf_ptr, buf_len);
		if (buf_ptr) {
			if (buf_len > self->buf_len) {
				esif_ccb_memset(buf_ptr + self->buf_len, 0, buf_len - self->buf_len);
			}
			self->buf_ptr = buf_ptr;
			self->buf_len = buf_len;
			return (ZString)self->buf_ptr;
		}
	}
	return 0;
}
Пример #2
0
void EsifAppMgrExit()
{
	u8 i = 0;
	EsifAppPtr a_app_ptr = NULL;

	ESIF_TRACE_ENTRY_INFO();

	EsifEventMgr_UnregisterEventByType(ESIF_EVENT_PARTICIPANT_SUSPEND, EVENT_MGR_MATCH_ANY, EVENT_MGR_DOMAIN_D0, EsifAppMgr_EventCallback, NULL);
	EsifEventMgr_UnregisterEventByType(ESIF_EVENT_PARTICIPANT_RESUME, EVENT_MGR_MATCH_ANY, EVENT_MGR_DOMAIN_D0, EsifAppMgr_EventCallback, NULL);

	EsifAppExit();
	ESIF_TRACE_DEBUG("Exit Action Manager (APPMGR)");

	esif_ccb_read_lock(&g_appMgr.fLock);
	for (i = 0; i < ESIF_MAX_APPS; i++) {
		a_app_ptr = &g_appMgr.fEntries[i];

		// Attempt to gracefully shutdown App before forcing library unload
		if (a_app_ptr->fLibNamePtr != NULL) {
			EsifAppStop(a_app_ptr);
		}
		if (a_app_ptr->fLibNamePtr != NULL) {
			esif_ccb_library_unload(a_app_ptr->fLibHandle);
			esif_ccb_free(a_app_ptr->fLibNamePtr);
			esif_ccb_memset(a_app_ptr, 0, sizeof(*a_app_ptr));
		}
	}
	esif_ccb_read_unlock(&g_appMgr.fLock);

	esif_ccb_lock_uninit(&g_appMgr.fLock);

	ESIF_TRACE_EXIT_INFO();
}
Пример #3
0
/*
 * This function processes requests for either websocket connections or
 * http connections.
 */
static eEsifError esif_ws_client_process_request(ClientRecordPtr clientPtr)
{
	eEsifError result = ESIF_OK;
	size_t messageLength  = 0;
	
	esif_ccb_memset(g_ws_http_buffer, 0, WS_BUFFER_LENGTH);

	/*Pull the next message from the client socket */
	messageLength = (size_t)recv(clientPtr->socket, (char*)g_ws_http_buffer, WS_BUFFER_LENGTH, 0);
	if (messageLength == 0 || messageLength == SOCKET_ERROR) {
		ESIF_TRACE_DEBUG("no messages received from the socket\n");
		result =  ESIF_E_WS_DISC;
		goto exit;
	} else {
		ESIF_TRACE_DEBUG("%d bytes received\n", (int)messageLength);
	}

	if (clientPtr->state == STATE_NORMAL) {
		result = esif_ws_client_process_active_client(clientPtr, (char *)g_ws_http_buffer, WS_BUFFER_LENGTH, messageLength);
		goto exit;
	}

	if (clientPtr->state == STATE_OPENING) {
		result = esif_ws_client_open_client(clientPtr, (char *)g_ws_http_buffer, WS_BUFFER_LENGTH, messageLength);
		goto exit;
	}

	result =  ESIF_E_WS_DISC;
exit:
	return result;
}
Пример #4
0
void EsifActMgrExit()
{
	u8 i = 0;
	EsifActPtr a_act_ptr = NULL;

	ESIF_TRACE_ENTRY_INFO();

	/* Call before destroying action manager */
	EsifActExit();

	if (NULL != g_actMgr.fActTypes) {
		esif_link_list_destroy(g_actMgr.fActTypes);
		g_actMgr.fActTypes = NULL;  //set to null so that it will be caught if mid-execution
	}

	esif_ccb_read_lock(&g_actMgr.fLock);
	for (i = 0; i < ESIF_MAX_ACTIONS; i++) {
		a_act_ptr = &g_actMgr.fEnrtries[i];
		esif_ccb_free(a_act_ptr->fLibNamePtr);
		esif_ccb_library_unload(a_act_ptr->fLibHandle);
		esif_ccb_memset(a_act_ptr, 0, sizeof(*a_act_ptr));
	}
	esif_ccb_read_unlock(&g_actMgr.fLock);

	esif_ccb_lock_uninit(&g_actMgr.fLock);

	ESIF_TRACE_EXIT_INFO();
}
Пример #5
0
void esif_dsp_table_destroy()
{
	UInt8 i;
	ESIF_TRACE_INFO("Destroy DSP Table");
	for (i = 0; i < g_dm.dme_count; i++) {
		esif_dsp_destroy(g_dm.dme[i].dsp_ptr);
		esif_ccb_free(g_dm.dme[i].file_ptr);
		esif_ccb_free(g_dm.dme[i].fpc_ptr);
		esif_ccb_memset(&g_dm.dme[i], 0, sizeof(g_dm.dme[i]));
	}
	g_dm.dme_count = 0;
}
Пример #6
0
/*
 * Used to iterate through the available participants.
 * First call EsifActMgr_InitIterator to initialize the iterator.
 * Next, call EsifActMgr_GetNexAction using the iterator.  Repeat until
 * EsifActMgr_GetNexAction fails. The call will release the reference of the
 * participant from the previous call.  If you stop iteration part way through
 * all participants, the caller is responsible for releasing the reference on
 * the last participant returned.  Iteration is complete when
 * ESIF_E_ITERATOR_DONE is returned.
 */
eEsifError EsifActMgr_InitIterator(
	ActMgrIteratorPtr iteratorPtr
	)
{
	eEsifError rc = ESIF_OK;

	if (NULL == iteratorPtr) {
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}

	esif_ccb_memset(iteratorPtr, 0, sizeof(*iteratorPtr));
	iteratorPtr->marker = ACT_MGR_ITERATOR_MARKER;
exit:
	return rc;
}
Пример #7
0
void EsifLogMgrExit(void)
{
	int j;

	ESIF_TRACE_ENTRY_INFO();

	for (j=0; j < MAX_ESIFLOG; j++) {
		if (g_EsifLogFile[j].handle != NULL) {
			esif_ccb_fclose(g_EsifLogFile[j].handle);
		}
		esif_ccb_free(g_EsifLogFile[j].name);
		esif_ccb_free(g_EsifLogFile[j].filename);
		esif_ccb_lock_uninit(&g_EsifLogFile[j].lock);
	}
	esif_ccb_memset(g_EsifLogFile, 0, sizeof(g_EsifLogFile));

	ESIF_TRACE_EXIT_INFO();
}
Пример #8
0
static eEsifError init_fpc_iterator(
	EsifDspPtr dspPtr,
	EsifFpcDomainIteratorPtr iteratorPtr
	)
{
	eEsifError rc = ESIF_OK;

	if ((NULL == dspPtr) || (NULL == iteratorPtr)) {
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}

	esif_ccb_memset(iteratorPtr, 0, sizeof(*iteratorPtr));
	iteratorPtr->marker = FPC_DOMAIN_ITERATOR_MARKER;
	iteratorPtr->currPtr = dspPtr->domain_ptr->head_ptr;
exit:
	return rc;
}
Пример #9
0
eEsifError EsifLogMgrInit(void)
{
	int j;

	ESIF_TRACE_ENTRY_INFO();

	esif_ccb_memset(g_EsifLogFile, 0, sizeof(g_EsifLogFile));
	for (j=0; j < MAX_ESIFLOG; j++) {
		esif_ccb_lock_init(&g_EsifLogFile[j].lock);
	}
	g_EsifLogFile[ESIF_LOG_EVENTLOG].name = esif_ccb_strdup("event");
	g_EsifLogFile[ESIF_LOG_DEBUGGER].name = esif_ccb_strdup("debug");
	g_EsifLogFile[ESIF_LOG_SHELL].name    = esif_ccb_strdup("shell");
	g_EsifLogFile[ESIF_LOG_TRACE].name    = esif_ccb_strdup("trace");
	g_EsifLogFile[ESIF_LOG_UI].name       = esif_ccb_strdup("ui");

	ESIF_TRACE_EXIT_INFO();
	return ESIF_OK;
}
Пример #10
0
void EsifCnjMgrExit()
{
    u8 i = 0;
    EsifCnjPtr a_conjure_ptr = NULL;

    EsifCnjExit();
    ESIF_TRACE_DEBUG("%s: Exit Action Manager (CNJMGR)", ESIF_FUNC);

    esif_ccb_read_lock(&g_cnjMgr.fLock);
    for (i = 0; i < ESIF_MAX_CONJURES; i++) {
        a_conjure_ptr = &g_cnjMgr.fEnrtries[i];
        esif_ccb_free(a_conjure_ptr->fLibNamePtr);
        esif_ccb_library_unload(a_conjure_ptr->fLibHandle);
        esif_ccb_memset(a_conjure_ptr, 0, sizeof(*a_conjure_ptr));
    }
    esif_ccb_read_unlock(&g_cnjMgr.fLock);

    esif_ccb_lock_uninit(&g_cnjMgr.fLock);

    ESIF_TRACE_EXIT_INFO();
}
Пример #11
0
// Search and Replace
ZString IString_ReplaceIString (
	IStringPtr self,
	IStringPtr what,
	IStringPtr with,
	int IgnoreCase
	)
{
	ZString from, to, find;
	u32 count, oldsize, newsize;

	// Sanity checks. Cannot replace an empty string
	ESIF_ASSERT(self && what && with);
	if (self->data_len <= 1 || what->data_len <= 1) {
		return 0;
	}

	// Count occurances of replacment string in original string
	for (count = 0, find = (ZString)self->buf_ptr; (find = (ZString)strfind(find, (ZString)what->buf_ptr, IgnoreCase)) != NULL; count++)
		find += what->data_len - 1;

	// Compute new string size and Resize if necessary
	oldsize = self->data_len;
	newsize = self->data_len + (count * (int)(esif_ccb_max(with->data_len, 1) - what->data_len));
	if (newsize > self->buf_len) {
#ifdef ISTRING_AUTOGROW
		if (IString_Resize(self, newsize + ISTRING_AUTOGROW) == NULL)
#endif
		return 0;
	}

	// Do an in-string replacement so that another copy of the string does not need to be allocated
	// a) newsize <= oldsize: Do a left-to-right copy replacment
	// b) newsize >  oldsize: Move string to end of newsize buffer, then do a left-to-right copy replacement
	from = to = (ZString)self->buf_ptr;
	self->data_len = newsize;
	if (newsize > oldsize) {
		// Move string to end of reallocated (data_len) buffer
		esif_ccb_memmove(((ZString)self->buf_ptr) + (newsize - oldsize), (ZString)self->buf_ptr, oldsize);
		from += newsize - oldsize;
	}
	// Do a left-to-right copy (from -> to), replacing each occurance of old string (what) with new string (with)
	while ((find = (ZString)strfind(from, (ZString)what->buf_ptr, IgnoreCase)) != NULL) {
		if (from > to) {
			esif_ccb_memcpy(to, from, (size_t)(find - from));
		}
		to += (size_t)(find - from);
		if (with->data_len > 0) {
			esif_ccb_memcpy(to, (ZString)with->buf_ptr, with->data_len - 1);
			to += with->data_len - 1;
		}
		from = find + (what->data_len > 0 ? what->data_len - 1 : 0);
	}
	// Copy remainder of string, if any
	if (to < from) {
		esif_ccb_memcpy(to, from, newsize - (size_t)(to - (ZString)self->buf_ptr));
	}
	to += newsize - (size_t)(to - (ZString)self->buf_ptr);
	// zero out remainder of old string, if any
	if (oldsize > newsize) {
		esif_ccb_memset(to, 0, oldsize - newsize);
	}
	return (ZString)self->buf_ptr;
}
Пример #12
0
void *esif_memtrace_alloc(
	void *old_ptr,
	size_t size,
	const char *func,
	const char *file,
	int line
	)
{
	struct memalloc_s *mem = NULL;
	struct memalloc_s **last = NULL;
	void *mem_ptr = NULL;

	esif_ccb_write_lock(&g_memtrace.lock);
	mem = g_memtrace.allocated;
	last = &g_memtrace.allocated;

	if (file) {
		const char *slash = strrchr(file, *ESIF_PATH_SEP);
		if (slash) {
			file = slash + 1;
		}
	}

	if (old_ptr) {
		mem_ptr = native_realloc(old_ptr, size);

		// realloc(ptr, size) leaves ptr unaffected if realloc fails and size is nonzero
		if (!mem_ptr && size > 0) {
			goto exit;
		}
		while (mem) {
			if (old_ptr == mem->mem_ptr) {
				// realloc(ptr, 0) behaves like free(ptr)
				if (size == 0) {
					*last = mem->next;
					native_free(mem);
				} else {
					mem->mem_ptr = mem_ptr;
					mem->size    = size;
					mem->func    = func;
					mem->file    = file;
					mem->line    = line;
				}
				goto exit;
			}
			last = &mem->next;
			mem = mem->next;
		}
	} else {
		mem_ptr = native_malloc(size);
		if (mem_ptr) {
			esif_ccb_memset(mem_ptr, 0, size);
			atomic_inc(&g_memtrace.allocs);
		}
	}

	mem = (struct memalloc_s *)native_malloc(sizeof(*mem));
	if (!mem) {
		goto exit;
	}
	esif_ccb_memset(mem, 0, sizeof(*mem));
	mem->mem_ptr = mem_ptr;
	mem->size    = size;
	mem->func    = func;
	mem->file    = file;
	mem->line    = line;
	mem->next    = g_memtrace.allocated;
	g_memtrace.allocated = mem;
exit:
	esif_ccb_write_unlock(&g_memtrace.lock);
	return mem_ptr;
}
Пример #13
0
Guid::Guid(void)
    : m_valid(false)
{
    esif_ccb_memset(m_guid, 0, GuidSize);
}
Пример #14
0
/* Get Kernel Information */
static void esif_execute_ipc_command_get_memory_stats(
	struct esif_ipc_command *command_ptr
	)
{
	/* Sanity Check */
	if (ESIF_DATA_STRUCTURE == command_ptr->rsp_data_type &&
	    0 == command_ptr->rsp_data_offset &&
	    sizeof(struct esif_command_get_memory_stats) ==
	    command_ptr->rsp_data_len) {

		struct esif_command_get_memory_stats *data_ptr =
			(struct esif_command_get_memory_stats *)
			(command_ptr + 1);
		u32 reset = *(u32 *)data_ptr;

		if (reset) {
			esif_ccb_memset(&data_ptr->stats, 0,
					sizeof(struct esif_memory_stats));

			esif_ccb_write_lock(&g_memstat_lock);
			esif_ccb_memset(&g_memstat, 0,
					sizeof(struct esif_memory_stats));
			esif_ccb_write_unlock(&g_memstat_lock);
		} else {
			int i = 0;

			esif_ccb_read_lock(&g_memstat_lock);
			esif_ccb_memcpy(&data_ptr->stats, &g_memstat,
					sizeof(struct esif_memory_stats));
			esif_ccb_read_unlock(&g_memstat_lock);

			esif_ccb_read_lock(&g_mempool_lock);
			for (i = 0; i < ESIF_MEMPOOL_TYPE_MAX; i++) {
				if (NULL == g_mempool[i])
					continue;	/* Skip Unused */

				esif_ccb_strcpy(data_ptr->mempool_stat[i].name,
						g_mempool[i]->name_ptr,
						ESIF_NAME_LEN);
				data_ptr->mempool_stat[i].pool_tag    =
					g_mempool[i]->pool_tag;
				data_ptr->mempool_stat[i].object_size =
					g_mempool[i]->object_size;
				data_ptr->mempool_stat[i].alloc_count =
					g_mempool[i]->alloc_count;
				data_ptr->mempool_stat[i].free_count  =
					g_mempool[i]->free_count;
			}
			esif_ccb_read_unlock(&g_mempool_lock);

			esif_ccb_read_lock(&g_memtype_lock);
			for (i = 0; i < ESIF_MEMTYPE_TYPE_MAX; i++) {
				if (NULL == g_memtype[i])
					continue;	/* Skip Unused */

				esif_ccb_strcpy(data_ptr->memtype_stat[i].name,
						g_memtype[i]->name_ptr,
						ESIF_NAME_LEN);
				data_ptr->memtype_stat[i].pool_tag    =
					g_memtype[i]->type_tag;
				data_ptr->memtype_stat[i].alloc_count =
					g_memtype[i]->alloc_count;
				data_ptr->memtype_stat[i].free_count  =
					g_memtype[i]->free_count;
			}
			esif_ccb_read_unlock(&g_memtype_lock);
		}

		ESIF_TRACE_DYN_COMMAND(
			"%s: ESIF_COMMAND_TYPE_GET_MEMORY_STATS reset %d\n",
			ESIF_FUNC,
			reset);

		command_ptr->return_code = ESIF_OK;
	}
}
Пример #15
0
static int esif_ws_server_create_inet_addr(
	void *addrPtr,
	socklen_t *addrlenPtr,
	char *hostPtr,
	char *portPtr,
	char *protPtr
	)
{
	struct sockaddr_in *sockaddr_inPtr = (struct sockaddr_in*)addrPtr;
	struct hostent *hostenPtr  = NULL;
	struct servent *serventPtr = NULL;

	char *endStr;
	long longVal;

	if (!hostPtr) {
		hostPtr = (char*)"*";
	}

	if (!portPtr) {
		portPtr = (char*)"*";
	}

	if (!protPtr) {
		protPtr = (char*)"tcp";
	}


	esif_ccb_memset(sockaddr_inPtr, 0, *addrlenPtr);
	sockaddr_inPtr->sin_family = AF_INET;
	sockaddr_inPtr->sin_port   = 0;
	sockaddr_inPtr->sin_addr.s_addr = INADDR_ANY;


	if (esif_ccb_strcmp(hostPtr, "*") == 0) {
		;
	} else if (isdigit(*hostPtr)) {
		sockaddr_inPtr->sin_addr.s_addr = inet_addr(hostPtr);

		if (sockaddr_inPtr->sin_addr.s_addr == INADDR_NONE) {
			return -1;
		}
	} else {
		hostenPtr = gethostbyname(hostPtr);

		if (!hostenPtr) {
			return -1;
		}

		if (hostenPtr->h_addrtype != AF_INET) {
			return -1;
		}

		sockaddr_inPtr->sin_addr = *(struct in_addr*)

			hostenPtr->h_addr_list[0];
	}

	if (!esif_ccb_strcmp(portPtr, "*")) {
		;
	} else if (isdigit(*portPtr)) {
		longVal = strtol(portPtr, &endStr, 10);
		if (endStr != NULL && *endStr) {
			return -2;
		}

		if (longVal < 0L || longVal >= 32768) {
			return -2;
		}

		sockaddr_inPtr->sin_port = htons((short)longVal);
	} else {
		serventPtr = getservbyname(portPtr, protPtr);
		if (!serventPtr) {
			return -2;
		}

		sockaddr_inPtr->sin_port = (short)serventPtr->s_port;
	}

	*addrlenPtr = sizeof *sockaddr_inPtr;

	return 0;
}