libk  Check-in [f85e6a07dd]

Overview
Comment:reorganize posix assembly code
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f85e6a07dd2dc8d917fc927dde153fdbc8a93c0085390a5f81d67b5c9bb610aa
User & Date: lexi on 2019-08-20 22:54:49
Other Links: manifest | tags
Context
2019-08-21
00:16
switch ansi "bold off" code to "reset" for terminals that interpret "bold off" as "double underline"; remove (incorrect) test code from kiosend check-in: cef83f0167 user: lexi tags: trunk
2019-08-20
22:54
reorganize posix assembly code check-in: f85e6a07dd user: lexi tags: trunk
04:04
improve syscall collection mechanism check-in: 9dd8bab2ac user: lexi tags: trunk
Changes

Deleted arch/posix.h version [676bf37092].

1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* arch/posix.h - posix constants
 *  ? this file defines posix magic numbers
 *    needed in syscalls, both cross-platform
 *    ones and os-dependent ones. note that
 *    the values may change depending on the
 *    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
};

enum posix_map {
	posix_map_shared  = 1,
	posix_map_private = 2
};

enum posix_flag {
	posix_flag_fixed     = 0x10,
#if KVos == KA_os_lin
	posix_flag_anonymous = 0x20,
#elif KVos == KA_os_fbsd
	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;
#elif KVos == KA_os_fbsd
	typedef u64  k_platform_syscall_arg;
#else
	/* we're going to just pick a sane
	 * fallback that's reasonably likely
	 * to work with most systems one way
	 * or another */
	typedef unsigned long 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
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<














































































































































































Added arch/posix/posix.h version [676bf37092].















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* arch/posix.h - posix constants
 *  ? this file defines posix magic numbers
 *    needed in syscalls, both cross-platform
 *    ones and os-dependent ones. note that
 *    the values may change depending on the
 *    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
};

enum posix_map {
	posix_map_shared  = 1,
	posix_map_private = 2
};

