Re-add Freebsd Support

freebsd-work
Jack Lucas 2019-02-08 19:17:30 -05:00
parent 6105055b82
commit 3154242a3a
48 changed files with 699 additions and 8 deletions

View File

@ -139,6 +139,7 @@ help:
@echo "linux-ppc-32" @echo "linux-ppc-32"
@echo "linux-ppc-64" @echo "linux-ppc-64"
@echo "linux-arm" @echo "linux-arm"
@echo "freebsd-x86-64"
@echo "macosx-x86-32" @echo "macosx-x86-32"
@echo "macosx-x86-64" @echo "macosx-x86-64"
@echo "macosx-x86-fat" @echo "macosx-x86-fat"
@ -153,6 +154,9 @@ help:
ALL = factor factor-ffi-test factor-lib ALL = factor factor-ffi-test factor-lib
freebsd-x86-64:
$(MAKE) $(ALL) CONFIG=vm/Config.freebsd.x86.64
macosx-x86-32: macosx-x86-32:
$(MAKE) $(ALL) macosx.app CONFIG=vm/Config.macosx.x86.32 $(MAKE) $(ALL) macosx.app CONFIG=vm/Config.macosx.x86.32

View File

@ -0,0 +1 @@
Jack Lucas

View File

@ -0,0 +1,26 @@
USING: alien.libraries.finder arrays assocs
combinators.short-circuit io io.encodings.utf8 io.files
io.files.info io.launcher kernel sequences sets splitting system
unicode ;
IN: alien.libraries.finder.freebsd
<PRIVATE
: parse-ldconfig-lines ( string -- triple )
[ ":-" split1 [ drop ] dip
"=>" split1 [ [ blank? ] trim ] bi@
2array
] map ;
: load-ldconfig-cache ( -- seq )
"/sbin/ldconfig -r" utf8 [ lines ] with-process-reader
rest parse-ldconfig-lines ;
: name-matches? ( lib double -- ? )
first swap ?head [ ?first CHAR: . = ] [ drop f ] if ;
PRIVATE>
M: freebsd find-library*
"l" prepend load-ldconfig-cache
[ name-matches? ] with find nip ?first dup [ ".so" append ] when ;

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1 @@
Slava Pestov

View File

@ -0,0 +1,9 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces system kernel accessors assocs continuations
unix io.backend io.backend.unix io.backend.unix.multiplexers
io.backend.unix.multiplexers.kqueue io.files.unix ;
IN: io.backend.unix.bsd
M: bsd init-io ( -- )
<kqueue-mx> mx set-global ;

View File

@ -0,0 +1 @@
bsd

View File

@ -0,0 +1,17 @@
<<<<<<< HEAD
USING: io.backend io.backend.unix system namespaces kernel accessors assocs continuations unix init io.backend.unix.multiplexers io.backend.unix.multiplexers.kqueue vocabs io.files.unix ;
<< "io.files.unix" require >> ! needed for deploy
M: freebsd init-io ( -- )
<kqueue-mx> mx set-global ;
freebsd set-io-backend
[ start-signal-pipe-thread ]
"io.backend.unix:signal-pipe-thread" add-startup-hook
=======
USING: io.backend.unix.bsd io.backend system ;
freebsd set-io-backend
>>>>>>> da9226d5b5... Re-add Freebsd Support

View File

@ -0,0 +1 @@
freebsd

View File

@ -1 +1,2 @@
macosx macosx
freebsd

View File

@ -0,0 +1,18 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel alien.syntax math io.files.unix system
unix.stat accessors combinators calendar.unix
io.files.info.unix ;
IN: io.files.info.unix.bsd
TUPLE: bsd-file-info < unix-file-info birth-time flags gen ;
M: bsd new-file-info ( -- class ) bsd-file-info new ;
M: bsd stat>file-info ( stat -- file-info )
[ call-next-method ] keep
{
[ st_flags>> >>flags ]
[ st_gen>> >>gen ]
[ st_birthtimespec>> timespec>unix-time >>birth-time ]
} cleave ;

View File

@ -0,0 +1 @@
bsd

View File

