Skip to content

Commit d37640b

Browse files
martin-hughesIsaacWoods
authored andcommitted
Move method context to do_execute_method
Then there's no way for re-entrancy to corrupt the stack. Fixes #292.
1 parent 7d42f88 commit d37640b

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/aml/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ where
105105
handler: H,
106106
pub namespace: Spinlock<Namespace>,
107107
pub object_token: Spinlock<ObjectToken>,
108-
context_stack: Spinlock<Vec<MethodContext>>,
109108
dsdt_revision: u8,
110109
region_handlers: Spinlock<BTreeMap<RegionSpace, Box<dyn RegionHandler>>>,
111110

@@ -141,7 +140,6 @@ where
141140
handler,
142141
namespace: Spinlock::new(Namespace::new(global_lock_mutex)),
143142
object_token: Spinlock::new(unsafe { ObjectToken::create_interpreter_token() }),
144-
context_stack: Spinlock::new(Vec::new()),
145143
dsdt_revision,
146144
region_handlers: Spinlock::new(BTreeMap::new()),
147145
global_lock_mutex,
@@ -434,6 +432,8 @@ where
434432
* traditional fast bytecode VM, but also provides enough flexibility to handle the
435433
* quirkier parts of the AML grammar, particularly the left-to-right encoding of operands.
436434
*/
435+
let mut context_stack: Vec<MethodContext> = Vec::new();
436+
437437
loop {
438438
/*
439439
* First, see if we've gathered enough arguments to complete some in-flight operations.
@@ -939,7 +939,7 @@ where
939939
let new_context =
940940
MethodContext::new_from_method(method.clone(), args, method_scope.clone())?;
941941
let old_context = mem::replace(&mut context, new_context);
942-
self.context_stack.lock().push(old_context);
942+
context_stack.push(old_context);
943943
context.retire_op(op);
944944
} else if let Object::NativeMethod { ref f, .. } = **method {
945945
let result = f(&args)?;
@@ -952,7 +952,7 @@ where
952952
extract_args!(op => [Argument::Object(object)]);
953953
let object = object.clone().unwrap_transparent_reference();
954954

955-
if let Some(last) = self.context_stack.lock().pop() {
955+
if let Some(last) = context_stack.pop() {
956956
context = last;
957957
context.contribute_arg(Argument::Object(object.clone()));
958958
context.retire_op(op);
@@ -1060,7 +1060,7 @@ where
10601060
BlockKind::Method { method_scope } => {
10611061
self.namespace.lock().remove_level(method_scope)?;
10621062

1063-
if let Some(prev_context) = self.context_stack.lock().pop() {
1063+
if let Some(prev_context) = context_stack.pop() {
10641064
context = prev_context;
10651065
continue;
10661066
} else {

tests/operation_region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn test_region_in_pci_device() {
146146
Device(TEST) {
147147
Name (_ADR, 0x00020001) // Arbitrary choice.
148148
Name (_BBN, 3)
149-
Name (_SEG, 4)
149+
Method (_SEG, 0, NotSerialized) { Return (4) }
150150
151151
OperationRegion(MEM, PCI_Config, 0x40, 0x20)
152152
Field(MEM, ByteAcc, NoLock, Preserve) {

0 commit comments

Comments
 (0)