-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathos.h
100 lines (82 loc) · 2.74 KB
/
os.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright 2018 Andrei Pangin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _OS_H
#define _OS_H
#include "arch.h"
#include <signal.h>
#include <stddef.h>
#include <sys/types.h>
typedef void (*SigAction)(int, siginfo_t *, void *);
typedef void (*SigHandler)(int);
typedef void (*TimerCallback)(void *);
// Interrupt threads with this signal. The same signal is used inside JDK to
// interrupt I/O operations.
const int WAKEUP_SIGNAL = SIGIO;
class ThreadList {
public:
virtual ~ThreadList() {}
virtual void rewind() = 0;
virtual int next() = 0;
virtual int size() = 0;
};
// W^X memory support
class JitWriteProtection {
private:
u64 _prev;
bool _restore;
public:
explicit JitWriteProtection(bool enable);
~JitWriteProtection();
};
class OS {
public:
static const size_t page_size;
static const size_t page_mask;
static u64 nanotime();
static u64 cputime();
static u64 micros();
static u64 processStartTime();
static void sleep(u64 nanos);
static u64 hton64(u64 x);
static u64 ntoh64(u64 x);
static int getMaxThreadId();
static int getMaxThreadId(int floor) {
int maxThreadId = getMaxThreadId();
return maxThreadId < floor ? floor : maxThreadId;
}
static int processId();
static int threadId();
static const char *schedPolicy(int thread_id);
static bool threadName(int thread_id, char *name_buf, size_t name_len);
static ThreadList *listThreads();
static bool isLinux();
static SigAction installSignalHandler(int signo, SigAction action,
SigHandler handler = NULL);
static SigAction replaceSigsegvHandler(SigAction action);
static SigAction replaceSigbusHandler(SigAction action);
static bool sendSignalToThread(int thread_id, int signo);
static void *safeAlloc(size_t size);
static void safeFree(void *addr, size_t size);
static bool getCpuDescription(char *buf, size_t size);
static u64 getProcessCpuTime(u64 *utime, u64 *stime);
static u64 getTotalCpuTime(u64 *utime, u64 *stime);
static void copyFile(int src_fd, int dst_fd, off_t offset, size_t size);
static int fileSize(int fd);
static int truncateFile(int fd);
static void freePageCache(int fd, off_t start_offset);
static void mallocArenaMax(int arena_max);
};
#endif // _OS_H