From dddff229c15e66de951a386a320f13b54ddbacee Mon Sep 17 00:00:00 2001
From: Kevin Bracey <kbracey@gitlab.riscosopen.org>
Date: Mon, 2 Oct 2000 10:46:57 +0000
Subject: [PATCH] * Trailing garbage no longer appears after some perror()
 calls.

* Correction to static base location in modulewrap - was affecting some
  DSL 4000 video software.

Version 5.15. Tagged as 'RISC_OSLib-5_15'
---
 VersionASM      | 14 ++++++++------
 VersionNum      | 19 ++++++++++---------
 c/string        |  8 ++++----
 h/hostsys       |  3 +++
 kernel/s/k_body | 37 +++++++++++++++++++++++++++++++++++++
 s/modulewrap    |  7 ++++---
 6 files changed, 66 insertions(+), 22 deletions(-)

diff --git a/VersionASM b/VersionASM
index 7c31a52..d9629d2 100644
--- a/VersionASM
+++ b/VersionASM
@@ -8,11 +8,13 @@
                         GBLS    Module_FullVersion
                         GBLS    Module_ApplicationDate2
                         GBLS    Module_ApplicationDate4
-Module_MajorVersion     SETS    "5.14"
-Module_Version          SETA    514
+                        GBLS    Module_HelpVersion
+Module_MajorVersion     SETS    "5.15"
+Module_Version          SETA    515
 Module_MinorVersion     SETS    ""
-Module_Date             SETS    "14 Sep 2000"
-Module_ApplicationDate2 SETS    "14-Sep-00"
-Module_ApplicationDate4 SETS    "14-Sep-2000"
-Module_FullVersion      SETS    "5.14"
+Module_Date             SETS    "02 Oct 2000"
+Module_ApplicationDate2 SETS    "02-Oct-00"
+Module_ApplicationDate4 SETS    "02-Oct-2000"
+Module_FullVersion      SETS    "5.15"
+Module_HelpVersion      SETS    "5.15 (02 Oct 2000)"
                         END
diff --git a/VersionNum b/VersionNum
index 2b958c6..aa7f895 100644
--- a/VersionNum
+++ b/VersionNum
@@ -1,18 +1,19 @@
-/* (5.14)
+/* (5.15)
  *
  * This file is automatically maintained by srccommit, do not edit manually.
  *
  */
-#define Module_MajorVersion_CMHG        5.14
+#define Module_MajorVersion_CMHG        5.15
 #define Module_MinorVersion_CMHG        
-#define Module_Date_CMHG                14 Sep 2000
+#define Module_Date_CMHG                02 Oct 2000
 
-#define Module_MajorVersion             "5.14"
-#define Module_Version                  514
+#define Module_MajorVersion             "5.15"
+#define Module_Version                  515
 #define Module_MinorVersion             ""
-#define Module_Date                     "14 Sep 2000"
+#define Module_Date                     "02 Oct 2000"
 
-#define Module_ApplicationDate2         "14-Sep-00"
-#define Module_ApplicationDate4         "14-Sep-2000"
+#define Module_ApplicationDate2         "02-Oct-00"
+#define Module_ApplicationDate4         "02-Oct-2000"
 
