提交 95307a0d 编写于 作者: W wcc0

add misc

Signed-off-by: Nwcc0 <917033401@qq.com>
Change-Id: Icaad37913ff3483fa0ff007deb94139408cac6b4
上级 326e92cc
......@@ -408,7 +408,8 @@
#define __NR_shellexec (__NR_OHOS_BEGIN + 18)
#define __NR_ohoscapget (__NR_OHOS_BEGIN + 19)
#define __NR_ohoscapset (__NR_OHOS_BEGIN + 20)
#define __NR_syscallend (__NR_OHOS_BEGIN + 21)
#define __NR_sysconf (__NR_OHOS_BEGIN + 21)
#define __NR_syscallend (__NR_OHOS_BEGIN + 22)
#define __ARM_NR_breakpoint 0x0f0001
#define __ARM_NR_cacheflush 0x0f0002
......
......@@ -390,7 +390,8 @@
#define __NR_shellexec (__NR_OHOS_BEGIN + 18)
#define __NR_ohoscapget (__NR_OHOS_BEGIN + 19)
#define __NR_ohoscapset (__NR_OHOS_BEGIN + 20)
#define __NR_syscallend (__NR_OHOS_BEGIN + 21)
#define __NR_sysconf (__NR_OHOS_BEGIN + 21)
#define __NR_syscallend (__NR_OHOS_BEGIN + 22)
#define __ARM_NR_breakpoint 0x0f0001
#define __ARM_NR_cacheflush 0x0f0002
......
......@@ -4,7 +4,6 @@
#include <sys/resource.h>
#include <signal.h>
#include <sys/sysinfo.h>
#include <unsupported_api.h>
#include "syscall.h"
#include "libc.h"
......@@ -25,196 +24,5 @@
long sysconf(int name)
{
static const short values[] = {
[_SC_ARG_MAX] = JT_ARG_MAX,
[_SC_CHILD_MAX] = RLIM(NPROC),
[_SC_CLK_TCK] = 100,
[_SC_NGROUPS_MAX] = 32,
[_SC_OPEN_MAX] = RLIM(NOFILE),
[_SC_STREAM_MAX] = -1,
[_SC_TZNAME_MAX] = TZNAME_MAX,
[_SC_JOB_CONTROL] = 1,
[_SC_SAVED_IDS] = 1,
[_SC_REALTIME_SIGNALS] = VER,
[_SC_PRIORITY_SCHEDULING] = -1,
[_SC_TIMERS] = VER,
[_SC_ASYNCHRONOUS_IO] = VER,
[_SC_PRIORITIZED_IO] = -1,
[_SC_SYNCHRONIZED_IO] = -1,
[_SC_FSYNC] = VER,
[_SC_MAPPED_FILES] = VER,
[_SC_MEMLOCK] = VER,
[_SC_MEMLOCK_RANGE] = VER,
[_SC_MEMORY_PROTECTION] = VER,
[_SC_MESSAGE_PASSING] = VER,
[_SC_SEMAPHORES] = VER,
[_SC_SHARED_MEMORY_OBJECTS] = VER,
[_SC_AIO_LISTIO_MAX] = -1,
[_SC_AIO_MAX] = -1,
[_SC_AIO_PRIO_DELTA_MAX] = JT_ZERO, /* ?? */
[_SC_DELAYTIMER_MAX] = JT_DELAYTIMER_MAX,
[_SC_MQ_OPEN_MAX] = -1,
[_SC_MQ_PRIO_MAX] = JT_MQ_PRIO_MAX,
[_SC_VERSION] = VER,
[_SC_PAGE_SIZE] = JT_PAGE_SIZE,
[_SC_RTSIG_MAX] = _NSIG - 1 - 31 - 3,
[_SC_SEM_NSEMS_MAX] = SEM_NSEMS_MAX,
[_SC_SEM_VALUE_MAX] = JT_SEM_VALUE_MAX,
[_SC_SIGQUEUE_MAX] = -1,
[_SC_TIMER_MAX] = -1,
[_SC_BC_BASE_MAX] = _POSIX2_BC_BASE_MAX,
[_SC_BC_DIM_MAX] = _POSIX2_BC_DIM_MAX,
[_SC_BC_SCALE_MAX] = _POSIX2_BC_SCALE_MAX,
[_SC_BC_STRING_MAX] = _POSIX2_BC_STRING_MAX,
[_SC_COLL_WEIGHTS_MAX] = COLL_WEIGHTS_MAX,
[_SC_EXPR_NEST_MAX] = -1,
[_SC_LINE_MAX] = -1,
[_SC_RE_DUP_MAX] = RE_DUP_MAX,
[_SC_2_VERSION] = VER,
[_SC_2_C_BIND] = VER,
[_SC_2_C_DEV] = -1,
[_SC_2_FORT_DEV] = -1,
[_SC_2_FORT_RUN] = -1,
[_SC_2_SW_DEV] = -1,
[_SC_2_LOCALEDEF] = -1,
[_SC_IOV_MAX] = IOV_MAX,
[_SC_THREADS] = VER,
[_SC_THREAD_SAFE_FUNCTIONS] = VER,
[_SC_GETGR_R_SIZE_MAX] = -1,
[_SC_GETPW_R_SIZE_MAX] = -1,
[_SC_LOGIN_NAME_MAX] = 256,
[_SC_TTY_NAME_MAX] = TTY_NAME_MAX,
[_SC_THREAD_DESTRUCTOR_ITERATIONS] = PTHREAD_DESTRUCTOR_ITERATIONS,
[_SC_THREAD_KEYS_MAX] = PTHREAD_KEYS_MAX,
[_SC_THREAD_STACK_MIN] = PTHREAD_STACK_MIN,
[_SC_THREAD_THREADS_MAX] = -1,
[_SC_THREAD_ATTR_STACKADDR] = VER,
[_SC_THREAD_ATTR_STACKSIZE] = VER,
[_SC_THREAD_PRIORITY_SCHEDULING] = VER,
[_SC_THREAD_PRIO_INHERIT] = -1,
[_SC_THREAD_PRIO_PROTECT] = -1,
[_SC_THREAD_PROCESS_SHARED] = VER,
[_SC_NPROCESSORS_CONF] = JT_NPROCESSORS_CONF,
[_SC_NPROCESSORS_ONLN] = JT_NPROCESSORS_ONLN,
[_SC_PHYS_PAGES] = JT_PHYS_PAGES,
[_SC_AVPHYS_PAGES] = JT_AVPHYS_PAGES,
[_SC_ATEXIT_MAX] = -1,
[_SC_PASS_MAX] = -1,
[_SC_XOPEN_VERSION] = _XOPEN_VERSION,
[_SC_XOPEN_XCU_VERSION] = _XOPEN_VERSION,
[_SC_XOPEN_UNIX] = 1,
[_SC_XOPEN_CRYPT] = -1,
[_SC_XOPEN_ENH_I18N] = 1,
[_SC_XOPEN_SHM] = 1,
[_SC_2_CHAR_TERM] = -1,
[_SC_2_UPE] = -1,
[_SC_XOPEN_XPG2] = -1,
[_SC_XOPEN_XPG3] = -1,
[_SC_XOPEN_XPG4] = -1,
[_SC_NZERO] = NZERO,
[_SC_XBS5_ILP32_OFF32] = -1,
[_SC_XBS5_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1,
[_SC_XBS5_LP64_OFF64] = sizeof(long)==8 ? 1 : -1,
[_SC_XBS5_LPBIG_OFFBIG] = -1,
[_SC_XOPEN_LEGACY] = -1,
[_SC_XOPEN_REALTIME] = -1,
[_SC_XOPEN_REALTIME_THREADS] = -1,
[_SC_ADVISORY_INFO] = VER,
[_SC_BARRIERS] = VER,
[_SC_CLOCK_SELECTION] = VER,
[_SC_CPUTIME] = VER,
[_SC_THREAD_CPUTIME] = VER,
[_SC_MONOTONIC_CLOCK] = VER,
[_SC_READER_WRITER_LOCKS] = VER,
[_SC_SPIN_LOCKS] = VER,
[_SC_REGEXP] = 1,
[_SC_SHELL] = 1,
[_SC_SPAWN] = VER,
[_SC_SPORADIC_SERVER] = -1,
[_SC_THREAD_SPORADIC_SERVER] = -1,
[_SC_TIMEOUTS] = VER,
[_SC_TYPED_MEMORY_OBJECTS] = -1,
[_SC_2_PBS] = -1,
[_SC_2_PBS_ACCOUNTING] = -1,
[_SC_2_PBS_LOCATE] = -1,
[_SC_2_PBS_MESSAGE] = -1,
[_SC_2_PBS_TRACK] = -1,
[_SC_SYMLOOP_MAX] = SYMLOOP_MAX,
[_SC_STREAMS] = JT_ZERO,
[_SC_2_PBS_CHECKPOINT] = -1,
[_SC_V6_ILP32_OFF32] = -1,
[_SC_V6_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1,
[_SC_V6_LP64_OFF64] = sizeof(long)==8 ? 1 : -1,
[_SC_V6_LPBIG_OFFBIG] = -1,
[_SC_HOST_NAME_MAX] = HOST_NAME_MAX,
[_SC_TRACE] = -1,
[_SC_TRACE_EVENT_FILTER] = -1,
[_SC_TRACE_INHERIT] = -1,
[_SC_TRACE_LOG] = -1,
[_SC_IPV6] = VER,
[_SC_RAW_SOCKETS] = VER,
[_SC_V7_ILP32_OFF32] = -1,
[_SC_V7_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1,
[_SC_V7_LP64_OFF64] = sizeof(long)==8 ? 1 : -1,
[_SC_V7_LPBIG_OFFBIG] = -1,
[_SC_SS_REPL_MAX] = -1,
[_SC_TRACE_EVENT_NAME_MAX] = -1,
[_SC_TRACE_NAME_MAX] = -1,
[_SC_TRACE_SYS_MAX] = -1,
[_SC_TRACE_USER_EVENT_MAX] = -1,
[_SC_XOPEN_STREAMS] = JT_ZERO,
[_SC_THREAD_ROBUST_PRIO_INHERIT] = -1,
[_SC_THREAD_ROBUST_PRIO_PROTECT] = -1,
};
unsupported_api(__FUNCTION__);
if (name >= sizeof(values)/sizeof(values[0]) || !values[name]) {
errno = EINVAL;
return -1;
} else if (values[name] >= -1) {
return values[name];
} else if (values[name] < -256) {
struct rlimit lim;
getrlimit(values[name]&16383, &lim);
if (lim.rlim_cur == RLIM_INFINITY)
return -1;
return lim.rlim_cur > LONG_MAX ? LONG_MAX : lim.rlim_cur;
}
switch ((unsigned char)values[name]) {
case VER & 255:
return _POSIX_VERSION;
case JT_ARG_MAX & 255:
return ARG_MAX;
case JT_MQ_PRIO_MAX & 255:
return MQ_PRIO_MAX;
case JT_PAGE_SIZE & 255:
return PAGE_SIZE;
case JT_SEM_VALUE_MAX & 255:
return SEM_VALUE_MAX;
case JT_DELAYTIMER_MAX & 255:
return DELAYTIMER_MAX;
case JT_NPROCESSORS_CONF & 255:
case JT_NPROCESSORS_ONLN & 255: ;
unsigned char set[128] = {1};
int i, cnt;
__syscall(SYS_sched_getaffinity, 0, sizeof set, set);
for (i=cnt=0; i<sizeof set; i++)
for (; set[i]; set[i]&=set[i]-1, cnt++);
return cnt;
case JT_PHYS_PAGES & 255:
case JT_AVPHYS_PAGES & 255: ;
unsigned long long mem;
struct sysinfo si;
__lsysinfo(&si);
if (!si.mem_unit) si.mem_unit = 1;
if (name==_SC_PHYS_PAGES) mem = si.totalram;
else mem = si.freeram + si.bufferram;
mem *= si.mem_unit;
mem /= PAGE_SIZE;
return (mem > LONG_MAX) ? LONG_MAX : mem;
case JT_ZERO & 255:
return 0;
}
return values[name];
return syscall(SYS_sysconf, name);
}
#define _GNU_SOURCE
#include <netdb.h>
#include <string.h>
#include <unistd.h>
#include <unsupported_api.h>
#define HOSTID_NUM 16
long gethostid()
{
unsupported_api(__FUNCTION__);
return 0;
int ret;
struct in_addr in;
struct hostent *hst = NULL;
char **p = NULL;
char host[128] = {0};
ret = gethostname(host, sizeof(host));
if (ret || host[0] == '\0') {
return -1;
}
hst = gethostbyname(host);
if (hst == NULL) {
return -1;
}
p = hst->h_addr_list;
memcpy(&in.s_addr, *p, sizeof(in.s_addr));
return (long)((in.s_addr << HOSTID_NUM) | (in.s_addr >> HOSTID_NUM));
}
#include <sys/resource.h>
#include <errno.h>
#include <unsupported_api.h>
#include "syscall.h"
#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
int getrlimit(int resource, struct rlimit *rlim)
{
unsigned long k_rlim[2];
unsupported_api(__FUNCTION__);
int ret = syscall(SYS_prlimit64, 0, resource, 0, rlim);
if (!ret) {
FIX(rlim->rlim_cur);
FIX(rlim->rlim_max);
}
if (!ret || errno != ENOSYS)
return ret;
unsigned long long k_rlim[2];
if (syscall(SYS_getrlimit, resource, k_rlim) < 0)
return -1;
rlim->rlim_cur = k_rlim[0] == -1UL ? RLIM_INFINITY : k_rlim[0];
rlim->rlim_max = k_rlim[1] == -1UL ? RLIM_INFINITY : k_rlim[1];
FIX(rlim->rlim_cur);
FIX(rlim->rlim_max);
rlim->rlim_cur = k_rlim[0];
rlim->rlim_max = k_rlim[1];
return 0;
}
......
#include <sys/resource.h>
#include <errno.h>
#include <unsupported_api.h>
#include "syscall.h"
#include "libc.h"
......@@ -9,7 +8,7 @@
static int __setrlimit(int resource, const struct rlimit *rlim)
{
unsigned long k_rlim[2];
unsigned long long k_rlim[2];
struct rlimit tmp;
if (SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
tmp = *rlim;
......@@ -17,10 +16,9 @@ static int __setrlimit(int resource, const struct rlimit *rlim)
FIX(tmp.rlim_max);
rlim = &tmp;
}
int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0);
if (ret != -ENOSYS) return ret;
k_rlim[0] = MIN(rlim->rlim_cur, MIN(-1UL, SYSCALL_RLIM_INFINITY));
k_rlim[1] = MIN(rlim->rlim_max, MIN(-1UL, SYSCALL_RLIM_INFINITY));
k_rlim[0] = rlim->rlim_cur;
k_rlim[1] = rlim->rlim_max;
return __syscall(SYS_setrlimit, resource, k_rlim);
}
......@@ -39,7 +37,6 @@ static void do_setrlimit(void *p)
int setrlimit(int resource, const struct rlimit *rlim)
{
unsupported_api(__FUNCTION__);
struct ctx c = { .res = resource, .rlim = rlim, .err = -1 };
__synccall(do_setrlimit, &c);
if (c.err) {
......
......@@ -4,10 +4,8 @@
#include <netdb.h>
#include <string.h>
#include <netinet/in.h>
#include <unsupported_api.h>
struct hostent *gethostbyname(const char *name)
{
unsupported_api(__FUNCTION__);
return gethostbyname2(name, AF_INET);
}
......@@ -4,7 +4,6 @@
#include <netdb.h>
#include <errno.h>
#include <stdlib.h>
#include <unsupported_api.h>
struct hostent *gethostbyname2(const char *name, int af)
{
......@@ -12,7 +11,7 @@ struct hostent *gethostbyname2(const char *name, int af)
size_t size = 63;
struct hostent *res;
int err;
unsupported_api(__FUNCTION__);
do {
free(h);
h = malloc(size+=size+1);
......
......@@ -7,7 +7,6 @@
#include <errno.h>
#include <stdint.h>
#include "lookup.h"
#include <unsupported_api.h>
int gethostbyname2_r(const char *name, int af,
struct hostent *h, char *buf, size_t buflen,
......@@ -19,7 +18,7 @@ int gethostbyname2_r(const char *name, int af,
size_t align, need;
*res = 0;
unsupported_api(__FUNCTION__);
cnt = __lookup_name(addrs, canon, name, af, AI_CANONNAME);
if (cnt<0) switch (cnt) {
case EAI_NONAME:
......
#include <unistd.h>
#include <sys/utsname.h>
#include <unsupported_api.h>
int gethostname(char *name, size_t len)
{
size_t i;
struct utsname uts;
unsupported_api(__FUNCTION__);
if (uname(&uts)) return -1;
if (len > sizeof uts.nodename) len = sizeof uts.nodename;
for (i=0; i<len && (name[i] = uts.nodename[i]); i++);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册