Thread: Direct memory access?

  1. #16
    Registered User
    Join Date
    Sep 2007
    Posts
    67
    Quote Originally Posted by CornedBee View Post
    There's nothing interesting about endless amounts of hex digits, believe me.
    Yeah there is!! I love hex editing, and converting hex to assembler and stuff. I love doing math and stuff with hex, it's fun!

    I'm a nerd, I know =P

  2. #17
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    If you really want to access memory and look at it because you think it would be 'cool' then create your own array, fill it with data, stream to std out, and enjoy. If that's not 'cool' enough for you then you probably are interested more in something we do not condone on this board. Well behaved programs don't go poking around in memory they do not own nor do they attempt to access the hard drive at a low level. Exceptions to the rule would be low level utils like defrag or Diskkeeper or some other utils. I highly doubt this is one of those exceptions.

    You can access memory but only that which belongs to you and that which you have allocated. There is nothing exciting about ton of hexadecimal digits.

  3. #18
    Registered User
    Join Date
    Sep 2007
    Posts
    67
    I'm not going to argue with you cause you can ban me. But if I were interested at the moment in lobbinb stuff like this onto other computers, I wouldn't be on this forum. It'd just be intersting to make a different interface into the hard drive, but not a really high-level one.

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I'm a nerd. You're just a masochist.

    A hard drive is a huge thing to look at. Load data files like PNGs or MP3s into a hex editor and compare their headers and general structure to the format descriptions, if that's your thing.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #20
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by Bubba View Post
    If you really want to access memory and look at it because you think it would be 'cool' then create your own array, fill it with data, stream to std out, and enjoy. If that's not 'cool' enough for you then you probably are interested more in something we do not condone on this board. Well behaved programs don't go poking around in memory they do not own nor do they attempt to access the hard drive at a low level. Exceptions to the rule would be low level utils like defrag or Diskkeeper or some other utils. I highly doubt this is one of those exceptions.

    You can access memory but only that which belongs to you and that which you have allocated. There is nothing exciting about ton of hexadecimal digits.
    How is asking for direct access to the hard drive akin to a malicious program? To do so in Windows he would need to be in kernel space, and to do so in Linux he would need root access. This does not at all sound like a "hacker" sort of question.

  6. #21
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I believe that as long as the drive isn't mounted, you can actually open a hard-disk for read/write as a raw device. Of course this excludes the boot-device, as that is definitely being mounted as part of the boot process. But if you have a disk that isn't being used by the OS, then you can [assuming you have sufficient [e.g. administrator] rights on the machine] open the drive itself for read/write, and use ReadFile and WriteFile to access the raw data on the drive.

    Now why anyone would want to do that on a modern OS with a modern filesystem is a different story.

    Of course, if you write your own driver, you can also access the hard-disk directly there - just bear in mind that if you mix this with OS accesses, God [or Satan, more likely, perhaps] only knows what you'll end up with, but it is unlikely to be anything good.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #22
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by matsp View Post
    Now why anyone would want to do that on a modern OS with a modern filesystem is a different story.
    Perhaps because there is no full-blown driver for that particular filesystem available, and you want to read some files anyway. There are various tools to read files from Linux FSs under Windows (e.g. rfsgui for ReiserFS).

    Or because you want to write a userspace format utility.

    Or because you want to draw a bit-by-bit backup.

    Or ... you get the idea.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #23
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    Perhaps because there is no full-blown driver for that particular filesystem available, and you want to read some files anyway. There are various tools to read files from Linux FSs under Windows (e.g. rfsgui for ReiserFS).

    Or because you want to write a userspace format utility.

    Or because you want to draw a bit-by-bit backup.

    Or ... you get the idea.
    Sure, but it gets quite complex quite quickly.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #24
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by Elysia View Post
    That would be a rather poor operating system, if I may say so.
    There's more OS's than desktop OS

  10. #25
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    I would recommend to pick up a book about driver writing for the OS you want to work on

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by KIBO View Post
    There's more OS's than desktop OS
    I'll admit, I didn't think of operating systems for embedded and things.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #27
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    First, I think people are gettign virtual memory confused with paging. Virtual memory is specifically when the OS uses mass storage to create the appearance of more memory than the system has physical RAM. Hence 'virtual' memory. It does this by marking unused pages as not-present in the global descriptor table or one of the local tables. The decriptor table entry is what maps the apparent memory location to a physical memory location, or to an external device. When the processor accesses a memory location the paging unit looks up the location in the descriptor tables, and if it is marked as present uses the value in the tables to access physical memory, if it is marked as not-present, then it causes a page fault, which the OS must handle. Usually this is done by paging a not recently used page to the pagefile, and paging the needed address block into physical ram, although there are other schemes.

  13. #28
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Quote Originally Posted by CornedBee View Post
    Hard disks have an organization, you know.
    They have a Union.

  14. #29
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by abachler View Post
    First, I think people are gettign virtual memory confused with paging. Virtual memory is specifically when the OS uses mass storage to create the appearance of more memory than the system has physical RAM. Hence 'virtual' memory. It does this by marking unused pages as not-present in the global descriptor table or one of the local tables. The decriptor table entry is what maps the apparent memory location to a physical memory location, or to an external device. When the processor accesses a memory location the paging unit looks up the location in the descriptor tables, and if it is marked as present uses the value in the tables to access physical memory, if it is marked as not-present, then it causes a page fault, which the OS must handle. Usually this is done by paging a not recently used page to the pagefile, and paging the needed address block into physical ram, although there are other schemes.
    Descriptor tables (in x86) are what describes memory segments, and although those HAVE a "present" bit that needs to be set for the segment to be accessible, it's not involved in "swapping to disk" [hasn't been that way since OS/2 1.x]. Most 32-bit OS's use only two segments, shared between EVERY process in the system [1]

    Paging and virtual memory are essentially, in a modern system, done by the page-table, where pages of 4KB at a time can be made present or not present. [2]

    But paging is also used in conjunction with protection, such that each process has it's own page-table, so that only that process can access the pages that particular process owns.

    Once paging is enabled, addresses within the processor [at least on x86] are considered "virtual", meaning that the page is accessed through the page-table. The virtual to physical translation can be linear or non-linear, where a linear translation is "direct", 1:1 between the virtual and the physical address. The non-linear, any virtual address can point to "any" physical location.


    [1] Technicaly, there is a duplicate set of segment descriptors for when the OS is in the kernel, and perhaps also some other "administrative", for example a TSS segment to handle Double-Fault/Stack-Fault [in kernel mode] conditions.


    [2] Some processors and OS's support "Large pages", where pages are for example 2MB instead of 4KB, which reduces the size of the page-table for example when having large shared sections of OS memory that is common between all processes, and thus don't need the small 4KB granularity.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #30
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by indigo0086 View Post
    They have a Union.
    Ah, that's what "Union FS" is all about

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. quick question on direct file access
    By Stevek in forum C++ Programming
    Replies: 2
    Last Post: 03-21-2003, 01:33 AM
  5. Memory Access Error when using Strcpy()
    By fgs3124 in forum C Programming
    Replies: 2
    Last Post: 03-15-2002, 03:07 PM