Age | Commit message (Collapse) | Author |
|
vm: fix crash due to stale frame pointer
|
|
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>
|
|
fs: improve ioctl implementation
|
|
ubus file descriptor passing and channel support
|
|
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>
|
|
Add a named parameter fd_cb, which is called when the callee returned a
file descriptor.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
File descriptors can be passed via the named fd argument
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
This can be used to send and receive file descriptors from within an object
method call.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
This can be used to synchronously complete a deferred ubus request,
waiting for completion or timeout.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
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>
|
|
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>
|
|
debian: fix lintian warnings
|
|
socket: properly support SO_ATTACH_FILTER sockopt
|
|
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>
|
|
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>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
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>
|
|
socket: fix AF_PACKET recvmsg() and sockaddr formatting
|
|
- 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>
|
|
main: add global ARGV0 variable
|
|
Fill it with the command line provided path to the source file
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
docs: Mention `libmd` in macOS docs
|
|
docs: Fix compilation command for macOS
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
|
Signed-off-by: Paul Spooren <mail@aparcar.org>
|
|
debian/control: libucode Recommends ucode-modules
|
|
|
|
debian/control: Build-Depend on cmake
|
|
|
|
|
|
|
|
struct: fix memory leak in buffer.pull()
|
|
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>
|
|
uci: eliminate usage of global variables
|
|
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>
|
|
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>
|
|
main: fix crash on printing -p output
|
|
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>
|
|
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>
|
|
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>
|
|
struct: Add new buffer API for incremental packing/unpacking
|
|
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>
|
|
main: pretty-print `-p` output by default
|
|
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>
|
|
lexer: Preserve keyword, regexp flags until processing non-comment to…
|