Skip to content

Commit 2086588

Browse files
IsaacWoodsrw-vanc
andcommitted
Make read_field and friends take a mutable context
This is necessary because these methods will need to invoke methods in the future. Co-authored-by: Ron Williams <[email protected]>
1 parent 616ccc5 commit 2086588

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

aml/src/expression.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ where
331331
DebugVerbosity::AllScopes,
332332
"DefIncrement",
333333
super_name().map_with_context(|addend, context| {
334-
let value = try_with_context!(context, context.read_target(&addend));
334+
let value = {
335+
let value = try_with_context!(context, context.read_target(&addend));
336+
value.clone()
337+
};
335338
let value = try_with_context!(context, value.as_integer(context));
336339
let new_value = AmlValue::Integer(value + 1);
337340
try_with_context!(context, context.store(addend, new_value.clone()));
@@ -353,7 +356,10 @@ where
353356
DebugVerbosity::AllScopes,
354357
"DefDecrement",
355358
super_name().map_with_context(|minuend, context| {
356-
let value = try_with_context!(context, context.read_target(&minuend));
359+
let value = {
360+
let value = try_with_context!(context, context.read_target(&minuend));
361+
value.clone()
362+
};
357363
let value = try_with_context!(context, value.as_integer(context));
358364
let new_value = AmlValue::Integer(value - 1);
359365
try_with_context!(context, context.store(minuend, new_value.clone()));

aml/src/lib.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,19 @@ impl AmlContext {
389389

390390
/// Read from an operation-region, performing only standard-sized reads (supported powers-of-2 only. If a field
391391
/// is not one of these sizes, it may need to be masked, or multiple reads may need to be performed).
392-
pub(crate) fn read_region(&self, region_handle: AmlHandle, offset: u64, length: u64) -> Result<u64, AmlError> {
392+
pub(crate) fn read_region(
393+
&mut self,
394+
region_handle: AmlHandle,
395+
offset: u64,
396+
length: u64,
397+
) -> Result<u64, AmlError> {
393398
use bit_field::BitField;
394399
use core::convert::TryInto;
395400
use value::RegionSpace;
396401

397402
let (region_space, region_base, _region_length, parent_device) = {
398403
if let AmlValue::OpRegion { region, offset, length, parent_device } =
399-
self.namespace.get(region_handle)?
404+
self.namespace.get(region_handle)?.clone()
400405
{
401406
(region, offset, length, parent_device)
402407
} else {
@@ -488,7 +493,7 @@ impl AmlContext {
488493

489494
let (region_space, region_base, _region_length, parent_device) = {
490495
if let AmlValue::OpRegion { region, offset, length, parent_device } =
491-
self.namespace.get(region_handle)?
496+
self.namespace.get(region_handle)?.clone()
492497
{
493498
(region, offset, length, parent_device)
494499
} else {
@@ -605,7 +610,8 @@ impl AmlContext {
605610
.add_value(
606611
AmlName::from_str("\\_OSI").unwrap(),
607612
AmlValue::native_method(1, false, 0, |context| {
608-
Ok(match context.current_arg(0)?.as_string(context)?.as_str() {
613+
let value = context.current_arg(0)?.clone();
614+
Ok(match value.as_string(context)?.as_str() {
609615
"Windows 2000" => true, // 2000
610616
"Windows 2001" => true, // XP
611617
"Windows 2001 SP1" => true, // XP SP1

aml/src/statement.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ where
224224
DebugVerbosity::Scopes,
225225
"DefSleep",
226226
term_arg().map_with_context(|milliseconds, context| {
227-
let milliseconds = try_with_context!(context, milliseconds.as_integer(&context));
227+
let milliseconds = try_with_context!(context, milliseconds.as_integer(context));
228228
context.handler.sleep(milliseconds);
229229
(Ok(()), context)
230230
}),
@@ -245,7 +245,7 @@ where
245245
DebugVerbosity::Scopes,
246246
"DefStall",
247247
term_arg().map_with_context(|microseconds, context| {
248-
let microseconds = try_with_context!(context, microseconds.as_integer(&context));
248+
let microseconds = try_with_context!(context, microseconds.as_integer(context));
249249
context.handler.stall(microseconds);
250250
(Ok(()), context)
251251
}),

aml/src/value.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl AmlValue {
288288
}
289289
}
290290

291-
pub fn as_integer(&self, context: &AmlContext) -> Result<u64, AmlError> {
291+
pub fn as_integer(&self, context: &mut AmlContext) -> Result<u64, AmlError> {
292292
match self {
293293
AmlValue::Integer(value) => Ok(*value),
294294
AmlValue::Boolean(value) => Ok(if *value { u64::max_value() } else { 0 }),
@@ -320,7 +320,7 @@ impl AmlValue {
320320
}
321321
}
322322

323-
pub fn as_buffer(&self, context: &AmlContext) -> Result<Arc<Spinlock<Vec<u8>>>, AmlError> {
323+
pub fn as_buffer(&self, context: &mut AmlContext) -> Result<Arc<Spinlock<Vec<u8>>>, AmlError> {
324324
match self {
325325
AmlValue::Buffer(ref bytes) => Ok(bytes.clone()),
326326
// TODO: implement conversion of String and Integer to Buffer
@@ -330,7 +330,7 @@ impl AmlValue {
330330
}
331331
}
332332

333-
pub fn as_string(&self, context: &AmlContext) -> Result<String, AmlError> {
333+
pub fn as_string(&self, context: &mut AmlContext) -> Result<String, AmlError> {
334334
match self {
335335
AmlValue::String(ref string) => Ok(string.clone()),
336336
// TODO: implement conversion of Buffer to String
@@ -404,7 +404,7 @@ impl AmlValue {
404404
/// `Integer` from: `Buffer`, `BufferField`, `DdbHandle`, `FieldUnit`, `String`, `Debug`
405405
/// `Package` from: `Debug`
406406
/// `String` from: `Integer`, `Buffer`, `Debug`
407-
pub fn as_type(&self, desired_type: AmlType, context: &AmlContext) -> Result<AmlValue, AmlError> {
407+
pub fn as_type(&self, desired_type: AmlType, context: &mut AmlContext) -> Result<AmlValue, AmlError> {
408408
// If the value is already of the correct type, just return it as is
409409
if self.type_of() == desired_type {
410410
return Ok(self.clone());
@@ -423,7 +423,7 @@ impl AmlValue {
423423

424424
/// Reads from a field of an opregion, returning either a `AmlValue::Integer` or an `AmlValue::Buffer`,
425425
/// depending on the size of the field.
426-
pub fn read_field(&self, context: &AmlContext) -> Result<AmlValue, AmlError> {
426+
pub fn read_field(&self, context: &mut AmlContext) -> Result<AmlValue, AmlError> {
427427
if let AmlValue::Field { region, flags, offset, length } = self {
428428
let _maximum_access_size = {
429429
if let AmlValue::OpRegion { region, .. } = context.namespace.get(*region)? {

0 commit comments

Comments
 (0)