News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

_msize

Started by SteveAsm, January 18, 2012, 11:06:33 PM

Previous topic - Next topic

SteveAsm

Jwasm's WinInc doesn't seem to have a prototype for _msize.
I have searched thru all the ..\jwasm\include\  .INC files.

I tried using malloc.inc from Mingw (malloc.h), but, that just opened a can of worms.
Any suggestions on how to proceed ?

hutch--

teve,

Do you know where it comes from, SDK, C runtime etc .... ?

OK< its a C runtime function.


size_t _msize(
   void *memblock
);


Just write a prototype for it and include the correct library.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MichaelW

I coded this in MASM, but I think the same basic approach (without the printf macro and the other MASM32 macros) should work for jwasm.

;==============================================================================
    include \masm32\include\masm32rt.inc
    includelib c:\MinGW\lib\libmsvcrt.a
;==============================================================================

malloc PROTO C memsize:DWORD

_msize PROTO C pMemblock:DWORD

;==============================================================================

printf MACRO format:REQ, args:VARARG
    IFNB <args>
        invoke crt_printf, cfm$(format), args
    ELSE
        invoke crt_printf, cfm$(format)
    ENDIF
    EXITM <>
ENDM

;==============================================================================
    .data
    .code
;==============================================================================
start:
;==============================================================================

    invoke malloc, 1000
    invoke _msize, eax
    printf("%d\n\n", eax)

    invoke malloc, 1000000
    invoke _msize, eax
    printf("%d\n\n", eax)

    inkey "Press any key to exit..."
    exit
;==============================================================================
end start


Note that my choice of a DWORD for pMemBlock assumes 32-bit code, and that I assumed that you do have MinGW but do not have the MASM32 components, which would allow you to do the invokes as:

    invoke crt_malloc, 1000
    invoke crt__msize, eax

Without the protos or the MinGW import library.


eschew obfuscation

SteveAsm

Quote from: hutch-- on January 18, 2012, 11:23:23 PM
OK< its a C runtime function.
...<snip>
Just write a prototype for it and include the correct library.

Hey Hutch,
Yeh, I tried that prior to posting, but, couldn't quite get the prototype right.

So, what I've done now is to simply copy the prototype from malloc.inc (from mingw):

    _msize proto c :ptr

minus all the rest of the stuff that was producing a bunch of error messages.
This works great now.
I guess it's pulling the function from either crtdll.lib or msvcrt.lib, both of which I have included.

Thanks

SteveAsm

Quote from: MichaelW on January 19, 2012, 12:07:12 AM
I coded this in MASM, but I think the same basic approach (without the printf macro and the other MASM32 macros) should work for jwasm.

Hi Michael,
Yes, it would work as you suggest, if I were using Masm32, but, in my project I am unable to do so.
This has to be plain-vanilla jwasm, without the benefits of masm32.
I can, however, use mingw, if I can get it to work.

MichaelW

I assembled and linked this with the Microsoft tools, but I'm assuming that JWasm and JWlink, or other available linkers, could be used as well.

;==============================================================================
; Link as a console app.
;==============================================================================
    .486
    .model flat, stdcall
    option casemap :none
    include c:\wininc2.0\include\windows.inc
    include c:\wininc2.0\include\stdio.inc
    includelib c:\wininc2.0\lib\kernel32.lib
    includelib c:\wininc2.0\lib\msvcrt.lib
;==============================================================================

_getch  PROTO C
malloc  PROTO C memsize:DWORD
_msize  PROTO C pMemblock:DWORD
free    PROTO C pMemblock:DWORD

;==============================================================================
    .data
        fmt db "%d",10,0
    .code
;==============================================================================
main:
;==============================================================================

    invoke malloc, 1000
    push eax
    invoke _msize, eax
    invoke printf, ADDR fmt, eax
    pop eax
    invoke free, eax

    invoke malloc, 1000000
    push eax
    invoke _msize, eax
    invoke printf, ADDR fmt, eax
    pop eax
    invoke free, eax

    invoke _getch

    invoke ExitProcess, 0

;==============================================================================
end main

eschew obfuscation