libk  Diff

Differences From Artifact [c08b42ee14]:

To Artifact [99ad7a3351]:


27
28
29
30
31
32
33









34
35
36
37
38
39
40
..
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
..
78
79
80
81
82
83
84




85
86
87
88
89
90
91
92
93
94
95
		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;









	kmres reply;

#	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
................................................................................
		k_platform_syscall_arg args[] = {
			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 */


		struct k_platform_syscall_answer r = k_platform_syscall
			(k_platform_syscall_mmap, Kmsz(args), args);

		if (r.error == 0) region.byte = (ubyte*)r.ret; else {
			switch (r.error) {
				case k_platform_error_EAGAIN: reply.cond = kmcond_bad_lock; break;
................................................................................
			reply.raw = (void*)0;
			return reply;
		}
#	else
 	   Knoimpl(kmheapa,KVos);
#		error missing implementation
#	endif




	
	void* const object = (region.byte + sizeof (kmbox));

	region.header -> kind = kmkind_heap;
	region.header -> size = len;

	reply.cond = kmcond_ok;
	reply.raw = object;

	return reply;
}







>
>
>
>
>
>
>
>
>







 







|
|
|
>







 







>
>
>
>











27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
		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;

	/* kmres reply is the struct that shall be returned by the
	 * function. if an error-condition occurs, the appropriate
	 * error code should be determined through system-specific
	 * means, the pointer value should be set to null, and the
	 * object should be returned immediately. if the object is
	 * not returned from within the system-specific section it
	 * will then be filled out with the appropriate values for
	 * a successful allocation and returned to the caller. */
	kmres reply;

#	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
................................................................................
		k_platform_syscall_arg args[] = {
			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, so we're setting it to that just to
		 * be safe. */

		struct k_platform_syscall_answer r = k_platform_syscall
			(k_platform_syscall_mmap, Kmsz(args), args);

		if (r.error == 0) region.byte = (ubyte*)r.ret; else {
			switch (r.error) {
				case k_platform_error_EAGAIN: reply.cond = kmcond_bad_lock; break;
................................................................................
			reply.raw = (void*)0;
			return reply;
		}
#	else
 	   Knoimpl(kmheapa,KVos);
#		error missing implementation
#	endif

	/* if the system-specific code has not returned early,
	 * we assume success and return the new pointer to the
	 * calling function along with a success code. */
	
	void* const object = (region.byte + sizeof (kmbox));

	region.header -> kind = kmkind_heap;
	region.header -> size = len;

	reply.cond = kmcond_ok;
	reply.raw = object;

	return reply;
}