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
7
8
9
10
11
12










13
14
15
16
17
18
19
..
30
31
32
33
34
35
36



37
38
39
40
41
42
43
..
52
53
54
55
56
57
58




59



60
61
62
63
64
65


 *    OS specified! */

#ifndef KIplatform_posix
#define KIplatform_posix
#include <k/def.h>
#include <k/type.h>











enum posix_prot {
	posix_prot_none  = 0,
	posix_prot_read  = 1 << 0,
	posix_prot_write = 1 << 1,
	posix_prot_exec  = 1 << 2
};

................................................................................
	posix_flag_anonymous = 0x1000,
#endif

	/* platform flags */
	posix_flag_linux_hugetlb = 0x40000
};




/* platform types */

typedef s64 k_platform_syscall_return;
typedef u64 k_platform_syscall_error;

#if KVos == KA_os_lin
	typedef long k_platform_syscall_arg;
................................................................................
#endif

struct k_platform_syscall_answer {
	k_platform_syscall_return ret;
	k_platform_syscall_error error;
};





#include <system_calls.h>




extern struct k_platform_syscall_answer
k_platform_syscall(enum k_platform_syscall call, u8 valency, 
		k_platform_syscall_arg args[]);

#endif









>
>
>
>
>
>
>
>
>
>







 







>
>
>







 







>
>
>
>
|
>
>
>






>
>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 *    OS specified! */

#ifndef KIplatform_posix
#define KIplatform_posix
#include <k/def.h>
#include <k/type.h>

#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
};

................................................................................
	posix_flag_anonymous = 0x1000,
#endif

	/* 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;

#if KVos == KA_os_lin
	typedef long k_platform_syscall_arg;
................................................................................
#endif

struct k_platform_syscall_answer {
	k_platform_syscall_return ret;
	k_platform_syscall_error error;
};

#endif

#if defined(KFplatform_define_constants) ||\
    defined(KFplatform_define_funcs)
#		include <system_calls.h>
#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

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

20
21
22
23
24
25
26





27
28
29
30
31







32
33
34
35
36
37
38
..
78
79
80
81
82
83
84

85

86












87
88
89
90
91








92
93
94
95
96
97
98
	./clean.sh
fi

# TODO: make it possible for user to change
#       default set with environment vars
modules=(kcore kmem kstr kio kgraft kfile)






target=$arch.$os
if test "$bits" != ""; then
	target=$target.$bits
fi








case $os in
	lin|?bsd|and|dar|osx) posix=yes; unix=yes;;
	hai) posix=yes; unix=no;;
	*) posix=no; unix=no;;
esac

case $os.$bits in
................................................................................

check cc "your C compiler of choice"
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};;

	fbsd) p_headers_syscall=${p_headers_syscall:-/usr/include/sys/syscall.h}
	p_headers_errno=${p_headers_errno:-/usr/include/errno.h};;
esac









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'

macro_compile_env="-Datom_target_arch=$arch -Datom_target_os=$os -Dtarget_posix=$posix -Dtarget_unix=$unix"







>
>
>
>
>





>
>
>
>
>
>
>







 







>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|

<
|
|
>
>
>
>
>
>
>
>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
	./clean.sh
fi

# 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

case $os.$bits in
................................................................................

check cc "your C compiler of choice"
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)

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_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'

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
3
4
5
6
7
8





9





10
11
12


13
14
15
16
17

 * ~ lexi hale <lexi@hale.su>
 * this file defines a function that prematurely exits from
 * a running libk program with an appropriate exit status. */

#include <k/core.h>
#include <k/def.h> // so we know what system this is
#include <k/type.h>











#ifdef KFenv_posix
#	define STOPFN kio_posix_exit
	extern noreturn void STOPFN(int);


#else
	Knoimpl(kstop)
#endif

noreturn void kstop (stat_long code) { STOPFN(code); }








>
>
>
>
>

>
>
>
>
>
|
<
<
>
>
|
|
|
|
<
>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20


21
22
23
24
25
26

27
 * ~ lexi hale <lexi@hale.su>
 * this file defines a function that prematurely exits from
 * a running libk program with an appropriate exit status. */

#include <k/core.h>
#include <k/def.h> // so we know what system this is
#include <k/type.h>
#ifdef KFenv_posix
#	define KFplatform_define_types
#	define KFplatform_define_constants
#	include <posix.h>
#endif

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
}