xref: /haiku/src/system/libroot/os/arch/x86/compatibility.c (revision 893988af824e65e49e55f517b157db8386e8002b)
1 /*
2  * Copyright 2005-2008, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 //!	This file includes some known R5 syscalls
7 
8 #include <errno.h>
9 #include <sys/resource.h>
10 #include <sys/stat.h>
11 
12 #include <SupportDefs.h>
13 #include <fs_info.h>
14 
15 #include <syscalls.h>
16 
17 
18 int _kset_mon_limit_(int num);
19 int _kset_fd_limit_(int num);
20 int _klock_node_(int fd);
21 int _kunlock_node_(int fd);
22 int _kget_cpu_state_(int cpuNum);
23 int _kset_cpu_state_(int cpuNum, int state);
24 int _kstatfs_(dev_t device, void *whatever, int fd, const char *path, fs_info *info);
25 
26 
27 int
28 _kset_mon_limit_(int num)
29 {
30 	struct rlimit rl;
31 	if (num < 1)
32 		return EINVAL;
33 	rl.rlim_cur = num;
34 	rl.rlim_max = RLIM_SAVED_MAX;
35 	if (setrlimit(RLIMIT_NOVMON, &rl) < 0)
36 		return errno;
37 	return B_OK;
38 }
39 
40 
41 int
42 _kset_fd_limit_(int num)
43 {
44 	struct rlimit rl;
45 	if (num < 1)
46 		return EINVAL;
47 	rl.rlim_cur = num;
48 	rl.rlim_max = RLIM_SAVED_MAX;
49 	if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
50 		return errno;
51 	return B_OK;
52 }
53 
54 
55 int
56 _klock_node_(int fd)
57 {
58 	return _kern_lock_node(fd);
59 }
60 
61 
62 int
63 _kunlock_node_(int fd)
64 {
65 	return _kern_unlock_node(fd);
66 }
67 
68 
69 int
70 _kget_cpu_state_(int cpuNum)
71 {
72 	return _kern_cpu_enabled(cpuNum);
73 }
74 
75 
76 int
77 _kset_cpu_state_(int cpuNum, int state)
78 {
79 	return _kern_set_cpu_enabled(cpuNum, state != 0);
80 }
81 
82 
83 int
84 _kstatfs_(dev_t device, void *whatever, int fd, const char *path, fs_info *info)
85 {
86 	if (device < 0) {
87 		if (fd >= 0) {
88 			struct stat stat;
89 			if (fstat(fd, &stat) < 0)
90 				return -1;
91 
92 			device = stat.st_dev;
93 		} else if (path != NULL)
94 			device = dev_for_path(path);
95 	}
96 	if (device < 0)
97 		return B_ERROR;
98 
99 	return fs_stat_dev(device, info);
100 }
101