@ -0,0 +1,64 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data alien.strings arrays
calendar.unix classes.struct combinators grouping
io.encodings.utf8 io.files io.files.info io.files.info.unix
io.files.unix libc kernel math sequences specialized-arrays
system unix unix.getfsstat.freebsd unix.statfs.freebsd
unix.statvfs.freebsd ;
SPECIALIZED-ARRAY: uint
SPECIALIZED-ARRAY: statfs
IN: io.files.info.unix.freebsd
TUPLE: freebsd-file-info < unix-file-info birth-time flags gen ;
M: freebsd new-file-info ( -- class ) freebsd-file-info new ;
M: freebsd stat>file-info ( stat -- file-info )
[ call-next-method ] keep
{
[ st_flags>> >>flags ]
[ st_gen>> >>gen ]
[ st_birthtimespec>> timespec>unix-time >>birth-time ]
} cleave ;
TUPLE: freebsd-file-system-info < unix-file-system-info
io-size owner type-id filesystem-subtype ;
M: freebsd file-systems ( -- array )
f void* <ref> dup 0 getmntinfo dup io-error
[ void* deref ] dip \ statfs <c-direct-array>
[ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ;
M: freebsd new-file-system-info freebsd-file-system-info new ;
M: freebsd file-system-statfs ( normalized-path -- statfs )
\ statfs <struct> [ statfs-func io-error ] keep ;
M: freebsd file-system-statvfs ( normalized-path -- statvfs )
\ statvfs <struct> [ statvfs-func io-error ] keep ;
M: freebsd statfs>file-system-info ( file-system-info byte-array -- file-system-info' )
{
[ f_bsize>> >>block-size ]
[ f_iosize>> >>io-size ]
[ f_blocks>> >>blocks ]
[ f_bfree>> >>blocks-free ]
[ f_bavail>> >>blocks-available ]
[ f_files>> >>files ]
[ f_ffree>> >>files-free ]
[ f_fsid>> >>id ]
[ f_owner>> >>owner ]
[ f_type>> >>type-id ]
[ f_flags>> >>flags ]
[ f_fstypename>> utf8 alien>string >>type ]
[ f_mntonname>> utf8 alien>string >>mount-point ]
[ f_mntfromname>> utf8 alien>string >>device-name ]
} cleave ;
M: freebsd statvfs>file-system-info ( file-system-info byte-array -- file-system-info' )
{
[ f_frsize>> >>preferred-block-size ]
[ f_favail>> >>files-available ]
[ f_namemax>> >>name-max ]
} cleave ;

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1,3 @@
IN: io.monitors.freebsd
! Empty for now

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1,142 @@
USING: alien.c-types alien.strings alien.syntax destructors
kernel system ;
IN: libc
LIBRARY: libc
CONSTANT: SIGHUP 1
CONSTANT: SIGINT 2
CONSTANT: SIGQUIT 3
CONSTANT: SIGILL 4
CONSTANT: SIGTRAP 5
CONSTANT: SIGABRT 6
CONSTANT: SIGEMT 7
CONSTANT: SIGFPE 8
CONSTANT: SIGKILL 9
CONSTANT: SIGBUS 10
CONSTANT: SIGSEGV 11
CONSTANT: SIGSYS 12
CONSTANT: SIGPIPE 13
CONSTANT: SIGALRM 14
CONSTANT: SIGTERM 15
CONSTANT: SIGURG 16
CONSTANT: SIGSTOP 17
CONSTANT: SIGTSTP 18
CONSTANT: SIGCONT 19
CONSTANT: SIGCHLD 20
CONSTANT: SIGTTIN 21
CONSTANT: SIGTTOU 22
CONSTANT: SIGIO 23
CONSTANT: SIGXCPU 24
CONSTANT: SIGXFSZ 25
CONSTANT: SIGVTALRM 26
CONSTANT: SIGPROF 27
CONSTANT: SIGWINCH 28
CONSTANT: SIGINFO 29
CONSTANT: SIGUSR1 30
CONSTANT: SIGUSR2 31
CONSTANT: SIGTHR 32
FUNCTION: int strerror_r ( int errno, char* buf, size_t buflen )
M: freebsd strerror ( errno -- str )
[
1024 [ malloc &free ] keep [ strerror_r ] keepd nip
alien>native-string
] with-destructors ;
CONSTANT: EPERM 1
CONSTANT: ENOENT 2
CONSTANT: ESRCH 3
CONSTANT: EINTR 4
CONSTANT: EIO 5
CONSTANT: ENXIO 6
CONSTANT: E2BIG 7
CONSTANT: ENOEXEC 8
CONSTANT: EBADF 9
CONSTANT: ECHILD 10
CONSTANT: EDEADLK 11
CONSTANT: ENOMEM 12
CONSTANT: EACCES 13
CONSTANT: EFAULT 14
CONSTANT: ENOTBLK 15
CONSTANT: EBUSY 16
CONSTANT: EEXIST 17
CONSTANT: EXDEV 18
CONSTANT: ENODEV 19
CONSTANT: ENOTDIR 20
CONSTANT: EISDIR 21
CONSTANT: EINVAL 22
CONSTANT: ENFILE 23
CONSTANT: EMFILE 24
CONSTANT: ENOTTY 25
CONSTANT: ETXTBSY 26
CONSTANT: EFBIG 27
CONSTANT: ENOSPC 28
CONSTANT: ESPIPE 29
CONSTANT: EROFS 30
CONSTANT: EMLINK 31
CONSTANT: EPIPE 32
CONSTANT: EDOM 33
CONSTANT: ERANGE 34
CONSTANT: EAGAIN 35
ALIAS: EWOULDBLOCK EAGAIN
CONSTANT: EINPROGRESS 36
CONSTANT: EALREADY 37
CONSTANT: ENOTSOCK 38
CONSTANT: EDESTADDRREQ 39
CONSTANT: EMSGSIZE 40
CONSTANT: EPROTOTYPE 41
CONSTANT: ENOPROTOOPT 42
CONSTANT: EPROTONOSUPPORT 43
CONSTANT: ESOCKTNOSUPPORT 44
CONSTANT: EOPNOTSUPP 45
ALIAS: ENOTSUP EOPNOTSUPP
CONSTANT: EPFNOSUPPORT 46
CONSTANT: EAFNOSUPPORT 47
CONSTANT: EADDRINUSE 48
CONSTANT: EADDRNOTAVAIL 49
CONSTANT: ENETDOWN 50
CONSTANT: ENETUNREACH 51
CONSTANT: ENETRESET 52
CONSTANT: ECONNABORTED 53
CONSTANT: ECONNRESET 54
CONSTANT: ENOBUFS 55
CONSTANT: EISCONN 56
CONSTANT: ENOTCONN 57
CONSTANT: ESHUTDOWN 58
CONSTANT: ETOOMANYREFS 59
CONSTANT: ETIMEDOUT 60
CONSTANT: ECONNREFUSED 61
CONSTANT: ELOOP 62
CONSTANT: ENAMETOOLONG 63
CONSTANT: EHOSTDOWN 64
CONSTANT: EHOSTUNREACH 65
CONSTANT: ENOTEMPTY 66
CONSTANT: EPROCLIM 67
CONSTANT: EUSERS 68
CONSTANT: EDQUOT 69
CONSTANT: ESTALE 70
CONSTANT: EREMOTE 71
CONSTANT: EBADRPC 72
CONSTANT: ERPCMISMATCH 73
CONSTANT: EPROGUNAVAIL 74
CONSTANT: EPROGMISMATCH 75
CONSTANT: EPROCUNAVAIL 76
CONSTANT: ENOLCK 77
CONSTANT: ENOSYS 78
CONSTANT: EFTYPE 79
CONSTANT: EAUTH 80
CONSTANT: ENEEDAUTH 81
CONSTANT: EIDRM 82
CONSTANT: ENOMSG 83
CONSTANT: EOVERFLOW 84
CONSTANT: ECANCELED 85
CONSTANT: EILSEQ 86
CONSTANT: ENOATTR 87
CONSTANT: EDOOFUS 88
CONSTANT: EBADMSG 89
CONSTANT: EMULTIHOP 90
CONSTANT: ENOLINK 91
CONSTANT: EPROTO 92

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1 @@
Slava Pestov

View File

@ -0,0 +1,86 @@
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.syntax classes.struct combinators
system unix.types vocabs.loader ;
IN: unix.ffi
CONSTANT: MAXPATHLEN 1024
CONSTANT: O_RDONLY 0x0000
CONSTANT: O_WRONLY 0x0001
CONSTANT: O_RDWR 0x0002
CONSTANT: O_NONBLOCK 0x0004
CONSTANT: O_APPEND 0x0008
CONSTANT: O_CREAT 0x0200
CONSTANT: O_TRUNC 0x0400
CONSTANT: O_EXCL 0x0800
CONSTANT: O_NOCTTY 0x20000
ALIAS: O_NDELAY O_NONBLOCK
CONSTANT: SOL_SOCKET 0xffff
CONSTANT: SO_REUSEADDR 0x4
CONSTANT: SO_OOBINLINE 0x100
CONSTANT: SO_SNDTIMEO 0x1005
CONSTANT: SO_RCVTIMEO 0x1006
CONSTANT: F_SETFD 2
CONSTANT: F_SETFL 4
CONSTANT: FD_CLOEXEC 1
STRUCT: sockaddr-in
{ len uchar }
{ family uchar }
{ port ushort }
{ addr in_addr_t }
{ unused longlong } ;
STRUCT: sockaddr-in6
{ len uchar }
{ family uchar }
{ port ushort }
{ flowinfo uint }
{ addr uchar[16] }
{ scopeid uint } ;
STRUCT: sockaddr-un
{ len uchar }
{ family uchar }
{ path char[104] } ;
STRUCT: passwd
{ pw_name c-string }
{ pw_passwd c-string }
{ pw_uid uid_t }
{ pw_gid gid_t }
{ pw_change time_t }
{ pw_class c-string }
{ pw_gecos c-string }
{ pw_dir c-string }
{ pw_shell c-string }
{ pw_expire time_t }
{ pw_fields int } ;
CONSTANT: max-un-path 104
CONSTANT: SOCK_STREAM 1
CONSTANT: SOCK_DGRAM 2
CONSTANT: SOCK_RAW 3
CONSTANT: AF_UNSPEC 0
CONSTANT: AF_UNIX 1
CONSTANT: AF_INET 2
ALIAS: PF_UNSPEC AF_UNSPEC
ALIAS: PF_UNIX AF_UNIX
ALIAS: PF_INET AF_INET
CONSTANT: IPPROTO_TCP 6
CONSTANT: IPPROTO_UDP 17
CONSTANT: AI_PASSIVE 1
CONSTANT: SEEK_SET 0
CONSTANT: SEEK_CUR 1
CONSTANT: SEEK_END 2

View File

@ -0,0 +1 @@
bsd

View File

@ -0,0 +1 @@
*BSD/Mac OS X support

View File

@ -0,0 +1,42 @@
USING: alien.c-types alien.syntax classes.struct unix.types unix.ffi.bsd ;
IN: unix.ffi
CONSTANT: AF_INET6 28
ALIAS: PF_INET6 AF_INET6
CONSTANT: FD_SETSIZE 1024
STRUCT: addrinfo
{ flags int }
{ family int }
{ socktype int }
{ protocol int }
{ addrlen socklen_t }
{ canonname c-string }
{ addr void* }
{ next addrinfo* } ;
STRUCT: dirent
{ d_fileno u_int32_t }
{ d_reclen u_int16_t }
{ d_type u_int8_t }
{ d_namlen u_int8_t }
{ d_name char[256] } ;
CONSTANT: SOL_SOCKET 0xffff
CONSTANT: SO_DEBUG 0x1
CONSTANT: SO_ACCEPTCONN 0x2
CONSTANT: SO_REUSEADDR 0x4
CONSTANT: SO_KEEPALIVE 0x8
CONSTANT: SO_DONTROUTE 0x10
CONSTANT: SO_BROADCAST 0x20
CONSTANT: SO_OOBINLINE 0x100
CONSTANT: SO_SNDBUF 0x1001
CONSTANT: SO_RCVBUF 0x1002
CONSTANT: SO_SNDLOWAT 0x1003
CONSTANT: SO_RCVLOWAT 0x1004
CONSTANT: SO_SNDTIMEO 0x1005
CONSTANT: SO_RCVTIMEO 0x1006
CONSTANT: SO_ERROR 0x1007
CONSTANT: SO_TYPE 0x1008

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1 @@
Jack Lucas

View File

@ -0,0 +1,12 @@
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.syntax unix.statfs.freebsd ;
IN: unix.getfsstat.freebsd
CONSTANT: MNT_WAIT 1 ! synchronously wait for I/O to complete
CONSTANT: MNT_NOWAIT 2 ! start all I/O, but do not wait for it
CONSTANT: MNT_LAZY 3 ! push data not written by filesystem syncer
CONSTANT: MNT_SUSPEND 4 ! suspend file system after sync
FUNCTION-ALIAS: getfsstat int getfsstat ( statfs* buf, long bufsize, int flags )
FUNCTION-ALIAS: getmntinfo int getmntinfo ( statfs **mntbufp, int flags )

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1,31 @@
USING: alien.c-types alien.syntax classes.struct unix.types unix.time ;
IN: unix.kqueue
STRUCT: kevent
{ ident ulong }
{ filter short }
{ flags ushort }
{ fflags uint }
{ data __uint64_t }
{ udata void* }
{ ext[4] __uint64_t } ;
FUNCTION-ALIAS: kevent-func int kevent ( int kq, kevent* changelist, int nchanges, kevent* eventlist, int nevents, timespec* timeout )
! from FreeBSD 12 sys/sys/event.h
CONSTANT: EVFILT_READ -1
CONSTANT: EVFILT_WRITE -2
CONSTANT: EVFILT_AIO -3 ! attached to aio requests
CONSTANT: EVFILT_VNODE -4 ! attached to vnodes
CONSTANT: EVFILT_PROC -5 ! attached to struct proc
CONSTANT: EVFILT_SIGNAL -6 ! attached to struct proc
CONSTANT: EVFILT_TIMER -7 ! timers
CONSTANT: EVFILT_PROCDESC -8 ! attached to process descriptors
CONSTANT: EVFILT_FS -9 ! Filesystem events
CONSTANT: EVFILT_LIO -10 ! attached to lio requests
CONSTANT: EVFILT_USER -11 ! user events
CONSTANT: EVFILT_SENDFILE -12 ! attached to sendfile requests
CONSTANT: EVFILT_EMPTY -13 ! empty send socket buf
CONSTANT: EVFILT_SYSCOUNT 13

View File

@ -0,0 +1 @@
freebsd

View File

@ -1 +1 @@
macosx macosx freebsd

View File

@ -0,0 +1,34 @@
USING: kernel alien.c-types alien.syntax math classes.struct unix.time
unix.types ;
IN: unix.stat
! FreeBSD 12
! stat64 structure
STRUCT: stat
{ st_dev dev_t }
{ st_ino ino_t }
{ st_mode mode_t }
{ st_nlink nlink_t }
{ st_uid uid_t }
{ st_gid gid_t }
{ st_rdev dev_t }
{ st_atimespec timespec }
{ st_mtimespec timespec }
{ st_ctimespec timespec }
{ st_size off_t }
{ st_blocks blkcnt_t }
{ st_blksize blksize_t }
{ st_flags fflags_t }
{ st_gen __uint64_t }
{ st_spare __int64_t }
{ st_birthtimespec timespec }
{ pad0 __int32_t[2] } ;
FUNCTION-ALIAS: stat-func int stat64 ( c-string pathname, stat* buf )
FUNCTION-ALIAS: lstat int lstat64 ( c-string pathname, stat* buf )
FUNCTION-ALIAS: fstat int fstat64 ( int fd, stat* buf )

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1,37 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax alien.c-types unix.types unix.stat classes.struct ;
IN: unix.statfs.freebsd
CONSTANT: MFSNAMELEN 16 ! length of type name including null */
CONSTANT: MNAMELEN 1024 ! size of on/from name bufs
CONSTANT: STAFS_VERSION 0x20140518
STRUCT: statfs
{ f_version uint32_t }
{ f_type uint32_t }
{ f_flags uint64_t }
{ f_bsize uint64_t }
{ f_iosize uint64_t }
{ f_blocks uint64_t }
{ f_bfree uint64_t }
{ f_bavail int64_t }
{ f_files uint64_t }
{ f_ffree int64_t }
{ f_syncwrites uint64_t }
{ f_asyncwrites uint64_t }
{ f_syncreads uint64_t }
{ f_asyncreads uint64_t }
{ f_spare uint64_t[10] }
{ f_namemax uint32_t }
{ f_owner uid_t }
{ f_fsid fsid_t }
{ f_charspare char[80] }
{ f_fstypename { char MFSNAMELEN } }
{ f_mntfromname { char MNAMELEN } }
{ f_mntonname { char MNAMELEN } } ;
FUNCTION-ALIAS: statfs-func int statfs ( c-string path, statfs* buf )
CONSTANT: MNT_WAIT 1 ! synchronously wait for I/O to complete
CONSTANT: MNT_NOWAIT 2 ! start all I/O, but do not wait for it

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1,24 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.syntax classes.struct unix.types ;
IN: unix.statvfs.freebsd
STRUCT: statvfs
{ f_bavail fsblkcnt_t }
{ f_bfree fsblkcnt_t }
{ f_blocks fsblkcnt_t }
{ f_favail fsfilcnt_t }
{ f_ffree fsfilcnt_t }
{ f_files fsfilcnt_t }
{ f_bsize ulong }
{ f_flag ulong }
{ f_frsize ulong }
{ f_fsid ulong }
{ f_namemax ulong } ;
! Flags
CONSTANT: ST_RDONLY 1 ! Read-only file system
CONSTANT: ST_NOSUID 2 ! Does not honor setuid/setgid
FUNCTION-ALIAS: statvfs-func int statvfs ( c-string path, statvfs* buf )

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1,23 @@
USING: alien.syntax alien.c-types ;
IN: unix.types
TYPEDEF: ushort __uint16_t
TYPEDEF: uint __uint32_t
TYPEDEF: int __int32_t
TYPEDEF: longlong __int64_t
TYPEDEF: __int32_t dev_t
TYPEDEF: __uint32_t ino_t
TYPEDEF: __uint16_t mode_t
TYPEDEF: __uint16_t nlink_t
TYPEDEF: __uint32_t uid_t
TYPEDEF: __uint32_t gid_t
TYPEDEF: __int64_t off_t
TYPEDEF: __int64_t blkcnt_t
TYPEDEF: __int64_t ino64_t
TYPEDEF: __int32_t blksize_t
TYPEDEF: __uint32_t fflags_t
TYPEDEF: long ssize_t
TYPEDEF: int pid_t
TYPEDEF: long time_t

View File

@ -0,0 +1 @@
freebsd

View File

@ -0,0 +1,9 @@
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: arrays io.launcher kernel present system webbrowser ;
IN: webbrowser.freebsd
M: freebsd open-item ( item -- )
present "open" swap 2array run-detached drop ;

View File

@ -0,0 +1 @@
freebsd

View File

@ -16,9 +16,10 @@ UNION: ppc ppc.32 ppc.64 ;
: cpu ( -- class ) \ cpu get-global ; foldable : cpu ( -- class ) \ cpu get-global ; foldable
SINGLETONS: windows macosx linux ; SINGLETONS: windows macosx linux freebsd ;
UNION: unix macosx linux ; UNION: bsd freebsd ;
UNION: unix macosx linux freebsd bsd ;
: os ( -- class ) \ os get-global ; foldable : os ( -- class ) \ os get-global ; foldable
@ -49,6 +50,7 @@ CONSTANT: string>cpu-hash H{
CONSTANT: string>os-hash H{ CONSTANT: string>os-hash H{
{ "windows" windows } { "windows" windows }
{ "macosx" macosx } { "macosx" macosx }
{ "freebsd" freebsd }
{ "linux" linux } { "linux" linux }
} }

4
vm/Config.freebsd Normal file
View File

@ -0,0 +1,4 @@
include vm/Config.unix
PLAF_DLL_OBJS += vm/os-genunix.o vm/os-freebsd.o vm/mvm-unix.o
PLAF_MASTER_HEADERS += vm/os-genunix.hpp vm/os-freebsd.hpp
LIBS = -lm $(X11_UI_LIBS) -pthread -lc -Wl,--export-dynamic -lthr

2
vm/Config.freebsd.x86.64 Normal file
View File

@ -0,0 +1,2 @@
include vm/Config.freebsd
include vm/Config.x86.64

40
vm/os-freebsd-x86.64.hpp Normal file
View File

@ -0,0 +1,40 @@
#include <ucontext.h>
#include <signal.h>
#include <sys/signal.h>
#include <machine/ucontext.h>
#include <sys/_ucontext.h>
#include <machine/fpu.h>
namespace factor {
inline static unsigned int uap_fpu_status(void *uap)
{
ucontext_t *ucontext = (ucontext_t *)uap;
if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM)
{
struct savefpu *xmm = (struct savefpu *)(&ucontext->uc_mcontext.mc_fpstate);
return xmm->sv_env.en_sw | xmm->sv_env.en_mxcsr;
}
else
return 0;
}
inline static void uap_clear_fpu_status(void *uap)
{
ucontext_t *ucontext = (ucontext_t *)uap;
if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM)
{
struct savefpu *xmm = (struct savefpu *)(&ucontext->uc_mcontext.mc_fpstate);
xmm->sv_env.en_sw = 0;
xmm->sv_env.en_mxcsr &= 0xffffffc0;
}
}
#define UAP_STACK_POINTER(ucontext) (((struct sigcontext *)ucontext)->sc_rsp)
#define UAP_PROGRAM_COUNTER(ucontext) (((struct sigcontext *)ucontext)->sc_rip)
#define UAP_SET_TOC_POINTER(uap, ptr) (void)0
#define UAP_STACK_POINTER_TYPE long
static const unsigned JIT_FRAME_SIZE = 32;
}

33
vm/os-freebsd.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "master.hpp"
namespace factor {
char *vm_saved_path;
/*
FreeBSD needs proc mounted for this function to work.
"mount -t procfs proc /proc"
*/
const char* vm_executable_path(){
ssize_t bufsiz = 4096;
while (true) {
char* buf = new char [bufsiz + 1];
ssize_t size = readlink("/proc/curproc/file", buf, bufsiz);
if (size < 0) {
fatal_error("Cannot read /proc/curproc/file", errno);
}
else {
if (size < bufsiz) {
buf[size] = '\0';
const char* ret = safe_strdup(buf);
delete[] buf;
return ret;
} else {
delete[] buf;
bufsiz *= 2;
}
}
}
}
}

7
vm/os-freebsd.hpp Normal file
View File

@ -0,0 +1,7 @@
namespace factor {
#define CODE_TO_FUNCTION_POINTER(code) (void)0
#define CODE_TO_FUNCTION_POINTER_CALLBACK(vm, code) (void)0
#define FUNCTION_CODE_POINTER(ptr) ptr
#define FUNCTION_TOC_POINTER(ptr) ptr
}

View File

@ -10,7 +10,6 @@
#include <signal.h> #include <signal.h>
#include <pthread.h> #include <pthread.h>
#include <sched.h> #include <sched.h>
#include "atomic-gcc.hpp" #include "atomic-gcc.hpp"
namespace factor { namespace factor {

View File

@ -27,10 +27,13 @@
#endif #endif
#else #else
#include "os-genunix.hpp" #include "os-genunix.hpp"
#if defined(__linux__) #if defined(__FreeBSD__)
#define FACTOR_OS_STRING "freebsd"
#include "os-freebsd.hpp"
#include "os-freebsd-x86.64.hpp"
#elif defined(__linux__)
#define FACTOR_OS_STRING "linux" #define FACTOR_OS_STRING "linux"
#include "os-linux.hpp" #include "os-linux.hpp"
#if defined(FACTOR_X86) #if defined(FACTOR_X86)
#include "os-linux-x86.32.hpp" #include "os-linux-x86.32.hpp"
#elif defined(FACTOR_PPC64) #elif defined(FACTOR_PPC64)
@ -44,8 +47,6 @@
#else #else
#error "Unsupported Linux flavor" #error "Unsupported Linux flavor"
#endif #endif
#else
#error "Unsupported OS"
#endif #endif
#endif #endif
#endif #endif