Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Computers are useless. They can only give you answers. -- Pablo Picasso


computers / comp.os.vms / Re: New PHP kits available (and a programming question)

Re: New PHP kits available (and a programming question)

<u8pbgr$3n0gb$1@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=28791&group=comp.os.vms#28791

  copy link   Newsgroups: comp.os.vms
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mar...@theberrymans.com (Mark Berryman)
Newsgroups: comp.os.vms
Subject: Re: New PHP kits available (and a programming question)
Date: Thu, 13 Jul 2023 11:16:10 -0600
Organization: A noiseless patient Spider
Lines: 328
Message-ID: <u8pbgr$3n0gb$1@dont-email.me>
References: <u8hg8b$2jcj5$1@dont-email.me>
<f9cdf39e-565e-40c2-b21c-9b89ada24cadn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 13 Jul 2023 17:16:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e10be56800b192cd0b644f6bc473d68c";
logging-data="3899915"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dhGCdx9Exn0Hp7X28cnea6aiUlBy9m+0="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.13.0
Cancel-Lock: sha1:KAouytIwQzTgezj8AnzI0iWIjrU=
In-Reply-To: <f9cdf39e-565e-40c2-b21c-9b89ada24cadn@googlegroups.com>
Content-Language: en-US
 by: Mark Berryman - Thu, 13 Jul 2023 17:16 UTC

On 7/10/23 2:20 PM, John Reagan wrote:
> On Monday, July 10, 2023 at 1:47:58 PM UTC-4, Mark Berryman wrote:
>> .
>> .
>> .
>> While I'm waiting for the answers, if anyone knows how I can
>> save/restore execution context and jump to a saved PC location, I would
>> appreciate any hints. I had hoped to use the various *INVO* functions
>> for this but, while I have found routines that will save the current
>> context, I haven't found any that will load the contents of an INVO
>> block back into the registers.
>>
>> Also, what languages have access to all of the registers?
>>
>> Mark Berryman
> Look at SYS$GOTO_UNWIND_64. It should be able to put all the registers back and jump to a PC.
>
> The trick is "which PC". Pascal uses it for non-local GOTOs and C uses it for setjmp()/longjmp().
> It takes an invo-handle and a target-PC. The target-PC needs to be a routine or a label that the
> optimizer treats special (not to optimize things across it).
>
> For C, setjmp() saves a bunch of stuff from the ICB, longjmp() actually uses a special
> routine inside the CRTL as the target for the SYS$GOTO_UNWIND_64 call. It gets passed
> the jmp-buf which has the actual destination back in setjmp(). It restores some registers
> and does an indirect jmp back to the saved pc inside the jmp-buf.

It looks like SYS$GOTO_UNWIND_64 will do the trick. Sadly, I have to
admit that I got lost trying to understand what the boost code does vs.
what VMS wants (especially in regards to register usage). I am asking
for help in this regard.

There are two functions involved here. They are defined as follows:

extern void *make_fcontext(void *sp, size_t size, void
(*fn)(boost_context_data));

extern ZEND_INDIRECT_RETURN boost_context_data jump_fcontext(void *to,
zend_fiber_transfer *transfer);

typedef struct {
void *handle;
zend_fiber_transfer *transfer;
} boost_context_data;

typedef struct _zend_fiber_transfer {
/* Fiber that will be switched to / has resumed us. */
zend_fiber_context *context;

/* Value to that should be send to (or was received from) a
fiber. */
zval value;

/* Bitmask of flags defined in enum zend_fiber_transfer_flag. */
uint8_t flags;
} zend_fiber_transfer;

struct _zend_fiber_context {
/* Pointer to boost.context or ucontext_t data. */
void *handle;

/* Pointer that identifies the fiber type. */
void *kind;

/* Entrypoint function of the fiber. */
zend_fiber_coroutine function;

/* Assigned C stack. */
zend_fiber_stack *stack;

/* Fiber status. */
zend_fiber_status status;

/* Reserved for extensions */
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
};

typedef struct _zend_fiber_context zend_fiber_context;

And these are the two routines.

-----------------------------------------------------------
/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/

/****************************************************************************************
*
*
*
----------------------------------------------------------------------------------
*
* | 0 | 1 | 2 | 3 | 4 | 5 | 6
| 7 | *
*
----------------------------------------------------------------------------------
*
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 |
0x18 | 0x1c | *
*
----------------------------------------------------------------------------------
*
* | fc_mxcsr|fc_x87_cw| R12 | R13 |
R14 | *
*
----------------------------------------------------------------------------------
*
*
----------------------------------------------------------------------------------
*
* | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | *
*
----------------------------------------------------------------------------------
*
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 |
0x38 | 0x3c | *
*
----------------------------------------------------------------------------------
*
* | R15 | RBX | RBP |
RIP | *
*
----------------------------------------------------------------------------------
*
*
*
****************************************************************************************/

