1 /* 2 * This file contains the main routine for retrieval of the kernel information 3 * page, as well as abstraction routines for retrieval of specific values from 4 * this kernel-mapped user information structure. These routines may be used 5 * from both userland and system services, and their accesses are considered to 6 * establish part of the userland ABI. Do not add routines here that are not 7 * for retrieval of userland ABI fields (e.g., clock information)! Also, since 8 * these functions are MINIX3 specific, their names should contain - preferably 9 * be prefixed with - "minix_". 10 */ 11 12 #define _MINIX_SYSTEM 13 14 #include <sys/cdefs.h> 15 #include "namespace.h" 16 #include <lib.h> 17 #include <minix/param.h> 18 #include <assert.h> 19 20 extern struct minix_kerninfo *_minix_kerninfo; 21 22 /* 23 * Get a pointer to the kernel information page. 24 */ 25 struct minix_kerninfo * get_minix_kerninfo(void)26get_minix_kerninfo(void) 27 { 28 29 assert(_minix_kerninfo != NULL); 30 31 return _minix_kerninfo; 32 } 33 34 /* 35 * Obtain the initial stack pointer for a new userland process. This value 36 * is used by routines that set up the stack when executing a new program. 37 * It is used for userland exec(2) and in various system services. 38 */ 39 vir_bytes minix_get_user_sp(void)40minix_get_user_sp(void) 41 { 42 struct minix_kerninfo *ki; 43 44 /* All information is obtained from the kernel information page. */ 45 ki = get_minix_kerninfo(); 46 47 /* 48 * Check whether we can retrieve the user stack pointer value from the 49 * kuserinfo structure. In general, this test is the correct one to 50 * see whether the kuserinfo structure has a certain field. 51 */ 52 if ((ki->ki_flags & MINIX_KIF_USERINFO) && 53 KUSERINFO_HAS_FIELD(ki->kuserinfo, kui_user_sp)) { 54 return ki->kuserinfo->kui_user_sp; 55 } 56 57 /* 58 * Otherwise, fall back to legacy support: retrieve the value from the 59 * kinfo structure. This field will eventually be removed. 60 */ 61 return ki->kinfo->user_sp; 62 } 63