About some DOS/32a functions d32a_xxx()

Programming, for all ages and all languages.
Post Reply
liaoo
Member
Member
Posts: 36
Joined: Wed Jun 13, 2012 8:37 pm

About some DOS/32a functions d32a_xxx()

Post by liaoo »

Dear all,

I have 2 questions about DOS/32a functions...

Could anybody provide me with the “exact function descriptions” of below functions which are found in the directory of <examples> after installing dos32a(dos extender)... Have anyone ever used these functions ?

1. d32a_getfreemem_low()
2. d32a_getfreemem_high()
3. d32a_getfreemem_total()
4. d32a_malloc()
5. d32a_malloc_low()
6. d32a_malloc_high()
7. d32a_free()
8. d32a_free_all()


And what is the difference between d32a_malloc() and malloc() ?
Ex. Watcom provides void *malloc( size_t size ) BUT why d32a_malloc() is introduced ? :?:

Thanks ! :)
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: About some DOS/32a functions d32a_xxx()

Post by Tosi »

The watcom malloc is probably 16 bits and either returns a near pointer or a far pointer.
Judging by the name, the dos32a extender uses either protected mode or unreal mode, or some other mode in which a 32-bit address space can be accessed. Thus, the dos32a malloc might return a flat 32-bit pointer. Of course, I have never used the extender so I don't know and you would be better off using google to find your answers.
liaoo
Member
Member
Posts: 36
Joined: Wed Jun 13, 2012 8:37 pm

Re: About some DOS/32a functions d32a_xxx()

Post by liaoo »

My app is written by combining watcom + dos/32a and I found malloc() will return 32-bit pointer if allocating memory successfully...
( the app runs in flat memory mode thus if print the pointer then get the result like "0:3012FE08" )

I did not find the function descriptions for these in dos/32a source BUT just the declarations in .h file...

The reason why I ask is my app often "reset" or "hang" after specific operations. By some observations I guess maybe this is due to memory allocating/de-allocating...
* In my code I allocated memory and de-allocate it frequently and the memory size ranges from 512Byte to 4MB.

Thus I want to know if d32a_malloc() and d32a_free() are more "stable" ? (because I used dos/32a as DOS extender and they belongs to dos/32a library...)
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: About some DOS/32a functions d32a_xxx()

Post by Tosi »

The 32-bit pointer returned by malloc is not a flat pointer.
It is a combined segment:offset. So if "0:3012FE08" got printed, something went wrong, because "3012:FE08" is what should have been printed. This points to 3FF28h in absolute addressing. Learn segment-offset addressing before writing DOS code, it will save you a lot of pain.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: About some DOS/32a functions d32a_xxx()

Post by Nable »

to Tosi
This topic is not about pure DOS, it's about some 32-bit DOS extender. So, i'm not sure that segment:offset addressing scheme is used here.
liaoo
Member
Member
Posts: 36
Joined: Wed Jun 13, 2012 8:37 pm

Re: About some DOS/32a functions d32a_xxx()

Post by liaoo »

It is true that my app runs at flat memory model and I quoted some information about flat memory as below from: http://www.azillionmonkeys.com/qed/watfaq.shtml
So WATCOM C/C++'s sweet spot model is the FLAT memory model. FLAT memory model is an analogue of TINY model for 32 bit programs. ES and DS are set to the same selector which points at the base of memory and maps all 4GB of address space. CS is a selector that points to all of memory like DS and ES, but has the execution attribute set, meaning that it cannot be written to directly. SS is set to a special stack segment to make stack overflow easier to detect. This set up allows you to, in nearly all situations, ignore segment/selector registers completely. FS and GS are available for applications to use as they see fit and by default are set to 0.
Unless you are dealing with interfacing to external 16 bit resources (such as APIs implemented through interrupts) you never need to deal with 64K segment limits, or strange keywords like FAR, NEAR or MK_FP. Pointers and int's are both 32 bit, and while its not advisable, you can cast between the two and still be portable to most platforms (16 bit x86 environments and 64 bit DEC Alpha environments being the most notable exceptions.)
Besides, someone told me about these functions as below:
Late in the development of DOS/32A there was an attempt to simplify DPMI programming (which required the use of assembly lang.) by creating a wrapper library around commonly used DPMI functions. The library was abandoned when DOS/32A went open-source and the source of d32a lib is now lost. The functions about query the amount of free memory in the DOS area, the extended memory and the total (DOS + extended). The other ones simply allocate memory from either low or high memory pools. Note the difference: DOS memory is visible for both real- and protected mode code, Extended memory cannot be accessed from real mode and is for protected mode use only.

See DOS/32A specific (i.e. non-standard) DPMI functions 0FF90h-0FF9Ah since those are the functions exposed by d32a library:

http://dos32a.narechk.net/manual/html/p ... /0ff90.htm
http://dos32a.narechk.net/manual/html/p ... /0ff91.htm
...
liaoo
Member
Member
Posts: 36
Joined: Wed Jun 13, 2012 8:37 pm

Re: About some DOS/32a functions d32a_xxx()

Post by liaoo »

Dear all,
I found the root cause why app hang or reset and it was due to heap trashed by accessing the memory area which was released before !

* I added _heapchk() in some check points to see if Heap is OK nor not to narrow down the root cause !

F.Y.I
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: About some DOS/32a functions d32a_xxx()

Post by bubach »

Using font colors should be forbidden for theme compatibility.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: About some DOS/32a functions d32a_xxx()

Post by Griwes »

bubach wrote:Using font colors should be forbidden for theme compatibility.
It is.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Post Reply