Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into Ractor-Local-GC-v…
Browse files Browse the repository at this point in the history
…ersion-1
  • Loading branch information
rm155 committed Sep 6, 2023
2 parents 21af1bf + acd626a commit b58276d
Show file tree
Hide file tree
Showing 316 changed files with 4,883 additions and 2,828 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The following default gems are updated.
* erb 4.0.3
* fiddle 1.1.2
* fileutils 1.7.1
* irb 1.8.0
* irb 1.8.1
* nkf 0.1.3
* optparse 0.4.0.pre.1
* psych 5.1.0
Expand All @@ -96,7 +96,7 @@ The following default gems are updated.
* time 0.2.2
* timeout 0.4.0
* uri 0.12.2
* yarp 0.9.0
* yarp 0.10.0

The following bundled gems are updated.

Expand Down
11 changes: 8 additions & 3 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -2178,9 +2178,14 @@ rb_ary_splice(VALUE ary, long beg, long len, const VALUE *rptr, long rlen)
ARY_SET_LEN(ary, alen);
}
if (rlen > 0) {
if (rofs != -1) rptr = RARRAY_CONST_PTR(ary) + rofs;
/* give up wb-protected ary */
RB_OBJ_WB_UNPROTECT_FOR(ARRAY, ary);
if (rofs == -1) {
rb_gc_writebarrier_remember(ary);
}
else {
/* In this case, we're copying from a region in this array, so
* we don't need to fire the write barrier. */
rptr = RARRAY_CONST_PTR(ary) + rofs;
}

/* do not use RARRAY_PTR() because it can causes GC.
* ary can contain T_NONE object because it is not cleared.
Expand Down
53 changes: 36 additions & 17 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,32 @@ new_adjust_body(rb_iseq_t *iseq, LABEL *label, int line)
return adjust;
}

static void
iseq_insn_each_markable_object(INSN *insn, void (*func)(VALUE *, VALUE), VALUE data)
{
const char *types = insn_op_types(insn->insn_id);
for (int j = 0; types[j]; j++) {
char type = types[j];
switch (type) {
case TS_CDHASH:
case TS_ISEQ:
case TS_VALUE:
case TS_IC: // constant path array
case TS_CALLDATA: // ci is stored.
func(&OPERAND_AT(insn, j), data);
break;
default:
break;
}
}
}

static void
iseq_insn_each_object_write_barrier(VALUE *obj_ptr, VALUE iseq)
{
RB_OBJ_WRITTEN(iseq, Qundef, *obj_ptr);
}

static INSN *
new_insn_core(rb_iseq_t *iseq, const NODE *line_node,
int insn_id, int argc, VALUE *argv)
Expand All @@ -1300,6 +1326,9 @@ new_insn_core(rb_iseq_t *iseq, const NODE *line_node,
iobj->operands = argv;
iobj->operand_size = argc;
iobj->sc_state = 0;

iseq_insn_each_markable_object(iobj, iseq_insn_each_object_write_barrier, (VALUE)iseq);

return iobj;
}

Expand Down Expand Up @@ -10741,6 +10770,12 @@ iseq_build_kw(rb_iseq_t *iseq, VALUE params, VALUE keywords)
return keyword;
}

static void
iseq_insn_each_object_mark_and_move(VALUE *obj_ptr, VALUE _)
{
rb_gc_mark_and_move(obj_ptr);
}

void
rb_iseq_mark_and_move_insn_storage(struct iseq_compile_data_storage *storage)
{
Expand All @@ -10767,23 +10802,7 @@ rb_iseq_mark_and_move_insn_storage(struct iseq_compile_data_storage *storage)
iobj = (INSN *)&storage->buff[pos];

if (iobj->operands) {
int j;
const char *types = insn_op_types(iobj->insn_id);

for (j = 0; types[j]; j++) {
char type = types[j];
switch (type) {
case TS_CDHASH:
case TS_ISEQ:
case TS_VALUE:
case TS_IC: // constant path array
case TS_CALLDATA: // ci is stored.
rb_gc_mark_and_move(&OPERAND_AT(iobj, j));
break;
default:
break;
}
}
iseq_insn_each_markable_object(iobj, iseq_insn_each_object_mark_and_move, (VALUE)0);
}
pos += (int)size;
}
Expand Down
5 changes: 4 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ AS_CASE(["$GCC:${warnflags+set}:${extra_warnflags:+set}:"],
AS_IF([test $gcc_major -le 6], [
extra_warnflags="$extra_warnflags -Wno-maybe-uninitialized"
])
AS_CASE([ $CFLAGS ], [*" -save-temps="*|*" -save-temps "*], [], [
extra_warnflags="$extra_warnflags -Werror=misleading-indentation"
])
# ICC doesn't support -Werror=
AS_IF([test $icc_version -gt 0], [
particular_werror_flags=no
Expand All @@ -693,7 +697,6 @@ AS_CASE(["$GCC:${warnflags+set}:${extra_warnflags:+set}:"],
-Werror=duplicated-cond \
-Werror=implicit-function-declaration \
-Werror=implicit-int \
-Werror=misleading-indentation \
-Werror=pointer-arith \
-Werror=shorten-64-to-32 \
-Werror=write-strings \
Expand Down
7 changes: 0 additions & 7 deletions ext/openssl/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@

Logging::message "=== OpenSSL for Ruby configurator ===\n"

##
# Adds -DOSSL_DEBUG for compilation and some more targets when GCC is used
# To turn it on, use: --with-debug or --enable-debug
#
if with_config("debug") or enable_config("debug")
$defs.push("-DOSSL_DEBUG")
end
$defs.push("-D""OPENSSL_SUPPRESS_DEPRECATED")

have_func("rb_io_descriptor")
Expand Down
7 changes: 2 additions & 5 deletions ext/openssl/lib/openssl/buffering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def consume_rbuff(size=nil)
nil
else
size = @rbuffer.size unless size
ret = @rbuffer[0, size]
@rbuffer[0, size] = ""
ret
@rbuffer.slice!(0, size)
end
end

Expand All @@ -106,8 +104,7 @@ def consume_rbuff(size=nil)
#
# Get the next 8bit byte from `ssl`. Returns `nil` on EOF
def getbyte
byte = read(1)
byte && byte.unpack1("C")
read(1)&.ord
end

##
Expand Down
20 changes: 10 additions & 10 deletions ext/openssl/lib/openssl/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ class SSLContext
}

if defined?(OpenSSL::PKey::DH)
DEFAULT_2048 = OpenSSL::PKey::DH.new <<-_end_of_pem_
DH_ffdhe2048 = OpenSSL::PKey::DH.new <<-_end_of_pem_
-----BEGIN DH PARAMETERS-----
MIIBCAKCAQEA7E6kBrYiyvmKAMzQ7i8WvwVk9Y/+f8S7sCTN712KkK3cqd1jhJDY
JbrYeNV3kUIKhPxWHhObHKpD1R84UpL+s2b55+iMd6GmL7OYmNIT/FccKhTcveab
VBmZT86BZKYyf45hUF9FOuUM9xPzuK3Vd8oJQvfYMCd7LPC0taAEljQLR4Edf8E6
YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3
1bNveX5wInh5GDx1FGhKBZ+s1H+aedudCm7sCgRwv8lKWYGiHzObSma8A86KG+MD
7Lo5JquQ3DlBodj3IDyPrxIv96lvRPFtAwIBAg==
MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz
+8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a
87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7
YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi
7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD
ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
-----END DH PARAMETERS-----
_end_of_pem_
private_constant :DEFAULT_2048
private_constant :DH_ffdhe2048

DEFAULT_TMP_DH_CALLBACK = lambda { |ctx, is_export, keylen| # :nodoc:
warn "using default DH parameters." if $VERBOSE
DEFAULT_2048
DH_ffdhe2048
}
end

Expand Down Expand Up @@ -494,7 +494,7 @@ def initialize(svr, ctx)
unless ctx.session_id_context
# see #6137 - session id may not exceed 32 bytes
prng = ::Random.new($0.hash)
session_id = prng.bytes(16).unpack('H*')[0]
session_id = prng.bytes(16).unpack1('H*')
@ctx.session_id_context = session_id
end
@start_immediately = true
Expand Down
105 changes: 0 additions & 105 deletions ext/openssl/ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,75 +463,6 @@ ossl_fips_mode_set(VALUE self, VALUE enabled)
#endif
}

#if defined(OSSL_DEBUG)
#if !defined(LIBRESSL_VERSION_NUMBER) && \
(OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_NO_CRYPTO_MDEBUG) || \
defined(CRYPTO_malloc_debug_init))
/*
* call-seq:
* OpenSSL.mem_check_start -> nil
*
* Calls CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON). Starts tracking memory
* allocations. See also OpenSSL.print_mem_leaks.
*
* This is available only when built with a capable OpenSSL and --enable-debug
* configure option.
*/
static VALUE
mem_check_start(VALUE self)
{
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
return Qnil;
}

/*
* call-seq:
* OpenSSL.print_mem_leaks -> true | false
*
* For debugging the Ruby/OpenSSL library. Calls CRYPTO_mem_leaks_fp(stderr).
* Prints detected memory leaks to standard error. This cleans the global state
* up thus you cannot use any methods of the library after calling this.
*
* Returns +true+ if leaks detected, +false+ otherwise.
*
* This is available only when built with a capable OpenSSL and --enable-debug
* configure option.
*
* === Example
* OpenSSL.mem_check_start
* NOT_GCED = OpenSSL::PKey::RSA.new(256)
*
* END {
* GC.start
* OpenSSL.print_mem_leaks # will print the leakage
* }
*/
static VALUE
print_mem_leaks(VALUE self)
{
#if OPENSSL_VERSION_NUMBER >= 0x10100000
int ret;
#endif

#ifndef HAVE_RB_EXT_RACTOR_SAFE
// for Ruby 2.x
void ossl_bn_ctx_free(void); // ossl_bn.c
ossl_bn_ctx_free();
#endif

#if OPENSSL_VERSION_NUMBER >= 0x10100000
ret = CRYPTO_mem_leaks_fp(stderr);
if (ret < 0)
ossl_raise(eOSSLError, "CRYPTO_mem_leaks_fp");
return ret ? Qfalse : Qtrue;
#else
CRYPTO_mem_leaks_fp(stderr);
return Qnil;
#endif
}
#endif
#endif

#if !defined(HAVE_OPENSSL_110_THREADING_API)
/**
* Stores locks needed for OpenSSL thread safety
Expand Down Expand Up @@ -1239,40 +1170,4 @@ Init_openssl(void)
Init_ossl_provider();
Init_ossl_asn1();
Init_ossl_kdf();

#if defined(OSSL_DEBUG)
/*
* For debugging Ruby/OpenSSL. Enable only when built with --enable-debug
*/
#if !defined(LIBRESSL_VERSION_NUMBER) && \
(OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_NO_CRYPTO_MDEBUG) || \
defined(CRYPTO_malloc_debug_init))
rb_define_module_function(mOSSL, "mem_check_start", mem_check_start, 0);
rb_define_module_function(mOSSL, "print_mem_leaks", print_mem_leaks, 0);

