delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/06/13/07:42:37

Message-ID: <22ec01c331a0$4a9a2410$0600000a@broadpark.no>
From: "Gisle Vanem" <giva AT bgnett DOT no>
To: "djgpp" <djgpp AT delorie DOT com>
Subject: mprotect() under Windows
Date: Fri, 13 Jun 2003 13:38:20 +0200
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Reply-To: djgpp AT delorie DOT com

Is mprotect() (in djgpp 2.03) supposed to have any effect under Win-XP?
I guess not since function 0x0507 is a DPMI 1.0 function.

But I find that __dpmi_set_page_attributes() doesn't return -1.
This small test program *doesn't* crash. Anybody see why?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dpmi.h>
#include <sys/mman.h>

#define PAGESIZE      4096
#define ROUND_PAGE(p) (((unsigned long)(p) + (PAGESIZE-1)) & ~(PAGESIZE-1))

int main (void)
{
  char *p = malloc (3*PAGESIZE);

  p = (char*) ROUND_PAGE(p);
  p += PAGESIZE;
  printf ("p = %08lX\n", (unsigned long)p);
  strcpy (p, "1234567890123456789");

  __dpmi_error = 0;
  if (mprotect (p, PAGESIZE, PROT_NONE) != 0)
     puts ("mprotect() failed");
  printf ("__dpmi_error %04X\n", __dpmi_error);

  printf ("%.10s", p);
  return (0);
}

--------------
The output is:
  p = 00025000
  __dpmi_error 0000
  1234567890

I'd expect a crash on the last printf()

--gv

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019