exstorob.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /******************************************************************************
  2. *
  3. * Module Name: exstorob - AML Interpreter object store support, store to object
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acinterp.h"
  45. #define _COMPONENT ACPI_EXECUTER
  46. ACPI_MODULE_NAME("exstorob")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_ex_store_buffer_to_buffer
  50. *
  51. * PARAMETERS: source_desc - Source object to copy
  52. * target_desc - Destination object of the copy
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Copy a buffer object to another buffer object.
  57. *
  58. ******************************************************************************/
  59. acpi_status
  60. acpi_ex_store_buffer_to_buffer(union acpi_operand_object *source_desc,
  61. union acpi_operand_object *target_desc)
  62. {
  63. u32 length;
  64. u8 *buffer;
  65. ACPI_FUNCTION_TRACE_PTR(ex_store_buffer_to_buffer, source_desc);
  66. /* We know that source_desc is a buffer by now */
  67. buffer = ACPI_CAST_PTR(u8, source_desc->buffer.pointer);
  68. length = source_desc->buffer.length;
  69. /*
  70. * If target is a buffer of length zero or is a static buffer,
  71. * allocate a new buffer of the proper length
  72. */
  73. if ((target_desc->buffer.length == 0) ||
  74. (target_desc->common.flags & AOPOBJ_STATIC_POINTER)) {
  75. target_desc->buffer.pointer = ACPI_ALLOCATE(length);
  76. if (!target_desc->buffer.pointer) {
  77. return_ACPI_STATUS(AE_NO_MEMORY);
  78. }
  79. target_desc->buffer.length = length;
  80. }
  81. /* Copy source buffer to target buffer */
  82. if (length <= target_desc->buffer.length) {
  83. /* Clear existing buffer and copy in the new one */
  84. ACPI_MEMSET(target_desc->buffer.pointer, 0,
  85. target_desc->buffer.length);
  86. ACPI_MEMCPY(target_desc->buffer.pointer, buffer, length);
  87. #ifdef ACPI_OBSOLETE_BEHAVIOR
  88. /*
  89. * NOTE: ACPI versions up to 3.0 specified that the buffer must be
  90. * truncated if the string is smaller than the buffer. However, "other"
  91. * implementations of ACPI never did this and thus became the defacto
  92. * standard. ACPI 3.0_a changes this behavior such that the buffer
  93. * is no longer truncated.
  94. */
  95. /*
  96. * OBSOLETE BEHAVIOR:
  97. * If the original source was a string, we must truncate the buffer,
  98. * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
  99. * copy must not truncate the original buffer.
  100. */
  101. if (original_src_type == ACPI_TYPE_STRING) {
  102. /* Set the new length of the target */
  103. target_desc->buffer.length = length;
  104. }
  105. #endif
  106. } else {
  107. /* Truncate the source, copy only what will fit */
  108. ACPI_MEMCPY(target_desc->buffer.pointer, buffer,
  109. target_desc->buffer.length);
  110. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  111. "Truncating source buffer from %X to %X\n",
  112. length, target_desc->buffer.length));
  113. }
  114. /* Copy flags */
  115. target_desc->buffer.flags = source_desc->buffer.flags;
  116. target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
  117. return_ACPI_STATUS(AE_OK);
  118. }
  119. /*******************************************************************************
  120. *
  121. * FUNCTION: acpi_ex_store_string_to_string
  122. *
  123. * PARAMETERS: source_desc - Source object to copy
  124. * target_desc - Destination object of the copy
  125. *
  126. * RETURN: Status
  127. *
  128. * DESCRIPTION: Copy a String object to another String object
  129. *
  130. ******************************************************************************/
  131. acpi_status
  132. acpi_ex_store_string_to_string(union acpi_operand_object *source_desc,
  133. union acpi_operand_object *target_desc)
  134. {
  135. u32 length;
  136. u8 *buffer;
  137. ACPI_FUNCTION_TRACE_PTR(ex_store_string_to_string, source_desc);
  138. /* We know that source_desc is a string by now */
  139. buffer = ACPI_CAST_PTR(u8, source_desc->string.pointer);
  140. length = source_desc->string.length;
  141. /*
  142. * Replace existing string value if it will fit and the string
  143. * pointer is not a static pointer (part of an ACPI table)
  144. */
  145. if ((length < target_desc->string.length) &&
  146. (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
  147. /*
  148. * String will fit in existing non-static buffer.
  149. * Clear old string and copy in the new one
  150. */
  151. ACPI_MEMSET(target_desc->string.pointer, 0,
  152. (acpi_size) target_desc->string.length + 1);
  153. ACPI_MEMCPY(target_desc->string.pointer, buffer, length);
  154. } else {
  155. /*
  156. * Free the current buffer, then allocate a new buffer
  157. * large enough to hold the value
  158. */
  159. if (target_desc->string.pointer &&
  160. (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
  161. /* Only free if not a pointer into the DSDT */
  162. ACPI_FREE(target_desc->string.pointer);
  163. }
  164. target_desc->string.pointer = ACPI_ALLOCATE_ZEROED((acpi_size)
  165. length + 1);
  166. if (!target_desc->string.pointer) {
  167. return_ACPI_STATUS(AE_NO_MEMORY);
  168. }
  169. target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
  170. ACPI_MEMCPY(target_desc->string.pointer, buffer, length);
  171. }
  172. /* Set the new target length */
  173. target_desc->string.length = length;
  174. return_ACPI_STATUS(AE_OK);
  175. }