enum posix_flag {
	posix_flag_fixed     = 0x10,
#if KVos == KA_os_lin
	posix_flag_anonymous = 0x20,
#elif KVos == KA_os_fbsd
	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;
#elif KVos == KA_os_fbsd
	typedef u64  k_platform_syscall_arg;
#else
	/* we're going to just pick a sane
	 * fallback that's reasonably likely
	 * to work with most systems one way
	 * or another */
	typedef unsigned long 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

Added arch/posix/syscalls version [24a70b57fd].











>
>
>
>
>
1
2
3
4
5
exit
read
write
mmap
munmap

Added arch/posix/x86.fbsd.32.s version [fb0cced6da].















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
;; abi definition file for x86 linux 64-bit
; vim: ft=nasm

; syscall numbers - syscall table must be created first!
%include "system_calls.s"

; extremely stupid freebsd-ism: expects the syscall to
; come from a function
_syscall: int 0x80
          ret

%define sys.call call _syscall

; parameters are passed on the stack
%macro syscall 1-*
	mov eax, %1
	%rep %0-1
		%rotate 1
		push %1
	%endrep
	sys.call
	add esp, 4*(%0-1)
%endmacro

Added arch/posix/x86.fbsd.64.s version [8f1b903740].

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
;; abi definition file for x86 linux 64-bit
; vim: ft=nasm

; syscall numbers - syscall table must be created first!
%include "system_calls.s"

; freebsd uses the common x86-64 ABI
%include "x86.syscall.64.s"

Added arch/posix/x86.lin.32.s version [30df0fa7c9].























>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
; register order for syscall convention
%define sys.reg.n 6
%define sys.reg.ret eax
%define sys.reg.0 eax
%define sys.reg.1 ebx
%define sys.reg.2 ecx
%define sys.reg.3 edx
%define sys.reg.4 esi
%define sys.reg.5 edi

%define sys.call int 0x80

Added arch/posix/x86.lin.64.s version [58546ff139].



















>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
;; abi definition file for x86 linux 64-bit
; vim: ft=nasm

; syscall64 numbers - syscall table must be created first!
%include "system_calls.s"

; linux uses the common x86-64 ABI
%include "../x86.syscall.64.s"

Deleted arch/x86.fbsd.32.s version [fb0cced6da].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
;; abi definition file for x86 linux 64-bit
; vim: ft=nasm

; syscall numbers - syscall table must be created first!
%include "system_calls.s"

; extremely stupid freebsd-ism: expects the syscall to
; come from a function
_syscall: int 0x80
          ret

%define sys.call call _syscall

; parameters are passed on the stack
%macro syscall 1-*
	mov eax, %1
	%rep %0-1
		%rotate 1
		push %1
	%endrep
	sys.call
	add esp, 4*(%0-1)
%endmacro
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<














































Deleted arch/x86.fbsd.64.s version [8f1b903740].

1
2
3
4
5
6
7
8
;; abi definition file for x86 linux 64-bit
; vim: ft=nasm

; syscall numbers - syscall table must be created first!
%include "system_calls.s"

; freebsd uses the common x86-64 ABI
%include "x86.syscall.64.s"
<
<
<
<
<
<
<
<
















Deleted arch/x86.lin.32.s version [30df0fa7c9].

1
2
3
4
5
6
7
8
9
10
11
; register order for syscall convention
%define sys.reg.n 6
%define sys.reg.ret eax
%define sys.reg.0 eax
%define sys.reg.1 ebx
%define sys.reg.2 ecx
%define sys.reg.3 edx
%define sys.reg.4 esi
%define sys.reg.5 edi

%define sys.call int 0x80
<
<
<
<
<
<
<
<
<
<
<






















Deleted arch/x86.lin.64.s version [a477b8d971].

1
2
3
4
5
6
7
8
9
;; abi definition file for x86 linux 64-bit
; vim: ft=nasm

; syscall64 numbers - syscall table must be created first!
%include "system_calls.s"

; linux uses the common x86-64 ABI
%include "x86.syscall.64.s"

<
<
<
<
<
<
<
<
<


















Modified build.sh from [5f22a34160] to [520c125701].

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
mkdir -p $gen
$cc -D_emit_m4_include arch/typesize.c -o $gen/typesize 
$gen/typesize > gen/typesize.m

# generate syscall tables
if test $posix = yes; then
	# on posix, we simply abuse CPP to garner a list of syscalls;
	# the file arch/posix_syscalls contains a list of syscalls
	# we wish to import; we use sed to transform this into a form
	# that cpp will fill out for us, producing a table that the
	# awk scripts can handle and turn into a list of constants.
	echo '#include <sys/syscall.h>' > $gen/system_calls.t.1 # this is the magic part
	cat arch/posix_syscalls > $gen/system_calls.t.2
	sed -e 's;^\(.*\)$;\1 SYS_\1;' -i $gen/system_calls.t.2
	cat $gen/system_calls.t.1 $gen/system_calls.t.2 | cpp -P >$gen/system_calls.tbl
else
	case $os in
		# lin) grep -h "#define __NR_" $p_headers_syscall | sed 's;^#define __NR_;;' > $gen/system_calls.tbl;;
		# fbsd) grep -h "#define	SYS_" $p_headers_syscall | sed 's;^#define	SYS_;;' | sed 's;[\t ]\+; ;' > $gen/system_calls.tbl;;
		*) noimpl 'system call table generation';;







|




|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
mkdir -p $gen
$cc -D_emit_m4_include arch/typesize.c -o $gen/typesize 
$gen/typesize > gen/typesize.m

# generate syscall tables
if test $posix = yes; then
	# on posix, we simply abuse CPP to garner a list of syscalls;
	# the file arch/posix/syscalls contains a list of syscalls
	# we wish to import; we use sed to transform this into a form
	# that cpp will fill out for us, producing a table that the
	# awk scripts can handle and turn into a list of constants.
	echo '#include <sys/syscall.h>' > $gen/system_calls.t.1 # this is the magic part
	cat arch/posix/syscalls > $gen/system_calls.t.2
	sed -e 's;^\(.*\)$;\1 SYS_\1;' -i $gen/system_calls.t.2
	cat $gen/system_calls.t.1 $gen/system_calls.t.2 | cpp -P >$gen/system_calls.tbl
else
	case $os in
		# lin) grep -h "#define __NR_" $p_headers_syscall | sed 's;^#define __NR_;;' > $gen/system_calls.tbl;;
		# fbsd) grep -h "#define	SYS_" $p_headers_syscall | sed 's;^#define	SYS_;;' | sed 's;[\t ]\+; ;' > $gen/system_calls.tbl;;
		*) noimpl 'system call table generation';;

