libk  Check-in [b2f129d7b9]

Overview
Comment:add error reporting to kiosend()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b2f129d7b9bea7fcd36d62bafb0cd2001d39ab3289adf2eb3c876bc2d2d156da
User & Date: lexi on 2019-08-18 18:29:54
Other Links: manifest | tags
Context
2019-08-19
01:46
updates, begin putting together error-handling mechanism check-in: b5f6f19923 user: lexi tags: trunk
2019-08-18
18:29
add error reporting to kiosend() check-in: b2f129d7b9 user: lexi tags: trunk
17:56
revamp arch/ makefile, add generic syscall fn on posix, rewrite kiosend() to use k_platform_syscall instead of k_platform_write check-in: 37b0cfaa06 user: lexi tags: trunk
Changes

Modified kio/io.h from [8ac183a3d1] to [d3b54028db].

53
54
55
56
57
58
59


60
61
62









63
64
65
66
67
68
69
70
71
72
73
74
75
	/* to check if a call failed, perform (x >= kiocond_fail) where x
	 * is that call's return value. more typically however you should
	 * select explicitly against kiocond_ok or kiocond_partial, since
	 * those situations will usually need to be handled differently. */

	kiocond_ok, // success
	kiocond_partial, // partial read or write



    kiocond_fail, // action failed - unspecified reason
	kiocond_fail_closed_stream, // action failed because stream is closed









} kiocond;

kiocond kiosend(kiochan, ksraw, sz*); // send data to a channel
kiocond kiorecv(kiochan, ksraw*); // receive data from a channel
kmptr kiorecvall(kiochan, kmcell*, kmkind); // automatically allocate a bufer for a channel
  // kmkind is only used if kmcell* is null
kiocond kiocon(kiochan, kiochan); // connect one channel to another

#ifdef __cplusplus
}
#endif

#endif







>
>



>
>
>
>
>
>
>
>
>













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
	/* to check if a call failed, perform (x >= kiocond_fail) where x
	 * is that call's return value. more typically however you should
	 * select explicitly against kiocond_ok or kiocond_partial, since
	 * those situations will usually need to be handled differently. */

	kiocond_ok, // success
	kiocond_partial, // partial read or write
	kiocond_poll, // call would block
	kiocond_interrupt, // call was interrupted by signal

    kiocond_fail, // action failed - unspecified reason
	kiocond_fail_closed_stream, // action failed because stream is closed
	kiocond_fail_invalid,
	kiocond_fail_io,
	kiocond_fail_no_peer,
	kiocond_fail_no_space,
	kiocond_fail_forbidden,
	kiocond_fail_over_quota,
	kiocond_fail_pfault,
	kiocond_fail_too_big,
	kiocond_fail_stream_mismatch,
} kiocond;

kiocond kiosend(kiochan, ksraw, sz*); // send data to a channel
kiocond kiorecv(kiochan, ksraw*); // receive data from a channel
kmptr kiorecvall(kiochan, kmcell*, kmkind); // automatically allocate a bufer for a channel
  // kmkind is only used if kmcell* is null
kiocond kiocon(kiochan, kiochan); // connect one channel to another

#ifdef __cplusplus
}
#endif

#endif

Modified kio/send.fn.c from [0bd4793a38] to [f571b39492].

7
8
9
10
11
12
13

14
15
16
17
18
19
20
..
22
23
24
25
26
27
28
29













30
31
32
33
34
35
36
37
38
39
40
41
 */

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


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
		 * retrieve errno and report it if necessary */
................................................................................
		k_platform_syscall_arg args[] = {
			target.out.platform_fd, (k_platform_syscall_arg)string.ptr, string.size };

		struct k_platform_syscall_answer a = k_platform_syscall
			(k_platform_syscall_write,3,args);

		sz size = a.ret;
		if (size == -1) return kiocond_fail; //TODO: retrieve errno and offer more specific errors













#	else
#		if KVos == win
#			error windows IO send function not yet defined
#		else
			Knoimpl(kiosend,KVos);
#			error missing implementation // boring error for plebs
#		endif
#	endif

	if (len != null) *len = size;
	return kiocond_ok;
}







>







 







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












7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
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
 */

/* 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
		 * retrieve errno and report it if necessary */
