Skip to content
Snippets Groups Projects
Commit 05a16119f815 authored by jfp's avatar jfp
Browse files

Fix ptd modules, use separate buffers

parent ee507f63361f
No related branches found
No related tags found
No related merge requests found
...@@ -270,8 +270,8 @@ ...@@ -270,8 +270,8 @@
self._to_screen(res) self._to_screen(res)
return res return res
def write(self, string: bytes | str) -> str: def write(self, string: bytes | str, echo: bool=False) -> str:
"""Write to the pseudo terminal, return the echo string""" """Write to the pseudo terminal, return the echo string"""
wres = "" wres = ""
n = Ptd.tty_typahdsz - 8 n = Ptd.tty_typahdsz - 8
for i in range(0, len(string), n): for i in range(0, len(string), n):
...@@ -274,8 +274,8 @@ ...@@ -274,8 +274,8 @@
"""Write to the pseudo terminal, return the echo string""" """Write to the pseudo terminal, return the echo string"""
wres = "" wres = ""
n = Ptd.tty_typahdsz - 8 n = Ptd.tty_typahdsz - 8
for i in range(0, len(string), n): for i in range(0, len(string), n):
_, res = _vmsptd.write(self.ptd, string[i:i+n]) _, res = _vmsptd.write(self.ptd, string[i:i+n], echo)
if isinstance(res, bytes): if isinstance(res, bytes):
res = res.decode("iso-8859-15") res = res.decode("iso-8859-15")
elif not isinstance(res, str): elif not isinstance(res, str):
...@@ -284,8 +284,8 @@ ...@@ -284,8 +284,8 @@
self._to_screen(res) self._to_screen(res)
return wres return wres
def writeln(self, string: bytes | str): def writeln(self, string: bytes | str, echo: bool=False):
"""Write to the pseudo terminal the command and send a '\\r' character""" """Write to the pseudo terminal the command and send a '\\r' character"""
if not isinstance(string, (bytes, str)): if not isinstance(string, (bytes, str)):
raise ValueError(f"{string} should be bytes or str") raise ValueError(f"{string} should be bytes or str")
return ( return (
...@@ -288,6 +288,6 @@ ...@@ -288,6 +288,6 @@
"""Write to the pseudo terminal the command and send a '\\r' character""" """Write to the pseudo terminal the command and send a '\\r' character"""
if not isinstance(string, (bytes, str)): if not isinstance(string, (bytes, str)):
raise ValueError(f"{string} should be bytes or str") raise ValueError(f"{string} should be bytes or str")
return ( return (
self.write(string + b"\r") self.write(string + b"\r", echo)
if isinstance(string, bytes) if isinstance(string, bytes)
...@@ -293,5 +293,5 @@ ...@@ -293,5 +293,5 @@
if isinstance(string, bytes) if isinstance(string, bytes)
else self.write(string + "\r") else self.write(string + "\r", echo)
) )
def read_until( def read_until(
...@@ -432,8 +432,8 @@ ...@@ -432,8 +432,8 @@
""" """
return self.expect(list + [self.prompt], timeout) return self.expect(list + [self.prompt], timeout)
def execute(self, cmd: bytes | str) -> Tuple[str, List[str]]: def execute(self, cmd: bytes | str, echo: bool=False) -> Tuple[str, List[str]]:
"""Execute synchronously a command, so wait for the prompt """Execute synchronously a command, so wait for the prompt
Return the echo string and the list of all the results of the Return the echo string and the list of all the results of the
command including the final prompt. command including the final prompt.
""" """
...@@ -436,8 +436,8 @@ ...@@ -436,8 +436,8 @@
"""Execute synchronously a command, so wait for the prompt """Execute synchronously a command, so wait for the prompt
Return the echo string and the list of all the results of the Return the echo string and the list of all the results of the
command including the final prompt. command including the final prompt.
""" """
resw = self.writeln(cmd) resw = self.writeln(cmd, echo)
resr = self.read_until_prompt() resr = self.read_until_prompt()
return resw, resr return resw, resr
......
...@@ -41,8 +41,9 @@ ...@@ -41,8 +41,9 @@
"""status, res = readw(handler)""" """status, res = readw(handler)"""
... ...
def write(handler: PtdHandler, wrstr: bytes | str) -> Tuple[int, bytes]: def write(handler: PtdHandler, wrstr: bytes | str, echo: bool=True
"""status, res = write(handler, wrstr)""" ) -> Tuple[int, bytes]:
"""status, res = write(handler, wrstr, echo=True)"""
... ...
def set_event_notification(handler: PtdHandler) -> int: def set_event_notification(handler: PtdHandler) -> int:
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
cdef extern from *: cdef extern from *:
pass pass
from libc.stdint cimport uintptr_t
cdef extern from "ovptd.h" nogil: cdef extern from "ovptd.h" nogil:
enum: DSC_K_DTYPE_T "DSC$K_DTYPE_T" enum: DSC_K_DTYPE_T "DSC$K_DTYPE_T"
enum: DSC_K_CLASS_S "DSC$K_CLASS_S" enum: DSC_K_CLASS_S "DSC$K_CLASS_S"
...@@ -18,7 +20,7 @@ ...@@ -18,7 +20,7 @@
cdef extern from "ovptd.h" nogil: cdef extern from "ovptd.h" nogil:
enum: DSC_K_DTYPE_T "DSC$K_DTYPE_T" enum: DSC_K_DTYPE_T "DSC$K_DTYPE_T"
enum: DSC_K_CLASS_S "DSC$K_CLASS_S" enum: DSC_K_CLASS_S "DSC$K_CLASS_S"
enum: _SC_PAGE_SIZE enum: _SC_PAGESIZE
enum: EFN_C_ENF "EFN$C_ENF" enum: EFN_C_ENF "EFN$C_ENF"
enum: SS__NORMAL "SS$_NORMAL" enum: SS__NORMAL "SS$_NORMAL"
enum: SS__TIMEOUT "SS$_TIMEOUT" enum: SS__TIMEOUT "SS$_TIMEOUT"
...@@ -66,9 +68,9 @@ ...@@ -66,9 +68,9 @@
ctypedef struct ptd_handler: ctypedef struct ptd_handler:
unsigned short channel unsigned short channel
int nbpages int nbpagelets
int buflen int buflen
unsigned int efn unsigned int efn
int read_status int read_status
int timer_status int timer_status
int read_start_read int read_start_read
...@@ -70,10 +72,14 @@ ...@@ -70,10 +72,14 @@
int buflen int buflen
unsigned int efn unsigned int efn
int read_status int read_status
int timer_status int timer_status
int read_start_read int read_start_read
int maxbuf
char* read_buf
char* echo_buf
char* write_buf
VA_RANGE inadr VA_RANGE inadr
ctypedef struct DevChar: ctypedef struct DevChar:
pass pass
...@@ -75,8 +81,10 @@ ...@@ -75,8 +81,10 @@
VA_RANGE inadr VA_RANGE inadr
ctypedef struct DevChar: ctypedef struct DevChar:
pass pass
enum: SYI__MAXBUF "SYI$_MAXBUF"
void DESCSTR(...) void DESCSTR(...)
void INITDEVCHAR(...) void INITDEVCHAR(...)
void cgetmsg(int, char*, int) void cgetmsg(int, char*, int)
...@@ -86,6 +94,7 @@ ...@@ -86,6 +94,7 @@
int lib_get_ef "lib$get_ef" (...) int lib_get_ef "lib$get_ef" (...)
int lib_get_vm_page "lib$get_vm_page" (...) int lib_get_vm_page "lib$get_vm_page" (...)
int lib_free_vm_page "lib$free_vm_page" (...) int lib_free_vm_page "lib$free_vm_page" (...)
int lib_getsyi "lib$getsyi" (...)
int sys_bintim "sys$bintim" (...) int sys_bintim "sys$bintim" (...)
int sys_setimr "sys$setimr" (...) int sys_setimr "sys$setimr" (...)
int sys_hiber "sys$hiber" (...) int sys_hiber "sys$hiber" (...)
...@@ -102,6 +111,7 @@ ...@@ -102,6 +111,7 @@
void read_timeout_ast (...) void read_timeout_ast (...)
void read_start_read_ast (...) void read_start_read_ast (...)
void read_end_read_ast (...) void read_end_read_ast (...)
void* align_pointer (...)
from libc.stdio cimport printf, puts, sprintf from libc.stdio cimport printf, puts, sprintf
...@@ -120,5 +130,5 @@ ...@@ -120,5 +130,5 @@
property channel: property channel:
def __get__(self): def __get__(self):
return self.handler.channel return self.handler.channel
property nbpages: property nbpagelets:
def __get__(self): def __get__(self):
...@@ -124,5 +134,8 @@ ...@@ -124,5 +134,8 @@
def __get__(self): def __get__(self):
return self.handler.nbpages return self.handler.nbpagelets
property maxbuf:
def __get__(self):
return self.handler.maxbuf
property buflen: property buflen:
def __get__(self): def __get__(self):
return self.handler.buflen return self.handler.buflen
...@@ -284,9 +297,8 @@ ...@@ -284,9 +297,8 @@
"status, handler = create(acmode=0, charbuff=None)" "status, handler = create(acmode=0, charbuff=None)"
cdef unsigned short s; cdef unsigned short s;
cdef char* inadr[2] cdef char* inadr[2]
cdef int pgsize = sysconf(_SC_PAGE_SIZE) cdef int pgsize = sysconf(_SC_PAGESIZE)
cdef int nbpages = <int>(6 * pgsize / 512) # 4 + 1 data + 1 guard pages
cdef char* ptrc cdef char* ptrc
cdef PtdHandler handler = PtdHandler() cdef PtdHandler handler = PtdHandler()
cdef DevChar* devchar cdef DevChar* devchar
cdef unsigned short buflen cdef unsigned short buflen
...@@ -289,10 +301,17 @@ ...@@ -289,10 +301,17 @@
cdef char* ptrc cdef char* ptrc
cdef PtdHandler handler = PtdHandler() cdef PtdHandler handler = PtdHandler()
cdef DevChar* devchar cdef DevChar* devchar
cdef unsigned short buflen cdef unsigned short buflen
cdef int item_code = SYI__MAXBUF
cdef int maxbuf
s = lib_getsyi(&item_code, &maxbuf)
cdef int nbpages = 6 # 4 + 1 data + 1 guard pages
cdef int nbpagelets = <int>(nbpages * pgsize / 512)
checkStatus(s);
if charbuff is None: if charbuff is None:
devchar = NULL devchar = NULL
buflen = 0 buflen = 0
else: else:
devchar = &(charbuff.devchar) devchar = &(charbuff.devchar)
buflen = sizeof(charbuff.devchar) buflen = sizeof(charbuff.devchar)
...@@ -293,8 +312,8 @@ ...@@ -293,8 +312,8 @@
if charbuff is None: if charbuff is None:
devchar = NULL devchar = NULL
buflen = 0 buflen = 0
else: else:
devchar = &(charbuff.devchar) devchar = &(charbuff.devchar)
buflen = sizeof(charbuff.devchar) buflen = sizeof(charbuff.devchar)
s = lib_get_vm_page(&nbpages, &(handler.handler)) s = lib_get_vm_page(&nbpagelets, &(handler.handler))
checkStatus(s) checkStatus(s)
...@@ -300,5 +319,8 @@ ...@@ -300,5 +319,8 @@
checkStatus(s) checkStatus(s)
ptrc = <char *>handler.handler + pgsize + pgsize - 1 # keep one data page ptrc = <char *>align_pointer(<char *>handler.handler + pgsize, pgsize, 1) # align to page boundary, keep one data page
ptrc = ptrc - <unsigned int>ptrc % pgsize handler.handler.read_buf = ptrc
handler.handler.nbpages = nbpages handler.handler.write_buf = ptrc + maxbuf
handler.handler.echo_buf = ptrc + 2 * maxbuf
handler.handler.nbpagelets = nbpagelets
handler.handler.maxbuf = maxbuf
handler.handler.inadr.va_range_ps_start_va = ptrc handler.handler.inadr.va_range_ps_start_va = ptrc
...@@ -304,7 +326,8 @@ ...@@ -304,7 +326,8 @@
handler.handler.inadr.va_range_ps_start_va = ptrc handler.handler.inadr.va_range_ps_start_va = ptrc
handler.handler.buflen = pgsize * 4 handler.handler.buflen = buflen
handler.handler.inadr.va_range_ps_end_va = ptrc + handler.handler.buflen - 1 handler.handler.inadr.va_range_ps_end_va = <char *>align_pointer(<char *>handler.handler + nbpagelets * 512 - 1,
pgsize, 0) - 1
handler.handler.read_status = 0 handler.handler.read_status = 0
handler.handler.timer_status = 0 handler.handler.timer_status = 0
s = lib_get_ef(<unsigned int *>&(handler.handler.efn)) s = lib_get_ef(<unsigned int *>&(handler.handler.efn))
if s & 1 == 0: if s & 1 == 0:
...@@ -307,8 +330,8 @@ ...@@ -307,8 +330,8 @@
handler.handler.read_status = 0 handler.handler.read_status = 0
handler.handler.timer_status = 0 handler.handler.timer_status = 0
s = lib_get_ef(<unsigned int *>&(handler.handler.efn)) s = lib_get_ef(<unsigned int *>&(handler.handler.efn))
if s & 1 == 0: if s & 1 == 0:
lib_free_vm_page(<int *>&(handler.handler.nbpages), lib_free_vm_page(<int *>&(handler.handler.nbpagelets),
&(handler.handler)) &(handler.handler))
checkStatus(s) checkStatus(s)
s = ptd_create(<unsigned short*>&(handler.handler.channel), acmode, s = ptd_create(<unsigned short*>&(handler.handler.channel), acmode,
...@@ -316,7 +339,7 @@ ...@@ -316,7 +339,7 @@
<VA_RANGE *>&(handler.handler.inadr)) <VA_RANGE *>&(handler.handler.inadr))
if s & 1 == 0: if s & 1 == 0:
lib_free_ef(<unsigned int *>&(handler.handler.efn)) lib_free_ef(<unsigned int *>&(handler.handler.efn))
lib_free_vm_page(<int *>&(handler.handler.nbpages), lib_free_vm_page(<int *>&(handler.handler.nbpagelets),
&(handler.handler)) &(handler.handler))
checkStatus(s) checkStatus(s)
return s, handler return s, handler
...@@ -330,7 +353,7 @@ ...@@ -330,7 +353,7 @@
checkStatus(s) checkStatus(s)
s = lib_free_ef(<unsigned int *>&(handler.handler.efn)) s = lib_free_ef(<unsigned int *>&(handler.handler.efn))
checkStatus(s) checkStatus(s)
s = lib_free_vm_page(<int *>&(handler.handler.nbpages), s = lib_free_vm_page(<int *>&(handler.handler.nbpagelets),
&(handler.handler)) &(handler.handler))
return s return s
...@@ -344,5 +367,6 @@ ...@@ -344,5 +367,6 @@
s = sys_hiber() s = sys_hiber()
s = SS__NORMAL s = SS__NORMAL
handler.handler.read_status = 0 handler.handler.read_status = 0
(<unsigned short *>(handler.handler.inadr.va_range_ps_start_va))[0] = 0
with nogil: with nogil:
s = ptd_readw(EFN_C_ENF, handler.handler.channel, 0, 0, s = ptd_readw(EFN_C_ENF, handler.handler.channel, 0, 0,
...@@ -347,5 +371,5 @@ ...@@ -347,5 +371,5 @@
with nogil: with nogil:
s = ptd_readw(EFN_C_ENF, handler.handler.channel, 0, 0, s = ptd_readw(EFN_C_ENF, handler.handler.channel, 0, 0,
handler.handler.inadr.va_range_ps_start_va, handler.handler.read_buf,
handler.handler.buflen - 4) handler.handler.maxbuf - 4)
checkStatus(s) checkStatus(s)
...@@ -351,4 +375,4 @@ ...@@ -351,4 +375,4 @@
checkStatus(s) checkStatus(s)
s = (<unsigned short *>(handler.handler.inadr.va_range_ps_start_va))[0] s = (<unsigned short *>(handler.handler.read_buf))[0]
checkStatus(s) checkStatus(s)
handler.handler.read_status = 0 handler.handler.read_status = 0
...@@ -353,6 +377,6 @@ ...@@ -353,6 +377,6 @@
checkStatus(s) checkStatus(s)
handler.handler.read_status = 0 handler.handler.read_status = 0
cdef char* buf = <char *>(handler.handler.inadr.va_range_ps_start_va) + 4 cdef char* buf = <char *>(handler.handler.read_buf) + 4
cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2) cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2)
return s, buf[:retlenPtr[0]] return s, buf[:retlenPtr[0]]
...@@ -385,11 +409,11 @@ ...@@ -385,11 +409,11 @@
with nogil: with nogil:
s = ptd_read(EFN_C_ENF, handler.handler.channel, read_ast, s = ptd_read(EFN_C_ENF, handler.handler.channel, read_ast,
<int>handler.handler, <int>handler.handler,
handler.handler.inadr.va_range_ps_start_va, handler.handler.read_buf,
handler.handler.buflen - 4) handler.handler.maxbuf - 4)
checkStatus(s) checkStatus(s)
while ((handler.handler.read_status == 1) and while ((handler.handler.read_status == 1) and
(handler.handler.timer_status == 1)): (handler.handler.timer_status == 1)):
s = sys_hiber() s = sys_hiber()
if handler.handler.timer_status == 2: if handler.handler.timer_status == 2:
handler.handler.timer_status = 0 handler.handler.timer_status = 0
...@@ -390,7 +414,8 @@ ...@@ -390,7 +414,8 @@
checkStatus(s) checkStatus(s)
while ((handler.handler.read_status == 1) and while ((handler.handler.read_status == 1) and
(handler.handler.timer_status == 1)): (handler.handler.timer_status == 1)):
s = sys_hiber() s = sys_hiber()
if handler.handler.timer_status == 2: if handler.handler.timer_status == 2:
handler.handler.timer_status = 0 handler.handler.timer_status = 0
handler.handler.read_status = 0
return SS__TIMEOUT, None return SS__TIMEOUT, None
...@@ -396,3 +421,5 @@ ...@@ -396,3 +421,5 @@
return SS__TIMEOUT, None return SS__TIMEOUT, None
cdef char* buf = <char *>(handler.handler.inadr.va_range_ps_start_va) + 4 s = (<unsigned short *>(handler.handler.read_buf))[0]
checkStatus(s)
cdef char* buf = <char *>(handler.handler.read_buf) + 4
cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2) cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2)
...@@ -398,4 +425,5 @@ ...@@ -398,4 +425,5 @@
cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2) cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2)
handler.handler.timer_status = 0
handler.handler.read_status = 0 handler.handler.read_status = 0
return s, buf[:retlenPtr[0]] return s, buf[:retlenPtr[0]]
...@@ -399,9 +427,9 @@ ...@@ -399,9 +427,9 @@
handler.handler.read_status = 0 handler.handler.read_status = 0
return s, buf[:retlenPtr[0]] return s, buf[:retlenPtr[0]]
def write(PtdHandler handler, wrtstr): def write(PtdHandler handler, wrtstr, echo=False):
"status, res = write(handler, wrstr)" "status, res = write(handler, wrstr, echo=False)"
wrtstr = getstr(wrtstr) wrtstr = getstr(wrtstr)
cdef char* wrtstrPtr = wrtstr cdef char* wrtstrPtr = wrtstr
cdef int wlen = len(wrtstr) cdef int wlen = len(wrtstr)
cdef unsigned short s; cdef unsigned short s;
...@@ -404,8 +432,10 @@ ...@@ -404,8 +432,10 @@
wrtstr = getstr(wrtstr) wrtstr = getstr(wrtstr)
cdef char* wrtstrPtr = wrtstr cdef char* wrtstrPtr = wrtstr
cdef int wlen = len(wrtstr) cdef int wlen = len(wrtstr)
cdef unsigned short s; cdef unsigned short s;
if wlen > 1024: cdef int with_echo;
raise ValueError('Invalid wrtstr length, maximum is 1024') with_echo = echo
cdef char* wrtbuf = <char *>(handler.handler.inadr.va_range_ps_start_va) if wlen > handler.handler.maxbuf - 4:
raise ValueError(f'Invalid wrtstr length, maximum is {handler.handler.maxbuf - 4}')
cdef char* wrtbuf = <char *>(handler.handler.write_buf)
cdef char* readbuf = \ cdef char* readbuf = \
...@@ -411,4 +441,6 @@ ...@@ -411,4 +441,6 @@
cdef char* readbuf = \ cdef char* readbuf = \
<char *>(handler.handler.inadr.va_range_ps_start_va) + 1024 <char *>(handler.handler.echo_buf)
cdef char* buf = <char *>(readbuf) + 4
cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2)
memset(wrtbuf, 4, 0) memset(wrtbuf, 4, 0)
strncpy(wrtbuf + 4, wrtstrPtr, wlen) strncpy(wrtbuf + 4, wrtstrPtr, wlen)
...@@ -413,6 +445,7 @@ ...@@ -413,6 +445,7 @@
memset(wrtbuf, 4, 0) memset(wrtbuf, 4, 0)
strncpy(wrtbuf + 4, wrtstrPtr, wlen) strncpy(wrtbuf + 4, wrtstrPtr, wlen)
memset(readbuf, 4, 0)
if handler.handler.read_status != 0: if handler.handler.read_status != 0:
cancel(handler) cancel(handler)
with nogil: with nogil:
s = ptd_write(handler.handler.channel, 0, 0, s = ptd_write(handler.handler.channel, 0, 0,
...@@ -415,7 +448,9 @@ ...@@ -415,7 +448,9 @@
if handler.handler.read_status != 0: if handler.handler.read_status != 0:
cancel(handler) cancel(handler)
with nogil: with nogil:
s = ptd_write(handler.handler.channel, 0, 0, s = ptd_write(handler.handler.channel, 0, 0,
handler.handler.inadr.va_range_ps_start_va, wlen, readbuf, handler.handler.write_buf, wlen, readbuf if with_echo else NULL,
handler.handler.buflen - 1024 - 4) handler.handler.maxbuf - 4 if with_echo else 0)
checkStatus(s)
s = (<unsigned short *>(wrtbuf))[0]
checkStatus(s) checkStatus(s)
...@@ -421,7 +456,5 @@ ...@@ -421,7 +456,5 @@
checkStatus(s) checkStatus(s)
s = (<unsigned short *>(handler.handler.inadr.va_range_ps_start_va))[0] if with_echo:
# if s != 0: s = (<unsigned short *>(readbuf))[0]
# checkStatus(s) checkStatus(s)
cdef char* buf = <char *>(handler.handler.inadr.va_range_ps_start_va) + 4
cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2)
return s, buf[:retlenPtr[0]] return s, buf[:retlenPtr[0]]
...@@ -427,4 +460,5 @@ ...@@ -427,4 +460,5 @@
return s, buf[:retlenPtr[0]] return s, buf[:retlenPtr[0]]
return s, buf[:0]
def set_event_notification(PtdHandler handler): def set_event_notification(PtdHandler handler):
"status = set_event_notification(handler)" "status = set_event_notification(handler)"
...@@ -446,4 +480,4 @@ ...@@ -446,4 +480,4 @@
) )
checkStatus(s) checkStatus(s)
return s return s
\ No newline at end of file
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <inttypes.h>
#include <descrip.h> #include <descrip.h>
#include <gen64def.h> #include <gen64def.h>
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
#include <starlet.h> #include <starlet.h>
#include <afrdef.h> #include <afrdef.h>
#include <ssdef.h> #include <ssdef.h>
#include <syidef.h>
#include <stsdef.h> #include <stsdef.h>
#include <ttdef.h> #include <ttdef.h>
#include <tt2def.h> #include <tt2def.h>
...@@ -62,7 +64,7 @@ ...@@ -62,7 +64,7 @@
typedef volatile struct { typedef volatile struct {
unsigned short channel; unsigned short channel;
int nbpages; int nbpagelets;
int buflen; int buflen;
unsigned int efn; unsigned int efn;
int read_status; /* 0: no IO, 1: IO started, 2: IO finished */ int read_status; /* 0: no IO, 1: IO started, 2: IO finished */
...@@ -70,6 +72,10 @@ ...@@ -70,6 +72,10 @@
int read_start_read; /* 0: no read request int read_start_read; /* 0: no read request
1: the pseudoterminal is starting an 1: the pseudoterminal is starting an
application's read request.*/ application's read request.*/
int maxbuf;
char* read_buf;
char* echo_buf;
char* write_buf;
VA_RANGE inadr; VA_RANGE inadr;
} ptd_handler; } ptd_handler;
...@@ -114,10 +120,10 @@ ...@@ -114,10 +120,10 @@
} }
if (ptr->timer_status != 0) { if (ptr->timer_status != 0) {
sys$cantim((unsigned __int64)ptr, 0); sys$cantim((unsigned __int64)ptr, 0);
ptr->timer_status = 0; // ptr->timer_status = 0;
} }
} }
static void read_timeout_ast(ptd_handler* ptr) { static void read_timeout_ast(ptd_handler* ptr) {
ptr->timer_status = 2; ptr->timer_status = 2;
ptd$cancel(ptr->channel); ptd$cancel(ptr->channel);
...@@ -118,10 +124,10 @@ ...@@ -118,10 +124,10 @@
} }
} }
static void read_timeout_ast(ptd_handler* ptr) { static void read_timeout_ast(ptd_handler* ptr) {
ptr->timer_status = 2; ptr->timer_status = 2;
ptd$cancel(ptr->channel); ptd$cancel(ptr->channel);
ptr->read_status = 0; // ptr->read_status = 0;
sys$wake(0, 0); sys$wake(0, 0);
} }
...@@ -135,4 +141,29 @@ ...@@ -135,4 +141,29 @@
// sys$wake(0, 0); // sys$wake(0, 0);
} }
void* align_pointer(char* ptr, size_t page_size, int align_up) {
/*
* Aligns a pointer to a page boundary (lower or upper).
*
* Parameters:
* ptr - The initial pointer (char*).
* page_size - The size of a memory page in bytes.
* align_up - If non-zero, aligns to the upper page boundary.
* If zero, aligns to the lower page boundary.
*
* Returns:
* A pointer aligned to the specified page boundary (void*).
*/
// Convert the pointer to an integer for alignment calculations
uintptr_t addr = (uintptr_t)ptr;
if (align_up) {
// Align to the upper page boundary
return (void*)((addr + (page_size - 1)) & ~(page_size - 1));
} else {
// Align to the lower page boundary
return (void*)(addr & ~(page_size - 1));
}
}
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment