diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2021-07-28 17:09:19 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2022-04-10 15:49:05 +0200 |
commit | a57ee6e6ef7472bce2c30f800e09daa89ea6fd47 (patch) | |
tree | 804d55315c3287bf0f222b911693208f63dd19e7 /src/slirp.c | |
parent | e9070f7ca279e2aede46540332842694c0021939 (diff) | |
download | slirp-a57ee6e6ef7472bce2c30f800e09daa89ea6fd47.zip slirp-a57ee6e6ef7472bce2c30f800e09daa89ea6fd47.tar.gz slirp-a57ee6e6ef7472bce2c30f800e09daa89ea6fd47.tar.bz2 |
introduce slirp_timer_new wrapper
In order to support CFI, we would like to avoid passing function pointers out of
libslirp, and instead use opaque integers for the timer callbacks. This patch
introduces an internal API for creating a timer that is based on such a timer
callback.
For now, it receives the id (SLIRP_TIMER_RA is the only one) and calls
slirp->cb->timer_new. The prototype of ra_timer_handler is changed slightly
to fit better with the next patch which introduces a new libslirp function,
to be called on timer expiration.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'src/slirp.c')
-rw-r--r-- | src/slirp.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/slirp.c b/src/slirp.c index 5e08b53..a2876f2 100644 --- a/src/slirp.c +++ b/src/slirp.c @@ -528,6 +528,27 @@ static void slirp_init_once(void) } } +static void ra_timer_handler_cb(void *opaque) +{ + Slirp *slirp = opaque; + + return ra_timer_handler(slirp, NULL); +} + +void *slirp_timer_new(Slirp *slirp, SlirpTimerId id, void *cb_opaque) +{ + g_return_val_if_fail(id >= 0 && id < SLIRP_TIMER_NUM, NULL); + + switch (id) { + case SLIRP_TIMER_RA: + g_return_val_if_fail(cb_opaque == NULL, NULL); + return slirp->cb->timer_new(ra_timer_handler_cb, slirp, slirp->opaque); + + default: + abort(); + } +} + Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks, void *opaque) { Slirp *slirp; |