diff options
Diffstat (limited to 'dux/src')
56 files changed, 0 insertions, 2288 deletions
diff --git a/dux/src/abrt.cc b/dux/src/abrt.cc deleted file mode 100644 index ef0fbf5..0000000 --- a/dux/src/abrt.cc +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <atomic> -# include <dux/sig> -# include <dux/thrd> - -auto ::dux::abrt() noexcept -> void { - static ::std::atomic_flag lock; - while (lock.test_and_set()) {} /* We make sure we don't abort from multiple threads. */ - ::dux::dbglog("dux.abrt :: Abort\n"); - if (::dux::haserr()) {::dux::dbglog("dux.abrt :: Last error: %s\n",::dux::errcdnm(::dux::geterr()));} - ::dux::setsighandl(::dux::sig::abrt,::dux::sighandl::dfl()); - ::dux::raise(::dux::sig::abrt); /* Raise SIGABRT to call the default signal handler. */ - ::dux::trap(); /* The default signal handler returned, so we will trap as we can't return. */ -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" dux_attr_cold auto dux_abrt() -> void {::dux::abrt();} diff --git a/dux/src/alloc.cc b/dux/src/alloc.cc deleted file mode 100644 index 278b095..0000000 --- a/dux/src/alloc.cc +++ /dev/null @@ -1,28 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/mem> - -# include <cstddef> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_alloc(::dux::uwrd const _sz) -> void * {return ::dux_priv_alloc(_sz,alignof (::std::max_align_t));} diff --git a/dux/src/crtfile.cc b/dux/src/crtfile.cc deleted file mode 100644 index 2d1d48b..0000000 --- a/dux/src/crtfile.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/io> - -# include <dux/str> - -# include <fcntl.h> -# if defined(dux_os_freebsd) -# include <errno.h> -# elif defined(dux_os_linux) -# include <linux/errno.h> -# endif - -auto ::dux::crtfile(char const * _path,::dux::uint16 const _acs) noexcept -> ::dux::file { - dux_ass("",_path != nullptr); - ::dux::file file; - ::dux::dbglog("dux.crtfile :: Create \"%s\"\n",_path); - auto const sysdat {static_cast<::dux::priv::filesysdat *>(file._sysdat)}; -# if defined(dux_os_posix) -open:; - auto const openatret {::dux_priv_posix_openat(AT_FDCWD,_path,O_CREAT | O_TRUNC | O_WRONLY,static_cast<::mode_t>(_acs))}; - if (openatret == -0x1) [[unlikely]] { - switch (dux_priv_errno) { - default: - ::dux::seterr(::dux::errcd::runerr); - break; - case EACCES: - [[fallthrough]]; - case EROFS: - ::dux::seterr(::dux::errcd::badacs); - break; - case EINTR: - goto open; - case ENOTDIR: - ::dux::seterr(::dux::errcd::nodir); - break; - } - ::dux::dbglog("dux.\x1B[91mcrtfile\x1B[0m :: Error!\n"); - return file; - } - sysdat->fd = openatret; -# endif - file._path.ptr = _path; - file._path.sz = ::dux::strlen(_path); - file._typ = ::dux::iotyp::w; - file._isopen = true; - return file; -} diff --git a/dux/src/errcdnm.cc b/dux/src/errcdnm.cc deleted file mode 100644 index 8401c28..0000000 --- a/dux/src/errcdnm.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_errcdnm(::dux::errcd const _cd) -> ::dux::str {return ::dux::errcdnm(_cd);} diff --git a/dux/src/exit.cc b/dux/src/exit.cc deleted file mode 100644 index e1eb4f8..0000000 --- a/dux/src/exit.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/thrd> - -# include <sys/types.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -auto ::dux::exit(::dux::stat const _stat) noexcept -> void { - if (::dux::ismainthrd()) [[unlikely]] { /* Check if the calling thread is also the main thread. Only thread exit and quick exit may be invoked outside the main thread. */ - ::dux::dbglog("dux.\x1B[91mexit\x1B[0m :: Standard exit invoked outside main thread!\n"); - ::dux::abrt(); - } - ::dux::priv::exitlock.store(true); - ::dux::priv::exitstat = _stat; - ::std::longjmp(::dux::priv::exitjmp,0x1); -} - -auto ::dux::exit(::dux::stat const _stat,::dux::priv::qexit) noexcept -> void { - using ::dux::priv::exitlock; - if (exitlock.load()) [[unlikely]] {for (;;) {}} - exitlock.store(true); - auto const stat {static_cast<int>(_stat)}; - for (;;) { -# if defined(dux_os_freebsd) - ::dux::syscall(SYS_exit,stat); -# elif defined(dux_os_linux) - ::dux::syscall(__NR_exit_group,stat); - ::dux::syscall(__NR_exit,stat); -# endif - } -} - -auto ::dux::exit(::dux::stat const _stat,::dux::priv::thrdexit) noexcept -> void { - auto const stat {static_cast<int>(_stat)}; - for (;;) { -# if defined(dux_os_freebsd) - ::dux::syscall(SYS_exit,stat); -# elif defined(dux_os_linux) - ::dux::syscall(__NR_exit,stat); -# endif - } -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" dux_attr_cold auto dux_exit( ::dux::stat const _stat) -> void {::dux::exit(_stat);} -extern "C" dux_attr_cold auto dux_qexit( ::dux::stat const _stat) -> void {::dux::exit(_stat,::dux::qexit);} -extern "C" dux_attr_cold auto dux_thrdexit(::dux::stat const _stat) -> void {::dux::exit(_stat,::dux::thrdexit);} diff --git a/dux/src/file.cc b/dux/src/file.cc deleted file mode 100644 index 094b310..0000000 --- a/dux/src/file.cc +++ /dev/null @@ -1,197 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/io> - -# include <dux/str> - -# include <fcntl.h> -# if defined(dux_os_freebsd) -# include <errno.h> -# elif defined(dux_os_linux) -# include <linux/errno.h> -# endif - -namespace dux::local { - [[nodiscard]] constexpr static auto iotypstr(::dux::iotyp const _typ) noexcept -> ::dux::str { - switch (_typ) { - case ::dux::iotyp::r: - return ::dux::priv::strlittoduxstr("R"); - case ::dux::iotyp::rw: - return ::dux::priv::strlittoduxstr("R/W"); - case ::dux::iotyp::w: - return ::dux::priv::strlittoduxstr("W"); - } - ::dux::unreach(); - } -} - -::dux::file::file() noexcept : _isopen(false) {this->_sysdat = ::dux::alloc<::dux::priv::filesysdat>();} - -::dux::file::~file() noexcept { - if (this->isopen()) [[unlikely]] { - ::dux::dbglog("dux.\x1B[91mfile\x1B[0m :: Pipe wasn't closed!\n"); - ::dux::abrt(); - } - auto const sysdat {static_cast<::dux::priv::filesysdat *>(this->_sysdat)}; - ::dux::free(sysdat); -} - -auto ::dux::file::close() noexcept -> void { - if (!this->isopen()) [[unlikely]] {return;} - ::dux::dbglog("dux.file.close :: Close \"%s\"\n",this->path().ptr); - auto const sysdat {static_cast<::dux::priv::filesysdat *>(this->_sysdat)}; -# if defined(dux_os_posix) -close:; - auto const closeret {::dux_priv_posix_close(sysdat->fd)}; - if (closeret == -0x1) [[unlikely]] { - switch (dux_priv_errno) { - default: - ::dux::seterr(::dux::errcd::runerr); - break; - case EINTR: - goto close; - } - ::dux::dbglog("dux.file.open :: Error!\n"); - return; - } -# endif - this->_isopen = false; -} - -auto ::dux::file::isopen() noexcept -> bool {return this->_isopen;} - -# if false /* Base for dux.pipe.mv (for future implementation): */ -auto ::dux::file::mv(char const * const _newpath) noexcept -> ::dux::str { - auto const oldpath {this->path()}; - auto const newpath {[&_newpath] { - ::dux::str newpath; - newpath.ptr = _newpath; - newpath.sz = ::dux::strlen(_newpath); - return newpath; - }()}; - if (newpath.sz != oldpath.sz || !::dux::memeq(newpath.ptr,newpath.sz,oldpath.ptr)) [[unlikely]] {goto retold;} -retold:; - return oldpath; -} -# endif - -auto ::dux::file::open(char const * const _path,::dux::iotyp const _typ) noexcept -> void { - dux_ass("",_path != nullptr); - if (this->isopen()) [[unlikely]] {this->close();} - ::dux::dbglog("dux.file.open :: Open %s:\"%s\"\n",::dux::local::iotypstr(_typ).ptr,_path); - auto const sysdat {static_cast<::dux::priv::filesysdat *>(this->_sysdat)}; -# if defined(dux_os_posix) - auto const openatflags {[&_typ] { - switch (_typ) { - case ::dux::iotyp::r: - return O_RDONLY; - case ::dux::iotyp::rw: - return O_RDWR; - case ::dux::iotyp::w: - return O_WRONLY; - } - ::dux::unreach(); - }()}; -open:; - auto const openatret {::dux_priv_posix_openat(AT_FDCWD,_path,openatflags,static_cast<::mode_t>(0x0))}; - if (openatret == -0x1) [[unlikely]] { - switch (dux_priv_errno) { - default: - ::dux::seterr(::dux::errcd::runerr); - break; - case EACCES: - [[fallthrough]]; - case EROFS: - ::dux::seterr(::dux::errcd::badacs); - break; - case EINTR: - goto open; - case ENOENT: - ::dux::seterr(::dux::errcd::nofile); - break; - case ENOTDIR: - ::dux::seterr(::dux::errcd::nodir); - break; - } - ::dux::dbglog("dux.file.\x1B[91mopen\x1B[0m :: Error!\n"); - return; - } - sysdat->fd = openatret; -# endif - this->_path.ptr = _path; - this->_path.sz = ::dux::strlen(_path); - this->_typ = _typ; - this->_isopen = true; -} - -auto ::dux::file::path() const noexcept -> ::dux::str {return this->_path;} - -auto ::dux::file::read(::dux::uwrd const _num) noexcept -> ::dux::arr<::dux::uint8> { - if (!this->isopen()) [[unlikely]] { - ::dux::dbglog("dux.file.\x1B[91mread\x1B[0m :: Pipe not open!\n"); - ::dux::abrt(); - } - if (this->typ() != ::dux::iotyp::r && this->typ() != ::dux::iotyp::rw) [[unlikely]] { - ::dux::dbglog("dux.file.\x1B[91mread\x1B[0m :: I/O type (%s) does not support reading!\n",::dux::local::iotypstr(_typ).ptr); - ::dux::abrt(); - } - ::dux::dbglog("dux.file.read :: Read %zu @ \"%s\"\n",_num,this->path()); - auto const sysdat {static_cast<::dux::priv::filesysdat *>(this->_sysdat)}; - ::dux::arr<::dux::uint8> buf; - buf.alloc(_num); -# if defined(dux_os_posix) -read:; - auto const readret {::dux_priv_posix_read(sysdat->fd,buf.raw(),_num)}; - if (readret == dux_swrdl(-0x1)) [[unlikely]] { - switch (dux_priv_errno) { - case EINTR: - goto read; - } - ::dux::dbglog("dux.file.\x1B[91mread\x1B[0m :: Unable to read file!\n"); - ::dux::seterr(::dux::errcd::ioerr); - buf.free(); - return buf; - } -# endif - return buf; -} - -auto ::dux::file::typ() const noexcept -> ::dux::iotyp {return this->_typ;} - -auto ::dux::file::write(void const * const _buf,::dux::uwrd const _sz) noexcept -> void { - dux_ass("",_buf != nullptr); - dux_ass("",_sz != dux_uwrdl(0x0)); - if (!this->isopen()) [[unlikely]] { - ::dux::dbglog("dux.file.\x1B[91mwrite\x1B[0m :: Pipe not open!\n"); - ::dux::abrt(); - } - if (this->typ() != ::dux::iotyp::rw && this->typ() != ::dux::iotyp::w) [[unlikely]] { - ::dux::dbglog("dux.file.\x1B[91mwrite\x1B[0m :: I/O type (%s) does not support writting!\n",::dux::local::iotypstr(_typ)); - ::dux::abrt(); - } - auto const sysdat {static_cast<::dux::priv::filesysdat *>(this->_sysdat)}; - ::dux::dbglog("dux.file.write :: Write %zu @ %p -> \"%s\"\n",_sz,_buf,this->path().ptr); -# if defined(dux_os_posix) - ::dux_priv_posix_write(sysdat->fd,_buf,_sz); - ::dux_priv_posix_fsync(sysdat->fd); -# endif -} diff --git a/dux/src/fndchr.cc b/dux/src/fndchr.cc deleted file mode 100644 index ec06041..0000000 --- a/dux/src/fndchr.cc +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_fndchr(char const * const restrict _str,int const _chr) -> ::dux_priv_uwrd { - if constexpr (::dux::dbg) { - if (_chr >= ::dux::maxval<char>) [[unlikely]] { - ::dux::seterr(::dux::errcd::illparam); - return dux_uwrdl(-0x1); - } - } - return ::dux::fndchr(_str,static_cast<char>(_chr)); -} diff --git a/dux/src/free.cc b/dux/src/free.cc deleted file mode 100644 index 4ec9864..0000000 --- a/dux/src/free.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/mem> - -# include <dux/sig> - -auto ::dux::free(::dux::nullptrtyp) noexcept -> void { - ::dux::dbglog("dux.free :: Address 0x0 is not freeable!\n"); - ::dux::raise(::dux::sig::segv); - ::dux::unreach(); /* SIGSEGV handlers may not return, so we can guarantee that this function also never returns. */ -} diff --git a/dux/src/freernd.cc b/dux/src/freernd.cc deleted file mode 100644 index 5325fb1..0000000 --- a/dux/src/freernd.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/math> - -# include <dux/mem> - -auto ::dux::priv::freernd(::dux::uint8 * const restrict _ptr) noexcept -> void {::dux::free(_ptr);} diff --git a/dux/src/getallocsz.cc b/dux/src/getallocsz.cc deleted file mode 100644 index db7de87..0000000 --- a/dux/src/getallocsz.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/mem> - -# include <dux/seq> - -auto ::dux::priv::getallocsz([[maybe_unused]] void * const restrict _ptr) noexcept -> ::dux::uwrd {return dux_uwrdl(-0x1);} /* TO-DO: Implement. */ diff --git a/dux/src/getenv.cc b/dux/src/getenv.cc deleted file mode 100644 index 5bb2ad4..0000000 --- a/dux/src/getenv.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -extern char * * environ; - -auto ::dux::getenv(char const * const restrict _envvarname) noexcept -> ::dux::str { - ::dux::str str; - constexpr auto envvarnamebufsz {dux_uwrdl(0xFF)}; - static char envvarnamebuf[envvarnamebufsz]; - if (environ == nullptr) [[unlikely]] { - str.ptr = nullptr; - return str; - } - for (auto envvars = const_cast<char const * const *>(environ);*envvars != nullptr;++envvars) { - auto envvar = *envvars; - auto const eqpos = ::dux::fndchr(envvar,'='); - auto envvarname = envvarnamebuf; - ::dux::cpy(envvar,eqpos,envvarname); - envvarname[eqpos] = '\u0000'; - if (::dux::streq(envvarname,_envvarname)) [[unlikely]] { - str.ptr = envvar + eqpos + dux_uwrdl(0x1); - str.sz = eqpos; - ::dux::dbglog("dux.getenv :: Got value of environment variable %s: \"%s\"\n",_envvarname,str.ptr); - return str; - } - } - str.ptr = ""; - str.sz = dux_uwrdl(0x0); - ::dux::dbglog("dux.getenv :: Environment variable %s did not exist!\n",_envvarname); - return str; -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_getenv(char const * const restrict _envvarname) -> ::dux::str {return ::dux::getenv(_envvarname);} diff --git a/dux/src/getmainparam.cc b/dux/src/getmainparam.cc deleted file mode 100644 index e25311f..0000000 --- a/dux/src/getmainparam.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_getmainparam(void const * const _params,::dux::uwrd const _n) noexcept -> ::dux::str {return static_cast<::dux::mainparams const *>(_params)->param(_n);} diff --git a/dux/src/getnummainparams.cc b/dux/src/getnummainparams.cc deleted file mode 100644 index e1c2532..0000000 --- a/dux/src/getnummainparams.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_getnummainparams(void const * const _params) noexcept -> ::dux::uwrd {return static_cast<::dux::mainparams const *>(_params)->num();} diff --git a/dux/src/gettime.cc b/dux/src/gettime.cc deleted file mode 100644 index 75b7d4b..0000000 --- a/dux/src/gettime.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/time> - -# include <time.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -static_assert(sizeof (::time_t) * dux_bytesz >= dux_uwrdl(0x40),"The size of the system type (time_t) must be eqaul to or larger than our replacement type's size."); - -auto ::dux::gettime() noexcept -> ::dux::sint64 { - struct timespec timespec {}; - ::dux_priv_posix_clock_gettime(CLOCK_REALTIME,×pec); - return static_cast<::dux::sint64>(timespec.tv_sec); -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_gettime() -> ::dux::sint64 {return ::dux::gettime();} diff --git a/dux/src/ismainthrd.cc b/dux/src/ismainthrd.cc deleted file mode 100644 index c5f2cf8..0000000 --- a/dux/src/ismainthrd.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/thrd> - -auto ::dux::ismainthrd() noexcept -> bool { -# if defined(dux_os_linux) - if (::dux_priv_posix_getpid() != static_cast<::pid_t>(::dux::syscall(__NR_gettid))) {return true;} /* Check if calling thread is also the main thread. Only thread exit and quick exit are allowed outside the main thread. */ -# endif - return false; /* I don't know how to check for this on other platforms. */ -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_ismainthrd() -> bool {return ::dux::ismainthrd();} diff --git a/dux/src/mainparams.cc b/dux/src/mainparams.cc deleted file mode 100644 index e00e62e..0000000 --- a/dux/src/mainparams.cc +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -::dux::mainparams::mainparams() noexcept {this->_alloc = false;} - -::dux::mainparams::~mainparams() noexcept {if (this->_alloc) {::dux::free(this->_params);}} - -auto ::dux::mainparams::fromstd(int const argc,char const * const * const argv) noexcept -> void { - this->~mainparams(); - if (argc == 0x0) [[unlikely]] { - this->_params = nullptr; - this->_num = dux_uwrdl(0x0); - return; - } - this->_num = {static_cast<::dux::uwrd>(argc)}; - this->_params = ::dux::alloc<::dux::str>(this->_num); - if (::dux::geterr() != ::dux::errcd::noerr) [[unlikely]] {return;} - this->_alloc = true; - for (auto n {dux_uwrdl(0x0)};n < this->_num;++n) { - auto & param {this->_params[n]}; - param.ptr = argv[n]; - param.sz = ::dux::strlen(param.ptr); - } -} - -auto ::dux::mainparams::num() const noexcept -> ::dux::uwrd {return this->_num;} - -auto ::dux::mainparams::param(::dux::uwrd const _n) const noexcept -> ::dux::str { - if (_n >= _num) [[unlikely]] { - ::dux::str str; - str.ptr = nullptr; - str.sz = dux_uwrdl(0x0); - ::dux::seterr(::dux::errcd::outofrange); - return str; - } - return this->_params[_n]; -} diff --git a/dux/src/memeq.cc b/dux/src/memeq.cc deleted file mode 100644 index bcf3e88..0000000 --- a/dux/src/memeq.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/mem> - -# include <dux/sig> - -auto ::dux::memeq(void const * const restrict _lptr,::dux::uwrd const _num,void const * const restrict _rptr) noexcept -> bool { - auto lptr {static_cast<::dux::uint8 const *>(_lptr)}; - auto rptr {static_cast<::dux::uint8 const *>(_rptr)}; - auto const maxlptr {lptr + _num - dux_uwrdl(0x1)}; - for (;lptr <= maxlptr;++lptr,++rptr) {if (*lptr != *rptr) [[unlikely]] {return false;}} - return true; -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_memeq(void const * const restrict _lptr,::dux::uwrd const _num,void const * const restrict _rptr) noexcept -> bool {return ::dux::memeq(_lptr,_num,_rptr);} diff --git a/dux/src/onexit.cc b/dux/src/onexit.cc deleted file mode 100644 index cde37f2..0000000 --- a/dux/src/onexit.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <atomic> - -auto ::dux::onexit(::dux::priv::onexitfn const _fn) noexcept -> void { - if (::dux::priv::exitlock.load()) [[unlikely]] { - ::dux::dbglog("dux.\x1B[91monexit\x1B[0m :: Invoked after exit!\n"); - ::dux::seterr(::dux::errcd::illcallseq); - return; - } - using ::dux::priv::onexitlock; - { - while (onexitlock.load()) {} /* Wait for other threads to register onexit functions. */ - onexitlock.store(true); - using ::dux::priv::onexitfns; - using ::dux::priv::numonexitfns; - for (auto n {dux_uwrdl(0x0)};n < numonexitfns;++n) {if (onexitfns[n] == _fn) [[unlikely]] { - ::dux::dbglog("dux.onexit :: Function at %p has already been registered!\n",reinterpret_cast<void *>(_fn)); - goto ret; - }} - if (numonexitfns == ::dux::priv::maxnumonexitfns) [[unlikely]] { - ::dux::dbglog("dux.\x1B[91monexit\x1B[0m :: Function at %p cannot be registered as limit (%zu) has been reached!\n",reinterpret_cast<void *>(_fn),::dux::priv::maxnumonexitfns); - ::dux::seterr(::dux::errcd::nospc); - goto ret; - } - ::dux::dbglog("dux.onexit :: Register %p!\n",reinterpret_cast<void *>(_fn)); - ++numonexitfns; - onexitfns[numonexitfns - 0x1] = _fn; - } -ret:; - onexitlock.store(false); -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" dux_attr_cold auto dux_onexit(::dux::priv::onexitfn const _fn) -> void {::dux::onexit(_fn);} diff --git a/dux/src/priv/alloc.cc b/dux/src/priv/alloc.cc deleted file mode 100644 index 26dfa96..0000000 --- a/dux/src/priv/alloc.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/mem> - -# include <cstddef> -# include <cstdlib> -# include <stdlib.h> - -extern "C" auto dux_priv_alloc(::dux::uwrd const _sz,::dux::uwrd const _align) -> void * { /* Currently, we implement memory using the standard C++ functions. Implement our own runtime system. */ - if (_sz == dux_uwrdl(0x0)) [[unlikely]] {return nullptr;} - auto const ptr {[&_align,&_sz] { - if (_align == alignof (::std::max_align_t)) {return ::std::malloc(_sz);} - return ::std::aligned_alloc(_align,_sz); - }()}; - if (ptr == nullptr) [[unlikely]] {goto badalloc;} - dux_ass("",reinterpret_cast<::dux::uwrd>(ptr) % _align == dux_uwrdl(0x0)); /* Make sure the pointer is aligned. */ - return ptr; -badalloc:; - ::dux::seterr(::dux::errcd::badalloc); - return nullptr; -} diff --git a/dux/src/priv/assfail.c b/dux/src/priv/assfail.c deleted file mode 100644 index f0ba07d..0000000 --- a/dux/src/priv/assfail.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -void dux_priv_assfail(char const * const restrict _filenm,unsigned long const _ln,char const * const restrict _fn,char const * const restrict _msg,char const * const restrict _exprstr) { - /* We will call dux_priv_dbglog directly, as we must print, even if debug mode is enabled. */ - dux_priv_dbglog("\n"); - dux_priv_dbglog("Assertion \x1B[38;2;225;61;61mfailed\x1B[0m"); - if (dux_streq(_msg,"")) {dux_priv_dbglog("!");} - else {dux_priv_dbglog(": \x1B[3m%s\x1B[0m",_msg);} - dux_priv_dbglog("\n"); - dux_priv_dbglog(" Expression (\x1B[38;2;61;225;169m%s\x1B[0m) does not evaluate to true!\n",_exprstr); - dux_priv_dbglog(" ... at \x1B[38;2;225;169;61m\"%s\"\x1B[0m:\x1B[38;2;255;169;61m%li\x1B[0m\n",_filenm,_ln); - dux_priv_dbglog(" ... in \x1B[38;2;169;225;61m%s\x1B[0m\n",_fn); - dux_priv_dbglog("\n"); - dux_abrt(); -} diff --git a/dux/src/priv/cpy.c b/dux/src/priv/cpy.c deleted file mode 100644 index 490d101..0000000 --- a/dux/src/priv/cpy.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/seq> - -void dux_priv_cpy(void const * const restrict _in,dux_uwrd const _num,void * const restrict _out,dux_uwrd const _sz) { -# if dux_dbg - dux_unlikely (_in == dux_nullptr || _out == dux_nullptr) { - dux_seterr(dux_errcd_badaddr); - return; - } -# endif - dux_uwrd const numbyte = _num * _sz; -# if dux_hasbuiltin(__builtin_memcpy) /* We would like to use this builtin, if available, as it may be optimised in a way which would be UB if we did it. */ - dux_ppmsg("Using __builtin_memcpy for dux_cpy.") - __builtin_memcpy((void *)_out,(void *)_in,numbyte); -# else - unsigned char const * const restrict in = (unsigned char const *)_in; - unsigned char * const restrict out = (unsigned char *)_out; - for (dux_uwrd n = dux_uwrdl(0x0);n < numbyte;++n) { - *(unsigned char *)&out[n] = *(unsigned char const *)&in[n]; - } -# endif -} diff --git a/dux/src/priv/curerrcd.c b/dux/src/priv/curerrcd.c deleted file mode 100644 index b046e5c..0000000 --- a/dux/src/priv/curerrcd.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -_Thread_local enum dux_priv_errcd dux_priv_curerrcd; diff --git a/dux/src/priv/dbglog.c b/dux/src/priv/dbglog.c deleted file mode 100644 index 7d88d72..0000000 --- a/dux/src/priv/dbglog.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <stdarg.h> -# include <stdio.h> - -void dux_priv_dbglog(char const * const restrict _str,...) { - va_list args; - va_start(args,_str); - vfprintf(stderr,_str,args); - va_end(args); -} diff --git a/dux/src/priv/dbgunreach.c b/dux/src/priv/dbgunreach.c deleted file mode 100644 index f2f80a2..0000000 --- a/dux/src/priv/dbgunreach.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -void dux_priv_dbgunreach(char const * const restrict _file,long const _line) { - dux_dbglog("dux.Unreachable point reached"); - if (!dux_streq(_file,"") && _line != 0x0l) { - dux_dbglog(" at \"%s\":%li",_file,_line); - } - dux_dbglog("!\n"); - dux_trap(); -} diff --git a/dux/src/priv/dup.c b/dux/src/priv/dup.c deleted file mode 100644 index 25ec3f0..0000000 --- a/dux/src/priv/dup.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/mem> -# include <dux/seq> - -void * dux_priv_dup(void const * const restrict _in,dux_uwrd const _num,dux_uwrd const _sz) { -# if dux_dbg - dux_unlikely (_in == dux_nullptr) { - dux_seterr(dux_errcd_badaddr); - return dux_nullptr; - } -# endif - dux_unlikely (_num == dux_uwrdl(0x0)) {return dux_nullptr;} - dux_uwrd const numbyte = _num * _sz; - void * newarr = dux_alloc(numbyte); - dux_reseterr(); - dux_unlikely (dux_haserr()) {return dux_nullptr;} - dux_cpy(_in,_num,newarr,_sz); - return newarr; -} diff --git a/dux/src/priv/fill.c b/dux/src/priv/fill.c deleted file mode 100644 index 2495ca1..0000000 --- a/dux/src/priv/fill.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/seq> - -void dux_priv_fill(void * const restrict _ptr,dux_uwrd const _num,dux_uint8 const _val,dux_uwrd const _sz) { -# if dux_dbg - dux_unlikely (_ptr == dux_nullptr) { - dux_seterr(dux_errcd_badaddr); - return; - } - dux_unlikely (_sz == dux_uwrdl(0x0)) { - dux_seterr(dux_errcd_illsz); - return; - } -# endif - dux_unlikely (_num == dux_uwrdl(0x0)) {return;} - dux_uwrd const numbyte = _num * _sz; -# if dux_hasbuiltin(__builtin_memset) - dux_ppmsg("Using __builtin_memset for dux_fill.") - __builtin_memset(_ptr,_val,numbyte); -# else - dux_uint8 * const restrict ptr = (dux_uint8 *)_ptr; - for (dux_uwrd n = dux_uwrdl(0x0);n < numbyte;++n) { - ptr[n] = _val; - } -# endif -} diff --git a/dux/src/priv/free.cc b/dux/src/priv/free.cc deleted file mode 100644 index 93e04b5..0000000 --- a/dux/src/priv/free.cc +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/mem> - -# include <dux/sig> - -# include <cstdlib> - -extern "C" auto dux_priv_free(void * const restrict _ptr) -> void { - if constexpr (::dux::dbg) {if (_ptr == nullptr) [[unlikely]] {::dux::free(nullptr);}} - ::std::free(static_cast<::dux::uint8 *>(_ptr)); -} diff --git a/dux/src/priv/geterrnoptr.c b/dux/src/priv/geterrnoptr.c deleted file mode 100644 index a94bf48..0000000 --- a/dux/src/priv/geterrnoptr.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# if defined(dux_os_freebsd) -dux_attr_const int * __error(void); -# elif defined(dux_os_linux) -dux_attr_const int * __errno_location(void); -# endif - -int * dux_priv_geterrnoptr(void) { -# if defined(dux_os_freebsd) - return __error(); -# elif defined(dux_os_linux) - return __errno_location(); -# endif -} - diff --git a/dux/src/priv/logstderr.c b/dux/src/priv/logstderr.c deleted file mode 100644 index 2263dff..0000000 --- a/dux/src/priv/logstderr.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -# include <unistd.h> - -void dux_priv_logstderr(char const * const restrict _str) {dux_priv_posix_write(STDERR_FILENO,_str,dux_strlen(_str));} diff --git a/dux/src/priv/nomedia.c b/dux/src/priv/nomedia.c deleted file mode 100644 index 26e19bf..0000000 --- a/dux/src/priv/nomedia.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -bool const dux_priv_nomedia = -# if defined(dux_priv_dis_media) - true; -# else - false; -# endif diff --git a/dux/src/priv/plot.c b/dux/src/priv/plot.c deleted file mode 100644 index 36f38a9..0000000 --- a/dux/src/priv/plot.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/seq> - -void dux_priv_plot(void const * const restrict _ptr,dux_uwrd const _num,dux_uwrd const _sz,void (* const _fn)(void const * ptr)) { -# if dux_dbg - dux_unlikely (_ptr == dux_nullptr) { - dux_seterr(dux_errcd_badaddr); - return; - } - dux_unlikely (_sz == dux_uwrdl(0x0)) { - dux_seterr(dux_errcd_illsz); - return; - } -# endif - dux_unlikely (_num == dux_uwrdl(0x0)) {return;} - dux_uwrd const numbyte = _num * _sz; - for (dux_uwrd n = dux_uwrdl(0x0);n < numbyte;n += _sz) {_fn((dux_uint8 *)_ptr + n);} -} diff --git a/dux/src/priv/posix/clock_gettime.c b/dux/src/priv/posix/clock_gettime.c deleted file mode 100644 index 6210c5c..0000000 --- a/dux/src/priv/posix/clock_gettime.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <time.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -int dux_priv_posix_clock_gettime(clockid_t const clockid,struct timespec * const tp) { -# if defined(dux_os_freebsd) - return (int)dux_syscall(SYS_clock_gettime,clockid,tp); -# elif defined(dux_os_linux) - return (int)dux_syscall(__NR_clock_gettime,clockid,tp); -# endif -} diff --git a/dux/src/priv/posix/close.c b/dux/src/priv/posix/close.c deleted file mode 100644 index 68dd2d1..0000000 --- a/dux/src/priv/posix/close.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -int dux_priv_posix_close(int const fildes) { -# if defined(dux_os_freebsd) - return (int)dux_syscall(SYS_close,fildes); -# elif defined(dux_os_linux) - return (int)dux_syscall(__NR_close,fildes); -# endif -} diff --git a/dux/src/priv/posix/fsync.c b/dux/src/priv/posix/fsync.c deleted file mode 100644 index f5a2840..0000000 --- a/dux/src/priv/posix/fsync.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -int dux_priv_posix_fsync(int const fd) { -# if defined(dux_os_freebsd) - return (int)dux_syscall(SYS_fsync,fd); -# elif defined(dux_os_linux) - return (int)dux_syscall(__NR_fsync,fd); -# endif -} diff --git a/dux/src/priv/posix/getpid.c b/dux/src/priv/posix/getpid.c deleted file mode 100644 index c7fa17d..0000000 --- a/dux/src/priv/posix/getpid.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <sys/types.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -pid_t dux_priv_posix_getpid(void) { -# if defined(dux_os_freebsd) - return (pid_t)dux_syscall(SYS_getpid); -# elif defined(dux_os_linux) - return (pid_t)dux_syscall(__NR_getpid); -# endif -} diff --git a/dux/src/priv/posix/getrandom.c b/dux/src/priv/posix/getrandom.c deleted file mode 100644 index ccedaaf..0000000 --- a/dux/src/priv/posix/getrandom.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -dux_swrd dux_priv_posix_getrandom(void * const buf,dux_uwrd const buflen,unsigned int flags) { -# if defined(dux_os_freebsd) - return (dux_swrd)dux_syscall(SYS_getrandom,buf,buflen,flags); -# elif defined(dux_os_linux) - return (dux_swrd)dux_syscall(__NR_getrandom,buf,buflen,flags); -# endif -} diff --git a/dux/src/priv/posix/kill.c b/dux/src/priv/posix/kill.c deleted file mode 100644 index be1534b..0000000 --- a/dux/src/priv/posix/kill.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <sys/types.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -int dux_priv_posix_kill(pid_t const pid,int const sig) { -# if defined(dux_os_freebsd) - return (int)dux_syscall(SYS_kill,pid,sig); -# elif defined(dux_os_linux) - return (int)dux_syscall(__NR_kill,pid,sig); -# endif -} diff --git a/dux/src/priv/posix/mmap.c b/dux/src/priv/posix/mmap.c deleted file mode 100644 index 7361653..0000000 --- a/dux/src/priv/posix/mmap.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <sys/mman.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -void * dux_priv_posix_mmap(void * const addr,dux_uwrd const length,int const prot,int const flags,int const fd,off_t const offset) { - return mmap(addr,length,prot,flags,fd,offset); -} diff --git a/dux/src/priv/posix/nanosleep.c b/dux/src/priv/posix/nanosleep.c deleted file mode 100644 index 14cb940..0000000 --- a/dux/src/priv/posix/nanosleep.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <time.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -int dux_priv_posix_nanosleep(struct timespec const * const req,struct timespec * const rem) { -# if defined(dux_os_freebsd) - return (int)dux_syscall(SYS_nanosleep,req,rem); -# elif defined(dux_os_linux) - return (int)dux_syscall(__NR_nanosleep,req,rem); -# endif -} diff --git a/dux/src/priv/posix/openat.c b/dux/src/priv/posix/openat.c deleted file mode 100644 index 1069c1e..0000000 --- a/dux/src/priv/posix/openat.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <fcntl.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -int dux_priv_posix_openat(int const fd,char const * const pathname,int const flags,mode_t const mode) { -# if defined(dux_os_freebsd) - return (int)dux_syscall(SYS_open,fd,pathname,flags,mode); -# elif defined(dux_os_linux) - return (int)dux_syscall(__NR_openat,fd,pathname,flags,mode); -# endif -} diff --git a/dux/src/priv/posix/read.c b/dux/src/priv/posix/read.c deleted file mode 100644 index e0781ad..0000000 --- a/dux/src/priv/posix/read.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -dux_swrd dux_priv_posix_read(int const fd,void * const buf,dux_uwrd const count) { -# if defined(dux_os_freebsd) - return (dux_swrd)dux_syscall(SYS_read,fd,buf,count); -# elif defined(dux_os_linux) - return (dux_swrd)dux_syscall(__NR_read,fd,buf,count); -# endif -} diff --git a/dux/src/priv/posix/sigaction.c b/dux/src/priv/posix/sigaction.c deleted file mode 100644 index 8a0e259..0000000 --- a/dux/src/priv/posix/sigaction.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <signal.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -int dux_priv_posix_sigaction(int const signum,struct sigaction const * const act,struct sigaction * const oldact) { -# if defined(dux_os_freebsd) - return (int)dux_syscall(SYS_sigaction,signum,act,oldact); -# elif defined(dux_os_linux) - return (int)dux_syscall(__NR_rt_sigaction,signum,act,oldact,sizeof (sigset_t)); -# endif -} diff --git a/dux/src/priv/posix/write.c b/dux/src/priv/posix/write.c deleted file mode 100644 index de80921..0000000 --- a/dux/src/priv/posix/write.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -dux_swrd dux_priv_posix_write(int const fildes,void const * const buf,dux_uwrd const nbyte) { -# if defined(dux_os_freebsd) - return (dux_swrd)dux_syscall(SYS_write,fildes,buf,nbyte); -# elif defined(dux_os_linux) - return (dux_swrd)dux_syscall(__NR_write,fildes,buf,nbyte); -# endif -} diff --git a/dux/src/priv/start.cc b/dux/src/priv/start.cc deleted file mode 100644 index f72aba0..0000000 --- a/dux/src/priv/start.cc +++ /dev/null @@ -1,65 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/mem> -# include <dux/sig> - -# include <csetjmp> - -auto main(int const argc,char const * const * const argv) -> int {return ::dux_priv_start(argc,argv);} - -extern "C" auto dux_main(::dux::mainparams const *) -> ::dux::stat; - -extern "C" auto dux_priv_start(int const argc,char const * const * const argv) -> int { - ::dux::dbglog("dux.priv.start :: Bootstrapping!\n"); - ::dux::mainparams mainparams; - mainparams.fromstd(argc,argv); - ::dux::stat volatile stat; - if (setjmp(::dux::priv::exitjmp) == 0x0) { - try {stat = ::dux_main(&mainparams);} - catch (...) { - ::dux::dbglog("dux.\x1B[91mpriv.start\x1B[0m :: Exception was not caught!\n"); - ::dux::abrt(); - } - ::dux::priv::exitlock.store(true); /* Disable all future exits. */ - ::dux::dbglog("dux.priv.start :: Program returned!\n"); - } - else {stat = ::dux::priv::exitstat;} - while (::dux::priv::onexitlock.load()) {} /* Wait for the remaining onexit function to be registered, if any. */ - if (::dux::priv::numonexitfns > dux_uwrdl(0x0)) { - using ::dux::priv::onexitfns; - for (::dux::uwrd n {::dux::priv::numonexitfns};n > 0x0;--n) { - auto const fn {onexitfns[n - dux_uwrdl(0x1)]}; - ::dux::dbglog("dux.exit :: Calling registered function #%zu at %p!\n",n - dux_uwrdl(0x1),reinterpret_cast<void *>(fn)); - if (fn == nullptr) [[unlikely]] { - ::dux::dbglog("dux.exit :: Registered function is invalid (address is null)!\n"); - ::dux::raise(::dux::sig::segv); - } - try {fn(stat);} /* Registered functions may not throw exceptions. */ - catch (...) { - ::dux_priv_logstderr("dux.exit :: Registered function threw an exception!\n"); - ::dux::abrt(); - } - } - } - ::dux::dbglog("dux.exit :: Exiting with system code (%i)!\n",static_cast<int>(stat)); - return static_cast<int>(stat); -} diff --git a/dux/src/priv/syscall.S b/dux/src/priv/syscall.S deleted file mode 100644 index 2ec5e36..0000000 --- a/dux/src/priv/syscall.S +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/sysinfo.h> - -.globl dux_priv_syscall - -dux_priv_syscall: -# if defined(dux_arch_arm) -# if dux_wrdsz == 0x40 - mov w8,w0 - mov x0,x1 - mov x1,x2 - mov x2,x3 - mov x3,x4 - mov x4,x5 - mov x5,x6 - svc #0 - ret -# endif -# elif defined(dux_arch_x86) -# if dux_wrdsz == 0x40 - .intel_syntax noprefix - mov rax,rdi /* Move first parameter (the syscall id) to rax. */ - mov rdi,rsi /* Shift all parameters. */ - mov rsi,rdx - mov rdx,rcx - mov r10,r8 /* Syscalls use r10 instead of rcx. */ - mov r8,r9 - mov r9,[rsp - 0x8] /* Extract the sixth argument from the stack. */ - syscall /* Slime incident */ - ret -# endif -# endif diff --git a/dux/src/raise.cc b/dux/src/raise.cc deleted file mode 100644 index 43057f3..0000000 --- a/dux/src/raise.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/sig> - -# include <sys/types.h> - -auto ::dux::raise(::dux::sig const _sig) noexcept -> void { - auto const syssig = static_cast<int>(_sig); - ::dux::dbglog("dux.raise :: Raise #%i\n",syssig); -# if defined(dux_priv_nosigtrap) - switch (_sig) { - [[likely]] default: - break; - case ::dux::sig::term: - ::dux_priv_dbglog("dux.raise :: Terminated!\n"); - ::dux::exit(::dux::stat::err); - case ::dux::sig::trap: - ::dux::trap(); - } -# endif - ::dux_priv_posix_kill(::dux_priv_posix_getpid(),syssig); -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_raise(dux_priv_sig const _sig) -> void {return ::dux::raise(static_cast<::dux::sig>(_sig));} diff --git a/dux/src/realloc.cc b/dux/src/realloc.cc deleted file mode 100644 index 68fe284..0000000 --- a/dux/src/realloc.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/sig> -# include <dux/mem> - -# include <cstddef> -# include <cstdlib> - -auto ::dux::priv::realloc(void * const restrict _ptr,::dux::uwrd const _newsz) noexcept -> void * { - if (reinterpret_cast<::dux::uwrd>(_ptr) % alignof (::std::max_align_t) != dux_uwrdl(0x0)) [[unlikely]] { - ::dux::dbglog("dux.realloc :: Address %p is not default-aligned and cannot be reallocated in the current version of dux!\n",_ptr); - ::dux::raise(::dux::sig::segv); - } - auto const newptr {::std::realloc(const_cast<void *>(_ptr),_newsz)}; - if (::dux::haserr()) [[unlikely]] {return nullptr;} - return newptr; -} diff --git a/dux/src/rnd.cc b/dux/src/rnd.cc deleted file mode 100644 index 4fdd940..0000000 --- a/dux/src/rnd.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/math> - -# include <sys/random.h> -# if defined(dux_os_freebsd) -# include <errno.h> -# elif defined(dux_os_linux) -# include <linux/errno.h> -# endif - -auto ::dux::priv::rnd(::dux::uint8 * const restrict _buf,::dux::uwrd const _sz) noexcept -> void { -getrnd:; - auto const getrndret = ::dux_priv_posix_getrandom(_buf,_sz,GRND_NONBLOCK); - if (getrndret == dux_swrdl(-0x1)) [[unlikely]] { - if (dux_priv_errno == EAGAIN) [[likely]] {goto getrnd;} /* We specify this as likely to speed this loop up. */ - return; - } - dux_ass("",static_cast<::dux::uwrd>(getrndret) == _sz); -} diff --git a/dux/src/setsighandl.cc b/dux/src/setsighandl.cc deleted file mode 100644 index a4131f6..0000000 --- a/dux/src/setsighandl.cc +++ /dev/null @@ -1,109 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/sig> - -# include <signal.h> -# if defined(dux_os_freebsd) -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# endif - -namespace dux::local { - static ::dux::sighandl sighandls[static_cast<::dux::uwrd>(::dux::numsig)] {}; -} - -auto ::dux::setsighandl(::dux::sig const _sig,::dux::sighandl const _handl) noexcept -> void { - switch (_sig) { /* We don't allow signal handler to be registered for every signal. */ - [[likely]] default: - break; - case ::dux::sig::abrt: - [[fallthrough]]; - case ::dux::sig::kill: - [[fallthrough]]; - case ::dux::sig::trap: - if (!_handl._isdfl) [[unlikely]] { - ::dux::dbglog("dux.\x1B[91msetsighandl\x1B[0m :: Attempted setting custom signal handler for SIGABRT, SIGKILL or SIGTRAP (not allowed)!\n"); - ::dux::seterr(::dux::errcd::badperms); - return; - } - } - if constexpr (::dux::dbg) { - if (!_handl._isdfl) { - if (_handl.handl == nullptr) [[unlikely]] { - ::dux::dbglog("dux.\x1B[91msetsighandl\x1B[0m :: Handler invalid (address is null)!\n"); - ::dux::seterr(::dux::errcd::illparam); - return; - } - } - } - ::dux::local::sighandls[static_cast<::dux::uwrd>(_sig)] = _handl; - auto const sig {static_cast<int>(_sig)}; - { - auto handlwrap {[](int const _sig) { - auto const & handl {::dux::local::sighandls[static_cast<::dux::uwrd>(_sig)]}; - auto const handlret {handl.handl(static_cast<::dux::sig>(_sig))}; - auto const handlptr {reinterpret_cast<void *>(handl.handl)}; - if (handlret) [[unlikely]] { - ::dux::dbglog("dux.\x1B[91mraise\x1B[0m :: Signal handler for #%i (at %p) indicated error!\n",_sig,handlptr); - ::dux::abrt(); - } - switch (_sig) { - [[likely]] default: - break; - case SIGFPE: - [[fallthrough]]; - case SIGILL: - [[fallthrough]]; - case SIGSEGV: - ::dux::dbglog("dux.\x1B[91mraise\x1B[0m :: Signal handler for SIGFPE, SIGILL or SIGSEGV (at %p) returned and did not indicate error (not allowed)!\n",handlptr); - ::dux::abrt(); - } - }}; - struct ::sigaction sigact {}; - if (_handl == ::dux::sighandl::dfl()) { - ::dux::dbglog("dux.setsighandl :: Set (default) -> #%i\n",sig); - sigact.sa_handler = SIG_DFL; - } - else { - ::dux::dbglog("dux.setsighandl :: Set %p -> #%i\n",_handl.handl,sig); - sigact.sa_handler = handlwrap; - } - ::sigemptyset(&sigact.sa_mask); - sigact.sa_flags = SA_RESTART; - struct ::sigaction oldsigact; - if (::sigaction(sig,&sigact,&oldsigact) == -0x1) [[unlikely]] { /* priv.posix.sigaction does not work for some reason on Linux, so we just use the POSIX function directly. */ - ::dux::seterr(::dux::errcd::runerr); - return; - } - } -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_setsighandl(::dux_priv_sig const _sig,::dux_priv_ctyp_sighandl const _handl) -> void { - auto const cxxhandl {[&] { - if (_handl == dux_priv_dflcsighandl) {return ::dux::sighandl::dfl();} - return ::dux::sighandl {reinterpret_cast<auto (*)(::dux::sig) -> bool>(reinterpret_cast<void *>(_handl))}; - }()}; - ::dux::setsighandl(static_cast<::dux::sig>(_sig),cxxhandl); -} diff --git a/dux/src/sleep.cc b/dux/src/sleep.cc deleted file mode 100644 index 512ecb4..0000000 --- a/dux/src/sleep.cc +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/time> - -# include <time.h> -# if defined(dux_os_freebsd) -# include <errno.h> -# include <sys/syscall.h> -# elif defined(dux_os_linux) -# include <linux/unistd.h> -# include <linux/errno.h> -# endif - -auto ::dux::sleep(::dux::uint64 const _sec) noexcept -> void { - struct timespec timespec {}; - timespec.tv_sec = static_cast<::time_t>(_sec); - timespec.tv_nsec = 0x0l; - ::dux::dbglog("dux.sleep :: Sleep " dux_printfuint64 "s\n",_sec); - while (timespec.tv_sec > static_cast<::time_t>(0x0)) { /* In case the sleep was interrupted, we must sleep the remaining time away. */ - if (::dux_priv_posix_nanosleep(×pec,×pec) == -0x1) [[unlikely]] { - if (dux_priv_errno == EINTR) { - ::dux::dbglog("dux.sleep :: Sleep was interrupted! Slept for " dux_printfuint64 " %s.\n",static_cast<::dux::uint64>(timespec.tv_sec),timespec.tv_sec == ::time_t {0x1} ? "second" : "seconds"); - continue; - } - ::dux::dbglog("dux.\x1B[91msleep\x1B[0m :: Sleep failed!\n"); - ::dux::seterr(::dux::errcd::runerr); - return; - } - break; /* If the sleep was not interrupted, the remaining time will not be written to timespec. As we already checked for errors, we know the sleep was successful. */ - } -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_sleep(::dux::uint64 const _sec) -> void {::dux::sleep(_sec);} diff --git a/dux/src/strcmp.cc b/dux/src/strcmp.cc deleted file mode 100644 index 23647ff..0000000 --- a/dux/src/strcmp.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_strcmp(char const * const restrict _lstr,char const * const restrict _rstr) -> ::dux::sint8 {return ::dux::strcmp(_lstr,_rstr);} diff --git a/dux/src/strcpy.cc b/dux/src/strcpy.cc deleted file mode 100644 index ddb9271..0000000 --- a/dux/src/strcpy.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_strcpy(char const * const restrict _src,char * const restrict _dest) -> void {::dux::strcpy(_src,_dest);} diff --git a/dux/src/strdup.cc b/dux/src/strdup.cc deleted file mode 100644 index 60fcffd..0000000 --- a/dux/src/strdup.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_strdup(char const * const restrict _str) -> ::dux::str {return ::dux::strdup(_str);} diff --git a/dux/src/streq.cc b/dux/src/streq.cc deleted file mode 100644 index e9c6d20..0000000 --- a/dux/src/streq.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_streq(char const * const restrict _lstr,char const * const restrict _rstr) -> bool {return ::dux::streq(_lstr,_rstr);} diff --git a/dux/src/strlen.cc b/dux/src/strlen.cc deleted file mode 100644 index ab22f2e..0000000 --- a/dux/src/strlen.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/str> - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_strlen(char const * const restrict _str) -> ::dux::uwrd {return ::dux::strlen(_str);} diff --git a/dux/src/trap.cc b/dux/src/trap.cc deleted file mode 100644 index af20cf4..0000000 --- a/dux/src/trap.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright 2021, 2022 Gabriel Jensen. - - This file is part of dux. - - dux is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - dux is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with dux. If not, see <https://www.gnu.org/licenses/>. -*/ - -# include <dux/priv> - -# include <dux/sig> - -auto ::dux::trap() noexcept -> void { - for (;;) { -# if !defined(dux_priv_nosigtrap) - ::dux::raise(::dux::sig::trap); /* POSIX systems have a signal for trapping. Use it. */ -# elif defined(dux_arch_x86) - asm volatile ( /* x86 has an interrupt instruction. Use it. */ - "int3\n" - ); -# elif dux_hasbuiltin(__builtin_trap) - ::__builtin_trap(); -# endif - } -} - -# pragma GCC diagnostic ignored "-Wmissing-declarations" - -extern "C" auto dux_trap() -> void {::dux::trap();} |