................................................................................
		k_platform_syscall_arg args[] = {
			target.out.platform_fd, (k_platform_syscall_arg)string.ptr, string.size };

		struct k_platform_syscall_answer a = k_platform_syscall
			(k_platform_syscall_write,3,args);

		sz size = a.ret;
		if (size == -1) switch(a.error) {
			case k_platform_error_EPERM:  return kiocond_fail_forbidden;
			case k_platform_error_EINVAL: return kiocond_fail_invalid;
			case k_platform_error_EBADF:  return kiocond_fail_invalid;
			case k_platform_error_EFAULT: return kiocond_fail_pfault;
			case k_platform_error_ENOSPC: return kiocond_fail_no_space;
			case k_platform_error_EDQUOT: return kiocond_fail_over_quota;
			case k_platform_error_EIO:    return kiocond_fail_io;
			case k_platform_error_EAGAIN: return kiocond_poll;
			case k_platform_error_EFBIG:  return kiocond_fail_too_big;
			case k_platform_error_EINTR:  return kiocond_interrupt;
			case k_platform_error_EDESTADDRREQ: return kiocond_fail_no_peer;
			default: return kiocond_fail;
		}
#	else
#		if KVos == win
#			error windows IO send function not yet defined
#		else
			Knoimpl(kiosend,KVos);
#			error missing implementation // boring error for plebs
#		endif
#	endif

	if (len != null) *len = size;
	return kiocond_ok;
}

Modified makefile from [5163613e5d] to [ed3c61cbaa].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
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
export OUT = $(PWD)/out

# TODO: calculate these using $(MAKE_HOST)
export ARCH = x86
export OS = lin
export BITS = 64
export ROOT = $(PWD)
export TMP = $(PWD)/tmp

ifneq ($(BITS),)
    export TARGET = $(ARCH).$(OS).$(BITS)
else
    export TARGET = $(ARCH).$(OS)
endif

................................................................................
uninstall: $(header-dir)/k $(lib-dir)/k
	rm -rf $^

lists = moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX
dbg:
	@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")

%.obj: %/makefile $(TMP)/system_calls.h $(TMP)/system_calls.s $(OUT)
	cd $* && $(MAKE) obj

%.tool: %/makefile $(OUT)
	cd $* && $(MAKE) tool

%.dbg: %/makefile $(OUT)
	cd $* && $(MAKE) dbg

%.def: %/makefile $(TMP)/typesize.def $(OUT) $(OUT)/k




	cd $* && $(MAKE) def

.PRECIOUS: $(TMP)/system_calls.%
$(TMP)/system_calls.%: arch/makefile
	$(MAKE) -C arch $@




$(TMP)/typesize.def: arch/makefile $(TMP)
	$(MAKE) -C arch $@

$(OUT)/libk.so: $(fnobjects) 
	ld -shared $(COMPLIB) -o $@ $^
	@# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o







|







 







|








|
>
>
>
>





>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
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
export OUT = $(PWD)/out

# TODO: calculate these using $(MAKE_HOST)
export ARCH = x86
export OS = lin
export BITS = 64
export ROOT = $(PWD)
export TMP = $(PWD)/gen

ifneq ($(BITS),)
    export TARGET = $(ARCH).$(OS).$(BITS)
else
    export TARGET = $(ARCH).$(OS)
endif

................................................................................
uninstall: $(header-dir)/k $(lib-dir)/k
	rm -rf $^

lists = moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX
dbg:
	@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")

%.obj: %/makefile  $(OUT)
	cd $* && $(MAKE) obj

%.tool: %/makefile $(OUT)
	cd $* && $(MAKE) tool

%.dbg: %/makefile $(OUT)
	cd $* && $(MAKE) dbg

%.def: %/makefile $(TMP)/typesize.def \
                  $(TMP)/system_calls.h \
				  $(TMP)/system_calls.s \
				  $(TMP)/error_table.h \
				  $(OUT) $(OUT)/k
	cd $* && $(MAKE) def

.PRECIOUS: $(TMP)/system_calls.%
$(TMP)/system_calls.%: arch/makefile
	$(MAKE) -C arch $@

$(TMP)/error_table.h: arch/makefile
	$(MAKE) -C arch $@

$(TMP)/typesize.def: arch/makefile $(TMP)
	$(MAKE) -C arch $@

$(OUT)/libk.so: $(fnobjects) 
	ld -shared $(COMPLIB) -o $@ $^
	@# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o