jdk

Форк
0
/
os_bsd_zero.cpp 
329 строк · 9.8 Кб
1
/*
2
 * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
3
 * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc.
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
 *
6
 * This code is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License version 2 only, as
8
 * published by the Free Software Foundation.
9
 *
10
 * This code is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
 * version 2 for more details (a copy is included in the LICENSE file that
14
 * accompanied this code).
15
 *
16
 * You should have received a copy of the GNU General Public License version
17
 * 2 along with this work; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
 *
20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
 * or visit www.oracle.com if you need additional information or have any
22
 * questions.
23
 *
24
 */
25

26
// no precompiled headers
27
#include "asm/assembler.inline.hpp"
28
#include "atomic_bsd_zero.hpp"
29
#include "classfile/vmSymbols.hpp"
30
#include "code/vtableStubs.hpp"
31
#include "interpreter/interpreter.hpp"
32
#include "jvm.h"
33
#include "memory/allocation.inline.hpp"
34
#include "nativeInst_zero.hpp"
35
#include "os_bsd.hpp"
36
#include "os_posix.hpp"
37
#include "prims/jniFastGetField.hpp"
38
#include "prims/jvm_misc.hpp"
39
#include "runtime/arguments.hpp"
40
#include "runtime/frame.inline.hpp"
41
#include "runtime/interfaceSupport.inline.hpp"
42
#include "runtime/java.hpp"
43
#include "runtime/javaCalls.hpp"
44
#include "runtime/javaThread.hpp"
45
#include "runtime/mutexLocker.hpp"
46
#include "runtime/osThread.hpp"
47
#include "runtime/sharedRuntime.hpp"
48
#include "runtime/stubRoutines.hpp"
49
#include "runtime/timer.hpp"
50
#include "signals_posix.hpp"
51
#include "utilities/events.hpp"
52
#include "utilities/vmError.hpp"
53

54
#if !defined(__APPLE__) && !defined(__NetBSD__)
55
#include <pthread.h>
56
# include <pthread_np.h> /* For pthread_attr_get_np */
57
#endif
58

59
address os::current_stack_pointer() {
60
  address dummy = (address) &dummy;
61
  return dummy;
62
}
63

64
frame os::get_sender_for_C_frame(frame* fr) {
65
  ShouldNotCallThis();
66
  return frame();
67
}
68

69
frame os::current_frame() {
70
  // The only thing that calls this is the stack printing code in
71
  // VMError::report:
72
  //   - Step 110 (printing stack bounds) uses the sp in the frame
73
  //     to determine the amount of free space on the stack.  We
74
  //     set the sp to a close approximation of the real value in
75
  //     order to allow this step to complete.
76
  //   - Step 120 (printing native stack) tries to walk the stack.
77
  //     The frame we create has a null pc, which is ignored as an
78
  //     invalid frame.
79
  frame dummy = frame();
80
  dummy.set_sp((intptr_t *) current_stack_pointer());
81
  return dummy;
82
}
83

84
char* os::non_memory_address_word() {
85
  // Must never look like an address returned by reserve_memory,
86
  // even in its subfields (as defined by the CPU immediate fields,
87
  // if the CPU splits constants across multiple instructions).
88
  // This is the value for x86; works pretty well for PPC too.
89
  return (char *) -1;
90
}
91

92
address os::Posix::ucontext_get_pc(const ucontext_t* uc) {
93
  ShouldNotCallThis();
94
  return nullptr;
95
}
96

97
void os::Posix::ucontext_set_pc(ucontext_t * uc, address pc) {
98
  ShouldNotCallThis();
99
}
100

101
address os::fetch_frame_from_context(const void* ucVoid,
102
                                     intptr_t** ret_sp,
103
                                     intptr_t** ret_fp) {
104
  ShouldNotCallThis();
105
  return nullptr;
106
}
107

108
frame os::fetch_frame_from_context(const void* ucVoid) {
109
  ShouldNotCallThis();
110
  return frame();
111
}
112

113
bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,
114
                                             ucontext_t* uc, JavaThread* thread) {
115

116
  if (info != nullptr && thread != nullptr) {
117
    // Handle ALL stack overflow variations here
118
    if (sig == SIGSEGV || sig == SIGBUS) {
119
      address addr = (address) info->si_addr;
120

121
      // check if fault address is within thread stack
122
      if (thread->is_in_full_stack(addr)) {
123
        StackOverflow* overflow_state = thread->stack_overflow_state();
124
        // stack overflow
125
        if (overflow_state->in_stack_yellow_reserved_zone(addr)) {
126
          overflow_state->disable_stack_yellow_reserved_zone();
127
          ShouldNotCallThis();
128
        }
129
        else if (overflow_state->in_stack_red_zone(addr)) {
130
          overflow_state->disable_stack_red_zone();
131
          ShouldNotCallThis();
132
        }
133
      }
134
    }
135

136
    /*if (thread->thread_state() == _thread_in_Java) {
137
      ShouldNotCallThis();
138
    }
139
    else*/ if ((thread->thread_state() == _thread_in_vm ||
140
               thread->thread_state() == _thread_in_native) &&
141
               sig == SIGBUS && thread->doing_unsafe_access()) {
142
      ShouldNotCallThis();
143
    }
144

145
    // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC
146
    // kicks in and the heap gets shrunk before the field access.
147
    /*if (sig == SIGSEGV || sig == SIGBUS) {
148
      address addr = JNI_FastGetField::find_slowcase_pc(pc);
149
      if (addr != (address)-1) {
150
        stub = addr;
151
      }
152
    }*/
153
  }
154

155
  return false;
156
}
157

