delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/07/30/12:38:59

Sender: rich AT phekda DOT freeserve DOT co DOT uk
Message-ID: <39845669.9BD5A7AB@phekda.freeserve.co.uk>
Date: Sun, 30 Jul 2000 17:23:05 +0100
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.14 i586)
X-Accept-Language: de,fr
MIME-Version: 1.0
To: DJGPP workers <djgpp-workers AT delorie DOT com>
Subject: Patch for packing in dpmi.h
Reply-To: djgpp-workers AT delorie DOT com

This is a multi-part message in MIME format.
--------------7B26F6670271E502E8C76F39
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello.

Please find attached a patch for putting the packed attribute on the
structures in dpmi.h. A diff for the changelog entry also attached.

I went through the code to see which structures actually need the packed
attribute, but it turned out all of them where involved somewhere in calls
to DPMI. So the simpler solution of blindly making them all packed would
have worked. ;)

I also noticed that a couple of the go32 structures assumed that field
were arranged in the same way as in __dpmi_paddr, __dpmi_raddr, so I added
a comment pointing this out.

I haven't tested this extensively - I recompiled libsocket using the new
header (since the assembly is unchanged) and it seemed to work OK.
libsocket uses the DPMI functions to allocate several blocks of memory,
both DOS and non-DOS, so it does a few reasonable memory-related calls.

I don't think this change needs much testing, but if someone could run the
go32 tests for me, I'd be grateful. I can't seem to get the test suite to
cross-compile on Linux.

I think a couple of other headers may need packing - coff.h, for instance.
Perhaps they need an audit sometime?

After some reflection, it strikes me that the possibility of adding
padding in the middle of a structure could make using libraries very
difficult - i.e. binary incompatibility between code compiled with
different padding regimes. I think padding in the middle is something that
a compiler would either: a) always do in a consistent manner; b) not do at
all. If the DJGPP port of gcc ever started padding in the middle, I think
we'd have a lot of broken code.

Thanks, bye, Rich =]

