utcopy.c

来自「是关于linux2.5.1的完全源码」· C语言 代码 · 共 877 行 · 第 1/2 页

C
877
字号
		if (!internal_object) {			return_ACPI_STATUS (AE_NO_MEMORY);		}		break;	default:		/*		 * Whatever other type -- it is not supported		 */		return_ACPI_STATUS (AE_SUPPORT);	}	switch (external_object->type) {	/* Must COPY string and buffer contents */	case ACPI_TYPE_STRING:		internal_object->string.pointer = ACPI_MEM_CALLOCATE (external_object->string.length + 1);		if (!internal_object->string.pointer) {			return_ACPI_STATUS (AE_NO_MEMORY);		}		ACPI_MEMCPY (internal_object->string.pointer,				  external_object->string.pointer,				  external_object->string.length);		internal_object->string.length = external_object->string.length;		break;	case ACPI_TYPE_BUFFER:		internal_object->buffer.pointer = ACPI_MEM_CALLOCATE (external_object->buffer.length);		if (!internal_object->buffer.pointer) {			return_ACPI_STATUS (AE_NO_MEMORY);		}		ACPI_MEMCPY (internal_object->buffer.pointer,				  external_object->buffer.pointer,				  external_object->buffer.length);		internal_object->buffer.length = external_object->buffer.length;		break;	case ACPI_TYPE_INTEGER:		internal_object->integer.value  = external_object->integer.value;		break;	}	*ret_internal_object = internal_object;	return_ACPI_STATUS (AE_OK);}#ifdef ACPI_FUTURE_IMPLEMENTATION/* Code to convert packages that are parameters to control methods *//******************************************************************************* * * FUNCTION:    Acpi_ut_copy_epackage_to_ipackage * * PARAMETERS:  *Internal_object   - Pointer to the object we are returning *              *Buffer         - Where the object is returned *              *Space_used     - Where the length of the object is returned * * RETURN:      Status          - the status of the call * * DESCRIPTION: This function is called to place a package object in a user *              buffer.  A package object by definition contains other objects. * *              The buffer is assumed to have sufficient space for the object. *              The caller must have verified the buffer length needed using the *              Acpi_ut_get_object_size function before calling this function. * ******************************************************************************/static acpi_statusacpi_ut_copy_epackage_to_ipackage (	acpi_operand_object     *internal_object,	u8                      *buffer,	u32                     *space_used){	u8                      *free_space;	acpi_object             *external_object;	u32                     length = 0;	u32                     this_index;	u32                     object_space = 0;	acpi_operand_object     *this_internal_obj;	acpi_object             *this_external_obj;	ACPI_FUNCTION_TRACE ("Ut_copy_epackage_to_ipackage");	/*	 * First package at head of the buffer	 */	external_object = (acpi_object *)buffer;	/*	 * Free space begins right after the first package	 */	free_space = buffer + sizeof(acpi_object);	external_object->type              = internal_object->common.type;	external_object->package.count     = internal_object->package.count;	external_object->package.elements  = (acpi_object *)free_space;	/*	 * Build an array of ACPI_OBJECTS in the buffer	 * and move the free space past it	 */	free_space += external_object->package.count * sizeof(acpi_object);	/* Call Walk_package */}#endif /* Future implementation *//******************************************************************************* * * FUNCTION:    Acpi_ut_copy_eobject_to_iobject * * PARAMETERS:  *Internal_object   - The external object to be converted *              *Buffer_ptr     - Where the internal object is returned * * RETURN:      Status          - the status of the call * * DESCRIPTION: Converts an external object to an internal object. * ******************************************************************************/acpi_statusacpi_ut_copy_eobject_to_iobject (	acpi_object             *external_object,	acpi_operand_object     **internal_object){	acpi_status             status;	ACPI_FUNCTION_TRACE ("Ut_copy_eobject_to_iobject");	if (external_object->type == ACPI_TYPE_PACKAGE) {		/*		 * Packages as external input to control methods are not supported,		 */		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,			"Packages as parameters not implemented!\n"));		return_ACPI_STATUS (AE_NOT_IMPLEMENTED);	}	else {		/*		 * Build a simple object (no nested objects)		 */		status = acpi_ut_copy_esimple_to_isimple (external_object, internal_object);	}	return_ACPI_STATUS (status);}/******************************************************************************* * * FUNCTION:    Acpi_ut_copy_simple_object * * PARAMETERS:  Source_desc         - The internal object to be copied *              Dest_desc           - New target object * * RETURN:      Status * * DESCRIPTION: Simple copy of one internal object to another.  Reference count *              of the destination object is preserved. * ******************************************************************************/acpi_statusacpi_ut_copy_simple_object (	acpi_operand_object     *source_desc,	acpi_operand_object     *dest_desc){	u16                     reference_count;	acpi_operand_object     *next_object;	/* Save fields from destination that we don't want to overwrite */	reference_count = dest_desc->common.reference_count;	next_object = dest_desc->common.next_object;	/* Copy the entire source object over the destination object*/	ACPI_MEMCPY ((char *) dest_desc, (char *) source_desc, sizeof (acpi_operand_object));	/* Restore the saved fields */	dest_desc->common.reference_count = reference_count;	dest_desc->common.next_object = next_object;	/* Handle the objects with extra data */	switch (dest_desc->common.type) {	case ACPI_TYPE_BUFFER:		dest_desc->buffer.node = NULL;		dest_desc->common.flags = source_desc->common.flags;		/* Fall through to common string/buffer case */	case ACPI_TYPE_STRING:		/*		 * Allocate and copy the actual string if and only if:		 * 1) There is a valid string (length > 0)		 * 2) The string is not static (not in an ACPI table) (in this case,		 *    the actual pointer was already copied above)		 */		if ((source_desc->string.length) &&			(!(source_desc->common.flags & AOPOBJ_STATIC_POINTER))) {			dest_desc->string.pointer = ACPI_MEM_ALLOCATE (source_desc->string.length);			if (!dest_desc->string.pointer) {				return (AE_NO_MEMORY);			}			ACPI_MEMCPY (dest_desc->string.pointer, source_desc->string.pointer,					  source_desc->string.length);		}		break;	}	return (AE_OK);}/******************************************************************************* * * FUNCTION:    Acpi_ut_copy_ielement_to_ielement * * PARAMETERS:  ACPI_PKG_CALLBACK * * RETURN:      Status * * DESCRIPTION: Copy one package element to another package element * ******************************************************************************/acpi_statusacpi_ut_copy_ielement_to_ielement (	u8                      object_type,	acpi_operand_object     *source_object,	acpi_generic_state      *state,	void                    *context){	acpi_status             status = AE_OK;	u32                     this_index;	acpi_operand_object     **this_target_ptr;	acpi_operand_object     *target_object;	ACPI_FUNCTION_ENTRY ();	this_index    = state->pkg.index;	this_target_ptr = (acpi_operand_object **)			   &state->pkg.dest_object->package.elements[this_index];	switch (object_type) {	case 0:		/*		 * This is a simple object, just copy it		 */		target_object = acpi_ut_create_internal_object (source_object->common.type);		if (!target_object) {			return (AE_NO_MEMORY);		}		status = acpi_ut_copy_simple_object (source_object, target_object);		if (ACPI_FAILURE (status)) {			return (status);		}		*this_target_ptr = target_object;		break;	case 1:		/*		 * This object is a package - go down another nesting level		 * Create and build the package object		 */		target_object = acpi_ut_create_internal_object (ACPI_TYPE_PACKAGE);		if (!target_object) {			return (AE_NO_MEMORY);		}		target_object->package.count = source_object->package.count;		target_object->common.flags = source_object->common.flags;		/*		 * Pass the new package object back to the package walk routine		 */		state->pkg.this_target_obj = target_object;		/*		 * Store the object pointer in the parent package object		 */		*this_target_ptr = target_object;		break;	default:		return (AE_BAD_PARAMETER);	}	return (status);}/******************************************************************************* * * FUNCTION:    Acpi_ut_copy_ipackage_to_ipackage * * PARAMETERS:  *Source_obj     - Pointer to the source package object *              *Dest_obj       - Where the internal object is returned * * RETURN:      Status          - the status of the call * * DESCRIPTION: This function is called to copy an internal package object *              into another internal package object. * ******************************************************************************/acpi_statusacpi_ut_copy_ipackage_to_ipackage (	acpi_operand_object     *source_obj,	acpi_operand_object     *dest_obj,	acpi_walk_state         *walk_state){	acpi_status             status = AE_OK;	ACPI_FUNCTION_TRACE ("Ut_copy_ipackage_to_ipackage");	dest_obj->common.type   = source_obj->common.type;	dest_obj->common.flags  = source_obj->common.flags;	dest_obj->package.count = source_obj->package.count;	/*	 * Create the object array and walk the source package tree	 */	dest_obj->package.elements = ACPI_MEM_CALLOCATE ((source_obj->package.count + 1) *			 sizeof (void *));	if (!dest_obj->package.elements) {		ACPI_REPORT_ERROR (			("Aml_build_copy_internal_package_object: Package allocation failure\n"));		return_ACPI_STATUS (AE_NO_MEMORY);	}	/*	 * Copy the package element-by-element by walking the package "tree".	 * This handles nested packages of arbitrary depth.	 */	status = acpi_ut_walk_package_tree (source_obj, dest_obj,			 acpi_ut_copy_ielement_to_ielement, walk_state);	if (ACPI_FAILURE (status)) {		/* On failure, delete the destination package object */		acpi_ut_remove_reference (dest_obj);	}	return_ACPI_STATUS (status);}/******************************************************************************* * * FUNCTION:    Acpi_ut_copy_iobject_to_iobject * * PARAMETERS:  Walk_state          - Current walk state *              Source_desc         - The internal object to be copied *              Dest_desc           - Where the copied object is returned * * RETURN:      Status * * DESCRIPTION: Copy an internal object to a new internal object * ******************************************************************************/acpi_statusacpi_ut_copy_iobject_to_iobject (	acpi_operand_object     *source_desc,	acpi_operand_object     **dest_desc,	acpi_walk_state         *walk_state){	acpi_status             status = AE_OK;	ACPI_FUNCTION_TRACE ("Ut_copy_iobject_to_iobject");	/* Create the top level object */	*dest_desc = acpi_ut_create_internal_object (source_desc->common.type);	if (!*dest_desc) {		return_ACPI_STATUS (AE_NO_MEMORY);	}	/* Copy the object and possible subobjects */	if (source_desc->common.type == ACPI_TYPE_PACKAGE) {		status = acpi_ut_copy_ipackage_to_ipackage (source_desc, *dest_desc,				  walk_state);	}	else {		status = acpi_ut_copy_simple_object (source_desc, *dest_desc);	}	return_ACPI_STATUS (status);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?