From 3154242a3a1fbdcbfd6ad3748189d4f7ffd2ee10 Mon Sep 17 00:00:00 2001 From: Jack Lucas Date: Fri, 8 Feb 2019 19:17:30 -0500 Subject: [PATCH] Re-add Freebsd Support --- GNUmakefile | 4 + .../libraries/finder/freebsd/authors.txt | 1 + .../libraries/finder/freebsd/freebsd.factor | 26 ++++ .../libraries/finder/freebsd/platforms.txt | 1 + basis/io/backend/unix/bsd/authors.txt | 1 + basis/io/backend/unix/bsd/bsd.factor | 9 ++ basis/io/backend/unix/bsd/platforms.txt | 1 + basis/io/backend/unix/freebsd/freebsd.factor | 17 +++ basis/io/backend/unix/freebsd/platforms.txt | 1 + .../unix/multiplexers/kqueue/platforms.txt | 1 + basis/io/files/info/unix/bsd/bsd.factor | 18 +++ basis/io/files/info/unix/bsd/platforms.txt | 1 + .../io/files/info/unix/freebsd/freebsd.factor | 64 ++++++++ .../io/files/info/unix/freebsd/platforms.txt | 1 + basis/io/monitors/freebsd/freebsd.factor | 3 + basis/io/monitors/freebsd/platforms.txt | 1 + basis/libc/freebsd/freebsd.factor | 142 ++++++++++++++++++ basis/libc/freebsd/platform.txt | 1 + basis/unix/ffi/bsd/authors.txt | 1 + basis/unix/ffi/bsd/bsd.factor | 86 +++++++++++ basis/unix/ffi/bsd/platforms.txt | 1 + basis/unix/ffi/bsd/summary.txt | 1 + basis/unix/ffi/freebsd/freebsd.factor | 42 ++++++ basis/unix/ffi/freebsd/platforms.txt | 1 + basis/unix/getfsstat/freebsd/authors.txt | 1 + basis/unix/getfsstat/freebsd/freebsd.factor | 12 ++ basis/unix/getfsstat/freebsd/platforms.txt | 1 + basis/unix/kqueue/freebsd/freebsd.factor | 31 ++++ basis/unix/kqueue/freebsd/platforms.txt | 1 + basis/unix/kqueue/platforms.txt | 2 +- basis/unix/stat/freebsd/freebsd.factor | 34 +++++ basis/unix/stat/freebsd/platforms.txt | 1 + basis/unix/statfs/freebsd/freebsd.factor | 37 +++++ basis/unix/statfs/freebsd/platforms.txt | 1 + basis/unix/statvfs/freebsd/freebsd.factor | 24 +++ basis/unix/statvfs/freebsd/platforms.txt | 1 + basis/unix/types/freebsd/freebsd.factor | 23 +++ basis/unix/types/freebsd/platforms.txt | 1 + basis/webbrowser/freebsd/freebsd.factor | 9 ++ basis/webbrowser/freebsd/platforms.txt | 1 + core/system/system.factor | 6 +- vm/Config.freebsd | 4 + vm/Config.freebsd.x86.64 | 2 + vm/os-freebsd-x86.64.hpp | 40 +++++ vm/os-freebsd.cpp | 33 ++++ vm/os-freebsd.hpp | 7 + vm/os-unix.hpp | 1 - vm/platform.hpp | 9 +- 48 files changed, 699 insertions(+), 8 deletions(-) create mode 100644 basis/alien/libraries/finder/freebsd/authors.txt create mode 100644 basis/alien/libraries/finder/freebsd/freebsd.factor create mode 100644 basis/alien/libraries/finder/freebsd/platforms.txt create mode 100755 basis/io/backend/unix/bsd/authors.txt create mode 100644 basis/io/backend/unix/bsd/bsd.factor create mode 100644 basis/io/backend/unix/bsd/platforms.txt create mode 100644 basis/io/backend/unix/freebsd/freebsd.factor create mode 100644 basis/io/backend/unix/freebsd/platforms.txt create mode 100644 basis/io/files/info/unix/bsd/bsd.factor create mode 100644 basis/io/files/info/unix/bsd/platforms.txt create mode 100644 basis/io/files/info/unix/freebsd/freebsd.factor create mode 100644 basis/io/files/info/unix/freebsd/platforms.txt create mode 100644 basis/io/monitors/freebsd/freebsd.factor create mode 100644 basis/io/monitors/freebsd/platforms.txt create mode 100644 basis/libc/freebsd/freebsd.factor create mode 100644 basis/libc/freebsd/platform.txt create mode 100644 basis/unix/ffi/bsd/authors.txt create mode 100644 basis/unix/ffi/bsd/bsd.factor create mode 100644 basis/unix/ffi/bsd/platforms.txt create mode 100644 basis/unix/ffi/bsd/summary.txt create mode 100644 basis/unix/ffi/freebsd/freebsd.factor create mode 100644 basis/unix/ffi/freebsd/platforms.txt create mode 100644 basis/unix/getfsstat/freebsd/authors.txt create mode 100644 basis/unix/getfsstat/freebsd/freebsd.factor create mode 100644 basis/unix/getfsstat/freebsd/platforms.txt create mode 100644 basis/unix/kqueue/freebsd/freebsd.factor create mode 100644 basis/unix/kqueue/freebsd/platforms.txt create mode 100644 basis/unix/stat/freebsd/freebsd.factor create mode 100644 basis/unix/stat/freebsd/platforms.txt create mode 100644 basis/unix/statfs/freebsd/freebsd.factor create mode 100644 basis/unix/statfs/freebsd/platforms.txt create mode 100644 basis/unix/statvfs/freebsd/freebsd.factor create mode 100644 basis/unix/statvfs/freebsd/platforms.txt create mode 100644 basis/unix/types/freebsd/freebsd.factor create mode 100644 basis/unix/types/freebsd/platforms.txt create mode 100644 basis/webbrowser/freebsd/freebsd.factor create mode 100644 basis/webbrowser/freebsd/platforms.txt create mode 100644 vm/Config.freebsd create mode 100644 vm/Config.freebsd.x86.64 create mode 100644 vm/os-freebsd-x86.64.hpp create mode 100644 vm/os-freebsd.cpp create mode 100644 vm/os-freebsd.hpp diff --git a/GNUmakefile b/GNUmakefile index 0cf1d9fd4c..5c734220c5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -139,6 +139,7 @@ help: @echo "linux-ppc-32" @echo "linux-ppc-64" @echo "linux-arm" + @echo "freebsd-x86-64" @echo "macosx-x86-32" @echo "macosx-x86-64" @echo "macosx-x86-fat" @@ -153,6 +154,9 @@ help: ALL = factor factor-ffi-test factor-lib +freebsd-x86-64: + $(MAKE) $(ALL) CONFIG=vm/Config.freebsd.x86.64 + macosx-x86-32: $(MAKE) $(ALL) macosx.app CONFIG=vm/Config.macosx.x86.32 diff --git a/basis/alien/libraries/finder/freebsd/authors.txt b/basis/alien/libraries/finder/freebsd/authors.txt new file mode 100644 index 0000000000..ef48e98229 --- /dev/null +++ b/basis/alien/libraries/finder/freebsd/authors.txt @@ -0,0 +1 @@ +Jack Lucas diff --git a/basis/alien/libraries/finder/freebsd/freebsd.factor b/basis/alien/libraries/finder/freebsd/freebsd.factor new file mode 100644 index 0000000000..23cc2535d3 --- /dev/null +++ b/basis/alien/libraries/finder/freebsd/freebsd.factor @@ -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 +" 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 ; + diff --git a/basis/alien/libraries/finder/freebsd/platforms.txt b/basis/alien/libraries/finder/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/alien/libraries/finder/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/io/backend/unix/bsd/authors.txt b/basis/io/backend/unix/bsd/authors.txt new file mode 100755 index 0000000000..1901f27a24 --- /dev/null +++ b/basis/io/backend/unix/bsd/authors.txt @@ -0,0 +1 @@ +Slava Pestov diff --git a/basis/io/backend/unix/bsd/bsd.factor b/basis/io/backend/unix/bsd/bsd.factor new file mode 100644 index 0000000000..209d1ab1e0 --- /dev/null +++ b/basis/io/backend/unix/bsd/bsd.factor @@ -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 ( -- ) + mx set-global ; diff --git a/basis/io/backend/unix/bsd/platforms.txt b/basis/io/backend/unix/bsd/platforms.txt new file mode 100644 index 0000000000..df796f15d4 --- /dev/null +++ b/basis/io/backend/unix/bsd/platforms.txt @@ -0,0 +1 @@ +bsd diff --git a/basis/io/backend/unix/freebsd/freebsd.factor b/basis/io/backend/unix/freebsd/freebsd.factor new file mode 100644 index 0000000000..93a186d3f2 --- /dev/null +++ b/basis/io/backend/unix/freebsd/freebsd.factor @@ -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 ( -- ) + 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 diff --git a/basis/io/backend/unix/freebsd/platforms.txt b/basis/io/backend/unix/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/io/backend/unix/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/io/backend/unix/multiplexers/kqueue/platforms.txt b/basis/io/backend/unix/multiplexers/kqueue/platforms.txt index 6e806f449e..8f05f5e83d 100644 --- a/basis/io/backend/unix/multiplexers/kqueue/platforms.txt +++ b/basis/io/backend/unix/multiplexers/kqueue/platforms.txt @@ -1 +1,2 @@ macosx +freebsd diff --git a/basis/io/files/info/unix/bsd/bsd.factor b/basis/io/files/info/unix/bsd/bsd.factor new file mode 100644 index 0000000000..64fcd0b5d6 --- /dev/null +++ b/basis/io/files/info/unix/bsd/bsd.factor @@ -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 ; diff --git a/basis/io/files/info/unix/bsd/platforms.txt b/basis/io/files/info/unix/bsd/platforms.txt new file mode 100644 index 0000000000..df796f15d4 --- /dev/null +++ b/basis/io/files/info/unix/bsd/platforms.txt @@ -0,0 +1 @@ +bsd diff --git a/basis/io/files/info/unix/freebsd/freebsd.factor b/basis/io/files/info/unix/freebsd/freebsd.factor new file mode 100644 index 0000000000..d4ceea9843 --- /dev/null +++ b/basis/io/files/info/unix/freebsd/freebsd.factor @@ -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* dup 0 getmntinfo dup io-error + [ void* deref ] dip \ statfs + [ 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 [ statfs-func io-error ] keep ; + +M: freebsd file-system-statvfs ( normalized-path -- statvfs ) + \ statvfs [ 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 ; diff --git a/basis/io/files/info/unix/freebsd/platforms.txt b/basis/io/files/info/unix/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/io/files/info/unix/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/io/monitors/freebsd/freebsd.factor b/basis/io/monitors/freebsd/freebsd.factor new file mode 100644 index 0000000000..45867b63f1 --- /dev/null +++ b/basis/io/monitors/freebsd/freebsd.factor @@ -0,0 +1,3 @@ +IN: io.monitors.freebsd + +! Empty for now \ No newline at end of file diff --git a/basis/io/monitors/freebsd/platforms.txt b/basis/io/monitors/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/io/monitors/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/libc/freebsd/freebsd.factor b/basis/libc/freebsd/freebsd.factor new file mode 100644 index 0000000000..2a9bc96eab --- /dev/null +++ b/basis/libc/freebsd/freebsd.factor @@ -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 diff --git a/basis/libc/freebsd/platform.txt b/basis/libc/freebsd/platform.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/libc/freebsd/platform.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/unix/ffi/bsd/authors.txt b/basis/unix/ffi/bsd/authors.txt new file mode 100644 index 0000000000..1901f27a24 --- /dev/null +++ b/basis/unix/ffi/bsd/authors.txt @@ -0,0 +1 @@ +Slava Pestov diff --git a/basis/unix/ffi/bsd/bsd.factor b/basis/unix/ffi/bsd/bsd.factor new file mode 100644 index 0000000000..181742ddc2 --- /dev/null +++ b/basis/unix/ffi/bsd/bsd.factor @@ -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 + + diff --git a/basis/unix/ffi/bsd/platforms.txt b/basis/unix/ffi/bsd/platforms.txt new file mode 100644 index 0000000000..df796f15d4 --- /dev/null +++ b/basis/unix/ffi/bsd/platforms.txt @@ -0,0 +1 @@ +bsd diff --git a/basis/unix/ffi/bsd/summary.txt b/basis/unix/ffi/bsd/summary.txt new file mode 100644 index 0000000000..9acec6c174 --- /dev/null +++ b/basis/unix/ffi/bsd/summary.txt @@ -0,0 +1 @@ +*BSD/Mac OS X support diff --git a/basis/unix/ffi/freebsd/freebsd.factor b/basis/unix/ffi/freebsd/freebsd.factor new file mode 100644 index 0000000000..91d9b3cf72 --- /dev/null +++ b/basis/unix/ffi/freebsd/freebsd.factor @@ -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 + diff --git a/basis/unix/ffi/freebsd/platforms.txt b/basis/unix/ffi/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/unix/ffi/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/unix/getfsstat/freebsd/authors.txt b/basis/unix/getfsstat/freebsd/authors.txt new file mode 100644 index 0000000000..ef48e98229 --- /dev/null +++ b/basis/unix/getfsstat/freebsd/authors.txt @@ -0,0 +1 @@ +Jack Lucas diff --git a/basis/unix/getfsstat/freebsd/freebsd.factor b/basis/unix/getfsstat/freebsd/freebsd.factor new file mode 100644 index 0000000000..b13226f5ee --- /dev/null +++ b/basis/unix/getfsstat/freebsd/freebsd.factor @@ -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 ) diff --git a/basis/unix/getfsstat/freebsd/platforms.txt b/basis/unix/getfsstat/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/unix/getfsstat/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/unix/kqueue/freebsd/freebsd.factor b/basis/unix/kqueue/freebsd/freebsd.factor new file mode 100644 index 0000000000..148974e4ac --- /dev/null +++ b/basis/unix/kqueue/freebsd/freebsd.factor @@ -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 + diff --git a/basis/unix/kqueue/freebsd/platforms.txt b/basis/unix/kqueue/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/unix/kqueue/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/unix/kqueue/platforms.txt b/basis/unix/kqueue/platforms.txt index 6e806f449e..f5763b39d9 100644 --- a/basis/unix/kqueue/platforms.txt +++ b/basis/unix/kqueue/platforms.txt @@ -1 +1 @@ -macosx +macosx freebsd diff --git a/basis/unix/stat/freebsd/freebsd.factor b/basis/unix/stat/freebsd/freebsd.factor new file mode 100644 index 0000000000..0ba3cbb508 --- /dev/null +++ b/basis/unix/stat/freebsd/freebsd.factor @@ -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 ) + + + diff --git a/basis/unix/stat/freebsd/platforms.txt b/basis/unix/stat/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/unix/stat/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/unix/statfs/freebsd/freebsd.factor b/basis/unix/statfs/freebsd/freebsd.factor new file mode 100644 index 0000000000..13c797d5cf --- /dev/null +++ b/basis/unix/statfs/freebsd/freebsd.factor @@ -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 + diff --git a/basis/unix/statfs/freebsd/platforms.txt b/basis/unix/statfs/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/unix/statfs/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/unix/statvfs/freebsd/freebsd.factor b/basis/unix/statvfs/freebsd/freebsd.factor new file mode 100644 index 0000000000..7abb225dc3 --- /dev/null +++ b/basis/unix/statvfs/freebsd/freebsd.factor @@ -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 ) + diff --git a/basis/unix/statvfs/freebsd/platforms.txt b/basis/unix/statvfs/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/unix/statvfs/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/unix/types/freebsd/freebsd.factor b/basis/unix/types/freebsd/freebsd.factor new file mode 100644 index 0000000000..e3c738b93e --- /dev/null +++ b/basis/unix/types/freebsd/freebsd.factor @@ -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 + diff --git a/basis/unix/types/freebsd/platforms.txt b/basis/unix/types/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/unix/types/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/basis/webbrowser/freebsd/freebsd.factor b/basis/webbrowser/freebsd/freebsd.factor new file mode 100644 index 0000000000..5b9db50b53 --- /dev/null +++ b/basis/webbrowser/freebsd/freebsd.factor @@ -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 ; diff --git a/basis/webbrowser/freebsd/platforms.txt b/basis/webbrowser/freebsd/platforms.txt new file mode 100644 index 0000000000..edfe86017d --- /dev/null +++ b/basis/webbrowser/freebsd/platforms.txt @@ -0,0 +1 @@ +freebsd diff --git a/core/system/system.factor b/core/system/system.factor index 4fcdefc024..cd25edf4e7 100644 --- a/core/system/system.factor +++ b/core/system/system.factor @@ -16,9 +16,10 @@ UNION: ppc ppc.32 ppc.64 ; : 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 @@ -49,6 +50,7 @@ CONSTANT: string>cpu-hash H{ CONSTANT: string>os-hash H{ { "windows" windows } { "macosx" macosx } + { "freebsd" freebsd } { "linux" linux } } diff --git a/vm/Config.freebsd b/vm/Config.freebsd new file mode 100644 index 0000000000..d80b37569e --- /dev/null +++ b/vm/Config.freebsd @@ -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 diff --git a/vm/Config.freebsd.x86.64 b/vm/Config.freebsd.x86.64 new file mode 100644 index 0000000000..01882aeab0 --- /dev/null +++ b/vm/Config.freebsd.x86.64 @@ -0,0 +1,2 @@ +include vm/Config.freebsd +include vm/Config.x86.64 \ No newline at end of file diff --git a/vm/os-freebsd-x86.64.hpp b/vm/os-freebsd-x86.64.hpp new file mode 100644 index 0000000000..a6bb00b89e --- /dev/null +++ b/vm/os-freebsd-x86.64.hpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include + +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; +} diff --git a/vm/os-freebsd.cpp b/vm/os-freebsd.cpp new file mode 100644 index 0000000000..5acf07fb13 --- /dev/null +++ b/vm/os-freebsd.cpp @@ -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; + } + } + } +} + +} diff --git a/vm/os-freebsd.hpp b/vm/os-freebsd.hpp new file mode 100644 index 0000000000..f2105fe649 --- /dev/null +++ b/vm/os-freebsd.hpp @@ -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 +} diff --git a/vm/os-unix.hpp b/vm/os-unix.hpp index 90d95cf59a..33bde83e5b 100644 --- a/vm/os-unix.hpp +++ b/vm/os-unix.hpp @@ -10,7 +10,6 @@ #include #include #include - #include "atomic-gcc.hpp" namespace factor { diff --git a/vm/platform.hpp b/vm/platform.hpp index 50005ad6b3..8c0ec7887c 100644 --- a/vm/platform.hpp +++ b/vm/platform.hpp @@ -27,10 +27,13 @@ #endif #else #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" #include "os-linux.hpp" - #if defined(FACTOR_X86) #include "os-linux-x86.32.hpp" #elif defined(FACTOR_PPC64) @@ -44,8 +47,6 @@ #else #error "Unsupported Linux flavor" #endif - #else - #error "Unsupported OS" #endif #endif #endif -- 2.34.1