Skip to content

Adding definition for _SC_AVPHYS_PAGES #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/bits/confname.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions include/sys/MISCFILES
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MISCFILES = MISCFILES \
statfs.h \
statvfs.h \
syscall.h \
sysinfo.h \
syslog.h \
sysmacros.h \
systeminfo.h \
Expand Down
19 changes: 19 additions & 0 deletions include/sys/sysinfo.h
Original file line number Diff line number Diff line change
@@ -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 */
19 changes: 17 additions & 2 deletions posix/sysconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
#include <errno.h>
#include <limits.h>
#include <time.h>
#include <sys/sysinfo.h>
#include "lib.h"

#ifndef UNLIMITED
#define UNLIMITED (0x7fffffffL)
#endif

long
__sysconf (int var)
Expand All @@ -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:
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions unix/SRCFILES
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SRCFILES = \
getrlimit.c \
getrusage.c \
getsid.c \
getsysstat.c \
gettimeofday.c \
getuid.c \
gtty.c \
Expand Down
84 changes: 84 additions & 0 deletions unix/getsysstat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

#include <unistd.h>
#include <bits/local_lim.h>
#include <mint/osbind.h>
#include <mint/sysvars.h>

#include <sys/sysinfo.h>

#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)