Index: arch/posix.h ================================================================== --- arch/posix.h +++ arch/posix.h @@ -8,10 +8,20 @@ #ifndef KIplatform_posix #define KIplatform_posix #include #include +#if (!defined(KFplatform_define_constants)) && \ + (!defined(KFplatform_define_types)) && \ + (!defined(KFplatform_define_funcs)) +#define KFplatform_define_constants +#define KFplatform_define_types +#define KFplatform_define_funcs +#endif + +#ifdef KFplatform_define_constants + enum posix_prot { posix_prot_none = 0, posix_prot_read = 1 << 0, posix_prot_write = 1 << 1, posix_prot_exec = 1 << 2 @@ -32,10 +42,13 @@ /* platform flags */ posix_flag_linux_hugetlb = 0x40000 }; +#endif +#ifdef KFplatform_define_types + /* platform types */ typedef s64 k_platform_syscall_return; typedef u64 k_platform_syscall_error; @@ -54,12 +67,21 @@ struct k_platform_syscall_answer { k_platform_syscall_return ret; k_platform_syscall_error error; }; -#include +#endif + +#if defined(KFplatform_define_constants) ||\ + defined(KFplatform_define_funcs) +# include +#endif + +#ifdef KFplatform_define_funcs extern struct k_platform_syscall_answer k_platform_syscall(enum k_platform_syscall call, u8 valency, k_platform_syscall_arg args[]); + +#endif #endif Index: build.sh ================================================================== --- build.sh +++ build.sh @@ -22,15 +22,27 @@ # TODO: make it possible for user to change # default set with environment vars modules=(kcore kmem kstr kio kgraft kfile) +# compose an arch tuple. this is used in +# places, mostly to select the correct +# version of assembly files for a given +# platform (each has an arch tuple in its +# name, following the linkage specifier) target=$arch.$os if test "$bits" != ""; then target=$target.$bits fi +# determine whether we have unix or posix +# APIs depending on the operating system. +# presumably if the user is running a bash +# script there is some degree of posix +# support available, but we might still be +# building for windows from within cygwin +# or whatever case $os in lin|?bsd|and|dar|osx) posix=yes; unix=yes;; hai) posix=yes; unix=no;; *) posix=no; unix=no;; esac @@ -80,17 +92,38 @@ check asm "an assembler that takes Intel syntax and nasm-style-macros" check m4 "the path to your m4 installation" export build=$(global/build-id.sh) -case $os in - lin) p_headers_syscall=${p_headers_syscall:-/usr/include/asm/unistd_${bits}.h} - p_headers_errno=${p_headers_errno:-/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h};; +if test "$p_headers_syscall" = ""; then + case $os in + lin) headers_syscall_search=( + /usr/include/asm/unistd_${bits}.h + /usr/include/asm-generic/unistd.h + /usr/include/*-linux-gnu/asm/unistd_${bits}.h + );; - fbsd) p_headers_syscall=${p_headers_syscall:-/usr/include/sys/syscall.h} - p_headers_errno=${p_headers_errno:-/usr/include/errno.h};; -esac + fbsd) p_headers_syscall_search=( + /usr/include/sys/syscall.h + );; + esac +fi + +if test "$p_headers_errno" = ""; then + case $os in + lin) p_headers_errno="${p_headers_errno:-/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h}";; + + fbsd) p_headers_errno="${p_headers_errno:-/usr/include/errno.h}";; + esac +fi + +for f in "${headers_syscall_search[@]}"; do + test -e "$f" || continue + p_headers_syscall="$f" + say "using syscall headers at $f" + break; +done check p_headers_syscall \ 'the location of a header defining your syscall numbers' check p_headers_errno \ 'the location of a header defining the values of each errno symbol' Index: kcore/stop.fn.c ================================================================== --- kcore/stop.fn.c +++ kcore/stop.fn.c @@ -4,14 +4,24 @@ * a running libk program with an appropriate exit status. */ #include #include // so we know what system this is #include - #ifdef KFenv_posix -# define STOPFN kio_posix_exit - extern noreturn void STOPFN(int); -#else - Knoimpl(kstop) +# define KFplatform_define_types +# define KFplatform_define_constants +# include #endif -noreturn void kstop (stat_long code) { STOPFN(code); } +noreturn extern struct k_platform_syscall_answer +k_platform_syscall(enum k_platform_syscall call, u8 valency, + k_platform_syscall_arg args[]); + +noreturn void kstop(stat_long code) { +# ifdef KFenv_posix + k_platform_syscall_arg exit_code[] = { code }; + k_platform_syscall(k_platform_syscall_exit, 1, exit_code); +# else + Knoimpl(kstop) +# endif +} +