99 // Helper function; describes pthread attributes as short string. String is written
100 // to buf with len buflen; buf is returned.
101 static char* describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr);
102
103 // A safe implementation of realpath which will not cause a buffer overflow if the resolved path
104 // is longer than PATH_MAX.
105 // On success, returns 'outbuf', which now contains the path.
106 // On error, it will return NULL and set errno. The content of 'outbuf' is undefined.
107 // On truncation error ('outbuf' too small), it will return NULL and set errno to ENAMETOOLONG.
108 static char* realpath(const char* filename, char* outbuf, size_t outbuflen);
109
110 // Returns true if given uid is root.
111 static bool is_root(uid_t uid);
112
113 // Returns true if given uid is effective or root uid.
114 static bool matches_effective_uid_or_root(uid_t uid);
115
116 // Returns true if either given uid is effective uid and given gid is
117 // effective gid, or if given uid is root.
118 static bool matches_effective_uid_and_gid_or_root(uid_t uid, gid_t gid);
119 };
120
121 // On POSIX platforms the signal handler is global so we just do the write.
122 static void write_memory_serialize_page_with_handler(JavaThread* thread) {
123 write_memory_serialize_page(thread);
124 }
125
126 /*
127 * Crash protection for the watcher thread. Wrap the callback
128 * with a sigsetjmp and in case of a SIGSEGV/SIGBUS we siglongjmp
129 * back.
130 * To be able to use this - don't take locks, don't rely on destructors,
131 * don't make OS library calls, don't allocate memory, don't print,
132 * don't call code that could leave the heap / memory in an inconsistent state,
133 * or anything else where we are not in control if we suddenly jump out.
134 */
135 class ThreadCrashProtection : public StackObj {
136 public:
137 static bool is_crash_protected(Thread* thr) {
138 return _crash_protection != NULL && _protected_thread == thr;
|
99 // Helper function; describes pthread attributes as short string. String is written
100 // to buf with len buflen; buf is returned.
101 static char* describe_pthread_attr(char* buf, size_t buflen, const pthread_attr_t* attr);
102
103 // A safe implementation of realpath which will not cause a buffer overflow if the resolved path
104 // is longer than PATH_MAX.
105 // On success, returns 'outbuf', which now contains the path.
106 // On error, it will return NULL and set errno. The content of 'outbuf' is undefined.
107 // On truncation error ('outbuf' too small), it will return NULL and set errno to ENAMETOOLONG.
108 static char* realpath(const char* filename, char* outbuf, size_t outbuflen);
109
110 // Returns true if given uid is root.
111 static bool is_root(uid_t uid);
112
113 // Returns true if given uid is effective or root uid.
114 static bool matches_effective_uid_or_root(uid_t uid);
115
116 // Returns true if either given uid is effective uid and given gid is
117 // effective gid, or if given uid is root.
118 static bool matches_effective_uid_and_gid_or_root(uid_t uid, gid_t gid);
119
120 static void print_umask(outputStream* st, mode_t umsk);
121
122 static void print_user_info(outputStream* st);
123 };
124
125 // On POSIX platforms the signal handler is global so we just do the write.
126 static void write_memory_serialize_page_with_handler(JavaThread* thread) {
127 write_memory_serialize_page(thread);
128 }
129
130 /*
131 * Crash protection for the watcher thread. Wrap the callback
132 * with a sigsetjmp and in case of a SIGSEGV/SIGBUS we siglongjmp
133 * back.
134 * To be able to use this - don't take locks, don't rely on destructors,
135 * don't make OS library calls, don't allocate memory, don't print,
136 * don't call code that could leave the heap / memory in an inconsistent state,
137 * or anything else where we are not in control if we suddenly jump out.
138 */
139 class ThreadCrashProtection : public StackObj {
140 public:
141 static bool is_crash_protected(Thread* thr) {
142 return _crash_protection != NULL && _protected_thread == thr;
|