summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2025-02-10Merge pull request #276 from nbd168/frame-fixJo-Philipp Wich
vm: fix crash due to stale frame pointer
2025-02-10vm: fix crash due to stale frame pointerFelix Fietkau
In some cases, calls made while processing insns in uc_vm_execute_chunk can lead to realloc of vm->callframes without reloading the current frame pointer. This was observed with I_ADD (which can call an object's tostring method). Instead of playing whac-a-mole with insns affecting the frame pointer, let's reload it whenever necessary. Signed-off-by: Felix Fietkau <nbd@nbd.name> [further refactor to avoid redundant null pointer checks, fix native function callframe stop condition while looking for exception handler] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2025-02-06Merge pull request #269 from jonasjelonek/improve-ioctlJo-Philipp Wich
fs: improve ioctl implementation
2025-02-05Merge pull request #263 from nbd168/ubus-fdJo-Philipp Wich
ubus file descriptor passing and channel support
2025-02-04ubus: add support for channelsFelix Fietkau
A channel is a context that is directly connected to a peer instead of going through ubusd. The use of this context is limited to calling ubus_invoke and receiving requests not bound to any registered object. The main use case for this is having a more stateful interaction between processes. A service using channels can attach metadata to each individual channel and keep track of its lifetime, which is not possible through the regular subscribe/notify mechanism. Using channels also improves request latency, since messages are passed directly between processes. A channel can either be opened by fd using ubus.open_channel(), or created from within a request by using req.new_channel(). When calling req.new_channel, the fd for the other side of the channel is automatically passed to the remote caller. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-02-04ubus: add support for receiving file descriptors in call and deferFelix Fietkau
Add a named parameter fd_cb, which is called when the callee returned a file descriptor. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-02-04ubus: add support for sending file descriptors via ubus.call/deferFelix Fietkau
File descriptors can be passed via the named fd argument Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-02-04ubus: add request get_fd/set_fd methodsFelix Fietkau
This can be used to send and receive file descriptors from within an object method call. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-02-04ubus: add defer.await() methodFelix Fietkau
This can be used to synchronously complete a deferred ubus request, waiting for completion or timeout. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-02-04fs: ioctl: improve ioctl read to avoid allocating twiceJonas Jelonek
Allocate memory for 'uc_string_t' with the proper size upfront and use it's internal buffer as ioctl buffer. This avoids redundant 'ucv_string_new_length' calls and thus allocating memory a second time. Also simplify the signature of the function, using a single parameter for handling size and input buffer values. Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com> [simplify arguments, adjust documentation, prevent in-place string modifications] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2025-02-04fs: ioctl: export constants for direction valuesJonas Jelonek
Exports IOC_DIR_* constants to use for the direction parameter instead of plain integer values. The constants are based on the target's _IOC_* definitions. Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
2025-02-04Merge pull request #268 from stokito/fix-debian-lintianJo-Philipp Wich
debian: fix lintian warnings
2025-02-04Merge pull request #274 from jow-/socket-filter-sockopt-supportJo-Philipp Wich
socket: properly support SO_ATTACH_FILTER sockopt
2025-02-04ubus: add named parameter support in functions with many paramsFelix Fietkau
When a function supports many parameters, the order can be somewhat confusing, especially when dealing with several optional ones. In order to make this easier to use, support for passing an object with named parameters. for example: obj.notify("test", data, null, null, null, 1000); can be written as: obj.notify({ method: "test", data, timeout: 1000 }); Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-02-04socket: properly support SO_ATTACH_FILTER sockoptJo-Philipp Wich
The SO_ATTACH_FILTER socket option requires special handling as it is not passing a self-contained structure to the kernel but a pointer to user memory holding the actual BPF bytecode. In order to properly support this, first rework the ucode value to C struct conversion callback machinery to pass an indirect struct base pointer, allowing conversion callbacks to realloc the struct memory as needed. Finally introduce custom uv to C conversion for the BPF data which accepts either a raw bytecode string, an array of opcode arrays or a flat array of opcode values which are converted into a C array of struct sock_filter records appended to the reallocated struct memory. Attaching a BPF program equivalent to the tcpdump expression `vlan 20 && ether proto 0x1234` would then look like this: sock.setopt(SOL_SOCKET, SO_ATTACH_FILTER, { filter: [ [ 0x28, 0, 0, 0x0000000c ], [ 0x15, 2, 0, 0x00008100 ], [ 0x15, 1, 0, 0x000088a8 ], [ 0x15, 0, 6, 0x00009100 ], [ 0x28, 0, 0, 0x0000000e ], [ 0x54, 0, 0, 0x00000fff ], [ 0x15, 0, 3, 0x00000014 ], [ 0x28, 0, 0, 0x00000010 ], [ 0x15, 0, 1, 0x00001234 ], [ 0x6, 0, 0, 0x00040000 ], [ 0x6, 0, 0, 0x00000000 ], ] }); Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2025-02-01ci: bump actions/upload-artifact to v4Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2025-02-01rtnl: properly handle runtime exceptions in listener callbackJo-Philipp Wich
Avoid re-invoking any event listener callbacks after an invocation triggered an exception in order to avoid accidentially clearing the exception information. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2025-01-25Merge pull request #271 from jow-/socket-fixesJo-Philipp Wich
socket: fix AF_PACKET recvmsg() and sockaddr formatting
2025-01-25socket: fix AF_PACKET recvmsg() and sockaddr formattingJo-Philipp Wich
- Do not unconditionally pass the `MSG_CMSG_CLOEXEC` flag to `recvmsg()` invocations as not all protocol specific recvmsg implementations in the kernel tolerate it; `packet_recvmsg()` for example will immediately return yield `EINVAL` if any non-whitelisted flag is passed. - Ensure that the HW address string buffer is zero-terminated when converting MAC addresses from C to ucode values. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2025-01-24Merge pull request #270 from nbd168/argv0Jo-Philipp Wich
main: add global ARGV0 variable
2025-01-24main: add global SCRIPT_NAME variableFelix Fietkau
Fill it with the command line provided path to the source file Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-01-22Merge pull request #266 from aparcar/libmdJo-Philipp Wich
docs: Mention `libmd` in macOS docs
2025-01-22Merge pull request #267 from aparcar/macosJo-Philipp Wich
docs: Fix compilation command for macOS
2025-01-19debian: ignore lintian warning no-manual-pageSergey Ponomarev
2025-01-18.gitignore: ignore files generated by debuildSergey Ponomarev
2025-01-18debian/changelog: switch versioning to native package schemeSergey Ponomarev
2025-01-18debian/control: pkg-config now called pkgconfSergey Ponomarev
2025-01-18debian/copyright: fix missing dot to separate paragraphsSergey Ponomarev
2025-01-05docs: Fix compilation command for macOSPaul Spooren
Fixes: #265 "macOS build broken not finding libucode.0.dylib" Suggested-by: Felix Fietkau <nbd@nbd.name> Signed-off-by: Paul Spooren <mail@aparcar.org>
2025-01-05docs: Mention `libmd` in macOS docsPaul Spooren
Signed-off-by: Paul Spooren <mail@aparcar.org>
2024-12-31Merge pull request #262 from stokito/patch-1Jo-Philipp Wich
debian/control: libucode Recommends ucode-modules
2024-12-31debian/control: libucode Recommends ucode-modulesSergey Ponomarev
2024-12-31Merge pull request #261 from stokito/patch-1Jo-Philipp Wich
debian/control: Build-Depend on cmake
2024-12-31debian/source/format: change to nativeSergey Ponomarev
2024-12-31debian/control: Fix Standards-Version, add BugsSergey Ponomarev
2024-12-31debian/control: Build-Depend on cmakeSergey Ponomarev
2024-12-31Merge pull request #260 from jow-/struct-memory-fixesJo-Philipp Wich
struct: fix memory leak in buffer.pull()
2024-12-30struct: fix memory leak in buffer.pull()Jo-Philipp Wich
Do not increase the refcount when returning the pulled buffer contents as string since the returned value already is the sole reference. Without this change, pulled buffer contents will be leaked whenever the `pull()` function is used. Also ensure that the buffer memory is completely zero initialized when it is allocated from scratch, the existing logic only cleared the trailing data area on reallocations but never the head on fresh allocations. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-13Merge pull request #258 from jow-/uci-no-globalsJo-Philipp Wich
uci: eliminate usage of global variables
2024-12-12uci: eliminate usage of global variablesJo-Philipp Wich
Use the VM registry to store the last uci error code and lookup the uci cursor resource type at resource creation time instead of caching it in a global variable. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-11vm: close signal pipe in uc_vm_signal_handlers_reset()Jo-Philipp Wich
The previously introduced signal handler restoration logic did not take the signal dispatching pipe into account. Extend the `uc_vm_signal_handlers_reset()` function to also close any related pipe handles. Fixes: #255 Fixes: f9d2faf ("vm: reset signals when freeing VM") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-11Merge pull request #256 from nbd168/pretty-printJo-Philipp Wich
main: fix crash on printing -p output
2024-12-08main: fix crash on printing -p outputFelix Fietkau
Delete a duplicate ucv_put() line that can lead to a double-free bug. Reproduced by running: ucode -l nl80211 -p 'sprintf("%.J\n", nl80211.request(nl80211.const.NL80211_CMD_GET_WIPHY, nl80211.const.NLM_F_DUMP, { wiphy: 0, split_wiphy_dump: true }))' Fixes: 0a7ff4715cb8 ("main: pretty-print `-p` output by default") Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-12-07tests: adjust testcases after previous commitJo-Philipp Wich
Reenabling signal dispatching caused a new object allocation so update the expected GC counts in the testcases. Fixes: a362263 ("vm: fix inverted condition in uc_vm_signal_handlers_setup()") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-07vm: fix inverted condition in uc_vm_signal_handlers_setup()Jo-Philipp Wich
The previous code refactoring inadvertently broke the signal setup condition check. Fixes: #254 Fixes: f9d2faf ("vm: reset signals when freeing VM") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-06Merge pull request #209 from jow-/struct-bufferJo-Philipp Wich
struct: Add new buffer API for incremental packing/unpacking
2024-12-06struct: do not use global variables for caching typesJo-Philipp Wich
Drop the usage of global static variables for caching the per-VM resource type objects in order to properly support loading the library in multiple concurrent threads or VM instances. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-06Merge pull request #252 from jow-/main-pretty-print-by-defaultJo-Philipp Wich
main: pretty-print `-p` output by default
2024-12-06struct: Add new buffer API for incremental packing/unpackingJo-Philipp Wich
Implement a new struct buffer API to support incremental packing and unpacking of binary data. This API allows for more flexible and efficient handling of structured data, especially for streaming or partial processing scenarios. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-06Merge pull request #251 from jow-/fix-parsing-kwlabels-after-commentsJo-Philipp Wich
lexer: Preserve keyword, regexp flags until processing non-comment to…