libk  Diff

Differences From Artifact [c8ccec879e]:

To Artifact [c08b42ee14]:


    16     16   #include <error_table.h>
    17     17   
    18     18   /* we define all our platform functions here, whether or not
    19     19    * they're for the correct platform - only the ones that are
    20     20    * called by the preprocessed form of the code will actually
    21     21    * be linked, linker errors are our friend here! */
    22     22   
    23         -kmcond kmheapa(void** where, sz len) {
           23  +kmres kmheapa(sz len) {
    24     24   	/* allocate an object on the heap and return
    25     25   	 * a pointer, or NULL if the allocation failed. */
    26     26   	union {
    27     27   		void* raw;
    28     28   		ubyte* byte;
    29     29   		kmbox* header;
    30     30   	} region;
    31     31   	/* we need to allocate space for the
    32     32   	 * header and for the actual object */
    33     33   	sz region_size = sizeof(kmbox) + len;
           34  +	kmres reply;
    34     35   
    35     36   #	ifdef KFenv_posix
    36     37   		/* posix  APIs  - we've  got  it  easy. currently  for
    37     38   		 * nonlinear  heap  allocation   kmheapa  simply  uses
    38     39   		 * m(un)map  and lets  the kernel  worry about  it. it
    39     40   		 * may  ultimately  be  worth replacing  this  with  a
    40     41   		 * more sophisticated  implementation, most  likely an
................................................................................
    64     65   		 * a value of -1 */
    65     66   
    66     67   		struct k_platform_syscall_answer r = k_platform_syscall
    67     68   			(k_platform_syscall_mmap, Kmsz(args), args);
    68     69   
    69     70   		if (r.error == 0) region.byte = (ubyte*)r.ret; else {
    70     71   			switch (r.error) {
    71         -				case k_platform_error_EAGAIN: return kmcond_bad_lock;
    72         -				case k_platform_error_EINVAL: return kmcond_bad_size;
    73         -				case k_platform_error_EMFILE: return kmcond_too_many;
    74         -				case k_platform_error_ENOMEM: return kmcond_no_room;
    75         -				default: return kmcond_fail_assert;
           72  +				case k_platform_error_EAGAIN: reply.cond = kmcond_bad_lock; break;
           73  +				case k_platform_error_EINVAL: reply.cond = kmcond_bad_size; break;
           74  +				case k_platform_error_EMFILE: reply.cond = kmcond_too_many; break;
           75  +				case k_platform_error_ENOMEM: reply.cond = kmcond_no_room;  break;
           76  +				default: reply.cond = kmcond_fail_assert;
    76     77   			}
           78  +			reply.raw = (void*)0;
           79  +			return reply;
    77     80   		}
    78     81   #	else
    79     82    	   Knoimpl(kmheapa,KVos);
    80     83   #		error missing implementation
    81     84   #	endif
    82     85   	
    83     86   	void* const object = (region.byte + sizeof (kmbox));
    84     87   
    85     88   	region.header -> kind = kmkind_heap;
    86     89   	region.header -> size = len;
    87     90   
    88         -	*where = object;
    89         -	return kmcond_ok;
           91  +	reply.cond = kmcond_ok;
           92  +	reply.raw = object;
           93  +
           94  +	return reply;
    90     95   }