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     53   	/* to check if a call failed, perform (x >= kiocond_fail) where x
    54     54   	 * is that call's return value. more typically however you should
    55     55   	 * select explicitly against kiocond_ok or kiocond_partial, since
    56     56   	 * those situations will usually need to be handled differently. */
    57     57   
    58     58   	kiocond_ok, // success
    59     59   	kiocond_partial, // partial read or write
           60  +	kiocond_poll, // call would block
           61  +	kiocond_interrupt, // call was interrupted by signal
    60     62   
    61     63       kiocond_fail, // action failed - unspecified reason
    62     64   	kiocond_fail_closed_stream, // action failed because stream is closed
           65  +	kiocond_fail_invalid,
           66  +	kiocond_fail_io,
           67  +	kiocond_fail_no_peer,
           68  +	kiocond_fail_no_space,
           69  +	kiocond_fail_forbidden,
           70  +	kiocond_fail_over_quota,
           71  +	kiocond_fail_pfault,
           72  +	kiocond_fail_too_big,
           73  +	kiocond_fail_stream_mismatch,
    63     74   } kiocond;
    64     75   
    65     76   kiocond kiosend(kiochan, ksraw, sz*); // send data to a channel
    66     77   kiocond kiorecv(kiochan, ksraw*); // receive data from a channel
    67     78   kmptr kiorecvall(kiochan, kmcell*, kmkind); // automatically allocate a bufer for a channel
    68     79     // kmkind is only used if kmcell* is null
    69     80   kiocond kiocon(kiochan, kiochan); // connect one channel to another
    70     81   
    71     82   #ifdef __cplusplus
    72     83   }
    73     84   #endif
    74     85   
    75     86   #endif

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

     7      7    */
     8      8   
     9      9   /* we define all platform functions here,
    10     10    * whether or not they're for the correct
    11     11    * platform - only the ones actually called
    12     12    * by the generated code will be linked */
    13     13   #include <posix.h>
           14  +#include <error_table.h>
    14     15   
    15     16   kiocond kiosend(kiochan target, ksraw string, sz* len) {
    16     17   	if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream;
    17     18   
    18     19   #	ifdef KFenv_posix
    19     20   		/* issue the write syscall here and now so we can
    20     21   		 * retrieve errno and report it if necessary */
................................................................................
    22     23   		k_platform_syscall_arg args[] = {
    23     24   			target.out.platform_fd, (k_platform_syscall_arg)string.ptr, string.size };
    24     25   
    25     26   		struct k_platform_syscall_answer a = k_platform_syscall
    26     27   			(k_platform_syscall_write,3,args);
    27     28   
    28     29   		sz size = a.ret;
    29         -		if (size == -1) return kiocond_fail; //TODO: retrieve errno and offer more specific errors
           30  +		if (size == -1) switch(a.error) {
           31  +			case k_platform_error_EPERM:  return kiocond_fail_forbidden;
           32  +			case k_platform_error_EINVAL: return kiocond_fail_invalid;
           33  +			case k_platform_error_EBADF:  return kiocond_fail_invalid;
           34  +			case k_platform_error_EFAULT: return kiocond_fail_pfault;
           35  +			case k_platform_error_ENOSPC: return kiocond_fail_no_space;
           36  +			case k_platform_error_EDQUOT: return kiocond_fail_over_quota;
           37  +			case k_platform_error_EIO:    return kiocond_fail_io;
           38  +			case k_platform_error_EAGAIN: return kiocond_poll;
           39  +			case k_platform_error_EFBIG:  return kiocond_fail_too_big;
           40  +			case k_platform_error_EINTR:  return kiocond_interrupt;
           41  +			case k_platform_error_EDESTADDRREQ: return kiocond_fail_no_peer;
           42  +			default: return kiocond_fail;
           43  +		}
    30     44   #	else
    31     45   #		if KVos == win
    32     46   #			error windows IO send function not yet defined
    33     47   #		else
    34     48   			Knoimpl(kiosend,KVos);
    35     49   #			error missing implementation // boring error for plebs
    36     50   #		endif
    37     51   #	endif
    38     52   
    39     53   	if (len != null) *len = size;
    40     54   	return kiocond_ok;
    41     55   }

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

     1      1   export OUT = $(PWD)/out
     2      2   
     3      3   # TODO: calculate these using $(MAKE_HOST)
     4      4   export ARCH = x86
     5      5   export OS = lin
     6      6   export BITS = 64
     7      7   export ROOT = $(PWD)
     8         -export TMP = $(PWD)/tmp
            8  +export TMP = $(PWD)/gen
     9      9   
    10     10   ifneq ($(BITS),)
    11     11       export TARGET = $(ARCH).$(OS).$(BITS)
    12     12   else
    13     13       export TARGET = $(ARCH).$(OS)
    14     14   endif
    15     15   
................................................................................
    90     90   uninstall: $(header-dir)/k $(lib-dir)/k
    91     91   	rm -rf $^
    92     92   
    93     93   lists = moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX
    94     94   dbg:
    95     95   	@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")
    96     96   
    97         -%.obj: %/makefile $(TMP)/system_calls.h $(TMP)/system_calls.s $(OUT)
           97  +%.obj: %/makefile  $(OUT)
    98     98   	cd $* && $(MAKE) obj
    99     99   
   100    100   %.tool: %/makefile $(OUT)
   101    101   	cd $* && $(MAKE) tool
   102    102   
   103    103   %.dbg: %/makefile $(OUT)
   104    104   	cd $* && $(MAKE) dbg
   105    105   
   106         -%.def: %/makefile $(TMP)/typesize.def $(OUT) $(OUT)/k
          106  +%.def: %/makefile $(TMP)/typesize.def \
          107  +                  $(TMP)/system_calls.h \
          108  +				  $(TMP)/system_calls.s \
          109  +				  $(TMP)/error_table.h \
          110  +				  $(OUT) $(OUT)/k
   107    111   	cd $* && $(MAKE) def
   108    112   
   109    113   .PRECIOUS: $(TMP)/system_calls.%
   110    114   $(TMP)/system_calls.%: arch/makefile
   111    115   	$(MAKE) -C arch $@
          116  +
          117  +$(TMP)/error_table.h: arch/makefile
          118  +	$(MAKE) -C arch $@
   112    119   
   113    120   $(TMP)/typesize.def: arch/makefile $(TMP)
   114    121   	$(MAKE) -C arch $@
   115    122   
   116    123   $(OUT)/libk.so: $(fnobjects) 
   117    124   	ld -shared $(COMPLIB) -o $@ $^
   118    125   	@# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o