158
void os::Bsd::init_thread_fpu_state(void) {
159
  // Nothing to do
160
}
161

162
///////////////////////////////////////////////////////////////////////////////
163
// thread stack
164

165
size_t os::_compiler_thread_min_stack_allowed = 64 * K;
166
size_t os::_java_thread_min_stack_allowed = 64 * K;
167
size_t os::_vm_internal_thread_min_stack_allowed = 64 * K;
168

169
size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
170
#ifdef _LP64
171
  size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
172
#else
173
  size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
174
#endif // _LP64
175
  return s;
176
}
177

178
void os::current_stack_base_and_size(address* base, size_t* size) {
179
  address bottom;
180

181
#ifdef __APPLE__
182
  pthread_t self = pthread_self();
183
  *base = (address) pthread_get_stackaddr_np(self);
184
  *size = pthread_get_stacksize_np(self);
185
  bottom = *base - *size;
186
#elif defined(__OpenBSD__)
187
  stack_t ss;
188
  int rslt = pthread_stackseg_np(pthread_self(), &ss);
189

190
  if (rslt != 0)
191
    fatal("pthread_stackseg_np failed with error = %d", rslt);
192

193
  *base = (address) ss.ss_sp;
194
  *size  = ss.ss_size;
195
  bottom = *base - *size;
196
#else
197
  pthread_attr_t attr;
198

199
  int rslt = pthread_attr_init(&attr);
200

201
  // JVM needs to know exact stack location, abort if it fails
202
  if (rslt != 0)
203
    fatal("pthread_attr_init failed with error = %d", rslt);
204

205
  rslt = pthread_attr_get_np(pthread_self(), &attr);
206

207
  if (rslt != 0)
208
    fatal("pthread_attr_get_np failed with error = %d", rslt);
209

210
  if (pthread_attr_getstackaddr(&attr, (void **) &bottom) != 0 ||
211
      pthread_attr_getstacksize(&attr, size) != 0) {
212
    fatal("Can not locate current stack attributes!");
213
  }
214

215
  *base = bottom + *size;
216

217
  pthread_attr_destroy(&attr);
218

219
#endif
220
  assert(os::current_stack_pointer() >= bottom &&
221
         os::current_stack_pointer() < *base, "just checking");
222
}
223

224
/////////////////////////////////////////////////////////////////////////////
225
// helper functions for fatal error handler
226

227
void os::print_context(outputStream* st, const void* context) {
228
  ShouldNotCallThis();
229
}
230

231
void os::print_tos_pc(outputStream *st, const void *context) {
232
  ShouldNotCallThis();
233
}
234

235
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
236
  ShouldNotCallThis();
237
}
238

239
/////////////////////////////////////////////////////////////////////////////
240
// Stubs for things that would be in bsd_zero.s if it existed.
241
// You probably want to disassemble these monkeys to check they're ok.
242

243
extern "C" {
244
  int SpinPause() {
245
    return 1;
246
  }
247

248
  void _Copy_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) {
249
    if (from > to) {
250
      const jshort *end = from + count;
251
      while (from < end)
252
        *(to++) = *(from++);
253
    }
254
    else if (from < to) {
255
      const jshort *end = from;
256
      from += count - 1;
257
      to   += count - 1;
258
      while (from >= end)
259
        *(to--) = *(from--);
260
    }
261
  }
262
  void _Copy_conjoint_jints_atomic(const jint* from, jint* to, size_t count) {
263
    if (from > to) {
264
      const jint *end = from + count;
265
      while (from < end)
266
        *(to++) = *(from++);
267
    }
268
    else if (from < to) {
269
      const jint *end = from;
270
      from += count - 1;
271
      to   += count - 1;
272
      while (from >= end)
273
        *(to--) = *(from--);
274
    }
275
  }
276
  void _Copy_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) {
277
    if (from > to) {
278
      const jlong *end = from + count;
279
      while (from < end)
280
        atomic_copy64(from++, to++);
281
    }
282
    else if (from < to) {
283
      const jlong *end = from;
284
      from += count - 1;
285
      to   += count - 1;
286
      while (from >= end)
287
        atomic_copy64(from--, to--);
288
    }
289
  }
290

291
  void _Copy_arrayof_conjoint_bytes(const HeapWord* from,
292
                                    HeapWord* to,
293
                                    size_t    count) {
294
    memmove(to, from, count);
295
  }
296
  void _Copy_arrayof_conjoint_jshorts(const HeapWord* from,
297
                                      HeapWord* to,
298
                                      size_t    count) {
299
    memmove(to, from, count * 2);
300
  }
301
  void _Copy_arrayof_conjoint_jints(const HeapWord* from,
302
                                    HeapWord* to,
303
                                    size_t    count) {
304
    memmove(to, from, count * 4);
305
  }
306
  void _Copy_arrayof_conjoint_jlongs(const HeapWord* from,
307
                                     HeapWord* to,
308
                                     size_t    count) {
309
    memmove(to, from, count * 8);
310
  }
311
};
312

313
#ifndef PRODUCT
314
void os::verify_stack_alignment() {
315
}
316
#endif
317

318
int os::extra_bang_size_in_bytes() {
319
  // Zero does not require an additional stack bang.
320
  return 0;
321
}
322

323
#if defined(AARCH64) && defined(__APPLE__)
324
void os::current_thread_enable_wx(WXMode mode) {
325
  pthread_jit_write_protect_np(mode == WXExec);
326
}
327
#endif
328

329
void os::setup_fpu() {}
330

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.