summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2022-07-30program: fix en/decoding debuginfo upvalue slots in precompiled bytecodeJo-Philipp Wich
The sizeof(size_t) might differ from the sizeof(uint32_t) used to serialize compiled bytecode, so extra care is needed to properly encode and decode upvalue slot values which are defined as (size_t)-1 / 2 + n. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-30source: add tracking of exported symbolsJo-Philipp Wich
Extend abstract source objects to maintain a list of exported symbols and add functions to append and lookup exported names. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-30lib: honor constant flag of arraysJo-Philipp Wich
Reject modifications on array values with a type exception when the constant flag is set on the array operated upon. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-30types: resolve upvalue references on stringificationJo-Philipp Wich
When stringifying upvalue references, resolve their target value and convert it to a string. Only yield the abstract string representation if the target value cannot be resolved. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-28types: add ability to mark array and object values as constantJo-Philipp Wich
The upcoming module import support requires constant object values to implement module wildcard import. Reuse the existing u64 bit in ucv heads to mark array or object values as constant and add corresponding `ucv_is_constant()` and `ucv_set_constant()` helpers. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-28lexer: recognize module related keywordsJo-Philipp Wich
Add support for the `import`, `export`, `from` and `as` keywords used in module import and export statements. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-28lexer: rewrite token scannerJo-Philipp Wich
- Use nested switches instead of lookup tables to detect tokens - Simplify input buffer logic - Reduce amount of intermediate states Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-12Merge pull request #95 from jow-/lexer-fix-non-lstrip-parsingJo-Philipp Wich
lexer: fix parsing with disabled block left stripping
2022-07-12Merge pull request #94 from jow-/rtnl-fix-bridge-afspec-rtaJo-Philipp Wich
rtnl: fix parsing/creation of IFLA_AF_SPEC RTA for the AF_BRIDGE family
2022-07-12lexer: fix parsing with disabled block left strippingJo-Philipp Wich
When a template was parsed with global block left stripping disabled, then any text preceding an expression or statement block start tag was incorrectly prepended to the first token value of the block, leading to syntax errors in the compiler. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-03rtnl: fix parsing/creation of IFLA_AF_SPEC RTA for the AF_BRIDGE familyJo-Philipp Wich
Some pecularities in the encoding of the IFLA_AF_SPEC attribute make it unsuitable for table driven parsing/generation. To solve this issue, introduce specific datatype handling for IFLA_AF_SPEC and parse/generate the RTA depending on the address family of the containing netlink message. Also add some missing constants while we're at it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-30Merge pull request #93 from jow-/compiler-fix-switch-stack-mismatchJo-Philipp Wich
compiler: fix stack mismatch on continue statements nested in switches
2022-06-30compiler: fix stack mismatch on continue statements nested in switchesJo-Philipp Wich
When compiling continue statements nested in switches, the compiler only emitted pop statements for the local variables in the switch body scope, but not for the locals in the scope(s) leading up to the containing loop body. Extend the compilers internal patchlist structure to keep track of the type of scope tied to the patchlist and extend `continue` statement compilation logic to select the appropriate parent patch list in order to determine the amount of locals (stack slots) to clear before the emitted jump instruction. As a result, the `uc_compiler_backpatch()` implementation can be simplified somewhat since we do not need to propagate entries to parent lists anymore. Also add a further regression test case to cover this issue. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-29Merge pull request #91 from jow-/ubus-propagate-exceptionsJo-Philipp Wich
ubus: end uloop on exceptions in managed code
2022-06-29Merge pull request #92 from jow-/uloop-propagate-exceptionsJo-Philipp Wich
uloop: end uloop on exceptions in managed code
2022-06-29uloop: end uloop on exceptions in managed codeJo-Philipp Wich
Instead of silently continuing, end the uloop when encountering exceptions in ucode callbacks to let those exceptions propagate to the host program. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-29ubus: end uloop on exceptions in managed codeJo-Philipp Wich
Instead of silently continuing, end the uloop when encountering exceptions in ucode callbacks to let those exceptions propagate to the host program. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-29Merge pull request #90 from jow-/rtnl-expose-stats64Jo-Philipp Wich
rtnl: expose IFLA_STATS64 contents
2022-06-28rtnl: expose IFLA_STATS64 contentsJo-Philipp Wich
Decode IFLA_STATS64 attribute and make contained counters available to ucode. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-28Merge pull request #89 from jow-/rtnl-expose-ifi-changeJo-Philipp Wich
rtnl: expose ifinfomsg.ifi_change member
2022-06-28rtnl: expose ifinfomsg.ifi_change memberJo-Philipp Wich
For certain operations, such as bringing up interfaces, it is required to initialize the ifi_change mask in the ifinfomsg struct. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-28Merge pull request #86 from jow-/rtnl-fix-strict-chkJo-Philipp Wich
rtnl: update NETLINK_GET_STRICT_CHK socket flag with every request
2022-06-28Merge pull request #87 from jow-/compiler-fix-switch-stack-mismatchJo-Philipp Wich
compiler: fix stack mismatch on nonmatching switch statements with lo…
2022-06-28Merge pull request #88 from jow-/nl80211-fix-survey-info-noise-typeJo-Philipp Wich
nl80211: fix NL80211_SURVEY_INFO_NOISE datatype
2022-06-27rtnl: update NETLINK_GET_STRICT_CHK socket flag with every requestJo-Philipp Wich
So far the NETLINK_GET_STRICT_CHK socket flag was only set on the implicit socket creation performed during the first request and ignored for subsequent ones which made it impossible to perform only some requests with enabled strict checking. Modify the logic to check the flag state for every request and change it if needed. This allows performing both strict and non-strict requests over the same connection. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-27nl80211: fix NL80211_SURVEY_INFO_NOISE datatypeJo-Philipp Wich
Report the noise value as signed integer to calling ucode. Reported-by: John Crispin <john@phrozen.org> Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-27compiler: fix stack mismatch on nonmatching switch statements with localsJo-Philipp Wich
When a switch statement containing cases with local variable declarations and no default case is evalulated and none of the the cases matched, the local variable slots were never initialized but got popped off the stack when execution resumed after the switch scope, leading to a mismatch in stack layout between compiler and runtime, causing local variables to yield wrong values or a stack underflow triggering a segmentation fault. Solve this issue by patching the last conditional case match jump to hop beyond the local variable pop instructions when no default case is defined. Also extend the regression test case dealing with other switch related stack mismatch issues to cover this particular problem as well. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-18Merge pull request #85 from jow-/nl80211-add-sta-info-nlasJo-Philipp Wich
nl80211: recognize further NL80211_STA_INFO_* NLAs
2022-06-17nl80211: recognize further NL80211_STA_INFO_* NLAsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-08Merge pull request #84 from jow-/struct-add-unpack-offsetJo-Philipp Wich
struct: add optional offset argument to `unpack()`
2022-06-08struct: add optional offset argument to `unpack()`Jo-Philipp Wich
Extend the `unpack()` function to take an optional, second offset parameter which is useful to skip an initial portion of the input data without having to encode pad bytes into the format string. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-08Merge pull request #83 from jow-/rtnl-fix-linkinfo-segfaultJo-Philipp Wich
rtnl: fix segmentation fault on parsing linkinfo RTA without data
2022-06-08Merge pull request #82 from jow-/rtnl-zero-msghdrJo-Philipp Wich
rtnl: zero request message headers
2022-06-08Merge pull request #81 from jow-/rtnl-fix-ack-handlingJo-Philipp Wich
rtnl: fix premature netlink reply receive abort
2022-06-08rtnl: fix segmentation fault on parsing linkinfo RTA without dataJo-Philipp Wich
Some link types, such as veth, yield an IFLA_LINKINFO nla without an embedded IFLA_INFO_DATA / INFLA_INFO_SLAVE_DATA nla which causes the nla converter to dereference a NULL nla pointer. Properly deal with such cases and check for the existence of the child nla before attempting to parse it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-08Merge pull request #80 from jow-/rtnl-fix-leftover-bytesJo-Philipp Wich
rtnl: avoid stray "netlink: %d bytes leftover after parsing attributes."
2022-06-08Merge pull request #79 from jow-/struct-fix-packing-asteriskJo-Philipp Wich
struct: fix packing `*` format after other repeated formats
2022-06-08rtnl: zero request message headersJo-Philipp Wich
For route netlink request messages having a header struct, uc_nl_request() invokes nlmsg_reserve() to reserve room for the struct data but the nlmsg_reserve() function only zeroes additional alignment bytes, not the actual reserved buffer space. Extend the existing logic to explicitly zero out the reserved header space in order to avoid sending uninitialized struct member values to the kernel. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-08rtnl: fix premature netlink reply receive abortJo-Philipp Wich
The nl_recvmsgs() logic in uc_nl_request() incorrectly stopped reading the socket before the netlink ACK message was handled for non-multipart replies. This caused subsequent requests to incorrectly receive the ACK of the previous request, leading to a failure to receive the actual reply. Fix this issue by continue reading the socket until either the finish callback for multipart (dump) messages or the ack callback for non- multipart messages was received. This fix is basically the same as the one applied to the nl80211 module in 54ef6c0 ("nl80211: fix premature netlink reply receive abort"). Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-04rtnl: avoid stray "netlink: %d bytes leftover after parsing attributes."Jo-Philipp Wich
Some nested RTAs such as IFLA_INET_CONF do not contain actual sub-RTAs but just an array of integers. Avoid calling a no-op `nla_parse()` for such attributes to suppress the non-harmful leftover bytes warning emitted by libnl. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-04struct: fix packing `*` format after other repeated formatsJo-Philipp Wich
When packing a format such as `!6C*`, the `*` format was not included into the result buffer due to improper tracking of the function argument offset. Solve this issue by taking field repetitions into account when tracking the argument offset while calculating the size of dynamic arguments. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-01Merge pull request #78 from jow-/number-literalsJo-Philipp Wich
Number literals
2022-06-01syntax: adjust number literal parsing and string to number conversionJo-Philipp Wich
- Recognize new number literal prefixes `0o` and `0O` for octal as well as `0b` and `0B` for binary number literals - Treat number literals with leading zeros as octal while parsing but as decimal ones on implicit number conversions, means `012` will yield `10` while `+"012"` or `"012" + 0` will yield `12` Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-01lib: refactor `uc_int()`Jo-Philipp Wich
For string cases, turn `int()` into a thin `strtoll()` wrapper which attempts to parse the initial portion of the string as a decimal integer literal, optionally preceded by white space and a sign character. Also introduce an optional `base` argument for string cases while we're at it and adjust the existing stdlib test case accordingly. The function now behaves mostly the same as ECMAScript `parseInt(val, 10)` for string cases, means it will recognize `012` as `12` and not `10` and it will accept trailing non-digit characters after the initial portition of the input string. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-05-31Merge pull request #75 from ynezz/ynezz/ci-speedupJo-Philipp Wich
ci: make jobs faster during pull request testing
2022-05-31Merge pull request #77 from jow-/lib-fix-indexJo-Philipp Wich
lib: rework uc_index() implementation
2022-05-30lib: rework uc_index() implementationJo-Philipp Wich
- Fix segfault on passing string haystack with non-string needle argument - Perform strict equality tests against array haystacks - Make string searches binary safe - Improve left index string search performance - Improve right index array search performance - Add missing test coverage for index() and rindex() Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-05-20compiler: fix segmentation fault on compiling unexpected unary expressionsJo-Philipp Wich
When compiling expressions followed by a unary operator, the compiler triggered a segmentation fault due to invoking an unset infix parser routine. Explicitly handle this case and raise a syntax error if such an invalid expression is encountered. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-05-20fs: avoid input buffering with small limits in fs.readfile()Jo-Philipp Wich
If the read limit passed to fs.readfile() is smaller than BUFSIZ then disable stdio input buffering to avoid overreading the underlying file. This is useful when reading small amounts of data from special files such as /dev/urandom, where a readfile call limited to 16 bytes might actually read 4096 due to stdio buffering. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-05-19Merge pull request #76 from jow-/hexcodecJo-Philipp Wich
lib: introduce hexenc() and hexdec()