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