Modified kcore/boot.rt.x86.lin.64.s from [22c891476d] to [c4c48f7422].

1
2
3
4
5
6
7
8
9
10
; vim: ft=nasm
bits 64
%include "../arch/x86.lin.64.s"
global _start:function
extern _boot
extern entry

_start:
	mov rbp, rsp
	mov rdi, [rbp + 0] ; argc


|







1
2
3
4
5
6
7
8
9
10
; vim: ft=nasm
bits 64
%include "../arch/posix/x86.lin.64.s"
global _start:function
extern _boot
extern entry

_start:
	mov rbp, rsp
	mov rdi, [rbp + 0] ; argc

Modified kcore/platform.syscall.fn.c from [4315e80d93] to [9c61e189e0].

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 * implementation may vary drastically.
 */

#include <k/def.h>
#include <k/type.h>

#ifdef KFenv_posix
#	include <posix.h>
#else
	Knoimpl(k_platform_syscall)
#endif

extern void k_platform_syscall_raw (
		k_platform_syscall_return* return_slot,
		k_platform_syscall_error*  error_no_slot,







|







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 * implementation may vary drastically.
 */

#include <k/def.h>
#include <k/type.h>

#ifdef KFenv_posix
#	include <posix/posix.h>
#else
	Knoimpl(k_platform_syscall)
#endif

extern void k_platform_syscall_raw (
		k_platform_syscall_return* return_slot,
		k_platform_syscall_error*  error_no_slot,

Modified kcore/stop.fn.c from [092afab243] to [1f91f150ef].

5
6
7
8
9
10
11
12
13
14


15
16
17
18
19
20
21
22
23
24
25
26
27

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








|


>
>













5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#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/posix.h>
#endif

/* this manual redefinition is necessary to stop gcc
 * bitching that kstop returns, which it def does not */
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
}

Modified kcore/syscall.fn.x86.lin.64.s from [27d79c3e63] to [472ad3a7d3].

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
; altogether and access the error value of a
; syscall directly. invoke as:
;
; 	void k_platform_syscall_raw(s64* result, u64* errno,
;		syscall, u8 valency, s64[] args)

bits 64
%include "../arch/x86.lin.64.s"
%include "../arch/x86.cdecl.64.s"
; vim: ft=nasm

%macro handle_arg 1
	%assign v %1+1
	mov sys.reg. %+ v, [ccall.reg.4 + 8 * %1]
	dec ccall.reg.3







|







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
; altogether and access the error value of a
; syscall directly. invoke as:
;
; 	void k_platform_syscall_raw(s64* result, u64* errno,
;		syscall, u8 valency, s64[] args)

bits 64
%include "../arch/posix/x86.lin.64.s"
%include "../arch/x86.cdecl.64.s"
; vim: ft=nasm

%macro handle_arg 1
	%assign v %1+1
	mov sys.reg. %+ v, [ccall.reg.4 + 8 * %1]
	dec ccall.reg.3

Modified kio/send.fn.c from [f571b39492] to [3d6d32a7c0].

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * kiosend() writes to a channel with an open out stream
 */

/* we define all platform functions here,
 * whether or not they're for the correct
 * platform - only the ones actually called
 * by the generated code will be linked */
#include <posix.h>
#include <error_table.h>

kiocond kiosend(kiochan target, ksraw string, sz* len) {
	if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream;

#	ifdef KFenv_posix
		/* issue the write syscall here and now so we can







|







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * kiosend() writes to a channel with an open out stream
 */

/* we define all platform functions here,
 * whether or not they're for the correct
 * platform - only the ones actually called
 * by the generated code will be linked */
#include <posix/posix.h>
#include <error_table.h>

kiocond kiosend(kiochan target, ksraw string, sz* len) {
	if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream;

#	ifdef KFenv_posix
		/* issue the write syscall here and now so we can

Modified kmem/heapa.fn.c from [8818444ab8] to [641176b71f].

1
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
28
29
30
31
32
33
34
35
36
37

38
39
40


41
42
43
44
45
46
47

48
49
50
51
52
53
54
55
56
#include <k/mem.h>
#include <k/core.h>
#include <k/def.h>
#include <k/type.h>
#include <posix.h>
/* heapa.c - kmheapa() "heap alloc"
 * ~ lexi hale <lexi@hale.su>
 * kmheapa() allocates a pointer on the heap à la libc malloc()
 * see also: kmheapf() "heap free"
 */






/* we define all platform functions here,
 * whether or not they're for the correct
 * platform - only the ones actually called
 * by the generated code will be linked,

 * linker errors are our friend here! */
extern void* kmem_platform_mmap(void* addr,
		unsigned long sz, unsigned long prot, unsigned long flags,
		unsigned long fd, unsigned long off);

void* kmheapa(sz len) {
	/* allocate an object on the heap and return
	 * a pointer, or NULL if the allocation failed. */
	union {
		void* raw;
		ubyte* byte;
		kmbox* header;
	} region;
	/* we need to allocate space for the header and
	 * for the actual object */
	sz region_size = sizeof(kmbox) + len;

#	ifdef KFenv_posix
 	   /* posix APIs - we've got it easy. currently for nonlinear
		* heap allocation kmheapa simply uses m(un)map and lets the 
		* kernel worry about it. it may ultimately be worth replacing
		* this with a more sophisticated implementation, most likely

		* an existing allocator like jemalloc, though i'm wary of
		* including outside code - it creates a licensing mess and
		* i'd prefer libk to be AGPLv3 across the board. possibility:


		* include hooks for multiple allocators, allowing the user
		* to select & link in her preferred allocator at compile time? */

		/* because munmap needs to be informed of the size of
		 * the region it is going to unmap, we need to store
		 * that information in the allocated region itself.
		 * the user will be given a pointer that can be

		 * adjusted to point a field of type size_t that
		 * contains the size of the allocate space.*/

		region.byte = kmem_platform_mmap(null, region_size,
				posix_prot_read | posix_prot_write,
				posix_flag_anonymous | posix_map_shared, -1, 0);
		/* impl note: while per manpage fd is "ignored"
		 * for MAP_ANONYMOUS, "some implementations" require
		 * a value of -1 */




<






>
>
>
>
>
|
<
|
<
>
|












|
|



|
|
|
|
>
|
|
<
>
>
|
|


|
|
<
>
|
|







1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
#include <k/mem.h>
#include <k/core.h>
#include <k/def.h>
#include <k/type.h>

/* heapa.c - kmheapa() "heap alloc"
 * ~ lexi hale <lexi@hale.su>
 * kmheapa() allocates a pointer on the heap à la libc malloc()
 * see also: kmheapf() "heap free"
 */

/* arch specific headers */
#ifdef KFenv_posix
#	include <posix/posix.h>
#endif

/* we define all our platform functions here, whether or not

 * they're for the correct platform - only the ones that are

 * called by the preprocessed form of the code will actually
 * be linked, linker errors are our friend here! */
extern void* kmem_platform_mmap(void* addr,
		unsigned long sz, unsigned long prot, unsigned long flags,
		unsigned long fd, unsigned long off);

void* kmheapa(sz len) {
	/* allocate an object on the heap and return
	 * a pointer, or NULL if the allocation failed. */
	union {
		void* raw;
		ubyte* byte;
		kmbox* header;
	} region;
	/* we need to allocate space for the
	 * header and for the actual object */
	sz region_size = sizeof(kmbox) + len;

#	ifdef KFenv_posix
		/* posix  APIs  - we've  got  it  easy. currently  for
		 * nonlinear  heap  allocation   kmheapa  simply  uses
		 * m(un)map  and lets  the kernel  worry about  it. it
		 * may  ultimately  be  worth replacing  this  with  a
		 * more sophisticated  implementation, most  likely an
		 * existing allocator  like jemalloc, though  i'm wary
		 * of including outside code  - it creates a licensing

		 * mess and  i'd prefer libk  to be AGPLv3  across the
		 * board.  possibility:  include  hooks  for  multiple
		 * allocators, allowing  the user to select  & link in
		 * her preferred allocator at compile time? */

		/* because munmap needs to be informed of the size of
		 * the region we are going to unmap, we need to store
		 * that information in the region that we are mapping.

		 * the user will receive an adjusted pointer that can
		 * be adjusted to point a field of type size_t that
		 * contains the size of the allocated space.*/

		region.byte = kmem_platform_mmap(null, region_size,
				posix_prot_read | posix_prot_write,
				posix_flag_anonymous | posix_map_shared, -1, 0);
		/* impl note: while per manpage fd is "ignored"
		 * for MAP_ANONYMOUS, "some implementations" require
		 * a value of -1 */

Modified kmem/heapf.fn.c from [6a14dc9781] to [3d67513f54].

1
2
3
4
5
6
7
8
9
10
11





12
13
14
15

16
17
18
19
20
21
22
23
..
34
35
36
37
38
39
40
41
42
43
44
45
#include <k/mem.h>
#include <k/core.h>
#include <k/def.h>
#include <k/type.h>
#include <posix.h>
/* heapf.c - kmheapf() "heap free"
 * ~ lexi hale <lexi@hale.su>
 * kmheapf() frees a region on the heap à la libc free()
 * see also: kmheapa() "heap alloc"
 */






/* we define all platform functions here,
 * whether or not they're for the correct
 * platform - only the ones actually called
 * by the generated code will be linked,

 * linker errors are our friend here! */
extern int kmem_platform_munmap(void* addr, unsigned long sz);

kmcond kmheapf(void* ptr) {
	/* take an object allocated on the heap and free it,
	 * returning kmcond_ok on success or an appropriate
	 * value on failure. */
	struct kmbox* header = (kmbox*)
................................................................................
		if(kmem_platform_munmap(header, total) == -1) {
			/* we don't need to bother recovering errno;
			 * there's only one possible munmap error */
			return kmcond_bad_address;
		}

#	else
		Knoimpl(kmheapa,KVos);
#		error missing implementation
#	endif
	return kmcond_ok;
}




<






>
>
>
>
>
|
<
|
<
>
|







 







|




1
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
..
37
38
39
40
41
42
43
44
45
46
47
48
#include <k/mem.h>
#include <k/core.h>
#include <k/def.h>
#include <k/type.h>

/* heapf.c - kmheapf() "heap free"
 * ~ lexi hale <lexi@hale.su>
 * kmheapf() frees a region on the heap à la libc free()
 * see also: kmheapa() "heap alloc"
 */

/* arch specific headers */
#ifdef KFenv_posix
#	include <posix/posix.h>
#endif

/* we define all our platform functions here, whether or not

 * they're for the correct platform - only the ones that are

 * called by the preprocessed form of the code will actually
 * be linked, linker errors are our friend here! */
extern int kmem_platform_munmap(void* addr, unsigned long sz);

kmcond kmheapf(void* ptr) {
	/* take an object allocated on the heap and free it,
	 * returning kmcond_ok on success or an appropriate
	 * value on failure. */
	struct kmbox* header = (kmbox*)
................................................................................
		if(kmem_platform_munmap(header, total) == -1) {
			/* we don't need to bother recovering errno;
			 * there's only one possible munmap error */
			return kmcond_bad_address;
		}

#	else
		Knoimpl(kmheapf,KVos);
#		error missing implementation
#	endif
	return kmcond_ok;
}

Modified kmem/platform.mmap.fn.x86.lin.64.s from [ceb93a428c] to [a05b3cdd12].

1
2
3
4
5
6
7
8
9
bits 64
%include "../arch/x86.lin.64.s"
%include "../arch/x86.cdecl.64.s"
; vim: ft=nasm

global kmem_platform_mmap
kmem_platform_mmap:
	; to call mmap, we need to translate the cdecl64
	; register arguments to their appropriate syscall64

|







1
2
3
4
5
6
7
8
9
bits 64
%include "../arch/posix/x86.lin.64.s"
%include "../arch/x86.cdecl.64.s"
; vim: ft=nasm

global kmem_platform_mmap
kmem_platform_mmap:
	; to call mmap, we need to translate the cdecl64
	; register arguments to their appropriate syscall64

Modified kmem/platform.munmap.fn.x86.lin.64.s from [6d9c3d5edf] to [7b471fc276].

1
2
3
4
5
6
7
8
9
bits 64
%include "../arch/x86.lin.64.s"
%include "../arch/x86.cdecl.64.s"
; vim: ft=nasm

global kmem_platform_munmap
kmem_platform_munmap:
	; to call munmap, we need to translate the cdecl64
	; register arguments to their appropriate syscall64

|







1
2
3
4
5
6
7
8
9
bits 64
%include "../arch/posix/x86.lin.64.s"
%include "../arch/x86.cdecl.64.s"
; vim: ft=nasm

global kmem_platform_munmap
kmem_platform_munmap:
	; to call munmap, we need to translate the cdecl64
	; register arguments to their appropriate syscall64