Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
vmspython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
Python
Modules
vmspython
Commits
56bdbeabb0c4
Commit
56bdbeabb0c4
authored
5 months ago
by
jfp
Browse files
Options
Downloads
Patches
Plain Diff
Allocate buffer with a end at page limit
parent
6e0b22f464a6
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/local/ovms_module/ovms/ptd/_vmsptd.pyx
+12
-15
12 additions, 15 deletions
python/local/ovms_module/ovms/ptd/_vmsptd.pyx
python/local/ovms_module/ovms/ptd/ovptd.h
+47
-0
47 additions, 0 deletions
python/local/ovms_module/ovms/ptd/ovptd.h
with
59 additions
and
15 deletions
python/local/ovms_module/ovms/ptd/_vmsptd.pyx
+
12
−
15
View file @
56bdbeab
...
...
@@ -112,7 +112,8 @@
void
read_start_read_ast
(...)
void
read_end_read_ast
(...)
void
*
align_pointer
(...)
void
*
allocate_page_aligned_memory
(...)
void
free_page_aligned_memory
(...)
from
libc.stdio
cimport
printf
,
puts
,
sprintf
...
...
@@ -305,5 +306,6 @@
cdef
int
item_code
=
SYI__MAXBUF
cdef
int
maxbuf
s
=
lib_getsyi
(
&
item_code
,
&
maxbuf
)
checkStatus
(
s
);
cdef
int
nbpages
=
6
# 4 + 1 data + 1 guard pages
cdef
int
nbpagelets
=
<
int
>
(
nbpages
*
pgsize
/
512
)
...
...
@@ -308,10 +310,9 @@
cdef
int
nbpages
=
6
# 4 + 1 data + 1 guard pages
cdef
int
nbpagelets
=
<
int
>
(
nbpages
*
pgsize
/
512
)
checkStatus
(
s
);
cdef
int
allocsz
=
sizeof
(
ptd_handler
)
+
3
*
maxbuf
+
pgsize
if
charbuff
is
None
:
devchar
=
NULL
buflen
=
0
else
:
devchar
=
&
(
charbuff
.
devchar
)
buflen
=
sizeof
(
charbuff
.
devchar
)
...
...
@@ -312,12 +313,11 @@
if
charbuff
is
None
:
devchar
=
NULL
buflen
=
0
else
:
devchar
=
&
(
charbuff
.
devchar
)
buflen
=
sizeof
(
charbuff
.
devchar
)
s
=
lib_get_vm_page
(
&
nbpagelets
,
&
(
handler
.
handler
))
checkStatus
(
s
)
ptrc
=
<
char
*>
align_pointer
(
<
char
*>
handler
.
handler
+
pgsize
,
pgsize
,
1
)
# align to page boundary, keep one data page
handler
.
handler
=
<
ptd_handler
*>
allocate_page_aligned_memory
(
allocsz
,
pgsize
)
ptrc
=
<
char
*>
handler
.
handler
+
pgsize
handler
.
handler
.
read_buf
=
ptrc
handler
.
handler
.
write_buf
=
ptrc
+
maxbuf
handler
.
handler
.
echo_buf
=
ptrc
+
2
*
maxbuf
...
...
@@ -325,9 +325,9 @@
handler
.
handler
.
maxbuf
=
maxbuf
handler
.
handler
.
inadr
.
va_range_ps_start_va
=
ptrc
handler
.
handler
.
buflen
=
buflen
handler
.
handler
.
inadr
.
va_range_ps_end_va
=
<
char
*>
align_pointer
(
<
char
*>
handler
.
handler
+
nbpagelets
*
512
-
1
,
pgsize
,
0
)
-
1
handler
.
handler
.
inadr
.
va_range_ps_end_va
=
\
<
char
*>
align_pointer
(
<
char
*>
handler
.
handler
+
allocsz
,
pgsize
,
1
)
-
1
handler
.
handler
.
read_status
=
0
handler
.
handler
.
timer_status
=
0
s
=
lib_get_ef
(
<
unsigned
int
*>&
(
handler
.
handler
.
efn
))
if
s
&
1
==
0
:
...
...
@@ -330,12 +330,11 @@
handler
.
handler
.
read_status
=
0
handler
.
handler
.
timer_status
=
0
s
=
lib_get_ef
(
<
unsigned
int
*>&
(
handler
.
handler
.
efn
))
if
s
&
1
==
0
:
lib_free_vm_page
(
<
int
*>&
(
handler
.
handler
.
nbpagelets
),
&
(
handler
.
handler
))
free_page_aligned_memory
(
ptrc
)
checkStatus
(
s
)
s
=
ptd_create
(
<
unsigned
short
*>&
(
handler
.
handler
.
channel
),
acmode
,
devchar
,
buflen
,
0
,
0
,
0
,
<
VA_RANGE
*>&
(
handler
.
handler
.
inadr
))
if
s
&
1
==
0
:
lib_free_ef
(
<
unsigned
int
*>&
(
handler
.
handler
.
efn
))
...
...
@@ -336,11 +335,10 @@
checkStatus
(
s
)
s
=
ptd_create
(
<
unsigned
short
*>&
(
handler
.
handler
.
channel
),
acmode
,
devchar
,
buflen
,
0
,
0
,
0
,
<
VA_RANGE
*>&
(
handler
.
handler
.
inadr
))
if
s
&
1
==
0
:
lib_free_ef
(
<
unsigned
int
*>&
(
handler
.
handler
.
efn
))
lib_free_vm_page
(
<
int
*>&
(
handler
.
handler
.
nbpagelets
),
&
(
handler
.
handler
))
free_page_aligned_memory
(
ptrc
)
checkStatus
(
s
)
return
s
,
handler
...
...
@@ -353,8 +351,7 @@
checkStatus
(
s
)
s
=
lib_free_ef
(
<
unsigned
int
*>&
(
handler
.
handler
.
efn
))
checkStatus
(
s
)
s
=
lib_free_vm_page
(
<
int
*>&
(
handler
.
handler
.
nbpagelets
),
&
(
handler
.
handler
))
free_page_aligned_memory
(
handler
.
handler
.
read_buf
)
return
s
def
readw
(
PtdHandler
handler
):
...
...
This diff is collapsed.
Click to expand it.
python/local/ovms_module/ovms/ptd/ovptd.h
+
47
−
0
View file @
56bdbeab
...
...
@@ -166,4 +166,51 @@
return
(
void
*
)(
addr
&
~
(
page_size
-
1
));
}
}
void
*
allocate_page_aligned_memory
(
size_t
size
,
size_t
page_size
)
{
/*
* Allocates memory aligned to a page boundary with a length rounded
* to the nearest multiple of the page size.
*
* Parameters:
* size - The requested size of the memory block.
* page_size - The alignment size (usually the system's page size).
*
* Returns:
* A pointer to the allocated memory (aligned) or NULL on failure.
*/
// Round size up to the nearest multiple of the page size
size_t
rounded_size
=
(
size
+
page_size
-
1
)
&
~
(
page_size
-
1
);
// Over-allocate memory to ensure alignment
void
*
raw_memory
=
malloc
(
rounded_size
+
page_size
-
1
+
sizeof
(
void
*
));
if
(
raw_memory
==
NULL
)
{
return
NULL
;
// Allocation failed
}
// Align the pointer
uintptr_t
raw_addr
=
(
uintptr_t
)
raw_memory
+
sizeof
(
void
*
);
uintptr_t
aligned_addr
=
(
raw_addr
+
(
page_size
-
1
))
&
~
(
page_size
-
1
);
// Store the original pointer just before the aligned memory
((
void
**
)
aligned_addr
)[
-
1
]
=
raw_memory
;
return
(
void
*
)
aligned_addr
;
}
void
free_page_aligned_memory
(
void
*
aligned_memory
)
{
/*
* Frees memory allocated with allocate_page_aligned_memory.
*
* Parameters:
* aligned_memory - Pointer to the aligned memory.
*/
if
(
aligned_memory
)
{
// Retrieve the original pointer and free it
void
*
raw_memory
=
((
void
**
)
aligned_memory
)[
-
1
];
free
(
raw_memory
);
}
}
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment