libk  Check-in [c7732c41c9]

Overview
Comment:add detection loop for syscall headers
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c7732c41c9907f2720d42378590bb4f91deb9810398216697e8f989537e3108f
User & Date: lexi on 2019-08-19 23:57:49
Other Links: manifest | tags
Context
2019-08-20
02:03
partially unfuck x86-32, correct major error in syscall ABI check-in: f9bf0d662b user: lexi tags: trunk
2019-08-19
23:57
add detection loop for syscall headers check-in: c7732c41c9 user: lexi tags: trunk
22:40
add documentation compilation check-in: 8d6d792515 user: lexi tags: trunk
Changes

Modified arch/posix.h from [b77089e7ab] to [676bf37092].

     6      6    *    OS specified! */
     7      7   
     8      8   #ifndef KIplatform_posix
     9      9   #define KIplatform_posix
    10     10   #include <k/def.h>
    11     11   #include <k/type.h>
    12     12   
           13  +#if (!defined(KFplatform_define_constants)) && \
           14  +    (!defined(KFplatform_define_types)) && \
           15  +    (!defined(KFplatform_define_funcs))
           16  +#define KFplatform_define_constants
           17  +#define KFplatform_define_types
           18  +#define KFplatform_define_funcs
           19  +#endif
           20  +
           21  +#ifdef KFplatform_define_constants
           22  +
    13     23   enum posix_prot {
    14     24   	posix_prot_none  = 0,
    15     25   	posix_prot_read  = 1 << 0,
    16     26   	posix_prot_write = 1 << 1,
    17     27   	posix_prot_exec  = 1 << 2
    18     28   };
    19     29   
................................................................................
    30     40   	posix_flag_anonymous = 0x1000,
    31     41   #endif
    32     42   
    33     43   	/* platform flags */
    34     44   	posix_flag_linux_hugetlb = 0x40000
    35     45   };
    36     46   
           47  +#endif
           48  +#ifdef KFplatform_define_types
           49  +
    37     50   /* platform types */
    38     51   
    39     52   typedef s64 k_platform_syscall_return;
    40     53   typedef u64 k_platform_syscall_error;
    41     54   
    42     55   #if KVos == KA_os_lin
    43     56   	typedef long k_platform_syscall_arg;
................................................................................
    52     65   #endif
    53     66   
    54     67   struct k_platform_syscall_answer {
    55     68   	k_platform_syscall_return ret;
    56     69   	k_platform_syscall_error error;
    57     70   };
    58     71   
    59         -#include <system_calls.h>
           72  +#endif
           73  +
           74  +#if defined(KFplatform_define_constants) ||\
           75  +    defined(KFplatform_define_funcs)
           76  +#		include <system_calls.h>
           77  +#endif
           78  +
           79  +#ifdef KFplatform_define_funcs
    60     80   
    61     81   extern struct k_platform_syscall_answer
    62     82   k_platform_syscall(enum k_platform_syscall call, u8 valency, 
    63     83   		k_platform_syscall_arg args[]);
           84  +
           85  +#endif
    64     86   
    65     87   #endif

Modified build.sh from [669569b504] to [a37c2dbfb1].

    20     20   	./clean.sh
    21     21   fi
    22     22   
    23     23   # TODO: make it possible for user to change
    24     24   #       default set with environment vars
    25     25   modules=(kcore kmem kstr kio kgraft kfile)
    26     26   
           27  +# compose an arch tuple. this is used in
           28  +# places, mostly to select the correct
           29  +# version of assembly files for a given
           30  +# platform (each has an arch tuple in its
           31  +# name, following the linkage specifier)
    27     32   target=$arch.$os
    28     33   if test "$bits" != ""; then
    29     34   	target=$target.$bits
    30     35   fi
    31     36   
           37  +# determine whether we have unix or posix
           38  +# APIs depending on the operating system.
           39  +# presumably if the user is running a bash
           40  +# script there is some degree of posix
           41  +# support available, but we might still be
           42  +# building for windows from within cygwin
           43  +# or whatever
    32     44   case $os in
    33     45   	lin|?bsd|and|dar|osx) posix=yes; unix=yes;;
    34     46   	hai) posix=yes; unix=no;;
    35     47   	*) posix=no; unix=no;;
    36     48   esac
    37     49   
    38     50   case $os.$bits in
................................................................................
    78     90   
    79     91   check cc "your C compiler of choice"
    80     92   check asm "an assembler that takes Intel syntax and nasm-style-macros"
    81     93   check m4 "the path to your m4 installation"
    82     94   
    83     95   export build=$(global/build-id.sh)
    84     96   
    85         -case $os in
    86         -	lin) p_headers_syscall=${p_headers_syscall:-/usr/include/asm/unistd_${bits}.h}
    87         -	p_headers_errno=${p_headers_errno:-/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h};;
           97  +if test "$p_headers_syscall" = ""; then
           98  +	case $os in
           99  +		lin) headers_syscall_search=(
          100  +				/usr/include/asm/unistd_${bits}.h
          101  +				/usr/include/asm-generic/unistd.h
          102  +				/usr/include/*-linux-gnu/asm/unistd_${bits}.h
          103  +			);;
    88    104   
    89         -	fbsd) p_headers_syscall=${p_headers_syscall:-/usr/include/sys/syscall.h}
    90         -	p_headers_errno=${p_headers_errno:-/usr/include/errno.h};;
    91         -esac
          105  +		fbsd) p_headers_syscall_search=(
          106  +				/usr/include/sys/syscall.h
          107  +			);;
          108  +	esac
          109  +fi
          110  +
          111  +if test "$p_headers_errno" = ""; then
          112  +	case $os in
          113  +		lin) p_headers_errno="${p_headers_errno:-/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h}";;
          114  +
          115  +		fbsd) p_headers_errno="${p_headers_errno:-/usr/include/errno.h}";;
          116  +	esac
          117  +fi
          118  +
          119  +for f in "${headers_syscall_search[@]}"; do
          120  +	test -e "$f" || continue
          121  +	p_headers_syscall="$f"
          122  +	say "using syscall headers at $f"
          123  +	break;
          124  +done
    92    125   
    93    126   check p_headers_syscall \
    94    127   	'the location of a header defining your syscall numbers'
    95    128   check p_headers_errno \
    96    129   	'the location of a header defining the values of each errno symbol'
    97    130   
    98    131   macro_compile_env="-Datom_target_arch=$arch -Datom_target_os=$os -Dtarget_posix=$posix -Dtarget_unix=$unix"

Modified kcore/stop.fn.c from [5c15d4cc49] to [092afab243].

     2      2    * ~ lexi hale <lexi@hale.su>
     3      3    * this file defines a function that prematurely exits from
     4      4    * a running libk program with an appropriate exit status. */
     5      5   
     6      6   #include <k/core.h>
     7      7   #include <k/def.h> // so we know what system this is
     8      8   #include <k/type.h>
     9         -
    10      9   #ifdef KFenv_posix
    11         -#	define STOPFN kio_posix_exit
    12         -	extern noreturn void STOPFN(int);
    13         -#else
    14         -	Knoimpl(kstop)
           10  +#	define KFplatform_define_types
           11  +#	define KFplatform_define_constants
           12  +#	include <posix.h>
    15     13   #endif
    16     14   
    17         -noreturn void kstop (stat_long code) { STOPFN(code); }
           15  +noreturn extern struct k_platform_syscall_answer
           16  +k_platform_syscall(enum k_platform_syscall call, u8 valency, 
           17  +		k_platform_syscall_arg args[]);
           18  +
           19  +noreturn void kstop(stat_long code) {
           20  +#	ifdef KFenv_posix
           21  +		k_platform_syscall_arg exit_code[] = { code };
           22  +		k_platform_syscall(k_platform_syscall_exit, 1, exit_code);
           23  +#	else
           24  +		Knoimpl(kstop)
           25  +#	endif
           26  +}
           27  +