# if defined __CET__
# include <cet.h>
# else
# define _CET_ENDBR
# endif
..file "make_x86_64_sysv_elf_gas.S"
..text
..globl make_fcontext
..type make_fcontext,@function
..align 16
make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movq %rdi, %rax

/* shift address in RAX to lower 16 byte boundary */
andq $-16, %rax

/* reserve space for context-data on context-stack */
/* on context-function entry: (RSP -0x8) % 16 == 0 */
leaq -0x40(%rax), %rax

/* third arg of make_fcontext() == address of context-function */
/* stored in RBX */
movq %rdx, 0x28(%rax)

/* save MMX control- and status-word */
stmxcsr (%rax)
/* save x87 control-word */
fnstcw 0x4(%rax)

/* compute abs address of label trampoline */
leaq trampoline(%rip), %rcx
/* save address of trampoline as return-address for context-function */
/* will be entered after calling jump_fcontext() first time */
movq %rcx, 0x38(%rax)

/* compute abs address of label finish */
leaq finish(%rip), %rcx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movq %rcx, 0x30(%rax)

ret /* return pointer to context-data */

trampoline:
/* store return address on stack */
/* fix stack alignment */
push %rbp
/* jump to context-function */
jmp *%rbx

finish:
/* exit code is zero */
xorq %rdi, %rdi
/* exit application */
/* call _exit@PLT */
hlt
..size make_fcontext,.-make_fcontext

/* Mark that we don't need executable stack. */
..section .note.GNU-stack,"",%progbits

------------------------------------------------------------

/*
Copyright Oliver Kowalke 2009.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/

/****************************************************************************************
*
*
*
----------------------------------------------------------------------------------
*
* | 0 | 1 | 2 | 3 | 4 | 5 | 6
| 7 | *
*
----------------------------------------------------------------------------------
*
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 |
0x18 | 0x1c | *
*
----------------------------------------------------------------------------------
*
* | fc_mxcsr|fc_x87_cw| R12 | R13 |
R14 | *
*
----------------------------------------------------------------------------------
*
*
----------------------------------------------------------------------------------
*
* | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | *
*
----------------------------------------------------------------------------------
*
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 |
0x38 | 0x3c | *
*
----------------------------------------------------------------------------------
*
* | R15 | RBX | RBP |
RIP | *
*
----------------------------------------------------------------------------------
*
*
*
****************************************************************************************/

# if defined __CET__
# include <cet.h>
# else
# define _CET_ENDBR
# endif
..file "jump_x86_64_sysv_elf_gas.S"
..text
..globl jump_fcontext
..type jump_fcontext,@function
..align 16
jump_fcontext:
leaq -0x38(%rsp), %rsp /* prepare stack */

#if !defined(BOOST_USE_TSX)
stmxcsr (%rsp) /* save MMX control- and status-word */
fnstcw 0x4(%rsp) /* save x87 control-word */
#endif

movq %r12, 0x8(%rsp) /* save R12 */
movq %r13, 0x10(%rsp) /* save R13 */
movq %r14, 0x18(%rsp) /* save R14 */
movq %r15, 0x20(%rsp) /* save R15 */
movq %rbx, 0x28(%rsp) /* save RBX */
movq %rbp, 0x30(%rsp) /* save RBP */

/* store RSP (pointing to context-data) in RAX */
movq %rsp, %rax

/* restore RSP (pointing to context-data) from RDI */
movq %rdi, %rsp

movq 0x38(%rsp), %r8 /* restore return-address */

#if !defined(BOOST_USE_TSX)
ldmxcsr (%rsp) /* restore MMX control- and status-word */
fldcw 0x4(%rsp) /* restore x87 control-word */
#endif

movq 0x8(%rsp), %r12 /* restore R12 */
movq 0x10(%rsp), %r13 /* restore R13 */
movq 0x18(%rsp), %r14 /* restore R14 */
movq 0x20(%rsp), %r15 /* restore R15 */
movq 0x28(%rsp), %rbx /* restore RBX */
movq 0x30(%rsp), %rbp /* restore RBP */

leaq 0x40(%rsp), %rsp /* prepare stack */

/* return transfer_t from jump */
#if !defined(_ILP32)
/* RAX == fctx, RDX == data */
movq %rsi, %rdx
#else
/* RAX == data:fctx */
salq $32, %rsi
orq %rsi, %rax
#endif
/* pass transfer_t as first arg in context function */
#if !defined(_ILP32)
/* RDI == fctx, RSI == data */
#else
/* RDI == data:fctx */
#endif
movq %rax, %rdi

/* indirect jump to context */
jmp *%r8
..size jump_fcontext,.-jump_fcontext

/* Mark that we don't need executable stack. */
..section .note.GNU-stack,"",%progbits

I would greatly appreciate it if anyone is able to take the time to look
at this.

Mark Berryman

SubjectRepliesAuthor
o New PHP kits available (and a programming question)

By: Mark Berryman on Mon, 10 Jul 2023

7Mark Berryman
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor