jdk
1/*
2* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*
5* This code is free software; you can redistribute it and/or modify it
6* under the terms of the GNU General Public License version 2 only, as
7* published by the Free Software Foundation.
8*
9* This code is distributed in the hope that it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12* version 2 for more details (a copy is included in the LICENSE file that
13* accompanied this code).
14*
15* You should have received a copy of the GNU General Public License version
16* 2 along with this work; if not, write to the Free Software Foundation,
17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18*
19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20* or visit www.oracle.com if you need additional information or have any
21* questions.
22*/
23
24#include "precompiled.hpp"25#include "downcallLinker.hpp"26#include "gc/shared/gcLocker.inline.hpp"27#include "runtime/interfaceSupport.inline.hpp"28
29#include <cerrno>30#ifdef _WIN6431#include <Windows.h>32#include <Winsock2.h>33#endif34
35// We call this from _thread_in_native, right after a downcall
36JVM_LEAF(void, DowncallLinker::capture_state(int32_t* value_ptr, int captured_state_mask))37// keep in synch with jdk.internal.foreign.abi.PreservableValues38enum PreservableValues {39NONE = 0,40GET_LAST_ERROR = 1,41WSA_GET_LAST_ERROR = 1 << 1,42ERRNO = 1 << 243};44#ifdef _WIN6445if (captured_state_mask & GET_LAST_ERROR) {46*value_ptr = GetLastError();47}48value_ptr++;49if (captured_state_mask & WSA_GET_LAST_ERROR) {50*value_ptr = WSAGetLastError();51}52value_ptr++;53#endif54if (captured_state_mask & ERRNO) {55*value_ptr = errno;56}57JVM_END
58
59void DowncallLinker::StubGenerator::add_offsets_to_oops(GrowableArray<VMStorage>& java_regs, VMStorage tmp1, VMStorage tmp2) const {60int reg_idx = 0;61for (int sig_idx = 0; sig_idx < _num_args; sig_idx++) {62if (_signature[sig_idx] == T_OBJECT) {63assert(_signature[sig_idx + 1] == T_LONG, "expected offset after oop");64VMStorage reg_oop = java_regs.at(reg_idx++);65VMStorage reg_offset = java_regs.at(reg_idx++);66sig_idx++; // skip offset67pd_add_offset_to_oop(reg_oop, reg_offset, tmp1, tmp2);68} else if (_signature[sig_idx] != T_VOID) {69reg_idx++;70}71}72}
73