xref: /haiku/src/system/libroot/os/arch/x86/compatibility.c (revision 6e927a5fc080cb934e7584454f472cacf4c3e361)
1 /*
2  * Copyright 2005-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
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 // ToDo: maybe they should indeed do something...
13 
14 #include <SupportDefs.h>
15 #include <fs_info.h>
16 
17 #include <syscalls.h>
18 
19 #include <errno.h>
20 #include <sys/resource.h>
21 #include <sys/stat.h>
22 
23 
24 int _kset_mon_limit_(int num);
25 int _kset_fd_limit_(int num);
26 int _klock_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 _kget_cpu_state_(int cpuNum)
69 {
70 	return _kern_cpu_enabled(cpuNum);
71 }
72 
73 
74 int
75 _kset_cpu_state_(int cpuNum, int state)
76 {
77 	return _kern_set_cpu_enabled(cpuNum, state != 0);
78 }
79 
80 
81 int
82 _kstatfs_(dev_t device, void *whatever, int fd, const char *path, fs_info *info)
83 {
84 	if (device < 0) {
85 		if (fd >= 0) {
86 			struct stat stat;
87 			if (fstat(fd, &stat) < 0)
88 				return -1;
89 
90 			device = stat.st_dev;
91 		} else if (path != NULL)
92 			device = dev_for_path(path);
93 	}
94 	if (device < 0)
95 		return B_ERROR;
96 
97 	return fs_stat_dev(device, info);
98 }
99 
100 
101 #endif	// __GNUC__ < 3
102