From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Waldemar Kozaczuk <jwkozac...@gmail.com>
Branch: master

zfs: export symbols needed by libsolaris.so

When one builds kernel with most symbols hidden, the libsolaris.so that
depends on 92 non-libc symbols from the kernel cannot be loaded and ZFS
filesystem cannot function. To address it, this patch exposes all those
symbols by annotating then with new macro OSV_LIBSOLARIS_API which
was added to the export.h header. It also adds new file with a list of
symbols to be exported - osv_libsolaris.so.symbols.

The kernel built with most symbols hidden gets larger by 12K only.

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>

---
diff --git a/arch/aarch64/smp.cc b/arch/aarch64/smp.cc
--- a/arch/aarch64/smp.cc
+++ b/arch/aarch64/smp.cc
@@ -11,6 +11,7 @@
 #include <osv/prio.hh>
 #include <osv/printf.hh>
 #include <osv/aligned_new.hh>
+#include <osv/export.h>
 #include "processor.hh"
 #include "psci.hh"
 #include "arch-dtb.hh"
@@ -21,6 +22,7 @@ extern "C" { /* see boot.S */
     extern u64 start_secondary_cpu();
 }
 
+OSV_LIBSOLARIS_API
 volatile unsigned smp_processors = 1;
 
 sched::cpu* smp_initial_find_current_cpu()