-#define Module_FullVersion              "5.14"
+#define Module_FullVersion              "5.15"
+#define Module_HelpVersion              "5.15 (02 Oct 2000)"
diff --git a/c/string b/c/string
index 00a05fa..7da4c21 100644
--- a/c/string
+++ b/c/string
@@ -505,13 +505,13 @@ char *_strerror(int n, char *v)
 {
     switch (n)
     {   case 0:
-            return _kernel_getmessage("No error (errno = 0)", "C35");
+            return _kernel_getmessage2("No error (errno = 0)", "C35", v, 80);
         case EDOM:
-            return _kernel_getmessage("EDOM - function argument out of range", "C36");
+            return _kernel_getmessage2("EDOM - function argument out of range", "C36", v, 80);
         case ERANGE:
-            return _kernel_getmessage("ERANGE - function result not representable", "C37");
+            return _kernel_getmessage2("ERANGE - function result not representable", "C37", v, 80);
         case ESIGNUM:
-            return _kernel_getmessage("ESIGNUM - illegal signal number to signal() or raise()", "C66");
+            return _kernel_getmessage2("ESIGNUM - illegal signal number to signal() or raise()", "C66", v, 80);
         default:
             return _hostos_error_string(n, v);
     }
diff --git a/h/hostsys b/h/hostsys
index 223550d..ccd2b73 100644
--- a/h/hostsys
+++ b/h/hostsys
@@ -321,9 +321,12 @@ extern FILE *_fopen_string_file(const char *data, int length);
 
 #ifdef DEFAULT_TEXT
 extern char *_kernel_getmessage(char *msg, char *tag);
+extern char *_kernel_getmessage2(char *msg, char *tag, char *dst, size_t len);
 #else
 extern char *_kernel_getmessage(char *tag);
+extern char *_kernel_getmessage2(char *tag, char *dst, size_t len);
 #define _kernel_getmessage(msg, tag) _kernel_getmessage(tag)
+#define _kernel_getmessage2(msg, tag, dst, len) _kernel_getmessage2(tag, dst, len)
 #endif
 extern char *decimal_point;
 
diff --git a/kernel/s/k_body b/kernel/s/k_body
index b77b58e..114b386 100644
--- a/kernel/s/k_body
+++ b/kernel/s/k_body
@@ -3058,6 +3058,7 @@ dividebyzero
 
         EXPORT  |_kernel_copyerror|
         EXPORT  |_kernel_getmessage|
+        EXPORT  |_kernel_getmessage2|
 
         [ SharedLibrary   ; Only works with module for the moment
 
@@ -3122,6 +3123,41 @@ n_module_lookupname EQU 18
         STRVC   r2, [sp]
         Return  "r0-r7,r12"
 
+; On entry:
+; [ DEFAULT_TEXT
+;   R0 = Message to use if failed to get message from message file
+;   R1 = Message tag
+;   R2 = Destination buffer
+;   R3 = Size of buffer
+; |
+;   R0 = Message tag
+;   R1 = Destination buffer
+;   R2 = Size of buffer
+; ]
+;
+; Return:
+;   R0 = Message
+;
+|_kernel_getmessage2|
+        FunctionEntry "r0-r7"
+        BL      open_messagefile
+        MOV     r0, r1
+      [ :DEF:DEFAULT_TEXT
+        LDR     r1, [sp, #4]
+      |
+        MOV     r3, r2
+        LDR     r2, [sp, #4]
+        LDR     r1, [sp]
+      ]
+        MOV     r4, #0
+        MOV     r5, #0
+        MOV     r6, #0
+        MOV     r7, #0
+        SWI     XMessageTrans_Lookup
+        STRVC   r2, [sp]
+        Return  "r0-r7"
+
+
 message_filename
         DCB     "SharedCLibrary:Messages", 0
         ALIGN
@@ -3161,6 +3197,7 @@ open_messagefile
         Return  ,LinkNotStacked
 
 |_kernel_getmessage|
+|_kernel_getmessage2|
         Return  ,LinkNotStacked
 
         ]
diff --git a/s/modulewrap b/s/modulewrap
index 1988bb3..9a7c179 100644
--- a/s/modulewrap
+++ b/s/modulewrap
@@ -425,14 +425,14 @@ ModuleWrap_Start ROUT
 
         ; Store the magic stack limit things
         LDMIA   sl, {r1, r2}
-        Push    "r1,r2,r4"
+        Push    "r1,r2,r4,sl"
 
         ; Initialise the application
         MOV     r0, #1                  ; Initialise re-entrantly
         BL      |_clib_initialisemodule|
 
         ; Restore the magic stack limit things
-        Pull    "r1,r2,r4"
+        Pull    "r1,r2,r4,sl"
         STMIA   sl, {r1,r2}
 
         ; If error rebalance stack and generate it
@@ -456,8 +456,9 @@ ModuleWrap_Start ROUT
 
         ; put a copy of the private word into the data for the
         ; app to get hold of if necessary
+        LDR     r0, [r12]               ; r0 -> workspace
         LDR     lr, module_private_word_ptr_adcon
-        LDR     r0, [sl, #-536]
+        LDR     r0, [r0, #8]            ; r0 = client static offset
         STR     r12, [lr, r0]
 
         ; call the application
-- 
GitLab