PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
state.c
Go to the documentation of this file.
2
5
6#include <errno.h>
7
9{
10 for (uint8_t i = 0; i < AML_MAX_LOCALS; i++)
11 {
12 state->locals[i] = NULL;
13 }
14
15 uint8_t argIndex = 0;
16 if (args != NULL)
17 {
18 while (args[argIndex] != NULL)
19 {
20 if (argIndex >= AML_MAX_ARGS)
21 {
22 for (uint8_t j = 0; j < AML_MAX_LOCALS; j++)
23 {
24 UNREF(state->locals[j]);
25 }
26 for (uint8_t k = 0; k < argIndex; k++)
27 {
28 UNREF(state->args[k]);
29 }
30 errno = E2BIG;
31 return ERR;
32 }
33
35 if (arg == NULL || aml_arg_set(arg, args[argIndex]) == ERR)
36 {
37 if (arg != NULL)
38 {
39 UNREF(arg);
40 }
41 for (uint8_t j = 0; j < AML_MAX_LOCALS; j++)
42 {
43 UNREF(state->locals[j]);
44 }
45 for (uint8_t k = 0; k < argIndex; k++)
46 {
47 UNREF(state->args[k]);
48 }
49 return ERR;
50 }
51
52 state->args[argIndex] = &arg->arg;
53 state->args[argIndex]->name = AML_NAME('A', 'R', 'G', '0' + argIndex);
54 argIndex++;
55 }
56 }
57 for (; argIndex < AML_MAX_ARGS; argIndex++)
58 {
59 state->args[argIndex] = NULL;
60 }
61
62 state->result = NULL;
63 state->errorDepth = 0;
65 return 0;
66}
67
69{
70 for (uint8_t i = 0; i < AML_MAX_LOCALS; i++)
71 {
72 UNREF(state->locals[i]);
73 }
74 for (uint8_t i = 0; i < AML_MAX_ARGS; i++)
75 {
76 UNREF(state->args[i]);
77 }
78 if (state->result != NULL)
79 {
80 UNREF(state->result);
81 }
82 state->result = NULL;
83
85}
86
88{
89 if (state == NULL)
90 {
91 return NULL;
92 }
93
94 aml_object_t* result = aml_object_new();
95 if (result == NULL)
96 {
97 return NULL;
98 }
99
100 if (state->result == NULL)
101 {
102 // The method never had any expressions evaluated or explicitly returned a value.
103 if (aml_integer_set(result, 0) == ERR)
104 {
105 UNREF(result);
106 return NULL;
107 }
108 result->flags |= AML_OBJECT_EXCEPTION_ON_USE;
109 return result; // Transfer ownership
110 }
111
112 if (aml_copy_object(state, state->result, result) == ERR)
113 {
114 UNREF(result);
115 return NULL;
116 }
117 return result; // Transfer ownership
118}
119
121{
122 if (state == NULL)
123 {
124 return;
125 }
126
127 if (state->result != NULL)
128 {
129 UNREF(state->result);
130 state->result = NULL;
131 }
132
133 if (result != NULL)
134 {
135 state->result = REF(result);
136 }
137}
#define REF(ptr)
Increment reference count.
Definition ref.h:65
#define UNREF(ptr)
Decrement reference count.
Definition ref.h:80
#define errno
Error number variable.
Definition errno.h:27
#define E2BIG
Argument list too long.
Definition errno.h:67
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
uint64_t aml_copy_object(aml_state_t *state, aml_object_t *src, aml_object_t *dest)
Copies the data from the source object to the destination object.
Definition copy.c:93
#define AML_MAX_ARGS
Maximum number of arguments that can be passed to a method.
Definition arg.h:19
#define AML_MAX_LOCALS
Maximum number of local variables that can be used in a method.
Definition local.h:21
#define AML_NAME(a, b, c, d)
Macro to create an aml_name_t from 4 characters.
Definition namespace.h:112
void aml_overlay_deinit(aml_overlay_t *overlay)
Deinitialize a namespace overlay.
Definition namespace.c:551
void aml_overlay_init(aml_overlay_t *overlay)
Initialize a namespace overlay.
Definition namespace.c:539
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
Definition object.c:62
uint64_t aml_arg_set(aml_object_t *object, aml_object_t *value)
Set a object as an argument with the given target object.
Definition object.c:1236
uint64_t aml_integer_set(aml_object_t *object, aml_uint_t value)
Set a object as an integer with the given value and bit width.
Definition object.c:772
@ AML_OBJECT_EXCEPTION_ON_USE
Definition object.h:135
void aml_state_result_set(aml_state_t *state, aml_object_t *result)
Set the result object of the state.
Definition state.c:120
uint64_t aml_state_init(aml_state_t *state, aml_object_t **args)
Initialize an AML state.
Definition state.c:8
aml_object_t * aml_state_result_get(aml_state_t *state)
Get the result object of the state.
Definition state.c:87
void aml_state_deinit(aml_state_t *state)
Deinitialize an AML state.
Definition state.c:68
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
ACPI object.
Definition object.h:447
aml_arg_t arg
Definition object.h:471
AML State.
Definition state.h:25
aml_object_t * result
The return value, see aml_method_invoke() for details.
Definition state.h:28
aml_arg_t * args[AML_MAX_ARGS]
Argument variables for the method, if any.
Definition state.h:27
uint64_t errorDepth
The length of the error traceback, if 0 then no error has occurred.
Definition state.h:29
aml_local_t * locals[AML_MAX_LOCALS]
Local variables for the method, if any, initialized lazily.
Definition state.h:26
aml_overlay_t overlay
Holds any named objects created during parsing.
Definition state.h:30