diff --git a/arch/x64/smp.cc b/arch/x64/smp.cc
--- a/arch/x64/smp.cc
+++ b/arch/x64/smp.cc
@@ -26,6 +26,7 @@ extern "C" {
 #include <osv/prio.hh>
 #include "osv/percpu.hh"
 #include <osv/aligned_new.hh>
+#include <osv/export.h>
 
 extern "C" { void smp_main(void); }
 
@@ -38,6 +39,7 @@ extern char smpboot[], smpboot_end[];
 using namespace processor;
 
 extern bool smp_allocator;
+OSV_LIBSOLARIS_API
 volatile unsigned smp_processors = 1;
 
 using boost::intrusive::get_parent_from_member;
diff --git a/bsd/porting/cpu.cc b/bsd/porting/cpu.cc
--- a/bsd/porting/cpu.cc
+++ b/bsd/porting/cpu.cc
@@ -6,11 +6,12 @@
  */
 
 #include <osv/sched.hh>
+#include <osv/export.h>
 #include <bsd/porting/netport.h>
 #include <machine/cpu.h>
 #include "processor.hh"
 
-extern "C" int get_cpuid(void)
+extern "C" OSV_LIBSOLARIS_API int get_cpuid(void)
 {
     return sched::cpu::current()->id;
 }
diff --git a/bsd/porting/kthread.cc b/bsd/porting/kthread.cc
--- a/bsd/porting/kthread.cc
+++ b/bsd/porting/kthread.cc
@@ -9,15 +9,17 @@
 #include <stddef.h>
 #include <assert.h>
 #include <osv/sched.hh>
+#include <osv/export.h>
 
 #include <bsd/porting/curthread.h>
 #include <bsd/porting/netport.h>
 #include <bsd/porting/kthread.h>
 #include <bsd/sys/sys/kthread.h>
 
+OSV_LIBSOLARIS_API
 struct proc proc0;
 
-int
+OSV_LIBSOLARIS_API int
 kthread_add(void (*func)(void *), void *arg, struct proc *p,
                struct thread **newtdp, int flags, int pages,
                const char *fmt, ...)
@@ -57,19 +59,19 @@ int kproc_create(void (*func)(void *), void *arg, struct 
proc **p,
     return 0;
 }
 
-void
+OSV_LIBSOLARIS_API void
 kthread_exit(void)
 {
     sched::thread::exit();
 }
 
-struct thread *
+OSV_LIBSOLARIS_API struct thread *
 get_curthread(void)
 {
     return reinterpret_cast<struct thread *>(sched::thread::current());
 }
 
-struct proc *
+OSV_LIBSOLARIS_API struct proc *
 get_curproc(void)
 {
     return reinterpret_cast<struct proc *>(sched::thread::current());
diff --git a/bsd/porting/mmu.cc b/bsd/porting/mmu.cc
--- a/bsd/porting/mmu.cc
+++ b/bsd/porting/mmu.cc
@@ -12,6 +12,7 @@
 #include <osv/mmio.hh>
 #include <osv/mempool.hh>
 #include <osv/pagecache.hh>
+#include <osv/export.h>
 
 void *pmap_mapdev(uint64_t paddr, size_t size)
 {
@@ -26,26 +27,31 @@ uint64_t virt_to_phys(void *virt)
 /*
  * Get the amount of used memory.
  */
+OSV_LIBSOLARIS_API
 uint64_t kmem_used(void)
 {
     return memory::stats::total() - memory::stats::jvm_heap() - 
memory::stats::free();
 }
 
+OSV_LIBSOLARIS_API
 int vm_paging_needed(void)
 {
     return 0;
 }
 
+OSV_LIBSOLARIS_API
 int vm_throttling_needed(void)
 {
     return memory::throttling_needed();
 }
 
+OSV_LIBSOLARIS_API
 void mmu_unmap(void* ab)
 {
     pagecache::unmap_arc_buf((arc_buf_t*)ab);
 }
 
+OSV_LIBSOLARIS_API
 void mmu_map(void* key, void* ab, void* page)
 {
     pagecache::map_arc_buf((pagecache::hashkey*)key, (arc_buf_t*)ab, page);
diff --git a/bsd/porting/netport.cc b/bsd/porting/netport.cc
--- a/bsd/porting/netport.cc
+++ b/bsd/porting/netport.cc
@@ -14,12 +14,16 @@
 #include <bsd/sys/net/if_var.h>
 #include <bsd/sys/net/if_media.h>
 
+#include <osv/export.h>
+
+OSV_LIBSOLARIS_API
 int copyin(const void *uaddr, void *kaddr, size_t len)
 {
     memcpy(kaddr, uaddr, len);
     return (0);
 }
 
+OSV_LIBSOLARIS_API
 int copyout(const void *kaddr, void *uaddr, size_t len)
 {
     memcpy(uaddr, kaddr, len);
@@ -57,6 +61,7 @@ int copystr(const void *kfaddr, void *kdaddr, size_t len, 
size_t *done)
     return do_copystr(kfaddr, kdaddr, len, done);
 }
 
+OSV_LIBSOLARIS_API
 int copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done)
 {
     return do_copystr(uaddr, kaddr, len, done);
@@ -159,4 +164,5 @@ ifmedia_ioctl(struct ifnet *ifp, struct bsd_ifreq *ifr, 
struct ifmedia *ifm, u_l
     return -ENOSYS;
 }
 
+OSV_LIBSOLARIS_API
 size_t physmem;
diff --git a/bsd/porting/netport1.cc b/bsd/porting/netport1.cc
--- a/bsd/porting/netport1.cc
+++ b/bsd/porting/netport1.cc
@@ -11,6 +11,7 @@
 #include "bsd/sys/cddl/compat/opensolaris/sys/kcondvar.h"
 #include "bsd/cddl/compat/opensolaris/include/mnttab.h"
 #include <osv/mount.h>
+#include <osv/export.h>
 
 extern "C" {
     #include <time.h>
@@ -58,6 +59,7 @@ size_t get_physmem(void)
     return memory::phys_mem_size / memory::page_size;
 }
 
+OSV_LIBSOLARIS_API
 int cv_timedwait(kcondvar_t *cv, mutex_t *mutex, clock_t tmo)
 {
     if (tmo <= 0) {
diff --git a/bsd/porting/shrinker.cc b/bsd/porting/shrinker.cc
--- a/bsd/porting/shrinker.cc
+++ b/bsd/porting/shrinker.cc
@@ -7,6 +7,7 @@
 
 #include <osv/mempool.hh>
 #include <osv/debug.hh>
+#include <osv/export.h>
 #include <sys/eventhandler.h>
 #include <algorithm>
 
@@ -105,7 +106,7 @@ void bsd_shrinker_init(void)
 
 //This needs to be a C-style function so it can be called
 //from libsolaris.so
-extern "C" void register_shrinker_arc_funs(
+extern "C" OSV_LIBSOLARIS_API void register_shrinker_arc_funs(
     size_t (*_arc_lowmem_fun)(void *, int),
     size_t (*_arc_sized_adjust_fun)(int64_t)) {
     arc_lowmem_fun = _arc_lowmem_fun;
diff --git a/bsd/porting/synch.cc b/bsd/porting/synch.cc
--- a/bsd/porting/synch.cc
+++ b/bsd/porting/synch.cc
@@ -10,6 +10,7 @@
 #include <errno.h>
 #include <osv/sched.hh>
 #include "osv/trace.hh"
+#include <osv/export.h>
 
 #include <bsd/porting/netport.h>
 #include <bsd/porting/synch.h>
@@ -169,7 +170,7 @@ void synch_port::wakeup_one(void* chan)
     mutex_unlock(&_lock);
 }
 
-extern "C" int _msleep(void *chan, struct mtx *mtx, int priority, const char 
*wmesg,
+extern "C" OSV_LIBSOLARIS_API int _msleep(void *chan, struct mtx *mtx, int 
priority, const char *wmesg,
      int timo)
 {
     return (synch_port::instance()->_msleep(chan, mtx, priority, wmesg, timo));
@@ -180,12 +181,12 @@ extern "C" int tsleep(void *chan, int priority, const 
char *wmesg, int timo)
     return (_msleep(chan, 0, priority, wmesg, timo));
 }
 
-extern "C" void bsd_pause(const char *wmesg, int timo)
+extern "C" OSV_LIBSOLARIS_API void bsd_pause(const char *wmesg, int timo)
 {
     _msleep(0, 0, 0, wmesg, timo);
 }
 
-extern "C" void wakeup(void* chan)
+extern "C" OSV_LIBSOLARIS_API void wakeup(void* chan)
 {
     synch_port::instance()->wakeup(chan);
 }
diff --git a/bsd/porting/uma_stub.cc b/bsd/porting/uma_stub.cc
--- a/bsd/porting/uma_stub.cc
+++ b/bsd/porting/uma_stub.cc
@@ -11,6 +11,7 @@
 #include <bsd/porting/netport.h>
 #include <bsd/porting/uma_stub.h>
 #include <osv/preempt-lock.hh>
+#include <osv/export.h>
 
 void* uma_zone::cache::alloc()
 {
@@ -84,6 +85,7 @@ void * uma_zalloc_arg(uma_zone_t zone, void *udata, int flags)
     return (ptr);
 }
 
+OSV_LIBSOLARIS_API
 void * uma_zalloc(uma_zone_t zone, int flags)
 {
     return uma_zalloc_arg(zone, NULL, flags);
@@ -120,6 +122,7 @@ void uma_zfree_arg(uma_zone_t zone, void *item, void *udata)
     }
 }
 
+OSV_LIBSOLARIS_API
 void uma_zfree(uma_zone_t zone, void *item)
 {
     uma_zfree_arg(zone, item, NULL);
@@ -140,6 +143,7 @@ int uma_zone_set_max(uma_zone_t zone, int nitems)
     return (nitems);
 }
 
+OSV_LIBSOLARIS_API
 uma_zone_t uma_zcreate(const char *name, size_t size, uma_ctor ctor,
             uma_dtor dtor, uma_init uminit, uma_fini fini,
             int align, u_int32_t flags)
@@ -202,6 +206,7 @@ u_int32_t *uma_find_refcnt(uma_zone_t zone, void *item)
     return &(UMA_ITEM_HDR(zone, item))->refcnt;
 }
 
+OSV_LIBSOLARIS_API
 void uma_zdestroy(uma_zone_t zone)
 {
     delete zone;
diff --git a/bsd/sys/crypto/sha2/sha2.c b/bsd/sys/crypto/sha2/sha2.c
--- a/bsd/sys/crypto/sha2/sha2.c
+++ b/bsd/sys/crypto/sha2/sha2.c
@@ -47,6 +47,7 @@
 #include <string.h>
 #endif
 #include <bsd/sys/crypto/sha2/sha2.h>
+#include <osv/export.h>
 
 /*
  * ASSERT NOTE:
@@ -321,6 +322,7 @@ static const char *sha2_hex_digits = "0123456789abcdef";
 
 
 /*** SHA-256: *********************************************************/
+OSV_LIBSOLARIS_API
 void SHA256_Init(SHA256_CTX* context) {
        if (context == (SHA256_CTX*)0) {
                return;
@@ -505,6 +507,7 @@ static void SHA256_Transform(SHA256_CTX* context, const 
sha2_word32* data) {
 
 #endif /* SHA2_UNROLL_TRANSFORM */
 
+OSV_LIBSOLARIS_API
 void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
        unsigned int    freespace, usedspace;
 
@@ -553,6 +556,7 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte 
*data, size_t len) {
        usedspace = freespace = 0;
 }
 
+OSV_LIBSOLARIS_API
 void SHA256_Final(sha2_byte digest[SHA256_DIGEST_LENGTH], SHA256_CTX* context) 
{
        sha2_word32     *d = (sha2_word32*)digest;
        unsigned int    usedspace;
diff --git a/bsd/sys/kern/subr_eventhandler.c b/bsd/sys/kern/subr_eventhandler.c
--- a/bsd/sys/kern/subr_eventhandler.c
+++ b/bsd/sys/kern/subr_eventhandler.c
@@ -34,6 +34,8 @@
 #include <bsd/sys/sys/eventhandler.h>
 #include <machine/atomic.h>
 
+#include <osv/export.h>
+
 MALLOC_DEFINE(M_EVENTHANDLER, "eventhandler", "Event handler records");
 
 /* List of 'slow' lists */
@@ -127,7 +129,7 @@ eventhandler_register_internal(struct eventhandler_list 
*list,
     return(epn);
 }
 
-eventhandler_tag
+OSV_LIBSOLARIS_API eventhandler_tag
 eventhandler_register(struct eventhandler_list *list, const char *name, 
                      void *func, void *arg, int priority)
 {
@@ -143,7 +145,7 @@ eventhandler_register(struct eventhandler_list *list, const 
char *name,
     return (eventhandler_register_internal(list, name, &eg->ee));
 }
 
-void
+OSV_LIBSOLARIS_API void
 eventhandler_deregister(struct eventhandler_list *list, eventhandler_tag tag)
 {
     struct eventhandler_entry  *ep = tag;
@@ -189,7 +191,7 @@ _eventhandler_find_list(const char *name)
  * Lookup a "slow" list by name.  Returns with the list locked.
  * Returns the list locked
  */
-struct eventhandler_list *
+OSV_LIBSOLARIS_API struct eventhandler_list *
 eventhandler_find_list(const char *name)
 {
     struct eventhandler_list   *list;
diff --git a/bsd/sys/kern/subr_sbuf.c b/bsd/sys/kern/subr_sbuf.c
--- a/bsd/sys/kern/subr_sbuf.c
+++ b/bsd/sys/kern/subr_sbuf.c
@@ -36,6 +36,8 @@
 #include <stdarg.h>
 #include <ctype.h>
 
+#include <osv/export.h>
+
 #define        SBMALLOC(size)          malloc(size)
 #define        SBFREE(buf)             free(buf)
 
@@ -147,7 +149,7 @@ sbuf_newbuf(struct sbuf *s, char *buf, int length, int 
flags)
  * If buf is non-NULL, it points to a static or already-allocated string
  * big enough to hold at least length characters.
  */
-struct sbuf *
+OSV_LIBSOLARIS_API struct sbuf *
 sbuf_new(struct sbuf *s, char *buf, int length, int flags)
 {
 
@@ -784,7 +786,7 @@ sbuf_vprintf(struct sbuf *s, const char *fmt, va_list ap)
 /*
  * Format the given arguments and append the resulting string to an sbuf.
  */
-int
+OSV_LIBSOLARIS_API int
 sbuf_printf(struct sbuf *s, const char *fmt, ...)
 {
        va_list ap;
@@ -843,7 +845,7 @@ sbuf_error(const struct sbuf *s)
 /*
  * Finish off an sbuf.
  */
-int
+OSV_LIBSOLARIS_API int
 sbuf_finish(struct sbuf *s)
 {
 
@@ -901,7 +903,7 @@ sbuf_len(struct sbuf *s)
 /*
  * Clear an sbuf, free its buffer if necessary.
  */
-void
+OSV_LIBSOLARIS_API void
 sbuf_delete(struct sbuf *s)
 {
        int isdyn;
diff --git a/bsd/sys/kern/subr_taskqueue.c b/bsd/sys/kern/subr_taskqueue.c
--- a/bsd/sys/kern/subr_taskqueue.c
+++ b/bsd/sys/kern/subr_taskqueue.c
@@ -38,6 +38,7 @@
 #include <bsd/sys/sys/priority.h>
 #include <bsd/sys/sys/taskqueue.h>
 
+#include <osv/export.h>
 
 struct taskqueue_busy {
        struct task     *tb_running;
@@ -113,7 +114,7 @@ _taskqueue_create(const char *name, int mflags,
        return queue;
 }
 
-struct taskqueue *
+OSV_LIBSOLARIS_API struct taskqueue *
 taskqueue_create(const char *name, int mflags,
                 taskqueue_enqueue_fn enqueue, void *context)
 {
@@ -134,7 +135,7 @@ taskqueue_terminate(struct thread **pp, struct taskqueue 
*tq)
        }
 }
 
-void
+OSV_LIBSOLARIS_API void
 taskqueue_free(struct taskqueue *queue)
 {
 
@@ -190,7 +191,8 @@ taskqueue_enqueue_locked(struct taskqueue *queue, struct 
task *task)
 
        return (0);
 }
-int
+
+OSV_LIBSOLARIS_API int
 taskqueue_enqueue(struct taskqueue *queue, struct task *task)
 {
        int res;
@@ -396,7 +398,7 @@ taskqueue_drain_timeout(struct taskqueue *queue,
 }
 #endif
 
-int
+OSV_LIBSOLARIS_API int
 taskqueue_start_threads(struct taskqueue **tqp, int count, int pri,
                        const char *name, ...)
 {
@@ -482,7 +484,7 @@ taskqueue_thread_loop(void *arg)
        kthread_exit();
 }
 
-void
+OSV_LIBSOLARIS_API void
 taskqueue_thread_enqueue(void *context)
 {
        struct taskqueue **tqp, *tq;
@@ -496,7 +498,7 @@ taskqueue_thread_enqueue(void *context)
 
 //TASKQUEUE_DEFINE_THREAD(thread);
 
-int
+OSV_LIBSOLARIS_API int
 taskqueue_member(struct taskqueue *queue, struct thread *td)
 {
        int i, j, ret = 0;
diff --git a/bsd/sys/libkern/arc4random.c b/bsd/sys/libkern/arc4random.c
--- a/bsd/sys/libkern/arc4random.c
+++ b/bsd/sys/libkern/arc4random.c
@@ -19,6 +19,8 @@
 #include <bsd/sys/sys/param.h>
 #include <bsd/sys/sys/libkern.h>
 
+#include <osv/export.h>
+
 #define        ARC4_RESEED_BYTES 65536
 #define        ARC4_RESEED_SECONDS 300
 #define        ARC4_KEYBYTES (256 / 8)
@@ -32,6 +34,7 @@ static struct mtx arc4_mtx;
 static u_int8_t arc4_randbyte(void);
 
 /* FIXME: OSv - use real random */
+OSV_LIBSOLARIS_API
 int read_random(void* buf, int count)
 {
     struct timeval tv;
diff --git a/core/condvar.cc b/core/condvar.cc
--- a/core/condvar.cc
+++ b/core/condvar.cc
@@ -10,6 +10,7 @@
 #include <errno.h>
 #include <osv/trace.hh>
 #include <osv/wait_record.hh>
+#include <osv/export.h>
 
 TRACEPOINT(trace_condvar_wait, "%p", condvar *);
 TRACEPOINT(trace_condvar_wake_one, "%p", condvar *);
@@ -161,7 +162,7 @@ void condvar::wake_all()
     }
 }
 
-extern "C"
+extern "C" OSV_LIBSOLARIS_API
 int condvar_wait(condvar_t *condvar, mutex_t* user_mutex, uint64_t expiration)
 {
     if (expiration) {
@@ -172,11 +173,13 @@ int condvar_wait(condvar_t *condvar, mutex_t* user_mutex, 
uint64_t expiration)
     }
 }
 
+OSV_LIBSOLARIS_API
 void condvar_wake_one(condvar_t *condvar)
 {
     condvar->wake_one();
 }
 
+OSV_LIBSOLARIS_API
 void condvar_wake_all(condvar_t *condvar)
 {
     condvar->wake_all();
diff --git a/core/debug.cc b/core/debug.cc
--- a/core/debug.cc
+++ b/core/debug.cc
@@ -14,6 +14,7 @@
 #include <osv/sched.hh>
 #include <osv/debug.hh>
 #include <osv/debug.h>
+#include <osv/export.h>
 
 #include "early-console.hh"
 
@@ -144,7 +145,7 @@ void logger::wrt(const char* tag, logger_severity severity, 
const char* _fmt, va
 }
 
 extern "C" {
-void tprintf(const char* tag, logger_severity severity, const char* _fmt, ...)
+OSV_LIBSOLARIS_API void tprintf(const char* tag, logger_severity severity, 
const char* _fmt, ...)
 {
     va_list ap;
     va_start(ap, _fmt);
@@ -220,6 +221,7 @@ extern "C" {
         }
     }
 
+    OSV_LIBSOLARIS_API
     void debug(const char *msg)
     {
         fill_debug_buffer(msg, strlen(msg));
diff --git a/core/kprintf.c b/core/kprintf.c
--- a/core/kprintf.c
+++ b/core/kprintf.c
@@ -10,6 +10,7 @@
  */
 
 #include <osv/debug.h>
+#include <osv/export.h>
 
 #include "../libc/stdio/stdio_impl.h"
 #include <assert.h>
@@ -44,6 +45,7 @@ int vkprintf(const char *restrict fmt, va_list ap)
        return vfprintf(&f, fmt, ap);
 }
 
+OSV_LIBSOLARIS_API
 int kprintf(const char *restrict fmt, ...)
 {
        int ret;
diff --git a/core/lfmutex.cc b/core/lfmutex.cc
--- a/core/lfmutex.cc
+++ b/core/lfmutex.cc
@@ -9,6 +9,7 @@
 #include <osv/trace.hh>
 #include <osv/sched.hh>
 #include <osv/wait_record.hh>
+#include <osv/export.h>
 
 namespace lockfree {
 
@@ -278,16 +279,16 @@ bool mutex::owned() const
 // functions, and make the methods inline, calling these functions with
 // "this" as a parameter. But this would be un-C++-like :(
 extern "C" {
-__attribute__((flatten)) void lockfree_mutex_lock(void *m) {
+OSV_LIBSOLARIS_API __attribute__((flatten)) void lockfree_mutex_lock(void *m) {
     static_cast<lockfree::mutex *>(m)->lock();
 }
-__attribute__ ((flatten)) void lockfree_mutex_unlock(void *m) {
+OSV_LIBSOLARIS_API __attribute__ ((flatten)) void lockfree_mutex_unlock(void 
*m) {
     static_cast<lockfree::mutex *>(m)->unlock();
 }
-__attribute__ ((flatten)) bool lockfree_mutex_try_lock(void *m) {
+OSV_LIBSOLARIS_API __attribute__ ((flatten)) bool lockfree_mutex_try_lock(void 
*m) {
     return static_cast<lockfree::mutex *>(m)->try_lock();
 }
-__attribute__ ((flatten)) bool lockfree_mutex_owned(void *m) {
+OSV_LIBSOLARIS_API __attribute__ ((flatten)) bool lockfree_mutex_owned(void 
*m) {
     return static_cast<lockfree::mutex *>(m)->owned();
 }
 }
diff --git a/core/mempool.cc b/core/mempool.cc
--- a/core/mempool.cc
+++ b/core/mempool.cc
@@ -61,6 +61,7 @@ static size_t object_size(void* v);
 
 std::atomic<unsigned int> smp_allocator_cnt{};
 bool smp_allocator = false;
+OSV_LIBSOLARIS_API
 unsigned char *osv_reclaimer_thread;
 
 namespace memory {
@@ -421,7 +422,7 @@ __thread unsigned emergency_alloc_level = 0;
 
 reclaimer_lock_type reclaimer_lock;
 
-extern "C" void thread_mark_emergency()
+extern "C" OSV_LIBSOLARIS_API void thread_mark_emergency()
 {
     emergency_alloc_level = 1;
 }
diff --git a/core/pagecache.cc b/core/pagecache.cc
--- a/core/pagecache.cc
+++ b/core/pagecache.cc
@@ -13,6 +13,7 @@
 #include <boost/variant.hpp>
 #include <osv/pagecache.hh>
 #include <osv/mempool.hh>
+#include <osv/export.h>
 #include <fs/vfs/vfs.h>
 #include <fs/vfs/vfs_id.h>
 #include <osv/trace.hh>
@@ -30,7 +31,7 @@ void (*arc_buf_get_hashkey_fun)(arc_buf_t*, uint64_t[4]);
 
 //This needs to be a C-style function so it can be called
 //from libsolaris.so
-extern "C" void register_pagecache_arc_funs(
+extern "C" OSV_LIBSOLARIS_API void register_pagecache_arc_funs(
     void (*_arc_unshare_buf_fun)(arc_buf_t*),
     void (*_arc_share_buf_fun)(arc_buf_t*),
     void (*_arc_buf_accessed_fun)(const uint64_t[4]),
@@ -773,6 +774,6 @@ constexpr double access_scanner::_min_cpu;
 //The access_scanner thread is ZFS specific so it
 //is initialized by calling the function below if libsolaris.so
 //is loaded.
-extern "C" void start_pagecache_access_scanner() {
+extern "C" OSV_LIBSOLARIS_API void start_pagecache_access_scanner() {
     pagecache::s_access_scanner = new pagecache::access_scanner();
 }
diff --git a/core/rwlock.cc b/core/rwlock.cc
--- a/core/rwlock.cc
+++ b/core/rwlock.cc
@@ -8,6 +8,7 @@
 #include <mutex>
 #include <osv/sched.hh>
 #include <osv/rwlock.h>
+#include <osv/export.h>
 
 rwlock::rwlock()
     : _readers(0),
@@ -180,56 +181,67 @@ bool rwlock::has_readers()
     return _readers;
 }
 
+OSV_LIBSOLARIS_API
 void rwlock_init(rwlock_t* rw)
 {
     new (rw) rwlock;
 }
 
+OSV_LIBSOLARIS_API
 void rwlock_destroy(rwlock_t* rw)
 {
     rw->~rwlock();
 }
 
+OSV_LIBSOLARIS_API
 void rw_rlock(rwlock_t* rw)
 {
     rw->rlock();
 }
 
+OSV_LIBSOLARIS_API
 void rw_wlock(rwlock_t* rw)
 {
     rw->wlock();
 }
 
+OSV_LIBSOLARIS_API
 int rw_try_rlock(rwlock_t* rw)
 {
     return rw->try_rlock();
 }
 
+OSV_LIBSOLARIS_API
 int rw_try_wlock(rwlock_t* rw)
 {
     return rw->try_wlock();
 }
 
+OSV_LIBSOLARIS_API
 void rw_runlock(rwlock_t* rw)
 {
     rw->runlock();
 }
 
+OSV_LIBSOLARIS_API
 void rw_wunlock(rwlock_t* rw)
 {
     rw->wunlock();
 }
 
+OSV_LIBSOLARIS_API
 int rw_try_upgrade(rwlock_t* rw)
 {
     return rw->try_upgrade();
 }
 
+OSV_LIBSOLARIS_API
 void rw_downgrade(rwlock_t* rw)
 {
     rw->downgrade();
 }
 
+OSV_LIBSOLARIS_API
 int rw_wowned(rwlock_t* rw)
 {
     return rw->wowned();
diff --git a/drivers/zfs.cc b/drivers/zfs.cc
--- a/drivers/zfs.cc
+++ b/drivers/zfs.cc
@@ -8,6 +8,7 @@
 #include "drivers/zfs.hh"
 
 #include <osv/device.h>
+#include <osv/export.h>
 
 namespace zfsdev {
 
@@ -68,6 +69,6 @@ void zfsdev_init(void)
 }
 
 //Needs to be a C-style function so it can be called from libsolaris.so
-extern "C" void register_osv_zfs_ioctl( int (*osv_zfs_ioctl_fun)(unsigned 
long, void*)) {
+extern "C" OSV_LIBSOLARIS_API void register_osv_zfs_ioctl( int 
(*osv_zfs_ioctl_fun)(unsigned long, void*)) {
     zfsdev::osv_zfs_ioctl_fun = osv_zfs_ioctl_fun;
 }
diff --git a/exported_symbols/osv_libsolaris.so.symbols 
b/exported_symbols/osv_libsolaris.so.symbols
--- a/exported_symbols/osv_libsolaris.so.symbols
+++ b/exported_symbols/osv_libsolaris.so.symbols
@@ -0,0 +1,92 @@
+alloc_bio
+bio_wait
+bsd_pause
+condvar_wait
+condvar_wake_all
+condvar_wake_one
+copyin
+copyinstr
+copyout
+cv_timedwait
+debug
+destroy_bio
+device_close
+device_open
+eventhandler_deregister
+eventhandler_find_list
+eventhandler_register
+fdrop
+file_dentry
+file_flags
+file_offset
+file_setoffset
+get_cpuid
+get_curproc
+get_curthread
+iftovt_tab
+kmem_used
+kprintf
+kthread_add
+kthread_exit
+lockfree_mutex_lock
+lockfree_mutex_owned
+lockfree_mutex_try_lock
+lockfree_mutex_unlock
+mmu_map
+mmu_unmap
+_msleep
+osv_reclaimer_thread
+physmem
+proc0
+read_random
+register_osv_zfs_ioctl
+register_pagecache_arc_funs
+register_shrinker_arc_funs
+release_mp_dentries
+rw_downgrade
+rwlock_destroy
+rwlock_init
+rw_rlock
+rw_runlock
+rw_try_rlock
+rw_try_upgrade
+rw_try_wlock
+rw_wlock
+rw_wowned
+rw_wunlock
+sbuf_delete
+sbuf_finish
+sbuf_new
+sbuf_printf
+SHA256_Final
+SHA256_Init
+SHA256_Update
+smp_processors
+start_pagecache_access_scanner
+sys_open
+sys_read
+sys_write
+taskqueue_create
+taskqueue_enqueue
+taskqueue_free
+taskqueue_member
+taskqueue_start_threads
+taskqueue_thread_enqueue
+thread_mark_emergency
+tprintf
+uiomove
+uma_zalloc
+uma_zcreate
+uma_zdestroy
+uma_zfree
+utsname
+vfs_busy
+vfs_nullop
+vfs_unbusy
+vget
+vm_paging_needed
+vm_throttling_needed
+vrele
+vttoif_tab
+wakeup
+zfs_update_vfsops
diff --git a/fs/devfs/device.cc b/fs/devfs/device.cc
--- a/fs/devfs/device.cc
+++ b/fs/devfs/device.cc
@@ -53,6 +53,7 @@
 #include <osv/device.h>
 #include <osv/debug.h>
 #include <osv/buf.h>
+#include <osv/export.h>
 
 #include <geom/geom_disk.h>
 
@@ -322,7 +323,7 @@ device_destroy(struct device *dev)
  * should be handled by an each device driver if it is
  * needed.
  */
-int
+OSV_LIBSOLARIS_API int
 device_open(const char *name, int mode, struct device **devp)
 {
        struct devops *ops;
@@ -356,7 +357,7 @@ device_open(const char *name, int mode, struct device 
**devp)
  * Even if the target driver does not have close routine,
  * this function does not return any errors.
  */
-int
+OSV_LIBSOLARIS_API int
 device_close(struct device *dev)
 {
        struct devops *ops;
diff --git a/fs/vfs/kern_descrip.cc b/fs/vfs/kern_descrip.cc
--- a/fs/vfs/kern_descrip.cc
+++ b/fs/vfs/kern_descrip.cc
@@ -185,6 +185,7 @@ void fhold(struct file* fp)
     __sync_fetch_and_add(&fp->f_count, 1);
 }
 
+OSV_LIBSOLARIS_API
 int fdrop(struct file *fp)
 {
     int o = fp->f_count, n;
@@ -253,6 +254,7 @@ void file::epoll_del(epoll_ptr ep)
     }
 }
 
+OSV_LIBSOLARIS_API
 dentry* file_dentry(file* fp)
 {
     return fp->f_dentry.get();
@@ -268,16 +270,19 @@ bool is_nonblock(struct file *f)
     return (f->f_flags & FNONBLOCK);
 }
 
+OSV_LIBSOLARIS_API
 int file_flags(file *f)
 {
     return f->f_flags;
 }
 
+OSV_LIBSOLARIS_API
 off_t file_offset(file* f)
 {
     return f->f_offset;
 }
 
+OSV_LIBSOLARIS_API
 void file_setoffset(file* f, off_t o)
 {
     f->f_offset = o;
diff --git a/fs/vfs/kern_physio.cc b/fs/vfs/kern_physio.cc
--- a/fs/vfs/kern_physio.cc
+++ b/fs/vfs/kern_physio.cc
@@ -13,13 +13,14 @@
 
 #include <osv/device.h>
 #include <osv/bio.h>
+#include <osv/export.h>
 #include <sys/param.h>
 #include <assert.h>
 #include <sys/refcount.h>
 #include <osv/mutex.h>
 #include <osv/waitqueue.hh>
 
-struct bio *
+OSV_LIBSOLARIS_API struct bio *
 alloc_bio(void)
 {
        auto *b = new (std::nothrow) bio();
@@ -28,13 +29,13 @@ alloc_bio(void)
        return b;
 }
 
-void
+OSV_LIBSOLARIS_API void
 destroy_bio(struct bio *bio)
 {
        delete bio;
 }
 
-int
+OSV_LIBSOLARIS_API int
 bio_wait(struct bio *bio)
 {
        SCOPE_LOCK(bio->bio_mutex);
diff --git a/fs/vfs/subr_uio.cc b/fs/vfs/subr_uio.cc
--- a/fs/vfs/subr_uio.cc
+++ b/fs/vfs/subr_uio.cc
@@ -39,8 +39,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <osv/uio.h>
+#include <osv/export.h>
 
-int
+OSV_LIBSOLARIS_API int
 uiomove(void *cp, size_t n, struct uio *uio)
 {
        assert(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE);
diff --git a/fs/vfs/vfs_mount.cc b/fs/vfs/vfs_mount.cc
--- a/fs/vfs/vfs_mount.cc
+++ b/fs/vfs/vfs_mount.cc
@@ -48,6 +48,7 @@
 #include <osv/device.h>
 #include <osv/debug.h>
 #include <osv/mutex.h>
+#include <osv/export.h>
 #include "vfs.h"
 
 #include <memory>
@@ -219,7 +220,7 @@ sys_mount(const char *dev, const char *dir, const char 
*fsname, int flags, const
     return error;
 }
 
-void
+OSV_LIBSOLARIS_API void
 release_mp_dentries(struct mount *mp)
 {
     /* Decrement referece count of root vnode */
@@ -417,7 +418,7 @@ vfs_findroot(const char *path, struct mount **mp, char 
**root)
 /*
  * Mark a mount point as busy.
  */
-void
+OSV_LIBSOLARIS_API void
 vfs_busy(struct mount *mp)
 {
     SCOPE_LOCK(mount_lock);
@@ -428,14 +429,14 @@ vfs_busy(struct mount *mp)
 /*
  * Mark a mount point as busy.
  */
-void
+OSV_LIBSOLARIS_API void
 vfs_unbusy(struct mount *mp)
 {
     SCOPE_LOCK(mount_lock);
     mp->m_count--;
 }
 
-int
+OSV_LIBSOLARIS_API int
 vfs_nullop(void)
 {
     return 0;
diff --git a/fs/vfs/vfs_syscalls.cc b/fs/vfs/vfs_syscalls.cc
--- a/fs/vfs/vfs_syscalls.cc
+++ b/fs/vfs/vfs_syscalls.cc
@@ -53,6 +53,7 @@
 #include <osv/prex.h>
 #include <osv/vnode.h>
 #include <osv/vfs_file.hh>
+#include <osv/export.h>
 #include "vfs.h"
 #include <fs/fs.hh>
 
@@ -105,7 +106,7 @@ open_no_follow_chk(char *path)
        return (error);
 }
 
-int
+OSV_LIBSOLARIS_API int
 sys_open(char *path, int flags, mode_t mode, struct file **fpp)
 {
        file *fp;
@@ -241,7 +242,7 @@ sys_close(struct file *fp)
        return 0;
 }
 
-int
+OSV_LIBSOLARIS_API int
 sys_read(struct file *fp, const struct iovec *iov, size_t niov,
                off_t offset, size_t *count)
 {
@@ -280,7 +281,7 @@ sys_read(struct file *fp, const struct iovec *iov, size_t 
niov,
     return error;
 }
 
-int
+OSV_LIBSOLARIS_API int
 sys_write(struct file *fp, const struct iovec *iov, size_t niov,
                off_t offset, size_t *count)
 {
diff --git a/fs/vfs/vfs_vnode.cc b/fs/vfs/vfs_vnode.cc
--- a/fs/vfs/vfs_vnode.cc
+++ b/fs/vfs/vfs_vnode.cc
@@ -41,12 +41,15 @@
 
 #include <osv/prex.h>
 #include <osv/vnode.h>
+#include <osv/export.h>
 #include "vfs.h"
 
+OSV_LIBSOLARIS_API
 enum vtype iftovt_tab[16] = {
        VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
        VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
 };
+OSV_LIBSOLARIS_API
 int vttoif_tab[10] = {
        0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK,
        S_IFSOCK, S_IFIFO, S_IFMT, S_IFMT
@@ -165,7 +168,7 @@ vn_unlock(struct vnode *vp)
  * Increment its reference count and lock it.
  * Returns 1 if vnode was found in cache; otherwise returns 0.
  */
-int
+OSV_LIBSOLARIS_API int
 vget(struct mount *mp, uint64_t ino, struct vnode **vpp)
 {
        struct vnode *vp;
@@ -270,7 +273,7 @@ vref(struct vnode *vp)
  * when it is finished with the vnode.
  * If count drops to zero, call inactive routine and return to freelist.
  */
-void
+OSV_LIBSOLARIS_API void
 vrele(struct vnode *vp)
 {
        ASSERT(vp);
diff --git a/fs/zfs/zfs_null_vfsops.cc b/fs/zfs/zfs_null_vfsops.cc
--- a/fs/zfs/zfs_null_vfsops.cc
+++ b/fs/zfs/zfs_null_vfsops.cc
@@ -6,6 +6,7 @@
  */
 
 #include <osv/mount.h>
+#include <osv/export.h>
 
 #define zfs_mount   ((vfsop_mount_t)vfs_nullop)
 #define zfs_umount  ((vfsop_umount_t)vfs_nullop)
@@ -43,7 +44,7 @@ extern "C" int zfs_init(void)
 //Normally (without ZFS enabled) the zfs_vfsops points to dummy
 //noop functions. So when libsolaris.so is loaded, we provide the
 //function below to be called to register real vfsops for ZFS
-extern "C" void zfs_update_vfsops(struct vfsops* _vfsops) {
+extern "C" OSV_LIBSOLARIS_API void zfs_update_vfsops(struct vfsops* _vfsops) {
     zfs_vfsops.vfs_mount = _vfsops->vfs_mount;
     zfs_vfsops.vfs_unmount = _vfsops->vfs_unmount;
     zfs_vfsops.vfs_sync = _vfsops->vfs_sync;
diff --git a/include/osv/export.h b/include/osv/export.h
--- a/include/osv/export.h
+++ b/include/osv/export.h
@@ -35,6 +35,9 @@
 //
 // This is to expose some OSv functions intended to be used by modules
 #define OSV_MODULE_API __attribute__((__visibility__("default")))
+//
+// This is to expose various FreeBSD specific functions needed by 
libsolaris.so (ZFS filesystem impl)
+#define OSV_LIBSOLARIS_API __attribute__((__visibility__("default")))
 
 // In some very few cases, when source files are compiled without visibility
 // flag in order to expose most symbols in the corresponding file, there are 
some specific
diff --git a/libc/misc/uname.c b/libc/misc/uname.c
--- a/libc/misc/uname.c
+++ b/libc/misc/uname.c
@@ -24,6 +24,7 @@ _Static_assert(KERNEL_VERSION(LINUX_MAJOR, LINUX_MINOR, 
LINUX_PATCH)
 #define str(s) #s
 #define str2(s) str(s)
 
+OSV_LIBSOLARIS_API
 struct utsname utsname = {
        .sysname        = "Linux",      /* lie, to avoid confusing the payload. 
*/
        .nodename       = "osv.local",

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/00000000000040590805e3407d9a%40google.com.

Reply via email to