#if defined(CRYPTO_malloc_debug_init) /* <= 1.0.2 */
CRYPTO_malloc_debug_init();
#endif

#if defined(V_CRYPTO_MDEBUG_ALL) /* <= 1.0.2 */
CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
#endif

#if OPENSSL_VERSION_NUMBER < 0x10100000 /* <= 1.0.2 */
{
int i;
/*
* See crypto/ex_data.c; call def_get_class() immediately to avoid
* allocations. 15 is the maximum number that is used as the class index
* in OpenSSL 1.0.2.
*/
for (i = 0; i <= 15; i++) {
if (CRYPTO_get_ex_new_index(i, 0, (void *)"ossl-mdebug-dummy", 0, 0, 0) < 0)
rb_raise(rb_eRuntimeError, "CRYPTO_get_ex_new_index for "
"class index %d failed", i);
}
}
#endif
#endif
#endif
}
2 changes: 1 addition & 1 deletion ext/openssl/ossl_ocsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ Init_ossl_ocsp(void)
* require 'net/http'
*
* http_response =
* Net::HTTP.start ocsp_uri.hostname, ocsp.port do |http|
* Net::HTTP.start ocsp_uri.hostname, ocsp_uri.port do |http|
* http.post ocsp_uri.path, request.to_der,
* 'content-type' => 'application/ocsp-request'
* end
Expand Down
16 changes: 11 additions & 5 deletions ext/openssl/ossl_x509ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,16 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
int nid;
VALUE rconf;
CONF *conf;
const char *oid_cstr = NULL;

