diff --git a/include/bits/confname.h b/include/bits/confname.h index 062caf7..556c487 100644 --- a/include/bits/confname.h +++ b/include/bits/confname.h @@ -43,6 +43,9 @@ #define _SC_PHYS_PAGES 7 /* physical pages */ #define _SC_GETPW_R_SIZE_MAX 8 /* passwd buffer size */ #define _SC_GETGR_R_SIZE_MAX 9 /* group buffer size */ +#define _SC_AVPHYS_PAGES 10 /* available physical pages */ +#define _SC_NPROCESSORS_CONF 11 +#define _SC_NPROCESSORS_ONLN 12 #if (defined __USE_POSIX2 || defined __USE_UNIX98 \ || defined __USE_FILE_OFFSET64 || defined __USE_LARGEFILE64 \ diff --git a/include/sys/MISCFILES b/include/sys/MISCFILES index bce4098..ca89b79 100644 --- a/include/sys/MISCFILES +++ b/include/sys/MISCFILES @@ -29,6 +29,7 @@ MISCFILES = MISCFILES \ statfs.h \ statvfs.h \ syscall.h \ + sysinfo.h \ syslog.h \ sysmacros.h \ systeminfo.h \ diff --git a/include/sys/sysinfo.h b/include/sys/sysinfo.h new file mode 100644 index 0000000..a9928d0 --- /dev/null +++ b/include/sys/sysinfo.h @@ -0,0 +1,19 @@ +#ifndef _SYS_SYSINFO_H +#define _SYS_SYSINFO_H + +/* Return number of configured processors. */ +extern int get_nprocs_conf (void); + +/* Return number of available processors. */ +extern int get_nprocs (void); + +/* Return number of physical pages of memory in the system. */ +extern long int get_phys_pages (void); + +/* Return number of available physical pages of memory in the system. */ +extern long int get_avphys_pages (void); + +/* Return maximum number of processes this real user ID can have. */ +extern long int get_child_max (void); + +#endif /* sys/sysinfo.h */ \ No newline at end of file diff --git a/posix/sysconf.c b/posix/sysconf.c index d0653f8..4385d06 100644 --- a/posix/sysconf.c +++ b/posix/sysconf.c @@ -12,9 +12,12 @@ #include #include #include +#include #include "lib.h" +#ifndef UNLIMITED #define UNLIMITED (0x7fffffffL) +#endif long __sysconf (int var) @@ -31,7 +34,7 @@ __sysconf (int var) switch(var) { case _SC_LAST: - return 4; + return 12; case _SC_MEMR_MAX: return UNLIMITED; /* not true for TOS < 1.4 :-( */ case _SC_ARG_MAX: @@ -42,11 +45,23 @@ __sysconf (int var) case _SC_NGROUPS_MAX: return NGROUPS_MAX; case _SC_CHILD_MAX: - return UNLIMITED; /* good 'ol TOS :-) */ + return get_child_max(); case _SC_CLK_TCK: return CLOCKS_PER_SEC; case _SC_PAGE_SIZE: return getpagesize(); + case _SC_GETPW_R_SIZE_MAX: + return -1; + case _SC_GETGR_R_SIZE_MAX: + return -1; + case _SC_PHYS_PAGES: + return get_phys_pages(); + case _SC_AVPHYS_PAGES: + return get_avphys_pages(); + case _SC_NPROCESSORS_CONF: + return get_nprocs_conf(); + case _SC_NPROCESSORS_ONLN: + return get_nprocs (); default: return -1; } diff --git a/unix/SRCFILES b/unix/SRCFILES index 5bd9e1b..4228cb9 100644 --- a/unix/SRCFILES +++ b/unix/SRCFILES @@ -47,6 +47,7 @@ SRCFILES = \ getrlimit.c \ getrusage.c \ getsid.c \ + getsysstat.c \ gettimeofday.c \ getuid.c \ gtty.c \ diff --git a/unix/getsysstat.c b/unix/getsysstat.c new file mode 100644 index 0000000..e502485 --- /dev/null +++ b/unix/getsysstat.c @@ -0,0 +1,84 @@ + +#include +#include +#include +#include + +#include + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef UNLIMITED +#define UNLIMITED (0x7fffffffL) +#endif + +static int is_there_altram(void){ + if(Supexec(*ramtop) > 0x01000000L){ + return TRUE; + } + return FALSE; +} + +static unsigned long int get_altram_value(void){ + if(is_there_altram()){ + return (int)((Supexec(*ramtop) - 0x01000000L)); + } + return 0; +} + +static unsigned long int get_stram_value(void){ + return Supexec(*phystop); +} + +static unsigned long int get_available_altram(void){ + if(is_there_altram()){ + return Mxalloc(-1, 1); + } + return 0; +} + +static unsigned long int get_available_stram(void){ + return Mxalloc(-1, 0); +} + +__typeof__(get_nprocs_conf) __get_nprocs_conf; +int __get_nprocs_conf (void){ + return 1; +} +weak_alias (__get_nprocs_conf, get_nprocs_conf) + +/* Return number of available processors. */ +__typeof__(get_nprocs) __get_nprocs; +int __get_nprocs (void){ + return 1; +} +weak_alias (__get_nprocs, get_nprocs) + +/* Return number of physical pages of memory in the system. */ +__typeof__(get_phys_pages) __get_phys_pages; +long int __get_phys_pages (void){ + return ((get_stram_value() + get_altram_value()) / getpagesize()); +} +weak_alias (__get_phys_pages, get_phys_pages) + +/* Return number of available physical pages of memory in the system. */ +__typeof__(get_avphys_pages) __get_avphys_pages; +long int __get_avphys_pages (void){ + return (get_available_stram() + get_available_altram()) / getpagesize(); +} +weak_alias (__get_avphys_pages, get_avphys_pages) + +/* Return maximum number of processes this real user ID can have. */ +__typeof__(get_child_max) __get_child_max; +long int __get_child_max (void){ +#ifdef CHILD_MAX + return CHILD_MAX; +#else + return UNLIMITED; +#endif +} +weak_alias (__get_child_max, get_child_max) \ No newline at end of file