Skip to content

Commit

Permalink
Add libc and OW fmemfree wrapper functions and man pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Nov 18, 2024
1 parent 781fcd7 commit 8d25a01
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions elkscmd/man/man2/fmemalloc.2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _fmemalloc \- allocate far memory outside process
.nf
.ft B
_fmemalloc(int \fIparas\fP, unsigned short *\fIpseg\fP)
_fmemfree(unsigned short \fIseg\fP)
.ft R
.fi
.SH DESCRIPTION
Expand All @@ -16,6 +17,10 @@ paragraphs of main memory
from outside the process for use using a __far pointer within the application.
The segment address of the memory is stored in the pointer
.IR pseg .
.PP
.B _fmemfree
frees the memory segment allocated by a previous
.BR _fmemalloc .
.SH "RETURN VALUE
The value 0 is returned if no error occurs. Otherwise,
the call returns a negative error number.
Expand Down
7 changes: 6 additions & 1 deletion elkscmd/man/man3/fmemalloc.3
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fmemalloc \- allocate far memory outside process
#include <stdlib.h>

void __far *fmemalloc(unsigned long \fIsize\fP)
int fmemfree(void __far *\fIptr\fP)
.ft R
.fi
.SH DESCRIPTION
Expand All @@ -19,7 +20,11 @@ within the application.
The
.IR size
parameter will be rounded up to the next paragraph boundary.

.PP
.B fmemfree
frees memory allocated by a prevous
.BR fmemalloc .
.PP
Any allocated memory will be automatically freed on exit from the application.
.SH "RETURN VALUE
The value 0 is returned if no error occurs. Otherwise,
Expand Down
1 change: 1 addition & 0 deletions libc/include/watcom/syselks.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ typedef int syscall_res;
#define SYS_setsockopt 204
#define SYS_getsocknam 205
#define SYS_fmemalloc 206
#define SYS_fmemfree 207


#define _sys_exit(rc) sys_call1n(SYS_exit, rc)
Expand Down
1 change: 1 addition & 0 deletions libc/malloc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ OBJS = \
realloc.o \
sbrk.o \
fmemalloc.o \
fmemfree.o \

.PHONY: all

Expand Down
7 changes: 7 additions & 0 deletions libc/malloc/fmemfree.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <malloc.h>

/* free from main memory */
int fmemfree(void __far *ptr)
{
return _fmemfree((unsigned short)((unsigned long)ptr >> 16));
}
14 changes: 14 additions & 0 deletions libc/watcom/syscall/fmemfree.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/****************************************************************************
*
* Description: ELKS _fmemfree() system call.
*
****************************************************************************/

#include <malloc.h>
#include "watcom/syselks.h"

int _fmemfree( unsigned short __seg )
{
syscall_res res = sys_call1( SYS_fmemfree, __seg);
__syscall_return( int, res );
}

0 comments on commit 8d25a01

Please sign in to comment.