File 0996-fix-hmax-command-line-argument-to-accept-4-Gb.patch of Package erlang

From 3bb8edb1fa476f5e9919461df0adc3f22bf2dac8 Mon Sep 17 00:00:00 2001
From: Maxim Fedorov <maximfca@gmail.com>
Date: Sun, 12 Jun 2022 11:14:57 -0700
Subject: [PATCH] fix +hmax command line argument to accept > 4 Gb

It is possible to set the maximum heap size for the process
using process_flag(max_heap_size, #{size => (1 bsl 59) -1}).
However command line parameter +hmax would not work with anything
beyond 4 Gb (536870911 words) due to signed int32 used to parse
the command line.
---
 erts/doc/src/erl_cmd.xml             |  2 +-
 erts/emulator/beam/erl_init.c        |  8 ++++++--
 erts/emulator/beam/erl_vm.h          |  2 +-
 erts/emulator/test/process_SUITE.erl | 14 ++++++++++++++
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/erts/doc/src/erl_cmd.xml b/erts/doc/src/erl_cmd.xml
index b8d36937ca..8f63d73b08 100644
--- a/erts/doc/src/erl_cmd.xml
+++ b/erts/doc/src/erl_cmd.xml
@@ -933,7 +933,7 @@ $ <input>erl \
       <tag><marker id="+hmax"/><c><![CDATA[+hmax Size]]></c></tag>
       <item>
         <p>Sets the default maximum heap size of processes to the size
-          <c><![CDATA[Size]]></c>. Defaults to <c>0</c>, which means that no
+          <c><![CDATA[Size]]></c> words. Defaults to <c>0</c>, which means that no
           maximum heap size is used. For more information, see
           <seeerl marker="erlang#process_flag_max_heap_size">
           <c>process_flag(max_heap_size, MaxHeapSize)</c></seeerl>.</p>
diff --git a/erts/emulator/beam/erl_init.c b/erts/emulator/beam/erl_init.c
index 872fa6b613..b2c7db1db1 100644
--- a/erts/emulator/beam/erl_init.c
+++ b/erts/emulator/beam/erl_init.c
@@ -162,7 +162,7 @@ int erts_initialized = 0;
 
 int H_MIN_SIZE;			/* The minimum heap grain */
 int BIN_VH_MIN_SIZE;		/* The minimum binary virtual*/
-int H_MAX_SIZE;			/* The maximum heap size */
+Uint H_MAX_SIZE;		/* The maximum heap size */
 int H_MAX_FLAGS;		/* The maximum heap flags */
 
 Uint32 erts_debug_flags;	/* Debug flags. */
@@ -1624,8 +1624,11 @@ erl_start(int argc, char **argv)
 		}
 		VERBOSE(DEBUG_SYSTEM, ("using max heap log %d\n", H_MAX_FLAGS));
 	    } else if (has_prefix("max", sub_param)) {
+                Sint hMaxSize;
+                char *rest;
 		arg = get_arg(sub_param+3, argv[i+1], &i);
-		if ((H_MAX_SIZE = atoi(arg)) < 0) {
+		hMaxSize = ErtsStrToSint(arg, &rest, 10);
+		if (hMaxSize < 0 || hMaxSize > MAX_SMALL) {
 		    erts_fprintf(stderr, "bad max heap size %s\n", arg);
 		    erts_usage();
 		}
@@ -1635,6 +1638,7 @@ erl_start(int argc, char **argv)
                                  arg, H_MIN_SIZE);
 		    erts_usage();
 		}
+		H_MAX_SIZE = hMaxSize;
 		VERBOSE(DEBUG_SYSTEM, ("using max heap size %d\n", H_MAX_SIZE));
 	    } else {
 	        /* backward compatibility */
diff --git a/erts/emulator/beam/erl_vm.h b/erts/emulator/beam/erl_vm.h
index cc5ba299d3..1eaea576fd 100644
--- a/erts/emulator/beam/erl_vm.h
+++ b/erts/emulator/beam/erl_vm.h
@@ -254,7 +254,7 @@ extern Uint erts_instr_count[];
 
 extern int H_MIN_SIZE;		/* minimum (heap + stack) */
 extern int BIN_VH_MIN_SIZE;	/* minimum virtual (bin) heap */
-extern int H_MAX_SIZE;          /* maximum (heap + stack) */
+extern Uint H_MAX_SIZE;          /* maximum (heap + stack) */
 extern int H_MAX_FLAGS;         /* maximum heap flags  */
 
 extern int erts_atom_table_size;/* Atom table size */
-- 
2.35.3

openSUSE Build Service is sponsored by