473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Another question about unaligned access

There is some kernel code that is playing with uncached memory in an unaligned fashion and halting the system, and hardware-supported unaligned access only works for cached memory. I want changes to existing code to be minimal. Is there a way to tell the compiler to access the memory a byte at a time, equivalent to the __unaligned keyword in MS C++?
Expand|Select|Wrap|Line Numbers
  1. unsigned char* uncachedMemory = (unsigned char*)GetUncachedMemory(); // returns 8 bytes of uncached memory, with an address that is 4-byte aligned
  2.  
  3. unsigned int* somePointer = (unsigned int*)(uncachedMemory+1);
  4.  
  5. *somePointer = 0xFFFFFFFFu; // whoops! - halts system
  6.  
Feb 28 '13 #1

✓ answered by CodeJingle

Preliminary finding is that defining a local function with the same name and prototype as an intrinsic will cause the compiler to use the user-defined function over the standard intrinsic, without emitting a duplicate symbol linker error. This can work to my advantage for solving unaligned access issues until I can come up with something better.

This solution is assuming that intrinsic memory copies and intrinsic memory sets are actually referencing intrinsic function calls, instead of performing the operation directly. So this idea may only work for a debug or non-optimized build, or it may not work at all.

But that is the only realistic option I have so far. I welcome something better. Thanks for your help :)

5 1531
Banfa
9,065 Expert Mod 8TB
Basically non, __unaligned is a MS C++ compiler extension and you should not expect to find it in any other platform.

That isn't to say you can't do it you will just have to code the byte accesses yourself.
Feb 28 '13 #2
Your solution is trivial and it would be my first choice, however is in not within the constraints I've been given.

Expecting unaligned access to uncached memory to cause exception is specific to the cpu, not the OS or development platform. And so it should not be unexpected to find an equivalent.

I either can make a tiny change to the existing code like adding another keyword to the type, or I have to change the behavior of the compiler to replace intrinsic memory copies from whatever code the compiler normally emits to code that does a strict align equivalent.

You could imagine I am being forced to solve the problem the wrong way, and I just want to know how to do it?
Feb 28 '13 #3
Banfa
9,065 Expert Mod 8TB
No __unaligned is not in the standard therefore it is an extension in that specific compiler. You can not rely on extensions because even if on another platform the same problem exists you have go guarantee that the authors of the compiler will have provide a solution and even if they have it may not be the same keyword.

The solution is to write portable code that access memory byte by byte. Not alter the behaviour of the compiler which is basically at this level impossible. You write functions to insert into and copy out of unaligned memory internally the functions access memory byte by byte and then you use those functions throughout your code.

Once you have limited the issue to a few small functions you can then write versions of those functions that are platform specific if specific platforms provide neat solutions to the problem.

Sorry I do realise that this does not involve minimal code changes but if the code was going to operate in this fashion it should have taken this consideration into account in the first place.

BTW since you have not said what compiler you are using it may be possible that the compiler you are using does provide a neat solution to this problem, however we can't tell because we don't know what it is.
Feb 28 '13 #4
Yes I own copies of the C and C++ standard specifications, you and I both know very well that __unaligned is an MS extension. My point was that if any other ARM compilers have extensions covering functionality and behavior not covered by the standards that are specific to that processor then I would expect there to be something equivalent in those extensions.

Even on the MS development platform, the __unaligned keyword only works when building for Itanium and x64. It is ignored for ARM. So on MS's own compiler I am looking for a way to replace the intrinsic memory copy emitted by the compiler with a strict align version.
Feb 28 '13 #5
Preliminary finding is that defining a local function with the same name and prototype as an intrinsic will cause the compiler to use the user-defined function over the standard intrinsic, without emitting a duplicate symbol linker error. This can work to my advantage for solving unaligned access issues until I can come up with something better.

This solution is assuming that intrinsic memory copies and intrinsic memory sets are actually referencing intrinsic function calls, instead of performing the operation directly. So this idea may only work for a debug or non-optimized build, or it may not work at all.

But that is the only realistic option I have so far. I welcome something better. Thanks for your help :)
Mar 1 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: geronimo_me | last post by:
Hi, I am atempting to compare part of a field with the whole of another field in access. Is this possible? Basically I have 2 tables with the following info: Table1 Field1 = MR.
24
by: David Mathog | last post by:
If this: int i,sum; int *array; for(sum=0, i=0; i<len; i++){ sum += array; } is converted to this (never mind why for the moment):
4
by: ad | last post by:
I want to develop DataBase application. How about Data Access Application Block? Is it useful?
4
by: CliffKing | last post by:
I am trying to use Windows Task Scheduler to run a batch file for an already open MS Access database. Below is the syntax to the batch file: Batch file: DailySalesExport.bat REM This runs the...
3
by: # Cyrille37 # | last post by:
Hello, I've got a method which could be called by a UI Event and a Timer. I would like to be shure that not 2 concurents calls append. I don't know if I can use System.Threading.Monitor....
2
by: Lauren Wilson | last post by:
Hi Folks, We have a user who is suddenly getting the following error message when they start our very mature application. Other users of the same version are NOT getting this error: "Error...
10
by: coffeesin | last post by:
Hi, I have a Table containing these fields: id-no, cold, cold ever, cold date,flu,flu ever and flu date. (The properties of id-no, cold,cold ever,flu,flu ever are set as Numbers.) What i want...
1
by: =?Utf-8?B?U00=?= | last post by:
Hi, We are trying to access a .net dll based method from classic asp code. When the method is accessed, system gives a message "You are about to access a Activex component". How do we suppress or...
2
by: Bill07 | last post by:
Hi, I'd like to import data from one table to another in MS Access using VB. Both tables have equal or same primary key. I need to match unique field's value and then update record in the second...
3
by: Salad | last post by:
I have Microsoft Office Professional 2003 and the computer I connect to also has A2003 retail. The others in that office use Access 2003 runtime. Q1) I wanted to see if they were up-to-date on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.