rb_scan_args(argc, argv, "21", &oid, &value, &critical);
StringValueCStr(oid);
StringValue(value);
if(NIL_P(critical)) critical = Qfalse;

nid = OBJ_ln2nid(RSTRING_PTR(oid));
if(!nid) nid = OBJ_sn2nid(RSTRING_PTR(oid));
if(!nid) ossl_raise(eX509ExtError, "unknown OID `%"PRIsVALUE"'", oid);
oid_cstr = StringValueCStr(oid);
nid = OBJ_ln2nid(oid_cstr);
if (nid != NID_undef)
oid_cstr = OBJ_nid2sn(nid);

valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
rb_str_append(valstr, value);
Expand All @@ -228,7 +229,12 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
rconf = rb_iv_get(self, "@config");
conf = NIL_P(rconf) ? NULL : GetConfig(rconf);
X509V3_set_nconf(ctx, conf);
ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr));

#if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_IS_LIBRESSL
ext = X509V3_EXT_nconf(conf, ctx, oid_cstr, RSTRING_PTR(valstr));
#else
ext = X509V3_EXT_nconf(conf, ctx, (char *)oid_cstr, RSTRING_PTR(valstr));
#endif
X509V3_set_ctx_nodb(ctx);
if (!ext){
ossl_raise(eX509ExtError, "%"PRIsVALUE" = %"PRIsVALUE, oid, valstr);
Expand Down
Loading

0 comments on commit b58276d

Please sign in to comment.