-- 
Richard Dawe
[ mailto:richdawe AT bigfoot DOT com | http://www.bigfoot.com/~richdawe/ ]
--------------7B26F6670271E502E8C76F39
Content-Type: text/plain; charset=us-ascii;
 name="dpmi.h.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="dpmi.h.diff"

*** dpmi.h.orig	Sat Jul 29 13:22:58 2000
--- dpmi.h	Sat Jul 29 13:50:57 2000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #ifndef __dj_include_dpmi_h_
***************
*** 16,136 ****
  extern unsigned short __dpmi_error;
  
  typedef struct {
!   unsigned short offset16;
!   unsigned short segment;
  } __dpmi_raddr;
  
  typedef struct {
!   unsigned long  offset32;
!   unsigned short selector;
  } __dpmi_paddr;
  
  typedef struct {
!   unsigned long handle;			/* 0, 2 */
!   unsigned long size; 	/* or count */	/* 4, 6 */
!   unsigned long address;		/* 8, 10 */
  } __dpmi_meminfo;
  
  typedef union {
    struct {
!     unsigned long edi;
!     unsigned long esi;
!     unsigned long ebp;
!     unsigned long res;
!     unsigned long ebx;
!     unsigned long edx;
!     unsigned long ecx;
!     unsigned long eax;
    } d;
    struct {
!     unsigned short di, di_hi;
!     unsigned short si, si_hi;
!     unsigned short bp, bp_hi;
!     unsigned short res, res_hi;
!     unsigned short bx, bx_hi;
!     unsigned short dx, dx_hi;
!     unsigned short cx, cx_hi;
!     unsigned short ax, ax_hi;
!     unsigned short flags;
!     unsigned short es;
!     unsigned short ds;
!     unsigned short fs;
!     unsigned short gs;
!     unsigned short ip;
!     unsigned short cs;
!     unsigned short sp;
!     unsigned short ss;
    } x;
    struct {
!     unsigned char edi[4];
!     unsigned char esi[4];
!     unsigned char ebp[4];
!     unsigned char res[4];
!     unsigned char bl, bh, ebx_b2, ebx_b3;
!     unsigned char dl, dh, edx_b2, edx_b3;
!     unsigned char cl, ch, ecx_b2, ecx_b3;
!     unsigned char al, ah, eax_b2, eax_b3;
    } h;
  } __dpmi_regs;
    
  typedef struct {
!   unsigned char  major;
!   unsigned char  minor;
!   unsigned short flags;
!   unsigned char  cpu;
!   unsigned char  master_pic;
!   unsigned char  slave_pic;
  } __dpmi_version_ret;
  
  typedef struct {
!   unsigned long largest_available_free_block_in_bytes;
!   unsigned long maximum_unlocked_page_allocation_in_pages;
!   unsigned long maximum_locked_page_allocation_in_pages;
!   unsigned long linear_address_space_size_in_pages;
!   unsigned long total_number_of_unlocked_pages;
!   unsigned long total_number_of_free_pages;
!   unsigned long total_number_of_physical_pages;
!   unsigned long free_linear_address_space_in_pages;
!   unsigned long size_of_paging_file_partition_in_pages;
!   unsigned long reserved[3];
  } __dpmi_free_mem_info;
  
  typedef struct {
!   unsigned long total_allocated_bytes_of_physical_memory_host;
!   unsigned long total_allocated_bytes_of_virtual_memory_host;
!   unsigned long total_available_bytes_of_virtual_memory_host;
!   unsigned long total_allocated_bytes_of_virtual_memory_vcpu;
!   unsigned long total_available_bytes_of_virtual_memory_vcpu;
!   unsigned long total_allocated_bytes_of_virtual_memory_client;
!   unsigned long total_available_bytes_of_virtual_memory_client;
!   unsigned long total_locked_bytes_of_memory_client;
!   unsigned long max_locked_bytes_of_memory_client;
!   unsigned long highest_linear_address_available_to_client;
!   unsigned long size_in_bytes_of_largest_free_memory_block;
!   unsigned long size_of_minimum_allocation_unit_in_bytes;
!   unsigned long size_of_allocation_alignment_unit_in_bytes;
!   unsigned long reserved[19];
  } __dpmi_memory_info;
  
  typedef struct {
!   unsigned long data16[2];
!   unsigned long code16[2];
!   unsigned short ip;
!   unsigned short reserved;
!   unsigned long data32[2];
!   unsigned long code32[2];
!   unsigned long eip;
  } __dpmi_callback_info;
  
  typedef struct {
!   unsigned long size_requested;
!   unsigned long size;
!   unsigned long handle;
!   unsigned long address;
!   unsigned long name_offset;
!   unsigned short name_selector;
!   unsigned short reserved1;
!   unsigned long reserved2;
  } __dpmi_shminfo;
  
  /* Unless otherwise noted, all functions return -1 on error, setting __dpmi_error to the DPMI error code */
--- 17,161 ----
  extern unsigned short __dpmi_error;
  
  typedef struct {
!   unsigned short offset16 __attribute__((packed));
!   unsigned short segment  __attribute__((packed));
  } __dpmi_raddr;
  
  typedef struct {
!   unsigned long  offset32 __attribute__((packed));
!   unsigned short selector __attribute__((packed));
  } __dpmi_paddr;
  
  typedef struct {
!   unsigned long handle  __attribute__((packed)); /* 0, 2 */
!   unsigned long size    __attribute__((packed)); /* 4, 6 */ /* or count */
!   unsigned long address __attribute__((packed)); /* 8, 10 */
  } __dpmi_meminfo;
  
  typedef union {
    struct {
!     unsigned long edi __attribute__((packed));
!     unsigned long esi __attribute__((packed));
!     unsigned long ebp __attribute__((packed));
!     unsigned long res __attribute__((packed));
!     unsigned long ebx __attribute__((packed));
!     unsigned long edx __attribute__((packed));
!     unsigned long ecx __attribute__((packed));
!     unsigned long eax __attribute__((packed));
    } d;
    struct {
!     unsigned short di, di_hi   __attribute__((packed));
!     unsigned short si, si_hi   __attribute__((packed));
!     unsigned short bp, bp_hi   __attribute__((packed));
!     unsigned short res, res_hi __attribute__((packed));
!     unsigned short bx, bx_hi   __attribute__((packed));
!     unsigned short dx, dx_hi   __attribute__((packed));
!     unsigned short cx, cx_hi   __attribute__((packed));
!     unsigned short ax, ax_hi   __attribute__((packed));
!     unsigned short flags       __attribute__((packed));
!     unsigned short es          __attribute__((packed));
!     unsigned short ds          __attribute__((packed));
!     unsigned short fs          __attribute__((packed));
!     unsigned short gs          __attribute__((packed));
!     unsigned short ip          __attribute__((packed));
!     unsigned short cs          __attribute__((packed));
!     unsigned short sp          __attribute__((packed));
!     unsigned short ss          __attribute__((packed));
    } x;
    struct {
!     unsigned char edi[4]                 __attribute__((packed));
!     unsigned char esi[4]                 __attribute__((packed));
!     unsigned char ebp[4]                 __attribute__((packed));
!     unsigned char res[4]                 __attribute__((packed));
!     unsigned char bl, bh, ebx_b2, ebx_b3 __attribute__((packed));
!     unsigned char dl, dh, edx_b2, edx_b3 __attribute__((packed));
!     unsigned char cl, ch, ecx_b2, ecx_b3 __attribute__((packed));
!     unsigned char al, ah, eax_b2, eax_b3 __attribute__((packed));
    } h;
  } __dpmi_regs;
    
  typedef struct {
!   unsigned char  major      __attribute__((packed));
!   unsigned char  minor      __attribute__((packed));
!   unsigned short flags      __attribute__((packed));
!   unsigned char  cpu        __attribute__((packed));
!   unsigned char  master_pic __attribute__((packed));
!   unsigned char  slave_pic  __attribute__((packed));
  } __dpmi_version_ret;
  
  typedef struct {
!   unsigned long largest_available_free_block_in_bytes
!                 __attribute__((packed));
!   unsigned long maximum_unlocked_page_allocation_in_pages
!                 __attribute__((packed));
!   unsigned long maximum_locked_page_allocation_in_pages
!                 __attribute__((packed));
!   unsigned long linear_address_space_size_in_pages
!                 __attribute__((packed));
!   unsigned long total_number_of_unlocked_pages
!                 __attribute__((packed));
!   unsigned long total_number_of_free_pages
!                 __attribute__((packed));
!   unsigned long total_number_of_physical_pages
!                 __attribute__((packed));
!   unsigned long free_linear_address_space_in_pages
!                 __attribute__((packed));
!   unsigned long size_of_paging_file_partition_in_pages
!                 __attribute__((packed));
!   unsigned long reserved[3]
!                 __attribute__((packed));
  } __dpmi_free_mem_info;
  
  typedef struct {
!   unsigned long total_allocated_bytes_of_physical_memory_host
!                 __attribute__((packed));
!   unsigned long total_allocated_bytes_of_virtual_memory_host
!                 __attribute__((packed));
!   unsigned long total_available_bytes_of_virtual_memory_host
!                 __attribute__((packed));
!   unsigned long total_allocated_bytes_of_virtual_memory_vcpu
!                 __attribute__((packed));
!   unsigned long total_available_bytes_of_virtual_memory_vcpu
!                 __attribute__((packed));
!   unsigned long total_allocated_bytes_of_virtual_memory_client
!                 __attribute__((packed));
!   unsigned long total_available_bytes_of_virtual_memory_client
!                 __attribute__((packed));
!   unsigned long total_locked_bytes_of_memory_client
!                 __attribute__((packed));
!   unsigned long max_locked_bytes_of_memory_client
!                 __attribute__((packed));
!   unsigned long highest_linear_address_available_to_client
!                 __attribute__((packed));
!   unsigned long size_in_bytes_of_largest_free_memory_block
!                 __attribute__((packed));
!   unsigned long size_of_minimum_allocation_unit_in_bytes
!                 __attribute__((packed));
!   unsigned long size_of_allocation_alignment_unit_in_bytes
!                 __attribute__((packed));
!   unsigned long reserved[19]
!                 __attribute__((packed));
  } __dpmi_memory_info;
  
  typedef struct {
!   unsigned long data16[2] __attribute__((packed));
!   unsigned long code16[2] __attribute__((packed));
!   unsigned short ip       __attribute__((packed));
!   unsigned short reserved __attribute__((packed));
!   unsigned long data32[2] __attribute__((packed));
!   unsigned long code32[2] __attribute__((packed));
!   unsigned long eip       __attribute__((packed));
  } __dpmi_callback_info;
  
  typedef struct {
!   unsigned long size_requested __attribute__((packed));
!   unsigned long size           __attribute__((packed));
!   unsigned long handle         __attribute__((packed));
!   unsigned long address        __attribute__((packed));
!   unsigned long name_offset    __attribute__((packed));
!   unsigned short name_selector __attribute__((packed));
!   unsigned short reserved1     __attribute__((packed));
!   unsigned long reserved2      __attribute__((packed));
  } __dpmi_shminfo;
  
  /* Unless otherwise noted, all functions return -1 on error, setting __dpmi_error to the DPMI error code */
***************
*** 241,257 ****
  
  #define _go32_dpmi_registers            __dpmi_regs
  
  typedef struct {
!   unsigned long available_memory;
!   unsigned long available_pages;
!   unsigned long available_lockable_pages;
!   unsigned long linear_space;
!   unsigned long unlocked_pages;
!   unsigned long available_physical_pages;
!   unsigned long total_physical_pages;
!   unsigned long free_linear_space;
!   unsigned long max_pages_in_paging_file;
!   unsigned long reserved[3];
  } _go32_dpmi_meminfo;
  
  #define _go32_dpmi_get_free_memory_information(x) __dpmi_get_free_memory_information((__dpmi_free_mem_info *)(x))
--- 266,284 ----
  
  #define _go32_dpmi_registers            __dpmi_regs
  
+ /* NB: This structure contains the same info as __dpmi_free_mem_info, but under
+  * different names. */
  typedef struct {
!   unsigned long available_memory         __attribute__((packed));
!   unsigned long available_pages          __attribute__((packed));
!   unsigned long available_lockable_pages __attribute__((packed));
!   unsigned long linear_space             __attribute__((packed));
!   unsigned long unlocked_pages           __attribute__((packed));
!   unsigned long available_physical_pages __attribute__((packed));
!   unsigned long total_physical_pages     __attribute__((packed));
!   unsigned long free_linear_space        __attribute__((packed));
!   unsigned long max_pages_in_paging_file __attribute__((packed));
!   unsigned long reserved[3]              __attribute__((packed));
  } _go32_dpmi_meminfo;
  
  #define _go32_dpmi_get_free_memory_information(x) __dpmi_get_free_memory_information((__dpmi_free_mem_info *)(x))
***************
*** 260,271 ****
  #define _go32_dpmi_simulate_fcall	__dpmi_simulate_real_mode_procedure_retf
  #define _go32_dpmi_simulate_fcall_iret	__dpmi_simulate_real_mode_procedure_iret
  
  typedef struct {
!   unsigned long size;
!   unsigned long pm_offset;
!   unsigned short pm_selector;
!   unsigned short rm_offset;
!   unsigned short rm_segment;
  } _go32_dpmi_seginfo;
  
  /* returns zero if success, else dpmi error and info->size is max size */
--- 287,300 ----
  #define _go32_dpmi_simulate_fcall	__dpmi_simulate_real_mode_procedure_retf
  #define _go32_dpmi_simulate_fcall_iret	__dpmi_simulate_real_mode_procedure_iret
  
+ /* NB: The offset, selector pairs should be arranged in the same order as they
+  * occur in __dpmi_paddr and __dpmi_raddr. */
  typedef struct {
!   unsigned long size         __attribute__((packed));
!   unsigned long pm_offset    __attribute__((packed));
!   unsigned short pm_selector __attribute__((packed));
!   unsigned short rm_offset   __attribute__((packed));
!   unsigned short rm_segment  __attribute__((packed));
  } _go32_dpmi_seginfo;
  
  /* returns zero if success, else dpmi error and info->size is max size */

--------------7B26F6670271E502E8C76F39
Content-Type: text/plain; charset=us-ascii;
 name="wc204.txi.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="wc204.txi.diff"

*** wc204.txi.orig	Sun Jul 30 17:11:54 2000
--- wc204.txi	Sun Jul 30 17:13:32 2000
***************
*** 92,94 ****
--- 92,96 ----
  @code{struct itimerval} set to zero no longer causes the timer to behave
  as if @code{it_interval.tv_usec} were set to the system clock
  granularity (55 AT dmn{msec} by default).
+ 
+ The structures in the header @file{dpmi.h} are now packed.

--------------7B26F6670271E502E8C76F39--

- Raw text -


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