|
85 | 85 | - [`experimental.socket_send_autotune`](#experimentalsocket_send_autotune) |
86 | 86 | - [`experimental.socket_send_buffer`](#experimentalsocket_send_buffer) |
87 | 87 | - [`experimental.strace_logging_mode`](#experimentalstrace_logging_mode) |
| 88 | +- [`experimental.syscall_override`](#experimentalsyscall_override) |
88 | 89 | - [`experimental.unblocked_syscall_latency`](#experimentalunblocked_syscall_latency) |
89 | 90 | - [`experimental.unblocked_vdso_latency`](#experimentalunblocked_vdso_latency) |
90 | 91 | - [`experimental.use_cpu_pinning`](#experimentaluse_cpu_pinning) |
@@ -425,6 +426,54 @@ Limitations: |
425 | 426 | process may not actually see this return value. Instead the syscall may be |
426 | 427 | restarted. |
427 | 428 |
|
| 429 | +#### `experimental.syscall_overrides` |
| 430 | + |
| 431 | +Default: {} |
| 432 | +Type: Object |
| 433 | + |
| 434 | +Override the behaviour of emulated syscalls. |
| 435 | + |
| 436 | +A map of syscall numbers to lists of [Lua expressions][lua]. For each syscall |
| 437 | +number listed, a list of expressions will be evaluated before running Shadow's |
| 438 | +syscall handler. If an expression returns a non-nil signed integer result, that |
| 439 | +result will be used as the return value for the syscall. Otherwise if all |
| 440 | +expressions return nil, Shadow will perform the syscall as usual. Note that not |
| 441 | +all syscalls can be overridden. Specifically, syscalls that are handled by |
| 442 | +Shadow's shim (for example `gettimeofday`) cannot currently be overridden. |
| 443 | + |
| 444 | +[lua]: https://www.lua.org/ |
| 445 | + |
| 446 | +The following variables are available in expressions: |
| 447 | + |
| 448 | +- `args`: Array of syscall arguments cast as integers. |
| 449 | +- `host`: The hostname of the current host. |
| 450 | +- `process`: The name of the current process. |
| 451 | +- `pid`: The pid of the current process. |
| 452 | +- `tid`: The tid of the current thread. |
| 453 | + |
| 454 | +Example: |
| 455 | + |
| 456 | +```yaml |
| 457 | +experimental: |
| 458 | + syscall_overrides: |
| 459 | + # SYS_SETSOCKOPT = 54, SOL_IP = 0, IP_BIND_ADDRESS_NO_PORT = 24, IP_TTL = 2 |
| 460 | + 54: |
| 461 | + - # setsockopt(_, SOL_IP, IP_BIND_ADDRESS_NO_PORT, ...) -> 0 |
| 462 | + "(args[1] == 0 and args[2] == 24) and 0 or nil" |
| 463 | + - # setsockopt(_, SOL_IP, IP_TTL, ...) -> 0 |
| 464 | + "(args[1] == 0 and args[2] == 2) and 0 or nil" |
| 465 | +``` |
| 466 | + |
| 467 | +You must not modify global state or do anything weird within an expression. In |
| 468 | +other words, there should be no side effects. The Lua interpreter may be reused. |
| 469 | + |
| 470 | +To easily find the integer value for a given libc constant, you can search for |
| 471 | +the constant name within the libc crate's documentation. For example to find |
| 472 | +the integer value of `SO_REUSEADDR`, you can [search for |
| 473 | +`SO_REUSEADDR`][so_reuseaddr] at https://docs.rs/libc/latest/libc/. |
| 474 | + |
| 475 | +[so_reuseaddr]: https://docs.rs/libc/latest/libc/constant.SO_REUSEADDR.html |
| 476 | + |
428 | 477 | #### `experimental.unblocked_syscall_latency` |
429 | 478 |
|
430 | 479 | Default: "1 microseconds" |
|
0 commit comments