From 8267c193415e8c8345d15671fc3385b692e6c289 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 29 Dec 2018 20:39:50 -0500 Subject: [PATCH] freebsd_network: Lots of additions and modifications for iflib. --- src/libs/compat/freebsd_network/Condvar.cpp | 7 +++ src/libs/compat/freebsd_network/Condvar.h | 1 + src/libs/compat/freebsd_network/bus.cpp | 4 +- src/libs/compat/freebsd_network/compat.c | 11 +++- .../freebsd_network/compat/dev/led/led.h | 8 +-- .../compat/freebsd_network/compat/net/if.h | 18 +++++- .../freebsd_network/compat/sys/_mutex.h | 5 ++ .../compat/freebsd_network/compat/sys/bus.h | 5 +- .../freebsd_network/compat/sys/callout.h | 4 +- .../compat/freebsd_network/compat/sys/cdefs.h | 15 +++++ .../freebsd_network/compat/sys/haiku-module.h | 2 +- .../freebsd_network/compat/sys/kthread.h | 1 + .../compat/freebsd_network/compat/sys/lock.h | 16 +++++ .../freebsd_network/compat/sys/mbuf-fbsd.h | 59 +++++++++++++++++++ .../compat/freebsd_network/compat/sys/mbuf.h | 5 ++ .../compat/freebsd_network/compat/sys/mutex.h | 32 +++++++--- .../compat/freebsd_network/compat/sys/param.h | 12 +++- .../freebsd_network/compat/sys/priority.h | 9 ++- .../compat/freebsd_network/compat/sys/sx.h | 27 +++++++++ .../compat/freebsd_network/compat/sys/systm.h | 5 ++ .../freebsd_network/compat/sys/taskqueue.h | 6 +- src/libs/compat/freebsd_network/mbuf.c | 42 +++++++------ src/libs/compat/freebsd_network/mutex.c | 7 ++- src/libs/compat/freebsd_network/synch.c | 7 +++ src/libs/compat/freebsd_network/systm.cpp | 1 + src/libs/compat/freebsd_network/taskqueue.c | 2 +- 26 files changed, 262 insertions(+), 49 deletions(-) create mode 100644 src/libs/compat/freebsd_network/compat/sys/sx.h diff --git a/src/libs/compat/freebsd_network/Condvar.cpp b/src/libs/compat/freebsd_network/Condvar.cpp index 9cb5be1dcd..76aadcafb8 100644 --- a/src/libs/compat/freebsd_network/Condvar.cpp +++ b/src/libs/compat/freebsd_network/Condvar.cpp @@ -79,3 +79,10 @@ publishedConditionNotifyAll(const void* waitChannel) { ConditionVariable::NotifyAll(waitChannel, B_OK); } + + +void +publishedConditionNotifyOne(const void* waitChannel) +{ + ConditionVariable::NotifyOne(waitChannel, B_OK); +} diff --git a/src/libs/compat/freebsd_network/Condvar.h b/src/libs/compat/freebsd_network/Condvar.h index bff1b0d7bb..e774fc442c 100644 --- a/src/libs/compat/freebsd_network/Condvar.h +++ b/src/libs/compat/freebsd_network/Condvar.h @@ -18,6 +18,7 @@ void conditionWait(struct cv*); void conditionNotifyOne(struct cv*); int publishedConditionTimedWait(const void*, const int); void publishedConditionNotifyAll(const void*); +void publishedConditionNotifyOne(const void*); #ifdef __cplusplus } diff --git a/src/libs/compat/freebsd_network/bus.cpp b/src/libs/compat/freebsd_network/bus.cpp index 7524ef3585..f914d13a4b 100644 --- a/src/libs/compat/freebsd_network/bus.cpp +++ b/src/libs/compat/freebsd_network/bus.cpp @@ -48,7 +48,7 @@ extern "C" { struct internal_intr { device_t dev; - driver_filter_t filter; + driver_filter_t* filter; driver_intr_t *handler; void *arg; int irq; @@ -325,7 +325,7 @@ free_internal_intr(struct internal_intr *intr) int bus_setup_intr(device_t dev, struct resource *res, int flags, - driver_filter_t filter, driver_intr_t handler, void *arg, void **_cookie) + driver_filter_t* filter, driver_intr_t handler, void *arg, void **_cookie) { /* TODO check MPSAFE etc */ diff --git a/src/libs/compat/freebsd_network/compat.c b/src/libs/compat/freebsd_network/compat.c index 73ff57795d..0f92586569 100644 --- a/src/libs/compat/freebsd_network/compat.c +++ b/src/libs/compat/freebsd_network/compat.c @@ -265,6 +265,13 @@ device_get_softc(device_t dev) } +void +device_set_softc(device_t dev, void *softc) +{ + dev->softc = softc; +} + + u_int32_t device_get_flags(device_t dev) { @@ -277,11 +284,11 @@ device_set_driver(device_t dev, driver_t *driver) { int i; - dev->softc = malloc(driver->softc_size); + dev->softc = malloc(driver->size); if (dev->softc == NULL) return -1; - memset(dev->softc, 0, driver->softc_size); + memset(dev->softc, 0, driver->size); dev->driver = driver; for (i = 0; driver->methods[i].name != NULL; i++) { diff --git a/src/libs/compat/freebsd_network/compat/dev/led/led.h b/src/libs/compat/freebsd_network/compat/dev/led/led.h index e09d89ca53..74a1029da1 100644 --- a/src/libs/compat/freebsd_network/compat/dev/led/led.h +++ b/src/libs/compat/freebsd_network/compat/dev/led/led.h @@ -9,27 +9,27 @@ typedef void led_t(void*, int); -static struct cdev* +static inline struct cdev* led_create_state(led_t* func, void* priv, char const* name, int state) { return NULL; } -static struct cdev* +static inline struct cdev* led_create(led_t* func, void* priv, char const* name) { return NULL; } -static void +static inline void led_destroy(struct cdev* dev) { } -static int +static inline int led_set(char const* name, char const* cmd) { return -1; diff --git a/src/libs/compat/freebsd_network/compat/net/if.h b/src/libs/compat/freebsd_network/compat/net/if.h index fde4ef522c..99f45c909f 100644 --- a/src/libs/compat/freebsd_network/compat/net/if.h +++ b/src/libs/compat/freebsd_network/compat/net/if.h @@ -13,7 +13,7 @@ #include -#define IF_Kbps(x) ((x) * 1000) +#define IF_Kbps(x) ((uintmax_t)(x) * 1000) #define IF_Mbps(x) (IF_Kbps((x) * 1000)) #define IF_Gbps(x) (IF_Mbps((x) * 1000)) @@ -52,7 +52,7 @@ #define IFCAP_CANTCHANGE (IFCAP_NETMAP) -/* Interface flags */ +/* interface flags -- these extend the Haiku-native ones from posix/net/if.h */ #define IFF_DRV_RUNNING 0x00010000 #define IFF_DRV_OACTIVE 0x00020000 #define IFF_LINK0 0x00040000 /* per link layer defined bit */ @@ -60,6 +60,7 @@ #define IFF_LINK2 0x00100000 /* per link layer defined bit */ #define IFF_DEBUG 0x00200000 #define IFF_MONITOR 0x00400000 /* (n) user-requested monitor mode */ +#define IFF_NOGROUP 0x00800000 /* (n) interface is not part of any groups */ #define LINK_STATE_UNKNOWN 0 #define LINK_STATE_DOWN 1 @@ -113,6 +114,19 @@ struct ifdrv { void* ifd_data; }; +/* + * Structure used to request i2c data + * from interface transceivers. + */ +struct ifi2creq { + uint8_t dev_addr; /* i2c address (0xA0, 0xA2) */ + uint8_t offset; /* read offset */ + uint8_t len; /* read length */ + uint8_t spare0; + uint32_t spare1; + uint8_t data[8]; /* read buffer */ +}; + #ifdef _KERNEL /* TODO: this should go away soon. */ # include diff --git a/src/libs/compat/freebsd_network/compat/sys/_mutex.h b/src/libs/compat/freebsd_network/compat/sys/_mutex.h index ebddbecaff..109b0365b9 100644 --- a/src/libs/compat/freebsd_network/compat/sys/_mutex.h +++ b/src/libs/compat/freebsd_network/compat/sys/_mutex.h @@ -8,6 +8,7 @@ #include +#include struct mtx { @@ -18,6 +19,10 @@ struct mtx { thread_id owner; } mutex; recursive_lock recursive; + struct { + spinlock lock; + cpu_status state; + } spinlock; } u; }; diff --git a/src/libs/compat/freebsd_network/compat/sys/bus.h b/src/libs/compat/freebsd_network/compat/sys/bus.h index a4d6637905..029cc831f9 100644 --- a/src/libs/compat/freebsd_network/compat/sys/bus.h +++ b/src/libs/compat/freebsd_network/compat/sys/bus.h @@ -78,7 +78,7 @@ int bus_generic_suspend(device_t dev); int bus_generic_resume(device_t dev); void bus_generic_shutdown(device_t dev); -typedef int (*driver_filter_t)(void *); +typedef int (driver_filter_t)(void *arg); typedef void driver_intr_t(void *); @@ -113,7 +113,7 @@ bus_alloc_resource_anywhere(device_t dev, int type, int *rid, bus_dma_tag_t bus_get_dma_tag(device_t dev); int bus_setup_intr(device_t dev, struct resource *r, int flags, - driver_filter_t filter, driver_intr_t handler, void *arg, void **_cookie); + driver_filter_t* filter, driver_intr_t handler, void *arg, void **_cookie); int bus_teardown_intr(device_t dev, struct resource *r, void *cookie); int bus_bind_intr(device_t dev, struct resource *r, int cpu); int bus_describe_intr(device_t dev, struct resource *irq, void *cookie, @@ -123,6 +123,7 @@ const char *device_get_name(device_t dev); const char *device_get_nameunit(device_t dev); int device_get_unit(device_t dev); void *device_get_softc(device_t dev); +void device_set_softc(device_t dev, void *softc); int device_printf(device_t dev, const char *, ...) __printflike(2, 3); void device_set_desc(device_t dev, const char *desc); void device_set_desc_copy(device_t dev, const char *desc); diff --git a/src/libs/compat/freebsd_network/compat/sys/callout.h b/src/libs/compat/freebsd_network/compat/sys/callout.h index fefdf1d5f6..35e18707e9 100644 --- a/src/libs/compat/freebsd_network/compat/sys/callout.h +++ b/src/libs/compat/freebsd_network/compat/sys/callout.h @@ -18,12 +18,14 @@ void callout_init(struct callout *c, int mpsafe); void callout_init_mtx(struct callout *c, struct mtx *mutex, int flags); -/* Time values are in ticks, see compat/sys/kernel.h for its definition */ int callout_schedule(struct callout *c, int _ticks); int callout_reset(struct callout *c, int _ticks, void (*func)(void *), void *arg); int callout_pending(struct callout *c); int callout_active(struct callout *c); +#define callout_reset_on(c, to_ticks, fn, arg, cpu) \ + callout_reset(c, to_ticks, fn, arg) + #define callout_drain(c) _callout_stop_safe(c, 1) #define callout_stop(c) _callout_stop_safe(c, 0) int _callout_stop_safe(struct callout *c, int safe); diff --git a/src/libs/compat/freebsd_network/compat/sys/cdefs.h b/src/libs/compat/freebsd_network/compat/sys/cdefs.h index e7563e9295..f208d0ebf2 100644 --- a/src/libs/compat/freebsd_network/compat/sys/cdefs.h +++ b/src/libs/compat/freebsd_network/compat/sys/cdefs.h @@ -264,6 +264,21 @@ #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) #endif +/* + * C99 Static array indices in function parameter declarations. Syntax such as: + * void bar(int myArray[static 10]); + * is allowed in C99 but not in C++. Define __min_size appropriately so + * headers using it can be compiled in either language. Use like this: + * void bar(int myArray[__min_size(10)]); + */ +#if !defined(__cplusplus) && \ + (defined(__clang__) || __GNUC_PREREQ__(4, 6)) && \ + (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901)) +#define __min_size(x) static (x) +#else +#define __min_size(x) (x) +#endif + #if __GNUC_PREREQ__(3, 1) #define __noinline __attribute__ ((__noinline__)) #else diff --git a/src/libs/compat/freebsd_network/compat/sys/haiku-module.h b/src/libs/compat/freebsd_network/compat/sys/haiku-module.h index 415c1ecb05..10450275b1 100644 --- a/src/libs/compat/freebsd_network/compat/sys/haiku-module.h +++ b/src/libs/compat/freebsd_network/compat/sys/haiku-module.h @@ -58,7 +58,7 @@ typedef struct device_method device_method_t; typedef struct { const char *name; device_method_t *methods; - size_t softc_size; + size_t size; } driver_t; #define DRIVER_MODULE_NAME(name, busname) \ diff --git a/src/libs/compat/freebsd_network/compat/sys/kthread.h b/src/libs/compat/freebsd_network/compat/sys/kthread.h index e69de29bb2..8b13789179 100644 --- a/src/libs/compat/freebsd_network/compat/sys/kthread.h +++ b/src/libs/compat/freebsd_network/compat/sys/kthread.h @@ -0,0 +1 @@ + diff --git a/src/libs/compat/freebsd_network/compat/sys/lock.h b/src/libs/compat/freebsd_network/compat/sys/lock.h index e69de29bb2..c0b21fa0e2 100644 --- a/src/libs/compat/freebsd_network/compat/sys/lock.h +++ b/src/libs/compat/freebsd_network/compat/sys/lock.h @@ -0,0 +1,16 @@ +/* + * Copyright 2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _FBSD_COMPAT_SYS_LOCK_H_ +#define _FBSD_COMPAT_SYS_LOCK_H_ + + +#define MPASS(ex) MPASS4(ex, #ex, __FILE__, __LINE__) +#define MPASS2(ex, what) MPASS4(ex, what, __FILE__, __LINE__) +#define MPASS3(ex, file, line) MPASS4(ex, #ex, file, line) +#define MPASS4(ex, what, file, line) \ + KASSERT((ex), ("assert %s failed at %s:%d", what, file, line)) + + +#endif /* _FBSD_COMPAT_SYS_LOCK_H_ */ \ No newline at end of file diff --git a/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h b/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h index 6a42d40076..1e06bf6122 100644 --- a/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h +++ b/src/libs/compat/freebsd_network/compat/sys/mbuf-fbsd.h @@ -153,6 +153,65 @@ m_extrefcnt(struct mbuf *m) *m->m_ext.ext_cnt); } +static __inline int +m_gettype(int size) +{ + int type; + + switch (size) { + case MCLBYTES: + type = EXT_CLUSTER; + break; +#if MJUMPAGESIZE != MCLBYTES + case MJUMPAGESIZE: + type = EXT_JUMBOP; + break; +#endif + case MJUM9BYTES: + type = EXT_JUMBO9; + break; + default: + panic("%s: invalid cluster size %d", __func__, size); + } + + return (type); +} + +/* + * XXX: m_cljset() is a dangerous API. One must attach only a new, + * unreferenced cluster to an mbuf(9). It is not possible to assert + * that, so care can be taken only by users of the API. + */ +static __inline void +m_cljset(struct mbuf *m, void *cl, int type) +{ + int size; + + switch (type) { + case EXT_CLUSTER: + size = MCLBYTES; + break; +#if MJUMPAGESIZE != MCLBYTES + case EXT_JUMBOP: + size = MJUMPAGESIZE; + break; +#endif + case EXT_JUMBO9: + size = MJUM9BYTES; + break; + default: + panic("%s: unknown cluster type %d", __func__, type); + break; + } + + m->m_data = m->m_ext.ext_buf = cl; + m->m_ext.ext_size = size; + m->m_ext.ext_type = type; + m->m_ext.ext_flags = EXT_FLAG_EMBREF; + m->m_ext.ext_count = 1; + m->m_flags |= M_EXT; +} + /* mbufq */ struct mbufq { diff --git a/src/libs/compat/freebsd_network/compat/sys/mbuf.h b/src/libs/compat/freebsd_network/compat/sys/mbuf.h index c10405a881..4401aa3163 100644 --- a/src/libs/compat/freebsd_network/compat/sys/mbuf.h +++ b/src/libs/compat/freebsd_network/compat/sys/mbuf.h @@ -24,7 +24,9 @@ #define M_TRYWAIT M_WAITOK #define M_WAIT M_WAITOK +/* mbuf types describing the content of the mbuf (including external storage). */ #define MT_DATA 1 +#define MT_NOINIT 255 /* not a type, a flag to allocate a non-initialized mbuf */ /* * mbuf flags of global significance and layer crossing. @@ -273,6 +275,9 @@ struct mbuf { #define m_pktdat M_dat.MH.MH_dat.MH_databuf #define m_dat M_dat.M_databuf +int m_init(struct mbuf *m, int how, short type, int flags); +int m_pkthdr_init(struct mbuf *m, int how); + void m_catpkt(struct mbuf *m, struct mbuf *n); void m_adj(struct mbuf*, int); int m_append(struct mbuf*, int, c_caddr_t); diff --git a/src/libs/compat/freebsd_network/compat/sys/mutex.h b/src/libs/compat/freebsd_network/compat/sys/mutex.h index 9fded57c0f..8445838eb6 100644 --- a/src/libs/compat/freebsd_network/compat/sys/mutex.h +++ b/src/libs/compat/freebsd_network/compat/sys/mutex.h @@ -8,6 +8,7 @@ #include +#include #include #include @@ -23,16 +24,19 @@ #define mtx_assert(mtx, what) -#define MTX_DEF 0x0000 -#define MTX_RECURSE 0x0004 -#define MTX_QUIET 0x40000 -#define MTX_DUPOK 0x400000 +#define MTX_DEF 0x00000000 +#define MTX_SPIN 0x00000001 +#define MTX_RECURSE 0x00000004 +#define MTX_QUIET 0x00040000 +#define MTX_DUPOK 0x00400000 #define MTX_NETWORK_LOCK "network driver" -#define NET_LOCK_GIANT() -#define NET_UNLOCK_GIANT() + +/* on FreeBSD these are different functions */ +#define mtx_lock_spin(x) mtx_lock(x) +#define mtx_unlock_spin(x) mtx_unlock(x) extern struct mtx Giant; @@ -49,8 +53,13 @@ mtx_lock(struct mtx* mutex) if (mutex->type == MTX_DEF) { mutex_lock(&mutex->u.mutex.lock); mutex->u.mutex.owner = find_thread(NULL); - } else if (mutex->type == MTX_RECURSE) + } else if (mutex->type == MTX_RECURSE) { recursive_lock_lock(&mutex->u.recursive); + } else if (mutex->type == MTX_SPIN) { + cpu_status status = disable_interrupts(); + acquire_spinlock(&mutex->u.spinlock.lock); + mutex->u.spinlock.state = status; + } } @@ -66,6 +75,8 @@ mtx_trylock(struct mtx* mutex) if (recursive_lock_trylock(&mutex->u.recursive) != B_OK) return 0; return 1; + } else if (mutex->type == MTX_SPIN) { + return 0; } return 0; } @@ -77,8 +88,13 @@ mtx_unlock(struct mtx* mutex) if (mutex->type == MTX_DEF) { mutex->u.mutex.owner = -1; mutex_unlock(&mutex->u.mutex.lock); - } else if (mutex->type == MTX_RECURSE) + } else if (mutex->type == MTX_RECURSE) { recursive_lock_unlock(&mutex->u.recursive); + } else if (mutex->type == MTX_SPIN) { + cpu_status status = mutex->u.spinlock.state; + release_spinlock(&mutex->u.spinlock.lock); + restore_interrupts(status); + } } diff --git a/src/libs/compat/freebsd_network/compat/sys/param.h b/src/libs/compat/freebsd_network/compat/sys/param.h index 99e180e59e..5d5ed02b0f 100644 --- a/src/libs/compat/freebsd_network/compat/sys/param.h +++ b/src/libs/compat/freebsd_network/compat/sys/param.h @@ -17,7 +17,7 @@ /* The version this compatibility layer is based on */ -#define __FreeBSD_version 1101000 +#define __FreeBSD_version 1200000 #define MAXBSIZE 0x10000 @@ -61,6 +61,16 @@ #error Need definition of ALIGNED_POINTER for this arch! #endif +/* defined in arch_cpu.h which we can't include here as it's C++ */ +#if defined(__x86_64__) || defined(__i386__) +#define CACHE_LINE_SIZE 64 +#else +#error Need definition of CACHE_LINE_SIZE for this arch! +#endif + +/* defined in platform_kernel_args.h as SMP_MAX_CPUS */ +#define MAXCPU 64 /* SMP_MAX_CPUS */ + /* Macros for counting and rounding. */ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) diff --git a/src/libs/compat/freebsd_network/compat/sys/priority.h b/src/libs/compat/freebsd_network/compat/sys/priority.h index 61fd7f1b27..55d8668ad4 100644 --- a/src/libs/compat/freebsd_network/compat/sys/priority.h +++ b/src/libs/compat/freebsd_network/compat/sys/priority.h @@ -1,12 +1,19 @@ /* - * Copyright 2009 Haiku Inc. All rights reserved. + * Copyright 2009-2018, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _FBSD_COMPAT_SYS_PRIORITY_H_ #define _FBSD_COMPAT_SYS_PRIORITY_H_ +#include + + +#define PI_NET (B_REAL_TIME_DISPLAY_PRIORITY - 9) +#define PI_SOFT (B_REAL_TIME_DISPLAY_PRIORITY - 1) #define PRI_MIN_KERN (64) #define PZERO (PRI_MIN_KERN + 20) +#define PWAIT (PRI_MIN_KERN + 28) + #endif /* _FBSD_COMPAT_SYS_PRIORITY_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/sx.h b/src/libs/compat/freebsd_network/compat/sys/sx.h new file mode 100644 index 0000000000..92c6ac0e85 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat/sys/sx.h @@ -0,0 +1,27 @@ +/* + * Copyright 2018, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Augustin Cavalier + */ +#ifndef _FBSD_COMPAT_SYS_SX_H_ +#define _FBSD_COMPAT_SYS_SX_H_ + + +#include + + +struct sx { + rw_lock l; +}; + +#define sx_init(lock, name) rw_lock_init(&(lock)->l, name) +#define sx_xlock(lock) rw_lock_write_lock(&(lock)->l) +#define sx_xunlock(lock) rw_lock_write_unlock(&(lock)->l) +#define sx_destroy(lock) rw_lock_destroy(&(lock)->l) + +#define sx_assert(sx, what) + + +#endif /* _FBSD_COMPAT_SYS_SX_H_ */ diff --git a/src/libs/compat/freebsd_network/compat/sys/systm.h b/src/libs/compat/freebsd_network/compat/sys/systm.h index 9e80ffb48c..7138300cea 100644 --- a/src/libs/compat/freebsd_network/compat/sys/systm.h +++ b/src/libs/compat/freebsd_network/compat/sys/systm.h @@ -56,7 +56,10 @@ int printf(const char *format, ...) __printflike(1, 2); snooze(n); \ } while (0) +#define cold 0 + void wakeup(void *); +void wakeup_one(void *); #ifndef CTASSERT /* Allow lint to override */ #define CTASSERT(x) _Static_assert(x, "compile-time assertion failed") @@ -96,6 +99,8 @@ int _pause(const char *, int); #define pause(waitMessage, timeout) _pause((waitMessage), (timeout)) #define tsleep(channel, priority, waitMessage, timeout) \ msleep((channel), NULL, (priority), (waitMessage), (timeout)) +#define msleep_spin(chan, mtx, wmesg, timo) \ + msleep(chan, mtx, PZERO, wmesg, timo) #define mtx_sleep msleep void critical_enter(void); diff --git a/src/libs/compat/freebsd_network/compat/sys/taskqueue.h b/src/libs/compat/freebsd_network/compat/sys/taskqueue.h index 7f131d93d3..2767b321c7 100644 --- a/src/libs/compat/freebsd_network/compat/sys/taskqueue.h +++ b/src/libs/compat/freebsd_network/compat/sys/taskqueue.h @@ -1,5 +1,5 @@ /* - * Copyright 2007 Haiku Inc. All rights reserved. + * Copyright 2007-2018, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _FBSD_COMPAT_SYS_TASKQUEUE_H_ @@ -11,9 +11,6 @@ #include -#define PI_NET (B_REAL_TIME_DISPLAY_PRIORITY - 1) - - struct timeout_task { struct taskqueue *q; struct task t; @@ -21,6 +18,7 @@ struct timeout_task { int f; }; +#define TASKQUEUE_NAMELEN 64 typedef void (*taskqueue_enqueue_fn)(void *context); diff --git a/src/libs/compat/freebsd_network/mbuf.c b/src/libs/compat/freebsd_network/mbuf.c index 5b7dabd107..4211219a6a 100644 --- a/src/libs/compat/freebsd_network/mbuf.c +++ b/src/libs/compat/freebsd_network/mbuf.c @@ -42,24 +42,26 @@ m_to_oc_flags(int how) } -static int -construct_mbuf(struct mbuf *memoryBuffer, short type, int flags) +int +m_init(struct mbuf *m, int how, short type, int flags) { - memoryBuffer->m_next = NULL; - memoryBuffer->m_nextpkt = NULL; - memoryBuffer->m_len = 0; - memoryBuffer->m_flags = flags; - memoryBuffer->m_type = type; + int error; - if (flags & M_PKTHDR) { - memoryBuffer->m_data = memoryBuffer->m_pktdat; - memset(&memoryBuffer->m_pkthdr, 0, sizeof(memoryBuffer->m_pkthdr)); - SLIST_INIT(&memoryBuffer->m_pkthdr.tags); - } else { - memoryBuffer->m_data = memoryBuffer->m_dat; - } + if (type == MT_NOINIT) + return 0; - return 0; + m->m_next = NULL; + m->m_nextpkt = NULL; + m->m_data = m->m_dat; + m->m_len = 0; + m->m_flags = flags; + m->m_type = type; + if (flags & M_PKTHDR) + error = m_pkthdr_init(m, how); + else + error = 0; + + return (error); } @@ -107,7 +109,8 @@ construct_ext_mbuf(struct mbuf *memoryBuffer, int how) static int construct_pkt_mbuf(int how, struct mbuf *memoryBuffer, short type, int flags) { - construct_mbuf(memoryBuffer, type, flags); + if (m_init(memoryBuffer, how, type, flags) < 0) + return -1; if (construct_ext_mbuf(memoryBuffer, how) < 0) return -1; memoryBuffer->m_ext.ext_type = EXT_CLUSTER; @@ -140,7 +143,7 @@ _m_get(int how, short type, int flags) if (memoryBuffer == NULL) return NULL; - construct_mbuf(memoryBuffer, type, flags); + m_init(memoryBuffer, how, type, flags); return memoryBuffer; } @@ -184,7 +187,10 @@ m_getjcl(int how, short type, int flags, int size) (struct mbuf *)object_cache_alloc(sMBufCache, m_to_oc_flags(how)); if (memoryBuffer == NULL) return NULL; - construct_mbuf(memoryBuffer, type, flags); + if (m_init(memoryBuffer, how, type, flags) < 0) { + object_cache_free(sMBufCache, memoryBuffer, 0); + return NULL; + } if (construct_ext_sized_mbuf(memoryBuffer, how, size) < 0) { object_cache_free(sMBufCache, memoryBuffer, 0); return NULL; diff --git a/src/libs/compat/freebsd_network/mutex.c b/src/libs/compat/freebsd_network/mutex.c index b9edac17e9..4a035fb5de 100644 --- a/src/libs/compat/freebsd_network/mutex.c +++ b/src/libs/compat/freebsd_network/mutex.c @@ -24,12 +24,15 @@ mtx_init(struct mtx *mutex, const char *name, const char *type, if ((options & MTX_RECURSE) != 0) { recursive_lock_init_etc(&mutex->u.recursive, name, MUTEX_FLAG_CLONE_NAME); + mutex->type = MTX_RECURSE; + } else if ((options & MTX_SPIN) != 0) { + B_INITIALIZE_SPINLOCK(&mutex->u.spinlock.lock); + mutex->type = MTX_SPIN; } else { mutex_init_etc(&mutex->u.mutex.lock, name, MUTEX_FLAG_CLONE_NAME); mutex->u.mutex.owner = -1; + mutex->type = MTX_DEF; } - - mutex->type = options; } diff --git a/src/libs/compat/freebsd_network/synch.c b/src/libs/compat/freebsd_network/synch.c index 48a022340d..d187915930 100644 --- a/src/libs/compat/freebsd_network/synch.c +++ b/src/libs/compat/freebsd_network/synch.c @@ -42,3 +42,10 @@ wakeup(void* identifier) { publishedConditionNotifyAll(identifier); } + + +void +wakeup_one(void* identifier) +{ + publishedConditionNotifyOne(identifier); +} diff --git a/src/libs/compat/freebsd_network/systm.cpp b/src/libs/compat/freebsd_network/systm.cpp index b56bb6bc83..a8d7ef61cc 100644 --- a/src/libs/compat/freebsd_network/systm.cpp +++ b/src/libs/compat/freebsd_network/systm.cpp @@ -1,5 +1,6 @@ /* * Copyright 2012, Jérôme Duval, korli@users.berlios.de. + * Copyright 2018, Haiku, Inc. * All rights reserved. Distributed under the terms of the MIT License. */ diff --git a/src/libs/compat/freebsd_network/taskqueue.c b/src/libs/compat/freebsd_network/taskqueue.c index 21bd1d08c8..33826a8ad4 100644 --- a/src/libs/compat/freebsd_network/taskqueue.c +++ b/src/libs/compat/freebsd_network/taskqueue.c @@ -25,7 +25,7 @@ #define DT_DRAIN_IN_PROGRESS (1 << 1) struct taskqueue { - char tq_name[64]; + char tq_name[TASKQUEUE_NAMELEN]; struct mtx tq_mutex; struct list tq_list; taskqueue_enqueue_fn tq_enqueue;