add large-object allocation (over 4 MB) with mmap

This commit is contained in:
Jesse D. McDonald 2020-10-20 22:21:20 -05:00
parent 53c76a2e6a
commit 9e21704825
2 changed files with 24 additions and 4 deletions

View File

@ -257,7 +257,7 @@ defconst SYS_BRK,__NR_brk
/* defconst SYS_SWAPON,__NR_swapon */ /* defconst SYS_SWAPON,__NR_swapon */
/* defconst SYS_REBOOT,__NR_reboot */ /* defconst SYS_REBOOT,__NR_reboot */
/* defconst SYS_READDIR,__NR_readdir */ /* defconst SYS_READDIR,__NR_readdir */
/* defconst SYS_MUNMAP,__NR_munmap */ defconst SYS_MUNMAP,__NR_munmap
/* defconst SYS_GETPRIORITY,__NR_getpriority */ /* defconst SYS_GETPRIORITY,__NR_getpriority */
/* defconst SYS_SETPRIORITY,__NR_setpriority */ /* defconst SYS_SETPRIORITY,__NR_setpriority */
/* defconst SYS_IOPERM,__NR_ioperm */ /* defconst SYS_IOPERM,__NR_ioperm */
@ -321,7 +321,7 @@ defconst SYS_BRK,__NR_brk
/* defconst SYS_CAPSET,__NR_capset */ /* defconst SYS_CAPSET,__NR_capset */
/* defconst SYS_SIGALTSTACK,__NR_sigaltstack */ /* defconst SYS_SIGALTSTACK,__NR_sigaltstack */
/* defconst SYS_VFORK,__NR_vfork */ /* defconst SYS_VFORK,__NR_vfork */
/* defconst SYS_MMAP2,__NR_mmap2 */ defconst SYS_MMAP2,__NR_mmap2
/* defconst SYS_TRUNCATE64,__NR_truncate64 */ /* defconst SYS_TRUNCATE64,__NR_truncate64 */
/* defconst SYS_FTRUNCATE64,__NR_ftruncate64 */ /* defconst SYS_FTRUNCATE64,__NR_ftruncate64 */
/* defconst SYS_STAT64,__NR_stat64 */ /* defconst SYS_STAT64,__NR_stat64 */

View File

@ -710,13 +710,33 @@ VARIABLE TOTAL
: ALIGN-TO ( u -- ) : ALIGN-TO ( u -- )
HERE SWAP ALIGNED-TO HERE - ALLOT ; HERE SWAP ALIGNED-TO HERE - ALLOT ;
0 CONSTANT NULL
: KB 10 LSHIFT ;
: MB 20 LSHIFT ;
: ALLOCATE ( size -- a-addr ) : ALLOCATE ( size -- a-addr )
CELL+ DUP BUDDY-MAX-BYTES CELL- U> "unsupported size" ?FAIL CELL+ DUP BUDDY-MAX-BYTES U> IF
MARK A
BEGIN
NULL OVER PROT_READ PROT_WRITE OR
MAP_PRIVATE MAP_ANONYMOUS OR -1 0 SYS_MMAP2 SYSCALL6
DUP -4095 U>=
WHILE
NEGATE ERRNO_EINTR <> IF EXCP-HEAP-OVERFLOW THROW THEN
REPEAT
TUCK ! CELL+ EXIT
THEN
MARK B
NATURALLY-ALIGNED DUP BUDDY-MIN-BYTES U< IF DROP BUDDY-MIN-BYTES THEN NATURALLY-ALIGNED DUP BUDDY-MIN-BYTES U< IF DROP BUDDY-MIN-BYTES THEN
BUDDY-ORDER-FROM-BYTES DUP BUDDY-ALLOCATE SWAP OVER ! CELL+ ; BUDDY-ORDER-FROM-BYTES DUP BUDDY-ALLOCATE SWAP OVER ! CELL+ ;
: FREE ( a-addr -- ) : FREE ( a-addr -- )
CELL- DUP @ SWAP BUDDY-FREE ; CELL- DUP @
DUP BUDDY-ORDERS U< IF SWAP BUDDY-FREE EXIT THEN
BEGIN
2DUP SYS_MUNMAP SYSCALL2 ?DUP 0= IF 2DROP EXIT THEN
NEGATE ERRNO_EINTR <> "munmap failed" ?FAIL
AGAIN ;
\ Read the next word and return the first character \ Read the next word and return the first character
: CHAR ( "<spaces>name" -- c ) : CHAR ( "<spaces>name" -- c )